예제 #1
0
파일: font.py 프로젝트: kateliev/TypeRig
    def newGlyph(self, glyph_name, layers=[], unicode_int=None):
        '''Creates new glyph and adds it to the font
		Args:
			glyph_name (str): New glyph name
			layers (list(str) or list(flLayer)): List of layers to be added to the new glyph
			unicode_int (int): Unicode int of the new glyph
		Returns:
			pGlyph
		'''

        # - Build
        base_glyph = fl6.flGlyph()
        base_glyph.name = glyph_name
        self.addGlyph(base_glyph)

        # - Get the newly added glyph (all sane methods exhausted)
        new_glyph = self.glyph(glyph_name)

        # - Set Unicode
        if unicode_int is not None: new_glyph.fg.setUnicode(unicode_int)

        # - Add layers
        if len(layers):
            for layer in layers:
                if isinstance(layer, basestring):
                    new_layer = fl6.flLayer()
                    new_layer.name = layer
                    new_glyph.addLayer(new_layer)

                elif isinstance(layer, fl6.flLayer):
                    new_glyph.addLayer(layer)

        # - Add to font
        return new_glyph
예제 #2
0
파일: font.py 프로젝트: kateliev/TypeRig
    def newGlyphFromRecipe(self,
                           glyph_name,
                           recipe,
                           layers=[],
                           unicode_int=None,
                           rtl=False):
        ''' Generate new glyph (glyph_name) using String Recipe (recipe)
		Args:
			glyph_name (str): New glyph name
			recipe (str): Glyph composition recipe using OLD Fontlab syntax (ex. A+acute=Aacute)
			layers (list(str)): List of layer names to be added
			unicode_int (int): Unicode int of the new glyph
			rtl (bool): Right to left
		Returns:
			pGlyph
		'''

        # - Prepare
        advanceWidth = 0  #!!! Figure it out later
        prepared_layers = []

        for layer_name in layers:
            layer_fontMetrics = fl6.FontMetrics(self.fl, layer_name)
            new_layer = fl6.flLayer(layer_name)
            gen_component = self.fl.generateGlyph(recipe, layer_name,
                                                  layer_fontMetrics, rtl)
            new_layer.setGlyphComponents(gen_component, advanceWidth, self.fl,
                                         True)
            prepared_layers.append(new_layer)

        new_glyph = self.newGlyph(glyph_name, prepared_layers, unicode_int)
        return new_glyph
예제 #3
0
	def blendLayers(self, layerA, layerB, blendTimes, outputFL=True, blendMode=0, engine='fg'):
		'''Blend two layers at given times (anisotropic support).
		Args:
			layerA (flLayer), layerB (flLayer): Shapes to be interpolated
			blendTimes (int or float or tuple(float, float)): (int) for percent 0%-100% or (float) time for both X,Y or tuple(float,float) times for anisotropic blending
			outputFL (bool): Return blend native format or flShape (default)
			blendMode (int): ?
			engine (str): 'fg' for FontGate (in-build).

		Returns:
			flLayer
		'''
		from typerig.brain import linInterp

		if isinstance(blendTimes, tuple): blendTimes = pqt.QtCore.QPointF(*blendTimes)
		if isinstance(blendTimes, int): blendTimes = pqt.QtCore.QPointF(float(blendTimes)/100, float(blendTimes)/100)
		if isinstance(blendTimes, float): blendTimes = pqt.QtCore.QPointF(blendTimes, blendTimes)

		if layerA.isCompatible(layerB, True):
			# - Init
			blendLayer = fl6.flLayer('B:%s %s, t:%s' %(layerA.name, layerB.name, str(blendTimes)))
			
			# - Set and interpolate metrics
			blendLayer.advanceWidth = int(linInterp(layerA.advanceWidth, layerB.advanceWidth, blendTimes.x()))
			
			# - Interpolate shapes
			for shapeA in layerA.shapes:
				for shapeB in layerB.shapes:
					if shapeA.isCompatible(shapeB, True):
						tempBlend = self.blendShapes(shapeA, shapeB, blendTimes, outputFL, blendMode, engine)
						blendLayer.addShape(tempBlend)

			return blendLayer
예제 #4
0
			def fgInterpolator(tx, ty):
				tempLayer = fl6.flLayer('B:%s %s, t:%s' %(l0.name, l1.name, (tx, ty)))
				
				for shapePair in shapes:
					tempBlend = fl6.flShape(fgt.fgShape(shapePair[0], shapePair[1], tx, ty, 0))
					tempLayer.addShape(tempBlend)

				return tempLayer
예제 #5
0
 def addLayer(self):
     if self.aux.doCheck():
         newLayer = fl6.flLayer()
         newLayer.name = str(self.edt_name.text)
         self.aux.glyph.addLayer(newLayer)
         self.aux.glyph.updateObject(self.aux.glyph.fl,
                                     'Add Layer: %s.' % newLayer.name)
         self.aux.glyph.update()
         self.aux.refresh()
예제 #6
0
파일: Layer.py 프로젝트: kateliev/TypeRig
 def layer_add(parent):
     if parent.doCheck():
         user_input = TR1FieldDLG(
             'Add new layer ', 'Please enter a name for the layer created.',
             'Name:').values
         newLayer = fl6.flLayer()
         newLayer.name = str(user_input)
         parent.glyph.addLayer(newLayer)
         parent.glyph.updateObject(parent.glyph.fl,
                                   'Add Layer: %s.' % newLayer.name)
         parent.refresh()
예제 #7
0
	def copyLayer(self, glyph, srcLayerName, dstLayerName, options, cleanDST=False, addLayer=False):
		# -- Check if srcLayerExists
		if glyph.layer(srcLayerName) is None:
			print 'WARN:\tGlyph: %s\tMissing source layer: %s\tSkipped!' %(glyph.name, srcLayerName)
			return

		# -- Check if dstLayerExists
		if glyph.layer(dstLayerName) is None:
			print 'WARN:\tGlyph: %s\tMissing destination layer: %s\tAdd new: %s.' %(glyph.name, dstLayerName, addLayer)
			
			if addLayer:
				newLayer = fl6.flLayer()
				newLayer.name = str(dstLayerName)
				glyph.addLayer(newLayer)
			else:
				return

		# -- Outline
		if options['out']:
			# --- Get shapes
			srcShapes = glyph.shapes(srcLayerName)

			# --- Cleanup destination layers
			if cleanDST:
				glyph.layer(dstLayerName).removeAllShapes()
			
			# --- Copy/Paste shapes
			for shape in srcShapes:
				newShape = glyph.layer(dstLayerName).addShape(shape.cloneTopLevel())

		# -- Metrics
		if options['lsb']: glyph.setLSB(glyph.getRSB(srcLayerName), dstLayerName)
		if options['adv']: glyph.setAdvance(glyph.getAdvance(srcLayerName), dstLayerName)
		if options['rsb']: glyph.setRSB(glyph.getRSB(srcLayerName), dstLayerName)
		if options['lnk']:
			glyph.setLSBeq(glyph.getSBeq(srcLayerName)[0], dstLayerName)
			glyph.setRSBeq(glyph.getSBeq(srcLayerName)[1], dstLayerName)

		# -- Anchors
		if options['anc']:
			if cleanDST:
				glyph.clearAnchors(dstLayerName)

			for src_anchor in glyph.anchors(srcLayerName):
				glyph.layer(dstLayerName).addAnchor(src_anchor)