示例#1
0
	def _set_text(self, value):
		from robofab.tools.fontlabFeatureSplitter import splitFeaturesForFontLab
		classes, features = splitFeaturesForFontLab(value)
		naked = self._object
		for OTClass in classes.splitlines():
			naked.addClassFromCode_( OTClass )
		naked.setFeatures_(None)
		for featureName, featureText in features:
			f = GSFeature()
			f.setName_(featureName)
			f.setCode_(featureText[featureText.find("{")+1: featureText.rfind( "}" )].strip(" \n"))
			naked.addFeature_(f)
示例#2
0
	def _set_text(self, value):
		from robofab.tools.fontlabFeatureSplitter import splitFeaturesForFontLab
		classes, features = splitFeaturesForFontLab(value)
		naked = self._object
		for OTClass in classes.splitlines():
			naked.addClassFromCode_( OTClass )
		naked.setFeatures_(None)
		for featureName, featureText in features:
			f = GSFeature()
			f.setName_(featureName)
			f.setCode_(featureText[featureText.find("{")+1: featureText.rfind( "}" )].strip(" \n"))
			naked.addFeature_(f)
示例#3
0
	def save(self, destDir=None, doProgress=False, formatVersion=2):
		"""Save the Font in UFO format."""
		# XXX note that when doing "save as" by specifying the destDir argument
		# _all_ glyphs get loaded into memory. This could be optimized by either
		# copying those .glif files that have not been edited or (not sure how
		# well that would work) by simply clearing out self._objects after the
		# save.
		from robofab.ufoLib import UFOWriter
		from robofab.tools.fontlabFeatureSplitter import splitFeaturesForFontLab
		# if no destination is given, or if
		# the given destination is the current
		# path, this is not a save as operation
		if destDir is None or destDir == self._path:
			saveAs = False
			destDir = self._path
		else:
			saveAs = True
		# start a progress bar
		nonGlyphCount = 5
		bar = None
		if doProgress:
			from robofab.interface.all.dialogs import ProgressBar
			bar = ProgressBar("Exporting UFO", nonGlyphCount + len(self._object.keys()))
		# write
		writer = UFOWriter(destDir, formatVersion=formatVersion)
		try:
			# make a shallow copy of the lib. stuff may be added to it.
			fontLib = dict(self.lib)
			# info
			if bar:
				bar.label("Saving info...")
			writer.writeInfo(self.info)
			if bar:
				bar.tick()
			# kerning
			if self.kerning.changed or saveAs:
				if bar:
					bar.label("Saving kerning...")
				writer.writeKerning(self.kerning.asDict())
				if bar:
					bar.tick()
			# groups
			if bar:
				bar.label("Saving groups...")
			writer.writeGroups(self.groups)
			if bar:
				bar.tick()
			# features
			if bar:
				bar.label("Saving features...")
			features = self.features.text
			if features is None:
				features = ""
			if formatVersion == 2:
				writer.writeFeatures(features)
			elif formatVersion == 1:
				classes, features = splitFeaturesForFontLab(features)
				if classes:
					fontLib["org.robofab.opentype.classes"] = classes.strip() + "\n"
				if features:
					featureDict = {}
					for featureName, featureText in features:
						featureDict[featureName] = featureText.strip() + "\n"
					fontLib["org.robofab.opentype.features"] = featureDict
					fontLib["org.robofab.opentype.featureorder"] = [featureName for featureName, featureText in features]
			if bar:
				bar.tick()
			# lib
			if formatVersion == 1:
				fontLib[postScriptHintDataLibKey] = self.psHints.asDict()
			if bar:
				bar.label("Saving lib...")
			writer.writeLib(fontLib)
			if bar:
				bar.tick()
			# glyphs
			glyphNameToFileNameFunc = self.getGlyphNameToFileNameFunc()

			glyphSet = writer.getGlyphSet(glyphNameToFileNameFunc)
			if len(self._scheduledForDeletion) != 0:
				if bar:
					bar.label("Removing deleted glyphs...")
				for glyphName in self._scheduledForDeletion:
					if glyphSet.has_key(glyphName):
						glyphSet.deleteGlyph(glyphName)
				if bar:
					bar.tick()
			if bar:
				bar.label("Saving glyphs...")
			count = nonGlyphCount
			if saveAs:
				glyphNames = self.keys()
			else:
				glyphNames = self._object.keys()
			for glyphName in glyphNames:
				glyph = self[glyphName]
				glyph.psHints._saveToLib(glyph.lib)
				glyph._saveToGlyphSet(glyphSet, glyphName=glyphName, force=saveAs)
				if bar and not count % 10:
					bar.tick(count)
				count = count + 1
			glyphSet.writeContents()
			self._glyphSet = glyphSet
		# only blindly stop if the user says to
		except KeyboardInterrupt:
			bar.close()
			bar = None
		# kill the progress bar
		if bar:
			bar.close()
		# reset internal stuff
		self._path = destDir
		self._scheduledForDeletion = []
		self.setChanged(False)
