[subset] actually, ignore the width of emptied charstrings

basically, implies setting them to their defaultWidthX, which is the most efficient
way to store these (unnecessary) piece of data.
This commit is contained in:
Cosimo Lupo 2019-01-16 16:01:12 +00:00
parent 3e400c8828
commit 6b4474b2c4
No known key found for this signature in database
GPG Key ID: 59D54DB0C9976482

View File

@ -66,29 +66,25 @@ def closure_glyphs(self, s):
s.glyphs.update(components) s.glyphs.update(components)
decompose = components decompose = components
def _empty_charstring(font, glyphName, isCFF2, width=None): def _empty_charstring(font, glyphName, isCFF2, ignoreWidth=False):
c, fdSelectIndex = font.CharStrings.getItemAndSelector(glyphName) c, fdSelectIndex = font.CharStrings.getItemAndSelector(glyphName)
if isCFF2: if isCFF2 or ignoreWidth:
# CFF2 charstrings have no widths nor 'endchar' operators # CFF2 charstrings have no widths nor 'endchar' operators
c.decompile() c.decompile()
c.program = [] c.program = [] if isCFF2 else ['endchar']
return
if hasattr(font, 'FDArray') and font.FDArray is not None:
private = font.FDArray[fdSelectIndex].Private
else: else:
private = font.Private if hasattr(font, 'FDArray') and font.FDArray is not None:
dfltWdX = private.defaultWidthX private = font.FDArray[fdSelectIndex].Private
nmnlWdX = private.nominalWidthX else:
if width is None: private = font.Private
dfltWdX = private.defaultWidthX
nmnlWdX = private.nominalWidthX
pen = NullPen() pen = NullPen()
c.draw(pen) # this will set the charstring's width c.draw(pen) # this will set the charstring's width
width = c.width if c.width != dfltWdX:
else: c.program = [c.width - nmnlWdX, 'endchar']
c.decompile() else:
if width != dfltWdX: c.program = ['endchar']
c.program = [width - nmnlWdX, 'endchar']
else:
c.program = ['endchar']
@_add_method(ttLib.getTableClass('CFF ')) @_add_method(ttLib.getTableClass('CFF '))
def prune_pre_subset(self, font, options): def prune_pre_subset(self, font, options):
@ -118,7 +114,7 @@ def subset_glyphs(self, s):
if s.options.retain_gids: if s.options.retain_gids:
for g in s.glyphs_emptied: for g in s.glyphs_emptied:
_empty_charstring(font, g, isCFF2=cff.major > 1, width=0) _empty_charstring(font, g, isCFF2=cff.major > 1, ignoreWidth=True)
else: else:
# Load all glyphs # Load all glyphs
for g in font.charset: for g in font.charset: