Exemplo n.º 1
0
def doHinting(options):
	global gLogReporter
	result = 1

	if fl.count < 1:
		return

	fl.SetUndo()
	logMsg(" ")
	if (options.doAllOpenFonts):
		fontRange = range(fl.count)
	elif options.doCurrentFont:
		fontRange = [fl.ifont]
	else:
		logMsg("Error: unsupported option for font selection.")
		return

	if options.getNamesFromFile:
		fontPath = fl.font.file_name
		if not fontPath:
			print "Cannot find list file next to font file, when font file doesn't yet exist."
			return
			
		fontPath = os.path.dirname(fontPath)
		nameList = GetGlyphNamesFromFile(fontPath)
		numGlyphs = len(nameList)
		if not nameList:
			print "No names found in glyph name list file."
			return
	# Temproary data file paths used with the autohintexe program.
	tempBaseName = os.tempnam()
	options.tempBez = tempBaseName + ".bez"
	options.tempBezNew = options.tempBez + ".new"
	options.tempFI = tempBaseName + ".fi"

	for fi in fontRange:
		font = fl[fi]
		
		if not options.getNamesFromFile:
			# Because of the options.doSelectedGlyphs option and the fact that we can't assume
			# that GI's are the same in every font, we first 
			# collect the selected glyph names from the current font,
			# and then index glyphs in all fonts by name.
			nameList = []
			if options.doSelectedGlyphs:
				# Note that I am getting the name list from the selected glyphs in the active font
				# which is not necessarily the one  being processed.
				for gi in range(len(fl.font)):
					if fl.Selected(gi):
						nameList.append(fl.font[gi].name)

			if options.doAllGlyphs:
				for gi in range(len(font)):
					nameList.append(font[gi].name)

			if not nameList:
				logMsg("No glyphs selected for font %s." % os.path.basename(font.file_name))
				continue

		# set up progress bar
		numGlyphs = len(nameList)
		if numGlyphs > kProgressBarThreshold:
			fl.BeginProgress("Checking glyphs...", numGlyphs)
		tick = 0


		# Create font-specific log file.
		fontName = font.font_name
		if not fontName:
			fontName = "FontName-Undefined"
		filePath = font.file_name
		if not filePath:
			filePath = fontName
		gLogReporter = Reporter(os.path.join(os.path.dirname(filePath), acLogFileName))
		if not gLogReporter.file:
			gLogReporter = None

		# load fontPlist.
		fontPlist = None
		isNewPlistFile = 0
		if options.doHistoryFile:
			fontPlist, fontPlistFilePath, isNewPlistFile = openFontPlistFile(fontName, os.path.dirname(filePath))
			if isNewPlistFile and (not (options.doReHintUnknown or options.doHintAll)):
				logMsg("No hint info plist file was found, so all glyphs are unknown to AC. To hint all glyphs, run AC again with option to hint all glyphs unconditionally.")
				return

		logMsg("Autohinting starting for font", os.path.basename(filePath), time.asctime())
		lenFont = len(font)
		if options.noFlex:
			FlexOK = 'false'
		else:
			FlexOK = 'true'
		fontInfo = BezChar.GetACFontInfoFromFLFont(font, FlexOK)
		fp = open(options.tempFI, "wt") # For name-keyed ofnts, there is only one fontinfo string.
		fp.write(fontInfo)
		fp.close()
		anyGlyphChanged = 0
		for gname in nameList:
			gi = font.FindGlyph(gname)
			if gi > -1: # not all open fonts will have the same list of glyphs.
				flGlyph = font.glyphs[gi]
				glyphChanged = Run_AC(flGlyph, fontInfo, fontPlist, options, isNewPlistFile)
				if glyphChanged:
					anyGlyphChanged = 1
				fl.UpdateGlyph(gi)
				if numGlyphs > kProgressBarThreshold:
					tick = tick + 1
					if (tick % kProgressBarTickStep == 0):
						result = fl.TickProgress(tick)
						if not result:
							break
		if fontPlist:
			fontPlist.write(fontPlistFilePath)
		if gLogReporter:
			gLogReporter.close()
			gLogReporter = None
		font.modified = 1


		
		if numGlyphs > kProgressBarThreshold:
			# can end the progress bar only if we started it.
			fl.EndProgress()

		if (not anyGlyphChanged) and options.doHistoryFile:
			if (options.doReHintUnknown):
				logMsg("No new hints. All selected glyphs were hinted and had same outline as recorded  in  %s." % (os.path.basename(fontPlistFilePath)))
			else:
				logMsg("No new hints. All selected glyphs either were hinted and had the same outline as recorded in  %s, or were not referenced in the hint info file." % (os.path.basename(fontPlistFilePath)))
	

	logMsg("All done with AC %s" % time.asctime())
