예제 #1
0
    def setupFile_menuName(self, path):
        """
        Make the menu name source file. This gets the values for
        the file using the fallback system as described below:

        ====  ===
        [PS]  postscriptFontName
        f=    openTypeNamePreferredFamilyName
        s=    openTypeNamePreferredSubfamilyName
        l=    styleMapFamilyName
        m=1,  openTypeNameCompatibleFullName
        ====  ===

        **This should not be called externally.** Subclasses
        may override this method to handle the file creation
        in a different way if desired.
        """
        psName = getAttrWithFallback(self.font.info, "postscriptFontName")
        lines = ["[%s]" % psName]
        # family name
        familyName = getAttrWithFallback(self.font.info,
                                         "openTypeNamePreferredFamilyName")
        encodedFamilyName = winStr(familyName)
        lines.append("f=%s" % encodedFamilyName)
        if encodedFamilyName != familyName:
            lines.append("f=1,%s" % macStr(familyName))
        # style name
        styleName = getAttrWithFallback(self.font.info,
                                        "openTypeNamePreferredSubfamilyName")
        encodedStyleName = winStr(styleName)
        lines.append("s=%s" % encodedStyleName)
        if encodedStyleName != styleName:
            lines.append("s=1,%s" % macStr(styleName))
        # compatible name
        winCompatible = getAttrWithFallback(self.font.info,
                                            "styleMapFamilyName")
        ## the second qualification here is in place for Mac Office <= 2004.
        ## in that app the menu name is pulled from name ID 18. the font
        ## may have standard naming data that combines to a length longer
        ## than the app can handle (see Adobe Tech Note #5088). the designer
        ## may have created a specific openTypeNameCompatibleFullName to
        ## get around this problem. sigh, old app bugs live long lives.
        if winCompatible != familyName or self.font.info.openTypeNameCompatibleFullName is not None:
            # windows
            l = "l=%s" % normalizeStringForPostscript(winCompatible)
            lines.append(l)
            # mac
            macCompatible = getAttrWithFallback(
                self.font.info, "openTypeNameCompatibleFullName")
            l = "m=1,%s" % macStr(macCompatible)
            lines.append(l)
        text = "\n".join(lines) + "\n"
        f = open(path, "wb")
        f.write(text)
        f.close()
예제 #2
0
    def setupFile_menuName(self, path):
        """
        Make the menu name source file. This gets the values for
        the file using the fallback system as described below:

        ====  ===
        [PS]  postscriptFontName
        f=    openTypeNamePreferredFamilyName
        s=    openTypeNamePreferredSubfamilyName
        l=    styleMapFamilyName
        m=1,  openTypeNameCompatibleFullName
        ====  ===

        **This should not be called externally.** Subclasses
        may override this method to handle the file creation
        in a different way if desired.
        """
        psName = getAttrWithFallback(self.font.info,"postscriptFontName")
        lines = [
            "[%s]" % psName
        ]
        # family name
        familyName = getAttrWithFallback(self.font.info,"openTypeNamePreferredFamilyName")
        encodedFamilyName = winStr(familyName)
        lines.append("f=%s" % encodedFamilyName)
        if encodedFamilyName != familyName:
            lines.append("f=1,%s" % macStr(familyName))
        # style name
        styleName = getAttrWithFallback(self.font.info,"openTypeNamePreferredSubfamilyName")
        encodedStyleName = winStr(styleName)
        lines.append("s=%s" % encodedStyleName)
        if encodedStyleName != styleName:
            lines.append("s=1,%s" % macStr(styleName))
        # compatible name
        winCompatible = getAttrWithFallback(self.font.info,"styleMapFamilyName")
        ## the second qualification here is in place for Mac Office <= 2004.
        ## in that app the menu name is pulled from name ID 18. the font
        ## may have standard naming data that combines to a length longer
        ## than the app can handle (see Adobe Tech Note #5088). the designer
        ## may have created a specific openTypeNameCompatibleFullName to
        ## get around this problem. sigh, old app bugs live long lives.
        if winCompatible != familyName or self.font.info.openTypeNameCompatibleFullName is not None:
            # windows
            l = "l=%s" % normalizeStringForPostscript(winCompatible)
            lines.append(l)
            # mac
            macCompatible = getAttrWithFallback(self.font.info,"openTypeNameCompatibleFullName")
            l = "m=1,%s" % macStr(macCompatible)
            lines.append(l)
        text = "\n".join(lines) + "\n"
        f = open(path, "wb")
        f.write(text)
        f.close()
예제 #3
0
    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()
예제 #4
0
    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()