Support 'ltag' table for IETF BCP-47 language tags

Resolves #226
This commit is contained in:
Sascha Brawer 2015-04-13 23:37:06 -07:00 committed by Behdad Esfahbod
parent 7c9ab300c2
commit dc8a66956a
3 changed files with 52 additions and 1 deletions

View File

@ -42,7 +42,7 @@ When using TTX from the command line there are a bunch of extra options, these a
The following tables are currently supported:
<BLOCKQUOTE><TT>
<!-- begin table list -->
BASE, CBDT, CBLC, CFF, COLR, CPAL, DSIG, EBDT, EBLC, FFTM, GDEF, GMAP, GPKG, GPOS, GSUB, JSTF, LTSH, MATH, META, OS/2, SING, SVG, TSI0, TSI1, TSI2, TSI3, TSI5, TSIB, TSID, TSIJ, TSIP, TSIS, TSIV, VDMX, VORG, cmap, cvt, feat, fpgm, fvar, gasp, glyf, hdmx, head, hhea, hmtx, kern, loca, maxp, name, post, prep, sbix, vhea and vmtx
BASE, CBDT, CBLC, CFF, COLR, CPAL, DSIG, EBDT, EBLC, FFTM, GDEF, GMAP, GPKG, GPOS, GSUB, JSTF, LTSH, MATH, META, OS/2, SING, SVG, TSI0, TSI1, TSI2, TSI3, TSI5, TSIB, TSID, TSIJ, TSIP, TSIS, TSIV, VDMX, VORG, cmap, cvt, feat, fpgm, fvar, gasp, glyf, hdmx, head, hhea, hmtx, kern, loca, ltag, maxp, name, post, prep, sbix, vhea and vmtx
<!-- end table list -->
</TT></BLOCKQUOTE>
Other tables are dumped as hexadecimal data.

View File

@ -56,6 +56,7 @@ def _moduleFinderHint():
from . import _h_m_t_x
from . import _k_e_r_n
from . import _l_o_c_a
from . import _l_t_a_g
from . import _m_a_x_p
from . import _n_a_m_e
from . import _p_o_s_t

View File

@ -0,0 +1,50 @@
from __future__ import print_function, division, absolute_import
from fontTools.misc.py23 import *
from fontTools.misc.textTools import safeEval
from . import DefaultTable
import struct
# https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6ltag.html
class table__l_t_a_g(DefaultTable.DefaultTable):
def decompile(self, data, ttFont):
self.version, self.flags, numTags = struct.unpack(">LLL", data[:12])
assert self.version == 1
self.tags = []
for i in range(numTags):
pos = 12 + i * 4
offset, length = struct.unpack(">HH", data[pos:pos+4])
tag = data[offset:offset+length]
self.tags.append(tag)
def compile(self, ttFont):
dataList = [struct.pack(">LLL", self.version, self.flags, len(self.tags))]
stringPool = ""
for tag in self.tags:
offset = stringPool.find(tag)
if offset < 0:
offset = len(stringPool)
stringPool = stringPool + tag
offset = offset + 12 + len(self.tags) * 4
dataList.append(struct.pack(">HH", offset, len(tag)))
dataList.append(stringPool)
return bytesjoin(dataList)
def toXML(self, writer, ttFont):
writer.simpletag("version", value=self.version)
writer.newline()
writer.simpletag("flags", value=self.flags)
writer.newline()
for tag in self.tags:
writer.simpletag("LanguageTag", tag=tag)
writer.newline()
def fromXML(self, name, attrs, content, ttFont):
if not hasattr(self, "tags"):
self.tags = []
if name == "LanguageTag":
self.tags.append(attrs["tag"])
elif "value" in attrs:
value = safeEval(attrs["value"])
setattr(self, name, value)