Skip to content

Instantly share code, notes, and snippets.

@jjgod
Created April 28, 2013 20:10
Show Gist options
  • Save jjgod/5478229 to your computer and use it in GitHub Desktop.
Save jjgod/5478229 to your computer and use it in GitHub Desktop.
ttx fonttool patch to dump sbix table from Apple Color Emoji, according to http://typophile.com/node/96671#comment-524375 and http://kanji-database.sourceforge.net/fonts/opentype.html
commit 7f2ef9213b3a179d4b39fd921c6affb3d1553053
Author: Jiang Jiang <jiangj@opera.com>
Date: Sun Apr 28 18:17:50 2013 +0200
Add decompilation tool for sbix table used in Apple Color Emoji
diff --git a/Lib/fontTools/ttLib/tables/_s_b_i_x.py b/Lib/fontTools/ttLib/tables/_s_b_i_x.py
new file mode 100644
index 0000000..e126440
--- /dev/null
+++ b/Lib/fontTools/ttLib/tables/_s_b_i_x.py
@@ -0,0 +1,44 @@
+import os
+import sys
+import DefaultTable
+import struct
+from fontTools import ttLib
+from fontTools.misc.textTools import safeEval, readHex
+from types import TupleType
+
+class table__s_b_i_x(DefaultTable.DefaultTable):
+ def decompile(self, data, ttFont):
+ tableMajorVersion, tableMinorVersion = struct.unpack(">HH", data[:4])
+ self.tableVersion = "%d.%d" % (int(tableMajorVersion), int(tableMinorVersion))
+ numSizes, = struct.unpack(">L", data[4:8])
+ self.numSizes = int(numSizes)
+ self.sizeTables = []
+ self.numGlyphs = 728
+ for i in range(self.numSizes):
+ start = 8+i*4
+ offset, = struct.unpack(">L", data[start:start+4])
+ size, dpi = struct.unpack(">HH", data[offset:offset+4])
+ images = []
+ os.makedirs("%d" % size)
+ for j in range(self.numGlyphs):
+ imageOffset, = struct.unpack(">L", data[offset+4+j*4:offset+8+j*4])
+ nextImageOffset, = struct.unpack(">L", data[offset+8+j*4:offset+12+j*4])
+ if nextImageOffset > imageOffset:
+ imageData = data[offset+imageOffset+8:offset+nextImageOffset]
+ f = open("%d/%d.png" % (size, j), "w")
+ f.write(imageData)
+ f.close()
+ self.sizeTables.append([int(size), int(dpi)])
+
+ def toXML(self, writer, ttFont):
+ writer.simpletag("tableVersion", version=self.tableVersion)
+ writer.newline()
+ writer.begintag("sizes", [
+ ("numSizes", self.numSizes),
+ ])
+ writer.newline()
+ for i in range(self.numSizes):
+ writer.simpletag("size", size=self.sizeTables[i][0], dpi=self.sizeTables[i][1])
+ writer.newline()
+ writer.endtag("sizes")
+ writer.newline()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment