fix(scene): correct MIRROR of TEXT under MIRRTEXT (commit + preview)

Root cause: the glyph tessellator advanced the pen by advance*width_factor
while the transform already scales the pen position by the width factor, so
a backward (negative width factor) run kept its word order and grew on the
same side of the anchor instead of mirroring across it. Advance in unscaled
glyph units to match text_local_bounds; the transform applies the factor once.

On top of that:
- The renderer honours the entity's own text-generation flags (DXF 71: bit 2
  backward / bit 4 upside-down) XOR the text style's flags, and signs the
  horizontal anchor by the width factor so Center/Right backward text mirrors
  about its anchor.
- MIRRTEXT on: a MIRROR toggles both group-71 bits so the reflected rotation
  renders a true glyph mirror (backward-upright for a vertical axis, flipped
  for a horizontal one).
- MIRRTEXT off: the text flips left<->right and lands mirror-symmetric to the
  source (right-reading) instead of hugging the axis.
- The MIRROR preview re-derives text ghosts to match the commit; mirrored()
  now reflects the double-single residual too.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Hakan Seven 2026-07-03 12:42:55 +03:00
commit 79a5ac6fed
7 changed files with 153 additions and 23 deletions

View file

@ -420,18 +420,22 @@ pub fn tessellate_text_run(
emit_glyph(out, &g.strokes, *cursor_x);
emit_fill(fill_tris, &g.fill_tris, *cursor_x);
}
*cursor_x += run.advance * wf;
// Advance the pen in unscaled glyph units — the `xform` scales the
// pen position by `wf`, so multiplying the advance here too would
// apply the width factor twice (and reverse a backward run's word
// order onto the wrong side). Matches `text_local_bounds`.
*cursor_x += run.advance;
} else {
for ch in seg.chars() {
match face.glyph(ch) {
Some(glyph) => {
emit_glyph(out, &glyph.strokes, *cursor_x);
emit_fill(fill_tris, &glyph.fill_tris, *cursor_x);
*cursor_x += (glyph.advance + face.letter_spacing() * tracking) * wf;
*cursor_x += glyph.advance + face.letter_spacing() * tracking;
}
None => {
warn_missing_glyph(font_name, ch);
*cursor_x += (6.0 + face.letter_spacing() * tracking) * wf;
*cursor_x += 6.0 + face.letter_spacing() * tracking;
}
}
}
@ -456,17 +460,17 @@ pub fn tessellate_text_run(
Some(glyph) => {
emit_glyph(&mut out, &glyph.strokes, cursor_x);
emit_fill(&mut fill_tris, &glyph.fill_tris, cursor_x);
cursor_x += (glyph.advance + face.letter_spacing() * tracking) * wf;
cursor_x += glyph.advance + face.letter_spacing() * tracking;
}
None => {
warn_missing_glyph(font_name, *c);
cursor_x += (6.0 + face.letter_spacing() * tracking) * wf;
cursor_x += 6.0 + face.letter_spacing() * tracking;
}
}
}
}
Tok::Space => cursor_x += face.word_spacing(),
Tok::Missing => cursor_x += (6.0 + face.letter_spacing() * tracking) * wf,
Tok::Missing => cursor_x += 6.0 + face.letter_spacing() * tracking,
Tok::Deco(deco, op) => {
let (slot, y) = match deco {
Deco::Under => (&mut underline, UNDER_Y),