1

is there a way to "tell" Inkscape to apply x/y coordinates on elements (clones of a symbol) instead of transform() when positioning?

The known trick with ungrouping/regrouping cannot be applied here since there's no group on the element.

background: transforms() statements bloats up final file size unnecessarily.

Thanks for input.

5
  • 1
    It cannot be a clone of symbol then. As it is saying its the same as this but here. The transform is the "but here" part and it cannot be in two places without this. Obviously if its nolonger a clone then no problem. So are you in fact asking how to make a symbol not a symbol? I'd think that would bloat things even more but ymmv.
    – joojaa
    Oct 6, 2022 at 4:34
  • @joojaa In SVG <use>-elements can also have x and y attributes to set the position, on top of the transform attribute. Inkscape seems to only use the latter, while this question is about using the former.
    – Xrott
    Oct 6, 2022 at 7:52
  • @joojaa in the context of Inkscape i understood the "clone" in the sense, that it looks the same Oct 6, 2022 at 13:04
  • 1
    @JanViehweger it wouldnt be inside a use element if it was a true full data copy.
    – joojaa
    Oct 6, 2022 at 15:10
  • @Xrott Right, good point, its still just a transform that is limitted in how it can manipulate the matrix. To be honest though how much exactly does it impact the size of a zipped svg really. youd think that the compression would pick up on this repetitive pattern. Seems like premature optimisation to me. If one really cared then why not use a binary format.
    – joojaa
    Oct 6, 2022 at 15:14

1 Answer 1

0

For most objects, you can set the 'Store transformation' setting in the preferences under 'Behavior → Transforms' to 'Optimized' to make Inkscape manipulate them directly instead of adding transform attributes whenever possible. There is also the 'Apply Transforms' extension to remove already existing transforms while keeping the object at the current position.

As for <use>-elements however, it seems like the developers have decided to always use transforms on clones instead of using their x and y attributes (at least I have never seen them set to anything other than '0' by Inkscape). You'll have to manually set these values with the 'Edit → XML-Editor...' afterwards (the 'Apply Transforms' extension doesn't seem to work well with clones either).

It probably wouldn't be that hard to write a script to do this automatically, though. Especially if the transforms only have translate() inside.

5
  • Thanks @Xrott, i've tried this setting already without success. I fear that the "Apply transform extension" won't work on version 1.2 and 0.9x version of inkscape doesn't run on macos 11.x. So writing a script could be an option. But then i think the better place for that would be a plugin for a svg optimizer like SVGO (github.com/svg/svgo) if there isn't one already? I just found the 'convertTransform' plugin there , but it seems not addressing my problem github.com/svg/svgo/blob/main/plugins/… Oct 6, 2022 at 13:19
  • 1
    A script/optimizer plugin could only cover the case of translate-only transformations. Everything else will give unintended results as soon as the referenced element is a <symbol> with a viewBox attribute.
    – ccprog
    Oct 7, 2022 at 14:31
  • 1
    @ccprog As per the spec, the x and y attributes simply act like an additional translate(x, y) "appended to the end (i.e., right-side) of the 'transform' attribute on the generated 'g'" when referencing a <symbol>, so in practice, I don't think the viewBox should be a problem. The transform matrix(0.5,0,0,0.5,5,10) can easily be converted to x="10" y="20" transform="scale(0.5)". See how the two circles perfectly overlap in this example.
    – Xrott
    Oct 7, 2022 at 17:22
  • 1
    @Xrott That is exactly what I meant. You have to seperate out the translation from the matrix, but the transform attribute must remain to apply the remaining 2x2 matrix. For example, trying to apply scale(1, 2) to the width and height attributes to get rid of it will fail unless preserveAspectRatio="none" was set.
    – ccprog
    Oct 7, 2022 at 17:58
  • 1
    @ccprog Ah, I see now what you mean. No, it can't eliminate the transform attribute entirely, but I think there is still value in extracting the offset and setting them as the x and y, because it makes it much easier to read and edit in a text-editor. Also in some circumstances it still might be shorter.
    – Xrott
    Oct 7, 2022 at 18:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.