GithubHelp home page GithubHelp logo

Exporting as SVGs about calico-icon HOT 8 CLOSED

enigma-dev avatar enigma-dev commented on July 24, 2024
Exporting as SVGs

from calico-icon.

Comments (8)

JoshDreamland avatar JoshDreamland commented on July 24, 2024

InkScape's exporter has always been pretty buggy. There's not much you or I can do about that. You can use an XML parser to extract just the defs and the group containing the icon you want, then reset the transform on that group so it renders correctly. From there, you may even be able to use InkScape's command line to minify the defs section.

I recommend this regardless, because I will be genuinely surprised if InkScape can actually accomplish what you're trying to do, even once that patch ships. You may want to figure out if it's preserving needed defs, and file a bug now if it's not. InkScape has the ability to copy defs dependencies from document to document, but it would actually surprise me if they were invoking those routines correctly during export.

from calico-icon.

RobertBColton avatar RobertBColton commented on July 24, 2024

Thanks, it's actually not, I did notice that myself this morning. It's copying in a TON of unneeded gradients that aren't even used by ICON_SPRITE when exporting only that ID. It's copying about 15,000 lines of unneeded gradients. So when I say a ton, I mean a TON.

Anyway, yeah, we can get what we want with Inkscape's exporter and just transform the output. But I think it will need to be run twice, once to export, and then a second time to minify. Is there an XML parser for bash? Maybe I should just write this in JS actually.

EDIT

To quote man pages:

-l, --export-plain-svg=FILENAME

Export document(s) to plain SVG format, without sodipodi: or inkscape: namespaces and without RDF > metadata.

So yeah it does not minify the defs.

Edit 2

Here's what I may have been missing:

-I, --query-id

Set the ID of the object whose dimensions are queried. If not set, query options will return the dimensions of the drawing (i.e. all document objects), not the page or viewbox
-X, --query-x

Query the X coordinate of the drawing or, if specified, of the object with --query-id. The returned value is in px (SVG user units).

Edit 3

Sigh.... even better:

$ inkscape "icons.svg" --export-id="ICON_SPRITE" --query-id="ICON_SPRITE" --export-id-only --export-plain-svg="sprite.svg"
Segmentation fault

And also:

$ inkscape "icons.svg" --export-id="Icon_Sprite" --query-id="Icon_Sprite" --export-id-only --export-plain-svg="sprite.svg"

** (inkscape.exe:4228): CRITICAL **: void SPObject::requestModified(unsigned int): assertion 'this->document != NULL' failed

I upgraded to 0.92.1 stable too.

from calico-icon.

JoshDreamland avatar JoshDreamland commented on July 24, 2024

Okay; this seems really easy to file an InkScape bug against. InkScape preserving all 15K lines of defs is intended behavior if you aren't using --export-id. If you were using --export-id, and it did not vacuum the defs, just file a bug. Post the bug number here for reference if you do.

The segfault probably warrants a bug regardless. Even if our IDs are somehow ill-formed, InkScape should detect that and report on it rather than exploding.

from calico-icon.

RobertBColton avatar RobertBColton commented on July 24, 2024

Yeah it's just spitting it out over and over again. Somehow one of those methods must have worked because it did output the file again now, and here's what we have as part of it:

  <g
     transform="translate(-2.5,-295.5)"
     id="Layer_Icons">
    <g
       transform="translate(0,18)"
       height="18"
       width="18"
       id="Icon_Sprite">
      <path
         d="M 15.467672,13.158811 A 7,7 0 0 1 7.5708683,16.228926 7,7 0 0 1 2.5002474,9.4411493 7,7 0 0 1 7.6842805,2.7395886 7,7 0 0 1 15.528347,5.9420465 L 9.5,9.5 Z"
         style="fill-opacity:1;fill-rule:evenodd"
         id="pac_body" />
      <ellipse
         ry="2"
         rx="1.5"
         cy="6"
         cx="9.5"
         id="pac_eye" />
      <ellipse
         ry="1"
         rx="0.5"
         cy="6.5"
         cx="10"
         id="pac_pupil" />
    </g>
  </g>

You can see it's not extracting the Icon_Sprite from the parent group layer, which we want. But that's good because it would be very easy for us to use an XML parser to transform that away ourselves as a quick workaround.

from calico-icon.

JoshDreamland avatar JoshDreamland commented on July 24, 2024