Exemplo n.º 2
0
def doCheck(options):
    global gLogReporter
    arg_string = ""
    if options.doFixProblems:
        arg_string = arg_string + " -n"
    if options.beVerbose:
        arg_string = arg_string + " -v"
    if options.skipInspectionTests:
        arg_string = arg_string + " -I"
    if options.doSmoothnessTest:
        arg_string = arg_string + " -s"
    if options.doSpikeTest:
        arg_string = arg_string + " -x"
    if options.doTriangleTest:
        arg_string = arg_string + " -3"
    if not options.doPathDirectionTest:
        arg_string = arg_string + " -O"
    if not options.doOverlapCheck:
        arg_string = arg_string + " -V"
    if not options.doCoincidentPathTest:
        arg_string = arg_string + " -k"
    if options.curveTolerance:
        arg_string = arg_string + " -C " + str(options.curveTolerance)
    if options.lineTolerance:
        arg_string = arg_string + " -L " + str(options.lineTolerance)
    if options.pathTolerance:
        arg_string = arg_string + " -K " + str(options.pathTolerance)

    if options.doAllOpenFonts:
        numOpenFonts = fl.count
    elif options.doWholeFamily:
        # close all fonts not in the family; open the ones that are missing.
        numOpenFonts = fl.count
    elif options.doCurrentFont:
        numOpenFonts = 1
    else:
        print "Error: unsupported option for font selection."

    fileName = fl.font.file_name
    if not fileName:
        fileName = "Font-Undefined"
    logDir = os.path.dirname(fileName)
    gLogReporter = Reporter(os.path.join(logDir, logFileName))

    tempBaseName = os.tempnam()
    options.tempBez = tempBaseName + ".bez"

    # set up progress bar
    if options.doAllGlyphs:
        numGlyphs = len(fl.font)
    else:
        numGlyphs = fl.count_selected
    numProcessedGlyphs = numGlyphs * numOpenFonts
    if numProcessedGlyphs > kProgressBarThreshold:
        fl.BeginProgress("Checking glyphs...", numProcessedGlyphs)
    tick = 0
    if options.doAllGlyphs:
        for fi in range(numOpenFonts):
            if numOpenFonts == 1:
                font = fl.font
            else:
                font = fl[fi]

            logMsg("Checking %s." % (font.font_name))
            lenFont = len(font)
            for gi in range(lenFont):
                glyph = font[gi]
                CheckGlyph(options, glyph, arg_string)
                if numGlyphs > kProgressBarThreshold:
                    tick = tick + 1
                    if (tick % kProgressBarTickStep == 0):
                        result = fl.TickProgress(tick)
                        if not result:
                            break
                CheckGlyph(options, glyph, arg_string)

    elif options.doSelectedGlyphs:
        if numOpenFonts == 1:  # we can use the current  selection
            font = fl.font
            lenFont = len(font)
            logMsg("Checking %s." % (font.font_name))
            for gi in range(lenFont):
                if fl.Selected(gi):
                    glyph = font[gi]
                    if numGlyphs > kProgressBarThreshold:
                        tick = tick + 1
                        if (tick % kProgressBarTickStep == 0):
                            result = fl.TickProgress(tick)
                            if not result:
                                break
                    CheckGlyph(options, glyph, arg_string)

        else:  # we can't assume that GI's are the same in every font.
            # Collect the selected glyph names from the current font,
            # and then index in all fonts by name.
            nameList = []
            for gi in range(lenFont):
                if fl.Selected(gi):
                    nameList.append(fl.font[gi].name)
            for fi in range(numOpenFonts):
                font = fl[fi]
                logMsg("Checking %s." % (font.font_name))
                lenFont = len(font)
                for gname in nameList:
                    gi = font.FindGlyph(gname)
                    if gi > -1:
                        glyph = font[gi]
                        if numGlyphs > kProgressBarThreshold:
                            tick = tick + 1
                            if (tick % kProgressBarTickStep == 0):
                                result = fl.TickProgress(tick)
                                if not result:
                                    break
                        CheckGlyph(options, glyph, arg_string)
                    else:
                        line = "Glyph in not in font"
                        logMsg("\t" + line + os.linesep)

    else:
        print "Error: unsupported option for glyph selection."
    gLogReporter.close()
    if numGlyphs > kProgressBarThreshold:
        fl.EndProgress()

    gLogReporter = None
