feature request: new special for accessing the <defs> part of the SVG file

Bug #1215878 reported by Till Tantau
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
dvisvgm
Fix Released
Medium
Martin Gieseking

Bug Description

Hi, another feature request entered as a bug report.

For the purposes of TikZ, it would be nice to have three new specials that give access to the <defs> part of the output SVG.

The background is that, for instance, a pattern or a filter is something that should be declared in the <defs> part of the output SVG. Things still work if they are declared right inside the main <g> of the document, but it would be nicer if a special gave access to the <defs> part.

Taking this a step further, what would be ideal are three specials like the following:

\special{dvisvgm:defstart name}
\special{dvisvgm:defend}
\special{dvisvgm:refdef name}

The idea is the following: Everything between the defstart and defend special should not be placed in the main svg stream; rather it should be put "on hold". Later, when the refdef special is encountered for the given name, the stuff that has been put on hold is inserted (once) into the <defs> of the current svg element. If the refdef is encountered a second time on the same page, nothing happens. If the refdef is later encountered on another page, the stuff is inserted once more into the <defs> of that other page.

This would allow one to write things like the following

...
\special{dvisvgm:defstart pattern1}
\special{dvisvgm:raw <pattern id="patternid1"> ... </pattern>}
\special{dvisvgm:defend}
 foobar
...
on page 3:
\special{dvisvgm:refdef pattern1} % ensure that the pattern is present in the defs section of page 3
\special{dvisvgm:raw <g pattern="url(\#patternid1)"> ... </g>}
yadda
\special{dvisvgm:refdef pattern1} % no effect, not inserted again.
\special{dvisvgm:raw <g pattern="url(\#patternid1)"> ... </g>}
...
on page 5:
\special{dvisvgm:refdef pattern1} % insert pattern code into the defs section of page 5
\special{dvisvgm:raw <g pattern="url(\#patternid1)"> ... </g>}
yadda yadda
\special{dvisvgm:refdef pattern1} % no effect, not inserted again on page 5
\special{dvisvgm:raw <g pattern="url(\#patternid1)"> ... </g>}

Revision history for this message
Martin Gieseking (martin-gieseking) wrote :

That shouldn't be too complicated to implement. However, it requires a prescan of all previous pages in order to collect all required definitions. I'll see what I can do without increasing the overall conversion speed too much.

Changed in dvisvgm:
importance: Undecided → Medium
assignee: nobody → Martin Gieseking (martin-gieseking)
Revision history for this message
Martin Gieseking (martin-gieseking) wrote :

s/increasing/reducing/

Revision history for this message
Martin Gieseking (martin-gieseking) wrote :

I'm just investigating the technical prerequisites for this feature to be considered during the upcoming code improvements. Would it be sufficient to record only the dvisvgm:raw specials present inside a defstart/defend block for later usage? If yes, that's easy to implement. It would be much more complicated to consider everything wrapped by "defstart" and "defend" because that would require the management of temporary SVG trees.

Changed in dvisvgm:
status: New → In Progress
Changed in dvisvgm:
status: In Progress → Fix Committed
Changed in dvisvgm:
milestone: none → 1.7
Changed in dvisvgm:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.