コード例 #1
0
 def loadSettings(self, sender):
     filePath = GetFile(message="Choose a previously processed UFO to load the settings back out of", fileTypes=["ufo"])
     if not filePath == None:
         prevFont = OpenFont(filePath, showInterface=False)
         if LIBKEY in prevFont.lib.keys():
             libData = prevFont.lib[LIBKEY]
             self.g.otherRadio.set(libData["otherOption"])
             self.g.skewBox.set(libData["skewOption"])
             self.g.infoBox.set(libData["infoOption"])
             # Apply the normalized info
             for case in ["uc", "lc"]:
                 scaleH = libData["normalizedInfo"][case]["scaleH"] / self.dataNorms["scaleH"]["scale"]
                 scaleV = libData["normalizedInfo"][case]["scaleV"] / self.dataNorms["scaleV"]["scale"]
                 interpH = libData["normalizedInfo"][case]["interpH"] / self.dataNorms["interpH"]["scale"]
                 interpV = libData["normalizedInfo"][case]["interpV"] / self.dataNorms["interpV"]["scale"]
                 tracking = libData["normalizedInfo"][case]["tracking"] / self.dataNorms["tracking"]["scale"]
                 info = [
                     dict(Name="Scale Horizontal %", attr="scaleH", Value=scaleH),
                     dict(Name="Scale Vertical %", attr="scaleV", Value=scaleV),
                     dict(Name="Interpolate Horizontal %", attr="interpH", Value=interpH),
                     dict(Name="Interpolate Vertical %", attr="interpV", Value=interpV),
                     dict(Name="Units of tracking", attr="tracking", Value=tracking)]
                 if case == "uc":
                     self.g.ucInfo.set(info)
                 else: self.g.lcInfo.set(info)
             # Reset the dropdown choices
             self.g.font0choice.set(-1)
             self.g.font1choice.set(-1)
             self.g.ucGroups.set(0)
             self.g.lcGroups.set(0)
     
         prevFont.close()
コード例 #2
0
 def _importSettings(self):
     path = GetFile(message='Import Tool Palette', fileTypes=[self.suffix])
     if path:
         settings = readPlist(path)
         self.toolDescription = settings['toolDescription']
         self.hotkeys = settings['hotkeys']
         self._updateTools()
         self._rebuildToolPalette()
コード例 #3
0
def generateInstances():
    path = GetFile("Open a Desingspace or Superpolator file to generate:",
                   fileTypes=['sp3', 'designspace'])
    if path is None:
        return
    if os.path.splitext(path)[-1] == ".sp3":
        path = convertSuperpolatorToDesignSpace(path)
        if path is None:
            return
    ufoProcessor.build(path)
コード例 #4
0
 def importCallback(self, sender):
     if len(self.fontList):
         fontChoice = self.w.fontChoice.get()
         f = self.fontList[fontChoice]
         filePath = GetFile(message="Choose the SVG file to import...")
         if not filePath == None:
             if os.path.splitext(filePath)[1] == ".svg":
                 otherExt = ".plist"
             else:
                 otherExt = ".svg"
             otherPath = os.path.splitext(filePath)[0] + otherExt
             if os.path.exists(otherPath):
                 self.doImport(f, filePath)
             else:
                 print("Can't find the other file!")
コード例 #5
0
    def changerecipee(self, sender):
        root = GetFile(
            message=
            "Please select a txt file containing glyph construction recipee",
            title="Select a txt file",
            allowsMultipleSelection=False,
            fileTypes=["glyphConstruction", "txt"])
        with open(root, 'r') as file:
            data = file.read()

            # Write over existing data
            with open(recipee.__file__, "w") as f:
                f.write(f"glyph_constructor = '''{data}'''")

            recipee.glyph_constructor = data

        self.constructions = data
コード例 #6
0
 def openDesignSpace(self, sender, path=None):
     if path == None:
         path = GetFile()
     if not path == None:
         self.dsPath = path
         self.ds = DesignSpaceProcessor(useVarlib=True)
         self.ds.read(path)
         self.ds.loadFonts()
         # Open new font objects
         self.sourceFonts = {}
         for sourceName in self.ds.fonts:
             df = self.ds.fonts[sourceName]
             f = OpenFont(df.path, showInterface=True)
             self.sourceFonts[sourceName] = f
         # Finish setup
         self.positionSourceWindows()
         self.updatePreview()
コード例 #7
0
 def importThemeCallback(self, sender):
     if self.debug: print("importThemeCallback")
     # Callback from the "Import" button
     # Pop open an "Open" dialog to get a file path, then call readThemePlist()
     path = GetFile(message="Import Theme", fileTypes=["roboFontTheme"])
     # If they did choose a path, save it.
     # If they clicked cancel, there would be no path.
     if path:
         themeData = readPlist(path)
         # Validate the themeData
         valid = True
         for key, name, valueType in THEMEKEYS:
             if not key in themeData:
                 valid = False
         if valid:
             self.themes += [themeData]
             self.rebuildThemeList()
         else:
             NSBeep()
             self.showMessage("Sorry!", "This is an invalid theme file.")
