def fontChanged(self, notification):
     if 'font' in notification:
         self.releaseObservedGlyphs()
         self.stringInput(self.w.textInput)
         self.currentFont = notification['font']
         self.cachedFont = RFont(showUI=False)
         self.updatePreview()
Beispiel #2
0
 def initCachedFont(self):
     currentFont = self.currentFont
     self.cachedFont = RFont(showUI=False)
     if currentFont is not None:
         for metric in ['ascender', 'descender', 'unitsPerEm']:
             setattr(self.cachedFont.info, metric,
                     getattr(currentFont.info, metric))
 def resetRepresentations(self):
     font = self.currentFont
     self.cachedFont = RFont(showUI=False)
     if font is not None:
         for glyphName in self.glyphNames:
             if glyphName in font:
                 font[glyphName].naked().destroyAllRepresentations()
Beispiel #4
0
 def generateGlyphsToFont(self, exportFont=None, layerName=None):
     font = RFont(showUI=False) if exportFont is None else exportFont
     currentFont = self.currentFont
     filterName = self.currentFilterName
     currentFilter = self.filters[filterName]
     if currentFont is not None and len(currentFont.selection):
         glyphs = [
             currentFont[glyphName] for glyphName in currentFont.selection
             if glyphName in currentFont
         ]
         for glyph in glyphs:
             if len(glyph.components) > 0:
                 for comp in glyph.components:
                     baseGlyphName = comp.baseGlyph
                     baseGlyph = currentFont[baseGlyphName]
                     baseFilteredGlyph = currentFilter(baseGlyph)
                     newFont.insertGlyph(baseFilteredGlyph, baseGlyphName)
                     newFont[
                         baseGlyphName].unicode = baseFilteredGlyph.unicode
             filteredGlyph = currentFilter(glyph)
             if filteredGlyph is not None:
                 if exportFont is None:
                     font.insertGlyph(filteredGlyph, glyph.name)
                 else:
                     glyph = font[
                         glyph.name] if layerName is None else font[
                             glyph.name].getLayer(layerName)
                     glyph.clearContours()
                     glyph.clearComponents()
                     glyph.appendGlyph(filteredGlyph)
         font.showUI()
     else:
         message(u'PenBallWizard', 'No selected glyphs to generate')
 def showWindow(self, font):
     try:
         a = []
         for idx in range(len(font.masters)):
             a.append(RFont(font, idx))
         FlexibleWindow(a)
     except:
         import traceback
         print(traceback.format_exc())
     return (True, None)
    def __init__(self):
        self.filters = PenBallFiltersManager()
        self.filters.loadFiltersFromJSON('/'.join([LOCALPATH, JSONFILE]))
        self.glyphNames = []
        self.observedGlyphs = []
        self.cachedFont = RFont(showUI=False)
        self.currentFont = CurrentFont()
        filtersList = self.filters.keys()
        if len(filtersList) > 0:
            self.currentFilterName = filtersList[0]
        else:
            self.currentFilterName = None
        self.fill = True

        self.observers = [
            ('fontChanged', 'fontBecameCurrent'),
            ('fontChanged', 'fontDidOpen'),
            ('fontChanged', 'fontDidClose'),
        ]

        self.w = Window((100, 100, 800, 500), 'PenBall Wizard v{0}'.format(__version__), minSize=(500, 400))
        self.w.filtersPanel = Group((0, 0, 300, -0))
        self.w.filtersPanel.filtersList = List((0, 0, -0, -40), filtersList, selectionCallback=self.filterSelectionChanged, doubleClickCallback=self.filterEdit, allowsMultipleSelection=False, allowsEmptySelection=False, rowHeight=22)
        self.w.filtersPanel.controls = Group((0, -40, -0, 0))
        self.w.filtersPanel.addFilter = SquareButton((0, -40, 100, 40), 'Add filter', sizeStyle='small', callback=self.addFilter)
        self.w.filtersPanel.addFilterChain = SquareButton((100, -40, 100, 40), 'Add operations', sizeStyle='small', callback=self.addFilterChain)
        self.w.filtersPanel.removeFilter = SquareButton((-100, -40, 100, 40), 'Remove filter', sizeStyle='small', callback=self.removeFilter)
        self.w.textInput = EditText((300, 0, -90, 22), '', callback=self.stringInput)
        self.w.generate = SquareButton((-90, 0, 90, 22), 'Generate', callback=self.generateGlyphsToFont, sizeStyle='small')
        self.w.preview = MultiLineView((300, 22, -0, -0))
        self.w.switchFillStroke = SquareButton((-75, -40, 60, 25), 'Stroke', callback=self.switchFillStroke, sizeStyle='small')
        displayStates = self.w.preview.getDisplayStates()
        for key in ['Show Metrics','Upside Down','Stroke','Beam','Inverse','Water Fall','Multi Line']:
            displayStates[key] = False
        for key in ['Fill','Single Line']:
            displayStates[key] = True
        self.w.preview.setDisplayStates(displayStates)

        for callback, event in self.observers:
            addObserver(self, callback, event)

        self.updateControls()

        self.w.bind('close', self.end)
        self.launchWindow()
        self.w.open()
