Example #1
0
def buildPairsFromString(uniString, aFont):
    pairs = []
    splittedText = splitText(uniString, aFont.naked().unicodeData)
    for eachI in range(1, len(splittedText)):
        myPair = (u'{}'.format(splittedText[eachI-1]), u'{}'.format(splittedText[eachI]))
        pairs.append(myPair)
    return pairs
Example #2
0
 def changeControlGlyph(self, sender):
     textInput = sender.get()
     glyphNames = splitText(textInput, self.cmap)
     if len(glyphNames):
         self.controlGlyph = glyphNames[0]
     elif not len(glyphNames):
         self.controlGlyph = 'H'
     self.updatePreview()
 def get(self):
     text = super(GlyphSequenceEditText, self).get()
     glyphNames = splitText(text, self._font.unicodeData)
     glyphs = [
         self._font[glyphName] for glyphName in glyphNames
         if glyphName in self._font
     ]
     return glyphs
 def stringInput(self, sender):
     text = sender.get()
     if self.currentFont is not None:
         cmap = self.currentFont.getCharacterMapping()
         self.glyphNames = splitText(text, cmap)
     else:
         self.glyphNames = []
     self.updatePreview()
Example #5
0
    def inputCallback(self, sender):

        typedString = sender.get()

        self.glyphSet = splitText(typedString, self.charMap)

        for i in range(len(self.fontsOnBench)):
            thisLineMethAttr = getattr(self.w.allLines, self.lineNames[i] + "MethAttr")
            thisLineMethAttr.setGlyphs(self.glyphSet)
Example #6
0
 def set(self, text):
     glyphNames = splitText(text, self._font.getCharacterMapping())
     # this assumes that the naked glyph will be defcon based.
     # the only other option is to fork the defocnAppKit code to use only RoboFab objects.
     glyphs = [
         self._font[glyphName].naked() for glyphName in glyphNames
         if glyphName in self._font
     ]
     super(GlyphLineView, self).set(glyphs)
    def inputCallback(self, sender):

        typedString = sender.get()

        self.glyphSet = splitText(typedString, self.charMap)

        for i in range(len(self.fontsOnBench)):
            thisLineMethAttr = getattr(self.w.allLines, self.lineNames[i] + "MethAttr")
            thisLineMethAttr.setGlyphs(self.glyphSet)
 def changeGlyph(self, sender):
     inputText = sender.get()
     try:
         charMap = CurrentFont().getCharacterMapping()
         glyphs = splitText(inputText, charMap)
         if len(glyphs):
             self.currentGlyph = glyphs[0]
             self.updateMatrix()
     except:
         return
Example #9
0
 def stringToGlyphs(self, text):
     glyphRecord = []
     cmap = self.cmap
     text = unicode(text, 'utf8')
     lines = text.split('\n')
     for line in lines:
         glyphRecord += splitText(line, cmap)
         glyphRecord.append('\n')
     glyphRecord.pop()
     return glyphRecord
Example #10
0
 def stringToGlyphs(self, text):
     glyphRecord = []
     cmap = self.cmap
     text = unicode(text, 'utf8')
     lines = text.split('\n')
     for line in lines:    
         glyphRecord += splitText(line, cmap)
         glyphRecord.append('\n')
     glyphRecord.pop()     
     return glyphRecord
Example #11
0
 def stringToGlyphs(self, text, font):
     glyphRecord = []
     cmap = font.getCharacterMapping()
     if isinstance(text, str):
         text = text
     lines = text.split('\n')
     for line in lines:
         glyphRecord += splitText(line, cmap)
         glyphRecord.append('\n')
     glyphRecord.pop()
     return glyphRecord
Example #12
0
def loadKerningTexts(aPath):
    kerningTextsPaths = catchFilesAndFolders(aPath, '.txt')
    kerningTextsUniqueNames = {}
    for eachPath in kerningTextsPaths:
        singleKerningText = [splitText(row.strip(), templateFont.naked().unicodeData) for row in codecs.open(eachPath, 'r', 'utf-8').readlines()]
        uniqueNames = []
        for eachRow in singleKerningText:
            for eachCell in eachRow:
                if eachCell not in uniqueNames:
                    uniqueNames.append(eachCell)
        kerningTextsUniqueNames[os.path.basename(eachPath)] = uniqueNames
    return kerningTextsUniqueNames
Example #13
0
 def stringToGlyphNames(self, string):
     cmap = self.getCMap()
     if cmap is not None:
         glyphLines = []
         lines = string.split('\\n')
         l = len(lines)
         for i, line in enumerate(lines):
             glyphs = splitText(line, cmap)
             if 0 < i < l:
                 glyphs.append('newLine')
             glyphLines += glyphs
         return glyphLines
     return []
Example #14
0
    def stringToGlyphs(self, text, path, font):
        glyphRecord = []

        if path.endswith(".ufo"):
            cmap = font.getCharacterMapping()
        if path.endswith(('.otf', '.ttf')):
            cmap = font.getBestCmap()
        
        if isinstance(text, str):
            text = text
        lines = text.split('\n')
        for line in lines:
            # Replace /? by current glyph name
            if "/?" in line:
                line = line.replace("/?", "/" + CurrentGlyph().name)
                
            glyphRecord += splitText(line, cmap)
            glyphRecord.append('\n')
        glyphRecord.pop()     
        return glyphRecord
    def generateGlyphSet(self, sender):

        incomingSpot = None
        if hasattr(sender, 'spot'):
            incomingSpot = sender.spot

        generateSheet = self.w.generateSheet
        generateSheet.close()
        glyphTab = generateSheet.tabs[1]
        axesGrid = self.axesGrid['horizontal'], self.axesGrid['vertical']
        masters = self.masters

        targetFontNameIndex = glyphTab.targetFont.get()
        targetFontName = glyphTab.targetFont.getItems()[targetFontNameIndex]

        cmap = masters[0][1].getCharacterMapping()
        glyphList = splitText(glyphTab.glyphSet.get(), cmap)
        spot = self.parseSpot(glyphTab.spot.get(), axesGrid)
        if spot is not None and len(spot):
            spot = spot[0]

        suffix = glyphTab.suffix.get()

        if spot is not None:
            progress = ProgressWindow('Generating glyphs', parentWindow=self.w)
            i, j = spot
            instanceLocation = Location(horizontal=i, vertical=j)
            masterLocations = [(matrixMaster.getLocation(), matrixMaster.getFont()) for matrixMaster in masters]
            if targetFontName == 'New font':
                targetFont = RFont(showUI=False)
            else:
                targetFont = AllFonts().getFontsByFamilyNameStyleName(*targetFontName.split(' > '))
            self.interpolateGlyphSet(instanceLocation, glyphList, masterLocations, targetFont, suffix)
            targetFont.showUI()
            progress.close()

        if incomingSpot is not None:
            ch, j = incomingSpot
            pickedCell = getattr(self.w.matrix, '%s%s'%(ch, j))
            pickedCell.selectionMask.show(False)
