kopia lustrzana https://github.com/evil-mad/EggBot
Remove Hershey Text
Hershey Text now has its own repository: https://gitlab.com/oskay/hershey-textpull/125/head
rodzic
658e9422a6
commit
62c057edb3
|
@ -1,127 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
|
||||
<_name>Hershey Text</_name>
|
||||
<id>org.evilmad.render.hershe</id>
|
||||
<!-- Version 2.2 November 28, 2017 -->
|
||||
<dependency type="executable" location="extensions">hershey.py</dependency>
|
||||
<dependency type="executable" location="extensions">hersheydata.py</dependency>
|
||||
<dependency type="executable" location="extensions">inkex.py</dependency>
|
||||
<param name="tab" type="notebook">
|
||||
<page name="splash" _gui-text="Render Text">
|
||||
<_param indent="1" name="splashpage" type="description" appearance="header">
|
||||
Hershey Text: Engraving Fonts for Inkscape
|
||||
|
||||
</_param>
|
||||
<param indent="2" name="text" type="string" _gui-text="Text:">The Quick Brown Fox Jumps Over a Lazy Dog</param>
|
||||
<param indent="2" name="action" type="enum" _gui-text="Action: ">
|
||||
<_item value="render">Typeset that text</_item>
|
||||
<_item value="sample">Generate font table: All fonts</_item>
|
||||
<_item value="sampleHW">Generate font table: Handwriting-like</_item>
|
||||
<_item value="table">Generate glyph table in selected font</_item>
|
||||
</param>
|
||||
<param indent="2" name="fontface" type="enum" _gui-text="Font face: ">
|
||||
<_item value="futural">Sans 1-stroke</_item>
|
||||
<_item value="futuram">Sans bold</_item>
|
||||
<_item value="timesr">Serif medium</_item>
|
||||
<_item value="timesi">Serif medium italic</_item>
|
||||
<_item value="timesib">Serif bold italic</_item>
|
||||
<_item value="timesrb">Serif bold</_item>
|
||||
<_item value="scripts">Script 1-stroke</_item>
|
||||
<_item value="cursive">Script 1-stroke (alt)</_item>
|
||||
<_item value="scriptc">Script medium</_item>
|
||||
<_item value="gothiceng">Gothic English</_item>
|
||||
<_item value="gothicger">Gothic German</_item>
|
||||
<_item value="gothicita">Gothic Italian</_item>
|
||||
<!-- Block below this are loosely adapted from fonts licensed under SIL Open Font License -->
|
||||
<_item value="EMSAllure">EMS Allure</_item>
|
||||
<_item value="EMSBird">EMS Bird</_item>
|
||||
<_item value="EMSBirdSwashCaps">EMS Bird Swash Caps</_item>
|
||||
<_item value="EMSBrush">EMS Brush</_item>
|
||||
<_item value="EMSCapitol">EMS Capitol</_item>
|
||||
<_item value="EMSCasualHand">EMS Casual Hand</_item>
|
||||
<_item value="EMSDecorousScript">EMS Decorous Script</_item>
|
||||
<_item value="EMSDelight">EMS Delight</_item>
|
||||
<_item value="EMSDelightSwashCaps">EMS Delight Swash Caps</_item>
|
||||
<_item value="EMSElfin">EMS Elfin</_item>
|
||||
<_item value="EMSFelix">EMS Felix</_item>
|
||||
<_item value="EMSHerculean">EMS Herculean</_item>
|
||||
<_item value="EMSInvite">EMS Invite</_item>
|
||||
<_item value="EMSLeague">EMS League</_item>
|
||||
<_item value="EMSLittlePrincess">EMS Little Princess</_item>
|
||||
<_item value="EMSMistyNight">EMS Misty Night</_item>
|
||||
<_item value="EMSNeato">EMS Neato</_item>
|
||||
<_item value="EMSNixish">EMS Nixish</_item>
|
||||
<_item value="EMSNixishItalic">EMS Nixish Italic</_item>
|
||||
<_item value="EMSOsmotron">EMS Osmotron</_item>
|
||||
<_item value="EMSPancakes">EMS Pancakes</_item>
|
||||
<_item value="EMSPepita">EMS Pepita</_item>
|
||||
<_item value="EMSQwandry">EMS Qwandry</_item>
|
||||
<_item value="EMSReadability">EMS Readability</_item>
|
||||
<_item value="EMSReadabilityItalic">EMS Readability Italic</_item>
|
||||
<_item value="EMSSociety">EMS Society</_item>
|
||||
<_item value="EMSSwiss">EMS Swiss</_item>
|
||||
<_item value="EMSTech">EMS Tech</_item>
|
||||
<!-- Block above this are loosely adapted from fonts licensed under SIL Open Font License -->
|
||||
<_item value="greek">Greek 1-stroke</_item>
|
||||
<_item value="timesg">Greek medium</_item>
|
||||
<_item value="cyrillic">Cyrillic</_item>
|
||||
<_item value="japanese">Japanese</_item>
|
||||
<_item value="astrology">Astrology</_item>
|
||||
<_item value="mathlow">Math (lower)</_item>
|
||||
<_item value="mathupp">Math (upper)</_item>
|
||||
<_item value="markers">Markers</_item>
|
||||
<_item value="meteorology">Meteorology</_item>
|
||||
<_item value="music">Music</_item>
|
||||
<_item value="symbolic">Symbolic</_item>
|
||||
</param>
|
||||
<_param name="emptyspace" type="description" xml:space="preserve">
|
||||
</_param>
|
||||
</page>
|
||||
<page name="info" _gui-text="About Hershey Text">
|
||||
<_param indent="1" name="aboutTitle" type="description" appearance="header">Hershey Text 2.2</_param>
|
||||
<_param name="aboutpage" type="description" xml:space="preserve">This tool renders a line of text using specialized
|
||||
"stroke" or "engraving" fonts designed for plotters.
|
||||
|
||||
Whereas regular "outline" fonts (e.g., TrueType) work
|
||||
by filling in the region inside an invisible outline,
|
||||
engraving fonts are composed only of individual lines
|
||||
or strokes; much like human handwriting.
|
||||
|
||||
Engraving fonts are used for creating text paths that
|
||||
computer controlled drawing and cutting machines (from
|
||||
pen plotters to CNC routers) can efficiently follow.
|
||||
|
||||
For a full introduction, please visit:
|
||||
www.evilmadscientist.com/go/hershey</_param>
|
||||
</page>
|
||||
<page name="info" _gui-text="Credits">
|
||||
<_param name="aboutpage" type="description" xml:space="preserve">
|
||||
The classic fonts included -- those without the "EMS"
|
||||
prefix -- are derived from work by Dr. A. V. Hershey,
|
||||
distributed by the US National Bureau of Standards
|
||||
(now NIST) in NBS SP-424 1976-04, "A contribution to
|
||||
computer typesetting techniques: Tables of Coordinates
|
||||
for Hershey's Repertory of Occidental Type Fonts and
|
||||
Graphic Symbols."
|
||||
|
||||
Additional modern "EMS" fonts in this distribution are
|
||||
derivatives created from fonts licensed under the SIL
|
||||
Open Font License.
|
||||
|
||||
For full credits and license information, please see
|
||||
the "hersheydata.py" file included with this
|
||||
distribution or visit:
|
||||
wiki.evilmadscientist.com/hershey
|
||||
</_param>
|
||||
</page>
|
||||
</param>
|
||||
<effect needs-live-preview="true" needs-document="true">
|
||||
<object-type>all</object-type>
|
||||
<effects-menu>
|
||||
<submenu _name="Render"/>
|
||||
</effects-menu>
|
||||
</effect>
|
||||
<script>
|
||||
<command reldir="extensions" interpreter="python">hershey.py</command>
|
||||
</script>
|
||||
</inkscape-extension>
|
|
@ -1,184 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Hershey Text - renders a line of text using "Hershey" fonts for plotters
|
||||
|
||||
Copyright 2011-2017, Windell H. Oskay, www.evilmadscientist.com
|
||||
|
||||
Additional contributions by Sheldon B. Michaels
|
||||
and by the contributors of the Inkscape project, http://inkscape.org
|
||||
|
||||
|
||||
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.
|
||||
"""
|
||||
import hersheydata # data file w/ Hershey font data
|
||||
import inkex
|
||||
import simplestyle
|
||||
|
||||
Debug = False
|
||||
FONT_GROUP_V_SPACING = 45
|
||||
|
||||
|
||||
def draw_svg_text(char, face, offset, vertoffset, parent):
|
||||
style = {'stroke': '#000000', 'fill': 'none'}
|
||||
path_string = face[char]
|
||||
split_string = path_string.split()
|
||||
midpoint = offset - float(split_string[0])
|
||||
splitpoint = path_string.find("M")
|
||||
# Space glyphs have just widths with no moves, so their splitpoint is 0
|
||||
# We only want to generate paths for visible glyphs where splitpoint > 0
|
||||
if splitpoint > 0:
|
||||
path_string = path_string[splitpoint:] # portion after first move
|
||||
trans = 'translate({0},{1})'.format(midpoint, vertoffset)
|
||||
text_attribs = {'style': simplestyle.formatStyle(style), 'd': path_string, 'transform': trans}
|
||||
inkex.etree.SubElement(parent, inkex.addNS('path', 'svg'), text_attribs)
|
||||
return midpoint + float(split_string[1]) # new offset value
|
||||
|
||||
|
||||
def svg_text_width(char, face, offset):
|
||||
path_string = face[char]
|
||||
split_string = path_string.split()
|
||||
midpoint = offset - float(split_string[0])
|
||||
return midpoint + float(split_string[1]) # new offset value
|
||||
|
||||
|
||||
class Hershey(inkex.Effect):
|
||||
def __init__(self):
|
||||
inkex.Effect.__init__(self)
|
||||
self.OptionParser.add_option("--tab", # NOTE: value is not used.
|
||||
action="store", type="string",
|
||||
dest="tab", default="splash",
|
||||
help="The active tab when Apply was pressed")
|
||||
self.OptionParser.add_option("--text",
|
||||
action="store", type="string",
|
||||
dest="text", default="Hershey Text for Inkscape",
|
||||
help="The input text to render")
|
||||
self.OptionParser.add_option("--action",
|
||||
action="store", type="string",
|
||||
dest="action", default="render",
|
||||
help="The active option when Apply was pressed")
|
||||
self.OptionParser.add_option("--fontface",
|
||||
action="store", type="string",
|
||||
dest="fontface", default="rowmans",
|
||||
help="The selected font face when Apply was pressed")
|
||||
|
||||
def effect(self):
|
||||
|
||||
output_generated = False
|
||||
|
||||
# Embed text in group to make manipulation easier:
|
||||
g_attribs = {inkex.addNS('label', 'inkscape'): 'Hershey Text'}
|
||||
g = inkex.etree.SubElement(self.current_layer, 'g', g_attribs)
|
||||
|
||||
scale = self.unittouu('1px') # convert to document units
|
||||
font = getattr(hersheydata, str(self.options.fontface))
|
||||
clearfont = hersheydata.futural
|
||||
# Baseline: modernized roman simplex from JHF distribution.
|
||||
|
||||
w = 0 # Initial spacing offset
|
||||
v = 0 # Initial vertical offset
|
||||
spacing = 3 # spacing between letters
|
||||
|
||||
if self.options.action == "render":
|
||||
# evaluate text string
|
||||
letter_vals = (ord(q) - 32 for q in self.options.text)
|
||||
for q in letter_vals:
|
||||
if q <= 0 or q > 95:
|
||||
w += 2 * spacing
|
||||
else:
|
||||
w = draw_svg_text(q, font, w, 0, g)
|
||||
output_generated = True
|
||||
elif self.options.action == 'sample':
|
||||
w, v = self.render_table_of_all_fonts('group_allfonts', g, spacing, clearfont)
|
||||
output_generated = True
|
||||
scale *= 0.4 # Typically scales to about A4/US Letter size
|
||||
elif self.options.action == 'sampleHW':
|
||||
w, v = self.render_table_of_all_fonts('group_hwfonts', g, spacing, clearfont)
|
||||
output_generated = True
|
||||
scale *= 0.5 # Typically scales to about A4/US Letter size
|
||||
else:
|
||||
# Generate glyph table
|
||||
wmax = 0
|
||||
for p in range(10):
|
||||
w = 0
|
||||
v = spacing * (15 * p - 67)
|
||||
for q in range(10):
|
||||
r = p * 10 + q
|
||||
if r <= 0 or r > 95:
|
||||
w += 5 * spacing
|
||||
else:
|
||||
w = draw_svg_text(r, clearfont, w, v, g)
|
||||
w = draw_svg_text(r, font, w, v, g)
|
||||
w += 5 * spacing
|
||||
if w > wmax:
|
||||
wmax = w
|
||||
w = wmax
|
||||
output_generated = True
|
||||
# Translate group to center of view, approximately
|
||||
t = 'translate({0}, {1})'.format(str(self.view_center[0] - scale * w / 2),
|
||||
str(self.view_center[1] - scale * v / 2))
|
||||
if scale != 1:
|
||||
t += ' scale({0})'.format(scale)
|
||||
g.set('transform', t)
|
||||
|
||||
if not output_generated:
|
||||
self.current_layer.remove(g) # remove empty group, if no SVG was generated.
|
||||
|
||||
def render_table_of_all_fonts(self, fontgroupname, parent, spacing, clearfont):
|
||||
v = 0
|
||||
wmax = 0
|
||||
wmin = 0
|
||||
fontgroup = getattr(hersheydata, fontgroupname)
|
||||
|
||||
# Render list of font names in a vertical column:
|
||||
for f in fontgroup:
|
||||
w = 0
|
||||
letter_vals = [ord(q) - 32 for q in (f[1] + ' -> ')]
|
||||
# we want to right-justify the clear text, so need to know its width
|
||||
for q in letter_vals:
|
||||
w = svg_text_width(q, clearfont, w)
|
||||
|
||||
w = -w # move the name text left by its width
|
||||
if w < wmin:
|
||||
wmin = w
|
||||
# print the font name
|
||||
for q in letter_vals:
|
||||
w = draw_svg_text(q, clearfont, w, v, parent)
|
||||
v += FONT_GROUP_V_SPACING
|
||||
if w > wmax:
|
||||
wmax = w
|
||||
|
||||
# Next, we render a second column. The user's text, in each of the different fonts:
|
||||
v = 0 # back to top line
|
||||
wmaxname = wmax + 8 # single space width
|
||||
for f in fontgroup:
|
||||
w = wmaxname
|
||||
font = getattr(hersheydata, f[0])
|
||||
# evaluate text string
|
||||
letter_vals = (ord(q) - 32 for q in self.options.text)
|
||||
for q in letter_vals:
|
||||
if q <= 0 or q > 95:
|
||||
w += 2 * spacing
|
||||
else:
|
||||
w = draw_svg_text(q, font, w, v, parent)
|
||||
v += FONT_GROUP_V_SPACING
|
||||
if w > wmax:
|
||||
wmax = w
|
||||
return wmax + wmin, v
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
e = Hershey()
|
||||
e.affect()
|
File diff suppressed because one or more lines are too long
Ładowanie…
Reference in New Issue