Add support for Google CBLC/CBDT color bitmaps
This commit is contained in:
parent
c33b0a22ef
commit
b9ba775413
@ -42,7 +42,11 @@ When using TTX from the command line there are a bunch of extra options, these a
|
|||||||
The following tables are currently supported:
|
The following tables are currently supported:
|
||||||
<BLOCKQUOTE><TT>
|
<BLOCKQUOTE><TT>
|
||||||
<!-- begin table list -->
|
<!-- begin table list -->
|
||||||
|
<<<<<<< HEAD
|
||||||
BASE, CFF, DSIG, EBDT, EBLC, GDEF, GMAP, GPKG, GPOS, GSUB, JSTF, LTSH, META, OS/2, SING, TSI0, TSI1, TSI2, TSI3, TSI5, TSIB, TSID, TSIJ, TSIP, TSIS, TSIV, VORG, cmap, cvt, fpgm, gasp, glyf, hdmx, head, hhea, hmtx, kern, loca, maxp, name, post, prep, vhea and vmtx
|
BASE, CFF, DSIG, EBDT, EBLC, GDEF, GMAP, GPKG, GPOS, GSUB, JSTF, LTSH, META, OS/2, SING, TSI0, TSI1, TSI2, TSI3, TSI5, TSIB, TSID, TSIJ, TSIP, TSIS, TSIV, VORG, cmap, cvt, fpgm, gasp, glyf, hdmx, head, hhea, hmtx, kern, loca, maxp, name, post, prep, vhea and vmtx
|
||||||
|
=======
|
||||||
|
BASE, CBDT, CBLC, CFF, COLR, CPAL, DSIG, EBDT, EBLC, GDEF, GMAP, GPKG, GPOS, GSUB, JSTF, LTSH, META, OS/2, SING, TSI0, TSI1, TSI2, TSI3, TSI5, TSIB, TSID, TSIJ, TSIP, TSIS, TSIV, VORG, cmap, cvt, fpgm, gasp, glyf, hdmx, head, hhea, hmtx, kern, loca, maxp, name, post, prep, vhea and vmtx
|
||||||
|
>>>>>>> 305bad8... Add support for Google CBLC/CBDT color bitmaps
|
||||||
<!-- end table list -->
|
<!-- end table list -->
|
||||||
</TT></BLOCKQUOTE>
|
</TT></BLOCKQUOTE>
|
||||||
Other tables are dumped as hexadecimal data.
|
Other tables are dumped as hexadecimal data.
|
||||||
|
88
Lib/fontTools/ttLib/tables/C_B_D_T_.py
Normal file
88
Lib/fontTools/ttLib/tables/C_B_D_T_.py
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
|
||||||
|
import E_B_D_T_
|
||||||
|
import string
|
||||||
|
import struct
|
||||||
|
import sstruct
|
||||||
|
from BitmapGlyphMetrics import BigGlyphMetrics, bigGlyphMetricsFormat, SmallGlyphMetrics, smallGlyphMetricsFormat
|
||||||
|
from E_B_D_T_ import BitmapGlyph, BitmapPlusSmallMetricsMixin, BitmapPlusBigMetricsMixin
|
||||||
|
|
||||||
|
class table_C_B_D_T_(E_B_D_T_.table_E_B_D_T_):
|
||||||
|
|
||||||
|
# Change the data locator table being referenced.
|
||||||
|
locatorName = 'CBLC'
|
||||||
|
|
||||||
|
# Modify the format class accessor for color bitmap use.
|
||||||
|
def getImageFormatClass(self, imageFormat):
|
||||||
|
try:
|
||||||
|
return E_B_D_T_.table_E_B_D_T_.getImageFormatClass(self, imageFormat)
|
||||||
|
except KeyError:
|
||||||
|
return cbdt_bitmap_classes[imageFormat]
|
||||||
|
|
||||||
|
# Helper method for removing export features not supported by color bitmaps.
|
||||||
|
# Write data in the parent class will default to raw if an option is unsupported.
|
||||||
|
def _removeUnsupportedForColor(dataFunctions):
|
||||||
|
dataFunctions = dict(dataFunctions)
|
||||||
|
del dataFunctions['row']
|
||||||
|
return dataFunctions
|
||||||
|
|
||||||
|
class ColorBitmapGlyph(BitmapGlyph):
|
||||||
|
|
||||||
|
fileExtension = '.png'
|
||||||
|
xmlDataFunctions = _removeUnsupportedForColor(BitmapGlyph.xmlDataFunctions)
|
||||||
|
|
||||||
|
class cbdt_bitmap_format_17(BitmapPlusSmallMetricsMixin, ColorBitmapGlyph):
|
||||||
|
|
||||||
|
def decompile(self):
|
||||||
|
self.metrics = SmallGlyphMetrics()
|
||||||
|
dummy, data = sstruct.unpack2(smallGlyphMetricsFormat, self.data, self.metrics)
|
||||||
|
(dataLen,) = struct.unpack(">L", data[:4])
|
||||||
|
data = data[4:]
|
||||||
|
|
||||||
|
# For the image data cut it to the size specified by dataLen.
|
||||||
|
assert dataLen <= len(data), "Data overun in format 17"
|
||||||
|
self.imageData = data[:dataLen]
|
||||||
|
|
||||||
|
def compile(self, ttFont):
|
||||||
|
dataList = []
|
||||||
|
dataList.append(sstruct.pack(smallGlyphMetricsFormat, self.metrics))
|
||||||
|
dataList.append(struct.pack(">L", len(self.imageData)))
|
||||||
|
dataList.append(self.imageData)
|
||||||
|
return string.join(dataList, "")
|
||||||
|
|
||||||
|
class cbdt_bitmap_format_18(BitmapPlusBigMetricsMixin, ColorBitmapGlyph):
|
||||||
|
|
||||||
|
def decompile(self):
|
||||||
|
self.metrics = BigGlyphMetrics()
|
||||||
|
dummy, data = sstruct.unpack2(bigGlyphMetricsFormat, self.data, self.metrics)
|
||||||
|
(dataLen,) = struct.unpack(">L", data[:4])
|
||||||
|
data = data[4:]
|
||||||
|
|
||||||
|
# For the image data cut it to the size specified by dataLen.
|
||||||
|
assert dataLen <= len(data), "Data overun in format 18"
|
||||||
|
self.imageData = data[:dataLen]
|
||||||
|
|
||||||
|
def compile(self, ttFont):
|
||||||
|
dataList = []
|
||||||
|
dataList.append(sstruct.pack(bigGlyphMetricsFormat, self.metrics))
|
||||||
|
dataList.append(struct.pack(">L", len(self.imageData)))
|
||||||
|
dataList.append(self.imageData)
|
||||||
|
return string.join(dataList, "")
|
||||||
|
|
||||||
|
class cbdt_bitmap_format_19(ColorBitmapGlyph):
|
||||||
|
|
||||||
|
def decompile(self):
|
||||||
|
(dataLen,) = struct.unpack(">L", self.data[:4])
|
||||||
|
data = self.data[4:]
|
||||||
|
|
||||||
|
assert dataLen <= len(data), "Data overun in format 19"
|
||||||
|
self.imageData = data[:dataLen]
|
||||||
|
|
||||||
|
def compile(self, ttFont):
|
||||||
|
return struct.pack(">L", len(self.imageData)) + self.imageData
|
||||||
|
|
||||||
|
# Dict for CBDT extended formats.
|
||||||
|
cbdt_bitmap_classes = {
|
||||||
|
17: cbdt_bitmap_format_17,
|
||||||
|
18: cbdt_bitmap_format_18,
|
||||||
|
19: cbdt_bitmap_format_19,
|
||||||
|
}
|
6
Lib/fontTools/ttLib/tables/C_B_L_C_.py
Normal file
6
Lib/fontTools/ttLib/tables/C_B_L_C_.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
import E_B_L_C_
|
||||||
|
|
||||||
|
class table_C_B_L_C_(E_B_L_C_.table_E_B_L_C_):
|
||||||
|
|
||||||
|
dependencies = ['CBDT']
|
@ -4,6 +4,8 @@ def _moduleFinderHint():
|
|||||||
dynamically imported. Generated by MetaTools/buildTableList.py.
|
dynamically imported. Generated by MetaTools/buildTableList.py.
|
||||||
"""
|
"""
|
||||||
import B_A_S_E_
|
import B_A_S_E_
|
||||||
|
import C_B_D_T_
|
||||||
|
import C_B_L_C_
|
||||||
import C_F_F_
|
import C_F_F_
|
||||||
import D_S_I_G_
|
import D_S_I_G_
|
||||||
import E_B_D_T_
|
import E_B_D_T_
|
||||||
|
Loading…
x
Reference in New Issue
Block a user