Пример #1
0
 def _flip_callback(self, sender):
     font = CurrentFont()
     if font is not None:
         glyph_names = get_glyphs(font)
         # get foreground anchors
         anchors_dict = get_anchors(font, glyph_names)
         for glyph_name in glyph_names:
             # flip layers (including anchors)
             font[glyph_name].prepareUndo('flip mask')
             font[glyph_name].flipLayers('foreground', self.mask_layer)
             # keep anchors from source layer in foreground
             if not self.w.flip_anchors.get():
                 if glyph_name in anchors_dict:
                     for anchor in anchors_dict[glyph_name]:
                         anchor_name, anchor_pos = anchor
                         font[glyph_name].appendAnchor(anchor_name, anchor_pos)
                         font[glyph_name].update()
                 # remove anchors from dest layer
                 dest_glyph = font[glyph_name].getLayer(self.mask_layer)
                 dest_glyph.clearAnchors()
             # done with glyph
             font[glyph_name].performUndo()
         # done with font
         font.update()
     else:
         print(no_font_open)
Пример #2
0
def getOtherMaster(nextFont=True, shuffleFont=False):
    cf = CurrentFont()
    orderedFonts = []
    fonts = {}
    for f in AllFonts():
        if f.path is None:
            continue
        fonts[f.path] = f
    sortedPaths = list(fonts.keys())
    sortedPaths.sort()
    #
    if shuffleFont:
        shufflePaths = sortedPaths[:]
        shufflePaths.remove(cf.path)
        shuffledPath = random.choice(shufflePaths)
        return fonts[shuffledPath]

    for i in range(len(sortedPaths)):
        if cf.path == fonts[sortedPaths[i]].path:
            prev = fonts[sortedPaths[i - 1]]
            nxt = fonts[sortedPaths[(i + 1) % len(sortedPaths)]]
            if nextFont:
                return nxt
            else:
                return prev
Пример #3
0
 def apply_callback(self, sender):
     f = CurrentFont()
     if f is not None:
         # get layer name
         layer_name_option = self.w.layer_name.get()
         # mask layer
         if not layer_name_option:
             layer_name = 'background'
         # font name
         else:
             layer_name = os.path.split(self.ufo_path)[1]
         # import layer
         print('importing .ufo...\n')
         print('\ttarget layer: %s\n' % layer_name)
         ufo = RFont(self.ufo_path, showUI=False)
         for glyph_name in list(f.keys()):
             if glyph_name in ufo:
                 layer_glyph = f[glyph_name].getLayer(layer_name)
                 pen = layer_glyph.getPointPen()
                 ufo[glyph_name].drawPoints(pen)
                 f[glyph_name].update()
         f.update()
         print('...done.\n')
     # no font open
     else:
         print(no_font_open)
