mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-10-24 10:08:00 -06:00
Merge r2-fix-engine: tests the combined batch broke
This commit is contained in:
@@ -108,10 +108,10 @@ fn assert_rendered_page(data: &[u8], dpi: u32, what: &str) {
|
||||
let mut buf = vec![0; reader.output_buffer_size().unwrap()];
|
||||
let frame = reader.next_frame(&mut buf).unwrap();
|
||||
assert_eq!((frame.width, frame.height), (200 * dpi / 72, 300 * dpi / 72), "{what}");
|
||||
// `render` writes 8-bit RGBA (`pdfcraft_engine::export::encode_png`).
|
||||
assert_eq!((frame.color_type, frame.bit_depth), (png::ColorType::Rgba, png::BitDepth::Eight), "{what}");
|
||||
// Opaque pixels with every colour channel below half intensity: ink, not white paper.
|
||||
let inked = buf[..frame.buffer_size()].as_chunks::<4>().0.iter().filter(|[r, g, b, a]| [r, g, b].iter().all(|c| **c < 128) && *a > 128).count();
|
||||
// A rendered page is opaque, so `render` writes it as 8-bit RGB (`pdfcraft_engine::export::encode_png`).
|
||||
assert_eq!((frame.color_type, frame.bit_depth), (png::ColorType::Rgb, png::BitDepth::Eight), "{what}");
|
||||
// Pixels with every colour channel below half intensity: ink, not white paper.
|
||||
let inked = buf[..frame.buffer_size()].as_chunks::<3>().0.iter().filter(|px| px.iter().all(|c| *c < 128)).count();
|
||||
assert!(inked > 100, "{what}: only {inked} inked pixels, the page is blank");
|
||||
}
|
||||
|
||||
|
||||
@@ -5342,10 +5342,12 @@ fn a_shaped_run_is_one_text_object_with_each_glyph_where_shaping_put_it() {
|
||||
#[test]
|
||||
fn a_subset_program_is_not_trusted_for_new_characters_and_the_error_names_the_character() {
|
||||
let mut doc = embedded_program_page("BT /F1 12 Tf 72 700 Td (Stable text) Tj ET", "ABCDEF+Inter-Regular");
|
||||
// The subset's own program is not trusted for a character: the bundled Inter face draws it
|
||||
// through a generated font instead (the subset may map a code whose outline was dropped).
|
||||
// The subset's own program is not trusted for a character: a fallback face draws it through a
|
||||
// generated font instead (the subset may map a code whose outline was dropped). The Japanese
|
||||
// sans face leads the fallbacks when built with craft-fonts; the bundled Inter face otherwise.
|
||||
let edit = text::rewrite_block(&mut doc, 0, 0, Some("Stable tőxt"), &text::BlockStyle::default()).unwrap();
|
||||
assert_eq!(edit.substituted.as_deref(), Some("Inter Type3"));
|
||||
let face = pdfcraft_fonts::document_japanese_font_for_style(false, false).map_or("Inter", |f| f.family);
|
||||
assert_eq!(edit.substituted, Some(format!("{face} Type3")));
|
||||
assert_eq!(text::text_blocks(&reopen(&doc), 0).unwrap()[0].editor_text, "Stable tőxt");
|
||||
// A character no fallback face has is refused, named, and left as it was.
|
||||
let mut doc = embedded_program_page("BT /F1 12 Tf 72 700 Td (Stable text) Tj ET", "ABCDEF+Inter-Regular");
|
||||
|
||||
@@ -1148,12 +1148,15 @@ impl Layouter<'_> {
|
||||
}
|
||||
let value = self.data.and_then(|d| d.value_at(&data_path(self.tpl, &ctx.som))).filter(|t| !t.trim().is_empty()).or_else(|| f.value.plain());
|
||||
let Some(value) = value.filter(|t| !t.trim().is_empty()) else { return 0.0 };
|
||||
// Beside a caption the text has what the caption leaves; 2pt of padding on each side.
|
||||
// Beside a caption the text has what the caption leaves; a widget's text has 2pt of
|
||||
// padding on each side, a non-interactive field's (drawn as text) none, so it wraps
|
||||
// where it is drawn.
|
||||
let beside = match self.caption_reserve(f, inner_w, ctx) {
|
||||
Some((Placement::Top | Placement::Bottom, _)) | None => 0.0,
|
||||
Some((_, r)) => r,
|
||||
};
|
||||
let w = (inner_w - beside - f.ui_margin.horizontal() - 4.0).max(1.0);
|
||||
let padding = if f.access == Access::NonInteractive { 0.0 } else { 4.0 };
|
||||
let w = (inner_w - beside - f.ui_margin.horizontal() - padding).max(1.0);
|
||||
let font = ctx.font.apply(&f.common.font);
|
||||
text::measure_height(&text::plain(value.trim_end()), w, &ctx.para, &Self::field_text_face(f, &font), &|_| String::new())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user