klowner / inkscape-applytransforms Goto Github PK
View Code? Open in Web Editor NEWAn Inkscape extension which removes all matrix transforms by applying them recursively to shapes
License: GNU General Public License v2.0
An Inkscape extension which removes all matrix transforms by applying them recursively to shapes
License: GNU General Public License v2.0
The stroke width seems to change also if there is no scale.
I uploaded a svg, you can execute the apply transform several times. The stroke width grows every time.
Thank you.
Is this works with Inkscape 0.92.5
?
I can't see anything in Modify Path
menu.
Info:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.2 LTS
Release: 20.04
Codename: focal
$ inkscape --version
Gtk-Message: 04:47:27.844: Failed to load module "atk-bridge"
Inkscape 0.92.5 (2060ec1f9f, 2020-04-08)
it didn't get applied to an ellipse in a group, but did get applied to paths in the group. sadly i have lost the file already so i can't provide a testcase.
I have the following file (didnt know how to link it but figured its small enough for code)
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
class="card"
face="JD"
height="3.5in"
preserveAspectRatio="none"
viewBox="-120 -168 240 336"
width="2.5in"
version="1.1"
id="svg89"
sodipodi:docname="testFile.svg"
inkscape:version="1.2.2 (b0a8486541, 2022-12-01)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<sodipodi:namedview
id="namedview91"
pagecolor="#505050"
bordercolor="#eeeeee"
borderopacity="1"
inkscape:showpageshadow="0"
inkscape:pageopacity="0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#505050"
inkscape:document-units="in"
showgrid="false"
inkscape:zoom="4.3226109"
inkscape:cx="80.391228"
inkscape:cy="96.238132"
inkscape:window-width="2560"
inkscape:window-height="1377"
inkscape:window-x="-8"
inkscape:window-y="-8"
inkscape:window-maximized="1"
inkscape:current-layer="layer1" />
<defs
id="defs45" />
<g
inkscape:groupmode="layer"
id="layer1"
inkscape:label="Layer 1">
<path
stroke="#4444ff"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="3"
fill="none"
d="m 85,590 c -4.700789,8.72507 -5.186787,17.0989 0,25 m 3.710078,6.88418 c -4.700789,8.72507 -5.186787,17.0989 0,25 m 0,10 c -4.700789,8.72507 -5.186787,17.0989 0,25 m 0,5 c -4.700789,8.72507 -5.186787,17.0989 0,25 M 130,510 c 0,25 10,30 10,30 m -89.072313,57.4996 c -1.13052,2.57966 -1.33893,5.77405 0,10 m 0,23.02404 c -1.13052,2.57966 -1.33893,5.77405 0,10 m 0,24.47596 c -1.13052,2.57966 -1.33893,5.77405 0,10 m 0,25.0004 c -1.13052,2.57966 -1.33893,5.77405 0,10 m 0,-13.84068 c -1.13052,2.57966 -1.33893,5.77405 0,10 M 725,500 c 25,-10 40,-10 50,-5 M 705,255 c -30,-20 -60.95115,-7.27972 -90,15 m 170,5 c 24.49605,-30.28885 50.8757,-35.96138 70,-25 m -162.45974,8.60402 c 5.79878,4.0092 9.63542,10.97454 9.63542,18.89598 0,12.42641 -9.44135,22.5 -21.08785,22.5 -11.6465,0 -21.08785,-10.07359 -21.08785,-22.5 0,-3.28538 0.65995,-6.40629 1.84613,-9.22005 m 191.2777,-6.54105 c 6.97583,3.39911 11.87622,11.41458 11.87622,20.7611 0,12.42641 -8.66208,22.5 -19.34729,22.5 -10.68521,0 -19.34729,-10.07359 -19.34729,-22.5 0,-3.81643 0.81704,-7.41094 2.25881,-10.55985 M 835,317.32348 c 11.29232,3.96884 26.09989,-0.36152 27.06897,-2.32348 M 517.96925,509.82169 C 557.53794,533.35836 604.4889,555.09153 650,555 M 525.36882,498.26604 C 565.47164,522.39165 613.48777,545.09355 660,545"
id="path389"
style="display:inline"
inkscape:label="Untransformed"
transform="matrix(0.12676923,0,0,0.13039999,-82.400002,-130.39999)" />
<path
stroke="#4444ff"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="3"
fill="none"
d="M -71.6246 -53.464 C -72.2205 -52.3263 -72.2822 -51.2343 -71.6246 -50.204 M -71.1543 -49.3063 C -71.7502 -48.1686 -71.8118 -47.0766 -71.1543 -46.0463 M -71.1543 -44.7423 C -71.7502 -43.6046 -71.8118 -42.5126 -71.1543 -41.4823 M -71.1543 -40.8303 C -71.7502 -39.6926 -71.8118 -38.6006 -71.1543 -37.5703 M -65.92 -63.896 C -65.92 -60.636 -64.6523 -59.984 -64.6523 -59.984 M -75.9439 -52.4861 C -76.0873 -52.1497 -76.1137 -51.7331 -75.9439 -51.1821 M -75.9439 -48.1797 C -76.0873 -47.8433 -76.1137 -47.4268 -75.9439 -46.8757 M -75.9439 -43.6841 C -76.0873 -43.3477 -76.1137 -42.9311 -75.9439 -42.3801 M -75.9439 -39.12 C -76.0873 -38.7836 -76.1137 -38.3671 -75.9439 -37.816 M -75.9439 -39.6208 C -76.0873 -39.2844 -76.1137 -38.8679 -75.9439 -38.3168 M 9.50752 -65.2 C 12.6767 -66.504 14.5783 -66.504 15.846 -65.852 M 6.97214 -97.148 C 3.16907 -99.756 -0.754571 -98.0973 -4.43707 -95.192 M 17.1137 -94.54 C 20.219 -98.4897 23.5631 -99.2294 25.9875 -97.8 M 5.39264 -96.678 C 6.12774 -96.1552 6.61411 -95.247 6.61411 -94.214 C 6.61411 -92.5936 5.41724 -91.28 3.94082 -91.28 C 2.46441 -91.28 1.26754 -92.5936 1.26754 -94.214 C 1.26754 -94.6424 1.3512 -95.0494 1.50157 -95.4163 M 25.7497 -96.2692 C 26.634 -95.826 27.2552 -94.7808 27.2552 -93.562 C 27.2552 -91.9416 26.1571 -90.628 24.8026 -90.628 C 23.448 -90.628 22.3499 -91.9416 22.3499 -93.562 C 22.3499 -94.0597 22.4535 -94.5284 22.6363 -94.939 M 23.4521 -89.021 C 24.8836 -88.5035 26.7608 -89.0682 26.8836 -89.324 M -16.7376 -63.9193 C -11.7215 -60.8501 -5.76955 -58.0161 -0.00015 -58.028 M -15.7995 -65.4261 C -10.7157 -62.2801 -4.62877 -59.3198 1.26754 -59.332"
id="path780"
style="display:inline"
inkscape:label="Transformed" />
</g>
</svg>
I have 1 untransformed path and one that is transformed but because the stroke width doesnt change, the lines are noticeably thicker. Wondering if this is by design, or i am doing something wrong with the plugin or if this is actually an issue.
I also wanted to ask if it is also by design that any labels on the path get removed after a transform, it is slightly annoying when i have labelled everything then go to transform and all the labels are replaced with auto generated names.
This extension does not work for me. It simply removes the transform
attribute from the <polyline>
element, but does not apply the transform to the data in the points
attribute.
I'm running
inkscape --actions="com.klowner.filter.apply-transform;export-do" file.svg
the svg looks like
..................snip.....
</defs>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(9.6501094,-20.044252)">
<path
d="m -2.5461094,106.82825 q -2.304,0 -4.032,-0.384 -1.728,-0.288 -3.072,-0.864 v -7.295998 q 1.536,0.384 3.264,0.672 1.728,0.288 3.648,0.288 2.40000002,0 4.512,-0.96 2.208,-0.96 3.552,-3.36 1.344,-2.4 1.344,-6.72 v -68.16 h 8.6400004 v 67.488 q 0,9.888 -4.896,14.591998 -4.8960004,4.704 -12.9600004,4.704 z M 51.693959,36.268252 q 9.408,0 13.92,4.128 4.512,4.128 4.512,13.152 v 35.04 h -6.144 l -1.632,-7.296 h -0.384 q -3.36,4.224 -7.104,6.24 -3.648,2.016 -10.176,2.016 -7.008,0 -11.616,-3.648 -4.608,-3.744 -4.608,-11.616 0,-7.68 6.048,-11.808 6.048,-4.224 18.624,-4.608 l 8.736,-0.288 v -3.072 q 0,-6.432 -2.784,-8.928 -2.784,-2.496 -7.872,-2.496 -4.032,0 -7.68,1.248 -3.648,1.152 -6.816,2.688 l -2.592,-6.336 q 3.36,-1.824 7.968,-3.072 4.608,-1.344 9.6,-1.344 z m 2.496,27.456 q -9.6,0.384 -13.344,3.072 -3.648,2.688 -3.648,7.584 0,4.32 2.592,6.336 2.688,2.016 6.816,2.016 6.528,0 10.848,-3.552 4.32,-3.648 4.32,-11.136 v -4.608 z m 56.640081,-27.552 q 9.216,0 13.92,4.512 4.704,4.416 4.704,14.4 v 33.504 h -8.352 v -32.928 q 0,-12.384 -11.52,-12.384 -8.544,0 -11.808001,4.8 -3.264,4.8 -3.264,13.824 v 26.688 h -8.448 v -51.456 h 6.816 l 1.248,7.008 h 0.48 q 2.496,-4.032 6.912001,-5.952 4.416,-2.016 9.312,-2.016 z"
id="text1"
style="font-size:96px;white-space:pre;stroke-width:1.38709;stroke-linecap:round;stroke-linejoin:round"
aria-label="Jan" />
</g>
</svg>
The error I receive is:
Emergency save activated!
Emergency save completed. Inkscape will close now.
If you can reproduce this crash, please file a bug at https://inkscape.org/report
with a detailed description of the steps leading to the crash, so we can fix it.
** Message: 09:31:03.066: Error:
0# Inkscape::Application::crash_handler(int) in inkscape
1# 0x00007F0BD565FBB0 in /lib64/libc.so.6
2# Inkscape::Extension::ExecutionEnv::ExecutionEnv(Inkscape::Extension::Effect*, Inkscape::UI::View::View*, Inkscape::Extension::Implementation::ImplementationDocumentCache*, bool, bool) in inkscape
3# Inkscape::Extension::Effect::effect(Inkscape::UI::View::View*) in inkscape
4# Inkscape::Extension::Effect::prefs(Inkscape::UI::View::View*) in inkscape
5# 0x00007F0BD6965C59 in /lib64/libgiomm-2.4.so.1
6# g_closure_invoke in /lib64/libgobject-2.0.so.0
7# 0x00007F0BD76E715D in /lib64/libgobject-2.0.so.0
8# g_signal_emit_valist in /lib64/libgobject-2.0.so.0
9# g_signal_emit in /lib64/libgobject-2.0.so.0
10# 0x00007F0BD77F35B5 in /lib64/libgio-2.0.so.0
11# InkscapeApplication::process_document(SPDocument*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) in inkscape
12# InkscapeApplication::on_open(std::vector<Glib::RefPtr<Gio::File>, std::allocator<Glib::RefPtr<Gio::File> > > const&, Glib::ustring const&) in inkscape
13# 0x00007F0BD6904194 in /lib64/libgiomm-2.4.so.1
14# g_closure_invoke in /lib64/libgobject-2.0.so.0
15# 0x00007F0BD76E715D in /lib64/libgobject-2.0.so.0
16# g_signal_emit_valist in /lib64/libgobject-2.0.so.0
17# g_signal_emit in /lib64/libgobject-2.0.so.0
18# 0x00007F0BD77EBD32 in /lib64/libgio-2.0.so.0
19# g_application_run in /lib64/libgio-2.0.so.0
20# main in inkscape
21# 0x00007F0BD5649B8A in /lib64/libc.so.6
22# __libc_start_main in /lib64/libc.so.6
23# _start in inkscape
Segmentation fault (core dumped)
Hi Klowner,
could you add a license to the extension? It's a useful tool for many people, but it's currently not 'safe to use'. I would suggest 'GPLv2 or higher', for it to be compatible with Inkscape's licensing.
...with a message
Traceback (most recent call last): File "applytransform.py", line 9, in <module> from inkex.paths import CubicSuperPath, Path ImportError: No module named paths
Steps to reproduce:
Open SVG in the Inkscape 1.0.2
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 459.75 385.83">
<g id="test">
<path class="cls-1"
d="M4917.86,4893.09c-64.49.89-159.87,67.81-132.49,141.92,12.84,34.73,56.12,39.55,86.66,24.12,32-16.17,52.86-49.24,68.56-79.6,10.53-20.39,26.46-53.24,8.8-74.07C4941.93,4896.66,4929.58,4892.93,4917.86,4893.09Z"
transform="translate(-4732.62 -4684.06)"/>
</g>
</svg>
and run this extension (taken from the master branch).
Actual result:
Traceback (most recent call last):
File "applytransform.py", line 160, in <module>
ApplyTransform().run()
File "/Applications/Inkscape.app/Contents/Resources/share/inkscape/extensions/inkex/base.py", line 140, in run
self.save_raw(self.effect())
File "applytransform.py", line 25, in effect
self.recursiveFuseTransform(self.document.getroot())
File "applytransform.py", line 157, in recursiveFuseTransform
self.recursiveFuseTransform(child, transf)
File "applytransform.py", line 157, in recursiveFuseTransform
self.recursiveFuseTransform(child, transf)
File "applytransform.py", line 73, in recursiveFuseTransform
p = CubicSuperPath(d)
File "/Applications/Inkscape.app/Contents/Resources/share/inkscape/extensions/inkex/paths.py", line 1325, in __init__
items = Path(items)
File "/Applications/Inkscape.app/Contents/Resources/share/inkscape/extensions/inkex/paths.py", line 1086, in __init__
for item in (path_d or ()):
File "/Applications/Inkscape.app/Contents/Resources/share/inkscape/extensions/inkex/paths.py", line 1102, in parse_string
args = list(strargs(numbers))
File "/Applications/Inkscape.app/Contents/Resources/share/inkscape/extensions/inkex/utils.py", line 187, in strargs
return [kind(val) for val in string.replace(',', ' ').replace('-', ' -').replace('e ', 'e').split()]
File "/Applications/Inkscape.app/Contents/Resources/share/inkscape/extensions/inkex/utils.py", line 187, in <listcomp>
return [kind(val) for val in string.replace(',', ' ').replace('-', ' -').replace('e ', 'e').split()]
ValueError: could not convert string to float: '-64.49.89'
Expected result:
transforms are removed
I flipped some objects with Edit->Flip Horizonal/Vertical
(or hitting v or h)
After running the plugin, the source is still left with: transform="scale(-1,1)"
Maybe this is the desired behaviour, it wasn't for me :)
Thanks for an otherwise very useful plugin!
After transformation is applied start and end point of linearGradient don't change. Thus SVGs look different.
It would be nice to have start and end point of linear gradients converted according to transformation.
Hi,
i created a new inkscape extension which is calling ApplyTransform class externally to do some cool stuff. This works fine for most things but it seems there is some small hidden error which was was able to fix by simply adding a str() cast. i am asking if you could add this to that repo. the explanation:
/home/tomate/.local/lib/python3.8/site-packages/shiboken2/files.dir/shibokensupport/__feature__.py:142: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
return original_import(name, *args, **kwargs)
Traceback (most recent call last):
File "vpypetools.py", line 200, in <module>
vpypetools().run()
File "/usr/share/inkscape/extensions/inkex/base.py", line 141, in run
self.save_raw(self.effect())
File "vpypetools.py", line 184, in effect
applytransform.ApplyTransform().recursiveFuseTransform(shape)
File "../applytransform.py", line 156, in recursiveFuseTransform
self.recursiveFuseTransform(child, transf)
File "../applytransform.py", line 75, in recursiveFuseTransform
node.set('d', Path(CubicSuperPath(p).to_path()))
File "src/lxml/etree.pyx", line 816, in lxml.etree._Element.set
File "src/lxml/apihelpers.pxi", line 593, in lxml.etree._setAttributeValue
File "src/lxml/apihelpers.pxi", line 1538, in lxml.etree._utf8
TypeError: Argument must be bytes or unicode, got 'Path'
the external call i did was
...
applyTransformAvailable = False
...
# at first we apply external extension
try:
sys.path.append("..") # add parent directory to path to allow importing applytransform (vpype extension is encapsulated in sub directory)
import applytransform
applyTransformAvailable = True
except Exception as e:
# inkex.utils.debug(e)
inkex.utils.debug("Calling 'Apply Transformations' extension failed. Maybe the extension is not installed. You can download it from official InkScape Gallery. Skipping this step")
...
if self.options.apply_transformations and applyTransformAvailable:
for shape in self.svg.selection:
applytransform.ApplyTransform().recursiveFuseTransform(shape)
i changed the line 75 from
node.set('d', Path(CubicSuperPath(p).to_path())
to
node.set('d', str(Path(CubicSuperPath(p).to_path()))
now this works perfectly
The command-line option --verb is deprecated
Extension does not work with my last Inkscape version. The following error is displayed :
File "applytransform.py", line 1
<?xml version="1.0" encoding="UTF-8"?>
^
SyntaxError: invalid syntax
Ubuntu 18.04
Inkscape 0.92.3 (2405546, 2018-03-11)
For some SVGs the extension fails with the following error:
Traceback (most recent call last):
File "applytransform.py", line 159, in <module>
ApplyTransform().run()
File "/nix/store/ahn6z9yjrwh8b12c1cxn77ydhym9l50c-inkscape-with-extensions-1.1/share/inkscape/extensions/inkex/base.py", line 131, in run
self.save_raw(self.effect())
File "applytransform.py", line 25, in effect
self.recursiveFuseTransform(self.document.getroot())
File "applytransform.py", line 156, in recursiveFuseTransform
self.recursiveFuseTransform(child, transf)
File "applytransform.py", line 156, in recursiveFuseTransform
self.recursiveFuseTransform(child, transf)
File "applytransform.py", line 156, in recursiveFuseTransform
self.recursiveFuseTransform(child, transf)
[Previous line repeated 1 more time]
File "applytransform.py", line 73, in recursiveFuseTransform
p = CubicSuperPath(d)
File "/nix/store/ahn6z9yjrwh8b12c1cxn77ydhym9l50c-inkscape-with-extensions-1.1/share/inkscape/extensions/inkex/paths.py", line 1450, in __init__
items = Path(items)
File "/nix/store/ahn6z9yjrwh8b12c1cxn77ydhym9l50c-inkscape-with-extensions-1.1/share/inkscape/extensions/inkex/paths.py", line 1173, in __init__
for item in (path_d or ()):
File "/nix/store/ahn6z9yjrwh8b12c1cxn77ydhym9l50c-inkscape-with-extensions-1.1/share/inkscape/extensions/inkex/paths.py", line 1188, in parse_string
args = list(strargs(numbers))
File "/nix/store/ahn6z9yjrwh8b12c1cxn77ydhym9l50c-inkscape-with-extensions-1.1/share/inkscape/extensions/inkex/utils.py", line 167, in strargs
return [kind(val) for val in string.replace(',', ' ').replace('-', ' -').replace('e ', 'e').replace('E ','e').split()]
File "/nix/store/ahn6z9yjrwh8b12c1cxn77ydhym9l50c-inkscape-with-extensions-1.1/share/inkscape/extensions/inkex/utils.py", line 167, in <listcomp>
return [kind(val) for val in string.replace(',', ' ').replace('-', ' -').replace('e ', 'e').replace('E ','e').split()]
ValueError: could not convert string to float: '-16.43.12'
I recently downloaded Inkscape 1.0.2 for Windows. I can confirm that the recommended path C:\Program Files\Inkscape\share\extensions does not work. The path is C:\Program Files\Inkscape\share\inkscape\extensions.
When a clipPath
is used, the transform is not applied to it.
This might be tricky since different elements might use a single clip path at the same time so it might need to be cloned.
Example:
Same with Mask:
Currently cannot perform even a simple translate transformation on a rect element.
Example:
<rect width="1" height="1" x="2" y="2" id="rect1" transform="translate(2, 2)" />
Expected result:
<rect width="1" height="1" x="4" y="4" id="rect1" />
When I run the extension, I get the following error:
Traceback (most recent call last):
File "~/.config/inkscape/extensions/applytransform.py", line 154, in <module>
ApplyTransform().run()
File "/usr/share/inkscape/extensions/inkex/base.py", line 131, in run
self.save_raw(self.effect())
File "~/.config/inkscape/extensions/applytransform.py", line 23, in effect
self.recursiveFuseTransform(shape)
File "~/.config/inkscape/extensions/applytransform.py", line 60, in recursiveFuseTransform
transf = Transform(transf) @ Transform(node.get("transform", None))
TypeError: unsupported operand type(s) for @: 'Transform' and 'Transform'
Take a SVG file and delete some path in it. Then go to "Document properties" and click "Adjust page to drawing or selection". You'll get a transform on the layer itself that's not removed by this extension.
On inkscape 1.0.2 (e86c8708, 2021-01-15)
, I run this extension on a file and get
Traceback (most recent call last):
File "applytransform.py", line 159, in <module>
ApplyTransform().run()
File "/Applications/Inkscape.app/Contents/Resources/share/inkscape/extensions/inkex/base.py", line 140, in run
self.save_raw(self.effect())
File "applytransform.py", line 25, in effect
self.recursiveFuseTransform(self.document.getroot())
File "applytransform.py", line 156, in recursiveFuseTransform
self.recursiveFuseTransform(child, transf)
File "applytransform.py", line 156, in recursiveFuseTransform
self.recursiveFuseTransform(child, transf)
File "applytransform.py", line 156, in recursiveFuseTransform
self.recursiveFuseTransform(child, transf)
File "applytransform.py", line 77, in recursiveFuseTransform
self.scaleStrokeWidth(node, transf)
File "applytransform.py", line 48, in scaleStrokeWidth
stroke_width = self.svg.uutounit(style.get('stroke-width').strip())
TypeError: uutounit() missing 1 required positional argument: 'to_unit'
related: #43
From https://gitlab.com/inkscape/extensions/-/blob/3796f912f666a0981917839c77eb94fdd6fc6a94/inkex/elements/_base.py#L453 it doesn't seem that to_unit
is a required argument. But for me, that function is defined in /Applications/Inkscape.app/Contents/Resources/share/inkscape/extensions/inkex/elements/_svg.py
as
def uutounit(self, value, to_unit):
"""Convert from the document's units to the given unit"""
return convert_unit(render_unit(value, self.unit), to_unit)
So this must have changed in a more recent Inkscape release. Indeed, at this commit:
https://gitlab.com/inkscape/extensions/-/commit/e15529f3ae9c1ee951ca4a60fd7b9f24be16126c
It should just be passed the "px" argument, then.
Good day!
The last commit at Oct 19, 2019 has introduced a new issue. Please look at the line 55 (as it seems) of the script:
stroke_width *= math.sqrt(transf[0][0] * transf[1][1])
This code will cause a domain error while scaling stroke width in case the figure being transformed has been previously flipped (mirrored) around one of the axises.
I propose to correct the problem by getting absolute value of the multiplication:
stroke_width *= math.sqrt(abs(transf[0][0] * transf[1][1]))
Best regards,
Alexey
As it currently stands, a line tilted at 45 degrees will get a different width than a vertical or horizontal line. In order to properly handle rotations, line 49 should actually be
stroke_width *= math.sqrt(abs(transf.a * transf.d - transf.b * transf.c))
This is because the width of something is better defined in terms of the transform's determinant. The above version is rotation-invariant.
Thanks for making this—I incorporated a version into my own extensions.
I thought this addon will help me to flatten transformations but i was wrong. It just exchanges one or few transformations add to object into one matrix transformation. I have two apps which i need to import created SVG and they totally don't understand matrix transformation thing. Really don't understand what this addon was for from the very start.
When trying to apply transform i get a deprecated warning:
DeprecationWarning: inkex.deprecated.main.transform_mul -> Use @ operator instead
transf = Transform(transf) * Transform(node.get("transform", None))
everytime I try to run the extension independently of the number and type of objects selected, I get this message
Traceback (most recent call last):
File "applytransform.py", line 9, in <module>
from inkex.paths import CubicSuperPath, Path
ImportError: No module named paths
I recive a error in new version of inskape
applytransform.py:60: DeprecationWarning: inkex.deprecated.main.transform_mul -> Use @ operator instead transf = Transform(transf) * Transform(node.get("transform", None))
What to change?
latest version of extension (as of 2019-12-22).
Inkscape 0.92.4 - Windows 10 Pro
stripped my svg file down to 1 grouped element, goal is to create a set of svg symbols to make up an Inkscape symbol library. So I need to eliminate the transform attributes per the Inkscape share/extensions/README. This extension does that quite well. I tried this both by un-grouping the set of path, text objects as well as using the source as is.
But weirdly, after running the extension, several of the path elements no longer render as previously. They are there - if I use the Object-> Objects tool, select the elements, they are present with the expected attributes, including the same style:fill RGB value as previously. If I use the 'Edit path by nodes' tool, the vertices are rendered, I can then use the 'show path outline' tool to show the polygon's edges. But no fill rendering as before. 1 item I noticed was the replacement of the z closepath instruction with trailing relative moves to the origin. I replaced these with the z instruction to see if it helped (ensuring the polygon was closed so a fill can be handled). No difference in the rendering. Nor did selecting either/both of the affected 2 path elements, then raising them to the 'top' of the rendering stack make any difference (ie. not occluded by some other object, that I can tell).
an xxdiff of the 2 attached files doesn't point out anything obvious to me. Nothing in the defs element was affected(?) by the apply transform extension.
But I'm not an SVG nor Inkscape expert :-(
Many thanks for writing this extension.
Istio-Pilot22-plain-posttransform.svg.txt
Istio-Pilot22-plain.svg.txt
Getting the following error when running the plugin:
C:\Program Files\Inkscape\bin\pythonw.exe: can't find 'main' module in 'C:\Program Files\Inkscape\bin'
Inkscape 1.2.2 (732a01da63, 2022-12-09)
The version on Inkscape.org is the old one that doesn't work with the new Inkscape.
Thanks
Hi, have a look at the attached image. When applying tranforms, I still get negative values:
m 500,200 c -93.00056,0.77365 -176.95216,75.89244 -196.49192,165.35893 -7.66452,28.92451 -5.36465,68.21355 27.02966,80.71182 32.7893,15.50741 73.39068,-14.23091 69.60155,-50.04238 5.97407,-50.33489 52.37777,-95.71901 103.83234,-95.88908 55.97802,6.45339 106.34526,64.06624 94.11814,121.42401 -12.01567,34.77315 -43.45207,57.47053 -67.87036,83.44066 -70.75545,68.78515 -137.95665,141.53976 -198.30828,219.63323 ...
Here is the preview in another app:
But image is still fine in InkScape. Did I miss something or is it a bug?
Inkscape 0.92, GNU/Linux
`
/home/nr/.config/inkscape/extensions/applytransform.inx:46: parser error : Specification mandate value for attribute data-pjax-transient
a name="hovercard-subject-tag" content="repository:15256624" data-pjax-transient
^
/home/nr/.config/inkscape/extensions/applytransform.inx:53: parser error : Specification mandate value for attribute data-pjax-transient
^
/home/nr/.config/inkscape/extensions/applytransform.inx:68: parser error : Specification mandate value for attribute data-pjax-transient
ta class="js-ga-set" name="dimension10" content="Responsive" data-pjax-transient
^
/home/nr/.config/inkscape/extensions/applytransform.inx:95: parser error : Specification mandate value for attribute data-pjax-transient
ner/inkscape-applytransforms/blob/master/applytransform.inx" data-pjax-transient
^
/home/nr/.config/inkscape/extensions/applytransform.inx:111: parser error : Opening and ending tag mismatch: link line 109 and head
^
/home/nr/.config/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag link line 102
^
/home/nr/.config/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 100
^
/home/nr/.config/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 98
^
/home/nr/.config/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag link line 95
^
/home/nr/.config/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 90
^
/home/nr/.config/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag link line 88
^
/home/nr/.config/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 85
^
/home/nr/.config/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 83
^
/home/nr/.config/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 80
^
/home/nr/.config/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 77
^
/home/nr/.config/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 76
^
/home/nr/.config/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 70
^
/home/nr/.config/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 68
^
/home/nr/.config/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 65
^
/home/nr/.config/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 58
^
/home/nr/.config/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 57
^
/home/nr/.config/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 56
^
/home/nr/.config/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 55
^
/home/nr/.config/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 53
^
/home/nr/.config/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 46
^
/home/nr/.config/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag link line 41
^
/home/nr/.config/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 36
^
/home/nr/.config/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 35
^
/home/nr/.config/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag link line 34
^
/home/nr/.config/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag link line 33
^
/home/nr/.config/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 32
^
/home/nr/.config/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 29
^
/home/nr/.config/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag link line 16
^
/home/nr/.config/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag link line 15
^
/home/nr/.config/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag link line 14
^
/home/nr/.config/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag link line 13
^
/home/nr/.config/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag link line 12
^
/home/nr/.config/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag link line 11
^
/home/nr/.config/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag link line 10
^
/home/nr/.config/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 9
^
/home/nr/.config/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag head line 8
^
/home/nr/.config/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag html line 7
^
** (inkscape:10033): WARNING **: Extension definition started with extension:html instead of extension:inkscape-extension. Extension will not be created. See http://wiki.inkscape.org/wiki/index.php/Extensions for reference.
** (inkscape:10033): WARNING **: Unable to create extension from definition file /home/nr/.config/inkscape/extensions/applytransform.inx.
/usr/share/inkscape/extensions/applytransform.inx:46: parser error : Specification mandate value for attribute data-pjax-transient
a name="hovercard-subject-tag" content="repository:15256624" data-pjax-transient
^
/usr/share/inkscape/extensions/applytransform.inx:53: parser error : Specification mandate value for attribute data-pjax-transient
^
/usr/share/inkscape/extensions/applytransform.inx:68: parser error : Specification mandate value for attribute data-pjax-transient
ta class="js-ga-set" name="dimension10" content="Responsive" data-pjax-transient
^
/usr/share/inkscape/extensions/applytransform.inx:95: parser error : Specification mandate value for attribute data-pjax-transient
ner/inkscape-applytransforms/blob/master/applytransform.inx" data-pjax-transient
^
/usr/share/inkscape/extensions/applytransform.inx:111: parser error : Opening and ending tag mismatch: link line 109 and head
^
/usr/share/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag link line 102
^
/usr/share/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 100
^
/usr/share/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 98
^
/usr/share/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag link line 95
^
/usr/share/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 90
^
/usr/share/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag link line 88
^
/usr/share/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 85
^
/usr/share/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 83
^
/usr/share/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 80
^
/usr/share/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 77
^
/usr/share/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 76
^
/usr/share/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 70
^
/usr/share/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 68
^
/usr/share/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 65
^
/usr/share/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 58
^
/usr/share/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 57
^
/usr/share/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 56
^
/usr/share/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 55
^
/usr/share/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 53
^
/usr/share/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 46
^
/usr/share/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag link line 41
^
/usr/share/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 36
^
/usr/share/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 35
^
/usr/share/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag link line 34
^
/usr/share/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag link line 33
^
/usr/share/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 32
^
/usr/share/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 29
^
/usr/share/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag link line 16
^
/usr/share/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag link line 15
^
/usr/share/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag link line 14
^
/usr/share/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag link line 13
^
/usr/share/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag link line 12
^
/usr/share/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag link line 11
^
/usr/share/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag link line 10
^
/usr/share/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag meta line 9
^
/usr/share/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag head line 8
^
/usr/share/inkscape/extensions/applytransform.inx:1024: parser error : Premature end of data in tag html line 7
^
`
This extension would work well as a core extension installed by default for all Inkscape users.
If you'd like to bring this extension to https://gitlab.com/inkscape/extensions/ with a merge request (it'll need to be upgraded to 1.0 and have a comparison test written) but would be a good addition.
I try the extension on Inkscape 1.2.1, I've got the following error.
applytransform.py:60: DeprecationWarning: inkex.deprecated.main.transform_mul -> Use @ operator instead
transf = Transform(transf) * Transform(node.get("transform", None))
I found the line in the Python script, but I'm not sure how to update the code.
I would like to apply this as part of a build script. I like having a source SVG with all the original transforms for easy editing, but optimizing the output requires flattening all these things. I'd like to add this as a verb to my scripts. Is there a way to define a new verb in an extension?
Here's the original SVG (with .txt
extension added so github accepts it...):
plate.svg.txt
The original SVG rendered as PNG:
SVG with "Apply Transform" run, rendered as PNG:
And finally, the transformed SVG:
plate-transformed.svg.txt
It looks like the outline had the transformation applied, but the circles did not.
When I run, I get the following error:
/usr/lib/python3/dist-packages/apport/report.py:13: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import fnmatch, glob, traceback, errno, sys, atexit, locale, imp, stat
Traceback (most recent call last):
File "applytransform.py", line 159, in <module>
ApplyTransform().run()
File "/usr/share/inkscape/extensions/inkex/base.py", line 140, in run
self.save_raw(self.effect())
File "applytransform.py", line 23, in effect
self.recursiveFuseTransform(shape)
File "applytransform.py", line 60, in recursiveFuseTransform
transf = Transform(transf) * Transform(node.get("transform", None))
AttributeError: 'tuple' object has no attribute 'get'
I'm on:
Any advice? Thanks!
Steps to reproduce:
Expected result:
Actual result:
Environment:
Windows 10, Inkscape 0.92.1.
Thanks for your extension! Unfortunately it doesn't work for me:
$ python --version
Python 2.7.12
inkscape v0.91
ubuntu 16.04
Traceback (most recent call last):
File "applytransform.py", line 96, in <module>
e.affect()
File "/usr/share/inkscape/extensions/inkex.py", line 265, in affect
self.getposinlayer()
File "/usr/share/inkscape/extensions/inkex.py", line 207, in getposinlayer
x = self.unittouu( xattr[0] + 'px' )
File "/usr/share/inkscape/extensions/inkex.py", line 351, in unittouu
return retval * (self.__uuconv[u.string[u.start():u.end()]] / self.__uuconv[self.getDocumentUnit()])
File "/usr/share/inkscape/extensions/inkex.py", line 304, in getDocumentUnit
p = param.match(svgwidth)
TypeError: expected string or buffer
Maybe it's a bug in ubuntu / inkscape?
There are some deprecated functions and dependencies.
After removing the deprecated dependencies from applytransforms.inx (as per http://wiki.inkscape.org/wiki/index.php/Updating_your_Extension_for_1.0) so that the extension will run, I get the following errors. The first few are easy enough to fix, but I haven't picked through the rest just yet!
applytransform.py:115: DeprecationWarning: Effect.affect is now `Effect.run()`. The `output` argument has changed.
e.affect()
applytransform.py:21: DeprecationWarning: Effect.getselected has been removed
self.getselected()
applytransform.py:23: DeprecationWarning: Effect.selected is now a dict in the svg. Use `self.svg.selected`.
if self.selected:
applytransform.py:27: DeprecationWarning: simpletransform.parseTransform -> Transform(str).matrix
self.recursiveFuseTransform(self.document.getroot(), parseTransform(None))
applytransform.py:66: DeprecationWarning: simpletransform.parseTransform -> Transform(str).matrix
transf = composeTransform(transf, parseTransform(node.get("transform", None)))
applytransform.py:66: DeprecationWarning: simpletransform.composeTransform -> Transform(M1) * Transform(M2)
transf = composeTransform(transf, parseTransform(node.get("transform", None)))
applytransform.py:103: DeprecationWarning: simpletransform.formatTransform -> str(Transform(mat))
node.set('transform', formatTransform(transf))
applytransform.py:75: DeprecationWarning: cubicsuperpath.parsePath -> None
p = cubicsuperpath.parsePath(d)
Traceback (most recent call last):
File "applytransform.py", line 115, in <module>
e.affect()
File "/Applications/Inkscape.app/Contents/Resources/share/inkscape/extensions/inkex/deprecated.py", line 181, in affect
return self.run(args=args)
File "/Applications/Inkscape.app/Contents/Resources/share/inkscape/extensions/inkex/base.py", line 111, in run
self.save_raw(self.effect())
File "applytransform.py", line 27, in effect
self.recursiveFuseTransform(self.document.getroot(), parseTransform(None))
File "applytransform.py", line 110, in recursiveFuseTransform
self.recursiveFuseTransform(child, transf)
File "applytransform.py", line 110, in recursiveFuseTransform
self.recursiveFuseTransform(child, transf)
File "applytransform.py", line 75, in recursiveFuseTransform
p = cubicsuperpath.parsePath(d)
File "/Applications/Inkscape.app/Contents/Resources/share/inkscape/extensions/inkex/deprecated.py", line 258, in _inner
return func(*args, **kwargs)
File "/Applications/Inkscape.app/Contents/Resources/share/inkscape/extensions/inkex/deprecated-simple/cubicsuperpath.py", line 37, in parsePath
return paths.CubicSuperPath(paths.Path(d))
File "/Applications/Inkscape.app/Contents/Resources/share/inkscape/extensions/inkex/paths.py", line 1014, in __init__
for item in (path_d or ()):
File "/Applications/Inkscape.app/Contents/Resources/share/inkscape/extensions/inkex/paths.py", line 1027, in parse_string
args = list(strargs(numbers))
File "/Applications/Inkscape.app/Contents/Resources/share/inkscape/extensions/inkex/utils.py", line 169, in strargs
return [kind(val) for val in string.replace(',', ' ').split()]
File "/Applications/Inkscape.app/Contents/Resources/share/inkscape/extensions/inkex/utils.py", line 169, in <listcomp>
return [kind(val) for val in string.replace(',', ' ').split()]
ValueError: could not convert string to float: '0-497'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.