mirror of
https://github.com/storytold/cadcraft.git
synced 2026-12-02 02:38:30 -06:00
* Stroke font: U+2205 is the diameter sign too Files from other software store the %%c symbol as U+2205 (empty set) rather than U+2300. The stroke font drew Ø, ø and U+2300 with its diameter glyph but had nothing for U+2205, so a stroke-font style showed it as a missing-glyph box, or as an installed font's ∅ when one had it. Draw it with the same strokes. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * Draw %%c with the style font's U+2205 or Ø when it has no U+2300, else the stroke glyph (fixes #1608) %%c becomes U+2300, which most Latin TrueType fonts lack (Arial, Times, Liberation Sans on Linux). A text style set in one of them drew the font's missing-glyph box for the diameter sign; only when a wide-coverage font (DejaVu Sans) happened to be installed did the per-character fallback show a symbol, in that other font's size and look. A character the style's face lacks is now first looked for as one of its substitutes in the same face: U+2300 as U+2205 or Ø, U+2205 as U+2300 or Ø (`substitutes`, a pure candidate list). All three read as the diameter sign in drawing text, and every Latin font has Ø, so the symbol keeps the text's font, size and weight. The existing fallback chain (FONTFALLBACK, FONTALT, installed fonts) is unchanged and comes next, as for every other missing character; when no font has the character and the stroke font does, its glyph is drawn as strokes instead of the face's box. The PDF glyph record carries the character actually drawn, so the ToUnicode map stays one-to-one when a text has both %%c and a literal Ø. Lines with right-to-left text (the shaped path) apply the same substitution before itemizing. Tests: the candidate order; the last resort's choice; and, with a real installed font that lacks U+2300 but has Ø (Liberation Sans, Arial...), %%c, U+2300 and U+2205 shape, measure and record the same glyph as Ø, also on a right-to-left line. Skips cleanly without such a font; no font file is added. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * Test the Ø substitution only in a font that also lacks U+2205 The installed-font test picks a face without U+2300 that has Ø, and expects %%c, U+2300 and U+2205 to shape as its Ø. A face that lacks U+2300 but has U+2205 satisfied that predicate, yet in it the substitution rightly chooses U+2205 over Ø, so the comparison with "Ø50" failed on such a machine. Require the face to lack U+2205 too; Liberation Sans does, so the test still runs where it ran before and still skips cleanly when no such font is installed. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * Shaped lines: draw what no font has with the stroke font too The left-to-right path draws a character that neither the text's font, its substitutes nor any installed font has with the stroke font's glyph when it has one, in place of the face's missing-glyph box. The shaped path for lines with right-to-left text stopped short: `resolve` went from the fallback chain straight to the face's box, so %%c on such a line in a font without a diameter sign, with no installed font to lend one, still showed a box where a left-to-right line showed the symbol. Select the stroke glyph before the face's box there as well. The piece is drawn and measured as the stroke-font pieces of a stroke-font line already are (the stroke font's advance, no PDF glyph record, since it is strokes, not an outline), so no other site needs a case. One difference remains deliberate: a stroke-font line leaves the trailing gap of its last glyph out of the width, as `shape_stroke` does; a TrueType line now keeps it, as `ttf::shape` does, so a line measures the same whichever path lays it out. Tests: with a face that maps nothing standing in for a font lacking the character, `resolve` picks the stroke glyph when no installed font has the character (the fallback font when one does), keeps the face's missing-glyph shape for what the stroke font lacks too, and the shaped line draws strokes rather than a box at the stroke font's advance. The installed-font test's right-to-left part also checks the width and that the face's Ø, not the stroke font's, is drawn. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * Shaped lines: take the bidi runs from the text before substitution A character the text's font lacks is drawn as one of its substitutes when the font has that: %%c (U+2300) as Ø in Arial, Liberation Sans and the like. The shaped path (lines with right-to-left text) substituted first and then ran the bidi algorithm over the substituted characters. U+2300 and U+2205 are bidi-neutral, Ø is left-to-right, so on a line like "⌀50 אב", right-to-left by its first strong character (the Hebrew), the Ø became the first strong character instead, the paragraph flipped to left-to-right and the runs changed order: "⌀50" moved from the right end of the line to the left, where a font with U+2300 never puts it. Resolve the runs from the characters as decoded and draw the substitute at the same logical index: substitution is one character for one, so the runs index both lists alike. Itemizing, shaping, mirroring and the widths keep using the substituted characters, since those are drawn. Tests: a TrueType font built in the test (character map and metrics, no outlines) gives a face whose coverage the test chooses, with or without U+2300, whatever is installed. "%%u⌀50%%u אב" in both faces underlines "⌀50" at the same place, the right end, at the same width. The installed-font test compared the glyphs of "⌀50 א" with "Ø50 א", equal only while the line flipped; it now checks that the face's Ø is the rightmost glyph of the former and the leftmost of the latter, at the same width and glyph count, still without stroke-font glyphs. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * Skip empty glyph slots when finding the rightmost glyph in the diameter test Main now keeps an empty outline slot for a glyph without contours (the space), so the slot's missing x put it last in the right-to-left check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com> Co-authored-by: FredApps <153173854+FredApps@users.noreply.github.com>