How to use the afdko.convertfonttocid function in afdko

To help you get started, we’ve selected a few afdko examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github adobe-type-tools / afdko / python / afdko / makeotf.py View on Github external
tempPath = fdkutils.get_temp_file_path()
        try:
            doSubr = 'true' == getattr(makeOTFParams, kFileOptPrefix + kDoSubr)

            if kMOTFOptions[kDoSubr][0] == kOptionNotSeen:
                doSubr = 'true' == getattr(makeOTFParams,
                                           kFileOptPrefix + kRelease)
            # Send the font.pfa file to convertfonttocid.py
            # rather than the OTF because the GlyphSet
            # definitions in the 'fontinfo' files use production
            # glyph names not final glyph names.
            convertfonttocid.convertFontToCID(
                outputPath, tempPath, makeOTFParams.fontinfoPath)
            convertfonttocid.mergeFontToCFF(tempPath, outputPath, doSubr)

        except(convertfonttocid.FontInfoParseError,
               convertfonttocid.FontParseError):
            raise

        if not os.path.exists(outputPath):
            print("makeotf [Error] Failed to convert font '%s' to CID." %
                  outputPath)
            raise MakeOTFRunError

    if getattr(makeOTFParams, kFileOptPrefix + kRelease):
        try:
            with TTFont(outputPath) as font:
                if 'head' not in font:
                    print("makeotf [Error] Could not extract version number "
                          "from file at '%s'." % outputPath)
                    raise MakeOTFShellError
                font_version = Decimal(
github adobe-type-tools / afdko / python / afdko / ufotools.py View on Github external
def getFontInfo(self, fontPSName, inputPath, allow_no_blues, noFlex,
                    vCounterGlyphs, hCounterGlyphs, fdIndex=0):
        if self.fontDict is not None:
            return self.fontDict

        if self.fontInfo is None:
            self.loadFontInfo()

        fdDict = convertfonttocid.FDDict()
        # should be 1 if the glyphs are ideographic, else 0.
        fdDict.LanguageGroup = self.fontInfo.get("languagegroup", "0")
        fdDict.OrigEmSqUnits = self.getUnitsPerEm()
        fdDict.FontName = self.getPSName()
        upm = self.getUnitsPerEm()
        low = min(-upm * 0.25,
                  float(self.fontInfo.get("openTypeOS2WinDescent", "0")) - 200)
        high = max(upm * 1.25,
                   float(self.fontInfo.get("openTypeOS2WinAscent", "0")) + 200)
        # Make a set of inactive alignment zones: zones outside
        # of the font bbox so as not to affect hinting.
        # Used when src font has no BlueValues or has invalid BlueValues.
        # Some fonts have bad BBox values, so we don't let this be smaller
        # than -upm*0.25, upm*1.25.
        inactiveAlignmentValues = [low, low, high, high]
        blueValues = sorted(self.fontInfo.get("postscriptBlueValues", []))
github adobe-type-tools / afdko / python / afdko / beztools.py View on Github external
def getFontInfo(self, fontPSName, inputPath, allow_no_blues, noFlex, vCounterGlyphs, hCounterGlyphs,fdIndex = 0):
		# The AC library needs the global font hint zones and standard stem widths. Format them
		# into a single  text string.
		# The text format is arbitrary, inherited from very old software, but there is no real need to change it.
		pTopDict = self.topDict
		if  hasattr(pTopDict, "FDArray"):
			pDict = pTopDict.FDArray[fdIndex]
		else:
			pDict = pTopDict
		privateDict = pDict.Private

		fdDict = convertfonttocid.FDDict()
		if  hasattr(privateDict, "LanguageGroup"):
			fdDict.LanguageGroup = privateDict.LanguageGroup
		else:
			fdDict.LanguageGroup = "0"

		if  hasattr(pDict, "FontMatrix"):
			fdDict.FontMatrix = pDict.FontMatrix
		else:
			fdDict.FontMatrix = pTopDict.FontMatrix
		upm = int(1/fdDict.FontMatrix[0])
		fdDict.OrigEmSqUnits = str(upm)

		if  hasattr(pTopDict, "FontName"):
			fdDict.FontName = pDict.FontName # FontName
		else:
			fdDict.FontName = fontPSName
github adobe-type-tools / afdko / python / afdko / ufotools.py View on Github external
hCounterGlyphs, fdIndex)
        fontDictList.append(fdDict)

        # Check the fontinfo file, and add any other font dicts
        srcFontInfo = os.path.dirname(inputPath)
        srcFontInfo = os.path.join(srcFontInfo, "fontinfo")
        maxX = self.getUnitsPerEm() * 2
        maxY = maxX
        minY = -self.getUnitsPerEm()
        if os.path.exists(srcFontInfo):
            with open(srcFontInfo, "r", encoding='utf-8') as fi:
                fontInfoData = fi.read()
            fontInfoData = re.sub(r"#[^\r\n]+", "", fontInfoData)

            if "FDDict" in fontInfoData:
                blueFuzz = convertfonttocid.getBlueFuzz(inputPath)
                fdGlyphDict, fontDictList, finalFDict = \
                    convertfonttocid.parseFontInfoFile(
                        fontDictList, fontInfoData, glyphList,
                        maxY, minY, psName, blueFuzz)
                if finalFDict is None:
                    # If a font dict was not explicitly specified for the
                    # output font, use the first user-specified font dict.
                    convertfonttocid.mergeFDDicts(
                        fontDictList[1:], self.fontDict)
                else:
                    convertfonttocid.mergeFDDicts(
                        [finalFDict], self.fontDict)

        return fdGlyphDict, fontDictList
