Ejemplo n.º 1
0
def extractTTFFontInfo(font):
	# UFO.info attribute name / index. 
	# name table entries index according to http://www.microsoft.com/typography/otspec/name.htm
	attrs = [
			('copyright', 0),
			('familyName', 1),
			('fontStyle', 1),
			('postscriptFullName', 4),
			('trademark', 7),
			('openTypeNameDesigner', 9),
			('openTypeNameLicenseURL', 14),
			('openTypeNameDesignerURL', 12),
			]
	info = RInfo()
	names = font['name']
	info.ascender = font['hhea'].ascent
	info.descender = font['hhea'].descent
	info.unitsPerEm = font['head'].unitsPerEm
	for name, index in attrs:
		entry = font["name"].getName(index, 3, 1)
		if entry is not None:
			try:
				setattr(info, name, unicode(entry.string, "utf16"))
			except:
				print "Error importing value %s: %s"%(str(name), str(info))
	return info
Ejemplo n.º 2
0
def extractTTFFontInfo(font):
    # UFO.info attribute name / index.
    # name table entries index according to http://www.microsoft.com/typography/otspec/name.htm
    attrs = [
        ('copyright', 0),
        ('familyName', 1),
        ('styleMapStyleName', 2),
        ('postscriptFullName', 4),
        ('trademark', 7),
        ('openTypeNameDesigner', 9),
        ('openTypeNameLicenseURL', 14),
        ('openTypeNameDesignerURL', 12),
    ]
    info = RInfo()
    names = font['name']
    info.ascender = font['hhea'].ascent
    info.descender = font['hhea'].descent
    info.unitsPerEm = font['head'].unitsPerEm
    for name, index in attrs:
        entry = font["name"].getName(index, 3, 1, 0x409)
        if entry is not None:
            try:
                value = unicode(entry.string, "utf_16_be")
                if name == "styleMapStyleName":
                    value = value.lower()
                setattr(info, name, value)
            except Exception, e:
                print "Error importing value %s: %s: %s" % (str(name), value,
                                                            e.message)
Ejemplo n.º 3
0
def extractTTFFontInfo(font):
	# UFO.info attribute name / index. 
	# name table entries index according to http://www.microsoft.com/typography/otspec/name.htm
	attrs = [
			('copyright', 0),
			('familyName', 1),
			('styleMapStyleName', 2),
			('postscriptFullName', 4),
			('trademark', 7),
			('openTypeNameDesigner', 9),
			('openTypeNameLicenseURL', 14),
			('openTypeNameDesignerURL', 12),
			]
	info = RInfo()
	names = font['name']
	info.ascender = font['hhea'].ascent
	info.descender = font['hhea'].descent
	info.unitsPerEm = font['head'].unitsPerEm
	for name, index in attrs:
		entry = font["name"].getName(index, 3, 1, 0x409)
		if entry is not None:
			try:
				value = unicode(entry.string, "utf_16_be")
				if name == "styleMapStyleName":
					value = value.lower()
				setattr(info, name, value)
			except Exception, e:
				print "Error importing value %s: %s: %s"%(str(name), value, e.message)
Ejemplo n.º 4
0
def extractTTFFontInfo(font):
    # UFO.info attribute name / index.
    # name table entries index according to http://www.microsoft.com/typography/otspec/name.htm
    attrs = [
        ('copyright', 0),
        ('familyName', 1),
        ('fontStyle', 1),
        ('postscriptFullName', 4),
        ('trademark', 7),
        ('openTypeNameDesigner', 9),
        ('openTypeNameLicenseURL', 14),
        ('openTypeNameDesignerURL', 12),
    ]
    info = RInfo()
    names = font['name']
    info.ascender = font['hhea'].ascent
    info.descender = font['hhea'].descent
    info.unitsPerEm = font['head'].unitsPerEm
    for name, index in attrs:
        entry = font["name"].getName(index, 3, 1)
        if entry is not None:
            try:
                setattr(info, name, unicode(entry.string, "utf16"))
            except:
                print "Error importing value %s: %s" % (str(name), str(info))
    return info
Ejemplo n.º 5
0
def extractT1FontInfo(font):
	info = RInfo()
	src = font.font['FontInfo']
	factor = font.font['FontMatrix'][0]
	assert factor > 0
	info.unitsPerEm = int(round(1/factor, 0))
	# assume something for ascender descender
	info.ascender = (info.unitsPerEm / 5) * 4
	info.descender = info.ascender - info.unitsPerEm
	info.versionMajor = font.font['FontInfo']['version']
	info.fullName = font.font['FontInfo']['FullName']
	info.familyName = font.font['FontInfo']['FullName'].split("-")[0]
	info.notice = unicode(font.font['FontInfo']['Notice'], "macroman")
	info.italicAngle = font.font['FontInfo']['ItalicAngle']
	info.uniqueID = font['UniqueID']
	return info
Ejemplo n.º 6
0
 def testRoundTripVersion1(self):
     infoObject = RInfo()
     for attr, value in fontInfoVersion1.items():
         if attr not in ufoLib.deprecatedFontInfoAttributesVersion2:
             setattr(infoObject, attr, value)
     for attr, expectedValue in fontInfoVersion1.items():
         if attr not in ufoLib.deprecatedFontInfoAttributesVersion2:
             value = getattr(infoObject, attr)
             self.assertEqual((attr, expectedValue), (attr, value))
Ejemplo n.º 7
0
    def testVersion1DeprecationRoundTrip(self):
        """
		unittest doesn't catch warnings in self.assertRaises,
		so some hackery is required to catch the warnings
		that are raised when setting deprecated attributes.
		"""
        saveStderr = sys.stderr
        tempStderr = StringIO()
        sys.stderr = tempStderr
        infoObject = RInfo()
        requiredWarnings = []
        try:
            for attr, value in fontInfoVersion1.items():
                if attr in ufoLib.deprecatedFontInfoAttributesVersion2:
                    setattr(infoObject, attr, value)
                    v = getattr(infoObject, attr)
                    self.assertEquals((attr, value), (attr, v))
                    s = "DeprecationWarning: The %s attribute has been deprecated." % attr
                    requiredWarnings.append((attr, s))
        finally:
            sys.stderr = saveStderr
        tempStderr = tempStderr.getvalue()
        for attr, line in requiredWarnings:
            self.assertEquals((attr, line in tempStderr), (attr, True))
Ejemplo n.º 8
0
 def testRoundTripVersion2(self):
     infoObject = RInfo()
     for attr, value in fontInfoVersion2.items():
         setattr(infoObject, attr, value)
         newValue = getattr(infoObject, attr)
         self.assertEqual((attr, newValue), (attr, value))
Ejemplo n.º 9
0
def extractT1FontInfo(font):
    info = RInfo()
    src = font.font['FontInfo']
    factor = font.font['FontMatrix'][0]
    assert factor > 0
    info.unitsPerEm = int(round(1 / factor, 0))
    # assume something for ascender descender
    info.ascender = (info.unitsPerEm / 5) * 4
    info.descender = info.ascender - info.unitsPerEm
    info.versionMajor = font.font['FontInfo']['version']
    info.fullName = font.font['FontInfo']['FullName']
    info.familyName = font.font['FontInfo']['FullName'].split("-")[0]
    info.notice = unicode(font.font['FontInfo']['Notice'], "macroman")
    info.italicAngle = font.font['FontInfo']['ItalicAngle']
    info.uniqueID = font['UniqueID']
    return info