Repository navigation
fix(typeset): shape runs with the font they are tagged with (garbled PDF export) - #42
Merged
Merged
Conversation
A span asking for another family, or for bold, was shaped with the paragraph's font but tagged with the span's family. The PDF then drew the paragraph font's glyph ids with the span's font and the text came out as garbage (issue TypesetOK#40). The bold case only worked because Frank Ruhl Libre Regular and Bold happen to share glyph order. Such runs are now shaped with a sibling session of the requested face (resolved through FontManager::face_for, so a family without a bold face keeps its regular one) and tagged with the font that shaped them. Refs TypesetOK#40
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
הבעיה
#40: בקובץ ה-PDF המיוצא יש מילים שיוצאות כג'יבריש (סימנים ומשבצות), אבל על המסך הן מוצגות כראוי.
הגורם
המנוע מעצב כל פסקה בגופן של הפסקה בלבד. כשלחלק מהטקסט יש span עם גופן אחר (למשל
David Libreבפסקת Frank Ruhl, מה שקורה בייבוא DOCX) או מודגש, המנוע עדיין עיצב אותו בגופן הפסקה, אבל סימן את המילה בשם הגופן של ה-span. ה-PDF צייר אז את מספרי הגליפים של Frank Ruhl בעזרת הגופן David Libre, והתוצאה ג'יבריש. המסך לא מושפע, כי הוא מצייר את הטקסט ב-CSS ולא לפי מספרי הגליפים.מודגש עבד עד היום רק במקרה: ל-Frank Ruhl Libre Regular ול-Bold יש אותו סדר גליפים.
התיקון
ShapingSession::sibling, ומסומן בגופן שבאמת עיצב אותו. מספר גליף תמיד שייך לגופן שרשום לידו.FontManager::face_for, במקום הרשימה הקבועה של"Frank Ruhl Libre"/"David Libre"עם" Bold". בזכות זה Noto Rashi מודגש מקבל את הגופן המודגש שלו, ו-David Libre מודגש (שאין לו גרסה מודגשת) נשאר ב-Regular במקום לבקש גופן שלא קיים.crates/tok-typeset/tests/span_font_glyphs_test.rs: גופן אחר, מודגש, ומודגש בגופן בלי Bold. בכל אחד הבדיקה מוודאת שמספר הגליף שווה ל-glyph_indexשל הגופן המסומן.שחזור
מסמך שנבנה עם
documentStateToDocumentRoot, render-pdf, pdftoppm. לפני התיקון השורה "גופן אחר" (span של David Libre) יצאה כאותיות לטיניות עם ניקוד. אחרי התיקון היא יוצאת בעברית תקינה ב-David Libre. שאר השורות (בלי עיצוב, גופן זהה לפסקה, מודגש, גרש וגרשיים בעברית וב-ASCII) זהות לפני ואחרי.השפעה
אורך טקסט ב-span עם גופן אחר נמדד עכשיו לפי הגופן הזה, ולכן שבירת השורות בפסקאות כאלה יכולה להשתנות, ונעשית קרובה יותר למה שמוצג על המסך.
בדיקות
עברו
cargo fmt --check,cargo clippy --workspace --all-targets -D warnings,cargo test --workspace(כולל 3 הבדיקות החדשות),npm run buildו-npm test.מה לא נבדק
לא שחזרתי את המסמך המקורי מ-#40, אלא מסמך שבניתי בעצמי. כדאי לייצא שוב את אותו מסמך עם התיקון כדי לוודא שזה אותו שיבוש.