Пример #4
0
 def update(self):
     self.glyph_window = CurrentGlyphWindow()
     if self.glyph_window is not None:
         self.glyph = CurrentGlyph()
         self.font = self.glyph.getParent()
         self.glyph_index = self.font.glyphOrder.index(self.glyph.name)
         self.font_index = self.all_fonts.index(self.font)
         self._update_text_box()
         return True
     else:
         f = CurrentFont()
         if f is not None:
             self.font = f
             self.font_index = self.all_fonts.index(self.font)
             glyph_names = get_glyphs(f)
             if len(glyph_names) > 0:
                 self.glyph = self.font[glyph_names[0]]
                 self.glyph_index = self.font.glyphOrder.index(
                     self.glyph.name)
                 self.glyph_window = OpenGlyphWindow(self.glyph,
                                                     newWindow=False)
                 self._update_text_box()
                 return True
             else:
                 print(no_glyph_selected)
                 return False
         else:
             print(no_font_open)
             return False
    def update(self, sender=None):
        self.font = CurrentFont()
        if self.font is None:
            names = []
        else:
            names = self.getSelection()
        if len(names) == 0:
            self.w.l.set(self.sampleText)
            self.w.copyAsGlyphNames.setTitle("names")
            self.w.copyAsGlyphNamesComma.setTitle("quoted names + comma")
            self.w.copyAsSlashedNames.setTitle("slashed names")
            self.w.copyAsUnicode.setTitle("Unicode text")
            self.w.copyAsFeatureGroup.setTitle("feature group")
        else:
            self.w.l.set(names)
            self.w.copyAsGlyphNames.setTitle(
                self._asTitle(self._asSpacedNames(names)))
            self.w.copyAsGlyphNamesComma.setTitle(
                self._asTitle(self._asQuotesAndCommasNames(names)))

            self.w.copyAsSlashedNames.setTitle(
                self._asTitle(self._asSlashedNames(names)))
            self.w.copyAsUnicode.setTitle(
                self._asTitle(self._asUnicodeText(names)))
            self.w.copyAsFeatureGroup.setTitle(
                self._asTitle(self._asFeatureGroup(names)))
        if len(names) == 0:
            if self.font is None:
                self.w.caption.set("No current font")
            else:
                self.w.caption.set("No glyphs selected")
        else:
            self.w.caption.set("Copy %d names" % (len(names)))
Пример #6
0
 def apply_callback(self, sender):
     f = CurrentFont()
     if f is not None:
         glyph_names = get_glyphs(f)
         if len(glyph_names) > 0:
             # get parameters
             old = self.w._old_name_value.get()
             new = self.w._new_name_value.get()
             boolstring = (False, True)
             # print info
             print 'renaming anchors in glyphs...\n'
             print '\told name: %s' % old
             print '\tnew name: %s' % new
             print
             print '\t',
             # change anchors names
             for glyph_name in glyph_names:
                 print glyph_name,
                 # rename anchor
                 f[glyph_name].prepareUndo('rename anchor')
                 has_name = rename_anchor(f[glyph_name], old, new)
                 f[glyph_name].performUndo()
                 f[glyph_name].update()
             # done
             f.update()
             print
             print '\n...done.\n'
         # no glyph selected
         else:
             print no_glyph_selected
     # no font open
     else:
         print no_font_open
Пример #7
0
 def copy_callback(self, sender):
     f = CurrentFont()
     glyph_name = get_glyphs(f)[0]
     print('copied glyph %s' % glyph_name)
     self.source_font = f
     self.source_glyph = self.source_font[glyph_name]
     print()
Пример #8
0
 def apply_callback(self, sender):
     f = CurrentFont()
     if f is not None:
         glyph_names = get_glyphs(f)
         if len(glyph_names) > 0:
             print('applying actions to selected glyphs...\n')
             for action in list(self.actions.keys()):
                 if self.actions[action]:
                     print('\t%s' % action)
             print()
             print('\t', end=' ')
             for glyph_name in glyph_names:
                 print(glyph_name, end=' ')
                 # current layer only
                 if not self.actions['all layers']:
                     self.apply_actions(f[glyph_name])
                 # all layers
                 else:
                     for layer_name in f.layerOrder:
                         layer_glyph = f[glyph_name].getLayer(layer_name)
                         self.apply_actions(layer_glyph)
                 # done glyph
                 f[glyph_name].update()
             # done font
             print()
             print('\n...done.\n')
         # no glyph selected
         else:
             print(no_glyph_selected)
     # no font open
     else:
         print(no_font_open)
