def compareToUFO(self, doInfo=True, doKerning=True, doGroups=True, doLib=True, doFeatures=True):
		reader = UFOReader(self.ufoPath)
		results = {}
		if doInfo:
			infoMatches = True
			info = self.font.info
			for attr, expectedValue in fontInfoVersion2.items():
				# cheat by skipping attrs that aren't supported
				if info._ufoToFLAttrMapping[attr]["nakedAttribute"] is None:
					continue
				writtenValue = getattr(info, attr)
				if expectedValue != writtenValue:
					infoMatches = False
					break
			results["info"]= infoMatches
		if doKerning:
			kerning = self.font.kerning.asDict()
			expectedKerning = reader.readKerning()
			results["kerning"] = expectedKerning == kerning
		if doGroups:
			groups = dict(self.font.groups)
			expectedGroups = reader.readGroups()
			results["groups"] = expectedGroups == groups
		if doFeatures:
			features = self.font.features.text
			expectedFeatures = reader.readFeatures()
			results["features"] = expectedFeatures == features
		if doLib:
			lib = dict(self.font.lib)
			expectedLib = reader.readLib()
			results["lib"] = expectedLib == lib
		return results
Beispiel #2
0
def extractFontFromUFO(pathOrFile, destination, doGlyphs=True, doInfo=True, doKerning=True, doGroups=True, doFeatures=True, doLib=True, customFunctions=[]):
    source = UFOReader(pathOrFile)
    if doInfo:
        source.readInfo(destination.info)
    if doKerning:
        kerning = source.readKerning()
        destination.kerning.update(kerning)
    if doGroups:
        groups = source.readGroups()
        destination.groups.update(groups)
    if doFeatures:
        features = source.readFeatures()
        destination.features.text = features
    if doLib:
        lib = source.readLib()
        destination.lib.update(lib)
    if doGlyphs:
        glyphSet = source.getGlyphSet()
        for glyphName in glyphSet.keys():
            destination.newGlyph(glyphName)
            glyph = destination[glyphName]
            pointPen = glyph.getPointPen()
            glyphSet.readGlyph(glyphName=glyphName, glyphObject=glyph, pointPen=pointPen)
    for function in customFunctions:
        function(source, destination)
Beispiel #3
0
def extractFontFromUFO(pathOrFile,
                       destination,
                       doGlyphs=True,
                       doInfo=True,
                       doKerning=True,
                       doGroups=True,
                       doFeatures=True,
                       doLib=True,
                       customFunctions=[]):
    source = UFOReader(pathOrFile)
    if doInfo:
        source.readInfo(destination.info)
    if doKerning:
        kerning = source.readKerning()
        destination.kerning.update(kerning)
    if doGroups:
        groups = source.readGroups()
        destination.groups.update(groups)
    if doFeatures:
        features = source.readFeatures()
        destination.features.text = features
    if doLib:
        lib = source.readLib()
        destination.lib.update(lib)
    if doGlyphs:
        glyphSet = source.getGlyphSet()
        for glyphName in glyphSet.keys():
            destination.newGlyph(glyphName)
            glyph = destination[glyphName]
            pointPen = glyph.getPointPen()
            glyphSet.readGlyph(glyphName=glyphName,
                               glyphObject=glyph,
                               pointPen=pointPen)
    for function in customFunctions:
        function(source, destination)
	def compareToUFO(self, doInfo=True):
		reader = UFOReader(ufoPath2)
		results = {}
		# info
		infoMatches = True
		info = self.font.info
		for attr, expectedValue in fontInfoVersion2.items():
			writtenValue = getattr(info, attr)
			if expectedValue != writtenValue:
				infoMatches = False
				break
		results["info"]= infoMatches
		# kerning
		kerning = self.font.kerning.asDict()
		expectedKerning = reader.readKerning()
		results["kerning"] = expectedKerning == kerning
		# groups
		groups = dict(self.font.groups)
		expectedGroups = reader.readGroups()
		results["groups"] = expectedGroups == groups
		# features
		features = self.font.features.text
		expectedFeatures = reader.readFeatures()
		results["features"] = expectedFeatures == features
		# lib
		lib = dict(self.font.lib)
		expectedLib = reader.readLib()
		results["lib"] = expectedLib == lib
		return results
