-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 62d10eb
Showing
5 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.DS_Store* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |