From 385846bb4f3de3b317fa3101a98d034ce6ca1fa7 Mon Sep 17 00:00:00 2001 From: Roel Nieskens Date: Tue, 3 Nov 2020 14:02:06 +0100 Subject: [PATCH] Add glyf table on the fly Instead of using a separate template, add_glyphs.py will add a `glyf` and `loca` table when requested via a flag. --- Makefile | 4 +- ...ColorEmoji_WindowsCompatible.tmpl.ttx.tmpl | 711 ------------------ add_glyphs.py | 41 +- 3 files changed, 24 insertions(+), 732 deletions(-) delete mode 100644 NotoColorEmoji_WindowsCompatible.tmpl.ttx.tmpl diff --git a/Makefile b/Makefile index 967a42f63..13f1717b0 100644 --- a/Makefile +++ b/Makefile @@ -203,8 +203,8 @@ $(COMPRESSED_DIR)/%.png: $(QUANTIZED_DIR)/%.png | check_tools $(COMPRESSED_DIR) $(EMOJI).tmpl.ttx: $(EMOJI).tmpl.ttx.tmpl $(ADD_GLYPHS) $(ALL_COMPRESSED_FILES) $(PYTHON) $(ADD_GLYPHS) -f "$<" -o "$@" -d "$(COMPRESSED_DIR)" $(ADD_GLYPHS_FLAGS) -$(EMOJI_WINDOWS).tmpl.ttx: $(EMOJI_WINDOWS).tmpl.ttx.tmpl $(ADD_GLYPHS) $(ALL_COMPRESSED_FILES) - $(PYTHON) $(ADD_GLYPHS) --add_cmap4 -f "$<" -o "$@" -d "$(COMPRESSED_DIR)" $(ADD_GLYPHS_FLAGS) +$(EMOJI_WINDOWS).tmpl.ttx: $(EMOJI).tmpl.ttx.tmpl $(ADD_GLYPHS) $(ALL_COMPRESSED_FILES) + $(PYTHON) $(ADD_GLYPHS) --add_cmap4 --add_glyf -f "$<" -o "$@" -d "$(COMPRESSED_DIR)" $(ADD_GLYPHS_FLAGS) %.ttf: %.ttx @rm -f "$@" diff --git a/NotoColorEmoji_WindowsCompatible.tmpl.ttx.tmpl b/NotoColorEmoji_WindowsCompatible.tmpl.ttx.tmpl deleted file mode 100644 index 76cfc57b9..000000000 --- a/NotoColorEmoji_WindowsCompatible.tmpl.ttx.tmpl +++ /dev/null @@ -1,711 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Copyright 2013 Google Inc. - - - Noto Color Emoji - - - Regular - - - Noto Color Emoji - - - Noto Color Emoji - - - Version 2.020;GOOG;noto-emoji:20200914:BETA - - - NotoColorEmoji - - - Noto is a trademark of Google Inc. - - - Google, Inc. - - - Google, Inc. - - - Color emoji font using CBDT glyph data. - - - http://www.google.com/get/noto/ - - - http://www.google.com/get/noto/ - - - This Font Software is licensed under the SIL Open Font License, Version 1.1. This Font Software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the SIL Open Font License for the specific language, permissions and limitations governing your use of this Font Software. - - - http://scripts.sil.org/OFL - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/add_glyphs.py b/add_glyphs.py index 23a3588ab..61b6f1100 100644 --- a/add_glyphs.py +++ b/add_glyphs.py @@ -18,9 +18,10 @@ import sys from fontTools import ttx from fontTools.ttLib.tables import otTables -from fontTools.ttLib import newTable from fontTools.pens.ttGlyphPen import TTGlyphPen from fontTools.ttLib.tables._c_m_a_p import CmapSubtable +from fontTools.ttLib.tables import _g_l_y_f +from fontTools.ttLib.tables import _l_o_c_a import add_emoji_gsub import add_aliases @@ -142,7 +143,7 @@ def get_font_cmap(font): return font['cmap'].tables[0].cmap -def add_glyph_data(font, seqs, seq_to_advance, vadvance): +def add_glyph_data(font, seqs, seq_to_advance, vadvance, add_glyf): """Add hmtx and GlyphOrder data for all sequences in seqs, and ensures there's a cmap entry for each single-codepoint sequence. Seqs not in seq_to_advance will get a zero advance.""" @@ -161,19 +162,20 @@ def add_glyph_data(font, seqs, seq_to_advance, vadvance): # # The added codepoints have no advance information, so will get a zero # advance. - # - # If a glyf table is present, empty glyphs will be added to ensure - # compatibility with systems requiring a glyf table, like Windows 10. cmap = get_font_cmap(font) hmtx = font['hmtx'].metrics vmtx = font['vmtx'].metrics - if 'glyf' in font: + + # Add glyf table so empty glyphs will be added to ensure compatibility + # with systems requiring a glyf table, like Windows 10. + if add_glyf: pen = TTGlyphPen(None) empty_glyph = pen.glyph() - glyf = font['glyf'] - else: - glyf = None + font['loca'] = _l_o_c_a.table__l_o_c_a() + font['glyf'] = glyf_table = _g_l_y_f.table__g_l_y_f() + glyf_table.glyphOrder = font.getGlyphOrder() + glyf_table.glyphs = {g:empty_glyph for g in glyf_table.glyphOrder} # We don't expect sequences to be in the glyphOrder, since we removed all the # single-cp sequences from it and don't expect it to already contain names @@ -198,13 +200,12 @@ def add_glyph_data(font, seqs, seq_to_advance, vadvance): if name not in reverseGlyphMap: font.glyphOrder.append(name) updatedGlyphOrder=True - if glyf is not None: - glyf[name] = empty_glyph + if add_glyf: + glyf_table[name] = empty_glyph if updatedGlyphOrder: delattr(font, '_reverseGlyphOrderDict') - def add_aliases_to_cmap(font, aliases): """Some aliases might map a single codepoint to some other sequence. These should map directly to the glyph for that sequence in the cmap. (Others will @@ -353,14 +354,14 @@ def add_cmap_format_4(font): newtable.language = 0 # Format 4 only has unicode values 0x0000 to 0xFFFF - newtable.cmap = newtable.cmap = {cp: name for cp, name in cmap.items() if cp <= 0xFFFF} + newtable.cmap = {cp: name for cp, name in cmap.items() if cp <= 0xFFFF} font['cmap'].tables.append(newtable) -def update_font_data(font, seq_to_advance, vadvance, aliases, add_cmap4): +def update_font_data(font, seq_to_advance, vadvance, aliases, add_cmap4, add_glyf): """Update the font's cmap, hmtx, GSUB, and GlyphOrder tables.""" seqs = get_all_seqs(font, seq_to_advance) - add_glyph_data(font, seqs, seq_to_advance, vadvance) + add_glyph_data(font, seqs, seq_to_advance, vadvance, add_glyf) add_aliases_to_cmap(font, aliases) add_ligature_sequences(font, seqs, aliases) if(add_cmap4): @@ -380,7 +381,7 @@ def apply_aliases(seq_dict, aliases): return usable_aliases -def update_ttx(in_file, out_file, image_dirs, prefix, ext, aliases_file, add_cmap4): +def update_ttx(in_file, out_file, image_dirs, prefix, ext, aliases_file, add_cmap4, add_glyf): if ext != '.png': raise Exception('extension "%s" not supported' % ext) @@ -404,7 +405,7 @@ def update_ttx(in_file, out_file, image_dirs, prefix, ext, aliases_file, add_cma vadvance = font['vhea'].advanceHeightMax if 'vhea' in font else lineheight - update_font_data(font, seq_to_advance, vadvance, aliases, add_cmap4) + update_font_data(font, seq_to_advance, vadvance, aliases, add_cmap4, add_glyf) font.saveXML(out_file) @@ -428,12 +429,14 @@ def main(): '-a', '--aliases', help='process alias table', const='emoji_aliases.txt', nargs='?', metavar='file') parser.add_argument( - '--add_cmap4', help='add cmap format 4', dest='add_cmap4', action='store_true') + '--add_cmap4', help='add cmap format 4 table', dest='add_cmap4', action='store_true') + parser.add_argument( + '--add_glyf', help='add glyf and loca tables', dest='add_glyf', action='store_true') args = parser.parse_args() update_ttx( args.in_file, args.out_file, args.image_dirs, args.prefix, args.ext, - args.aliases, args.add_cmap4) + args.aliases, args.add_cmap4, args.add_glyf) if __name__ == '__main__':