Skip to content

Commit

Permalink
first commit 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark2Mark committed May 2, 2018
0 parents commit 9a42608
Show file tree
Hide file tree
Showing 33 changed files with 1,684 additions and 0 deletions.
44 changes: 44 additions & 0 deletions Anchors/Center Anchors Horizontally.py
@@ -0,0 +1,44 @@
#MenuTitle: Center Anchors Horizontally
# -*- coding: utf-8 -*-
__doc__ = """
• Center Anchors horizontally for selected Glyphs (only current Layer)
"""
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# >> Mark Froemberg << aka `Mark2Mark` @ GitHub
# >> www.markfromberg.com <<
#
# _NOTES:
# -
#
# _TODO:
# -
#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

import math

Font = Glyphs.font
selection = Font.selectedLayers


def angle(angle, xHeight, yPos):
'''
Italic Angle
'''
# rotation point is half of x-height
offset = math.tan(math.radians(angle)) * xHeight / 2
shift = math.tan(math.radians(angle)) * yPos - offset
return shift


for l in selection:
print l.anchors
# print "__glyphMetrics(): ", l.glyphMetrics()
charWidth = l.glyphMetrics()[0]
thisMasterAngle = l.glyphMetrics()[5]
thisMasterXHeight = l.glyphMetrics()[4]
for anchor in l.anchors:
anchor.x = charWidth / 2 + angle(thisMasterAngle, thisMasterXHeight, anchor.y)
26 changes: 26 additions & 0 deletions Anchors/Remove All Anchors.py
@@ -0,0 +1,26 @@
#MenuTitle: Remove All Anchors
# -*- coding: utf-8 -*-
__doc__ = """
• Remove All Anchors in current Glyph Layer.
• Worsk with selection of multiple glyphs as well.
"""
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# >> Mark Froemberg << aka `Mark2Mark` @ GitHub
# >> www.markfromberg.com <<
#
# _NOTES:
# -
#
# _TODO:
# -
#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

thisFont = Glyphs.font
selectedLayers = thisFont.selectedLayers

for layer in selectedLayers:
layer.setAnchors_(None)
63 changes: 63 additions & 0 deletions Anchors/Report Anchors That Are Not on KeyHeights 0.3.py
@@ -0,0 +1,63 @@
#MenuTitle: Report Anchors That Are Not on KeyHeights
# -*- coding: utf-8 -*-
__doc__ = """
• Ignores ogonek and center (Option in this script).
"""
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# >> Mark Froemberg << aka `Mark2Mark` @ GitHub
# >> www.markfromberg.com <<
#
# _NOTES:
# -
#
# _TODO:
# -
#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# Version 0.3

Glyphs.clearLog()
Glyphs.showMacroWindow()


#+++++++++++++++++++++++++++++++
#
exclude = ["ogonek", "center"]
#
#+++++++++++++++++++++++++++++++

Font = Glyphs.font
selection = Font.selectedLayers
thisMaster = Font.selectedFontMaster

allGlyphsToReport = []

for layer in selection:
glyphName = layer.parent.name
anchors = layer.anchors
glyphWithReportedAnchors = []
glyphWithReportedAnchors.append(glyphName)
anchorsList = []
metrics = list(layer.glyphMetrics())
metrics.append(0)
for anchor in anchors:
if anchor.name not in exclude:
if anchor.position.y not in metrics:
try:
anchorsList.append( u'{0:{5}} → {1:20} {3:5} {4:40}'.format("", anchor.name, int(anchor.position.x), int(anchor.position.y), [int(y) for y in metrics][1:-3], 40) )
except Exception, e:
print e

glyphWithReportedAnchors.append( anchorsList )
allGlyphsToReport.append(glyphWithReportedAnchors)

for glyph in allGlyphsToReport:
if glyph[1]:
print "-"*100
print glyph[0]
for anch in glyph[1]:
print anch
37 changes: 37 additions & 0 deletions Anchors/Report Missing Anchors.py
@@ -0,0 +1,37 @@
#MenuTitle: Report Missing Anchors
# -*- coding: utf-8 -*-
__doc__ = """
• Report all glyphs that have no anchors at all.
• Selected Master
"""
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# >> Mark Froemberg << aka `Mark2Mark` @ GitHub
# >> www.markfromberg.com <<
#
# _NOTES:
# -
#
# _TODO:
# -
#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Glyphs.clearLog()
Glyphs.showMacroWindow()

Font = Glyphs.font
selection = Font.selectedLayers
thisMaster = Font.selectedFontMaster

allGlyphsToReport = []

for layer in selection:
glyphName = layer.parent.name
anchors = layer.anchors
if len(anchors) == 0:
allGlyphsToReport.append(glyphName)

