Re: Clipped svg output
luigi scarso <[email protected]> Thu, 19 Jan 2023 09:15:32 +0100
| Newsgroups | gmane.comp.tex.metapost |
|---|---|
| Message-ID | <CAG5iGsA5pxU6KUYBqSS39b+Tf-eNYS352PnVNEg1Z5e_8j8nNw@mail.gmail.com> |
On Wed, 18 Jan 2023 at 13:04, luigi scarso <[email protected]> wrote: > > > On Wed, 18 Jan 2023 at 12:53, Lutz Haseloff <[email protected]> > wrote: > >> Hi Luigi, >> >> I tested a bit further. >> >> MP: >> >> outputformat := "svg"; >> outputtemplate := "%j-%c.%{outputformat}"; >> beginfig(19) >> fill fullcircle scaled 19 withcolor red ; >> endfig; >> end >> >> SVG: >> >> <?xml version="1.0"?> >> <!-- Created by MetaPost 2.02 on 2023.01.18:1229 --> >> <svg version="1.1" xmlns="http://www.w3.org/2000/svg" >> <http://www.w3.org/2000/svg> xmlns:xlink="http://www.w3.org/1999/xlink" >> <http://www.w3.org/1999/xlink> width="19.000000" height="19.000000" >> viewBox="0 0 19.000000 19.000000"> >> <!-- Original BoundingBox: -9.500000 -9.500000 9.500000 9.500000 --> >> <path d="M18.500000 9.000000 (should be 19.0 9.5) ... 11.519557 >> -0.500000 (should be 0) ... -0.500000 9.000000 (should be 0) ... ,18.500000 >> 9.000000Z" style="fill: rgb(100.000000%,0.000000%,0.000000%);stroke: >> none;"></path> >> </svg> >> >> It seems, that the path d is not correctly transformed from the ps hires >> boundingbox (-9.5 -9.5 9.5 9.5) to the svg viewbox (0 0 19 19). >> >> With even sizes ( say 20) it works ok. >> >> >> > indeed, I was looking at it ... this evening can check it better > > -- > luigi > > > looking at this now, maybe the integer dx and dy are not ok. @ We often need to print a pair of coordinates. Because of bugs in svg rendering software, it is necessary to change the point coordinates so that there are all in the "positive" quadrant of the SVG field. This means an shift and a vertical flip. The two correction values are calculated by the function that writes the initial |<svg>| tag, and are stored in two globals: @<Globals@>= integer dx; integer dy; @ @c void mp_svg_pair_out (MP mp,double x, double y) { mp_svg_store_double(mp, (x+mp->svg->dx)); append_char(' '); mp_svg_store_double(mp, (-(y+mp->svg->dy))); } If I use double, i.e. @<Globals@>= double dx; double dy; I have now <?xml version="1.0"?> <!-- Created by MetaPost 2.02 on 2023.01.19:0912 --> <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink=" http://www.w3.org/1999/xlink" width="19.000000" height="19.000000" viewBox="0 0 19.000000 19.000000"> <!-- Original BoundingBox: -9.500000 -9.500000 9.500000 9.500000 --> <path d="M19.000000 9.500000C19.000000 6.980331,17.998917 4.564163,16.217377 2.782623C14.435837 1.001083,12.019669 -0.000000,9.500000 -0.000000C6.980331 -0.000000,4.564163 1.001083,2.782623 2.782623C1.001083 4.564163,0.000000 6.980331,0.000000 9.500000C0.000000 12.019669,1.001083 14.435837,2.782623 16.217377C4.564163 17.998917,6.980331 19.000000,9.500000 19.000000C12.019669 19.000000,14.435837 17.998917,16.217377 16.217377C17.998917 14.435837,19.000000 12.019669,19.000000 9.500000Z" style="fill: rgb(100.000000%,0.000000%,0.000000%);stroke: none;"></path> </svg> -- luigi -- http://tug.org/metapost/