-
Notifications
You must be signed in to change notification settings - Fork 1
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 4b5616f
Showing
8 changed files
with
417 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,90 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>English</string> | ||
<key>CFBundleDisplayName</key> | ||
<string>ShowPathArea</string> | ||
<key>CFBundleExecutable</key> | ||
<string>ShowPathArea</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>org.simon-cozens.ShowPathArea</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleName</key> | ||
<string>ShowPathArea</string> | ||
<key>CFBundlePackageType</key> | ||
<string>BNDL</string> | ||
<key>CFBundleSignature</key> | ||
<string>????</string> | ||
<key>CFBundleVersion</key> | ||
<string>4</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>1.1.1</string> | ||
<key>UpdateFeedURL</key> | ||
<string></string> | ||
<key>productPageURL</key> | ||
<string></string> | ||
<key>LSHasLocalizedDisplayName</key> | ||
<false/> | ||
<key>NSAppleScriptEnabled</key> | ||
<false/> | ||
<key>NSHumanReadableCopyright</key> | ||
<string>Copyright, by Simon Cozens, 2015</string> | ||
<key>NSMainNibFile</key> | ||
<string>MainMenu</string> | ||
<key>NSPrincipalClass</key> | ||
<string>ShowPathArea</string> | ||
<key>PyMainFileNames</key> | ||
<array> | ||
<string>__boot__</string> | ||
</array> | ||
<key>PyOptions</key> | ||
<dict> | ||
<key>alias</key> | ||
<true/> | ||
<key>argv_emulation</key> | ||
<false/> | ||
<key>no_chdir</key> | ||
<false/> | ||
<key>optimize</key> | ||
<integer>0</integer> | ||
<key>prefer_ppc</key> | ||
<false/> | ||
<key>site_packages</key> | ||
<false/> | ||
<key>use_pythonpath</key> | ||
<false/> | ||
</dict> | ||
<key>PyResourcePackages</key> | ||
<array> | ||
<string>lib/python2.6</string> | ||
<string>lib/python2.6/lib-dynload</string> | ||
<string>lib/python2.6/site-packages.zip</string> | ||
<string>lib/python26.zip</string> | ||
</array> | ||
<key>PyRuntimeLocations</key> | ||
<array> | ||
<string>@executable_path/../Frameworks/Python.framework/Versions/2.6/Python</string> | ||
<string>/System/Library/Frameworks/Python.framework/Versions/2.6/Python</string> | ||
</array> | ||
<key>PythonInfoDict</key> | ||
<dict> | ||
<key>PythonExecutable</key> | ||
<string>/usr/bin/python2.6</string> | ||
<key>PythonLongVersion</key> | ||
<string>2.6.7 (r267:88850, Oct 11 2012, 20:15:00) | ||
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)]</string> | ||
<key>PythonShortVersion</key> | ||
<string>2.6</string> | ||
<key>py2app</key> | ||
<dict> | ||
<key>template</key> | ||
<string>bundle</string> | ||
<key>version</key> | ||
<string>0.6.3</string> | ||
</dict> | ||
</dict> | ||
</dict> | ||
</plist> |
Binary file not shown.
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 @@ | ||
/System/Library/Frameworks/Python.framework/Versions/2.6/bin/python |
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 @@ | ||
BNDL???? |
136 changes: 136 additions & 0 deletions
136
ShowPathArea.glyphsReporter/Contents/Resources/ShowPathArea.py
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,136 @@ | ||
#!/usr/bin/env python | ||
# encoding: utf-8 | ||
import objc | ||
from Foundation import * | ||
from AppKit import * | ||
import sys, os, re | ||
import math | ||
|
||
MainBundle = NSBundle.mainBundle() | ||
path = MainBundle.bundlePath() + "/Contents/Scripts" | ||
if not path in sys.path: | ||
sys.path.append( path ) | ||
|
||
import GlyphsApp | ||
|
||
GlyphsReporterProtocol = objc.protocolNamed( "GlyphsReporter" ) | ||
|
||
class ShowPathArea ( NSObject, GlyphsReporterProtocol ): | ||
|
||
def init( self ): | ||
return self | ||
|
||
def interfaceVersion( self ): | ||
return 1 | ||
|
||
def title( self ): | ||
return "Path Area" | ||
|
||
def keyEquivalent( self ): | ||
return None | ||
|
||
def modifierMask( self ): | ||
return 0 | ||
|
||
def drawForegroundForLayer_( self, Layer ): | ||
pass | ||
|
||
def drawPathArea( self, Layer ): | ||
Glyph = Layer.parent | ||
Font = Glyph.parent | ||
selectedLayers = Font.selectedLayers | ||
|
||
for thisLayer in selectedLayers: | ||
for thisPath in thisLayer.paths: | ||
if thisPath.closed: | ||
area = 0 | ||
for s in thisPath.segments: | ||
area += self.segmentArea(s) | ||
self.drawTextAtPoint( u"%d" % abs(area), (thisPath.nodes[0].position.x - 5, thisPath.nodes[0].position.y + 5) ) | ||
|
||
def segmentArea(self, s): | ||
if len(s) == 4: | ||
xa, ya = s[0].x, s[0].y/20 | ||
xb, yb = s[1].x, s[1].y/20 | ||
xc, yc = s[2].x, s[2].y/20 | ||
xd, yd = s[3].x, s[3].y/20 | ||
else: | ||
xa, ya = s[0].x, s[0].y/20 | ||
xb, yb = xa, ya | ||
xc, yc = s[1].x, s[1].y/20 | ||
xd, yd = xc, yc | ||
return (xb-xa)*(10*ya + 6*yb + 3*yc + yd) + (xc-xb)*( 4*ya + 6*yb + 6*yc + 4*yd) +(xd-xc)*( ya + 3*yb + 6*yc + 10*yd) | ||
|
||
def drawBackgroundForLayer_( self, Layer ): | ||
try: | ||
self.drawPathArea( Layer ) | ||
except Exception as e: | ||
self.logToConsole( "drawBackgroundForLayer_: %s" % str(e) ) | ||
|
||
def drawBackgroundForInactiveLayer_( self, Layer ): | ||
pass | ||
|
||
def drawTextAtPoint( self, text, textPosition, fontSize=10.0, fontColor=NSColor.colorWithCalibratedRed_green_blue_alpha_( 1, 0, .5, 1 ) ): | ||
""" | ||
Use self.drawTextAtPoint( "blabla", myNSPoint ) to display left-aligned text at myNSPoint. | ||
""" | ||
try: | ||
glyphEditView = self.controller.graphicView() | ||
currentZoom = self.getScale() | ||
fontAttributes = { | ||
NSFontAttributeName: NSFont.labelFontOfSize_( fontSize/currentZoom ), | ||
NSForegroundColorAttributeName: fontColor } | ||
displayText = NSAttributedString.alloc().initWithString_attributes_( text, fontAttributes ) | ||
textAlignment = 2 # top left: 6, top center: 7, top right: 8, center left: 3, center center: 4, center right: 5, bottom left: 0, bottom center: 1, bottom right: 2 | ||
glyphEditView.drawText_atPoint_alignment_( displayText, textPosition, textAlignment ) | ||
except Exception as e: | ||
self.logToConsole( "drawTextAtPoint: %s" % str(e) ) | ||
|
||
def needsExtraMainOutlineDrawingForInactiveLayer_( self, Layer ): | ||
return True | ||
|
||
def getHandleSize( self ): | ||
""" | ||
Returns the current handle size as set in user preferences. | ||
Use: self.getHandleSize() / self.getScale() | ||
to determine the right size for drawing on the canvas. | ||
""" | ||
try: | ||
Selected = NSUserDefaults.standardUserDefaults().integerForKey_( "GSHandleSize" ) | ||
if Selected == 0: | ||
return 5.0 | ||
elif Selected == 2: | ||
return 10.0 | ||
else: | ||
return 7.0 # Regular | ||
except Exception as e: | ||
self.logToConsole( "getHandleSize: HandleSize defaulting to 7.0. %s" % str(e) ) | ||
return 7.0 | ||
|
||
def getScale( self ): | ||
""" | ||
self.getScale() returns the current scale factor of the Edit View UI. | ||
Divide any scalable size by this value in order to keep the same apparent pixel size. | ||
""" | ||
try: | ||
return self.controller.graphicView().scale() | ||
except: | ||
self.logToConsole( "Scale defaulting to 1.0" ) | ||
return 1.0 | ||
|
||
def setController_( self, Controller ): | ||
""" | ||
Use self.controller as object for the current view controller. | ||
""" | ||
try: | ||
self.controller = Controller | ||
except Exception as e: | ||
self.logToConsole( "Could not set controller" ) | ||
|
||
def logToConsole( self, message ): | ||
""" | ||
The variable 'message' will be passed to Console.app. | ||
Use self.logToConsole( "bla bla" ) for debugging. | ||
""" | ||
myLog = "Show %s plugin:\n%s" % ( self.title(), message ) | ||
NSLog( myLog ) |
47 changes: 47 additions & 0 deletions
47
ShowPathArea.glyphsReporter/Contents/Resources/__boot__.py
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,47 @@ | ||
# def _site_packages(): | ||
# import site, sys, os | ||
# paths = [] | ||
# prefixes = [sys.prefix] | ||
# if sys.exec_prefix != sys.prefix: | ||
# prefixes.append(sys.exec_prefix) | ||
# for prefix in prefixes: | ||
# if prefix == sys.prefix: | ||
# paths.append(os.path.join("/Library/Python", sys.version[:3], "site-packages")) | ||
# paths.append(os.path.join(sys.prefix, "Extras", "lib", "python")) | ||
# else: | ||
# paths.append(os.path.join(prefix, 'lib', 'python' + sys.version[:3], 'site-packages')) | ||
# if os.path.join('.framework', '') in os.path.join(sys.prefix, ''): | ||
# home = os.environ.get('HOME') | ||
# if home: | ||
# paths.append(os.path.join(home, 'Library', 'Python', sys.version[:3], 'site-packages')) | ||
# | ||
# # Workaround for a misfeature in setuptools: easy_install.pth places | ||
# # site-packages way too early on sys.path and that breaks py2app bundles. | ||
# # NOTE: this hacks into an undocumented feature of setuptools and | ||
# # might stop to work without warning. | ||
# sys.__egginsert = len(sys.path) | ||
# | ||
# for path in paths: | ||
# site.addsitedir(path) | ||
# | ||
# _site_packages() | ||
# | ||
# def _path_inject(): | ||
# import sys | ||
# sys.path[:0] = sys.path[0] | ||
# | ||
# _path_inject() | ||
|
||
def _run(*scripts): | ||
global __file__ | ||
import os, sys# , site | ||
sys.frozen = 'macosx_plugin' | ||
base = os.environ['RESOURCEPATH'] | ||
# site.addsitedir(base) | ||
# site.addsitedir(os.path.join(base, 'Python', 'site-packages')) | ||
for script in scripts: | ||
path = os.path.join(base, script) | ||
__file__ = path | ||
execfile(path, globals(), globals()) | ||
|
||
_run('ShowPathArea.py') |
12 changes: 12 additions & 0 deletions
12
ShowPathArea.glyphsReporter/Contents/Resources/__error__.sh
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,12 @@ | ||
#!/bin/sh | ||
# | ||
# This is the default bundletemplate error script | ||
# Note that this DOES NOT present a GUI dialog, because | ||
# it has no output on stdout, and has a return value of 0. | ||
# | ||
if ( test -n "$2" ) ; then | ||
echo "[$1] Unexpected Exception:" 1>&2 | ||
echo "$2: $3" 1>&2 | ||
else | ||
echo "[$1] Could not find a suitable Python runtime" 1>&2 | ||
fi |
Oops, something went wrong.