Ejemplo n.º 1
0
def test_doTitle_pageIncludeTitle_0():
    with TTFont(get_input_path(OTF_FONT)) as otfont:
        params = FontPDFParams()
        params.pageIncludeTitle = 0
        pdfFont = txPDFFont(otfont, params)
        rt_canvas = Canvas("pdf_file_path")
        assert rt_canvas._code == []
        doTitle(rt_canvas, pdfFont, params, 1)
        assert rt_canvas._code == []
Ejemplo n.º 2
0
def test_doTitle_pageIncludeTitle_0():
    with TTFont(get_input_path(OTF_FONT)) as otfont:
        params = FontPDFParams()
        params.pageIncludeTitle = 0
        pdfFont = txPDFFont(otfont, params)
        rt_canvas = Canvas("pdf_file_path")
        assert rt_canvas._code == []
        doTitle(rt_canvas, pdfFont, params, 1)
        assert rt_canvas._code == []
Ejemplo n.º 3
0
def test_doTitle_pageIncludeTitle_1():
    with TTFont(get_input_path(OTF_FONT)) as otfont:
        params = FontPDFParams()
        assert params.pageIncludeTitle == 1
        pdfFont = txPDFFont(otfont, params)
        rt_canvas = Canvas("pdf_file_path")
        assert rt_canvas._code == []
        doTitle(rt_canvas, pdfFont, params, 1)
        assert len(rt_canvas._code)
        assert 'SourceSansPro-Black' in rt_canvas._code[1]
Ejemplo n.º 4
0
def test_doTitle_pageIncludeTitle_1():
    with TTFont(get_input_path(OTF_FONT)) as otfont:
        params = FontPDFParams()
        assert params.pageIncludeTitle == 1
        pdfFont = txPDFFont(otfont, params)
        rt_canvas = Canvas("pdf_file_path")
        assert rt_canvas._code == []
        doTitle(rt_canvas, pdfFont, params, 1)
        assert len(rt_canvas._code)
        assert 'SourceSansPro-Black' in rt_canvas._code[1]
Ejemplo n.º 5
0
def proofMakePDF(pathList, params, txPath):
    #    use fontTools library to open font and extract CFF table.
    #    If error, skip font and report error.
    if params.rt_doFontSet:
        pdfFontList = []
        logMsg("")
        logMsg("Collecting font data from:")
        fontCount = 0
        for path in pathList:
            fontFileName = os.path.basename(path)
            params.rt_filePath = os.path.abspath(path)
            logMsg("\t%s." % (path))
            try:
                ttFont, tempPathCFF = openFile(path, txPath)
            except FontError:
                print(
                    traceback.format_exception_only(sys.exc_type,
                                                    sys.exc_value)[-1])
                return
            try:
                fontGlyphList = ttFont.getGlyphOrder()
            except FontError:
                print(
                    traceback.format_exception_only(sys.exc_type,
                                                    sys.exc_value)[-1])
                return

            #   filter specified list, if any, with font list.
            glyphList = filterGlyphList(params, fontGlyphList, fontFileName)
            if not glyphList:
                raise FontError(
                    "Error: selected glyph list is empty for font <%s>." %
                    fontFileName)
            params.rt_reporter = logMsg

            if ttFont.has_key("CFF "):
                pdfFont = otfpdf.txPDFFont(ttFont, params)
            elif ttFont.has_key("glyf"):
                pdfFont = ttfpdf.txPDFFont(ttFont, params)
            else:
                logMsg("Quitting. Font type is not recognized. %s.." % (path))
                break
            if tempPathCFF:
                pdfFont.path = tempPathCFF
            pdfFontList.append([glyphList, pdfFont, tempPathCFF])

        doProgressBar = not params.quietMode
        pdfFilePath = makeFontSetPDF(pdfFontList, params, doProgressBar)
        for entry in pdfFontList:
            tempPathCFF = entry[2]
            pdfFont = entry[1]
            pdfFont.clientFont.close()
            if tempPathCFF:
                os.remove(tempPathCFF)

        logMsg("Wrote proof file %s. End time: %s." %
               (pdfFilePath, time.asctime()))
        if pdfFilePath and params.openPDFWhenDone:
            if curSystem == "Windows":
                command = 'start "" "%s"' % pdfFilePath
                fdkutils.runShellCmdLogging(command)
            elif curSystem == "Linux":
                command = 'xdg-open "%s" &' % pdfFilePath
                fdkutils.runShellCmdLogging(command)
            else:
                command = 'open "%s" &' % pdfFilePath
                fdkutils.runShellCmdLogging(command)

    else:
        tmpList = []
        for path in pathList:
            fontFileName = os.path.basename(path)
            params.rt_filePath = os.path.abspath(path)
            if not params.quietMode:
                logMsg("")
                logMsg("Proofing font %s. Start time: %s." %
                       (path, time.asctime()))
            try:
                ttFont, tempPathCFF = openFile(path, txPath)
                fontGlyphList = ttFont.getGlyphOrder()
            except FontError:
                print(
                    traceback.format_exception_only(sys.exc_type,
                                                    sys.exc_value)[-1])
                return

            #   filter specified list, if any, with font list.
            params.rt_glyphList = filterGlyphList(params, fontGlyphList,
                                                  fontFileName)
            if not params.rt_glyphList:
                raise FontError(
                    "Error: selected glyph list is empty for font <%s>." %
                    fontFileName)
            params.rt_reporter = logMsg

            if "CFF " in ttFont:
                pdfFont = otfpdf.txPDFFont(ttFont, params)
            elif "glyf" in ttFont:
                pdfFont = ttfpdf.txPDFFont(ttFont, params)
            else:
                logMsg("Quitting. Font type is not recognized. %s.." % (path))
                return

            if tempPathCFF:
                pdfFont.path = tempPathCFF
            doProgressBar = not params.quietMode

            pdfFilePath = makePDF(pdfFont, params, doProgressBar)
            ttFont.close()

            if tempPathCFF:
                os.remove(tempPathCFF)

            if not params.quietMode:
                logMsg("Wrote proof file %s. End time: %s." %
                       (pdfFilePath, time.asctime()))
            if pdfFilePath and params.openPDFWhenDone:
                if curSystem == "Windows":
                    command = 'start "" "%s"' % pdfFilePath
                    fdkutils.runShellCmdLogging(command)
                elif curSystem == "Linux":
                    command = 'xdg-open "%s" &' % pdfFilePath
                    fdkutils.runShellCmdLogging(command)
                else:
                    command = 'open "%s" &' % pdfFilePath
                    fdkutils.runShellCmdLogging(command)
Ejemplo n.º 6
0
def proofMakePDF(pathList, params, txPath):
	#    use fontTools library to open font and extract CFF table.
	#    If error, skip font and report error.
	if params.rt_doFontSet:
		pdfFontList = []
		logMsg("")
		logMsg( "Collecting font data from:")
		fontCount = 0
		for path in pathList:
			fontFileName = os.path.basename(path)
			params.rt_filePath = os.path.abspath(path)
			logMsg( "\t%s." % (path))
			try:
				ttFont, tempPathCFF = openFile(path, txPath)
			except FontError:
				print(traceback.format_exception_only(sys.exc_type, sys.exc_value)[-1])
				return
			try:
				fontGlyphList = ttFont.getGlyphOrder()
			except FontError:
				print(traceback.format_exception_only(sys.exc_type, sys.exc_value)[-1])
				return


			#   filter specified list, if any, with font list.
			glyphList = filterGlyphList(params, fontGlyphList, fontFileName)
			if not glyphList:
				raise FontError("Error: selected glyph list is empty for font <%s>." % fontFileName)
			params.rt_reporter = logMsg

			if ttFont.has_key("CFF "):
				pdfFont = otfpdf.txPDFFont(ttFont, params)
			elif ttFont.has_key("glyf"):
				pdfFont = ttfpdf.txPDFFont(ttFont, params)
			else:
				logMsg( "Quitting. Font type is not recognized. %s.." % (path))
				break
			if tempPathCFF:
				pdfFont.path = tempPathCFF
			pdfFontList.append([glyphList, pdfFont, tempPathCFF])

		doProgressBar = not params.quietMode
		pdfFilePath = makeFontSetPDF(pdfFontList, params, doProgressBar)
		for entry in pdfFontList:
			tempPathCFF =  entry[2]
			pdfFont = entry[1]
			pdfFont.clientFont.close()
			if tempPathCFF:
				os.remove(tempPathCFF)

		logMsg( "Wrote proof file %s. End time: %s." % (pdfFilePath, time.asctime()))
		if pdfFilePath and params.openPDFWhenDone:
			if curSystem == "Windows":
				command = 'start "" "%s"' % pdfFilePath
				fdkutils.runShellCmdLogging(command)
			elif curSystem == "Linux":
				command = 'xdg-open "%s" &' % pdfFilePath
				fdkutils.runShellCmdLogging(command)
			else:
				command = 'open "%s" &' % pdfFilePath
				fdkutils.runShellCmdLogging(command)

	else:
		tmpList = []
		for path in pathList:
			fontFileName = os.path.basename(path)
			params.rt_filePath = os.path.abspath(path)
			if not params.quietMode:
				logMsg("")
				logMsg( "Proofing font %s. Start time: %s." % (path, time.asctime()))
			try:
				ttFont, tempPathCFF = openFile(path, txPath)
				fontGlyphList = ttFont.getGlyphOrder()
			except FontError:
				print(traceback.format_exception_only(sys.exc_type, sys.exc_value)[-1])
				return

			#   filter specified list, if any, with font list.
			params.rt_glyphList = filterGlyphList(params, fontGlyphList, fontFileName)
			if not params.rt_glyphList:
				raise FontError("Error: selected glyph list is empty for font <%s>." % fontFileName)
			params.rt_reporter = logMsg

			if "CFF " in ttFont:
				pdfFont = otfpdf.txPDFFont(ttFont, params)
			elif "glyf" in ttFont:
				pdfFont = ttfpdf.txPDFFont(ttFont, params)
			else:
				logMsg( "Quitting. Font type is not recognized. %s.." % (path))
				return

			if tempPathCFF:
				pdfFont.path = tempPathCFF
			doProgressBar = not params.quietMode

			pdfFilePath = makePDF(pdfFont, params, doProgressBar)
			ttFont.close()

			if tempPathCFF:
				os.remove(tempPathCFF)

			if not params.quietMode:
				logMsg("Wrote proof file %s. End time: %s." % (pdfFilePath, time.asctime()))
			if pdfFilePath and params.openPDFWhenDone:
				if curSystem == "Windows":
					command = 'start "" "%s"' % pdfFilePath
					fdkutils.runShellCmdLogging(command)
				elif curSystem == "Linux":
					command = 'xdg-open "%s" &' % pdfFilePath
					fdkutils.runShellCmdLogging(command)
				else:
					command = 'open "%s" &' % pdfFilePath
					fdkutils.runShellCmdLogging(command)