diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..66829ef --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store* \ No newline at end of file diff --git a/UI/drawAntialiasedStroke.py b/UI/drawAntialiasedStroke.py new file mode 100644 index 0000000..831bf91 --- /dev/null +++ b/UI/drawAntialiasedStroke.py @@ -0,0 +1,64 @@ +from AppKit import * +from fontTools.pens.basePen import BasePen + +from mojo.events import addObserver +from lib.tools.defaults import getDefaultColor + + +class AntialiasCocoaPen(BasePen): + + """ + - create a nsBezierPath for each segment. + - Straight lines are ignored. + """ + + def __init__(self, glyphSet): + BasePen.__init__(self, glyphSet) + self.path = NSBezierPath.bezierPath() + self.prevPoint = None + self.firstPoint = None + + def _moveTo(self, pt): + self.firstPoint = pt + self.prevPoint = pt + + def _lineTo(self, pt): + if pt[0] != self.prevPoint[0] and pt[1] != self.prevPoint[1]: + # only draw the antialiased line if x or y is different + self.path.moveToPoint_(self.prevPoint) + self.path.lineToPoint_(pt) + self.prevPoint = pt + + def _curveToOne(self, pt1, pt2, pt3): + self.path.moveToPoint_(self.prevPoint) + self.path.curveToPoint_controlPoint1_controlPoint2_(pt3, pt1, pt2) + self.prevPoint = pt3 + + def closePath(self): + if self.firstPoint != self.prevPoint: + self._lineTo(self.firstPoint) + self.prevPoint = None + + +class NiceLines(object): + + def __init__(self): + ## add observer when the glyph view draws the content + addObserver(self, "myDraw", "drawBackground") + ## get the stroke color from the defaults + self.strokeColor = getDefaultColor("glyphViewStrokeColor") + + def myDraw(self, glyph, info): + ## initiate the pen + pen = AntialiasCocoaPen(glyph.getParent()) + ## draw the glyph in the pen + glyph.draw(pen) + ## set the stroke color + self.strokeColor.set() + ## set the line width of the path, the same as the scale of the glyph view + pen.path.setLineWidth_(info["scale"]) + ## stroke the path + pen.path.stroke() + +## install the observer +NiceLines() \ No newline at end of file diff --git a/objectBrowser/objectBrowser.py b/objectBrowser/objectBrowser.py new file mode 100644 index 0000000..fde5ba6 --- /dev/null +++ b/objectBrowser/objectBrowser.py @@ -0,0 +1,23 @@ +import vanilla +import mojo + +class ObjectBrowserController(): + + def __init__(self, inspectObject): + + if inspectObject is None: + raise TypeError, "can not inspect None value" + + self.w = vanilla.Window((400, 400), + "inspect %s" %inspectObject, + minSize=(100, 100)) + self.w.b = vanilla.ObjectBrowser((0, 0, -0, -0), + inspectObject) + self.w.open() + + +#obj = vanilla +#obj = mojo +obj = CurrentFont() + +ObjectBrowserController(obj) \ No newline at end of file diff --git a/openFonts/openFontInLayer.py b/openFonts/openFontInLayer.py new file mode 100644 index 0000000..4bece9e --- /dev/null +++ b/openFonts/openFontInLayer.py @@ -0,0 +1,19 @@ +f = OpenFont(showUI=False) + +cf = CurrentFont() + +layerName = "%s_%s" %(f.info.familyName, f.info.styleName) + +for g in f: + if g.name not in cf: + cf.newGlyph(g.name) + + layerGLyph = cf[g.name].getLayer(layerName) + + pen = layerGLyph.getPointPen() + g.drawPoints(pen) + +print "done" + + + diff --git a/simpleMoveExample/moveGlyphWinow.py b/simpleMoveExample/moveGlyphWinow.py new file mode 100644 index 0000000..aef45d3 --- /dev/null +++ b/simpleMoveExample/moveGlyphWinow.py @@ -0,0 +1,39 @@ +from vanilla import * + +class MoveGlyphWindow: + def __init__(self, glyph): + if glyph is None: + print "There should be a glyph window selected!!" + return + self.glyph = glyph + + self.moveX = 0 + self.moveY = 0 + + self.w = Window((200, 60), "Move %s" %self.glyph.name) + + self.w.hs = Slider((10, 10, -10, 22), value=0, + maxValue=200, + minValue=-200, + callback=self.adjust) + + self.w.vs = Slider((10, 30, -10, 22), value=0, + maxValue=200, + minValue=-200, + callback=self.adjust) + + self.w.open() + + def adjust(self, sender): + hValue = self.w.hs.get() + vValue = self.w.vs.get() + + x = self.moveX - hValue + y = self.moveY - vValue + + self.moveX = hValue + self.moveY = vValue + + self.glyph.move((x, y)) + +OpenWindow(MoveGlyphWindow, CurrentGlyph()) \ No newline at end of file