Add cmap format 4 3/1 table for Windows compatibility
parent
d453af82c9
commit
6c222b5917
2
Makefile
2
Makefile
|
@ -204,7 +204,7 @@ $(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) -f "$<" -o "$@" -d "$(COMPRESSED_DIR)" $(ADD_GLYPHS_FLAGS)
|
||||
$(PYTHON) $(ADD_GLYPHS) --add_cmap4 -f "$<" -o "$@" -d "$(COMPRESSED_DIR)" $(ADD_GLYPHS_FLAGS)
|
||||
|
||||
%.ttf: %.ttx
|
||||
@rm -f "$@"
|
||||
|
|
|
@ -339,14 +339,33 @@ def add_ligature_sequences(font, seqs, aliases):
|
|||
for seq, name in pairs:
|
||||
add_ligature(lookup, cmap, seq, name)
|
||||
|
||||
def add_cmap_format_4(font):
|
||||
"""Add cmap format 4 table for Windows support, based on the
|
||||
format 12 cmap."""
|
||||
|
||||
def update_font_data(font, seq_to_advance, vadvance, aliases):
|
||||
cmap = get_font_cmap(font)
|
||||
|
||||
newtable = CmapSubtable.newSubtable(4)
|
||||
newtable.platformID = 3
|
||||
newtable.platEncID = 1
|
||||
newtable.language = 0
|
||||
newtable.cmap = {}
|
||||
|
||||
# Format 4 only has unicode values 0x0000 to 0xFFFF
|
||||
for cp, name in cmap.items():
|
||||
if cp < 65535:
|
||||
newtable.cmap[cp] = name
|
||||
|
||||
font['cmap'].tables.append(newtable)
|
||||
|
||||
def update_font_data(font, seq_to_advance, vadvance, aliases, add_cmap4):
|
||||
"""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_aliases_to_cmap(font, aliases)
|
||||
add_ligature_sequences(font, seqs, aliases)
|
||||
|
||||
if(add_cmap4):
|
||||
add_cmap_format_4(font)
|
||||
|
||||
def apply_aliases(seq_dict, aliases):
|
||||
"""Aliases is a mapping from sequence to replacement sequence. We can use
|
||||
|
@ -362,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):
|
||||
def update_ttx(in_file, out_file, image_dirs, prefix, ext, aliases_file, add_cmap4):
|
||||
if ext != '.png':
|
||||
raise Exception('extension "%s" not supported' % ext)
|
||||
|
||||
|
@ -386,7 +405,7 @@ def update_ttx(in_file, out_file, image_dirs, prefix, ext, aliases_file):
|
|||
|
||||
vadvance = font['vhea'].advanceHeightMax if 'vhea' in font else lineheight
|
||||
|
||||
update_font_data(font, seq_to_advance, vadvance, aliases)
|
||||
update_font_data(font, seq_to_advance, vadvance, aliases, add_cmap4)
|
||||
|
||||
font.saveXML(out_file)
|
||||
|
||||
|
@ -409,11 +428,13 @@ def main():
|
|||
parser.add_argument(
|
||||
'-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')
|
||||
args = parser.parse_args()
|
||||
|
||||
update_ttx(
|
||||
args.in_file, args.out_file, args.image_dirs, args.prefix, args.ext,
|
||||
args.aliases)
|
||||
args.aliases, args.add_cmap4)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in New Issue