Exemplo n.º 3
0
def doCheck(options):
	global gLogReporter
	arg_string = ""
	if options.doFixProblems:
		arg_string = arg_string + " -n"
	if options.beVerbose:
		arg_string = arg_string + " -v"
	if options.skipInspectionTests:
		arg_string = arg_string + " -I"
	if options.doSmoothnessTest:
		arg_string = arg_string + " -s"
	if options.doSpikeTest:
		arg_string = arg_string + " -x"
	if options.doTriangleTest:
		arg_string = arg_string + " -3"
	if not options.doPathDirectionTest:
		arg_string = arg_string + " -O"
	if not options.doOverlapCheck:
		arg_string = arg_string + " -V"
	if not options.doCoincidentPathTest:
		arg_string = arg_string + " -k"
	if options.curveTolerance:
		arg_string = arg_string + " -C " + str(options.curveTolerance)
	if options.lineTolerance:
		arg_string = arg_string + " -L " + str(options.lineTolerance)
	if options.pathTolerance:
		arg_string = arg_string + " -K " + str(options.pathTolerance)

	if options.doAllOpenFonts:
		numOpenFonts = fl.count
	elif options.doWholeFamily:
		# close all fonts not in the family; open the ones that are missing.
		numOpenFonts = fl.count
	elif options.doCurrentFont:
		numOpenFonts = 1
	else:
		print "Error: unsupported option for font selection."

	fileName = fl.font.file_name
	if not fileName:
		fileName = "Font-Undefined"
	logDir = os.path.dirname(fileName)
	gLogReporter = Reporter(os.path.join(logDir, logFileName))

	tempBaseName = os.tempnam()
	options.tempBez = tempBaseName + ".bez"
		
	# set up progress bar
	if options.doAllGlyphs:
		numGlyphs = len(fl.font)
	else:
		numGlyphs = fl.count_selected
	numProcessedGlyphs = numGlyphs * numOpenFonts
	if numProcessedGlyphs > kProgressBarThreshold:
		fl.BeginProgress("Checking glyphs...", numProcessedGlyphs)
	tick = 0
	if options.doAllGlyphs:
		for fi in range(numOpenFonts):
			if numOpenFonts == 1:
				font = fl.font
			else:
				font = fl[fi]

			logMsg("Checking %s." % (font.font_name))
			lenFont = len(font)
			for gi in range(lenFont):
				glyph = font[gi]
				CheckGlyph(options, glyph, arg_string)
				if numGlyphs > kProgressBarThreshold:
					tick = tick + 1
					if (tick % kProgressBarTickStep == 0):
						result = fl.TickProgress(tick)
						if not result:
							break
				CheckGlyph(options, glyph, arg_string)
			
	elif options.doSelectedGlyphs:
		if numOpenFonts == 1: # we can use the current  selection
			font = fl.font
			lenFont =  len(font)
			logMsg("Checking %s." % (font.font_name))
			for gi in range(lenFont):
				if fl.Selected(gi):
					glyph = font[gi]
					if numGlyphs > kProgressBarThreshold:
						tick = tick + 1
						if (tick % kProgressBarTickStep == 0):
							result = fl.TickProgress(tick)
							if not result:
								break
					CheckGlyph(options, glyph, arg_string)

		else: # we can't assume that GI's are the same in every font. 
			# Collect the selected glyph names from the current font,
			# and then index in all fonts by name.
			nameList = []
			for gi in range(lenFont):
				if fl.Selected(gi):
					nameList.append(fl.font[gi].name)
			for fi in range(numOpenFonts):
				font = fl[fi]
				logMsg("Checking %s." % (font.font_name))
				lenFont = len(font)
				for gname in nameList:
					gi = font.FindGlyph(gname)
					if gi > -1:
						glyph = font[gi]
						if numGlyphs > kProgressBarThreshold:
							tick = tick + 1
							if (tick % kProgressBarTickStep == 0):
								result = fl.TickProgress(tick)
								if not result:
									break
						CheckGlyph(options, glyph, arg_string)
					else:
						line = "Glyph in not in font"
						logMsg("\t" + line + os.linesep)
			 
	else:
		print "Error: unsupported option for glyph selection."
	gLogReporter.close()
	if numGlyphs > kProgressBarThreshold:
		fl.EndProgress()
	
	gLogReporter = None
