diff --git a/README.md b/README.md index 3a43181..2de9667 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ You can also follow the instructions below. I have tried to make them pretty gra In a terminal, use `cd` to get to a folder you want this project in. Then, clone the repo and move into it: -``` +```sh git clone https://github.com/arrowtype/recursive-code-config.git cd recursive-code-config ``` @@ -58,7 +58,7 @@ cd recursive-code-config Then, set up the venv and install requirements: -```bash +```sh python3 -m venv venv # make a virtual environment called "venv" source venv/bin/activate # activate the virtual environment pip install -r requirements.txt # install dependencies @@ -68,7 +68,7 @@ pip install -r requirements.txt # install dependencies Setting up the venv and install requirements is slightly different in Windows, in my testing. Navigate to the project in a terminal, and then use the following commands: -```bash +```sh py -m venv venv # make a virtual environment called "venv" venv\Scripts\activate # activate the virtual environment pip install -r requirements.txt # install dependencies @@ -78,7 +78,7 @@ pip install -r requirements.txt # install dependencies This file uses YAML. Hopefully, it is fairly self-explanatory. If not, file an issue and someone will hopefully help out! -First, specify the family name you want (e.g. `Rec Mono Custom`). +First, specify the family name you want (e.g. `Rec Code Custom`). Then, specify axis values you want for Regular, Italic, Bold, & Bold Italic fonts. @@ -121,7 +121,7 @@ source venv/bin/activate # activate the virtual environment if you haven python3 scripts/instantiate-code-fonts.py ``` -It will build & output fonts to a folder like `RecMono-Custom` (this is affected by whatever custom name you give fonts in config.yaml). +It will build & output fonts to a folder like `RecCode-Custom` (this is affected by whatever custom name you give fonts in config.yaml). #### 3. Install the fonts and activate the ligatures! diff --git a/config.yaml b/config.yaml index 4e16c21..5bc038d 100644 --- a/config.yaml +++ b/config.yaml @@ -1,4 +1,4 @@ -# Configure your own custom Rec Mono for Code font +# Configure your own custom Rec Code for Code font # # /$$$$$$ /$$ @@ -16,11 +16,11 @@ # ----------------------------------------------------------------------------- # Family Name -# The name you want after "Rec Mono" in your custom fonts. -# Example: "Custom" will yield the family "Rec Mono Custom". +# The name you want after "Rec Code" in your custom fonts. +# Example: "Custom" will yield the family "Rec Code Custom". # Keep under 13 characters in length to avoid potential OS bugs. -Family Name: Custom +Family Name Suffix: Custom # ----------------------------------------------------------------------------- # Font Styles @@ -71,7 +71,7 @@ Fonts: Code Ligatures: True # Include font features to freeze in stylistic options. Copy them below to use. -# See README for details. +# See the project README for details. # These options only have an affect at CRSV<=0.5 (Roman/normal styles) # ss01 # Single-story a diff --git a/fonts/RecMonoCasual/RecMonoCasual-Bold-1.085.ttf b/fonts/RecCodeCasual/RecCodeCasual-Bold-1.085.ttf similarity index 99% rename from fonts/RecMonoCasual/RecMonoCasual-Bold-1.085.ttf rename to fonts/RecCodeCasual/RecCodeCasual-Bold-1.085.ttf index 92eb36e..605394f 100644 Binary files a/fonts/RecMonoCasual/RecMonoCasual-Bold-1.085.ttf and b/fonts/RecCodeCasual/RecCodeCasual-Bold-1.085.ttf differ diff --git a/fonts/RecMonoCasual/RecMonoCasual-BoldItalic-1.085.ttf b/fonts/RecCodeCasual/RecCodeCasual-BoldItalic-1.085.ttf similarity index 99% rename from fonts/RecMonoCasual/RecMonoCasual-BoldItalic-1.085.ttf rename to fonts/RecCodeCasual/RecCodeCasual-BoldItalic-1.085.ttf index 28fd072..574d3d9 100644 Binary files a/fonts/RecMonoCasual/RecMonoCasual-BoldItalic-1.085.ttf and b/fonts/RecCodeCasual/RecCodeCasual-BoldItalic-1.085.ttf differ diff --git a/fonts/RecMonoCasual/RecMonoCasual-Italic-1.085.ttf b/fonts/RecCodeCasual/RecCodeCasual-Italic-1.085.ttf similarity index 98% rename from fonts/RecMonoCasual/RecMonoCasual-Italic-1.085.ttf rename to fonts/RecCodeCasual/RecCodeCasual-Italic-1.085.ttf index ab9b272..5cda7e3 100644 Binary files a/fonts/RecMonoCasual/RecMonoCasual-Italic-1.085.ttf and b/fonts/RecCodeCasual/RecCodeCasual-Italic-1.085.ttf differ diff --git a/fonts/RecMonoCasual/RecMonoCasual-Regular-1.085.ttf b/fonts/RecCodeCasual/RecCodeCasual-Regular-1.085.ttf similarity index 99% rename from fonts/RecMonoCasual/RecMonoCasual-Regular-1.085.ttf rename to fonts/RecCodeCasual/RecCodeCasual-Regular-1.085.ttf index b618529..d275735 100644 Binary files a/fonts/RecMonoCasual/RecMonoCasual-Regular-1.085.ttf and b/fonts/RecCodeCasual/RecCodeCasual-Regular-1.085.ttf differ diff --git a/fonts/RecMonoDuotone/RecMonoDuotone-Bold-1.085.ttf b/fonts/RecCodeDuotone/RecCodeDuotone-Bold-1.085.ttf similarity index 99% rename from fonts/RecMonoDuotone/RecMonoDuotone-Bold-1.085.ttf rename to fonts/RecCodeDuotone/RecCodeDuotone-Bold-1.085.ttf index 8b04680..c2bd84e 100644 Binary files a/fonts/RecMonoDuotone/RecMonoDuotone-Bold-1.085.ttf and b/fonts/RecCodeDuotone/RecCodeDuotone-Bold-1.085.ttf differ diff --git a/fonts/RecMonoDuotone/RecMonoDuotone-BoldItalic-1.085.ttf b/fonts/RecCodeDuotone/RecCodeDuotone-BoldItalic-1.085.ttf similarity index 99% rename from fonts/RecMonoDuotone/RecMonoDuotone-BoldItalic-1.085.ttf rename to fonts/RecCodeDuotone/RecCodeDuotone-BoldItalic-1.085.ttf index a49507d..ed94643 100644 Binary files a/fonts/RecMonoDuotone/RecMonoDuotone-BoldItalic-1.085.ttf and b/fonts/RecCodeDuotone/RecCodeDuotone-BoldItalic-1.085.ttf differ diff --git a/fonts/RecMonoDuotone/RecMonoDuotone-Italic-1.085.ttf b/fonts/RecCodeDuotone/RecCodeDuotone-Italic-1.085.ttf similarity index 98% rename from fonts/RecMonoDuotone/RecMonoDuotone-Italic-1.085.ttf rename to fonts/RecCodeDuotone/RecCodeDuotone-Italic-1.085.ttf index 422e686..1584525 100644 Binary files a/fonts/RecMonoDuotone/RecMonoDuotone-Italic-1.085.ttf and b/fonts/RecCodeDuotone/RecCodeDuotone-Italic-1.085.ttf differ diff --git a/fonts/RecMonoDuotone/RecMonoDuotone-Regular-1.085.ttf b/fonts/RecCodeDuotone/RecCodeDuotone-Regular-1.085.ttf similarity index 99% rename from fonts/RecMonoDuotone/RecMonoDuotone-Regular-1.085.ttf rename to fonts/RecCodeDuotone/RecCodeDuotone-Regular-1.085.ttf index 6c70b56..cfc1cb0 100644 Binary files a/fonts/RecMonoDuotone/RecMonoDuotone-Regular-1.085.ttf and b/fonts/RecCodeDuotone/RecCodeDuotone-Regular-1.085.ttf differ diff --git a/fonts/RecMonoLinear/RecMonoLinear-Bold-1.085.ttf b/fonts/RecCodeLinear/RecCodeLinear-Bold-1.085.ttf similarity index 99% rename from fonts/RecMonoLinear/RecMonoLinear-Bold-1.085.ttf rename to fonts/RecCodeLinear/RecCodeLinear-Bold-1.085.ttf index 3531b95..c0324a0 100644 Binary files a/fonts/RecMonoLinear/RecMonoLinear-Bold-1.085.ttf and b/fonts/RecCodeLinear/RecCodeLinear-Bold-1.085.ttf differ diff --git a/fonts/RecMonoLinear/RecMonoLinear-BoldItalic-1.085.ttf b/fonts/RecCodeLinear/RecCodeLinear-BoldItalic-1.085.ttf similarity index 99% rename from fonts/RecMonoLinear/RecMonoLinear-BoldItalic-1.085.ttf rename to fonts/RecCodeLinear/RecCodeLinear-BoldItalic-1.085.ttf index 4bfacb5..626f52c 100644 Binary files a/fonts/RecMonoLinear/RecMonoLinear-BoldItalic-1.085.ttf and b/fonts/RecCodeLinear/RecCodeLinear-BoldItalic-1.085.ttf differ diff --git a/fonts/RecMonoLinear/RecMonoLinear-Italic-1.085.ttf b/fonts/RecCodeLinear/RecCodeLinear-Italic-1.085.ttf similarity index 99% rename from fonts/RecMonoLinear/RecMonoLinear-Italic-1.085.ttf rename to fonts/RecCodeLinear/RecCodeLinear-Italic-1.085.ttf index a50983b..8e9d656 100644 Binary files a/fonts/RecMonoLinear/RecMonoLinear-Italic-1.085.ttf and b/fonts/RecCodeLinear/RecCodeLinear-Italic-1.085.ttf differ diff --git a/fonts/RecMonoLinear/RecMonoLinear-Regular-1.085.ttf b/fonts/RecCodeLinear/RecCodeLinear-Regular-1.085.ttf similarity index 99% rename from fonts/RecMonoLinear/RecMonoLinear-Regular-1.085.ttf rename to fonts/RecCodeLinear/RecCodeLinear-Regular-1.085.ttf index 329e99c..7622c66 100644 Binary files a/fonts/RecMonoLinear/RecMonoLinear-Regular-1.085.ttf and b/fonts/RecCodeLinear/RecCodeLinear-Regular-1.085.ttf differ diff --git a/fonts/RecCodeSansDuo/RecCodeSansDuo-Bold-1.085.ttf b/fonts/RecCodeSansDuo/RecCodeSansDuo-Bold-1.085.ttf new file mode 100644 index 0000000..72ca94a Binary files /dev/null and b/fonts/RecCodeSansDuo/RecCodeSansDuo-Bold-1.085.ttf differ diff --git a/fonts/RecCodeSansDuo/RecCodeSansDuo-BoldItalic-1.085.ttf b/fonts/RecCodeSansDuo/RecCodeSansDuo-BoldItalic-1.085.ttf new file mode 100644 index 0000000..43c509e Binary files /dev/null and b/fonts/RecCodeSansDuo/RecCodeSansDuo-BoldItalic-1.085.ttf differ diff --git a/fonts/RecCodeSansDuo/RecCodeSansDuo-Italic-1.085.ttf b/fonts/RecCodeSansDuo/RecCodeSansDuo-Italic-1.085.ttf new file mode 100644 index 0000000..94c0f42 Binary files /dev/null and b/fonts/RecCodeSansDuo/RecCodeSansDuo-Italic-1.085.ttf differ diff --git a/fonts/RecCodeSansDuo/RecCodeSansDuo-Regular-1.085.ttf b/fonts/RecCodeSansDuo/RecCodeSansDuo-Regular-1.085.ttf new file mode 100644 index 0000000..c2e458d Binary files /dev/null and b/fonts/RecCodeSansDuo/RecCodeSansDuo-Regular-1.085.ttf differ diff --git a/fonts/RecMonoSemicasual/RecMonoSemicasual-Bold-1.085.ttf b/fonts/RecCodeSemicasual/RecCodeSemicasual-Bold-1.085.ttf similarity index 99% rename from fonts/RecMonoSemicasual/RecMonoSemicasual-Bold-1.085.ttf rename to fonts/RecCodeSemicasual/RecCodeSemicasual-Bold-1.085.ttf index c42c07e..62a7a93 100644 Binary files a/fonts/RecMonoSemicasual/RecMonoSemicasual-Bold-1.085.ttf and b/fonts/RecCodeSemicasual/RecCodeSemicasual-Bold-1.085.ttf differ diff --git a/fonts/RecMonoSemicasual/RecMonoSemicasual-BoldItalic-1.085.ttf b/fonts/RecCodeSemicasual/RecCodeSemicasual-BoldItalic-1.085.ttf similarity index 99% rename from fonts/RecMonoSemicasual/RecMonoSemicasual-BoldItalic-1.085.ttf rename to fonts/RecCodeSemicasual/RecCodeSemicasual-BoldItalic-1.085.ttf index 9d7e793..5f8b0ea 100644 Binary files a/fonts/RecMonoSemicasual/RecMonoSemicasual-BoldItalic-1.085.ttf and b/fonts/RecCodeSemicasual/RecCodeSemicasual-BoldItalic-1.085.ttf differ diff --git a/fonts/RecMonoSemicasual/RecMonoSemicasual-Italic-1.085.ttf b/fonts/RecCodeSemicasual/RecCodeSemicasual-Italic-1.085.ttf similarity index 99% rename from fonts/RecMonoSemicasual/RecMonoSemicasual-Italic-1.085.ttf rename to fonts/RecCodeSemicasual/RecCodeSemicasual-Italic-1.085.ttf index 6a5c48e..b2e8e2b 100644 Binary files a/fonts/RecMonoSemicasual/RecMonoSemicasual-Italic-1.085.ttf and b/fonts/RecCodeSemicasual/RecCodeSemicasual-Italic-1.085.ttf differ diff --git a/fonts/RecMonoSemicasual/RecMonoSemicasual-Regular-1.085.ttf b/fonts/RecCodeSemicasual/RecCodeSemicasual-Regular-1.085.ttf similarity index 99% rename from fonts/RecMonoSemicasual/RecMonoSemicasual-Regular-1.085.ttf rename to fonts/RecCodeSemicasual/RecCodeSemicasual-Regular-1.085.ttf index 2957b7d..2f18ff2 100644 Binary files a/fonts/RecMonoSemicasual/RecMonoSemicasual-Regular-1.085.ttf and b/fonts/RecCodeSemicasual/RecCodeSemicasual-Regular-1.085.ttf differ diff --git a/premade-configs/casual.yaml b/premade-configs/casual.yaml index e4b4a77..31d06f8 100644 --- a/premade-configs/casual.yaml +++ b/premade-configs/casual.yaml @@ -1,8 +1,8 @@ -# Configuration for Rec Mono Casual +# Configuration for Rec Code Casual # Here as an example, or to tweak & use if you wish to -# See README for details. +# See the project README and top-level config.yaml for details. -Family Name: Casual +Family Name Suffix: Casual Fonts: Regular: diff --git a/premade-configs/duotone.yaml b/premade-configs/duotone.yaml index e081b37..5b3706c 100644 --- a/premade-configs/duotone.yaml +++ b/premade-configs/duotone.yaml @@ -1,8 +1,8 @@ -# Configuration for Rec Mono Duotone +# Configuration for Rec Code Duotone # Here as an example, or to tweak & use if you wish to -# See README for details. +# See the project README and top-level config.yaml for details. -Family Name: Duotone +Family Name Suffix: Duotone Fonts: Regular: diff --git a/premade-configs/linear.yaml b/premade-configs/linear.yaml index 03372de..5b4981b 100644 --- a/premade-configs/linear.yaml +++ b/premade-configs/linear.yaml @@ -1,8 +1,8 @@ -# Configuration for Rec Mono Linear +# Configuration for Rec Code Linear # Here as an example, or to tweak & use if you wish to -# See README for details. +# See the project README and top-level config.yaml for details. -Family Name: Linear +Family Name Suffix: Linear Fonts: Regular: diff --git a/premade-configs/sans-duo.yaml b/premade-configs/sans-duo.yaml new file mode 100644 index 0000000..a663169 --- /dev/null +++ b/premade-configs/sans-duo.yaml @@ -0,0 +1,40 @@ +# Configuration for Rec Code Sans Duo +# Here as an example, or to tweak & use if you wish to +# See the project README and top-level config.yaml for details. + +Family Name Suffix: Sans Duo + +Fonts: + Regular: + MONO: 0 + CASL: 0 + wght: 400 + slnt: 0 + CRSV: 0 + Italic: + MONO: 0 + CASL: 1 + wght: 400 + slnt: -10 + CRSV: 1 + Bold: + MONO: 0 + CASL: 0 + wght: 750 + slnt: 0 + CRSV: 0 + Bold Italic: + MONO: 0 + CASL: 1 + wght: 750 + slnt: -10 + CRSV: 1 + +Code Ligatures: True + +Features: +- ss03 # Simplified f +- ss05 # Simplified l +- ss08 # Serifless L and Z +- ss09 # Simplified 6 and 9 +- ss12 # Simplified @ \ No newline at end of file diff --git a/premade-configs/semicasual.yaml b/premade-configs/semicasual.yaml index 2126bdb..11a23e5 100644 --- a/premade-configs/semicasual.yaml +++ b/premade-configs/semicasual.yaml @@ -1,8 +1,8 @@ -# Configuration for Rec Mono SemiCasual +# Configuration for Rec Code SemiCasual # Here as an example, or to tweak & use if you wish to -# See README for details. +# See the project README and top-level config.yaml for details. -Family Name: Semicasual +Family Name Suffix: Semicasual Fonts: Regular: diff --git a/scripts/dlig2calt.py b/scripts/dlig2calt.py index 9eba945..da1281a 100644 --- a/scripts/dlig2calt.py +++ b/scripts/dlig2calt.py @@ -1,6 +1,6 @@ """ A script to change dlig features to calt features, - to make code ligatures on by default in Rec Mono for Code. + to make code ligatures on by default in Rec Code for Code. """ from fontTools import ttLib @@ -9,68 +9,123 @@ from fontTools.pens.ttGlyphPen import TTGlyphPen from argparse import ArgumentParser import pathops +import subprocess +import os +def simpleDlig2calt(fontPath, inplace=False): + """ + A simple way to change a "dlig" feature to "calt." -# codeLigs = {} # probably not needed + Assumes the fontPath hasn’t already been converted to a TTX file, + as that would confuse the variables below. + """ -def dlig2calt(fontPath, inplace=False): + # convert font’s GSUB table to a TTX file + subprocess.run(["ttx", "-t", "GSUB", fontPath]) + + # make the path for a ttx + ttxPath = fontPath.replace(".ttf",".ttx") + + # Read in the TTX file + with open(ttxPath, 'r', encoding='utf-8') as file: + ttxData = file.read() + + # Replace the target string to update the dlig feature tags to calt feature tags + ttxData = ttxData.replace('"dlig"', '"calt"') + + # Write the TTX file out again + with open(ttxPath, 'w', encoding='utf-8') as file: + file.write(ttxData) + + # merge TTX back into font: + # ttx -m fontname.ttf fontname.ttx + + # save font + if inplace: + subprocess.run(["ttx", "-f", "-m", fontPath, ttxPath]) + print("\nCode ligatures are now under the calt feature and on by default.\n") + else: + newFontPath = fontPath.replace('.ttf','.calt_ligs.ttf') + subprocess.run(["ttx", "-o", newFontPath, "-m", fontPath, ttxPath]) + print("Saved font with feature 'dlig' changed to 'calt' at ", newFontPath) + + # clean up the temporary TTX file + os.remove(ttxPath) + + +def makeCodeLigsMonospace(fontPath, inplace=False): + """ + Takes code ligatures with different widths, and makes them all exactly one monospace character wide. + + The extra width goes over the left bound, and the space is made up for by a newly-created "LIG" glyph. + """ font = ttLib.TTFont(fontPath) - unitWidth = font['hmtx']['space'][0] # 600 for most monospace fonts w/ UPM=1000 + # set unit width / tabular width ... assumes the "=" symbol will have a tabular width for any code font + # 600 for most monospace fonts w/ UPM=1000 + unitWidth = font['hmtx']['equal'][0] - # make "LIG" glyph + # create the "LIG" glyph to fill in gaps for code ligatures made into single-unit-wide glyphs font['glyf'].__setitem__('LIG', font['glyf']['space']) - font['hmtx'].__setitem__('LIG', font['hmtx']['space']) + # set /LIG glyph width to /equal width, not /space, to allow proportional fonts + font['glyf']._setCoordinates('LIG', [(0,0), (600,0), (0, 0), (0, 0)], font['hmtx'].metrics) + + # update code ligature widths to be single units with left overhang for glyphName in font.getGlyphNames(): if font['hmtx'][glyphName][0] > unitWidth: - # set width to space (e.g. 600), then offset left side to be negative - oldWidth = font['hmtx'][glyphName][0] - oldLSB = font['hmtx'][glyphName][1] - widthDiff = oldWidth - unitWidth - newLSB = oldLSB - widthDiff - font['hmtx'].__setitem__(glyphName, (unitWidth, newLSB)) + # only apply this to code ligatures... leave other glyphs as-is, in case they are intentionally proportional (i.e. MONO != 1) + if ".code" in glyphName: - # Adjust coordinates in glyf table - coords = font['glyf']._getCoordinatesAndControls(glyphName, font['hmtx'].metrics)[0] - phantoms = font['glyf']._getPhantomPoints(glyphName, font['hmtx'].metrics) + # set width to equal sign (e.g. 600), then offset left side to be negative + oldWidth = font['hmtx'][glyphName][0] + oldLSB = font['hmtx'][glyphName][1] + widthDiff = oldWidth - unitWidth + newLSB = oldLSB - widthDiff + font['hmtx'].__setitem__(glyphName, (unitWidth, newLSB)) - # take off last four items of coords to allow adjusted phantoms to be handled separately, then combined - coords = coords[:len(coords)-4] + # Adjust coordinates in glyf table + coords = font['glyf']._getCoordinatesAndControls(glyphName, font['hmtx'].metrics)[0] + phantoms = font['glyf']._getPhantomPoints(glyphName, font['hmtx'].metrics) - adjustedCoords = [(x-widthDiff, y) for x, y in coords] - adjustedPhantoms = [(0,0), (600,0), phantoms[-2], phantoms[-1]] + # take off last four items of coords to allow adjusted phantoms to be handled separately, then combined + coords = coords[:len(coords)-4] - newCoords = adjustedCoords+adjustedPhantoms - font['glyf']._setCoordinates(glyphName, newCoords, font['hmtx'].metrics) + adjustedCoords = [(x-widthDiff, y) for x, y in coords] + adjustedPhantoms = [(0,0), (600,0), phantoms[-2], phantoms[-1]] + newCoords = adjustedCoords+adjustedPhantoms + font['glyf']._setCoordinates(glyphName, newCoords, font['hmtx'].metrics) # add new feature code, using calt rather than dlig builder.addOpenTypeFeatures(font,"font-data/features/calt-generated--code_fonts_only.fea") - # save font if inplace: font.save(fontPath) print("\nCode ligatures are now on by default.\n") else: - newPath = fontPath.replace('.ttf','.calt_ligs.ttf') - font.save(newPath) - print("Saved font with feature 'dlig' changed to 'calt' at ", newPath) + fontPath = fontPath.replace('.ttf','.calt_ligs.ttf') + font.save(fontPath) + print("Saved font with feature 'dlig' changed to 'calt' at ", fontPath) def main(): - description = "Change dlig features to calt features." - parser = ArgumentParser(description=description) - parser.add_argument('font', nargs=1) - parser.add_argument('--inplace', action='store_true') - args = parser.parse_args() - - dlig2calt(args.font[0], args.inplace) + description = "Change dlig features to calt features." + parser = ArgumentParser(description=description) + parser.add_argument('font', nargs=1) + parser.add_argument('--inplace', action='store_true') + parser.add_argument('--mono', '-m', action='store_true') + args = parser.parse_args() + + if args.mono: + makeCodeLigsMonospace(args.font[0], args.inplace) + else: + simpleDlig2calt(args.font[0], args.inplace) if __name__ == '__main__': diff --git a/scripts/instantiate-code-fonts.py b/scripts/instantiate-code-fonts.py index f9fe233..b944328 100644 --- a/scripts/instantiate-code-fonts.py +++ b/scripts/instantiate-code-fonts.py @@ -20,7 +20,7 @@ from fontTools.varLib import instancer from fontTools.varLib.instancer import OverlapMode from opentype_feature_freezer import cli as pyftfeatfreeze -from dlig2calt import dlig2calt +from dlig2calt import (makeCodeLigsMonospace, simpleDlig2calt) from mergePowerlineFont import mergePowerlineFont from ttfautohint.options import USER_OPTIONS as ttfautohint_options @@ -76,8 +76,8 @@ def setFontNameID(font, ID, newName): oldName = "Recursive" def splitFont( - outputDirectory=f"RecMono{fontOptions['Family Name']}".replace(" ",""), - newName="Rec Mono", + outputDirectory=f"RecCode{fontOptions['Family Name Suffix']}".replace(" ",""), + newName="Rec Code", ): # access font as TTFont object @@ -108,7 +108,7 @@ def splitFont( currentPsName = getFontNameID(instanceFont, 6) newPsName = (currentPsName\ .replace("Sans", "")\ - .replace(oldName,newName.replace(" ", "") + fontOptions['Family Name'].replace(" ",""))\ + .replace(oldName,newName.replace(" ", "") + fontOptions['Family Name Suffix'].replace(" ",""))\ .replace("LinearLight", instance.replace(" ", ""))) setFontNameID(instanceFont, 6, newPsName) @@ -116,7 +116,7 @@ def splitFont( currentFullName = getFontNameID(instanceFont, 4) newFullName = (currentFullName\ .replace("Sans", "")\ - .replace(oldName, newName + " " + fontOptions['Family Name'])\ + .replace(oldName, newName + " " + fontOptions['Family Name Suffix'])\ .replace(" Linear Light", instance))\ .replace(" Regular", "") setFontNameID(instanceFont, 4, newFullName) @@ -138,7 +138,7 @@ def splitFont( setFontNameID(instanceFont, 16, newFamName) newFileName = fontFileName\ - .replace(oldName, (newName + fontOptions['Family Name']).replace(" ", ""))\ + .replace(oldName, (newName + fontOptions['Family Name Suffix']).replace(" ", ""))\ .replace("_VF_", "-" + instance.replace(" ", "") + "-") # make dir for new fonts @@ -155,12 +155,19 @@ def splitFont( # ------------------------------------------------------- # Code font special stuff in post processing - # freeze in rvrn & stylistic set features with pyftfeatfreeze - pyftfeatfreeze.main([f"--features=rvrn,{','.join(fontOptions['Features'])}", outputPath, outputPath]) + if fontOptions["Fonts"][instance]["MONO"] == 1: + # freeze in rvrn & stylistic set features with pyftfeatfreeze + pyftfeatfreeze.main([f"--features=rvrn,{','.join(fontOptions['Features'])}", outputPath, outputPath]) + else: + # if font is proportional, also keep the kern feature for kerning + pyftfeatfreeze.main([f"--features=rvrn,{','.join(fontOptions['Features'])},kern", outputPath, outputPath]) - if fontOptions['Code Ligatures']: + if fontOptions['Code Ligatures'] and fontOptions["Fonts"][instance]["MONO"] == 1: # swap dlig2calt to make code ligatures work in old code editor apps - dlig2calt(outputPath, inplace=True) + makeCodeLigsMonospace(outputPath, inplace=True) + + if fontOptions['Code Ligatures'] and fontOptions["Fonts"][instance]["MONO"] < 1: + simpleDlig2calt(outputPath, inplace=True) # if casual, merge with casual PL; if linear merge w/ Linear PL if fontOptions["Fonts"][instance]["CASL"] > 0.5: @@ -181,14 +188,16 @@ def splitFont( except KeyError: print("Font has no STAT table.") - # In the post table, isFixedPitched flag must be set in the code fonts - monoFont['post'].isFixedPitch = 1 + if fontOptions["Fonts"][instance]["MONO"] == 1: + + # In the post table, isFixedPitched flag must be set in the code fonts + monoFont['post'].isFixedPitch = 1 - # In the OS/2 table Panose bProportion must be set to 9 - monoFont["OS/2"].panose.bProportion = 9 + # In the OS/2 table Panose bProportion must be set to 9 + monoFont["OS/2"].panose.bProportion = 9 - # Also in the OS/2 table, xAvgCharWidth should be set to 600 rather than 612 (612 is an average of glyphs in the "Mono" files which include wide ligatures). - monoFont["OS/2"].xAvgCharWidth = 600 + # Also in the OS/2 table, xAvgCharWidth should be set to 600 rather than 612 (612 is an average of glyphs in the "Mono" files which include wide ligatures). + monoFont["OS/2"].xAvgCharWidth = 600 # Code to fix fsSelection adapted from: # https://github.com/googlefonts/gftools/blob/a0b516d71f9e7988dfa45af2d0822ec3b6972be4/Lib/gftools/fix.py#L764 diff --git a/scripts/mergePowerlineFont.py b/scripts/mergePowerlineFont.py index ac9428e..6096c2b 100644 --- a/scripts/mergePowerlineFont.py +++ b/scripts/mergePowerlineFont.py @@ -1,5 +1,5 @@ """ - Script to include PowerLine glyphs by merging powerline-only TTFs with Rec Mono TTFs. + Script to include PowerLine glyphs by merging powerline-only TTFs with Rec Code TTFs. More background at https://github.com/arrowtype/recursive/issues/351 Work in progress.