def otf2ttf(otf_path, ttf_path): ''' Generate a .ttf font from an .otf source font. Requires RoboFont. ''' otf_font = OpenFont(otf_path, showUI=False) ### is this curve conversion really necessary? ### some scripts do just `font.generate('myfont.ttf', 'ttf')` coreFont = otf_font.naked() for glyph in coreFont: curveConverter.bezier2quadratic(glyph) coreFont.segmentType = glyph.segmentType ### end conversion otf_font.generate(ttf_path, 'ttf') return os.path.exists(ttf_path)
def otf2ttf(otf_path, ttf_path): ''' Generate a .ttf font from an .otf source font. Requires RoboFont. ''' otf_font = OpenFont(otf_path, showInterface=False) ### is this curve conversion really necessary? ### some scripts do just `font.generate('myfont.ttf', 'ttf')` coreFont = otf_font.naked() for glyph in coreFont: curveConverter.bezier2quadratic(glyph) coreFont.segmentType = glyph.segmentType ### end conversion otf_font.generate(ttf_path, 'ttf') return os.path.exists(ttf_path)
def expandGlyph(self, glyph, preserveComponents=True): defconGlyph = glyph.naked() glyph.prepareUndo("Outline") isQuad = curveConverter.isQuadratic(defconGlyph) if isQuad: curveConverter.quadratic2bezier(defconGlyph) outline = self.calculate(defconGlyph, preserveComponents) glyph.clearContours() outline.drawPoints(glyph.getPointPen()) if isQuad: curveConverter.bezier2quadratic(defconGlyph) glyph.round() glyph.performUndo()
def expandGlyph(self, glyph, preserveComponents=True): defconGlyph = glyph.naked() glyph.prepareUndo("Outline") isQuad = curveConverter.isQuadratic(defconGlyph) if isQuad: curveConverter.quadratic2bezier(defconGlyph) outline = self.calculate(glyph, preserveComponents) glyph.clearContours() outline.drawPoints(glyph.getPointPen()) if isQuad: curveConverter.bezier2quadratic(defconGlyph) glyph.round() glyph.performUndo()
def expand(self, sender): glyph = CurrentGlyph() defconGlyph = glyph.naked() glyph.prepareUndo("Outline") isQuad = curveConverter.isQuadratic(defconGlyph) if isQuad: curveConverter.quadratic2bezier(defconGlyph) outline = self.calculate(glyph) glyph.clear() outline.drawPoints(glyph.getPointPen()) if isQuad: curveConverter.bezier2quadratic(defconGlyph) glyph.round() glyph.performUndo()
def Convert2Quadratic(f, RemoveOverlap=False): currentpath = f.path root, tail = os.path.split(f.path) QuadraticUFOTail = 'Quatratic_' + tail.split('.')[0] + '.ufo' QuadraticUFOPath = os.path.join(root, QuadraticUFOTail) nf = NewFont() nf.preferredSegmentType = "qCurve" CFI.copyAllInfoFromTo(f, nf) for g in f: nf[g.name] = g.copy() for g in nf: if RemoveOverlap: g.removeOverlap() mask = g.getLayer("CubicContour") mask.clear() g.copyToLayer("CubicContour") glyphNaked = g.naked() if curveConverter.isBezier(glyphNaked): curveConverter.bezier2quadratic(glyphNaked) glyphNaked.correctDirection(trueType=True) nf.save(QuadraticUFOPath)
from lib.tools.bezierTools import curveConverter from vanilla.dialogs import * inputFonts = getFile("select masters to add feature code to", allowsMultipleSelection=True, fileTypes=["ufo"]) for fontPath in inputFonts: # font = CurrentFont() font = OpenFont(fontPath, showInterface=False) coreFont = font.naked() for glyph in coreFont: # convert from cubic to quad curveConverter.bezier2quadratic(glyph) # convert from quad to cubic # curveConverter.quadratic2bezier(glyph) coreFont.segmentType = glyph.segmentType font.save() font.close() print("done")