def pasteExpr(self): font = pFont() dstGlyphs = {glyph.name: glyph for glyph in font.pGlyphs()} print 'WARN:\t Pasting Metric expressions to Font:%s;' % font.name for glyphName, glyphMetrics in self.srcGlyphBounds.iteritems(): if glyphName in dstGlyphs: wGlyph = dstGlyphs[glyphName] if self.cmb_mode.currentIndex == 1: for layer in wGlyph.masters(): if glyphMetrics.has_key(layer.name): wGlyph.setLSBeq(glyphMetrics[layer.name][0], layer.name) wGlyph.setRSBeq(glyphMetrics[layer.name][1], layer.name) wGlyph.setADVeq(glyphMetrics[layer.name][2], layer.name) wGlyph.update() print 'PASTE MM:\t Glyph: /%s;\tLayer: %s;\tExp(LSB, RSB, ADV): %s.' % ( glyphName, layer.name, glyphMetrics) else: print 'WARN:\t Glyph /%s - Layer %s not found!' % glyphName, layerName else: wGlyph.setLSBeq(glyphMetrics[0]) wGlyph.setRSBeq(glyphMetrics[1]) wGlyph.setADVeq(glyphMetrics[2]) wGlyph.update() print 'PASTE:\t Glyph: /%s;\tLayer: %s;\tExp(LSB, RSB, ADV): %s.' % ( glyphName, wGlyph.layer().name, glyphMetrics) else: print 'SKIP:\t Glyph /%s not found.' % glyphName fl6.Update(CurrentFont())
def process_lerp(self): if self.chk_setAxis.isChecked(): try: tx = self.mixer_dx.sld_axis.value / float( self.mixer_dx.edt_1.text) except ZeroDivisionError: tx = 0. dst_array = [ self.lerpXY(item[0], item[1], tx, tx) for item in self.process_array ] self.aux.glyph._setCoordArray(dst_array) self.aux.glyph.update() fl6.Update(self.aux.glyph.fl)
def pasteAnchor(self): font = pFont() dst_glyphs = {glyph.name: glyph for glyph in font.pGlyphs()} print 'WARN:\t Pasting Glyph Anchors to Font:%s;' % font.name for glyph_name, layer_anchors in self.srcGlyphAnchors.iteritems(): if glyph_name in dst_glyphs: w_glyph = dst_glyphs[glyph_name] if self.cmb_mode.currentIndex == 1: # - All master layers for layer in w_glyph.masters(): if layer_anchors.has_key(layer.name): w_glyph.clearAnchors(layer.name) for anchor_name, anchor_pos in layer_anchors[ layer.name]: w_glyph.addAnchor(anchor_pos, anchor_name, layer.name) print 'PASTE MM:\t Glyph: /%s;\tLayer: %s.' % ( glyph_name, layer.name) else: print 'WARN:\t Glyph /%s - Layer %s not found!' % ( glyph_name, layer.name) else: # - Active Layer only w_glyph.clearAnchors() for anchor_name, anchor_pos in layer_anchors: w_glyph.addAnchor(anchor_pos, anchor_name) print 'PASTE:\t Glyph: /%s;\tLayer: %s.' % ( glyph_name, w_glyph.layer().name) if self.cmb_flag.currentText != 'None': w_glyph.setMark( QtGui.QColor(self.cmb_flag.currentText).hue()) else: print 'SKIP:\t Glyph /%s not found.' % glyph_name fl6.Update(CurrentFont())
def execute_scale(self): if len(self.axis_points): # - Stems curr_sw_dx = float(self.mixer_dx.sld_axis.value) curr_sw_dy = float(self.mixer_dy.sld_axis.value) # - Scaling sx = float(self.scalerX.sld_axis.value)/100. sy = float(self.scalerY.sld_axis.value)/100. # - Options opt_extrapolate = self.head.btn_setExtrapolate.isChecked() opt_italic = radians(-float(self.italic_angle)) if self.head.btn_setItalic.isChecked() else 0. # - Process self.glyph._setPointArray(self.axis_points.scale_by_stem((curr_sw_dx, curr_sw_dy), (sx,sy), (0.,0.), (0.,0.), opt_italic, extrapolate=opt_extrapolate)) self.glyph.update() #fl6.Update(fl6.CurrentGlyph()) fl6.Update(self.glyph.fl)
def scalerMM(glyph, sx, sy, t): if len(glyph.axis): #mms = transform.adaptive_scale([glyph.axis[0].x, glyph.axis[0].y], [glyph.axis[1].x, glyph.axis[1].y], [sw_V[0], sw_H[0]], [sw_V[1], sw_H[1]], [sx, sy], [dx, dy], [t, t], scmp, angle) if useFortran: # Original Fortran 95 implementation mms = lambda sx, sy, t: transform.adaptive_scale([ glyph.axis[0].x, glyph.axis[0].y ], [glyph.axis[1].x, glyph.axis[1].y ], [sw_V[0], sw_H[0]], [sw_V[1], sw_H[ 1]], [sx, sy], [dx, dy], [t, t], scmp, angle) else: # NumPy implementation mms = lambda sx, sy, t: transform.adaptive_scale( [glyph.axis[0].x, glyph.axis[0].y ], [glyph.axis[1].x, glyph.axis[1].y], sx, sy, dx, dy, t, t, scmp[0], scmp[1], angle, sw_V0, sw_V1) glyph._setCoordArray(mms(sx, sy, tx)) for contour in glyph.contours(): contour.changed() fl6.Update(glyph.fg)
def process_scale(self, glyph, layerIndex=None, anisotropic=False, live_update=False, keep_metrics=False): wGlyph = glyph config_data = self.tab_masters.getRow(layerIndex) if len(self.data_PointArrays.keys() ) and wGlyph.name in self.data_PointArrays.keys(): # - Backup Metrics if keep_metrics: data_lsb, data_rsb = wGlyph.getLSB( config_data[0]), wGlyph.getRSB(config_data[0]) data_lsb_eq, data_rsb_eq = wGlyph.getSBeq(config_data[0]) # - Axis a = self.data_PointArrays[wGlyph.name][config_data[1]] b = self.data_PointArrays[wGlyph.name][config_data[2]] # - Compensation scmp = float(config_data[11]), float(config_data[12]) # - Italic Angle if self.chk_italic.isChecked(): angle = radians(float(self.italic_angle)) else: angle = 0 # - Stems sw_dx = [float(config_data[3]), float(config_data[4])] sw_dy = [float(config_data[5]), float(config_data[6])] if live_update: curr_sw_dx = float(self.mixer_dx.sld_axis.value) curr_sw_dy = float(self.mixer_dy.sld_axis.value) else: curr_sw_dx = float(config_data[7]) curr_sw_dy = float(config_data[8]) # - Stem values sw_dx0, sw_dx1 = sorted(sw_dx) sw_dy0, sw_dy1 = sorted(sw_dy) # - Interpolation times tx = transform.timer(curr_sw_dx, sw_dx0, sw_dx1, self.chk_boundry.isChecked()) ty = transform.timer(curr_sw_dy, sw_dy0, sw_dy1, self.chk_boundry.isChecked()) # - Scaling if live_update: sx = 100. / float(self.scaler_dx.edt_1.text) + float( self.scaler_dx.sld_axis.value) / float( self.scaler_dx.edt_1.text) sy = 100. / float(self.scaler_dy.edt_1.text) + float( self.scaler_dy.sld_axis.value) / float( self.scaler_dy.edt_1.text) else: sx = float(config_data[9]) / 100 # scale X sy = float(config_data[10]) / 100 # scale Y dx, dy = 0.0, 0.0 # shift X, Y # - Build # -- Numpy #mm_scaler = lambda sx, sy, tx, ty : transform.adaptive_scale_array([a.x, a.y], [b.x, b.y], sx, sy, dx, dy, tx, ty, scmp[0], scmp[1], angle, [sw_dx0, sw_dx1, sw_dy0, sw_dy1]) # -- Native joined_array = zip(a.tuple, b.tuple) mm_scaler = lambda sx, sy, tx, ty: transform.adaptive_scale_array( joined_array, (sx, sy), (dx, dy), (tx, ty), (scmp[0], scmp[1]), angle, [sw_dx0, sw_dx1, sw_dy0, sw_dy1]) if anisotropic: # - Dual axis mixer - anisotropic wGlyph._setPointArray(mm_scaler(sx, sy, tx, ty), layer=config_data[0]) else: # - Single axis mixer wGlyph._setPointArray(mm_scaler(sx, sy, tx, tx), layer=config_data[0]) if live_update: wGlyph.update() fl6.Update(wGlyph.fl) # - Restore metrics if keep_metrics: wGlyph.setLSB(data_lsb) wGlyph.setRSB(data_rsb) wGlyph.setLSBeq(data_lsb_eq) wGlyph.setRSBeq(data_rsb_eq)
def process_scale(self, anisotropic=False, process=False, true_update=False): if len(self.axis): # - Axis a = self.axis[0] b = self.axis[1] # - Compensation scmp = float(self.head.spb_compH.value), float( self.head.spb_compV.value) # - Italic Angle if self.head.chk_italic.isChecked(): angle = radians(-float(self.italic_angle)) else: angle = 0 # - Stems sw_dx = (float(self.head.edt_stemV0.text), float(self.head.edt_stemV1.text)) sw_dy = (float(self.head.edt_stemH0.text), float(self.head.edt_stemH1.text)) curr_sw_dx = float(self.mixer_dx.sld_axis.value) curr_sw_dy = float(self.mixer_dy.sld_axis.value) sw_dx0, sw_dx1 = min(*sw_dx), max(*sw_dx) sw_dy0, sw_dy1 = min(*sw_dy), max(*sw_dy) # - Interpolation tx = ((curr_sw_dx - sw_dx0) / (sw_dx1 - sw_dx0)) * (1, -1)[sw_dx[0] > sw_dx[1]] + ( 0, 1)[sw_dx[0] > sw_dx[1]] ty = ((curr_sw_dy - sw_dy0) / (sw_dy1 - sw_dy0)) * (1, -1)[sw_dy[0] > sw_dy[1]] + ( 0, 1)[sw_dy[0] > sw_dy[1]] # - Scaling sx = 100. / float(self.scaler_dx.edt_1.text) + float( self.scaler_dx.sld_axis.value) / float( self.scaler_dx.edt_1.text) sy = 100. / float(self.scaler_dy.edt_1.text) + float( self.scaler_dy.sld_axis.value) / float( self.scaler_dy.edt_1.text) dx, dy = 0.0, 0.0 # - Build if useFortran: # Original Fortran 95 implementation mm_scaler = lambda sx, sy, tx, ty: transform.adaptive_scale( [a.x, a.y], [b.x, b.y], [sw_dx[0], sw_dy[0]], [ sw_dx[1], sw_dy[1] ], [sx, sy], [dx, dy], [tx, ty], scmp, angle) else: # NumPy implementation mm_scaler = lambda sx, sy, tx, ty: transform.adaptive_scale( [a.x, a.y], [b.x, b.y], sx, sy, dx, dy, tx, ty, scmp[ 0], scmp[1], angle, sw_dx0, sw_dx1) if process: ''' # - Keep width constant for weight change if self.btn_revWidth.isChecked(): glyph_width = self.glyph.getBounds().width() scale_result = mm_scaler(sx, sy, tx, ty) max_width = scale_result.T[0].max() - scale_result.T[0].min() sx = float(glyph_width)/max_width #ratfrac(min(max_width, glyph_width), max(max_width, glyph_width), 1.) ''' # - Process if anisotropic: # - Single axis mixer self.glyph._setCoordArray(mm_scaler(sx, sy, tx, ty)) else: # - Dual axis mixer - anisotropic self.glyph._setCoordArray(mm_scaler(sx, sy, tx, tx)) if not true_update: self.glyph.update() #fl6.Update(fl6.CurrentGlyph()) fl6.Update(self.glyph.fl) else: self.glyph.update() self.glyph.updateObject( self.glyph.fl, 'Glyph: %s | Mixer | sx: %s; sy: %s; tx: %s; ty: %s.' % (self.glyph.name, sx, sy, tx, ty)) else: # - Just return output #return mm_scaler(sx, sy, tx, ty) scale_result = mm_scaler(sx, sy, tx, ty) self.tail.edt_width_t.setText(scale_result.T[0].max() - scale_result.T[0].min()) self.tail.edt_height_t.setText(scale_result.T[1].max() - scale_result.T[1].min())
def process_scale(self, glyph, layerIndex=None, anisotropic=False, live_update=False, keep_metrics=False): wGlyph = glyph config_data = self.tab_masters.getRow(layerIndex) if len(self.data_coordArrays.keys() ) and wGlyph.name in self.data_coordArrays.keys(): # - Backup Metrics if keep_metrics: data_lsb, data_rsb = wGlyph.getLSB( config_data[0]), wGlyph.getRSB(config_data[0]) data_lsb_eq, data_rsb_eq = wGlyph.getSBeq(config_data[0]) # - Axis a = self.data_coordArrays[wGlyph.name][config_data[1]] b = self.data_coordArrays[wGlyph.name][config_data[2]] # - Compensation scmp = float(config_data[11]), float(config_data[12]) # - Italic Angle if self.chk_italic.isChecked(): angle = radians(-float(self.italic_angle)) else: angle = 0 # - Stems sw_dx = (float(config_data[3]), float(config_data[4])) sw_dy = (float(config_data[5]), float(config_data[6])) if live_update: curr_sw_dx = float(self.mixer_dx.sld_axis.value) curr_sw_dy = float(self.mixer_dy.sld_axis.value) else: curr_sw_dx = float(config_data[7]) curr_sw_dy = float(config_data[8]) sw_dx0, sw_dx1 = min(*sw_dx), max(*sw_dx) sw_dy0, sw_dy1 = min(*sw_dy), max(*sw_dy) # !!! Very crude boundry error fix if self.chk_boundry.isChecked() and curr_sw_dx == sw_dx1: sw_dx1 += 1 if self.chk_boundry.isChecked() and curr_sw_dy == sw_dy1: sw_dy1 += 1 # - Interpolation try: tx = ((curr_sw_dx - sw_dx0) / (sw_dx1 - sw_dx0)) * (1, -1)[sw_dx[0] > sw_dx[1]] + ( 0, 1)[sw_dx[0] > sw_dx[1]] except ZeroDivisionError: tx = 0. try: ty = ((curr_sw_dy - sw_dy0) / (sw_dy1 - sw_dy0)) * (1, -1)[sw_dy[0] > sw_dy[1]] + ( 0, 1)[sw_dy[0] > sw_dy[1]] except ZeroDivisionError: ty = 0. # - Scaling if live_update: sx = 100. / float(self.scaler_dx.edt_1.text) + float( self.scaler_dx.sld_axis.value) / float( self.scaler_dx.edt_1.text) sy = 100. / float(self.scaler_dy.edt_1.text) + float( self.scaler_dy.sld_axis.value) / float( self.scaler_dy.edt_1.text) else: sx = float(config_data[9]) / 100 # scale X sy = float(config_data[10]) / 100 # scale Y dx, dy = 0.0, 0.0 # shift X, Y # - Build mm_scaler = lambda sx, sy, tx, ty: transform.adaptive_scaleXY( [a.x, a.y], [b.x, b.y], sx, sy, dx, dy, tx, ty, scmp[0], scmp[ 1], angle, [sw_dx0, sw_dx1, sw_dy0, sw_dy1]) if anisotropic: # - Dual axis mixer - anisotropic wGlyph._setCoordArray(mm_scaler(sx, sy, tx, ty), layer=config_data[0]) else: # - Single axis mixer wGlyph._setCoordArray(mm_scaler(sx, sy, tx, tx), layer=config_data[0]) if live_update: wGlyph.update() fl6.Update(wGlyph.fl) # - Restore metrics if keep_metrics: wGlyph.setLSB(data_lsb) wGlyph.setRSB(data_rsb) wGlyph.setLSBeq(data_lsb_eq) wGlyph.setRSBeq(data_rsb_eq)
def updateFont(f=None): f = f if f else CurrentFont() f.update() #lf = fl6.flPackage(f) #fl6.flItems.notifyPackageContentUpdated(lf.id) fl6.Update(f)
def applyTransform(self): # - Init activeFont = pFont() inp_x, inp_y = float(self.edt_x.text), float(self.edt_y.text) def transformGlyph(glyph, layer, matrix): ''' if glyph.hasLayer(layer): for shape in glyph.listUnboundShapes(layer): tShape = pShape(shape) if not tShape.isChanged(): for node in tShape.nodes(): tNode = matrix.applyTransformation(node.x, node.y) node.setXY(*tNode) tShape.fl.update() glyph.update() #glyph.updateObject(glyph.fl, 'DONE:\tTransform:\t Glyph /%s;\tLayer: %s' %(glyph.name, layer)) print 'DONE:\tTransform:\t Glyph /%s;\tLayer: %s' %(glyph.name, layer) else: print 'ERROR:\tNot found:\t Glyph /%s;\tLayer: %s' %(glyph.name, layer) ''' if glyph.hasLayer(layer): if not len(glyph.hasGlyphComponents()): for node in glyph.nodes(layer): tNode = matrix.applyTransformation(node.x, node.y) node.setXY(*tNode) glyph.update() glyph.updateObject( glyph.fl, 'DONE:\tTransform:\t Glyph /%s;\tLayer: %s' % (glyph.name, layer)) else: print 'ERROR:\tNot found:\t Glyph /%s;\tLayer: %s' % ( glyph.name, layer) # - Set parameters if self.cmb_glyphset.currentIndex == 0: workSet = activeFont.pGlyphs() elif self.cmb_glyphset.currentIndex == 1: workSet = activeFont.selected_pGlyphs() else: workSet = [] if self.cmb_layer.currentIndex == 0: wLayer = None else: wLayer = activeFont.masters() # - Set Transformation if self.cmb_transform.currentIndex == 0: workTrans = transform().skew(inp_x, inp_y) elif self.cmb_transform.currentIndex == 2: workTrans = transform().rotate(inp_x) elif self.cmb_transform.currentIndex == 1: workTrans = transform().scale(inp_x, inp_y) for glyph in workSet: if wLayer is not None: for layer in wLayer: transformGlyph(glyph, layer, workTrans) else: transformGlyph(glyph, None, workTrans) activeFont.update() fl6.Update(CurrentFont())