Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVG Text Anchor position for Inkscape PDF-TeX export #9

Open
dshemnv opened this issue Sep 27, 2023 · 1 comment
Open

SVG Text Anchor position for Inkscape PDF-TeX export #9

dshemnv opened this issue Sep 27, 2023 · 1 comment

Comments

@dshemnv
Copy link

dshemnv commented Sep 27, 2023

Hi !

I really appreciate this project as it is way simpler to customize the appearance of the diagrams. However, I noticed that on the exported SVG files, the anchor for text boxes is positioned in the middle. This is a problem since when converting the SVG to a PDF file with LaTeX text using Inkscape, the obtained text is positioned higher than it should be.

Here is an example of what I mean:
SVG file
image

Produced LaTeX PDF with Inkscape export
image

It would be awesome if the text anchor was by default as it is in Inkscape, enabling fast integration of the diagrams in LaTeX documents.

Seems like the property that is in charge of this is: dominant-baseline="middle"

Here is the SVG code for the example SVG file used above

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->

<svg
   width="210mm"
   height="297mm"
   viewBox="0 0 210 297"
   version="1.1"
   id="svg1"
   inkscape:version="1.3 (0e150ed6c4, 2023-07-21)"
   sodipodi:docname="testing.svg"
   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:svg="http://www.w3.org/2000/svg">
  <sodipodi:namedview
     id="namedview1"
     pagecolor="#ffffff"
     bordercolor="#000000"
     borderopacity="0.25"
     inkscape:showpageshadow="2"
     inkscape:pageopacity="0.0"
     inkscape:pagecheckerboard="0"
     inkscape:deskcolor="#d1d1d1"
     inkscape:document-units="mm"
     inkscape:zoom="4.1725703"
     inkscape:cx="394.72073"
     inkscape:cy="419.64542"
     inkscape:window-width="1920"
     inkscape:window-height="1164"
     inkscape:window-x="0"
     inkscape:window-y="36"
     inkscape:window-maximized="1"
     inkscape:current-layer="layer1"
     showguides="true">
    <sodipodi:guide
       position="118.59244,201.21439"
       orientation="0,-1"
       id="guide1"
       inkscape:locked="false" />
  </sodipodi:namedview>
  <defs
     id="defs1" />
  <g
     inkscape:label="Calque 1"
     inkscape:groupmode="layer"
     id="layer1">
    <rect
       style="fill:#e8d5c4;stroke-width:0.352777;stroke-linecap:square;stroke-linejoin:round"
       id="rect1"
       width="56.30822"
       height="5.9605546"
       x="76.845886"
       y="92.805336" />
    <text
       text-anchor="middle"
       dominant-baseline="middle"
       font-family="Helvetica"
       font-size="3.70417px"
       fill="#000000"
       letter-spacing="0"
       id="text55"
       x="110.42086"
       y="94.868874"
       style="text-align:center;text-anchor:middle;white-space:pre;inline-size:30.1773;stroke-width:0.264583"
       transform="translate(8.1011636,0.90747783)"
       xml:space="preserve"><tspan
         x="110.42086"
         y="94.868874"
         id="tspan2">Bad anchor pos</tspan></text>
    <text
       xml:space="preserve"
       style="font-size:3.88056px;line-height:normal;font-family:Carlito;-inkscape-font-specification:Carlito;text-align:center;text-decoration-color:#000000;text-anchor:middle;fill:#000000;stroke-width:1.05833;-inkscape-stroke:none;stop-color:#000000"
       x="91.673836"
       y="96.820175"
       id="text111"><tspan
         sodipodi:role="line"
         id="tspan111"
         x="91.673836"
         y="96.820175"
         style="stroke-width:1.05833">Good anchor pos</tspan></text>
  </g>
</svg>
@coastalwhite
Copy link
Owner

Thank you for the issue.

This dominant-baseline="middle" is very probably indeed the offender here. In this case the fix would be rather easy. We already have the pixel height of the text. Just replace the dominant-baseline=middle with a offset on the y coordinate.

I will see what I can do to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants