def fix(self): if 'DSIG' in self.font: return False try: from fontTools.ttLib.tables.D_S_I_G_ import SignatureRecord except ImportError: error_message = ("The '{}' font does not have an existing" " digital signature proving its authenticity," " so Fontbakery needs to add one. To do this" " requires version 2.3 or later of Fonttools" " to be installed. Please upgrade at" " https://pypi.python.org/pypi/FontTools/2.4") logger.error(error_message.format(os.path.basename(self.fontpath))) return False newDSIG = ttLib.newTable("DSIG") newDSIG.ulVersion = 1 newDSIG.usFlag = 1 newDSIG.usNumSigs = 1 sig = SignatureRecord() sig.ulLength = 20 sig.cbSignature = 12 sig.usReserved2 = 0 sig.usReserved1 = 0 sig.pkcs7 = '\xd3M4\xd3M5\xd3M4\xd3M4' sig.ulFormat = 1 sig.ulOffset = 20 newDSIG.signatureRecords = [sig] self.font.tables["DSIG"] = newDSIG return True
def makeDSIG(tt_font): ''' Add a dummy DSIG table to an OpenType-TTF font, so positioning features work in Office applications on Windows. thanks to Ben Kiel on TypeDrawers: http://typedrawers.com/discussion/192/making-ot-ttf-layout-features-work-in-ms-word-2010 ''' from fontTools import ttLib from fontTools.ttLib.tables.D_S_I_G_ import SignatureRecord newDSIG = ttLib.newTable("DSIG") newDSIG.ulVersion = 1 newDSIG.usFlag = 1 newDSIG.usNumSigs = 1 sig = SignatureRecord() sig.ulLength = 20 sig.cbSignature = 12 sig.usReserved2 = 0 sig.usReserved1 = 0 sig.pkcs7 = '\xd3M4\xd3M5\xd3M4\xd3M4' sig.ulFormat = 1 sig.ulOffset = 20 newDSIG.signatureRecords = [sig] tt_font["DSIG"] = newDSIG # ugly but necessary -> so all tables are added to ttfont # tt_font.lazy = False for key in tt_font.keys(): print tt_font[key]
def main(): args = parser.parse_args() for path in args.ttf_font: if not os.path.exists(path): continue font = ttLib.TTFont(path) if "DSIG" not in font: try: if args.autofix: from fontTools.ttLib.tables.D_S_I_G_ import SignatureRecord newDSIG = ttLib.newTable("DSIG") newDSIG.ulVersion = 1 newDSIG.usFlag = 1 newDSIG.usNumSigs = 1 sig = SignatureRecord() sig.ulLength = 20 sig.cbSignature = 12 sig.usReserved2 = 0 sig.usReserved1 = 0 sig.pkcs7 = '\xd3M4\xd3M5\xd3M4\xd3M4' sig.ulFormat = 1 sig.ulOffset = 20 newDSIG.signatureRecords = [sig] font.tables["DSIG"] = newDSIG font.save(path) print(("HOTFIX: '{}': The font lacks a digital" " signature (DSIG), so we just added a dummy" " placeholder that should be enough for the" " applications that require its presence in" " order to work properly.").format(path)) else: print(("ERROR: '{}': This font lacks a digital signature" " (DSIG table). Some applications may required" " one (even if only a dummy placeholder)" " in order to work properly. Re-run this script" " passing --autofix in order to hotfix the font" " with a dummy signature.").format(path)) except ImportError: error_message = ( "ERROR '{}': The font lacks a" " digital signature (DSIG), so OpenType features" " will not be available in some applications that" " use its presense as a (stupid) heuristic." " So we need to add one. But for that we'll need " "Fonttools v2.3+ so you need to upgrade it. Try:" " $ pip install --upgrade fontTools; or see" " https://pypi.python.org/pypi/FontTools") print(error_message.format(path))
def makeDSIG(font): from fontTools.ttLib.tables.D_S_I_G_ import SignatureRecord newDSIG = ttLib.newTable("DSIG") newDSIG.ulVersion = 1 newDSIG.usFlag = 1 newDSIG.usNumSigs = 1 sig = SignatureRecord() sig.ulLength = 20 sig.cbSignature = 12 sig.usReserved2 = 0 sig.usReserved1 = 0 sig.pkcs7 = '\xd3M4\xd3M5\xd3M4\xd3M4' sig.ulFormat = 1 sig.ulOffset = 20 newDSIG.signatureRecords = [sig] font.tables["DSIG"] = newDSIG
def create(fontpath): font = ttLib.TTFont(fontpath) newDSIG = ttLib.newTable("DSIG") newDSIG.ulVersion = 1 newDSIG.usFlag = 1 newDSIG.usNumSigs = 1 sig = SignatureRecord() sig.ulLength = 20 sig.cbSignature = 12 sig.usReserved2 = 0 sig.usReserved1 = 0 sig.pkcs7 = '\xd3M4\xd3M5\xd3M4\xd3M4' sig.ulFormat = 1 sig.ulOffset = 20 newDSIG.signatureRecords = [sig] font.tables["DSIG"] = newDSIG font.save(fontpath + '.fix')
def makeDSIG(font): """ Makes a fake DSIG to keep certain applications happy. *font* is a fontTools font object """ from fontTools.ttLib.tables.D_S_I_G_ import SignatureRecord newDSIG = ttLib.newTable("DSIG") newDSIG.ulVersion = 1 newDSIG.usFlag = 1 newDSIG.usNumSigs = 1 sig = SignatureRecord() sig.ulLength = 20 sig.cbSignature = 12 sig.usReserved2 = 0 sig.usReserved1 = 0 sig.pkcs7 = b'\xd3M4\xd3M5\xd3M4\xd3M4' sig.ulFormat = 1 sig.ulOffset = 20 newDSIG.signatureRecords = [sig] font.tables["DSIG"] = newDSIG