[merge] Move more code to merge.cmap
This commit is contained in:
parent
3bb1c5b58f
commit
8ee5f26731
@ -68,7 +68,7 @@ class Merger(object):
|
|||||||
#
|
#
|
||||||
fonts = [ttLib.TTFont(fontfile) for fontfile in fontfiles]
|
fonts = [ttLib.TTFont(fontfile) for fontfile in fontfiles]
|
||||||
glyphOrders = [font.getGlyphOrder() for font in fonts]
|
glyphOrders = [font.getGlyphOrder() for font in fonts]
|
||||||
megaGlyphOrder = self._mergeGlyphOrders(glyphOrders)
|
megaGlyphOrder = computeMegaGlyphOrder(self, glyphOrders)
|
||||||
|
|
||||||
# Take first input file sfntVersion
|
# Take first input file sfntVersion
|
||||||
sfntVersion = fonts[0].sfntVersion
|
sfntVersion = fonts[0].sfntVersion
|
||||||
@ -99,7 +99,7 @@ class Merger(object):
|
|||||||
self.fonts = fonts
|
self.fonts = fonts
|
||||||
self.duplicateGlyphsPerFont = [{} for _ in fonts]
|
self.duplicateGlyphsPerFont = [{} for _ in fonts]
|
||||||
|
|
||||||
compute_mega_cmap(self, [font['cmap'] for font in fonts])
|
computeMegaCmap(self, [font['cmap'] for font in fonts])
|
||||||
|
|
||||||
allTags = reduce(set.union, (list(font.keys()) for font in fonts), set())
|
allTags = reduce(set.union, (list(font.keys()) for font in fonts), set())
|
||||||
allTags.remove('GlyphOrder')
|
allTags.remove('GlyphOrder')
|
||||||
@ -129,22 +129,6 @@ class Merger(object):
|
|||||||
|
|
||||||
return mega
|
return mega
|
||||||
|
|
||||||
def _mergeGlyphOrders(self, glyphOrders):
|
|
||||||
"""Modifies passed-in glyphOrders to reflect new glyph names.
|
|
||||||
Returns glyphOrder for the merged font."""
|
|
||||||
mega = {}
|
|
||||||
for glyphOrder in glyphOrders:
|
|
||||||
for i,glyphName in enumerate(glyphOrder):
|
|
||||||
if glyphName in mega:
|
|
||||||
n = mega[glyphName]
|
|
||||||
while (glyphName + "#" + repr(n)) in mega:
|
|
||||||
n += 1
|
|
||||||
mega[glyphName] = n
|
|
||||||
glyphName += "#" + repr(n)
|
|
||||||
glyphOrder[i] = glyphName
|
|
||||||
mega[glyphName] = 1
|
|
||||||
return list(mega.keys())
|
|
||||||
|
|
||||||
def _renameCFFCharStrings(self, glyphOrder, cffTable):
|
def _renameCFFCharStrings(self, glyphOrder, cffTable):
|
||||||
"""Rename topDictIndex charStrings based on glyphOrder."""
|
"""Rename topDictIndex charStrings based on glyphOrder."""
|
||||||
td = cffTable.cff.topDictIndex[0]
|
td = cffTable.cff.topDictIndex[0]
|
||||||
|
@ -279,7 +279,7 @@ def merge(self, m, tables):
|
|||||||
|
|
||||||
# TODO Handle format=14.
|
# TODO Handle format=14.
|
||||||
if not hasattr(m, 'cmap'):
|
if not hasattr(m, 'cmap'):
|
||||||
compute_mega_cmap(m, tables)
|
computeMegaCmap(m, tables)
|
||||||
cmap = m.cmap
|
cmap = m.cmap
|
||||||
|
|
||||||
cmapBmpOnly = {uni: gid for uni,gid in cmap.items() if uni <= 0xFFFF}
|
cmapBmpOnly = {uni: gid for uni,gid in cmap.items() if uni <= 0xFFFF}
|
||||||
|
@ -10,6 +10,23 @@ import logging
|
|||||||
log = logging.getLogger("fontTools.merge")
|
log = logging.getLogger("fontTools.merge")
|
||||||
|
|
||||||
|
|
||||||
|
def computeMegaGlyphOrder(merger, glyphOrders):
|
||||||
|
"""Modifies passed-in glyphOrders to reflect new glyph names.
|
||||||
|
Returns glyphOrder for the merged font."""
|
||||||
|
mega = {}
|
||||||
|
for glyphOrder in glyphOrders:
|
||||||
|
for i,glyphName in enumerate(glyphOrder):
|
||||||
|
if glyphName in mega:
|
||||||
|
n = mega[glyphName]
|
||||||
|
while (glyphName + "#" + repr(n)) in mega:
|
||||||
|
n += 1
|
||||||
|
mega[glyphName] = n
|
||||||
|
glyphName += "#" + repr(n)
|
||||||
|
glyphOrder[i] = glyphName
|
||||||
|
mega[glyphName] = 1
|
||||||
|
return list(mega.keys())
|
||||||
|
|
||||||
|
|
||||||
def _glyphsAreSame(glyphSet1, glyphSet2, glyph1, glyph2,
|
def _glyphsAreSame(glyphSet1, glyphSet2, glyph1, glyph2,
|
||||||
advanceTolerance=.05,
|
advanceTolerance=.05,
|
||||||
advanceToleranceEmpty=.20):
|
advanceToleranceEmpty=.20):
|
||||||
@ -40,7 +57,7 @@ class CmapUnicodePlatEncodings:
|
|||||||
FullRepertoire = {(12, 3, 10), (12, 0, 4), (12, 0, 6)}
|
FullRepertoire = {(12, 3, 10), (12, 0, 4), (12, 0, 6)}
|
||||||
|
|
||||||
|
|
||||||
def compute_mega_cmap(merger, tables):
|
def computeMegaCmap(merger, tables):
|
||||||
# TODO Handle format=14.
|
# TODO Handle format=14.
|
||||||
# Only merge format 4 and 12 Unicode subtables, ignores all other subtables
|
# Only merge format 4 and 12 Unicode subtables, ignores all other subtables
|
||||||
# If there is a format 12 table for a font, ignore the format 4 table of it
|
# If there is a format 12 table for a font, ignore the format 4 table of it
|
||||||
|
Loading…
x
Reference in New Issue
Block a user