Page MenuHomePhabricator

Offer to invert text-anchor for RTL languages
Open, Needs TriagePublic


When writing about Positioning text for easier translation, I realized that the suggestion of "using text-anchor properly" breaks down for RTL languages. Basically the story goes:

  • You want to label something to the text's right, so you want right-alignment for positioning to be independent of text length. For English that's text-anchor: end, and it works for other LTR languages like Chinese too. (Or maybe to the left, in which case you do start. Or maybe above or below, you get the point.)
  • You realize that RTL languages exist. You feed the thing through SVG Translate Tool, and paste in some random Arabic test for testing.
  • Since the tool does not yet invert the anchor, your output is all messed up. Anchoring to the end becomes left-align, so you see text colliding with the object you have meant to label.

The SVG-TT can have a little checkbox to deal with these things. center stays as center, but start and end are swapped, CSS or XML attribute.

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

The issue is much more complicated.

text-anchor, direction, and BIDI interact.

For the most part, SVG Translate should be able to ignore the problem by assuming that direction="ltr" and the .textContent will be strong LTR or strong RTL. In that case, BIDI reordering does the right thing. All text starts out LTR and has an appropriate text-anchor. If RTL text is encountered, Unicode BIDI embeds the RTL text into a separate RTL block within the initial LTR block. Doing nothing sort of works out. Things break down if some strong LTR text is encountered after the RTL: it will be placed to the right rather than the left of the RTL text block. But as long as the .textContent does not change direction, it will work out.

If one wants to do it right, then one must change both direction and text-anchor.

But that gets into trouble immediately. librsvg does not handle text-anchor correctly when when direction is RTL.

The clever way to handle swapping text-anchor and direction is to put them in a CSS style element, but librsvg does not handle language selectors (e.g., :lang(ar)) or attribute selectors (e.g., [systemLanguage="ar"]).

To add more confusion, CSS text-align uses left or right in addition to (the experimental) start or end. IIRC, SVG 1.1 does not have that property.

The simple version is this issue is stalled until librsvg is fixed or WMF uses a different renderer.

Every time I hear a librsvg bug, I can't help but ask: "is it a Debian stable librsvg bug or an actual librsvg bug?" (urgh) And indeed, a quick test using rsvg-convert from libsrvg 2.50 shows the red and black text on the last line overlapping fine.

(Angry remarks about Debian "stale" and "please backport from testing" omitted.)