Exemplo n.º 4
0
def doHinting(options):
    global gLogReporter
    result = 1

    if fl.count < 1:
        return

    fl.SetUndo()
    logMsg(" ")
    if (options.doAllOpenFonts):
        fontRange = range(fl.count)
    elif options.doCurrentFont:
        fontRange = [fl.ifont]
    else:
        logMsg("Error: unsupported option for font selection.")
        return

    if options.getNamesFromFile:
        fontPath = fl.font.file_name
        if not fontPath:
            print "Cannot find list file next to font file, when font file doesn't yet exist."
            return

        fontPath = os.path.dirname(fontPath)
        nameList = GetGlyphNamesFromFile(fontPath)
        numGlyphs = len(nameList)
        if not nameList:
            print "No names found in glyph name list file."
            return
    # Temproary data file paths used with the autohintexe program.
    tempBaseName = os.tempnam()
    options.tempBez = tempBaseName + ".bez"
    options.tempBezNew = options.tempBez + ".new"
    options.tempFI = tempBaseName + ".fi"

    for fi in fontRange:
        font = fl[fi]

        if not options.getNamesFromFile:
            # Because of the options.doSelectedGlyphs option and the fact that we can't assume
            # that GI's are the same in every font, we first
            # collect the selected glyph names from the current font,
            # and then index glyphs in all fonts by name.
            nameList = []
            if options.doSelectedGlyphs:
                # Note that I am getting the name list from the selected glyphs in the active font
                # which is not necessarily the one  being processed.
                for gi in range(len(fl.font)):
                    if fl.Selected(gi):
                        nameList.append(fl.font[gi].name)

            if options.doAllGlyphs:
                for gi in range(len(font)):
                    nameList.append(font[gi].name)

            if not nameList:
                logMsg("No glyphs selected for font %s." %
                       os.path.basename(font.file_name))
                continue

        # set up progress bar
        numGlyphs = len(nameList)
        if numGlyphs > kProgressBarThreshold:
            fl.BeginProgress("Checking glyphs...", numGlyphs)
        tick = 0

        # Create font-specific log file.
        fontName = font.font_name
        if not fontName:
            fontName = "FontName-Undefined"
        filePath = font.file_name
        if not filePath:
            filePath = fontName
        gLogReporter = Reporter(
            os.path.join(os.path.dirname(filePath), acLogFileName))
        if not gLogReporter.file:
            gLogReporter = None

        # load fontPlist.
        fontPlist = None
        isNewPlistFile = 0
        if options.doHistoryFile:
            fontPlist, fontPlistFilePath, isNewPlistFile = openFontPlistFile(
                fontName, os.path.dirname(filePath))
            if isNewPlistFile and (not (options.doReHintUnknown
                                        or options.doHintAll)):
                logMsg(
                    "No hint info plist file was found, so all glyphs are unknown to AC. To hint all glyphs, run AC again with option to hint all glyphs unconditionally."
                )
                return

        logMsg("Autohinting starting for font", os.path.basename(filePath),
               time.asctime())
        lenFont = len(font)
        if options.noFlex:
            FlexOK = 'false'
        else:
            FlexOK = 'true'
        fontInfo = BezChar.GetACFontInfoFromFLFont(font, FlexOK)
        fp = open(
            options.tempFI,
            "wt")  # For name-keyed ofnts, there is only one fontinfo string.
        fp.write(fontInfo)
        fp.close()
        anyGlyphChanged = 0
        for gname in nameList:
            gi = font.FindGlyph(gname)
            if gi > -1:  # not all open fonts will have the same list of glyphs.
                flGlyph = font.glyphs[gi]
                glyphChanged = Run_AC(flGlyph, fontInfo, fontPlist, options,
                                      isNewPlistFile)
                if glyphChanged:
                    anyGlyphChanged = 1
                fl.UpdateGlyph(gi)
                if numGlyphs > kProgressBarThreshold:
                    tick = tick + 1
                    if (tick % kProgressBarTickStep == 0):
                        result = fl.TickProgress(tick)
                        if not result:
                            break
        if fontPlist:
            fontPlist.write(fontPlistFilePath)
        if gLogReporter:
            gLogReporter.close()
            gLogReporter = None
        font.modified = 1

        if numGlyphs > kProgressBarThreshold:
            # can end the progress bar only if we started it.
            fl.EndProgress()

        if (not anyGlyphChanged) and options.doHistoryFile:
            if (options.doReHintUnknown):
                logMsg(
                    "No new hints. All selected glyphs were hinted and had same outline as recorded  in  %s."
                    % (os.path.basename(fontPlistFilePath)))
            else:
                logMsg(
                    "No new hints. All selected glyphs either were hinted and had the same outline as recorded in  %s, or were not referenced in the hint info file."
                    % (os.path.basename(fontPlistFilePath)))

    logMsg("All done with AC %s" % time.asctime())