Пример #9
0
    def getMorfFont(self, sender):
        f = CurrentFont()
        self.font = f
        self.currentRecipe = self.font.lib['morf']['recipes'].keys()[
            self.w.recipe.get()]
        recipe = self.currentRecipe
        nf = f.copy()
        nf.info.styleName = self.currentRecipe

        glyphs = f.keys()

        for gn in glyphs:
            g = f[gn]
            #if 1:
            if 'morf' in g.lib.keys() and recipe in g.lib['morf'].keys():
                self.widthBy = g.lib['morf'][recipe]['widthBy']
                self.heightBy = g.lib['morf'][recipe]['heightBy']
                self.factor = g.lib['morf'][recipe]['factor']
                self.weightByX = g.lib['morf'][recipe]['weightByX']
                self.weightByY = g.lib['morf'][recipe]['weightByY']
            else:
                self.getDefaultValues()
            # self.getDefaultValues()
            path = GetMorfGlyph(g, self.factor, self.weightByX, self.weightByY,
                                self.widthBy, self.heightBy).path
            if path and type(path) != type(""):
                # print g
                nf.newGlyph(g.name)
                nf[g.name].width = g.width * self.widthBy

                writePathInGlyph(path, nf[g.name])
                nf[g.name].round()
            else:
                continue
        nf.showUI()
Пример #10
0
 def _rasterize_callback(self, sender):
     font = CurrentFont()
     if font is not None:
         glyph_names = get_glyphs(font)
         if len(glyph_names) > 0:
             gridsize = int(self.w.spinner.value.get())
             res = (gridsize, gridsize)
             self.w.bar.start()
             print "rasterizing glyphs...\n"
             for glyph_name in glyph_names:
                 glyph = font[glyph_name]
                 print '\tscanning %s...' % glyph_name
                 glyph.prepareUndo('rasterize glyph')
                 R = RasterGlyph(glyph)
                 R.rasterize(res=res)
                 glyph.update()
                 glyph.performUndo()
             # done
             font.update()
             self.w.bar.stop()
             print "\n...done.\n"
         # no glyph selected
         else:
             print no_glyph_selected
     # no font open
     else:
         print no_font_open
Пример #11
0
 def expandSelection(self, sender):
     font = CurrentFont()
     preserveComponents = bool(self.w.preserveComponents.get())
     selection = font.selection
     for glyphName in selection:
         glyph = font[glyphName]
         self.expandGlyph(glyph, preserveComponents)
Пример #12
0
 def paint_callback(self, sender):
     f = CurrentFont()
     if f is not None:
         _mark_color = self.w.mark_color.get()
         _mark_color = (
             _mark_color.redComponent(),
             _mark_color.greenComponent(),
             _mark_color.blueComponent(),
             _mark_color.alphaComponent(),
         )
         glyph_names = get_glyphs(f)
         if len(glyph_names) > 0:
             print('painting selected glyphs...\n')
             print('\tcolor: %s %s %s %s' % _mark_color)
             print()
             print('\t', end=' ')
             for glyph_name in glyph_names:
                 print(glyph_name, end=' ')
                 f[glyph_name].prepareUndo('paint glyph')
                 f[glyph_name].mark = _mark_color
                 f[glyph_name].performUndo()
             print()
             print('\n...done.\n')
         # no glyph selected
         else:
             print(no_glyph_selected)
     # no font open
     else:
         print(no_font_open)
    def draw(self, info):
        if not self.calculatePreview:
            return
        cur = CurrentGlyph()
        if cur == None:
            return

        scale = info['scale']
        layerToConvert = self.layers[self.w.layerPopup.get()]
        otherLayer = layerToConvert != 'foreground'
        if (not otherLayer) and (
                CurrentFont().lib['com.typemytype.robofont.segmentType']
                == 'qcurve'):
            return
        if otherLayer: cur.flipLayers('foreground', layerToConvert)
        copy = cur.copy()
        if otherLayer: cur.flipLayers('foreground', layerToConvert)
        convert(copy, self.maxDistanceValue, self.minLengthValue,
                self.useArcLength)

        for c in copy:
            for p in c.points:
                if p.type == 'offCurve':
                    color = OffColor
                    r = 4 * scale
                else:
                    color = OnColor
                    r = 6 * scale
                self.drawDiscAtPoint(r, p.x, p.y, color)
        save()
        stroke(0.2, .8, .8, 1)
        fill(None)
        strokeWidth(scale)
        drawGlyph(copy)
        restore()
