w3c / svgwg

SVG Working Group specifications
Other
695 stars 131 forks source link

Bidi reordering and textchunks give odd results when following SVG 2.0 text algorithm #897

Open therahedwig opened 1 year ago

therahedwig commented 1 year ago

I've been doing some tests, and found that if the following SVG gives different results in different browsers.

<text  fill="#0000ff" stroke="none" direction="rtl" style="font-family: DejaVu Sans;font-size: 10;"><tspan x="250" y="34">aa bb <tspan style="text-decoration: underline;">حادثتا</tspan> السفينتين بسين cc dd </tspan><tspan fill="#000000" text-anchor="middle"  x="250" dy="10">aa bb <tspan style="text-decoration: underline;">حادثتا</tspan> السفينتين بسين cc dd </tspan></text>

Chromium 106: image

Firefox 105: image

Now, SVG 2.0 spec right now says that text chunks should always have their own shaping and reordering, however, that means joined scripts might break, discussed in #631, which then suggests it's undefined. However, the SVG 2.0 text layout algorithm also says "For all other text (SVG 1.1 compatible text and SVG 1.1 like multi-line text), layout the text in a CSS content box that is unconstrained in width and height. " Which means that the following happens:

image

The top being the text as it rolls out of the CSS-based renderer, and the bottom being the SVG text layout algorithm adjusting the positions. Which means that spec-wise, technically the behaviour is defined and Firefox is implementing it correctly.

So, there's the following options:

  1. Layout every text chunk as a separate paragraph. Confuses the idea of a text element being a paragraph, though, and that will affect paragraph-based CSS properties like text-indent.
  2. Insert bidi-controls around each text chunk. I know too little of the bidi algorithm what kind of effect this has.
  3. Recalculate the advances of each glyph so they'll sit snug together. In theory this could have odd results caused by shaping, but I don't know enough of the related algorithms to tell you whether this is a serious issue.
  4. Somehow figure out a way to have each text chunk laid out as a wrapping-line.
  5. Do nothing?

I mostly wanted to make sure people would know that this is what happens if you follow the spec precisely. I am glad SVG 2.0 has proper text-wrapping when as the basic positioning of SVG 1.1 leads to a lot of questions.