diff options
author | Rasmus Andersson <rasmus@notion.se> | 2023-05-29 20:05:47 +0300 |
---|---|---|
committer | Rasmus Andersson <rasmus@notion.se> | 2023-05-29 20:05:51 +0300 |
commit | e12027c4c107731fd33823578fd7ca5107d38b8f (patch) | |
tree | d434280c67931a18bd613644ff2ab3c9441c6533 /misc | |
parent | a2d84eb0eaacc1330ab1353d89e79c88c9716ecc (diff) | |
download | inter-e12027c4c107731fd33823578fd7ca5107d38b8f.tar.xz |
Remove "Display" named-instances from variable font
A lot of software gets confused when there are named instances that differ
only by opsz. This change removes all "Display" instances from the fvar table
and makes opsz=32 the default, so that software without automatic opsz-to-size
mapping displays the "Display" styles instead of the text styles by default.
This is the same approach taken by Apple San Francisco Pro.
Closes #519
Diffstat (limited to 'misc')
-rw-r--r-- | misc/dist/help.txt | 39 | ||||
-rw-r--r-- | misc/dist/inter.css | 15 | ||||
-rw-r--r-- | misc/makezip2.sh | 29 | ||||
-rwxr-xr-x | misc/tools/fontinfo.py | 34 | ||||
-rw-r--r-- | misc/tools/gen-var-designspace.py | 68 |
5 files changed, 129 insertions, 56 deletions
diff --git a/misc/dist/help.txt b/misc/dist/help.txt index acc9f4de9..3d1e9b278 100644 --- a/misc/dist/help.txt +++ b/misc/dist/help.txt @@ -6,14 +6,13 @@ Contents: 1.2. Installing on Microsoft Windows 1.3. Installing on Ubuntu Linux 2. Using Inter in Web content - 3. Hinted TrueType fonts (Inter TrueType.ttc) + 3. Hinted TrueType fonts 4. Extras 5. License (can I use Inter for x?) File index: - Inter.ttc Complete font family (CFF1) - Inter Variable*.ttf Complete font family (Variable TrueType) - Inter TrueType.ttc Complete font family (TrueType, with TT hints) + Inter.ttc Complete font family "Inter" + Inter Variable*.ttf Complete font family "Inter Variable" Web/* Web fonts and CSS --------------------------------------------------------------------- @@ -21,7 +20,7 @@ File index: 1. Installing font files Inter fonts comes in two flavors: - Variable (Inter Variable*.ttf) and Static (Inter.ttc). + Variable (Inter Variable*.ttf) and Static (Inter.ttc) Variable fonts allow you to choose any weight and optical size in supported software. Variable fonts is a relatively recent new @@ -42,7 +41,8 @@ File index: 1. Open the "Font Book" application. 2. In the main menu, select "File" → "Add Fonts..." 3. Select "Inter.ttc", "Inter Variable.ttf" and - "Inter Variable Italic.ttf", then press "Open" + "Inter Variable Italic.ttf" + 4. Press the "Open" button Alternatively, if you prefer not to use Font Book, you can move or copy the font files directly into ~/Library/Fonts/ @@ -51,7 +51,7 @@ File index: 1.2. Installing on Microsoft Windows 1. Open the zip file you downloaded - 2. Select the files "Inter TrueType.ttc", "Inter Variable.ttf" and + 2. Select "Inter.ttc", "Inter Variable.ttf" and "Inter Variable Italic.ttf" 3. Right-click the selected files, choose "Install for all users" @@ -68,9 +68,6 @@ File index: "Inter Variable Italic.ttf" into your .fonts directory (cp Inter.ttc *.ttf ~/.fonts/) - If you prefer the look of Microsoft ClearType-style "hinted" fonts, - for step 2, install "Inter TrueType.ttc" (INSTEAD OF "Inter.ttc".) - You may have to restart apps and/or your window server session. --------------------------------------------------------------------- @@ -118,36 +115,22 @@ File index: --------------------------------------------------------------------- -3. Hinted TrueType fonts (Inter TrueType.ttc) +3. Hinted TrueType fonts - This distribution contains TrueType fonts with hints (the programs - needed by ClearType) in a separate font bundle "Inter TrueType.ttc" + This distribution contains TrueType fonts with hints in "Inter.ttc" Microsoft Windows uses a technology called ClearType which alters the shape of letters to increase sharpness, in particular for low- density displays. This requires a font to have little programs built into them, called TrueType hinting instructions, which lets ClearType knows how to alter each character. - The standard distribution of Inter doesn't contain such "hints" - since it is relatively rare (and the web fonts would grow much - larger if they did contain such hinting programs.) - Additionally, some people on Windows do not like the appearance of - ClearType and prefer non-hinted fonts. (Tip: You can customize - ClearType to your liking in Window's settings.) The variable font is currently not available with TrueType hints, only the traditional "static" font files are. This will hopefully change in a future release. - Important: DO NOT INSTALL BOTH VERSIONS! - - DO NOT install both "Inter.ttc" and "Inter TrueType.ttc". - DO install ONE OF those font files, - or else confusing, strange things might happen (conflicts.) - - Recap: - - If you want to make use of ClearType, install "Inter TrueType.ttc" - - If you do not want or need ClearType support, install "Inter.ttc" + Note that the web fonts does not contain hints to minimize file + size. You can get hinted web fonts from the "extras" distribution. --------------------------------------------------------------------- diff --git a/misc/dist/inter.css b/misc/dist/inter.css index e9da8bbed..028d7b522 100644 --- a/misc/dist/inter.css +++ b/misc/dist/inter.css @@ -8,20 +8,20 @@ font-weight: 100 900; font-display: swap; font-style: normal; - src: url("Inter.var.woff2?v=3.19") format("woff2-variations"), - url("Inter.var.woff2?v=3.19") format("woff2"); - src: url("Inter.var.woff2?v=3.19") format("woff2") tech("variations"); + src: url("InterVariable.woff2?v=3.19") format("woff2-variations"), + url("InterVariable.woff2?v=3.19") format("woff2"); + src: url("InterVariable.woff2?v=3.19") format("woff2") tech("variations"); } @font-face { font-family: "InterVar"; font-weight: 100 900; font-display: swap; font-style: italic; - src: url("Inter-Italic.var.woff2?v=3.19") format("woff2-variations"), - url("Inter-Italic.var.woff2?v=3.19") format("woff2"); - src: url("Inter-Italic.var.woff2?v=3.19") format("woff2") tech("variations"); + src: url("InterVariable-Italic.woff2?v=3.19") format("woff2-variations"), + url("InterVariable-Italic.woff2?v=3.19") format("woff2"); + src: url("InterVariable-Italic.woff2?v=3.19") format("woff2") tech("variations"); } -/* static fonts "Inter" */ +/* static fonts */ @font-face { font-family: "Inter"; font-style: normal; font-weight: 100; font-display: swap; src: url("Inter-Thin.woff2?v=3.19") format("woff2"); } @font-face { font-family: "Inter"; font-style: italic; font-weight: 100; font-display: swap; src: url("Inter-ThinItalic.woff2?v=3.19") format("woff2"); } @font-face { font-family: "Inter"; font-style: normal; font-weight: 200; font-display: swap; src: url("Inter-ExtraLight.woff2?v=3.19") format("woff2"); } @@ -40,7 +40,6 @@ @font-face { font-family: "Inter"; font-style: italic; font-weight: 800; font-display: swap; src: url("Inter-ExtraBoldItalic.woff2?v=3.19") format("woff2"); } @font-face { font-family: "Inter"; font-style: normal; font-weight: 900; font-display: swap; src: url("Inter-Black.woff2?v=3.19") format("woff2"); } @font-face { font-family: "Inter"; font-style: italic; font-weight: 900; font-display: swap; src: url("Inter-BlackItalic.woff2?v=3.19") format("woff2"); } -/* static fonts "InterDisplay" */ @font-face { font-family: "InterDisplay"; font-style: normal; font-weight: 100; font-display: swap; src: url("Inter-DisplayThin.woff2?v=3.19") format("woff2"); } @font-face { font-family: "InterDisplay"; font-style: italic; font-weight: 100; font-display: swap; src: url("Inter-DisplayThinItalic.woff2?v=3.19") format("woff2"); } @font-face { font-family: "InterDisplay"; font-style: normal; font-weight: 200; font-display: swap; src: url("Inter-DisplayExtraLight.woff2?v=3.19") format("woff2"); } diff --git a/misc/makezip2.sh b/misc/makezip2.sh index 9f8c17086..77c7817af 100644 --- a/misc/makezip2.sh +++ b/misc/makezip2.sh @@ -54,29 +54,32 @@ mkdir -p "$(dirname "$OUTFILE_ABS")" "$ZIPDIR" cp LICENSE.txt "$ZIPDIR/LICENSE.txt" if $OPT_EXTRAS; then - mkdir -p "$ZIPDIR/OTF" "$ZIPDIR/TTF" + mkdir -p "$ZIPDIR/OTF" "$ZIPDIR/TTF" "$ZIPDIR/Web with TrueType hints" - cp misc/dist/extras-readme.txt "$ZIPDIR/README.txt" - cp build/fonts/static/Inter-*.otf "$ZIPDIR/OTF/" & - cp build/fonts/static-hinted/Inter-*.ttf "$ZIPDIR/TTF/" & + cp misc/dist/extras-readme.txt "$ZIPDIR/README.txt" + cp build/fonts/static/Inter-*.otf "$ZIPDIR/OTF/" & + cp build/fonts/static-hinted/Inter-*.ttf "$ZIPDIR/TTF/" & + cp build/fonts/static-hinted/Inter-*.woff2 "$ZIPDIR/Web with TrueType hints/" & else mkdir -p "$ZIPDIR/Web" - cp misc/dist/help.txt "$ZIPDIR/help.txt" - cp build/fonts/static/Inter.ttc "$ZIPDIR/Inter.ttc" - cp build/fonts/static-hinted/Inter-truetype.ttc "$ZIPDIR/Inter TrueType.ttc" - cp build/fonts/var/InterV.var.ttf "$ZIPDIR/Inter Variable.ttf" - cp build/fonts/var/InterV-Italic.var.ttf "$ZIPDIR/Inter Variable Italic.ttf" + cp misc/dist/help.txt "$ZIPDIR/help.txt" + cp build/fonts/static/Inter.ttc "$ZIPDIR/Inter.ttc" + cp build/fonts/var/InterV.var.ttf "$ZIPDIR/Inter Variable.ttf" + cp build/fonts/var/InterV-Italic.var.ttf "$ZIPDIR/Inter Variable Italic.ttf" + cp build/fonts/static/Inter-*.woff2 "$ZIPDIR/Web/" & + cp build/fonts/var/Inter.var.woff2 "$ZIPDIR/Web/InterVariable.woff2" + cp build/fonts/var/Inter-Italic.var.woff2 "$ZIPDIR/Web/InterVariable-Italic.woff2" + cp misc/dist/inter.css "$ZIPDIR/Web/" - cp build/fonts/static/Inter-*.woff2 \ - build/fonts/var/Inter.var.woff2 \ - build/fonts/var/Inter-Italic.var.woff2 \ - misc/dist/inter.css "$ZIPDIR/Web/" & + . build/venv/bin/activate + python misc/tools/patch-version.py "$ZIPDIR/Web/inter.css" fi mkdir -p "$(dirname "$OUTFILE_ABS")" wait +rm -rf "$OUTFILE_ABS" pushd "$ZIPDIR" >/dev/null zip -q -X -r "$OUTFILE_ABS" * popd >/dev/null diff --git a/misc/tools/fontinfo.py b/misc/tools/fontinfo.py index 5f578f808..0a4565929 100755 --- a/misc/tools/fontinfo.py +++ b/misc/tools/fontinfo.py @@ -21,6 +21,7 @@ from fontTools.ttLib.tables._m_a_x_p import maxpFormat_0_5, maxpFormat_1_0_add from fontTools.ttLib.tables._p_o_s_t import postFormat from fontTools.ttLib.tables.O_S_2f_2 import OS2_format_1, OS2_format_2, OS2_format_5, panoseFormat from fontTools.ttLib.tables._m_e_t_a import table__m_e_t_a +import fontTools.ttLib.tables._t_r_a_k as t_r_a_k # from robofab.world import world, RFont, RGlyph, OpenFont, NewFont # from robofab.objects.objectsRF import RFont, RGlyph, OpenFont, NewFont, RContour @@ -296,7 +297,10 @@ def genFontInfo(fontpath, outputType, withGlyphs=True): version = v[0] if version.lower() == 'version': version = v[1] - version = '.'.join([str(int(v)) for v in version.split('.')]) + try: + version = '.'.join([str(int(v)) for v in version.split('.')]) + except: + version = nameDict['version'] info['version'] = version if outputType is not OUTPUT_TYPE_GLYPHLIST: @@ -447,11 +451,11 @@ def genFontInfo(fontpath, outputType, withGlyphs=True): if fsSelection & 0b0000000000001000: s.append('3: OUTLINED') if fsSelection & 0b0000000000010000: s.append('4: STRIKEOUT') if fsSelection & 0b0000000000100000: s.append('5: BOLD') - if fsSelection & 0b0000000010000000: s.append('6: REGULAR') - if fsSelection & 0b0000000100000000: s.append('7: USE_TYPO_METRICS') - if fsSelection & 0b0000001000000000: s.append('8: WWS') - if fsSelection & 0b0000010000000000: s.append('9: OBLIQUE') - os2['fsSelection_raw'] = fsSelection + if fsSelection & 0b0000000001000000: s.append('6: REGULAR') + if fsSelection & 0b0000000010000000: s.append('7: USE_TYPO_METRICS') + if fsSelection & 0b0000000100000000: s.append('8: WWS') + if fsSelection & 0b0000001000000000: s.append('9: OBLIQUE') + os2['fsSelection_raw'] = bin(fsSelection) os2['fsSelection'] = s @@ -464,9 +468,25 @@ def genFontInfo(fontpath, outputType, withGlyphs=True): v.decode('utf8') meta[k] = v except: - meta[k] = 'data:;base64,' + b64encode(v) + meta[k] = 'data:;base64,' + b64encode(v).decode('ascii') info['meta'] = meta + if 'trak' in tt: + # Apple-specific table, linking size to tracking values. + # https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6trak.html + trak = {} + table = tt['trak'] + for direction in ("horiz", "vert"): + dataName = direction + "Data" + trackData = getattr(table, dataName, t_r_a_k.TrackData()) + td = {} + for k, tableEntry in trackData.__dict__['_map'].items(): + td[k] = { "nameIndex": tableEntry.nameIndex } + for k2 in tableEntry.keys(): + td[k][str(k2)] = tableEntry[k2] + trak[dataName] = td + info['trak'] = trak + # rest of tables for tname in tt.keys(): if tname not in info: diff --git a/misc/tools/gen-var-designspace.py b/misc/tools/gen-var-designspace.py new file mode 100644 index 000000000..7b3e4b757 --- /dev/null +++ b/misc/tools/gen-var-designspace.py @@ -0,0 +1,68 @@ +import sys, argparse, re +from fontTools.designspaceLib import DesignSpaceDocument + + +WHITESPACE_RE = re.compile(r'\s+') + + +def remove_whitespace(s): + return WHITESPACE_RE.sub("", s) + + +def fixup_instances_text(designspace): + # makes the "text" (non-display) instances the default ones + i = len(designspace.instances) + while i > 0: + i -= 1 + instance = designspace.instances[i] + if instance.name.find('Inter Display') != -1: + del designspace.instances[i] + + +def fixup_instances_display(designspace): + # makes the display instances the default ones + i = len(designspace.instances) + while i > 0: + i -= 1 + instance = designspace.instances[i] + if instance.name.find('Inter Display') != -1: + if instance.styleName == 'Display': + instance.styleName = 'Regular' + else: + instance.styleName = instance.styleName.replace('Display ', '') + else: + del designspace.instances[i] + # change default opsz value + for a in designspace.axes: + if a.tag == "opsz": + a.default = a.maximum + break + + +def fixup_postscript_instance_names(designspace): + # make sure there are PostScript names assigned (fontmake does not create these) + psFamilyName = remove_whitespace(designspace.instances[0].familyName) + for instance in designspace.instances: + instance.postScriptFontName = psFamilyName + remove_whitespace(instance.styleName) + + +def main(argv): + ap = argparse.ArgumentParser(description= + 'Generate designspace file for variable font from generic designspace file') + ap.add_argument("input_designspace", help="Path to generic designspace file") + ap.add_argument("output_designspace", help="Path for output designspace file") + + args = ap.parse_args() + + designspace = DesignSpaceDocument.fromfile(args.input_designspace) + + # fixup_instances_text(designspace) + fixup_instances_display(designspace) + + fixup_postscript_instance_names(designspace) + + designspace.write(args.output_designspace) + + +if __name__ == '__main__': + main(sys.argv) |