mgieseki / dvisvgm

A fast DVI, EPS, and PDF to SVG converter
https://dvisvgm.de
GNU General Public License v3.0
295 stars 28 forks source link

Q: How is option `--embed-bitmaps` supposed to be used? #229

Open agrahn opened 1 year ago

agrahn commented 1 year ago

I tried PNG inclusion with the dvisvgm:img special and using the --embed-bitmaps option with dvisvgm, v. 3.0.2. The resulting image tag in the SVG output still contains an xlink:href=... link to the PNG instead physically embedding it as a data:image... blob. Am I missing something?

muzimuzhi commented 1 year ago

(Just some doc searching and reading, I don't have access to --embed-bitmaps because dvisvgm 3.0 is not available to macOS users and I'm not able to build it myself (yet).)

The manpage https://dvisvgm.de/Manpage/ says

This option only affects bitmaps referenced in DVI/XDV files, e.g. added by \includegraphics.

hence I go to the graphics driver file for dvisvgm (dvisvgm.def) and find in \Ginclude@bitmap, \special{dvisvgm:bbox ...} and \special{dvisvgm:raw ...} are used. https://github.com/latex3/graphics-def/blob/082eb8c28da564c622b08097fdd7e10658d46a31/dvisvgm.def#L162-L184

BTW in manpage there're missing -- before embed-bitmaps.

mgieseki commented 1 year ago

I probably should add more details to the manpage about this. At the moment, --embed-bitmaps only affects psfile and pdffile specials as created by \includegraphics is PS mode, for example. dvisvgm:img still creates file references, but I plan to extend the embed functionality so that it covers this special as well.

BTW in manpage there're missing -- before embed-bitmaps.

Thanks for the hint. I've fixed it.

agrahn commented 1 year ago

The manpage https://dvisvgm.de/Manpage/ says

This option only affects bitmaps referenced in DVI/XDV files, e.g. added by \includegraphics.

hence I go to the graphics driver file for dvisvgm (dvisvgm.def) and find in \Ginclude@bitmap, \special{dvisvgm:bbox ...} and \special{dvisvgm:raw ...} are used. https://github.com/latex3/graphics-def/blob/082eb8c28da564c622b08097fdd7e10658d46a31/dvisvgm.def#L162-L184

I know this, as I loosely co-maintain dvisvgm.def and which is the reason why I am asking. I finally want to replace the dvisvgm:raw special with the dedicated dvisvgm:img special. However, the current method allows me to easily "patch" the driver code at document level in order to physically embed bitmaps as data blobs. For example: https://tex.stackexchange.com/a/580847

mgieseki commented 2 months ago

I finally found some time to enhance the evaluation of dvisvgm:img so that it works similar to special psfile. The syntax is still the same but bitmaps can now optionally be embedded into the generated SVG files by using option --embed-bitmaps.

The previous implementation seemed a bit buggy because image position and bounding box didn't match. I fixed this as well. The lower left corner of the image is now placed at the current DVI position (if the current transformation matrix is the unity matrix), so that the image sits on the baseline. Also, the images and their bounding boxes are transformed according to the current matrix. I hope that these improvements make the special a bit more useful.

agrahn commented 2 months ago

I finally found some time to enhance the evaluation of dvisvgm:img so that it works similar to special psfile. The syntax is still the same but bitmaps can now optionally be embedded into the generated SVG files by using option --embed-bitmaps. .. Also, the images and their bounding boxes are transformed according to the current matrix. I hope that these improvements make the special a bit more useful.

This sounds very promising! Thank you! I will be testing this soon.