github adobe-type-tools / afdko / python / afdko / makeotf.py View on Github external
# we do this as a post processing step on the OTF.
    # NOTE: See comment about font.pfa below.
    if doConvertToCID == "true":
        print("Converting CFF table to CID-keyed CFF...")
        tempPath = fdkutils.get_temp_file_path()
        try:
            doSubr = 'true' == getattr(makeOTFParams, kFileOptPrefix + kDoSubr)

            if kMOTFOptions[kDoSubr][0] == kOptionNotSeen:
                doSubr = 'true' == getattr(makeOTFParams,
                                           kFileOptPrefix + kRelease)
            # Send the font.pfa file to convertfonttocid.py
            # rather than the OTF because the GlyphSet
            # definitions in the 'fontinfo' files use production
            # glyph names not final glyph names.
            convertfonttocid.convertFontToCID(
                outputPath, tempPath, makeOTFParams.fontinfoPath)
            convertfonttocid.mergeFontToCFF(tempPath, outputPath, doSubr)

        except(convertfonttocid.FontInfoParseError,
               convertfonttocid.FontParseError):
            raise

        if not os.path.exists(outputPath):
            print("makeotf [Error] Failed to convert font '%s' to CID." %
                  outputPath)
            raise MakeOTFRunError

    if getattr(makeOTFParams, kFileOptPrefix + kRelease):
        try:
            with TTFont(outputPath) as font:
                if 'head' not in font:
github adobe-type-tools / afdko / python / afdko / beztools.py View on Github external
#print numBlueValues
		#for i in range(0, len(fontinfo),2):
		#	print fontinfo[i], fontinfo[i+1]

		if hasattr(privateDict, "OtherBlues"):
			# For all OtherBlues, the pairs are bottom zones, and the first value of each pair is the overshoot position.
			i = 0
			numBlueValues = len(privateDict.OtherBlues)
			blueValues = privateDict.OtherBlues[:]
			blueValues.sort()
			for i in range(0, numBlueValues,2):
				blueValues[i] = blueValues[i] - blueValues[i+1]
			blueValues = [str(val) for val in blueValues]
			numBlueValues = min(numBlueValues, len(convertfonttocid.kOtherBlueValueKeys))
			for i in range(numBlueValues):
				key = convertfonttocid.kOtherBlueValueKeys[i]
				value = blueValues[i]
				exec("fdDict.%s = %s" % (key, value))

		if hasattr(privateDict, "StemSnapV"):
			vstems = privateDict.StemSnapV
		elif hasattr(privateDict, "StdVW"):
			vstems = [privateDict.StdVW]
		else:
			if allow_no_blues:
				vstems =  [upm] # dummy value. Needs to be larger than any hint will likely be,
				# as the autohint program strips out any hint wider than twice the largest global stem width.
			else:
				raise	ACFontError("Error: font has neither StemSnapV nor StdVW!")
		vstems.sort()
		if (len(vstems) == 0) or ((len(vstems) == 1) and (vstems[0] < 1) ):
			vstems =  [upm] # dummy value that will allow PyAC to run