Beispiel #5
0
	def _loadData(self, path):
		from robofab.ufoLib import UFOReader
		reader = UFOReader(path)
		fontLib = reader.readLib()
		# info
		reader.readInfo(self.info)
		# kerning
		self.kerning.update(reader.readKerning())
		self.kerning.setChanged(False)
		# groups
		self.groups.update(reader.readGroups())
		# features
		if reader.formatVersion == 1:
			# migrate features from the lib
			features = []
			classes = fontLib.get("org.robofab.opentype.classes")
			if classes is not None:
				del fontLib["org.robofab.opentype.classes"]
				features.append(classes)
			splitFeatures = fontLib.get("org.robofab.opentype.features")
			if splitFeatures is not None:
				order = fontLib.get("org.robofab.opentype.featureorder")
				if order is None:
					order = splitFeatures.keys()
					order.sort()
				else:
					del fontLib["org.robofab.opentype.featureorder"]
				del fontLib["org.robofab.opentype.features"]
				for tag in order:
					oneFeature = splitFeatures.get(tag)
					if oneFeature is not None:
						features.append(oneFeature)
			features = "\n".join(features)
		else:
			features = reader.readFeatures()
		self.features.text = features
		# hint data
		self.psHints = PostScriptFontHintValues(self)
		if postScriptHintDataLibKey in fontLib:
			del fontLib[postScriptHintDataLibKey]
		# lib
		self.lib.update(fontLib)
		# glyphs
		self._glyphSet = reader.getGlyphSet()
		self._hasNotChanged(doGlyphs=False)
Beispiel #6
0
 def _loadData(self, path):
     from robofab.ufoLib import UFOReader
     reader = UFOReader(path)
     fontLib = reader.readLib()
     # info
     reader.readInfo(self.info)
     # kerning
     self.kerning.update(reader.readKerning())
     self.kerning.setChanged(False)
     # groups
     self.groups.update(reader.readGroups())
     # features
     if reader.formatVersion == 1:
         # migrate features from the lib
         features = []
         classes = fontLib.get("org.robofab.opentype.classes")
         if classes is not None:
             del fontLib["org.robofab.opentype.classes"]
             features.append(classes)
         splitFeatures = fontLib.get("org.robofab.opentype.features")
         if splitFeatures is not None:
             order = fontLib.get("org.robofab.opentype.featureorder")
             if order is None:
                 order = splitFeatures.keys()
                 order.sort()
             else:
                 del fontLib["org.robofab.opentype.featureorder"]
             del fontLib["org.robofab.opentype.features"]
             for tag in order:
                 oneFeature = splitFeatures.get(tag)
                 if oneFeature is not None:
                     features.append(oneFeature)
         features = "\n".join(features)
     else:
         features = reader.readFeatures()
     self.features.text = features
     # hint data
     self.psHints = PostScriptFontHintValues(self)
     if postScriptHintDataLibKey in fontLib:
         del fontLib[postScriptHintDataLibKey]
     # lib
     self.lib.update(fontLib)
     # glyphs
     self._glyphSet = reader.getGlyphSet()
     self._hasNotChanged(doGlyphs=False)
	def compareToUFO(self, doInfo=True):
		reader = UFOReader(ufoPath1)
		results = {}
		# info
		infoMatches = True
		info = self.font.info
		for attr, expectedValue in expectedFontInfo1To2Conversion.items():
			writtenValue = getattr(info, attr)
			if expectedValue != writtenValue:
				infoMatches = False
				break
		results["info"]= infoMatches
		# kerning
		kerning = self.font.kerning.asDict()
		expectedKerning = reader.readKerning()
		results["kerning"] = expectedKerning == kerning
		# groups
		groups = dict(self.font.groups)
		expectedGroups = reader.readGroups()
		results["groups"] = expectedGroups == groups
		# features
		features = self.font.features.text
		f = open(os.path.join(ufoPath2, "features.fea"), "r")
		expectedFeatures = f.read()
		f.close()
		match = True
		features = [line for line in features.splitlines() if line]
		expectedFeatures = [line for line in expectedFeatures.splitlines() if line]
		if expectedFeatures != features or reader.readFeatures() != "":
			match = False
		results["features"] = match
		# lib
		lib = dict(self.font.lib)
		expectedLib = reader.readLib()
		for key in removeFromFormatVersion1Lib:
			if key in expectedLib:
				del expectedLib[key]
		results["lib"] = expectedLib == lib
		return results
Beispiel #8
0
 def compareToUFO(self,
                  doInfo=True,
                  doKerning=True,
                  doGroups=True,
                  doLib=True,
                  doFeatures=True):
     reader = UFOReader(self.ufoPath)
     results = {}
     if doInfo:
         infoMatches = True
         info = self.font.info
         for attr, expectedValue in fontInfoVersion2.items():
             # cheat by skipping attrs that aren't supported
             if info._ufoToFLAttrMapping[attr]["nakedAttribute"] is None:
                 continue
             writtenValue = getattr(info, attr)
             if expectedValue != writtenValue:
                 infoMatches = False
                 break
         results["info"] = infoMatches
     if doKerning:
         kerning = self.font.kerning.asDict()
         expectedKerning = reader.readKerning()
         results["kerning"] = expectedKerning == kerning
     if doGroups:
         groups = dict(self.font.groups)
         expectedGroups = reader.readGroups()
         results["groups"] = expectedGroups == groups
     if doFeatures:
         features = self.font.features.text
         expectedFeatures = reader.readFeatures()
         results["features"] = expectedFeatures == features
     if doLib:
         lib = dict(self.font.lib)
         expectedLib = reader.readLib()
         results["lib"] = expectedLib == lib
     return results