Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should we replace inkscape with rsvg-convert? #654

Open
tomschr opened this issue Oct 10, 2021 · 6 comments
Open

Should we replace inkscape with rsvg-convert? #654

tomschr opened this issue Oct 10, 2021 · 6 comments

Comments

@tomschr
Copy link
Collaborator

tomschr commented Oct 10, 2021

Problem description

Some time ago we had some issues with Inkscape:

  • Dependencies: drags other packages into the daps installation, like Tex (although this seems to be solved now)
  • Changes: Command line changed from 0.9 to 1.0
  • Size: huge(?) package

It seems we could replaces Inkscape with a more light-weight tool.

Idea

I got informed that Fedora had some problems with Inkscape too (see [1]). This was mainly for the dblatex tool, but it should be correct for daps as well. Originally, the bug was filed in [2], but it seems the Inkscape won't fix it. Fedora created a patch[3] because of this which basically replaces inkscape with rsvg-convert.

We need to check if:

  • technically feasible
  • has no side effects
  • supports most of the SVG tags (or we should be aware about convertion problems)

References

  1. https://sourceforge.net/p/dblatex/feature-requests/21/
  2. https://gitlab.com/inkscape/inkscape/-/issues/1342
  3. https://src.fedoraproject.org/rpms/dblatex/raw/rawhide/f/dblatex-0.3.11-replace-inkscape-by-rsvg.patch
  4. https://build.opensuse.org/request/show/921890
@ghost
Copy link

ghost commented Oct 11, 2021

Using rsvg instead of Inkscape will bring rather predictable conversion issues, especially (but not limited to) when graphics have been originally created with Inkscape, e.g. when they use the flowRoot text element.

You are right that Inkscape is huge and drags in a lot more dependencies than we want though.

@tomschr
Copy link
Collaborator Author

tomschr commented Oct 12, 2021

We've discussed this topic during our sync call. Probably we will have issues with the svg:flowRoot tag which is likely to be unsupported by rsvg-convert.

I've tried to create a test but was unable to find a svg:flowRoot tag in my SVG with Inkscape 1.0.2. Digging a bit deeper, I found this:

»The SVG 1.2 Full specification was never completed (as you can see from the link it's still in draft from 2005) and only Inkscape ever supported flowRoot I think. I don't think it's intended that flowRoot will be part of SVG 2 either as that is likely to implement flowing text with a different and more CSS compatible mechanism so flowRoot is best avoided.«
Source: https://stackoverflow.com/a/19391378

which seem to explain why it doesn't appear anymore. I can also save my SVG in Inkscape as version 1.1, not as 1.2. I'm pretty sure this flowRoot was available in the pre 1.0 version.

I've also looked into our images/srv/svg and haven't found any occurances of flowRoot (as it was to be expected). Sooo... to make a long story short, maybe this flowRoot isn't a big deal anymore. For SVG images which are created by other tools, you can convert the flow text into some static presentation (use main menu "Text > Unflow" or "Text > Convert to Text").

However, we may still have other conversion issues when using rsvg-convert. To clarify which elements and attributes are actually supported, I've created issue 801 in the upstream project. Let's see if they find it useful.

Maybe we need to compare if there are any differences between the Inkscape generated PNGs and the rsvg-convert generated ones. After then we can decide if this is going to fly or not.

@tomschr
Copy link
Collaborator Author

tomschr commented Oct 12, 2021

I've investigated a little bit further and wrote a small (dirty) Shell script that you can run on any cloned repo. It a) converts each SVG to PNG with rsvg-convert and inkscape and b) compares the result of the two PNGs with compare (ImageMagick).

Shell script to convert and compare SVGs
#!/bin/bash

BASEDIR=/tmp/svgcompare
LIBRSVG=$BASEDIR/librsvg
INKSCAPE=$BASEDIR/inkscape
DIFFS=$BASEDIR/diffs

mkdir -p $LIBRSVG $INKSCAPE $DIFFS

for i in images/src/svg/*.svg; do
  base=${i##*/}
  base=${base%%.svg}
  format=png
  echo "## Converting $i..."
  rsvg-convert --format=$format --width=800 --height=600 \
               --background-color=white $i > $LIBRSVG/$base.$format
  inkscape --export-type=$format \
           --export-width=800 --export-height=600 \
           --export-background=white \
           -o $INKSCAPE/$base.$format \
           $i
  echo "## Calculating difference for $i..."
  # from https://askubuntu.com/a/209548 using Imagemagick
  compare -compose src $INKSCAPE/$base.$format \
          $LIBRSVG/$base.$format \
          $DIFFS/$base.$format
done

My findings so far:

  • From 36 SVGs (SLE repo, main branch) 8 had no differences
  • Most differences come from font issues, mainly word or letter spacing
  • Most look quite similar, but two look horribly wrong

@ghost
Copy link

ghost commented Oct 12, 2021

(use main menu "Text > Unflow"

Aah, good to know! I never knew this tool existed!

In the past, Inkscape created flowRoots when dragging open a bounding box first rather than just clicking and then typing. However, I just tried it on Inkscape 1.0.1 (the version that ships in Leap 15.3) and, you're right, it does not create flowRoots in either case! Progress! Awesome.

@tomschr
Copy link
Collaborator Author

tomschr commented Oct 13, 2021

After some further tests, the xmlgraphics-batik-rasterizer script makes the best output from what I can see. It's based on Batik, a SVG library which supports a lot of features.

If we really want to move away from Inkscape, it could be an alternative. However, it's Java, so it's not as fast as Inkscape or rsvg-convert. 😞

@ghost
Copy link

ghost commented Oct 13, 2021

However, we probably already need the Batik rasterizer because we use FOP. So, speed and java-ness aside, if Batik is a good implementation of SVG and runs reliably, then using that as broadly as possible sounds like a good idea. (edit We have our troubles with FOP... and switching away from FOP has been on my mind more than once. That might play into this decision too.)

I just checked how the Dia pipeline works and it seems that is already independent from Inkscape -- DAPS currently allows DIA->PNG and DIA->SVG but both only use the dia command, e.g.

DIA->PNG -- make/images.mk:448:

	LANG=C dia -t png --export=$@ $< $(DEVNULL) $(ERR_DEVNULL)

Analogously on l. 520 for DIA->SVG.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant