Skip to content

Commit

Permalink
initial upload
Browse files Browse the repository at this point in the history
  • Loading branch information
typemytype committed Feb 8, 2012
0 parents commit 62d10eb
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store*
64 changes: 64 additions & 0 deletions UI/drawAntialiasedStroke.py
Original file line number Diff line number Diff line change
@@ -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()
23 changes: 23 additions & 0 deletions objectBrowser/objectBrowser.py
Original file line number Diff line number Diff line change
@@ -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)
19 changes: 19 additions & 0 deletions openFonts/openFontInLayer.py
Original file line number Diff line number Diff line change
@@ -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"



39 changes: 39 additions & 0 deletions simpleMoveExample/moveGlyphWinow.py
Original file line number Diff line number Diff line change
@@ -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())

0 comments on commit 62d10eb

Please sign in to comment.