示例#4
0
    def save(self, destDir=None, doProgress=False, formatVersion=2):
        """Save the Font in UFO format."""
        # XXX note that when doing "save as" by specifying the destDir argument
        # _all_ glyphs get loaded into memory. This could be optimized by either
        # copying those .glif files that have not been edited or (not sure how
        # well that would work) by simply clearing out self._objects after the
        # save.
        from robofab.ufoLib import UFOWriter
        from robofab.tools.fontlabFeatureSplitter import splitFeaturesForFontLab
        # if no destination is given, or if
        # the given destination is the current
        # path, this is not a save as operation
        if destDir is None or destDir == self._path:
            saveAs = False
            destDir = self._path
        else:
            saveAs = True
        # start a progress bar
        nonGlyphCount = 5
        bar = None
        if doProgress:
            from robofab.interface.all.dialogs import ProgressBar
            bar = ProgressBar("Exporting UFO",
                              nonGlyphCount + len(self._object.keys()))
        # write
        writer = UFOWriter(destDir, formatVersion=formatVersion)
        try:
            # make a shallow copy of the lib. stuff may be added to it.
            fontLib = dict(self.lib)
            # info
            if bar:
                bar.label("Saving info...")
            writer.writeInfo(self.info)
            if bar:
                bar.tick()
            # kerning
            if self.kerning.changed or saveAs:
                if bar:
                    bar.label("Saving kerning...")
                writer.writeKerning(self.kerning.asDict())
                if bar:
                    bar.tick()
            # groups
            if bar:
                bar.label("Saving groups...")
            writer.writeGroups(self.groups)
            if bar:
                bar.tick()
            # features
            if bar:
                bar.label("Saving features...")
            features = self.features.text
            if features is None:
                features = ""
            if formatVersion == 2:
                writer.writeFeatures(features)
            elif formatVersion == 1:
                classes, features = splitFeaturesForFontLab(features)
                if classes:
                    fontLib["org.robofab.opentype.classes"] = classes.strip(
                    ) + "\n"
                if features:
                    featureDict = {}
                    for featureName, featureText in features:
                        featureDict[featureName] = featureText.strip() + "\n"
                    fontLib["org.robofab.opentype.features"] = featureDict
                    fontLib["org.robofab.opentype.featureorder"] = [
                        featureName for featureName, featureText in features
                    ]
            if bar:
                bar.tick()
            # lib
            if formatVersion == 1:
                fontLib[postScriptHintDataLibKey] = self.psHints.asDict()
            if bar:
                bar.label("Saving lib...")
            writer.writeLib(fontLib)
            if bar:
                bar.tick()
            # glyphs
            glyphNameToFileNameFunc = self.getGlyphNameToFileNameFunc()

            glyphSet = writer.getGlyphSet(glyphNameToFileNameFunc)
            if len(self._scheduledForDeletion) != 0:
                if bar:
                    bar.label("Removing deleted glyphs...")
                for glyphName in self._scheduledForDeletion:
                    if glyphSet.has_key(glyphName):
                        glyphSet.deleteGlyph(glyphName)
                if bar:
                    bar.tick()
            if bar:
                bar.label("Saving glyphs...")
            count = nonGlyphCount
            if saveAs:
                glyphNames = self.keys()
            else:
                glyphNames = self._object.keys()
            for glyphName in glyphNames:
                glyph = self[glyphName]
                glyph.psHints._saveToLib(glyph.lib)
                glyph._saveToGlyphSet(glyphSet,
                                      glyphName=glyphName,
                                      force=saveAs)
                if bar and not count % 10:
                    bar.tick(count)
                count = count + 1
            glyphSet.writeContents()
            self._glyphSet = glyphSet
        # only blindly stop if the user says to
        except KeyboardInterrupt:
            bar.close()
            bar = None
        # kill the progress bar
        if bar:
            bar.close()
        # reset internal stuff
        self._path = destDir
        self._scheduledForDeletion = []
        self.setChanged(False)