mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-12-05 13:33:00 -05:00
Format the Greek Add Text fix and describe its Inter path
This commit is contained in:
1 parent
6db0c2bec4
commit
949e0d6f2d
2 files changed
+10
-16
No files matched your search
@@ -193,14 +193,11 @@ pub(super) fn is_hebrew(c: char) -> bool {
|
||||
/// A supported non-WinAnsi character that uses the bundled Inter face; the existing Arabic,
|
||||
/// Hebrew and Thai faces retain priority for their own scripts.
|
||||
pub(super) fn is_inter(c: char) -> bool {
|
||||
!is_arabic(c) && !is_hebrew(c) && !is_thai(c) && !is_bidi_control(c) && !c.is_control()
|
||||
&& pdfcraft_fonts::shaped_text::latin_fallback(c)
|
||||
!is_arabic(c) && !is_hebrew(c) && !is_thai(c) && !is_bidi_control(c) && !c.is_control() && pdfcraft_fonts::shaped_text::latin_fallback(c)
|
||||
}
|
||||
|
||||
/// The first character of `t` that would be drawn as `?`: outside WinAnsiEncoding and not drawn
|
||||
/// with the craft-fonts Arabic (#125) or Hebrew (#128) face, or Arabic or Hebrew that the face can't
|
||||
/// draw (or that has no face to draw it). Page-content tools refuse such text; the Add-text editor
|
||||
/// keeps it open.
|
||||
/// The first character of `t` that neither WinAnsiEncoding nor the available script faces can draw.
|
||||
/// Page-content tools refuse such text and the Add-text editor keeps the draft open.
|
||||
pub fn first_undrawable(t: &AddedText) -> Option<char> {
|
||||
if t.font_resource.is_some() {
|
||||
return None;
|
||||
@@ -233,8 +230,7 @@ pub fn first_undrawable(t: &AddedText) -> Option<char> {
|
||||
})
|
||||
}
|
||||
|
||||
/// Whether `t` has Arabic or Hebrew that its craft-fonts face draws (so `draw` lays it out with
|
||||
/// [`draw_shaped`]).
|
||||
/// Whether `t` needs the Arabic, Hebrew, or Inter face on the shaped-text path.
|
||||
fn shaped_by_a_face(t: &AddedText) -> bool {
|
||||
(pdfcraft_fonts::document_arabic_font().is_some() && t.text.chars().any(is_arabic))
|
||||
|| (pdfcraft_fonts::document_hebrew_font(false).is_some() && t.text.chars().any(is_hebrew))
|
||||
|
||||
@@ -8632,10 +8632,7 @@ fn hostile_form_xobjects_are_read_once() {
|
||||
fn added_greek_and_cyrillic_use_vector_fallback_and_survive_reopen() {
|
||||
let mut doc = fixture();
|
||||
let text = AddedText {
|
||||
rect: [72.0, 600.0, 500.0, 700.0],
|
||||
text: "Καλημέρα Hello Привет A\u{301}".into(),
|
||||
size: 14.0,
|
||||
..AddedText::default()
|
||||
rect: [72.0, 600.0, 500.0, 700.0], text: "Καλημέρα Hello Привет A\u{301}".into(), size: 14.0, ..AddedText::default()
|
||||
};
|
||||
assert_eq!(first_undrawable(&text), None);
|
||||
add_content(&mut doc, 0, &Content::Text(text.clone())).unwrap();
|
||||
@@ -8650,13 +8647,14 @@ fn added_greek_and_cyrillic_use_vector_fallback_and_survive_reopen() {
|
||||
let page = &pdfcraft_model::pages(&reopened)[0];
|
||||
let resources = reopened.resolve(page.dict.get(b"Resources").unwrap());
|
||||
let fonts = reopened.resolve(resources.as_dict().unwrap().get(b"Font").unwrap()).as_dict().unwrap().clone();
|
||||
let fallback: Vec<_> = fonts.iter().filter(|(k, _)| k.starts_with(b"PCAr")).map(|(_, v)| reopened.resolve(v).as_dict().unwrap().clone()).collect();
|
||||
let fallback: Vec<_> =
|
||||
fonts.iter().filter(|(k, _)| k.starts_with(b"PCAr")).map(|(_, v)| reopened.resolve(v).as_dict().unwrap().clone()).collect();
|
||||
assert!(!fallback.is_empty());
|
||||
assert!(fallback.iter().all(|font| font.name(b"Subtype") == Some(&b"Type3"[..]) && font.get(b"ToUnicode").is_some()));
|
||||
|
||||
let bad = Content::Text(AddedText { text: "Ελλάδα 日本".into(), ..text.clone() });
|
||||
assert_eq!(first_undrawable(match &bad { Content::Text(t) => t, _ => unreachable!() }), Some('日'));
|
||||
assert!(add_content(&mut doc, 0, &bad).is_err(), "unsupported glyphs are still refused");
|
||||
let bad = AddedText { text: "Ελλάδα 日本".into(), ..text.clone() };
|
||||
assert_eq!(first_undrawable(&bad), Some('日'));
|
||||
assert!(add_content(&mut doc, 0, &Content::Text(bad)).is_err(), "unsupported glyphs are still refused");
|
||||
let chosen = Content::Text(AddedText { font_resource: Some("MissingFont".into()), ..text });
|
||||
assert!(add_content(&mut doc, 0, &chosen).is_err(), "an explicit font never silently falls back");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user