Function resolve_positions_list

Source
fn resolve_positions_list(
    text_node: SvgNode<'_, '_>,
    state: &State<'_>,
) -> Vec<CharacterPosition>
Expand description

Resolves text’s character positions.

This includes: x, y, dx, dy.

§The character

The first problem with this task is that the character itself is basically undefined in the SVG spec. Sometimes it’s an XML character, sometimes a glyph, and sometimes just a character.

There is an ongoing discussion on the SVG working group that addresses this by stating that a character is a Unicode code point. But it’s not final.

Also, according to the SVG 2 spec, character is a Unicode code point.

Anyway, we treat a character as a Unicode code point.

§Algorithm

To resolve positions, we have to iterate over descendant nodes and if the current node is a tspan and has x/y/dx/dy attribute, than the positions from this attribute should be assigned to the characters of this tspan and it’s descendants.

Positions list can have more values than characters in the tspan, so we have to clamp it, because values should not overlap, e.g.:

(we ignore whitespaces for example purposes, so the text content is Text and not T ex t)

<text>
  a
  <tspan x="10 20 30">
    bc
  </tspan>
  d
</text>

In this example, the d position should not be set to 30. And the result should be: [None, 10, 20, None]

Another example:

<text>
  <tspan x="100 110 120 130">
    a
    <tspan x="50">
      bc
    </tspan>
  </tspan>
  d
</text>

The result should be: [100, 50, 120, None]