print "\n".join(allGlyphsToReport)
26 changes: 26 additions & 0 deletions Anchors/Round Anchors xPosition.py
@@ -0,0 +1,26 @@
#MenuTitle: Round Anchors xPosition
# -*- coding: utf-8 -*-
__doc__ = """
"""
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# >> Mark Froemberg << aka `Mark2Mark` @ GitHub
# >> www.markfromberg.com <<
#
# _NOTES:
# -
#
# _TODO:
# -
#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

selection = Glyphs.font.selectedLayers

for g in selection:
for layer in g.parent.layers:
for anchor in layer.anchors:
anchor.x = round(anchor.x)
38 changes: 38 additions & 0 deletions Anchors/Select All Anchors.py
@@ -0,0 +1,38 @@
#MenuTitle: Select All Anchors
# -*- coding: utf-8 -*-
__doc__ = """
• Select All Anchors in current Glyph.
• Worsk with selection of multiple glyphs as well.
• Adds selection to existing selection.
"""
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# >> Mark Froemberg << aka `Mark2Mark` @ GitHub
# >> www.markfromberg.com <<
#
# _NOTES:
# -
#
# _TODO:
# -
#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

thisFont = Glyphs.font
selectedLayers = thisFont.selectedLayers

for layer in selectedLayers:
### select all anchors
for anchor in layer.anchors:
layer.addSelection_(anchor)

### select all components
# for component in layer.components:
# layer.addSelection_(component)

### select all paths
# for path in layer.paths:
# for node in path.nodes:
# layer.addSelection_(node)
73 changes: 73 additions & 0 deletions Color Labels/Color Label for Selection to All Open Fonts.py
@@ -0,0 +1,73 @@
#MenuTitle: Color Label for Selection to All Open Fonts ...
# -*- coding: utf-8 -*-
__doc__="""
• Same value for all Layers (!)
"""
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# >> Mark Froemberg << aka `Mark2Mark` @ GitHub
# >> www.markfromberg.com <<
#
# _NOTES:
# -
#
# _TODO:
# -
#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

import GlyphsApp
import vanilla
import traceback

colors = [
["Red", 0],
["Orange", 1],
["Brown", 2],
["Yellow", 3],
["Light Green", 4],
["Dark Green", 5],
["Light Blue", 6],
["Dark Blue", 7],
["Purple", 8],
["Magenta", 9],
["Light gray", 10],
["Charcoal", 11],
["White", 9223372036854775807],
]

class Window( object ):
def __init__( self ):
self.w = vanilla.FloatingWindow( (380, 45), "Set Color Label" )

self.w.editText = vanilla.PopUpButton((10, 10, 100, 20), [c[0] for c in colors], sizeStyle='small')
self.w.make_button = vanilla.Button((170, 12, -15, 17), "Set for all Fonts", sizeStyle='small', callback=self.setColor)

self.w.center()
self.w.open()
self.w.setDefaultButton(self.w.make_button)
self.w.makeKey() ### Focus on Window and Button


def setColor(self, sender):
try:
sourceFont = Glyphs.fonts[0]
sourceGlyphs = [g.parent.name for g in sourceFont.selectedLayers]

userInput = self.w.editText.getTitle()
for thisGlyph in sourceGlyphs:
for targetFont in Glyphs.fonts:
for g in targetFont.glyphs:
if g.name == thisGlyph:
### access colors list, and take only the first item (hack to avoid it being a list)
g.color = int( [c[1] for c in colors if c[0] == str(userInput)][0] )


except:
print traceback.format_exc()

self.w.close()

Window()
41 changes: 41 additions & 0 deletions Debug & Dev/Print Glyphs User Defaults.py
@@ -0,0 +1,41 @@
#MenuTitle: Print Glyphs User Defaults
# -*- coding: utf-8 -*-
__doc__ = """
• Print Glyphs User Defaults & Examples for related objects
"""
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# >> Mark Froemberg << aka `Mark2Mark` @ GitHub
# >> www.markfromberg.com <<
#
# _NOTES:
# -
#
# _TODO:
# -
#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Glyphs.clearLog() # clear macro window log
Glyphs.showMacroWindow()


'''
see:
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSUserDefaults_Class/#//apple_ref/occ/instm/NSUserDefaults/dictionaryRepresentation
'''
print NSUserDefaults.standardUserDefaults().dictionaryRepresentation()



## Example: Bool for preview is black or white:
print
print NSUserDefaults.standardUserDefaults().boolForKey_("GSPreview_Black")

'''
OFFICIAL SOLUTION:
Example
'''
print Glyphs.defaults["TransformRotate"]

0 comments on commit 9a42608

Please sign in to comment.