Пример #14
0
 def clear_callback(self, sender):
     font = CurrentFont()
     if font is not None:
         delete_groups(font)
     # no font open
     else:
         print no_font_open
Пример #15
0
    def compileGlyphs(self, sender):
        """
        need to rewrite for RF3
        """
        font = CurrentFont()
        g = CurrentGlyph()
        base = g.name
        l = self.w.list.get()
        for i in l:
            if i['checkBox']:
                accent = i['construction']['accent']
                anchor = i['construction']['anchor']
                compo = "testcompo"  # self.sd[base][accent][anchor]
                if base not in font.keys():
                    continue
                if accent not in font.keys():
                    continue

                inBase, height = anchorInGlyph(anchor, font[base])
                if inBase and height > 600:
                    if accent + ".cap" in font.keys():
                        accent = accent + ".cap"
                inAccent, height = anchorInGlyph(anchor, font[accent])
                construction = "%s = %s + %s@%s" % (compo, base, accent,
                                                    anchor)

                if not inBase:
                    continue
                if not inAccent:
                    continue

                self.compileGlyph(construction)
Пример #16
0
 def apply_callback(self, sender):
     font = CurrentFont()
     if font is not None:
         glyph_names = get_glyphs(font)
         # transform glyphs
         if len(glyph_names) > 0:
             # get parameters
             delta = int(self.w.delta_spinner.value.get())
             join = self.w.join.get()
             cap = self.w.cap.get()
             # print info
             print('applying stroke to skeletons...\n')
             print('\tdelta: %s' % delta)
             print('\tjoin style: %s' % self.stroke_parameters[join])
             print('\tcap style: %s' % self.stroke_parameters[cap])
             print()
             print('\t', end=' ')
             # apply outline
             for glyph_name in glyph_names:
                 src_glyph = dst_glyph = font[glyph_name]
                 print(glyph_name, end=' ')
                 expand(src_glyph, dst_glyph, delta, join, cap)
             print()
             print('\n...done.\n')
         # no glyph selected
         else:
             print(no_glyph_selected)
     # no font open
     else:
         print(no_font_open)
Пример #17
0
 def _mirror_glyphs(self, xxx_todo_changeme2):
     (scale_x, scale_y) = xxx_todo_changeme2
     f = CurrentFont()
     if f is not None:
         glyph_names = get_glyphs(f)
         if len(glyph_names):
             print('reflecting selected glyphs...\n')
             print('\t', end=' ')
             for glyph_name in glyph_names:
                 print(glyph_name, end=' ')
                 # mirror all layers
                 if self.layers:
                     for layer_name in f.layerOrder:
                         _g = f[glyph_name].getLayer(layer_name)
                         self._mirror_glyph(_g, (scale_x, scale_y))
                 # mirror active layer only
                 else:
                     self._mirror_glyph(f[glyph_name], (scale_x, scale_y))
                 # done with glyph
                 f[glyph_name].update()
             # done with font
             f.update()
             print()
             print('\n...done.\n')
         # no glyph selected
         else:
             print(no_glyph_selected)
     # no font open
     else:
         print(no_font_open)
 def apply_callback(self, sender):
     # get font
     font = CurrentFont()
     if font is not None:
         # get glyphs
         glyph_names = font.selection
         if len(glyph_names) > 0:
             # get values
             esize = get_esize(font)
             self.rand_min = self.w.spinner_min.value.get()
             self.rand_max = self.w.spinner_max.value.get()
             # randomize elements
             for glyph_name in glyph_names:
                 w = font[glyph_name].width
                 g = RasterGlyph(font[glyph_name])
                 g.rasterize()
                 randomize_elements(font[glyph_name], esize, (self.rand_min, self.rand_max))
                 font[glyph_name].width = w
             font.update()
         # no glyph selected
         else:
             print no_glyph_selected
     # no font open
     else:
         print no_font_open