I'm not sure what's up with the transform on the outer layer... I tried to avoid having a transform at the layer level for this reason. Does it render properly this way? What is the size of the document?

from calico-icon.

RobertBColton avatar RobertBColton commented on July 24, 2024

Sorry my G710 replacement just got here, I hadn't noticed how much my LEDs faded over 2 years time. This is what I was trying to explain that it was doing. It exports an 18x18 canvas that's blank and the sprite icon is about -295.5 above this canvas. So that's why before I thought it wasn't exporting anything at all. I just randomly had the idea to zoom out and then I finally noticed what was going on.

from calico-icon.

RobertBColton avatar RobertBColton commented on July 24, 2024

This is what --query-all gives me:

Layer_Icons,-8.8817842e-016,-275,13.028347,14
Icon_Sprite,-8.8817842e-016,-275,13.028347,14
pac_body,-8.8817842e-016,-275,13.028347,14
pac_eye,5.5,-273.5,3,4
pac_pupil,7,-272,1,2

Also, I found how to minify the defs:

--vacuum-defs

Remove all unused items from the defs section of the SVG file. If this option is invoked in conjunction with --export-plain-svg, only the exported file will be affected. If it is used alone, the specified file will be modified in place.

Pretty sure it's broke actually:

Owner@Bedroom-Desktop MINGW64 ~/Desktop/Projects/Calico-Icon (master)
$ inkscape "icons.svg" --select "Layer_Icons" --verb SelectionUnGroup --vacuum-defs --export-id="Icon_Sprite" --export-id-only --export-plain-svg="sprite.svg"  Segmentation fault

Owner@Bedroom-Desktop MINGW64 ~/Desktop/Projects/Calico-Icon (master)
$ inkscape "icons.svg" --select="Layer_Icons" --verb=SelectionUnGroup --vacuum-defs --export-id="Icon_Sprite" --export-id-only --export-plain-svg="sprite.svg"
Segmentation fault

Owner@Bedroom-Desktop MINGW64 ~/Desktop/Projects/Calico-Icon (master)
$ inkscape "icons.svg" --select="Layer_Icons" --verb="SelectionUnGroup" --vacuum-defs --export-id="Icon_Sprite" --export-id-only --export-plain-svg="sprite.svg"
Segmentation fault

Edit

I tried the following extension too:
https://graphicdesign.stackexchange.com/a/74455

It semi-works and actually gets rid of the unused defs leaving very small icon files but it still has the translate problem and also kind of mangles the output a bit. "Fit page to object" also seems to cause it to just hang.

Edit 2

Ok so just to mention, reverting my PR btw exacerbates the translating problem too. So that pull request was still useful anyway.

Edit 3

It looks like people want this to happen but it just hasn't happened:
https://bugs.launchpad.net/inkscape/+bug/1530380

from calico-icon.

RobertBColton avatar RobertBColton commented on July 24, 2024

Alright, here's the closest I got so far, removing the parent group layer and or adding the following attributes to the root SVG element:

width="18"
height="18"
preserveAspectRatio="xMinYMin slice"
viewBox="0 0 18 18">

But we still end up with a small translate, the defs are not minified, and the width and height on the exported root SVG element is too small:

  <g
     transform="translate(-2.5,16.5)"
     height="18"
     width="18"
     id="Icon_Sprite">
    <path
       d="M 15.467672,13.158811 A 7,7 0 0 1 7.5708683,16.228926 7,7 0 0 1 2.5002474,9.4411493 7,7 0 0 1 7.6842805,2.7395886 7,7 0 0 1 15.528347,5.9420465 L 9.5,9.5 Z"
       style="fill-opacity:1;fill-rule:evenodd"
       id="pac_body" />
    <ellipse
       ry="2"
       rx="1.5"
       cy="6"
       cx="9.5"
       id="pac_eye" />
    <ellipse
       ry="1"
       rx="0.5"
       cy="6.5"
       cx="10"
       id="pac_pupil" />
  </g>

Something is definitely bugged because even removing all transforms and defs from the original and then exporting it still adds a translation for some reason. See the following bugs I've reported:
https://bugs.launchpad.net/inkscape/+bug/1707368
https://bugs.launchpad.net/inkscape/+bug/1707365
https://bugs.launchpad.net/inkscape/+bug/1707371
https://bugs.launchpad.net/inkscape/+bug/1707373

What should we do, in addition to filing bugs? Why does it always feel like the things I want are impossible?

from calico-icon.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.