Merge pull request #7934 from dotCooCoo/fix/svg-import-absolute-ltr-character

SVG import: absolutely placed characters one text object cannot place import as a group
This commit is contained in:
BFlat
2026-11-16 04:27:23 +07:00
committed by GitHub
5 changed files with 329 additions and 88 deletions
+2 -1
View File
@@ -1793,7 +1793,8 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
A gap between glyphs of two sizes is measured against the smaller one, so a word set beside a much larger one with no space glyph between them (a browser's margin between two sizes, as in `≤ 4` and a small `hours`) keeps its word space (#3623).
SVG import's style cascade, used for hidden objects, non-scaling strokes and type, tests each element only against the `<style>` rules for its id, its classes and its element name, and the rules whose selector ends in none of these (`*`, `[x]`).
SVG import places right-to-left point type and type on a path as [SVG 2's `text-anchor`](https://www.w3.org/TR/SVG2/text.html#TextAnchoringProperties) says: with `direction: rtl`, `start` puts the right edge of the text at its position (on a path, the text ends at `startOffset`) and `end` puts the left edge there. Each line and each absolutely placed chunk is anchored by the `text-anchor` and `direction` of the element holding its first character, a `<tspan>`'s own included, and each line starts at its own `x`. An absolutely placed chunk is anchored by the left and right edges of its glyphs as they are drawn, so a chunk of several right-to-left characters, whose first character is drawn at its right, sits on its anchor too. A letter-spaced right-to-left line keeps the tracking of all its letters inside the advance it anchors (`rtl_point_text_start_and_end_use_directional_edges`, `rtl_type_on_a_path_starts_at_its_directional_edge`, `rtl_letter_spaced_lines_stay_on_their_anchor`, `rtl_lines_use_each_chunk_first_character_direction_and_anchor`, `each_line_starts_at_its_own_x`, `absolutely_placed_chunks_use_their_own_rtl_anchor` and `absolutely_placed_rtl_chunks_of_several_characters_anchor_by_their_visual_edges` in `crates/svg/tests/it/import_text.rs`).
SVG import puts each absolutely placed character of right-to-left text on its own `x`, as [SVG 1.1's text chunks](https://www.w3.org/TR/SVG11/text.html#TextLayoutIntroduction) require, also when the characters run right to left on a later line: in `<text direction="rtl" font-size="20">`, `<tspan x="100 160" y="80 80">אב</tspan>` after a first line puts the right edges of `א` and `ב` at 100 and 160, where import put the right edge of `א` at 393.48 before. Chunks that overlap keep their own anchors, and characters stretched by `lengthAdjust="spacingAndGlyphs"` land on their `x` too. A left-to-right character drawn between two absolutely placed right-to-left characters leaves the one after it where the line puts it, and the import warns about it (`absolutely_placed_right_to_left_characters_sit_on_their_own_x` in `crates/svg/tests/it/import_text.rs`).
SVG import puts each absolutely placed character of right-to-left text on its own `x`, as [SVG 1.1's text chunks](https://www.w3.org/TR/SVG11/text.html#TextLayoutIntroduction) require, also when the characters run right to left on a later line: in `<text direction="rtl" font-size="20">`, `<tspan x="100 160" y="80 80">אב</tspan>` after a first line puts the right edges of `א` and `ב` at 100 and 160, where import put the right edge of `א` at 393.48 before. Chunks that overlap keep their own anchors, and characters stretched by `lengthAdjust="spacingAndGlyphs"` land on their `x` too (`absolutely_placed_right_to_left_characters_sit_on_their_own_x` in `crates/svg/tests/it/import_text.rs`).
SVG import puts an absolutely placed character on its `x` also when one text object cannot place it. [SVG 1.1 reorders right-to-left characters only within a text chunk](https://www.w3.org/TR/SVG11/text.html#RelationshipWithBi-directionality), while one object reorders the whole line: in `<text x="100 160 220" y="80" direction="rtl" font-size="20">אbג</text>`, the left-to-right `b` is drawn right before `ג` with no kerning between them, and import left `ג` where the line put it, with a warning, before. Such a text imports as a group of point type objects named after the element, cut before each character one object cannot place, with the right edges of `א`, `b` and `ג` at 100, 160 and 220, and the import warns that the text became several objects. A text that one object can place stays one object, and a split text in a clip path clips by the outlines of all its objects (`absolutely_placed_characters_one_object_cannot_place_import_as_a_group` in `crates/svg/tests/it/import_text.rs`, `a_text_imported_as_several_objects_clips_by_all_their_outlines` in `crates/svg/tests/it/clip_text.rs`).
SVG import places type on a path of one closed subpath as [SVG 2's `startOffset` attribute](https://www.w3.org/TR/SVG2/text.html#TextPathElementStartOffsetAttribute) describes: text anchored to start before the path's start point, or offset past its end, wraps around the path, so text with `text-anchor="end"` at `startOffset` 0 ends at the start point, and a negative `startOffset` counts back from the end. Text longer than the loop draws its first characters whatever its anchor. A path of several closed subpaths still starts the text at the path's start or end (`text_on_a_closed_path_wraps_past_the_path_start` in `crates/svg/tests/it/import_text.rs`).
Type on an open path can start before the path's start (`type.pathOptions` `start` below 0), and the characters whose middle falls before the path's start are not drawn, as [SVG 2's text on a path layout](https://www.w3.org/TR/SVG2/text.html#TextLayoutPath) describes for the path's start; past the path's end, text that does not fit is overflow, as for other type on a path. The text keeps every character, and the start bracket stays at the path's start. SVG import reads text anchored or offset before an open path's start this way instead of starting it at the path's start, and SVG export writes it with a negative `startOffset`. PDF export writes only the characters drawn on the path, the legacy `.ai` and `.ai` editing data writers write the type from the path's start with a warning, and Release Type on a Path keeps the first drawn character where it was drawn (`type_on_an_open_path_starts_before_the_path` in `crates/doc/src/text/tests.rs`, `on_path_open_start_before_the_path_hides_the_glyphs_before_it` in `crates/text/src/tests.rs`, `text_on_an_open_path_starts_before_the_path` in `crates/svg/tests/it/import_text.rs`, `text_on_an_open_path_starting_before_it_round_trips` in `crates/svg/tests/it/roundtrip.rs`, `options_start_type_before_an_open_path` in `crates/engine/src/tests/pathtype.rs`).
SVG import reads the bidi embedding of a `<tspan>`, `<textPath>` or `<a>` inside a `<text>` as [SVG 1.1's bidi section](https://www.w3.org/TR/SVG11/text.html#RelationshipWithBi-directionality) describes: with `unicode-bidi: embed` its characters take its `direction` as their Character Direction, an element with `normal` stays in its parent's embedding, and the `<text>` keeps its own paragraph direction, so a run that SVG export writes with `direction` and `unicode-bidi="embed"` opens with its Character Direction again. Character Direction holds one level of embedding, so `bidi-override`, `isolate` and `isolate-override` are imported as embeddings in their `direction`, `plaintext` as an embedding in the direction of its first strong character, and an embedding inside another as an embedding of its own, each with an import warning. With `unicode-bidi: plaintext` on the `<text>`, each of its paragraphs runs, and each chunk is anchored, in the direction of its first strong character (`a_tspan_bidi_embedding_becomes_its_character_direction`, `unicode_bidi_is_not_inherited_and_reads_from_the_cascade` and `unicode_bidi_values_the_text_model_cannot_hold_are_reported` in `crates/svg/tests/it/import_text.rs`; `character_direction_reads_back` in `crates/svg/tests/it/text_layout.rs`).