Пример #19
0
 def _glyph_changed(self, notification):
     if self.glyph is not None:
         self.save_settings()
     self.glyph = notification["glyph"]
     self.font = CurrentFont()
     self.font_layers = self.getLayerList()
     if self.glyph is not None:
         self.load_settings()
Пример #20
0
 def updateGlyphList(self):
     if self.activeFontPath == CURRENT_FONT_REPR:
         activeFont = CurrentFont()
     else:
         activeFont = getOpenedFontFromPath(AllFonts(), self.activeFontPath)
     activeGlyphOrder = makeGlyphList(activeFont)
     self.glyphPop.setItems(activeGlyphOrder)
     self.glyphPop.set(activeGlyphOrder.index(self.activeGlyphName))
Пример #21
0
 def prepareFontsToAction(self):
     if self.whichFont == 'All Fonts':
         fontsToProcess = AllFonts()
     elif self.whichFont == 'Current Font':
         fontsToProcess = [CurrentFont()]
     else:
         fontsToProcess = [self.whichFont]
     return fontsToProcess
Пример #22
0
 def print_callback(self, sender):
     font = CurrentFont()
     if font is not None:
         _mode = self.w._mode.get()
         print_groups(font, mode=_mode)
     # no font open
     else:
         print no_font_open
Пример #23
0
 def update_font(self):
     self.font = CurrentFont()
     if self.font is not None:
         self.w.box.text.set(get_full_name(self.font))
         self.set_defaults()
         self.restore_x()
         self.restore_y()
     else:
         print no_font_open
Пример #24
0
 def setInFontCallback(self, sender):
     if self.w.fontSelection.get() == 0:
         if CurrentFont() is not None:
             fonts = [CurrentFont()]
         else:
             fonts = []
     else:
         fonts = AllFonts()
     for f in fonts:
         with f.undo('italicBowtie'):
             f.info.italicAngle = self.getItalicAngle()
             f.lib[self.italicSlantOffsetKey] = self.getItalicSlantOffset()
     try:
         window = CurrentGlyphWindow()
         window.setGlyph(CurrentGlyph().naked())
     except Exception:
         print(self.DEFAULTKEY, 'error resetting window, please refresh it')
     self.updateBowtie()
Пример #25
0
 def __init__(self):
     self.font = CurrentFont()
     if self.font is None:
         return
     doc = self.font.document()
     if doc is None:
         return
     self.window = doc.getMainWindow()
     vanilla.dialogs.getFolder(parentWindow=self.window, resultCallback=self.generate)
Пример #26
0
    def buildAccentList(self, sender=None):
        self.w = getExtensionDefault(settingsWindow)
        if not self.w:
            return
        font = CurrentFont()
        glyph = CurrentGlyph()

        if glyph is None:
            self.w.setTitle("---")
            self.w.list.set([])
            return

        glyphName = glyph.name
        self.w.setTitle(glyphName)

        if "." in glyphName:
            glyphName = glyphName.split(".")[0]

        theAccentsList = []
        # defaults = getExtensionDefault(defaultKey+".check", dict())
        if glyphName in self.baseDict:
            for accent in self.baseDict[glyphName]['accents']:
                for c in self.baseDict[glyphName]['constructions']:
                    # print(c)
                    if c['accent'] == accent:
                        position = c['anchor']
                        thisConstructon = c
                        if position not in pijlen.keys():
                            pijlen[position] = position

                theAccentsList.append(
                    dict(
                        anchor=pijlen[position],
                        accent=accent,
                        checkBox=getExtensionDefault(
                            defaultKey + "." + accent + "@" + position, True),
                        construction=thisConstructon,
                    ), )
        if glyphName in self.accentDict:
            for base in self.accentDict[glyphName]['bases']:
                for c in self.accentDict[glyphName]['constructions']:
                    # print(c)
                    if c['base'] == base:
                        position = c['anchor']
