weisJ/jsvg

px to mm conversion doesn't match CEF/Batik

Closed this issue · 3 comments

SVG:

      <?xml version="1.0" encoding="UTF-8" standalone="no"?>
      <!-- Created with Inkscape (http://www.inkscape.org/) -->
      
      <svg
              width="4.7624998mm"
              height="3.6064999mm"
              viewBox="0 0 4.7624998 3.6064999"
              version="1.1"
              id="svg5"
              xml:space="preserve"
              xmlns="http://www.w3.org/2000/svg"
      ><defs
           id="defs2" /><path
           id="path1699"
           style="display:inline;fill:#ed4646;fill-opacity:1;stroke-width:0.571737;stroke-linecap:round;stroke-linejoin:round"
           d="M 2.38125,0 A 2.3812459,2.3812459 0 0 0 0,2.38125 2.3812459,2.3812459 0 0 0 0.33848,3.6034 L 0.79065,3.329 A 1.8520975,1.8520975 0 0 1 0.52917,2.38125 1.8520975,1.8520975 0 0 1 2.38125,0.52917 1.8520975,1.8520975 0 0 1 3.48816,0.89814 L 4.06849,0.70177 A 2.3812459,2.3812459 0 0 0 2.38125,0 Z m 2.30581,1.0666 c 0,0 -2.32679,0.73226 -2.55592,0.86455 C 1.902,2.06344 1.81263,2.43807 1.93735,2.6541 2.06208,2.87013 2.43117,2.98019 2.66031,2.84789 2.88945,2.7156 4.68706,1.0666 4.68706,1.0666 Z M 4.66996,1.73064 4.21521,2.1301 A 1.8520975,1.8520975 0 0 1 4.23331,2.38125 1.8520975,1.8520975 0 0 1 3.96924,3.33416 L 4.42296,3.6065 A 2.3812459,2.3812459 0 0 0 4.76247,2.38125 2.3812459,2.3812459 0 0 0 4.66997,1.73064 Z" /></svg>
    

In jsvg, one mm == 0.1f * inchesPerCm + pixelsPerInch * value; (0.1f * .3936f + 96f * value): https://github.com/weisJ/jsvg/blob/ebb6773734cf105715e93d40f7da8d4e2afc069a/jsvg/src/main/java/com/github/weisj/jsvg/geometry/size/Length.java#L69-L70C31
In Apache Batik implementation and cef, 1mm ≅ 3.7795px.

My quick fix — develar@d732568#diff-e0cf72e3e25b79b9f4da2121974303309d1e53bde3b862c2c0d989d0838c0a60R70

0.1*0.3936*96 = 3.77856

So the fix is to fix a typo in +.

weisJ commented

Just leaving this here for reference. The SVG spec refers to the CSS Units Level 3 spec for how units are to be resolved:

https://www.w3.org/TR/css-values-3/#absolute-lengths

I will adjust to use those values instead. Won’t be able to work on it until next week though.

weisJ commented

Fixed in a4ceb15