def copyExpr(self): font = pFont() if self.cmb_mode.currentIndex == 1: self.srcGlyphBounds = { glyph.name: { layer.name: (layer.metricsLeft, layer.metricsRight, layer.metricsWidth) for layer in glyph.masters() } for glyph in font.pGlyphs() } print 'COPY MM:\t Font:%s; Glyph Metric Expressions copied: %s.' % ( font.name, len(self.srcGlyphBounds.keys())) else: self.srcGlyphBounds = { glyph.name: (glyph.layer(fixedLayer).metricsLeft, glyph.layer(fixedLayer).metricsRight, glyph.layer(fixedLayer).metricsWidth) for glyph in font.pGlyphs() } print 'COPY:\t Font:%s; Glyph Metric Expressions copied: %s.' % ( font.name, len(self.srcGlyphBounds.keys())) self.btn_paste.setEnabled(True)
def exportExpr(self): font = pFont() fontPath = os.path.split(font.fg.path)[0] fname = QtGui.QFileDialog.getSaveFileName( self, 'Save Metric Expressions to file', fontPath, '*.json') if self.cmb_mode.currentIndex == 1: expGlyphBounds = { glyph.name: { layer.name: (layer.metricsLeft, layer.metricsRight, layer.metricsWidth) for layer in glyph.masters() } for glyph in font.pGlyphs() } print 'EXPORT MM:\t Font:%s; Glyph Metric Expressions found: %s.' % ( font.name, len(expGlyphBounds.keys())) else: expGlyphBounds = { glyph.name: (glyph.layer(fixedLayer).metricsLeft, glyph.layer(fixedLayer).metricsRight, glyph.layer(fixedLayer).metricsWidth) for glyph in font.pGlyphs() } print 'EXPORT:\t Font:%s; Glyph Metric Expressions found: %s.' % ( font.name, len(expGlyphBounds.keys())) with open(fname, 'w') as exportFile: json.dump(expGlyphBounds, exportFile) print 'SAVE:\t Font:%s; %s Glyph Metric Expressions saved to %s.' % ( font.name, len(expGlyphBounds.keys()), fname)
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 importExprFLC(self): from typerig.utils import fontClassesFromFile as importFLC font = pFont() fontPath = os.path.split(font.fg.path)[0] fname = QtGui.QFileDialog.getOpenFileName(self, 'Open Fontlab class file', fontPath, '*.flc') classesFLC = importFLC(fname) print classesFLC.classPosition
def importAnchor(self): font = pFont() fontPath = os.path.split(font.fg.path)[0] fname = QtGui.QFileDialog.getOpenFileName( self, 'Open Glyph Anchors from file', fontPath, '*.json') with open(fname, 'r') as importFile: self.srcGlyphAnchors = json.load(importFile) print 'LOAD:\t Font:%s; %s Glyph Anchors loaded from %s.' % ( font.name, len(self.srcGlyphAnchors.keys()), fname) print 'NOTE:\t Use < Paste Anchors > to apply loaded!' self.btn_paste.setEnabled(True)
def exportAnchor(self): font = pFont() fontPath = os.path.split(font.fg.path)[0] fname = QtGui.QFileDialog.getSaveFileName( self, 'Save Metric Anchoressions to file', fontPath, '*.json') self.copyAnchor() print 'EXPORT:\t Font:%s; Glyph Anchors found: %s.' % ( font.name, len(self.srcGlyphAnchors.keys())) with open(fname, 'w') as exportFile: json.dump(self.srcGlyphAnchors, exportFile) print 'SAVE:\t Font:%s; %s Glyph Anchors saved to %s.' % ( font.name, len(self.srcGlyphAnchors.keys()), fname)
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 copyAnchor(self): font = pFont() if self.cmb_mode.currentIndex == 1: self.srcGlyphAnchors = {} for glyph in font.pGlyphs(): current_masters = glyph.masters() if len(current_masters): layer_anchors = {} for layer in current_masters: current_anchors = layer.anchors if len(current_anchors): layer_anchors[layer.name] = [ (anchor.name, (int(anchor.point.x()), int(anchor.point.y()))) for anchor in current_anchors ] if len(layer_anchors.keys()): self.srcGlyphAnchors[glyph.name] = layer_anchors print 'COPY MM:\t Font:%s; Glyph Anchors copied: %s.' % ( font.name, len(self.srcGlyphAnchors.keys())) else: self.srcGlyphAnchors = { glyph.name: [(anchor.name, (int(anchor.point.x()), int(anchor.point.y()))) for anchor in glyph.anchors(fixedLayer)] for glyph in font.pGlyphs() if len(glyph.anchors(fixedLayer)) } print 'COPY:\t Font:%s; Glyph Anchors copied: %s.' % ( font.name, len(self.srcGlyphAnchors.keys())) self.btn_paste.setEnabled(True)
#FLM: TR: Mark Composites # VER : 1.0 # ---------------------------------------- # (C) Vassil Kateliev, 2019 (http://www.kateliev.com) # (C) Karandash Type Foundry (http://www.karandash.eu) #----------------------------------------- # www.typerig.com # No warranties. By using this you agree # that you use it at your own risk! # - Dependancies from typerig.proxy.fl import pFont, pGlyph # - Init font = pFont() mark_color = 120 # Green # - Process for glyph in font.pGlyphs(): if len(glyph.layers()) and len(glyph.components()): glyph.fl.mark = mark_color print 'MARK:\tGlyph: %s;\tComposite.' % glyph.name print 'Done.'