コード例 #8
0
    def addVowelAttr(self):
        glyphpath = GetFile("Choose a UFO")
        filelist = os.listdir(glyphpath)

        filelist2 = []
        for f in filelist:
            f2 = glyphpath + "/" + f
            filelist2.append(f2)

        for f in filelist2:
            if f.endswith(".glif"):
                print(f + " <- glif file\n")
                doc = parse(f)
                root = doc.getroot()

                for outline in root.iter("outline"):
                    serifCount = 1
                    roundCount = 1

                    for contour in outline.iter("contour"):
                        minX = 1000
                        minY = 1000
                        maxX = -1000
                        maxY = -1000

                        for point in contour.iter("point"):
                            pointX = int(float(point.get('x')))
                            pointY = int(float(point.get('y')))
                            if minX > pointX:
                                minX = pointX
                            if maxX <= pointX:
                                maxX = pointX
                            if minY > pointY:
                                minY = pointY
                            if maxY <= pointY:
                                maxY = pointY

                        horizontalLine = maxX - minX
                        verticalLine = maxY - minY

                        if horizontalLine * 6 < verticalLine:
                            for point in contour.iter("point"):
                                pointX = int(float(point.get('x')))
                                pointY = int(float(point.get('y')))
                                if pointX == minX and pointY == maxY:
                                    point.set("serif", str(serifCount))
                                    serifCount += 1
                                    serifPenPair = point.get("penPair")
                                    if serifPenPair[-1] == "r":
                                        pairSerifPenPair = serifPenPair
                                        serifPenPair = serifPenPair[:2] + "l"
                                        point.set("penPair", serifPenPair)
                                        for pairPoint in contour.iter("point"):
                                            if point == pairPoint:
                                                continue
                                            if pairPoint.get("penPair").find(
                                                    serifPenPair) != -1:
                                                pairPoint.set(
                                                    "penPair",
                                                    pairSerifPenPair)
                                                break
                                elif pointX == minX and pointY == minY:
                                    point.set("round", str(roundCount))
                                    roundCount += 1
                                    roundPenPair = point.get("penPair")
                                    if roundPenPair[-1] == "r":
                                        pairRoundPenPair = roundPenPair
                                        roundPenPair = roundPenPair[:2] + "l"
                                        point.set("penPair", roundPenPair)
                                        for pairPoint in contour.iter("point"):
                                            if point == pairPoint:
                                                continue
                                            if pairPoint.get("penPair").find(
                                                    roundPenPair) != -1:
                                                pairPoint.set(
                                                    "penPair",
                                                    pairRoundPenPair)
                                                break
                doc.write(f, encoding="utf-8", xml_declaration=True)
コード例 #9
0
    def addConsonantAttr(self):
        glyphpath = GetFile("Choose a UFO")
        filelist = os.listdir(glyphpath)

        filelist2 = []
        for f in filelist:
            f2 = glyphpath + "/" + f
            filelist2.append(f2)

        for f in filelist2:
            if f.endswith(".glif"):
                doc = parse(f)
                root = doc.getroot()
                totalminX = 1000
                for outline in root.iter("outline"):
                    for contour in outline.iter("contour"):
                        minX = 1000
                        minY = 1000
                        maxX = 0
                        maxY = 0
                        for point in contour.iter("point"):
                            pointX = int(float(point.get('x')))
                            pointY = int(float(point.get('y')))
                            if minX > pointX:
                                minX = pointX
                            if maxX < pointX:
                                maxX = pointX
                            if minY > pointY:
                                minY = pointY
                            if maxY < pointY:
                                maxY = pointY
                            if totalminX > minX:
                                totalminX = minX

                for outline in root.iter("outline"):
                    connerCount = 1
                    for contour in outline.iter("contour"):
                        minX = 1000
                        minY = 1000
                        maxX = 0
                        maxY = 0

                        vessel = []
                        for point in contour.iter("point"):
                            pointX = int(float(point.get('x')))
                            pointY = int(float(point.get('y')))
                            if minX > pointX:
                                minX = pointX
                            if maxX < pointX:
                                maxX = pointX
                            if minY > pointY:
                                minY = pointY
                            if maxY < pointY:
                                maxY = pointY

                        horizontalLine = maxX - minX
                        verticalLine = maxY - minY
                        for point in contour.iter("point"):
                            x = int(float(point.get('x')))
                            y = int(float(point.get('y')))
                            dx = 0
                            dy = 0
                            for point2 in contour.iter("point"):
                                compX = int(float(point2.get('x')))
                                compY = int(float(point2.get('y')))

                                if x == compX:
                                    if y == compY:
                                        continue
                                    elif y > compY:
                                        dy = -1
                                    else:
                                        dy = 1

                                if y == compY:
                                    if x == compX:
                                        continue
                                    elif x > compX:
                                        dx = -1
                                    else:
                                        dx = 1
                            if dx == 1 and dy == 1:
                                vessel.append(point)
                        result = sorted(
                            vessel,
                            key=lambda vessel: int(float(vessel.get('x'))))
                        result2 = sorted(
                            vessel,
                            key=lambda vessel: int(float(vessel.get('y'))))
                        if len(vessel) == 0:
                            pass
                        elif len(vessel) == 1:
                            if horizontalLine * 3 < verticalLine:
                                tmpx = int(float(result[0].get('x')))
                                if tmpx == totalminX:
                                    result[0].set('corner', str(connerCount))
                                    connerCount += 1
                        elif int(float(result[0].get('x'))) == int(
                                float(result2[0].get('x'))):
                            result[0].set('corner', str(connerCount))
                            connerCount += 1
                doc.write(f, encoding="utf-8", xml_declaration=True)
            else:
                pass
コード例 #10
0
 def importCallback(self, sender):
     '''Import spacing groups from .json file.'''
     font = CurrentFont()
     filePath = GetFile(message='import spacing groups', fileTypes=['json'])
     importSpacingGroups(font, filePath)