Example #16
0
    def draw(self):

        try:
            glyphsToDisplay = splitText(self.displayedWord,
                                        self.fontObj.naked().unicodeData)

            # if the user switches the glyphs from the groups
            # here we have to arrange the list of glyphnames properly
            if self.activePair is not None:
                lftName, rgtName = self.activePair
                glyphsToDisplay[self.indexPair] = lftName
                glyphsToDisplay[self.indexPair + 1] = rgtName

            # here we draw
            dt.save()

            # this is for safety reason, user should be notified about possible unwanted kerning corrections
            if self.isSwappedEditingOn is True:
                dt.save()
                dt.fill(*FLIPPED_BACKGROUND_COLOR)
                dt.rect(0, 0, self.ctrlWidth, self.ctrlHeight)
                dt.restore()

            if self.isSymmetricalEditingOn is True:
                dt.save()
                dt.fill(*SYMMETRICAL_BACKGROUND_COLOR)
                dt.rect(0, 0, self.ctrlWidth, self.ctrlHeight)
                dt.restore()

            dt.scale(
                self.ctrlHeight /
                (self.canvasScalingFactor * self.fontObj.info.unitsPerEm)
            )  # the canvas is virtually scaled according to self.canvasScalingFactor value and canvasSize
            dt.translate(TEXT_MARGIN, 0)

            # group glyphs
            dt.translate(0, 600)

            if self.areGroupsShown is True:
                dt.save()
                prevGlyphName = None
                for indexChar, eachGlyphName in enumerate(glyphsToDisplay):
                    eachGlyph = self.fontObj[eachGlyphName]

                    # this is for kerning
                    if indexChar > 0:
                        correction, kerningReference, pairKind = getCorrection(
                            (prevGlyphName, eachGlyphName), self.fontObj)

                        if kerningReference:
                            exceptionStatus, doesExists, exceptionParents = isPairException(
                                kerningReference, self.fontObj)
                            if exceptionStatus is True:
                                self._drawException(
                                    (prevGlyphName, eachGlyphName), correction)

                        if (indexChar - 1) == self.indexPair:
                            if correction is None:
                                offsetCorrection = 0
                            else:
                                offsetCorrection = correction
                            self._drawGlyphOutlinesFromGroups(
                                (prevGlyphName, eachGlyphName),
                                kerningReference, offsetCorrection)

                        if correction and correction != 0 and self.isKerningDisplayActive:
                            dt.translate(correction, 0)

                    dt.translate(eachGlyph.width, 0)
                    prevGlyphName = eachGlyphName
                dt.restore()

            # background loop
            dt.save()
            glyphsToDisplayTotalWidth = 0
            prevGlyphName = None
            for indexChar, eachGlyphName in enumerate(glyphsToDisplay):
                eachGlyph = self.fontObj[eachGlyphName]

                # this is for kerning
                if indexChar > 0:
                    correction, kerningReference, pairKind = getCorrection(
                        (prevGlyphName, eachGlyphName), self.fontObj)
                    if self.isKerningDisplayActive and correction is not None:
                        if correction != 0 and self.isColorsActive is True:
                            self._drawColoredCorrection(correction)

                        if self.isCorrectionActive is True:
                            self._drawMetricsCorrection(correction)

                        dt.translate(correction, 0)
                        glyphsToDisplayTotalWidth += correction

                    if (indexChar - 1) == self.indexPair:
                        if correction is None:
                            offsetCorrection = 0
                        else:
                            offsetCorrection = correction
                        self._drawCursor(offsetCorrection, pairKind)

                # # draw metrics info
                if self.isMetricsActive is True:
                    self._drawMetricsData(eachGlyphName, 52)

                if self.isSidebearingsActive is True:
                    self._drawBaseline(eachGlyphName)
                    self._drawSidebearings(eachGlyphName)

                dt.translate(eachGlyph.width, 0)
                glyphsToDisplayTotalWidth += eachGlyph.width
                prevGlyphName = eachGlyphName
            dt.restore()

            # foreground loop
            dt.save()
            prevGlyphName = None
            for indexChar, eachGlyphName in enumerate(glyphsToDisplay):
                eachGlyph = self.fontObj[eachGlyphName]

                # this is for kerning
                if indexChar > 0:
                    correction, kerningReference, pairKind = getCorrection(
                        (prevGlyphName, eachGlyphName), self.fontObj)

                    if correction and correction != 0 and self.isKerningDisplayActive:
                        dt.translate(correction, 0)

                self._drawGlyphOutlines(eachGlyphName)
                dt.translate(eachGlyph.width, 0)

                prevGlyphName = eachGlyphName
            dt.restore()

            # collisions loop
            if self.areCollisionsShown is True:
                dt.save()
                prevGlyphName = None
                for indexChar, eachGlyphName in enumerate(glyphsToDisplay):
                    eachGlyph = self.fontObj[eachGlyphName]

                    if indexChar > 0:
                        correction, kerningReference, pairKind = getCorrection(
                            (prevGlyphName, eachGlyphName), self.fontObj)
                        if correction and correction != 0 and self.isKerningDisplayActive:
                            dt.translate(correction, 0)

                        if (indexChar - 1) == self.indexPair:
                            self._drawCollisions(
                                (prevGlyphName, eachGlyphName))

                    dt.translate(eachGlyph.width, 0)
                    prevGlyphName = eachGlyphName

                dt.restore()

            # main restore, it wraps the three loops
            dt.restore()

            if self.areVerticalLettersDrawn is True:
                # separate from the rest, we put the vertical letters
                dt.save()
                # we push the matrix forward
                dt.translate(self.ctrlWidth, 0)
                # then we rotate
                dt.rotate(90)
                # then we scale, but how much? a quarter of the main lettering
                dt.scale(
                    self.ctrlHeight /
                    (self.canvasScalingFactor * self.fontObj.info.unitsPerEm) *
                    .25)
                # the reference is the baseline, so we have to put some air below the letters
                dt.translate(0, 600)  # upm value
                # let's define the graphics
                dt.fill(*BLACK)
                dt.stroke(None)
                # then we draw, we need a prevGlyphName in order to get kerning correction
                prevGlyphName = None
                # we iterate on the letters we need to draw + a space as a margin
                for indexChar, eachGlyphName in enumerate(['space'] +
                                                          glyphsToDisplay):
                    # accessing the glyph obj
                    eachGlyph = self.fontObj[eachGlyphName]
                    # if it isn't the first letter...
                    if indexChar > 0:
                        # ... we grab the kerning correction from the pair
                        correction, kerningReference, pairKind = getCorrection(
                            (prevGlyphName, eachGlyphName), self.fontObj)
                        # if there is any correction...
                        if correction and correction != 0 and self.isKerningDisplayActive:
                            # ... we apply it to the transformation matrix
                            dt.translate(correction, 0)
                    # then we draw the outlines
                    self._drawGlyphOutlines(eachGlyphName)
                    # and we move the transformation matrix according to glyph width
                    dt.translate(eachGlyph.width, 0)
                    # then we load the glyph to the prevGlyphName
                    prevGlyphName = eachGlyphName
                # restoring the vertical drawing
                dt.restore()

        except Exception:
            print traceback.format_exc()
 def get(self):
     text = super(GlyphSequenceEditText, self).get()
     glyphNames = splitText(text, self._font.unicodeData)
     glyphs = [self._font[glyphName] for glyphName in glyphNames if glyphName in self._font]
     return glyphs
Example #18
0
    def getKernGroups(self, glyphRecord):
        thisFont = self.thisFont
        getGroups = self.getGroups
        fontKeys = thisFont.keys()
        glyphRecord = set(glyphRecord)
        return {gn:getGroups(gn) for gn in glyphRecord if gn in fontKeys}
        
    
    def stringToGlyphs(self, text):
        glyphRecord = []
        cmap = self.cmap
        if isinstance(text, str):
            text = unicode(text, 'utf8')
        lines = text.split('\n')
        for line in lines:    
            glyphRecord += splitText(line, cmap)
            glyphRecord.append('\n')
        glyphRecord.pop()     
        return glyphRecord


    def set(self, glyphInput, keepWords=False):
        thisFont = self.thisFont
        kerning = self.kerning
        fontKeys = thisFont.keys()
        if isinstance(glyphInput, str) or isinstance(glyphInput, unicode):
            glyphRecord = self.stringToGlyphs(glyphInput)
        elif isinstance(glyphInput, list):
            glyphRecord = glyphInput

        suffixes = self.settings['suffix']
Example #19
0
 def draw(self, info):
     
     if not self._drawing:
         return
         
     glyph = info.get("glyph")
     drawingScale = info.get('scale')
     
     if glyph is None:
         return
         
     current = glyph.getParent()
     fonts = self.getActiveFonts()
     
     for font in fonts:
         
         nakedFont = font.naked()
         
         contextLeft, contextCurrent, contextRight = self.getContexts()
         contextLeft = splitText(contextLeft or '', nakedFont.unicodeData or '')
         contextLeft = [font[gname] for gname in contextLeft if gname in font.keys()]
         contextRight = splitText(contextRight or '', nakedFont.unicodeData or '')
         contextRight = [font[gname] for gname in contextRight if gname in font.keys()]
         contextCurrent = splitText(contextCurrent or '', nakedFont.unicodeData or '')
         if len(contextCurrent) > 0:
             contextCurrent = [font[gname] for gname in [contextCurrent[0]] if gname in font.keys()]
             if len(contextCurrent) > 0:
                 sourceGlyph = contextCurrent[0]
             else:
                 sourceGlyph = None
         elif glyph.name in font.keys():
             sourceGlyph = font[glyph.name]
             contextCurrent = [sourceGlyph]
         else:
             sourceGlyph = None
             contextCurrent = []
         
         save()
         
         self._fillColor.setFill()
         self._strokeColor.setStroke()
         scale(current.info.unitsPerEm/float(font.info.unitsPerEm))
         
         # Draw left context
         previousGlyph = sourceGlyph
         contextLeft.reverse()
         totalWidth = 0
         for i, cbGlyph in enumerate(contextLeft):
             kernValue = self.getKernValue(nakedFont, cbGlyph, previousGlyph) # right to left
             translate(-cbGlyph.width-kernValue, 0)
             totalWidth += cbGlyph.width + kernValue
             glyphBezierPath = cbGlyph.naked().getRepresentation("defconAppKit.NSBezierPath")
             if self._fill:
                 glyphBezierPath.fill()
             if self._stroke:
                 glyphBezierPath.setLineWidth_(self._strokeWidth*drawingScale)
                 strokePixelPath(glyphBezierPath)
             previousGlyph = cbGlyph
         translate(totalWidth, 0)
         
         # Draw current context or current glyph 
         if contextCurrent:
             previousGlyph = None
             alignment = self.getAlignment()
             if alignment == 'left':
                 offset = 0
             elif alignment == 'center':
                 offset = (glyph.width - contextCurrent[0].width)/2                                        
             elif alignment == 'right':
                 offset = glyph.width - contextCurrent[0].width                                     
             totalWidth = offset
             translate(totalWidth, 0)
         
         for i, cbGlyph in enumerate(contextCurrent):
             #if cbGlyph == glyph:
             #    continue # Don't show if is current glyph
             kernValue = self.getKernValue(nakedFont, previousGlyph, cbGlyph)
             translate(kernValue, 0)
             glyphBezierPath = cbGlyph.naked().getRepresentation("defconAppKit.NSBezierPath")
             if self._fill:
                 glyphBezierPath.fill()
             if self._stroke:
                 glyphBezierPath.setLineWidth_(self._strokeWidth*drawingScale)
                 strokePixelPath(glyphBezierPath)
             if self._points:
                 self.drawPoints(cbGlyph, info['scale'])
             translate(cbGlyph.width, 0)
             totalWidth += cbGlyph.width + kernValue
             previousGlyph = cbGlyph
         translate(-totalWidth, 0)
         
         # Draw right context
         translate(glyph.width)
         totalWidth = glyph.width
         for i, cbGlyph in enumerate(contextRight):
             kernValue = self.getKernValue(nakedFont, previousGlyph, cbGlyph)
             translate(kernValue, 0)
             glyphBezierPath = cbGlyph.naked().getRepresentation("defconAppKit.NSBezierPath")
             if self._fill:
                 glyphBezierPath.fill()
             if self._stroke:
                 glyphBezierPath.setLineWidth_(self._strokeWidth*drawingScale)
                 strokePixelPath(glyphBezierPath)
             translate(cbGlyph.width, 0)
             totalWidth += cbGlyph.width + kernValue
             previousGlyph = cbGlyph
             
         restore()
Example #20
0
 def set(self, text):
     glyphNames = splitText(text, self._font.getCharacterMapping())
     # this assumes that the naked glyph will be defcon based.
     # the only other option is to fork the defocnAppKit code to use only RoboFab objects.
     glyphs = [self._font[glyphName].naked() for glyphName in glyphNames if glyphName in self._font]
     super(GlyphLineView, self).set(glyphs)