summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsu_v <suv-sf@users.sourceforge.net>2015-09-29 23:43:25 +0000
committer~suv <suv-sf@users.sourceforge.net>2015-09-29 23:43:25 +0000
commitb5c6cb107bdcc23444ab66ea0d21245dafd9c059 (patch)
tree913bd131d2b805e459a2265e33c3e7342a6bf469
parentTranslations. German translation update. (diff)
downloadinkscape-b5c6cb107bdcc23444ab66ea0d21245dafd9c059.tar.gz
inkscape-b5c6cb107bdcc23444ab66ea0d21245dafd9c059.zip
Extensions. Measure Path: Add more layout options for text (Bug #1460422)
(bzr r14388)
-rw-r--r--share/extensions/measure.inx33
-rwxr-xr-xshare/extensions/measure.py105
2 files changed, 117 insertions, 21 deletions
diff --git a/share/extensions/measure.inx b/share/extensions/measure.inx
index 8fae020e0..7a6598bc7 100644
--- a/share/extensions/measure.inx
+++ b/share/extensions/measure.inx
@@ -11,11 +11,36 @@
<_item msgctxt="measure extension" value="area">Area</_item>
<_item msgctxt="measure extension" value="cofm">Center of Mass</_item>
</param>
- <param name="format" type="enum" _gui-text="Text Orientation: ">
- <_item msgctxt="measure extension" value="textonpath">Text On Path</_item>
- <_item msgctxt="measure extension" value="angle">Fixed Angle</_item>
+ <param name="format" type="notebook">
+ <page name="presets" _gui-text="Text Presets">
+ <param name="presetFormat" type="enum" _gui-text="Position:">
+ <_item value="default">Default</_item>
+ <_item value="TaP_start">Text on Path, Start</_item>
+ <_item value="TaP_middle">Text on Path, Middle</_item>
+ <_item value="TaP_end">Text on Path, End</_item>
+ <_item value="FT_start">Fixed Text, Start of Path</_item>
+ <_item value="FT_bbox">Fixed Text, Center of BBox</_item>
+ <_item value="FT_mass">Fixed Text, Center of Mass</_item>
+ </param>
+ </page>
+ <page name="textonpath" _gui-text="Text on Path">
+ <param name="startOffset" type="string" gui-hidden="true">custom</param>
+ <param name="startOffsetCustom" type="int" appearance="full" min="0" max="100" _gui-text="Offset (%)">50</param>
+ <param name="anchor" type="enum" _gui-text="Text anchor:">
+ <_item value="start">Left</_item>
+ <_item value="middle">Center</_item>
+ <_item value="end">Right</_item>
+ </param>
+ </page>
+ <page name="fixedtext" _gui-text="Fixed Text">
+ <param name="position" type="enum" _gui-text="Position:">
+ <_item value="start">Start of Path</_item>
+ <_item value="center">Center of BBox</_item>
+ <_item value="mass">Center of Mass</_item>
+ </param>
+ <param name="angle" type="float" min="-360" max="360" _gui-text="Angle (°):">0</param>
+ </page>
</param>
- <param name="angle" type="float" min="-360" max="360" _gui-text="Angle [with Fixed Angle option only] (°):">0</param>
<param name="fontsize" type="int" min="1" max="1000" _gui-text="Font size (px):">12</param>
<param name="offset" type="float" min="-10000" max="10000" _gui-text="Offset (px):">-6</param>
<param name="precision" type="int" min="0" max="25" _gui-text="Precision:">2</param>
diff --git a/share/extensions/measure.py b/share/extensions/measure.py
index 0b01ae9c3..9fc632c2a 100755
--- a/share/extensions/measure.py
+++ b/share/extensions/measure.py
@@ -5,6 +5,7 @@ It adds text to the selected path containing the length in a given unit.
Area and Center of Mass calculated using Green's Theorem:
http://mathworld.wolfram.com/GreensTheorem.html
+Copyright (C) 2015 ~suv <suv-sf@users.sf.net>
Copyright (C) 2010 Alvin Penner
Copyright (C) 2006 Georg Wiora
Copyright (C) 2006 Nathan Hurst
@@ -41,7 +42,14 @@ import cubicsuperpath
import bezmisc
inkex.localize()
-locale.setlocale(locale.LC_ALL, '')
+
+# On darwin, fall back to C in cases of
+# - incorrect locale IDs (see comments in bug #406662)
+# - https://bugs.python.org/issue18378
+try:
+ locale.setlocale(locale.LC_ALL, '')
+except locale.Error:
+ locale.setlocale(locale.LC_ALL, 'C')
# third party
try:
@@ -130,17 +138,37 @@ class Length(inkex.Effect):
def __init__(self):
inkex.Effect.__init__(self)
self.OptionParser.add_option("--type",
- action="store", type="string",
- dest="type", default="length",
+ action="store", type="string",
+ dest="mtype", default="length",
help="Type of measurement")
self.OptionParser.add_option("--format",
- action="store", type="string",
- dest="format", default="textonpath",
+ action="store", type="string",
+ dest="mformat", default="textonpath",
help="Text Orientation")
+ self.OptionParser.add_option("--presetFormat",
+ action="store", type="string",
+ dest="presetFormat", default="TaP_start",
+ help="Preset text layout")
+ self.OptionParser.add_option("--startOffset",
+ action="store", type="string",
+ dest="startOffset", default="custom",
+ help="Text Offset along Path")
+ self.OptionParser.add_option("--startOffsetCustom",
+ action="store", type="int",
+ dest="startOffsetCustom", default=50,
+ help="Text Offset along Path")
+ self.OptionParser.add_option("--anchor",
+ action="store", type="string",
+ dest="anchor", default="start",
+ help="Text Anchor")
+ self.OptionParser.add_option("--position",
+ action="store", type="string",
+ dest="position", default="start",
+ help="Text Position")
self.OptionParser.add_option("--angle",
- action="store", type="float",
+ action="store", type="float",
dest="angle", default=0,
- help="Angle")
+ help="Angle")
self.OptionParser.add_option("-f", "--fontsize",
action="store", type="int",
dest="fontsize", default=20,
@@ -175,6 +203,8 @@ class Length(inkex.Effect):
help="dummy")
def effect(self):
+ if self.options.mformat == '"presets"':
+ self.setPreset()
# get number of digits
prec = int(self.options.precision)
scale = self.unittouu('1px') # convert to document units
@@ -195,10 +225,10 @@ class Length(inkex.Effect):
mat = simpletransform.composeParents(node, [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0]])
p = cubicsuperpath.parsePath(node.get('d'))
simpletransform.applyTransformToPath(mat, p)
- if self.options.type == "length":
+ if self.options.mtype == "length":
slengths, stotal = csplength(p)
self.group = inkex.etree.SubElement(node.getparent(),inkex.addNS('text','svg'))
- elif self.options.type == "area":
+ elif self.options.mtype == "area":
stotal = abs(csparea(p)*factor*self.options.scale)
self.group = inkex.etree.SubElement(node.getparent(),inkex.addNS('text','svg'))
else:
@@ -209,16 +239,57 @@ class Length(inkex.Effect):
continue
# Format the length as string
lenstr = locale.format("%(len)25."+str(prec)+"f",{'len':round(stotal*factor*self.options.scale,prec)}).strip()
- if self.options.format == 'textonpath':
- if self.options.type == "length":
- self.addTextOnPath(self.group, 0, 0, lenstr+' '+self.options.unit, id, 'start', '50%', self.options.offset)
+ if self.options.mformat == '"textonpath"':
+ startOffset = self.options.startOffset
+ if startOffset == "custom":
+ startOffset = str(self.options.startOffsetCustom) + '%'
+ if self.options.mtype == "length":
+ self.addTextOnPath(self.group, 0, 0, lenstr+' '+self.options.unit, id, self.options.anchor, startOffset, self.options.offset)
else:
- self.addTextOnPath(self.group, 0, 0, lenstr+' '+self.options.unit+'^2', id, 'start', '0%', self.options.offset)
- else:
- if self.options.type == "length":
- self.addTextWithTspan(self.group, p[0][0][1][0], p[0][0][1][1], lenstr+' '+self.options.unit, id, 'start', -int(self.options.angle), self.options.offset + self.options.fontsize/2)
+ self.addTextOnPath(self.group, 0, 0, lenstr+' '+self.options.unit+'^2', id, self.options.anchor, startOffset, self.options.offset)
+ elif self.options.mformat == '"fixedtext"':
+ if self.options.position == "mass":
+ tx, ty = cspcofm(p)
+ anchor = 'middle'
+ elif self.options.position == "center":
+ bbox = simpletransform.computeBBox([node])
+ tx = bbox[0] + (bbox[1] - bbox[0])/2.0
+ ty = bbox[2] + (bbox[3] - bbox[2])/2.0
+ anchor = 'middle'
+ else: # default
+ tx = p[0][0][1][0]
+ ty = p[0][0][1][1]
+ anchor = 'start'
+ if self.options.mtype == "length":
+ self.addTextWithTspan(self.group, tx, ty, lenstr+' '+self.options.unit, id, anchor, -int(self.options.angle), self.options.offset + self.options.fontsize/2)
else:
- self.addTextWithTspan(self.group, p[0][0][1][0], p[0][0][1][1], lenstr+' '+self.options.unit+'^2', id, 'start', -int(self.options.angle), -self.options.offset + self.options.fontsize/2)
+ self.addTextWithTspan(self.group, tx, ty, lenstr+' '+self.options.unit+'^2', id, anchor, -int(self.options.angle), -self.options.offset + self.options.fontsize/2)
+ else:
+ # center of mass, no text
+ pass
+
+ def setPreset(self):
+ # keep dict in sync with enum in INX file:
+ preset_dict = {
+ 'default_length': ['"textonpath"', "50%", "start", None, None],
+ 'default_area': ['"fixedtext"', None, None, "start", 0.0],
+ 'default_cofm': [None, None, None, None, None],
+ 'TaP_start': ['"textonpath"', "0%", "start", None, None],
+ 'TaP_middle': ['"textonpath"', "50%", "middle", None, None],
+ 'TaP_end': ['"textonpath"', "100%", "end", None, None],
+ 'FT_start': ['"fixedtext"', None, None, "start", 0.0],
+ 'FT_bbox': ['"fixedtext"', None, None, "center", 0.0],
+ 'FT_mass': ['"fixedtext"', None, None, "mass", 0.0],
+ }
+ if self.options.presetFormat == "default":
+ current_preset = 'default_' + self.options.mtype
+ else:
+ current_preset = self.options.presetFormat
+ self.options.mformat = preset_dict[current_preset][0]
+ self.options.startOffset = preset_dict[current_preset][1]
+ self.options.anchor = preset_dict[current_preset][2]
+ self.options.position = preset_dict[current_preset][3]
+ self.options.angle = preset_dict[current_preset][4]
def addCross(self, node, x, y, scale):
l = 3*scale # 3 pixels in document units