Storing pikchr src in the SVG metadata
(1) By Stephan Beal (stephan) on 2020-09-14 20:50:01 [source]
Uplifting my own threadjack from /forumpost/b8756503de...
In this branch:
https://pikchr.org/home/timeline?r=pikchr-src-in-metadata
each pik's original source script gets injected into the SVG metadata, where it's invisible to anyone unless they go looking for it. With that patch, the current fossil trunk will, in pikchrshow and /forum/forumpost, activate the ability to dynamically switch all pikchrs between svg form and their original script.
The only part of that patch i'm not happy about is that it currently unconditionally adds that source to the svg metadata, whereas it "should" expect a flag to be able to do so. We have the infrastructure for those flags (the branch adds Pik::mFlags
and assigns it the value pass in as the 3rd argument to pikchr()
), but what is missing is how to declare the flags such that they will become part of the visible API, such that fossil can pass that flag (or not, depending on the context) to pikchr()
?
There doesn't seem to be a way for me to tell lemon "add this to the generated pikchr.h
".
In essence, what we need is the equivalent of:
enum pikchr_flags {
PIKCHR_F_SRC_METADATA = 1,
...
};
or equivalent #define
s.
But... where to put that?
(2) By drh on 2020-09-14 22:08:19 in reply to 1 [link] [source]
Correct - there is no good way to generate a pikchr.h file at the moment. The pikchr.h file that does get generated does not contain any useful information. This is something I need to work on.
I'm happy for you to merge the other changes to trunk, in the meantime, if you like.
(3.1) By Stephan Beal (stephan) on 2020-09-15 06:00:42 edited from 3.0 in reply to 2 [link] [source]
I'm happy for you to merge the other changes to trunk, in the meantime, if you like.
The only change in that branch is the metadata addition and the flags which will ostensibly someday control whether that gets emitted. If you don't mind it always being emitted for the time being i'd be happy to merge it so that others can try it out and provide feedback on the usability.
Having the original pikchr script in the SVG is not fundamentally a problem, but i'd prefer that it be option simply because of the bloat it adds (and it likely won't interest anyone other than various fossil pages). If you don't mind it always being baked in for the time being, that's fine by me (we can make good use of it in fossil, anyway).
(4) By drh on 2020-09-15 11:27:34 in reply to 3.1 [link] [source]
The Pikchr-generated SVG is much smaller than the GUI-tool generated SVGs that it has replaced, so far. So I don't mind you adding the text in all cases, for now.
But here is a thought: What if there is a variable in Pikchr itself that turns this feature on and off? Currently you can do "debug=1" to get information about each graphic element as a comment in the output. Would it serve your purpose to include something like "source=1" as a special recipe that forces the source code to be present?
(5) By Stephan Beal (stephan) on 2020-09-15 13:01:53 in reply to 4 [link] [source]
Would it serve your purpose to include something like "source=1" as a special recipe that forces the source code to be present?
You mean a global, perhaps undocumented, int we'd just flip on from fossil? Don't see why not. i'll add that before merging it later on today.
(6) By drh on 2020-09-15 13:08:30 in reply to 5 [link] [source]
Thinking about this more, I'm not sure I like my own idea. I think a flag is better. I just need to fix up pikchr.h to include the interface.
(7) By Stephan Beal (stephan) on 2020-09-15 13:21:44 in reply to 6 [link] [source]
I just need to fix up pikchr.h to include the interface.
"What if" lemon could be told to output its .h
to a different name, a hypothetical:
./lemon pikchr.y -hpikchr_internal.h
so pikchr.h
could then become a public header?
(8) By Stephan Beal (stephan) on 2020-09-15 13:22:59 in reply to 6 [link] [source]
Or, for that matter, a compile-time flag would suit me. For fossil's own purposes we'll always, or almost always, want to enable the script (for all contexts where we want to enable the option to interactively see an SVGs sources, anyway).
(9.2) By drh on 2020-09-15 13:27:07 edited from 9.1 in reply to 6 [link] [source]
Alternative changes implemented and merged. Fossil checkin 041390d3f88afd48.
(10) By Stephan Beal (stephan) on 2020-09-15 13:28:56 in reply to 9.2 [link] [source]
i coincidentally hit refresh on the pikchr timeline within a few seconds of that update, and am already almost done with the integration. Thank you :).