Exemplo n.º 1
0
def prune_pre_subset(self, font, options):
    cff = self.cff
    # CFF table must have one font only
    cff.fontNames = cff.fontNames[:1]

    if options.notdef_glyph and not options.notdef_outline:
        for fontname in cff.keys():
            font = cff[fontname]
            c, fdSelectIndex = font.CharStrings.getItemAndSelector('.notdef')
            if hasattr(font, 'FDArray') and font.FDArray is not None:
                private = font.FDArray[fdSelectIndex].Private
            else:
                private = font.Private
            dfltWdX = private.defaultWidthX
            nmnlWdX = private.nominalWidthX
            pen = NullPen()
            c.draw(pen)  # this will set the charstring's width
            if c.width != dfltWdX:
                c.program = [c.width - nmnlWdX, 'endchar']
            else:
                c.program = ['endchar']

    # Clear useless Encoding
    for fontname in cff.keys():
        font = cff[fontname]
        # https://github.com/behdad/fonttools/issues/620
        font.Encoding = "StandardEncoding"

    return True  # bool(cff.fontNames)
 def test_getGlyphSet(self):
     font = t1Lib.T1Font(PFA)
     glyphs = font.getGlyphSet()
     i = random.randrange(len(glyphs))
     aglyph = list(glyphs.values())[i]
     self.assertTrue(hasattr(aglyph, 'draw'))
     self.assertFalse(hasattr(aglyph, 'width'))
     aglyph.draw(NullPen())
     self.assertTrue(hasattr(aglyph, 'width'))
Exemplo n.º 3
0
def _empty_charstring(font, glyphName, isCFF2, ignoreWidth=False):
	c, fdSelectIndex = font.CharStrings.getItemAndSelector(glyphName)
	if isCFF2 or ignoreWidth:
		# CFF2 charstrings have no widths nor 'endchar' operators
		c.decompile()
		c.program = [] if isCFF2 else ['endchar']
	else:
		if hasattr(font, 'FDArray') and font.FDArray is not None:
			private = font.FDArray[fdSelectIndex].Private
		else:
			private = font.Private
		dfltWdX = private.defaultWidthX
		nmnlWdX = private.nominalWidthX
		pen = NullPen()
		c.draw(pen)  # this will set the charstring's width
		if c.width != dfltWdX:
			c.program = [c.width - nmnlWdX, 'endchar']
		else:
			c.program = ['endchar']
Exemplo n.º 4
0
 def __init__(self):
     NullPen.__init__(self)
     self.exists = False