def mainCalculation(self): try: #Calculate scale xFactor = self.targetHeight / currentHeight #Decompose every glyph first (in case of component-based font) for glyph in f: glyph.decompose() #Scale & tans every glyph for glyph in f: glyph.scale(xFactor) glyph.width *= xFactor glyph.round() #Rounds all float values (incl. side bearings) glyph.mark = (0.69, 0.43, 0.18, 1) #Modify vertical metrics to new dimensions f.info.ascender *= xFactor f.info.capHeight *= xFactor f.info.xHeight *= xFactor f.info.descender *= xFactor Message("Nice tan!") #In case user inputs strings that can't be converted to integers except ValueError: Message("The Mooch only likes numbers!")
def searchGroupProcess(): selectedDict = dict() #try: standardGlyph = CurrentGlyph() setExtensionDefault(DefaultKey + ".standardGlyph", standardGlyph) for contour in standardGlyph.contours: for point in contour.selection: if point.selected is True: selectedDict[point.getParent().index] = True if len(selectedDict) != 1: print(Message("글자의 컨투어를 하나만 선택해주세요.")) return contourIndex = list(selectedDict.keys())[0] jsonFilePath = getExtensionDefault(DefaultKey + ".jsonFilePath") mode = getExtensionDefault(DefaultKey + ".mode") jsonFileName1 = getExtensionDefault(DefaultKey + ".jsonFileName1") jsonFileName2 = getExtensionDefault(DefaultKey + ".jsonFileName2") groupDict = getExtensionDefault(DefaultKey + ".groupDict") KoreanCheck = getExtensionDefault(DefaultKey + ".korean") print("Short Cut KoreanCheck : ", KoreanCheck) if KoreanCheck == True: tMC.handleSearchGlyphList(standardGlyph, contourIndex, groupDict) else: ctMC.cHandleSearchGlyphList(standardGlyph, contourIndex, groupDict) for contour in standardGlyph.contours: contour.selected = False
def __init__(self, glyph): # if glyph is None, show a message if glyph is None: Message('no glyph selected', title='moveTool', informativeText='Please select one glyph first!') return # store the glyph and initial move values as object attributes self.glyph = glyph self.moveXTRA = 0 # create a floating window self.w = FloatingWindow((200, 74), "move %s" % self.glyph.name) # add a slider for moving in the x axis self.w.sliderXTRA = Slider((10, 10, -10, 22), value=0, maxValue=200, minValue=0, callback=self.adjustXTRA) # self.w.sliderXOPQ = Slider( # (10, 10, -10, 22), # value=0, maxValue=200, minValue=-200, # callback=self.adjust) # open the window self.w.open()
def tofuButtonCallback(self, sender): self.outputText = self.inputText noBueno = self.tofuText self.updateFont() if self.ucCheck == 1: self.outputText = self.inputText.upper() noBueno = noBueno.upper() if self.lcCheck == 1: self.outputText = self.inputText.lower() noBueno = noBueno.lower() if self.digitCheck == 1: noBueno += s.digits if self.punctCheck == 1: noBueno += s.punctuation + "‘’“”«»".decode("utf-8") self.outputText = removeExtraSpaces("".join( letter for letter in self.outputText if letter not in noBueno)) # outputText = outputText.translate(None, noBueno) self.w.outputText.set(self.outputText) if self.copyToSCCheck == 1 and self.outputText != "": try: OpenSpaceCenter(self.font, newWindow=False) sc = CurrentSpaceCenter() sc.setRaw(self.outputText) except AttributeError: Message("You need a font to copy to Space Center")
def glyphsToCopy(self, sender): if self.w.editText.get() == "": Message('no glyphs listed', title='Glyph Fax Machine', informativeText='Please list glyphs to send copies of!') return return self.w.editText.get().split(" ")
def convertCurrentFontCallback(self, sender): f = CurrentFont() if f.lib['com.typemytype.robofont.segmentType'] == 'qcurve': Message("I can only convert cubic fonts.") return progress = self.startProgress(u'Copying font…') closeWindow = False try: closeWindow = self.convertFont(f, progress) except: print("Unexpected error in QuadraticConverter:", sys.exc_info()) progress.close()
def rollbackAttribute(self, sender): restoreStack = getExtensionDefault(DefaultKey + ".restoreStack") if restoreStack is None or restoreStack.front == restoreStack.rear: restoreStack.print() Message("복원할 수 없습니다.") return target = restoreStack.rollback() if target is None: Message("복원할 수 없습니다.") return for element in target: element[0].name = element[1] restoreStack.print() CurrentFont().update() CurrentFont().save(self.testPath)
def popAttributeWindow(self, sender): # Window for Assign & Remove Attribute mode = getExtensionDefault(DefaultKey + ".mode") contourNumber = getExtensionDefault(DefaultKey + ".contourNumber") if mode is None or contourNumber is None: Message("먼저 속성을 부여할 그룹을 찾아야 합니다.") return if self.w[3] is not None and self.w[3].w is not None: self.w[3].w.close() print("self.w[3].w = ", self.w[3].w) self.w[3] = attributeWindow()
def restoreAttribute(self, sender): restoreStack = getExtensionDefault(DefaultKey + ".restoreStack") if restoreStack is None or restoreStack.isEmpty() is True: restoreStack.print() Message("더 이상 되돌릴 수 없습니다.") return top = restoreStack.pop() if top is None: restoreStack.print() Message("더 이상 되돌릴 수 없습니다.") return for element in top: element[0].name = element[1] restoreStack.print() CurrentFont().update() CurrentFont().save(self.testPath)
def convertCurrentGlyphCallback(self, sender): g = CurrentGlyph() if None == g: return layerToConvert = self.layers[self.w.layerPopup.get()] if layerToConvert == 'foreground': Message( "I can only convert contours from a layer different from 'foreground'." ) return g.flipLayers('foreground', layerToConvert) g.copyToLayer(layerToConvert) convert(g, self.maxDistanceValue, self.minLengthValue, self.useArcLength) CurrentFont().changed() UpdateCurrentGlyphView()
def checkFont(self, useSelection=False, excludeZeroWidth=True): f = CurrentFont() if f is not None: # initialize things self.w.options.progress.start() time0 = time.time() self.excludeZeroWidth = excludeZeroWidth self.f = f glyphNames = f.selection if useSelection else f.keys() glyphList = [f[x] for x in glyphNames] glyphList = self._trimGlyphList(glyphList) self.touchingPairs = Touche(f).findTouchingPairs(glyphList) # display output self.w.results.stats.set("%d glyphs checked" % len(glyphList)) self.w.results.result.set("%d touching pairs found" % len(self.touchingPairs)) self.w.results.show(True) outputList = [{ "left glyph": g1, "right glyph": g2 } for (g1, g2) in self.touchingPairs] self.w.outputList.set(outputList) if len(self.touchingPairs) > 0: self.w.outputList.setSelection([0]) else: self.w.preview.set("") outputButtons = [ self.w.results.spaceView, self.w.results.exportTxt ] for b in outputButtons: b.enable(False) if len( self.touchingPairs) == 0 else b.enable(True) self.w.preview.setFont(f) self.w.preview.setApplyKerning(True) self.w.options.progress.stop() self._resizeWindow(enlarge=True) time1 = time.time() print(u'Touché: finished checking %d glyphs in %.2f seconds' % (len(glyphList), time1 - time0)) else: Message(u'Touché: Can’t find a font to check')
ISFULL = True print(ISFULL) break # Use #drawGlyph() out of the box drawGlyph(f[g]) # It's basically this # pen = CocoaPen(f) # f[g].draw(pen) # drawPath(pen.path) translate(f[g].width, 0) restore() try: EtchASketch() except NameError: Message("Please install DrawBot module") """ --------------- TO DO --------------- + Make a DrawingTools version so it's not reliant on DrawBot - (is it possible? mojo.Canvas is a pain...) + Input string catches could be better... + Expand to have typecooker mode? + Add Observer to update everything when CurrentFont is switched """
def windowCloseCallback(self, sender): removeObserver(self, "fontBecameCurrent") super(PreviewFacet, self).windowCloseCallback(sender) def draw(self): """ This function is what Canvas calls to draw """ fill(0) stroke(None) translate(10, 40) scale(.3) for letter in self.letters: glyph = self.f[letter] # myDrawGlyph(glyph) facetDrawGlyph(glyph, int(self.facet)) translate(glyph.width, 0) if CurrentFont() is not None: PreviewFacet() else: Message("You need to open a font!")
from mojo.UI import Message from vanilla import * from mojo.drawingTools import * from mojo.canvas import Canvas f = CurrentFont() if f == None: Message("Open a font first!") upm = f.info.unitsPerEm currentHeight = int( f.info.ascender + -f.info.descender) #Total measurement from ascender to descender class ScaleAMucci(object): def __init__(self): self.targetHeight = currentHeight self.buildUI() self.w.open() def buildUI(self): self.w = Window((300, 415)) self.w.currentHeightText = TextBox( (10, 10, 150, 17), "Current height: " + str(currentHeight)) self.w.currentUPM = TextBox((200, 10, -10, 17),
glyph.contours[0].points[-2].y) pt3 = (glyph.contours[0].points[-1].x, glyph.contours[0].points[-1].y) if getAngle(pt0, pt1) >= 90 or getAngle(pt0, pt1) <= -90: rotateFlag = True db.translate(0, -820) db.newPath() pen = StrokePen(glyph.getParent(), self.widthValue) glyph.draw(pen) db.drawPath() if rotateFlag: db.rotate(-90) db.translate(0, 0) else: db.translate(glyph.width, 0) try: PreviewStroke() except: Message("Something's not right... Is the font there?") # if CurrentFont() is not None: # PreviewStroke() # else: # Message("You need to open a font!")