def writeFeatures_hhea(self): """ Write the hhea to a string and return it. This gets the values for the file using the fallback system as described below: =========== === Ascender openTypeHheaAscender Descender openTypeHheaDescender LineGap openTypeHheaLineGap CaretOffset openTypeHheaCaretOffset =========== === **This should not be called externally.** Subclasses may override this method to handle the string creation in a different way if desired. """ ascender = getAttrWithFallback(self.font.info, "openTypeHheaAscender") descender = getAttrWithFallback(self.font.info, "openTypeHheaDescender") lineGap = getAttrWithFallback(self.font.info, "openTypeHheaLineGap") caret = getAttrWithFallback(self.font.info, "openTypeHheaCaretOffset") writer = FeatureTableWriter("hhea") writer.addLineWithKeyValue("Ascender", _roundInt(ascender)) writer.addLineWithKeyValue("Descender", _roundInt(descender)) writer.addLineWithKeyValue("LineGap", _roundInt(lineGap)) writer.addLineWithKeyValue("CaretOffset", _roundInt(caret)) return writer.write()
def writeFeatures_name(self): """ Write the name to a string and return it. This gets the values for the file using the fallback system as described below: ========= === nameid 0 copyright nameid 7 trademark nameid 8 openTypeNameManufacturer nameid 9 openTypeNameDesigner nameid 10 openTypeNameDescription nameid 11 openTypeNameManufacturerURL nameid 12 openTypeNameDesignerURL nameid 13 openTypeNameLicense nameid 14 openTypeNameLicenseURL nameid 19 openTypeNameSampleText ========= === **This should not be called externally.** Subclasses may override this method to handle the string creation in a different way if desired. """ idToAttr = [ (0 , "copyright"), (7 , "trademark"), (8 , "openTypeNameManufacturer"), (9 , "openTypeNameDesigner"), (10 , "openTypeNameDescription"), (11 , "openTypeNameManufacturerURL"), (12 , "openTypeNameDesignerURL"), (13 , "openTypeNameLicense"), (14 , "openTypeNameLicenseURL"), (19 , "openTypeNameSampleText") ] multilineNameTableEntries = {} lines = [] for id, attr in idToAttr: value = getAttrWithFallback(self.font.info, attr) if value is None: continue s = 'nameid %d "%s";' % (id, winStr(value)) lines.append(s) s = 'nameid %d 1 "%s";' % (id, macStr(value)) lines.append(s) if not lines: return "" writer = FeatureTableWriter("name") for line in lines: writer.addLine(line) return writer.write()
def writeFeatures_head(self): """ Write the head to a string and return it. This gets the values for the file using the fallback system as described below: ===== === X.XXX versionMajor.versionMinor ===== === **This should not be called externally.** Subclasses may override this method to handle the string creation in a different way if desired. """ versionMajor = getAttrWithFallback(self.font.info, "versionMajor") versionMinor = getAttrWithFallback(self.font.info, "versionMinor") value = "%d.%s" % (versionMajor, str(versionMinor).zfill(3)) writer = FeatureTableWriter("head") writer.addLineWithKeyValue("FontRevision", value) return writer.write()
def writeFeatures_OS2(self): """ Write the OS/2 to a string and return it. This gets the values for the file using the fallback system as described below: ============= === FSType openTypeOS2Type Panose openTypeOS2Panose UnicodeRange openTypeOS2UnicodeRanges CodePageRange openTypeOS2CodePageRanges TypoAscender openTypeOS2TypoAscender TypoDescender openTypeOS2TypoDescender TypoLineGap openTypeOS2TypoLineGap winAscent openTypeOS2WinAscent winDescent openTypeOS2WinDescent XHeight xHeight CapHeight capHeight WeightClass openTypeOS2WeightClass WidthClass openTypeOS2WidthClass Vendor openTypeOS2VendorID ============= === **This should not be called externally.** Subclasses may override this method to handle the string creation in a different way if desired. """ codePageBitTranslation = { 0 : "1252", 1 : "1250", 2 : "1251", 3 : "1253", 4 : "1254", 5 : "1255", 6 : "1256", 7 : "1257", 8 : "1258", 16 : "874", 17 : "932", 18 : "936", 19 : "949", 20 : "950", 21 : "1361", 48 : "869", 49 : "866", 50 : "865", 51 : "864", 52 : "863", 53 : "862", 54 : "861", 55 : "860", 56 : "857", 57 : "855", 58 : "852", 59 : "775", 60 : "737", 61 : "708", 62 : "850", 63 : "437" } # writer writer = FeatureTableWriter("OS/2") # type writer.addLineWithKeyValue("FSType", intListToNum(getAttrWithFallback(self.font.info, "openTypeOS2Type"), 0, 16)) # panose panose = [str(i) for i in getAttrWithFallback(self.font.info, "openTypeOS2Panose")] writer.addLineWithKeyValue("Panose", " ".join(panose)) # unicode ranges unicodeRange = [str(i) for i in getAttrWithFallback(self.font.info, "openTypeOS2UnicodeRanges")] if unicodeRange: writer.addLineWithKeyValue("UnicodeRange", " ".join(unicodeRange)) # code page ranges codePageRange = [codePageBitTranslation[i] for i in getAttrWithFallback(self.font.info, "openTypeOS2CodePageRanges") if i in codePageBitTranslation] if codePageRange: writer.addLineWithKeyValue("CodePageRange", " ".join(codePageRange)) # vertical metrics writer.addLineWithKeyValue("TypoAscender", _roundInt(getAttrWithFallback(self.font.info, "openTypeOS2TypoAscender"))) writer.addLineWithKeyValue("TypoDescender", _roundInt(getAttrWithFallback(self.font.info, "openTypeOS2TypoDescender"))) writer.addLineWithKeyValue("TypoLineGap", _roundInt(getAttrWithFallback(self.font.info, "openTypeOS2TypoLineGap"))) writer.addLineWithKeyValue("winAscent", _roundInt(getAttrWithFallback(self.font.info, "openTypeOS2WinAscent"))) writer.addLineWithKeyValue("winDescent", abs(_roundInt(getAttrWithFallback(self.font.info, "openTypeOS2WinDescent")))) writer.addLineWithKeyValue("XHeight", _roundInt(getAttrWithFallback(self.font.info, "xHeight"))) writer.addLineWithKeyValue("CapHeight", _roundInt(getAttrWithFallback(self.font.info, "capHeight"))) writer.addLineWithKeyValue("WeightClass", getAttrWithFallback(self.font.info, "openTypeOS2WeightClass")) writer.addLineWithKeyValue("WidthClass", getAttrWithFallback(self.font.info, "openTypeOS2WidthClass")) writer.addLineWithKeyValue("Vendor", '"%s"' % getAttrWithFallback(self.font.info, "openTypeOS2VendorID")) return writer.write()
def writeFeatures_OS2(self): """ Write the OS/2 to a string and return it. This gets the values for the file using the fallback system as described below: ============= === FSType openTypeOS2Type Panose openTypeOS2Panose UnicodeRange openTypeOS2UnicodeRanges CodePageRange openTypeOS2CodePageRanges TypoAscender openTypeOS2TypoAscender TypoDescender openTypeOS2TypoDescender TypoLineGap openTypeOS2TypoLineGap winAscent openTypeOS2WinAscent winDescent openTypeOS2WinDescent XHeight xHeight CapHeight capHeight WeightClass openTypeOS2WeightClass WidthClass openTypeOS2WidthClass Vendor openTypeOS2VendorID ============= === **This should not be called externally.** Subclasses may override this method to handle the string creation in a different way if desired. """ codePageBitTranslation = { 0: "1252", 1: "1250", 2: "1251", 3: "1253", 4: "1254", 5: "1255", 6: "1256", 7: "1257", 8: "1258", 16: "874", 17: "932", 18: "936", 19: "949", 20: "950", 21: "1361", 48: "869", 49: "866", 50: "865", 51: "864", 52: "863", 53: "862", 54: "861", 55: "860", 56: "857", 57: "855", 58: "852", 59: "775", 60: "737", 61: "708", 62: "850", 63: "437" } # writer writer = FeatureTableWriter("OS/2") # type writer.addLineWithKeyValue( "FSType", intListToNum( getAttrWithFallback(self.font.info, "openTypeOS2Type"), 0, 16)) # panose panose = [ str(i) for i in getAttrWithFallback(self.font.info, "openTypeOS2Panose") ] writer.addLineWithKeyValue("Panose", " ".join(panose)) # unicode ranges unicodeRange = [ str(i) for i in getAttrWithFallback(self.font.info, "openTypeOS2UnicodeRanges") ] if unicodeRange: writer.addLineWithKeyValue("UnicodeRange", " ".join(unicodeRange)) # code page ranges codePageRange = [ codePageBitTranslation[i] for i in getAttrWithFallback( self.font.info, "openTypeOS2CodePageRanges") if i in codePageBitTranslation ] if codePageRange: writer.addLineWithKeyValue("CodePageRange", " ".join(codePageRange)) # vertical metrics writer.addLineWithKeyValue( "TypoAscender", _roundInt( getAttrWithFallback(self.font.info, "openTypeOS2TypoAscender"))) writer.addLineWithKeyValue( "TypoDescender", _roundInt( getAttrWithFallback(self.font.info, "openTypeOS2TypoDescender"))) writer.addLineWithKeyValue( "TypoLineGap", _roundInt( getAttrWithFallback(self.font.info, "openTypeOS2TypoLineGap"))) writer.addLineWithKeyValue( "winAscent", _roundInt( getAttrWithFallback(self.font.info, "openTypeOS2WinAscent"))) writer.addLineWithKeyValue( "winDescent", abs( _roundInt( getAttrWithFallback(self.font.info, "openTypeOS2WinDescent")))) writer.addLineWithKeyValue( "XHeight", _roundInt(getAttrWithFallback(self.font.info, "xHeight"))) writer.addLineWithKeyValue( "CapHeight", _roundInt(getAttrWithFallback(self.font.info, "capHeight"))) writer.addLineWithKeyValue( "WeightClass", getAttrWithFallback(self.font.info, "openTypeOS2WeightClass")) writer.addLineWithKeyValue( "WidthClass", getAttrWithFallback(self.font.info, "openTypeOS2WidthClass")) writer.addLineWithKeyValue( "Vendor", '"%s"' % getAttrWithFallback(self.font.info, "openTypeOS2VendorID")) return writer.write()
def writeFeatures_name(self): """ Write the name to a string and return it. This gets the values for the file using the fallback system as described below: ========= === nameid 0 copyright nameid 7 trademark nameid 8 openTypeNameManufacturer nameid 9 openTypeNameDesigner nameid 10 openTypeNameDescription nameid 11 openTypeNameManufacturerURL nameid 12 openTypeNameDesignerURL nameid 13 openTypeNameLicense nameid 14 openTypeNameLicenseURL nameid 19 openTypeNameSampleText ========= === **This should not be called externally.** Subclasses may override this method to handle the string creation in a different way if desired. """ idToAttr = [(0, "copyright"), (7, "trademark"), (8, "openTypeNameManufacturer"), (9, "openTypeNameDesigner"), (10, "openTypeNameDescription"), (11, "openTypeNameManufacturerURL"), (12, "openTypeNameDesignerURL"), (13, "openTypeNameLicense"), (14, "openTypeNameLicenseURL"), (19, "openTypeNameSampleText")] multilineNameTableEntries = {} lines = [] for id, attr in idToAttr: value = getAttrWithFallback(self.font.info, attr) if value is None: continue s = 'nameid %d "%s";' % (id, winStr(value)) lines.append(s) s = 'nameid %d 1 "%s";' % (id, macStr(value)) lines.append(s) if self.font.info.openTypeNameRecords is not None: for record in self.font.info.openTypeNameRecords: nameID = record["nameID"] if nameID >= 1 and nameID <= 6: continue platformID = record["platformID"] encodingID = record["encodingID"] languageID = record["languageID"] string = record["string"] if platformID == 0: string = macStr(string) else: string = winStr(string) s = 'nameid %d %d %d %d "%s";' % ( nameID, platformID, encodingID, languageID, string) lines.append(s) if not lines: return "" writer = FeatureTableWriter("name") for line in lines: writer.addLine(line) return writer.write()