Wanted: some very tight SVG, brutally short and efficient, from PostScript.=
It can be done by Distilling to PDF, and then using the likes of www.cloud= convert.com/pdf-to-svg to change that to SVG.
The natural way to proceed is to go back to native PostScript. Perhaps as follows: [...]
I first produced PDF output, and then used a program called "pdf2svg", although better might be making a SVG output driver for Ghostscript. (I
think there might be one but doesn't fully work, or something like that.
I don't know if it supports pdfmarks, or what device parameters it has.)
In article <1593895164.bystand@zzo38computer.org>, news@zzo38computer.org.invalid says...
I first produced PDF output, and then used a program called "pdf2svg", although better might be making a SVG output driver for Ghostscript. (I think there might be one but doesn't fully work, or something like that.
There *was* an SVG output device and at one time an SVG interpreter,
both were declared defunct and removed from the source tree on the 9th
March 2014.
Essentially the problem was that fonts are not well supported in SVG and
many SVG consumers (at least back then) didn't really support fonts in
SVG at all.
I expect the device still works so you could probably get the source for Ghostscript 9.10, take the gdevsvg.c file from ghostpdl/devices/vector,
and then modify the makefile of the current code to build and include
the device.
The pdfmark PostScript operator is only supported by the pdfwrite
device.
OK, the SVG output device is discussed below, but the SVG interpreter,I
did also think of the possibility to write a SVG reader in PostScript, if there is a XML parser in PostScript.
(I also don't like how the "run" operator reads PDF and EPS files as well
as PostScript programs; I would think that it would be better to have a separate operator, perhaps called "rundoc", to do such thing (it would
still interpret it as a normal PostScript file if it is not recognized as
PDF or EPS, though). I think a EPS file is a PostScript program, anyways.
An alternative would be for the PostScript only run operator to be called ".run" and to leave "run" like it is; if you use -dWRITESYSTEMDICT then
you can write "/run /.run load def" if you want to disable PDF.)
Essentially the problem was that fonts are not well supported in SVG and many SVG consumers (at least back then) didn't really support fonts in
SVG at all.
You could have the option to output text as paths, perhaps (either for
some fonts or for all fonts, I suppose).
The pdfmark PostScript operator is only supported by the pdfwrite
device.
While that may be the only included device which does, it would seem that
it is implemented as a device parameter, so it is possible to implement
other drivers that do that by checking for the /pdfmark device parameter.
(A test I have made seems to confirm that.)
Also, I think I read the DjVu output driver supports some pdfmarks too.
Wanted: some very tight SVG, brutally short and efficient, from PostScript.
I first produced PDF output, and then used a program called "pdf2svg",
There *was* an SVG output device and at one time an SVG interpreter,
both were declared defunct and removed from the source tree on the 9th
March 2014.
Essentially the problem was that fonts are not well supported in SVG and many SVG consumers (at least back then) didn't really support fonts in
SVG at all.
OK, the SVG output device is discussed below, but the SVG interpreter, I
did also think of the possibility to write a SVG reader in PostScript, if there is a XML parser in PostScript.
Otherwise, if you better like the C language, I put a small PostScript to
SVG converter in abcm2ps (svg.c). But it does not handle 'dict'.
Wanted: some very tight SVG, brutally short and efficient, from PostScript. It can be done by Distilling to PDF, and then using the likes of www.cloudconvert.com/pdf-to-svg to change that to SVG.setgray, and maybe others. What these do is: their usual; store state data to a data object; sometimes grow an SVG text string.
It’s not bad. But it could be much tighter. E.g., via PDF changes arcs to Bézier, and so the SVG isn’t as tight as it could be. Going direct from PS also does this, so it might be internally transforming via PDF.
The natural way to proceed is to go back to native PostScript. Perhaps as follows:
• SvgCommandsDict begin
Necessary. Obviously an ‘end’ later ends.
• width height SvgSetViewBox
Sets bounding box.
• matrix SvgSetMatrix
All SVG commands will be output in this space. If currentmatrix element-wise-equals this, no transformations will be done. If not, points will be reverse transformed back to this.
• filename SvgFinish
Output accumulated SVG to named file.
SvgCommandsDict needs redefinitions of moveto, lineto, rlineto, curveto, rcurveto, closepath, arc, arcn, arct, arcto, clip, clipsave, cliprestore, gsave, grestore, fill, stroke, setlinewidth, setlinejoin, setlinecap, setdash, stroke, setrgbcolor,
Text is harder: are fonts set with the PS, or inherited from the CSS? But my diagrams have no text, so that isn’t needed here.
Have readers ever implemented SVG in raw PostScript? Have you working code, or advice?
On Saturday, July 4, 2020 at 7:53:21 AM UTC-5, jdaw1 wrote:setgray, and maybe others. What these do is: their usual; store state data to a data object; sometimes grow an SVG text string.
Wanted: some very tight SVG, brutally short and efficient, from PostScript. It can be done by Distilling to PDF, and then using the likes of www.cloudconvert.com/pdf-to-svg to change that to SVG.
It’s not bad. But it could be much tighter. E.g., via PDF changes arcs to Bézier, and so the SVG isn’t as tight as it could be. Going direct from PS also does this, so it might be internally transforming via PDF.
The natural way to proceed is to go back to native PostScript. Perhaps as follows:
• SvgCommandsDict begin
Necessary. Obviously an ‘end’ later ends.
• width height SvgSetViewBox
Sets bounding box.
• matrix SvgSetMatrix
All SVG commands will be output in this space. If currentmatrix element-wise-equals this, no transformations will be done. If not, points will be reverse transformed back to this.
• filename SvgFinish
Output accumulated SVG to named file.
SvgCommandsDict needs redefinitions of moveto, lineto, rlineto, curveto, rcurveto, closepath, arc, arcn, arct, arcto, clip, clipsave, cliprestore, gsave, grestore, fill, stroke, setlinewidth, setlinejoin, setlinecap, setdash, stroke, setrgbcolor,
Text is harder: are fonts set with the PS, or inherited from the CSS? But my diagrams have no text, so that isn’t needed here.
Have readers ever implemented SVG in raw PostScript? Have you working code, or advice?I posted an early draft of a pdf writer in PostScript that could probably
be modified to produce SVG. Not needing a xref table means a lot of the
code could disappear in the rewrite.
Capturing arcs as arcs is trickier tho. Yeah you can capture the call,
but then you'd have to take over a lot more operators and manage the
path. Not impossible -- You could store it easily enough. If a path is
an array of subpaths, a subpath is an array of elements, and an element
is a 2-element array (moveto or lineto) or a 6-element array (curveto)
then you could use a 5-element array for an arc. So arcs might be
"the other 90%" of the work.
https://stackoverflow.com/q/48535765/733077
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 296 |
Nodes: | 16 (2 / 14) |
Uptime: | 84:00:00 |
Calls: | 6,658 |
Calls today: | 4 |
Files: | 12,203 |
Messages: | 5,333,599 |
Posted today: | 1 |