├── LICENSE ├── README.md └── createGlyphsPDF.py /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Alphabet 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DrawBot-Scripts 2 | Some DrawBot/RoboFont scripts 3 | 4 | See also: 5 | * RoboFont: http://robofont.com 6 | * RF DrawBot Extension: https://github.com/typemytype/drawBotRoboFontExtension 7 | * DrawBot Documentation: http://drawbot.readthedocs.org 8 | 9 | 10 | ## createGlyphsPDF.py 11 | (for RF DrawBot Extension) 12 | 13 | Save a PDF file containing one page per glyph of current font. 14 | 15 | -------------------------------------------------------------------------------- /createGlyphsPDF.py: -------------------------------------------------------------------------------- 1 | from fontTools.pens.cocoaPen import CocoaPen 2 | 3 | # Some configuration 4 | page_format = 'A4' # See http://drawbot.readthedocs.org/content/canvas/pages.html#size for other size-values 5 | my_selection = CurrentFont() # May also be CurrentFont.selection or else 6 | pdf_filepath = '~/Desktop/AllMyGlyphs.pdf' 7 | 8 | # Init 9 | font = CurrentFont() 10 | size(page_format) 11 | page_width = width() 12 | page_height = height() 13 | 14 | # Drawbox Settings 15 | drawbox = {} 16 | drawbox['left_margin'] = 50 17 | drawbox['top_margin'] = 50 18 | drawbox['right_margin'] = 50 19 | drawbox['bottom_margin'] = 50 20 | drawbox['xMin'] = drawbox['left_margin'] 21 | drawbox['yMin'] = drawbox['bottom_margin'] 22 | drawbox['xMax'] = page_width - drawbox['right_margin'] 23 | drawbox['yMax'] = page_width - drawbox['top_margin'] 24 | drawbox['width'] = page_width - drawbox['left_margin'] - drawbox['right_margin'] 25 | drawbox['height'] = page_height - drawbox['bottom_margin'] - drawbox['top_margin'] 26 | 27 | 28 | def showPageMargins(): 29 | fill(None) 30 | stroke(0, 0, 1, .1) 31 | rect(drawbox['xMin'], drawbox['yMin'], drawbox['width'], drawbox['height']) 32 | 33 | 34 | 35 | class RegisterGlyph(object): 36 | 37 | def __init__(self, glyph): 38 | self.glyph = glyph 39 | #print 'Registered glyph:', self.glyph.name 40 | 41 | self.getGlyphSizeData() 42 | 43 | def getGlyphSizeData(self): 44 | self.xMin, self.yMin, self.xMax, self.yMax = self.glyph.box 45 | self.w = self.xMax - self.xMin 46 | self.h = self.yMax - self.yMin 47 | self.xHeight_pos = xHeight + abs(descender) 48 | self.capHeight_pos = capHeight + abs(descender) 49 | self.x_pos = self.glyph.leftMargin + drawbox['xMin'] 50 | 51 | #print self.xMin, self.yMin, self.xMax, self.yMax 52 | 53 | def getScale(self): 54 | if self.w > self.h: 55 | return drawbox['width']/self.w 56 | else: 57 | return 1 58 | #return drawbox['height']/self.h 59 | 60 | def drawBoundingBox(self): 61 | stroke(255,0,0) 62 | fill(None) 63 | rect(drawbox['xMin'], drawbox['yMin'], self.glyph.width*sc, UPM*sc) 64 | 65 | def drawXHeight(self): 66 | stroke(255, 0,0) 67 | line((drawbox['xMin'], drawbox['yMin'] + self.xHeight_pos*sc), (drawbox['xMin'] + self.glyph.width*sc, drawbox['yMin'] + self.xHeight_pos*sc)) 68 | 69 | def drawCapHeight(self): 70 | stroke(255,0,0) 71 | line((drawbox['xMin'], drawbox['yMin'] + self.capHeight_pos*sc), (drawbox['xMin'] + self.glyph.width*sc, drawbox['yMin'] + self.capHeight_pos*sc)) 72 | 73 | def drawBaseline(self): 74 | stroke(255, 0, 0) 75 | line((drawbox['xMin'], drawbox['yMin'] + abs(descender)*sc), (drawbox['xMin'] + self.glyph.width*sc, drawbox['yMin'] + abs(descender)*sc)) 76 | 77 | def drawLeftMargin(self): 78 | stroke(None) 79 | fill(255,0,0,0.5) 80 | rect(drawbox['xMin'], drawbox['yMin'], self.glyph.leftMargin*sc, UPM*sc) 81 | 82 | def drawRightMargin(self): 83 | stroke(None) 84 | fill(255,0,0,0.5) 85 | rect(drawbox['xMin'] + (self.glyph.width - self.glyph.rightMargin)*sc, drawbox['yMin'], self.glyph.rightMargin*sc, UPM*sc) 86 | #rect((drawbox['xMax'] - self.glyph.rightMargin)*sc, drawbox['yMin'], self.glyph.width*sc, UPM*sc) 87 | 88 | 89 | 90 | def addNewPage(self): 91 | newPage() 92 | showPageMargins() 93 | 94 | def drawGlyph(self): 95 | save() 96 | stroke(None) 97 | fill(0) 98 | translate(drawbox['xMin'], 0) 99 | translate(0, drawbox['yMin'] + abs(descender)*sc) 100 | scale(sc) 101 | 102 | self._drawGlyph() 103 | restore() 104 | 105 | def center(self, horizontal=True, vertical=True): 106 | offset_x = 0 107 | offset_y = 0 108 | if horizontal: 109 | offset_x = (drawbox['width'] - self.glyph.width*sc)/2 110 | 111 | if vertical: 112 | offset_y = (drawbox['height'] - UPM*sc)/2 113 | 114 | translate(offset_x, offset_y) 115 | 116 | 117 | 118 | def _drawGlyph(self): 119 | pen = CocoaPen(self.glyph.getParent()) 120 | self.glyph.draw(pen) 121 | drawPath(pen.path) 122 | 123 | 124 | 125 | def getMaxWidth(): 126 | max_width = 0 127 | for g in my_selection: 128 | if g.width > max_width: 129 | max_width = g.width 130 | 131 | return max_width 132 | 133 | def getScale(): 134 | # The glyphs should be displayed as big as possible. 135 | # So the most wide glyph will be the base for the scaling. 136 | 137 | sc = drawbox['width']/max_width 138 | return sc 139 | 140 | 141 | 142 | max_width = getMaxWidth() 143 | sc = getScale() 144 | UPM = font.info.unitsPerEm 145 | xHeight = font.info.xHeight 146 | capHeight = font.info.capHeight 147 | ascender = font.info.ascender 148 | descender = font.info.descender 149 | 150 | for g in my_selection: 151 | if len(g) > 0: # Ignore whitespace glyphs 152 | glyph = RegisterGlyph(g) 153 | glyph.addNewPage() 154 | # Just uncomment any of the following methods if you don't want them to be drawn 155 | glyph.center(True, True) 156 | glyph.drawLeftMargin() 157 | glyph.drawRightMargin() 158 | glyph.drawGlyph() 159 | glyph.drawBoundingBox() 160 | glyph.drawBaseline() 161 | glyph.drawXHeight() 162 | glyph.drawCapHeight() 163 | 164 | 165 | 166 | --------------------------------------------------------------------------------