Center text on point?

Post questions on how to use or achieve an effect in Inkscape.
datumizer
Posts: 5
Joined: Tue Dec 29, 2015 11:27 am

Center text on point?

Postby datumizer » Sat Jul 14, 2018 6:37 pm

In my SVG file I have the following

Code: Select all

      <text
         x="-109.900896284470" y="167.621035971656"
         alignment-baseline="middle"
         text-anchor="middle"
         style="font-family:sans-serif;font-size:12pt;fill:#ff0000;">
         30°
      </text>


angles_isometric.svg
(2.25 KiB) Downloaded 161 times


In Google Chrome this works as intended. The text is centered on the x and y coordinates.

However, in Inkscape (and Gimp) the centering is incorrect. Is there a way to fix this in Inkscape?

Thanks.

Moini
Posts: 3381
Joined: Mon Oct 05, 2015 10:44 am

Re: Center text on point?

Postby Moini » Sat Jul 14, 2018 9:52 pm

Probably, there is. But you would need to ask for a fix on the bug tracker at https://bugs.launchpad.net/inkscape - please search to see if this has already been reported.
I can confirm there's a difference in rendering between web browsers and Inkscape (Linux Mint 18.3, with the stable 0.92.x and the master (development) branch).
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)

User avatar
Xav
Posts: 1209
Joined: Fri May 08, 2009 1:18 am
Location: UK
Contact:

Re: Center text on point?

Postby Xav » Sun Jul 15, 2018 5:58 pm

From a quick look at the file, I think it's Chrome that has the bug.

In your <svg> element is an xml:space="preserve" attribute. This means that white space in text content should be kept, rather than collapsed. Your text itself is then set on a line of its own, with tabs in front of it. So Inkscape is centring the whole string, including the tabs, making the visible text appear to move off centre.

You can confirm that the tabs (and some trailing white space) are present by repeatedly double-clicking on the text until you get a cursor, then using the arrow keys to move it beyond either end of the text. Pressing Ctrl-A in this mode will highlight the whole string, including the white space, so you can see its true extents.

One fix is to remove the attribute from the <svg> tag, but you might still get caught out with carriage returns and other characters that might not collapse as you expect. A better fix is to change the code from this:

Code: Select all

<text ...>
      120°
</text>


to this:

Code: Select all

<text ...>120°</text>
Co-creator of The Greys and Monsters, Inked - Inkscape drawn webcomics
Web SiteFacebookTwitter

datumizer
Posts: 5
Joined: Tue Dec 29, 2015 11:27 am

Re: Center text on point?

Postby datumizer » Mon Jul 16, 2018 7:02 am

Thanks! Removing the white space eliminates the horizontal alignment problem, but vertical alignment is still not correct.

But I found a way to export from Chrome, so the problem is moot.

User avatar
Xav
Posts: 1209
Joined: Fri May 08, 2009 1:18 am
Location: UK
Contact:

Re: Center text on point?

Postby Xav » Mon Jul 16, 2018 7:21 pm

I would guess that Inkscape doesn't support the alignment-baseline attribute. You might want to file a feature request for this, but it doesn't look like it's universally supported elsewhere either. For example, although Chrome supports it, Firefox doesn't - at least based on opening this page in both browsers:

https://developer.mozilla.org/en-US/doc ... t-baseline


One tip though - if you need help with alignment issues or similar problems in future, it would make things vastly simpler if your SVG file also includes some lines that cross where you expect the content to align to, otherwise it may not be immediately obvious to us what the problem actually is.
Co-creator of The Greys and Monsters, Inked - Inkscape drawn webcomics
Web SiteFacebookTwitter


Return to “Help with using Inkscape”