[svgPathPen] Add --glyphs
This commit is contained in:
parent
16991a8cd2
commit
0572f78718
@ -220,12 +220,18 @@ def main(args=None):
|
|||||||
"fonttools pens.svgPathPen", description="Generate SVG from text"
|
"fonttools pens.svgPathPen", description="Generate SVG from text"
|
||||||
)
|
)
|
||||||
parser.add_argument("font", metavar="font.ttf", help="Font file.")
|
parser.add_argument("font", metavar="font.ttf", help="Font file.")
|
||||||
parser.add_argument("text", metavar="text", help="Text string.")
|
parser.add_argument("text", metavar="text", nargs="?", help="Text string.")
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-y",
|
"-y",
|
||||||
metavar="<number>",
|
metavar="<number>",
|
||||||
help="Face index into a collection to open. Zero based.",
|
help="Face index into a collection to open. Zero based.",
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--glyphs",
|
||||||
|
metavar="whitespace-separated list of glyph names",
|
||||||
|
type=str,
|
||||||
|
help="Glyphs to show. Exclusive with text option",
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--variations",
|
"--variations",
|
||||||
metavar="AXIS=LOC",
|
metavar="AXIS=LOC",
|
||||||
@ -241,6 +247,7 @@ def main(args=None):
|
|||||||
|
|
||||||
font = TTFont(options.font, fontNumber=fontNumber)
|
font = TTFont(options.font, fontNumber=fontNumber)
|
||||||
text = options.text
|
text = options.text
|
||||||
|
glyphs = options.glyphs
|
||||||
|
|
||||||
location = {}
|
location = {}
|
||||||
for tag_v in options.variations.split():
|
for tag_v in options.variations.split():
|
||||||
@ -255,10 +262,17 @@ def main(args=None):
|
|||||||
glyphset = font.getGlyphSet(location=location)
|
glyphset = font.getGlyphSet(location=location)
|
||||||
cmap = font["cmap"].getBestCmap()
|
cmap = font["cmap"].getBestCmap()
|
||||||
|
|
||||||
|
if glyphs is not None and text is not None:
|
||||||
|
raise ValueError("Options --glyphs and --text are exclusive")
|
||||||
|
|
||||||
|
if glyphs is None:
|
||||||
|
glyphs = " ".join(cmap[ord(u)] for u in text)
|
||||||
|
|
||||||
|
glyphs = glyphs.split()
|
||||||
|
|
||||||
s = ""
|
s = ""
|
||||||
width = 0
|
width = 0
|
||||||
for u in text:
|
for g in glyphs:
|
||||||
g = cmap[ord(u)]
|
|
||||||
glyph = glyphset[g]
|
glyph = glyphset[g]
|
||||||
|
|
||||||
pen = SVGPathPen(glyphset)
|
pen = SVGPathPen(glyphset)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user