Beispiel #7
0
def SelectFont(message="Select a font:", title='RoboFab'):
    """
	Returns font instance if there is one, otherwise it returns None.
	Availability: FontLab
	"""
    from robofab.world import RFont
    if inFontLab:
        list = []
        for i in range(fl.count):
            list.append(fl[i].full_name)
        name = OneList(list, message, title)
        if name is None:
            return None
        else:
            return RFont(fl[list.index(name)])
    else:
        _raisePlatformError('SelectFont')
 def generateGlyphsToFont(self, sender):
     newFont = RFont(showUI=False)
     font = self.currentFont
     filterName = self.currentFilterName
     currentFilter = self.filters[filterName]
     if font is not None:
         glyphs = [font[glyphName] for glyphName in font.selection if glyphName in font]
         for glyph in glyphs:
             if len(glyph.components) > 0:
                 for comp in glyph.components:
                     baseGlyphName = comp.baseGlyph
                     baseGlyph = font[baseGlyphName]
                     baseFilteredGlyph = currentFilter(baseGlyph)
                     newFont.insertGlyph(baseFilteredGlyph, baseGlyphName)
                     newFont[baseGlyphName].unicode = baseFilteredGlyph.unicode
             filteredGlyph = currentFilter(glyph)
             if filteredGlyph is not None:
                 newFont.insertGlyph(filteredGlyph, glyph.name)
         newFont.showUI()
 def filterSelectionChanged(self, sender):
     selectedFilterName = self.getSelectedFilterName()
     self.cachedFont = RFont(showUI=False)
     self.currentFilterName = selectedFilterName
     self.updateControls()
     self.updatePreview()
Beispiel #10
0
# robothon06
# demo of executing python in FontLab, MacOS only

# this script runs in the Python IDE
# it will send some python code to FontLab
# FontLab will execute the python code:
# it will find the current glyph and send it to our other script.

from robofab.tools.remote import runFontLabRemote, receiveGlyph
from robofab.world import RFont

# this is what we want FontLab to do:
pythonCode = """
from robofab.world import CurrentGlyph
from robofab.tools.remote import transmitGlyph
g = CurrentGlyph()
transmitGlyph(g)
"""

# this the font where we'll store the glyph from FontLab
destFont = RFont()

result = runFontLabRemote(pythonCode)
receiveGlyph(result, destFont)
print destFont.keys()
Beispiel #11
0
#coding=utf-8

from mutatorScale.objects.scaler import MutatorScaleEngine
from mutatorScale.utilities.fontUtils import intersect
from robofab.world import RFont

paths = [
    'testFonts/two-axes/regular-low-contrast.ufo',
    'testFonts/two-axes/bold-low-contrast.ufo'
]
outputPath = 'testFonts/two-axes/scaled-low-contrast.ufo'

fonts = []
for p in paths:
    fonts.append(RFont(p))

scaler = MutatorScaleEngine(fonts)
scaler.set({'scale': (0.85, 0.8)})

outputFont = RFont()
for glyphName in 'AHIO':
    glyph = scaler.getScaledGlyph(glyphName, (95, 75))
    outputFont.insertGlyph(glyph, glyphName)

outputFont.save(outputPath)
Beispiel #12
0
        if not callable(test):
            raise
    except:
        raise AttributeError(
            '''\
            Please update your objectsGS.py file.
            Download the latest verion at:
            https://github.com/schriftgestalt/Glyphs-Scripts''')


# Check if a font is open -- if not, create a new one.

f = CurrentFont()

if f is None:
    f = RFont()

if f is not None and inGlyphs:
    f._object.font.disableUpdateInterface()


names = {
    # List of glyphs and their drawing recipes.

    # Lines:
    ('lighthorzbxd',
        '2500'): ['horBar()'],

    ('heavyhorzbxd',
        '2501'): ['horBar(FAT)'],
Beispiel #13
0

def allGlyphs(groups, spacer=None):
    allGlyphs = ""
    skip = ['invisible']
    for groupName in groups.keys():
        if groupName in skip:
            pass
        else:
            gNamesList = groups[groupName]
            allGlyphs += makeString(gNamesList, spacer)
    return allGlyphs


def drawGlyph(gName, ufo_path, (x, y), context, _color=None, _scale=1):
    _ufo = RFont(ufo_path)
    _pen = NodeBoxPen(_ufo._glyphSet, context)
    _units_per_em = _ufo.info.unitsPerEm
    _units_per_element = 64
    _ppem = _units_per_em / _units_per_element
    # draw glyph outline
    context.stroke(None)
    if _color is not None:
        context.fill(_color)
    else:
        context.fill(1, 0, .5, .3)
    g = _ufo[gName]
    context.push()
    context.transform(mode='CORNER')
    context.translate(x, y)
    context.scale(_scale)
Beispiel #14
0
def loadUfoFont(fontFile):
    if not file_exists(fontFile):
        sys.exit(error_messages['font_not_found'] + ' Supplied: ' + fontFile)
    else:
        return RFont(fontFile)
#FLM: RoboFab Intro, Interpolating two fonts

#	Basic interpolation of two fonts. This is clean
#	non-FontLab specific implementation of
#	interpolating. This interpolation is strict: it
#	adds no points to contours, it does not alter
#	the outlines of the extremes in any possible
#	way. Note that this works in FontLab as well as
#	NoneLab.
#
#	In fontlab: select two .vfb files, the result will be a new .vfb
#	In NoneLab: select two .ufo files, the result will be a new .ufo

from robofab.world import OpenFont, RFont, RGlyph
from robofab.pens.pointPen import AbstractPointPen
from robofab.interface.all.dialogs import GetFolder

f = OpenFont(None, "First master")
g = OpenFont(None, "Second master")

factor = .5

d = RFont()
d.interpolate(factor, f, g)

path = GetFolder("Select a place to save this UFO")
if path:
    d.save(path)

print 'done'