mirror of
https://github.com/storytold/gridcraft.git
synced 2026-11-16 15:23:57 +00:00
## Summary Arabic text reached the PDF writer intact, then WinAnsi encoding replaced its characters with question marks. This fixes #923 through the shared PDF text path, including cells, headers and chart labels. ```diff PDF text - encode Arabic through WinAnsi + shape with harfrust and Unicode bidi + embed licensed glyph outlines with matching weight coordinates + preserve logical source using ToUnicode and ActualText + fall back to the standard and CID fonts for characters the Arabic face lacks ``` Font binaries stay in the optional craft-fonts build input. Native unbundled builds can use installed Noto Sans Arabic. Explicit cell reading-direction integration follows separately. **Web build:** shaped Arabic on web needs the bundled craft fonts. The current release workflow doesn't enable `web-craft-fonts`, so until a maintainer enables it, web sets Arabic in the CID font, as main does today, which has no Arabic glyphs, and shows a message that no Noto Sans Arabic face was found. The same applies to a desktop without Noto Sans Arabic, and to bold Arabic where only the regular face is installed. ## Evidence - **Before:** Arabic exported as `?` (#923, v0.6.1); main now sets it in the CID font, which has no Arabic glyphs, so readers show blanks or boxes. **After:** native and bundled exports show joined letters, marks, Western/Arabic digits, bold/italic, wrapping, rotation and chart labels. Fresh `pdfinfo`, `pdffonts` and `pdftotext -bbox` checks accept the files; eight original Arabic strings match extracted logical text exactly. - At the current head, with Noto Sans Arabic installed and no `CRAFT_FONTS_DIR`: the `gridcraft-pdf`, `gridcraft-engine` and `gridcraft-xlsx` tests, clippy, fmt, layers, assets, parity and the wasm check pass. The full `cargo xtask ci` with the craft-fonts bundle relies on the hosted gate. - Characters the Arabic face lacks (emoji, Cyrillic) are set like non-Arabic text, and without an Arabic face for the text's weight Arabic takes the CID path main uses, with one message per export. Only a broken font or a size limit fails the export. Size limits cover text, glyph subsets, outlines and page content. ## Merge Danger **Door:** two-way **Blast Radius:** printing `PdfDoc::finish` now returns a Result and every caller handles it. Latin-only rendering stays on its existing path. This is a glyph-outline PDF solution; platform printer and physical screen-reader behavior are not claimed.
1.3 KiB
1.3 KiB
gridcraft-pdf
A small PDF 1.7 writer for shaped Arabic text, vector drawing and RGBA images.
API migration
The geometry-taking methods now use Point and Rect values to name their coordinates, and
image_rgba groups its pixel dimensions into an array. Update calls to the four changed methods as
follows:
use gridcraft_pdf::{Font, PdfDoc, Point, Rect};
let mut doc = PdfDoc::new();
let page = doc.add_page(612.0, 792.0);
// Before: page.link_page(20.0, 30.0, 80.0, 16.0, 1, 40.0, 50.0);
page.link_page(Rect::new(20.0, 30.0, 80.0, 16.0), 1, Point::new(40.0, 50.0));
// Before: page.stroke_line_dashed(0.0, 0.0, 100.0, 40.0, 1.0, [0, 0, 0], &[4.0, 2.0]);
page.stroke_line_dashed(Point::new(0.0, 0.0), Point::new(100.0, 40.0), 1.0, [0, 0, 0], &[4.0, 2.0]);
// Before: page.text_rotated(20.0, 40.0, 12.0, Font::Helvetica, [0, 0, 0], "Label", 0.2);
page.text_rotated(Point::new(20.0, 40.0), 12.0, Font::Helvetica, [0, 0, 0], "Label", 0.2);
let rgba = [255, 0, 0, 255];
// Before: page.image_rgba(10.0, 10.0, 24.0, 24.0, &rgba, 1, 1);
page.image_rgba(Rect::new(10.0, 10.0, 24.0, 24.0), &rgba, [1, 1]);
Point::new(x, y) uses the page's top-left origin, where y increases downward. Rect::new(x, y, width, height) describes the destination or link rectangle in the same coordinate system. The
image_rgba pixel-size array is [width, height].