# key = defaultKey+"."+item["accent"]+"@"+anchor
                theAccentsList.append(
                    dict(
                        anchor=pijlen[position],
                        accent=base,
                        checkBox=getExtensionDefault(
                            defaultKey + "." + base + "@" + position, True),
                        construction=self.accentDict[glyphName],
                    ), )

        self.w.list.set(theAccentsList)
        # print len(items)
        self.w.resize(160, 17 + 17 + 17 + 17 + (19 * len(theAccentsList)) + 21)
Пример #27
0
 def _currentFontChanged(self, info):
     self.font.naked().removeObserver(self, "Font.Changed")
     self.font = CurrentFont()
     self.font.naked().addObserver(self, "fontWasModified", "Font.Changed")
     self.w.lineView.setFont(self.font)
     self.fillAnchorsAndMarksDicts()
     del self.glyphNamesList[:]
     del self.selectedGlyphNamesList[:]
     self.updateExtensionWindow()
Пример #28
0
 def draw_background(self, notification):
     s = notification['scale']
     g1 = notification['glyph']
     # get colors
     _mark_color = self.w.mark_color.get()
     _mark_color = (
         _mark_color.redComponent(),
         _mark_color.greenComponent(),
         _mark_color.blueComponent(),
         _mark_color.alphaComponent(),
     )
     _mark_color_2 = self.w.mark_color_2.get()
     _mark_color_2 = (
         _mark_color_2.redComponent(),
         _mark_color_2.greenComponent(),
         _mark_color_2.blueComponent(),
         _mark_color_2.alphaComponent(),
     )
     # get fonts
     f1 = CurrentFont()
     i = self.w.f2.get()
     f2 = self.all_fonts[sorted(self.all_fonts.keys())[i]]
     r = 2
     # interpolate steps
     if f1 != f2:
         # check if f2 has this glyph
         if f2.has_key(g1.name):
             g2 = f2[g1.name]
             # check if glyph in f2 is compatible
             if g1.isCompatible(g2):
                 # create colors
                 c1 = Color.NewFromRgb(*_mark_color)
                 c2 = Color.NewFromRgb(*_mark_color_2)
                 colors = c1.Gradient(c2, self.steps)
                 # create steps and draw
                 for i in range(self.steps):
                     factor = i * (1.0 / (self.steps - 1))
                     g3 = RGlyph()
                     g3.interpolate(factor, g1, g2)
                     save()
                     fill(None)
                     stroke(*colors[i])
                     strokeWidth(s)
                     if g3.width != g1.width:
                         diff = g3.width - g1.width
                         translate(-diff * 0.5, 0)
                     drawGlyph(g3)
                     for c in g3.contours:
                         for pt in c.points:
                             rect(pt.x - r, pt.y - r, r * 2, r * 2)
                     restore()
                 # done
                 # restore()
         else:
             if self.verbose:
                 print '%s not in font 2' % g1.name
Пример #29
0
    def fitButtonCallback(self, sender):
        if self.fontTarget == 'All Fonts':
            fontsToProcess = AllFonts()
        else:
            fontsToProcess = [CurrentFont()]

        for eachFont in fontsToProcess:
            if self.glyphTarget == 'All Glyphs':
                glyphNamesToProcess = eachFont.glyphOrder
            elif self.glyphTarget == 'Selection':
                glyphNamesToProcess = CurrentFont().selection
            else:
                glyphNamesToProcess = [CurrentGlyph().name]

            for eachName in glyphNamesToProcess:
                eachGlyph = eachFont[eachName]
                gridFit(eachGlyph,
                        self.gridSize,
                        bcpHandlesFit=self.bcpHandlesFit)
Пример #30
0
    def cleanButtonCallback(self, sender):
        if self.target == 'All Fonts':
            fontsToProcess = AllFonts()
        else:
            fontsToProcess = [CurrentFont()]

        for eachFont in fontsToProcess:
            for eachTargetName, _ in self.transferList:
                if eachTargetName in eachFont:
                    eachFont[eachTargetName].clear()