forked from Shriinivas/inkscapestrokefont
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stroke_font_templ.py
137 lines (102 loc) · 5.43 KB
/
stroke_font_templ.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Inkscape extension to generate template for designing / tracing custom stroke fonts
Copyright (C) 2019 Shrinivas Kulkarni
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
'''
from inkex import Effect
import sys, os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from stroke_font_common import CommonDefs, getDecodedChars, createTempl, addText
from stroke_font_common import getAddFnTypes, runEffect
from stroke_font_manager import xSpaceROff, getDefaultExtraInfo
class CustStrokeFontTempl(Effect):
def __init__(self):
Effect.__init__(self)
addFn, typeFloat, typeInt, typeString, typeBool = getAddFnTypes(self)
addFn('--rowCnt', action = 'store', type = typeInt, dest = 'rowCnt', default = '5', \
help = 'Number of rows (horizontal guides) in the template')
addFn("--createGlyphs", action="store", type=typeBool, dest="createGlyphs", \
default=True, help = 'Render glyphs of the source font family for tracing ')
addFn('--srcFontFamily', action = 'store', type = typeString, dest = 'srcFontFamily', \
help = 'Exact name of the source font family')
addFn('--fontSize', action = 'store', type = typeInt, dest = 'fontSize', default = '100', \
help = 'Size of the source glyphs to be rendered')
addFn('--spaceWidth', action = 'store', \
type = typeInt, dest = 'spaceWidth', default = '50', \
help = 'Width of the space character (generally 1/3 to 1/2 times the font size')
addFn('--fontType', action = 'store', type = typeString, dest = 'fontType', \
default = 'normal', help = 'Font Style')
addFn('--startGlyph', action = 'store', type = typeString, dest = 'startGlyph', \
default = '0', help = 'Starting glyph to be rendered')
addFn('--glyphCnt', action = 'store', type = typeInt, dest = 'glyphCnt', \
default = '75', help = 'Number of template glyphs')
addFn("--rvGuides", action = "store", type = typeBool, dest = "rvGuides", \
default = False, help = 'Render vertical guide at the right of each glyph')
addFn("--fillOpacity", action = "store", type = typeFloat, dest = "fillOpacity", \
default = False, help = 'Fill opacity of source glyph')
addFn("--strokeOpacity", action = "store", type = typeFloat, dest = "strokeOpacity", \
default = False, help = 'Stroke opacity of source glyph')
addFn("--tab", action = "store", type = typeString, dest = "tab", \
default = "sampling", help="Tab")
def addElem(self, sourceGlyphLayer, editLayer, glyphIdx, posX, posY):
if(self.createTTGlyphs):
if(CommonDefs.pyVer == 2):
glyph = unichr(ord(self.startGlyph) + glyphIdx)
else:
glyph = chr(ord(self.startGlyph) + glyphIdx)
addText(sourceGlyphLayer, glyph, posX, posY, self.textStyle)
return None
def effect(self):
#TODO: Maybe validate if a template was already created
rowCnt = self.options.rowCnt
srcFontFamily = self.options.srcFontFamily
fontType = self.options.fontType
glyphCnt = self.options.glyphCnt
rvGuides = self.options.rvGuides
fontSize = self.options.fontSize
strokeOpacity = self.options.strokeOpacity
fillOpacity = self.options.fillOpacity
spaceWidth = self.options.spaceWidth
self.createTTGlyphs = self.options.createGlyphs
sg = self.options.startGlyph
self.startGlyph = None
if(len(sg) > 0):
if(len(sg) == 4):
try: self.startGlyph = eval("u'\\u" + sg + "'")
except: pass
if(self.startGlyph == None):
self.startGlyph = getDecodedChars(sg)[0]
else:
self.startGlyph = 'A'
lineT = CommonDefs.lineT * fontSize
if('bold' in fontType):
fontWeight = 'bold'
else:
fontWeight = 'normal'
if('italic' in fontType):
fontStyle = 'italic'
else:
fontStyle = 'normal'
self.textStyle = {'font-family':srcFontFamily, 'font-size':str(fontSize),\
'fill':'#000000', 'fill-opacity':str(fillOpacity), 'stroke':'#000000', 'stroke-width':str(lineT),\
'stroke-opacity':str(strokeOpacity), 'font-style':fontStyle,'font-weight':fontWeight,\
'text-align':'start'}
vgScaleFact = CommonDefs.vgScaleFact
fontName = 'NA'
extraInfo = getDefaultExtraInfo(fontName, fontSize)
extraInfo[xSpaceROff] = spaceWidth
createTempl(self.addElem, self, extraInfo, rowCnt, glyphCnt, vgScaleFact, \
rvGuides, lineT, newCallBackLayerName = 'Source Glyphs')
runEffect(CustStrokeFontTempl())