[CFF2] Make recalcBBoxes work with CFF2 table
Add checks for CFF2 table next to CFF checks as applicable.
This commit is contained in:
parent
366c08a9d6
commit
09174b9129
@ -4,7 +4,7 @@ from fontTools.misc.fixedTools import floatToFixedToStr, strToFixedToFloat
|
|||||||
from fontTools.misc.textTools import safeEval, num2binary, binary2num
|
from fontTools.misc.textTools import safeEval, num2binary, binary2num
|
||||||
from fontTools.misc.timeTools import timestampFromString, timestampToString, timestampNow
|
from fontTools.misc.timeTools import timestampFromString, timestampToString, timestampNow
|
||||||
from fontTools.misc.timeTools import epoch_diff as mac_epoch_diff # For backward compat
|
from fontTools.misc.timeTools import epoch_diff as mac_epoch_diff # For backward compat
|
||||||
from fontTools.misc.arrayTools import intRect
|
from fontTools.misc.arrayTools import intRect, unionRect
|
||||||
from . import DefaultTable
|
from . import DefaultTable
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ headFormat = """
|
|||||||
|
|
||||||
class table__h_e_a_d(DefaultTable.DefaultTable):
|
class table__h_e_a_d(DefaultTable.DefaultTable):
|
||||||
|
|
||||||
dependencies = ['maxp', 'loca', 'CFF ']
|
dependencies = ['maxp', 'loca', 'CFF ', 'CFF2']
|
||||||
|
|
||||||
def decompile(self, data, ttFont):
|
def decompile(self, data, ttFont):
|
||||||
dummy, rest = sstruct.unpack2(headFormat, data, self)
|
dummy, rest = sstruct.unpack2(headFormat, data, self)
|
||||||
@ -65,6 +65,19 @@ class table__h_e_a_d(DefaultTable.DefaultTable):
|
|||||||
if 'CFF ' in ttFont:
|
if 'CFF ' in ttFont:
|
||||||
topDict = ttFont['CFF '].cff.topDictIndex[0]
|
topDict = ttFont['CFF '].cff.topDictIndex[0]
|
||||||
self.xMin, self.yMin, self.xMax, self.yMax = intRect(topDict.FontBBox)
|
self.xMin, self.yMin, self.xMax, self.yMax = intRect(topDict.FontBBox)
|
||||||
|
elif 'CFF2' in ttFont:
|
||||||
|
topDict = ttFont['CFF2'].cff.topDictIndex[0]
|
||||||
|
charStrings = topDict.CharStrings
|
||||||
|
fontBBox = None
|
||||||
|
for charString in charStrings.values():
|
||||||
|
bounds = charString.calcBounds(charStrings)
|
||||||
|
if bounds is not None:
|
||||||
|
if fontBBox is not None:
|
||||||
|
fontBBox = unionRect(fontBBox, bounds)
|
||||||
|
else:
|
||||||
|
fontBBox = bounds
|
||||||
|
if fontBBox is not None:
|
||||||
|
self.xMin, self.yMin, self.xMax, self.yMax = intRect(fontBBox)
|
||||||
if ttFont.recalcTimestamp:
|
if ttFont.recalcTimestamp:
|
||||||
self.modified = timestampNow()
|
self.modified = timestampNow()
|
||||||
data = sstruct.pack(headFormat, self)
|
data = sstruct.pack(headFormat, self)
|
||||||
|
@ -33,7 +33,7 @@ class table__h_h_e_a(DefaultTable.DefaultTable):
|
|||||||
|
|
||||||
# Note: Keep in sync with table__v_h_e_a
|
# Note: Keep in sync with table__v_h_e_a
|
||||||
|
|
||||||
dependencies = ['hmtx', 'glyf', 'CFF ']
|
dependencies = ['hmtx', 'glyf', 'CFF ', 'CFF2']
|
||||||
|
|
||||||
# OpenType spec renamed these, add aliases for compatibility
|
# OpenType spec renamed these, add aliases for compatibility
|
||||||
@property
|
@property
|
||||||
@ -52,7 +52,7 @@ class table__h_h_e_a(DefaultTable.DefaultTable):
|
|||||||
sstruct.unpack(hheaFormat, data, self)
|
sstruct.unpack(hheaFormat, data, self)
|
||||||
|
|
||||||
def compile(self, ttFont):
|
def compile(self, ttFont):
|
||||||
if ttFont.recalcBBoxes and (ttFont.isLoaded('glyf') or ttFont.isLoaded('CFF ')):
|
if ttFont.recalcBBoxes and (ttFont.isLoaded('glyf') or ttFont.isLoaded('CFF ') or ttFont.isLoaded('CFF2')):
|
||||||
self.recalc(ttFont)
|
self.recalc(ttFont)
|
||||||
self.tableVersion = fi2ve(self.tableVersion)
|
self.tableVersion = fi2ve(self.tableVersion)
|
||||||
return sstruct.pack(hheaFormat, self)
|
return sstruct.pack(hheaFormat, self)
|
||||||
@ -74,8 +74,11 @@ class table__h_h_e_a(DefaultTable.DefaultTable):
|
|||||||
# Calculate those.
|
# Calculate those.
|
||||||
g.recalcBounds(glyfTable)
|
g.recalcBounds(glyfTable)
|
||||||
boundsWidthDict[name] = g.xMax - g.xMin
|
boundsWidthDict[name] = g.xMax - g.xMin
|
||||||
elif 'CFF ' in ttFont:
|
elif 'CFF ' in ttFont or 'CFF2' in ttFont:
|
||||||
topDict = ttFont['CFF '].cff.topDictIndex[0]
|
if 'CFF ' in ttFont:
|
||||||
|
topDict = ttFont['CFF '].cff.topDictIndex[0]
|
||||||
|
else:
|
||||||
|
topDict = ttFont['CFF2'].cff.topDictIndex[0]
|
||||||
charStrings = topDict.CharStrings
|
charStrings = topDict.CharStrings
|
||||||
for name in ttFont.getGlyphOrder():
|
for name in ttFont.getGlyphOrder():
|
||||||
cs = charStrings[name]
|
cs = charStrings[name]
|
||||||
|
@ -32,13 +32,13 @@ class table__v_h_e_a(DefaultTable.DefaultTable):
|
|||||||
|
|
||||||
# Note: Keep in sync with table__h_h_e_a
|
# Note: Keep in sync with table__h_h_e_a
|
||||||
|
|
||||||
dependencies = ['vmtx', 'glyf', 'CFF ']
|
dependencies = ['vmtx', 'glyf', 'CFF ', 'CFF2']
|
||||||
|
|
||||||
def decompile(self, data, ttFont):
|
def decompile(self, data, ttFont):
|
||||||
sstruct.unpack(vheaFormat, data, self)
|
sstruct.unpack(vheaFormat, data, self)
|
||||||
|
|
||||||
def compile(self, ttFont):
|
def compile(self, ttFont):
|
||||||
if ttFont.recalcBBoxes and (ttFont.isLoaded('glyf') or ttFont.isLoaded('CFF ')):
|
if ttFont.recalcBBoxes and (ttFont.isLoaded('glyf') or ttFont.isLoaded('CFF ') or ttFont.isLoaded('CFF2')):
|
||||||
self.recalc(ttFont)
|
self.recalc(ttFont)
|
||||||
self.tableVersion = fi2ve(self.tableVersion)
|
self.tableVersion = fi2ve(self.tableVersion)
|
||||||
return sstruct.pack(vheaFormat, self)
|
return sstruct.pack(vheaFormat, self)
|
||||||
@ -60,8 +60,11 @@ class table__v_h_e_a(DefaultTable.DefaultTable):
|
|||||||
# Calculate those.
|
# Calculate those.
|
||||||
g.recalcBounds(glyfTable)
|
g.recalcBounds(glyfTable)
|
||||||
boundsHeightDict[name] = g.yMax - g.yMin
|
boundsHeightDict[name] = g.yMax - g.yMin
|
||||||
elif 'CFF ' in ttFont:
|
elif 'CFF ' in ttFont or 'CFF2' in ttFont:
|
||||||
topDict = ttFont['CFF '].cff.topDictIndex[0]
|
if 'CFF ' in ttFont:
|
||||||
|
topDict = ttFont['CFF '].cff.topDictIndex[0]
|
||||||
|
else:
|
||||||
|
topDict = ttFont['CFF2'].cff.topDictIndex[0]
|
||||||
charStrings = topDict.CharStrings
|
charStrings = topDict.CharStrings
|
||||||
for name in ttFont.getGlyphOrder():
|
for name in ttFont.getGlyphOrder():
|
||||||
cs = charStrings[name]
|
cs = charStrings[name]
|
||||||
|
@ -19,10 +19,10 @@
|
|||||||
<unitsPerEm value="1000"/>
|
<unitsPerEm value="1000"/>
|
||||||
<created value="Wed Mar 27 00:23:21 2019"/>
|
<created value="Wed Mar 27 00:23:21 2019"/>
|
||||||
<modified value="Wed Mar 27 00:23:21 2019"/>
|
<modified value="Wed Mar 27 00:23:21 2019"/>
|
||||||
<xMin value="0"/>
|
<xMin value="100"/>
|
||||||
<yMin value="0"/>
|
<yMin value="100"/>
|
||||||
<xMax value="0"/>
|
<xMax value="600"/>
|
||||||
<yMax value="0"/>
|
<yMax value="1000"/>
|
||||||
<macStyle value="00000000 00000000"/>
|
<macStyle value="00000000 00000000"/>
|
||||||
<lowestRecPPEM value="3"/>
|
<lowestRecPPEM value="3"/>
|
||||||
<fontDirectionHint value="2"/>
|
<fontDirectionHint value="2"/>
|
||||||
@ -35,10 +35,10 @@
|
|||||||
<ascent value="824"/>
|
<ascent value="824"/>
|
||||||
<descent value="200"/>
|
<descent value="200"/>
|
||||||
<lineGap value="0"/>
|
<lineGap value="0"/>
|
||||||
<advanceWidthMax value="0"/>
|
<advanceWidthMax value="600"/>
|
||||||
<minLeftSideBearing value="0"/>
|
<minLeftSideBearing value="0"/>
|
||||||
<minRightSideBearing value="0"/>
|
<minRightSideBearing value="200"/>
|
||||||
<xMaxExtent value="0"/>
|
<xMaxExtent value="400"/>
|
||||||
<caretSlopeRise value="1"/>
|
<caretSlopeRise value="1"/>
|
||||||
<caretSlopeRun value="0"/>
|
<caretSlopeRun value="0"/>
|
||||||
<caretOffset value="0"/>
|
<caretOffset value="0"/>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user