mirror of
https://github.com/storytold/wordcraft.git
synced 2026-11-19 17:05:08 +00:00
Merge main into fix/issue-6636
This commit is contained in:
commit
e6e8c61dbf
231 files changed
+1822
-48090
No files matched your search
@@ -377,11 +377,7 @@ mod tests {
|
||||
#[test]
|
||||
fn pictures_wrap_around_their_opaque_pixels() {
|
||||
crate::test_fonts();
|
||||
let png = |img: image::DynamicImage| {
|
||||
let mut buf = Vec::new();
|
||||
img.write_to(&mut std::io::Cursor::new(&mut buf), image::ImageFormat::Png).unwrap();
|
||||
buf
|
||||
};
|
||||
let png = |img: image::DynamicImage| wordcraft_geom::picture::encode_format(&img, image::ImageFormat::Png).unwrap();
|
||||
// An opaque disc in the middle of a transparent 64 × 64 picture.
|
||||
let disc = image::RgbaImage::from_fn(64, 64, |x, y| {
|
||||
let (dx, dy) = (x as f32 + 0.5 - 32.0, y as f32 + 0.5 - 32.0);
|
||||
|
||||
@@ -49,6 +49,7 @@ use wordcraft_geom::{Point, Rect, Spin};
|
||||
|
||||
pub use fields::FieldCtx;
|
||||
pub use hit::VisualStep;
|
||||
pub use missing::{MetafileTextLayout, layout_metafile_text};
|
||||
pub use para::{LineEnd, ParaLayout};
|
||||
pub use table::{autofit_widths, cell_margins, measure_table_columns};
|
||||
|
||||
@@ -86,9 +87,7 @@ use headers::MAX_HEADER_ITEMS;
|
||||
use headers::placed_cost;
|
||||
use headers::placed_cost_by;
|
||||
pub use metafile::{MAX_METAFILE_DASHES, crop_sides, crop_window, metafile_average_color, metafile_dashes, metafile_miter_limit};
|
||||
pub use missing::{
|
||||
MAX_MISSING_GLYPHS, MetafileTextLayout, MissingGlyphs, metafile_text_layout, metafile_text_run, missing_watermark_glyphs, watermark_run,
|
||||
};
|
||||
pub use missing::{MAX_MISSING_GLYPHS, MissingGlyphs, metafile_text_run, missing_watermark_glyphs, watermark_run};
|
||||
pub use notes::DECOR_STORY;
|
||||
pub(crate) use notes::NOTE_SEP_W;
|
||||
use notes::{MAX_NOTE_PASSES, footnote_pages};
|
||||
|
||||
@@ -182,7 +182,7 @@ pub struct MetafileTextLayout {
|
||||
/// baseline. The font height is the em size when negative and the cell height (ascent plus
|
||||
/// descent) when positive. The per-character advances `dx` place each cluster when there is one
|
||||
/// per character. None when the size is not finite and positive.
|
||||
pub fn metafile_text_layout(
|
||||
pub fn layout_metafile_text(
|
||||
t: &craft_metafile::Text,
|
||||
upem: f64,
|
||||
ascent: f64,
|
||||
@@ -365,7 +365,7 @@ fn meta_runs(bytes: &[u8]) -> Vec<MetaRun> {
|
||||
let craft_metafile::Item::Text(t) = item else { continue };
|
||||
let (face, shaped) = metafile_text_run(t);
|
||||
let glyphs: Vec<_> = shaped.iter().map(|g| (g.cluster, f64::from(g.x_advance), f64::from(g.x_offset), f64::from(g.y_offset))).collect();
|
||||
if metafile_text_layout(t, face.upem, face.ascent, face.descent, &glyphs).is_none() {
|
||||
if layout_metafile_text(t, face.upem, face.ascent, face.descent, &glyphs).is_none() {
|
||||
continue;
|
||||
}
|
||||
let ranges = cluster_ranges(&t.text, &shaped);
|
||||
|
||||
@@ -277,9 +277,7 @@ fn disc_png(size: u32) -> Vec<u8> {
|
||||
let (dx, dy) = (x as f32 + 0.5 - c, y as f32 + 0.5 - c);
|
||||
image::Rgba([0, 0, 0, if dx * dx + dy * dy < c * c * 0.5 { 255 } else { 0 }])
|
||||
});
|
||||
let mut buf = Vec::new();
|
||||
image::DynamicImage::from(img).write_to(&mut std::io::Cursor::new(&mut buf), image::ImageFormat::Png).unwrap();
|
||||
buf
|
||||
wordcraft_geom::picture::encode_format(&image::DynamicImage::from(img), image::ImageFormat::Png).unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -331,9 +329,7 @@ fn decoding_pictures_stops_at_the_layouts_budget() {
|
||||
/// A `size` × `size` PNG with no transparency.
|
||||
fn opaque_png(size: u32) -> Vec<u8> {
|
||||
let img = image::RgbImage::from_pixel(size, size, image::Rgb([0, 0, 0]));
|
||||
let mut buf = Vec::new();
|
||||
image::DynamicImage::from(img).write_to(&mut std::io::Cursor::new(&mut buf), image::ImageFormat::Png).unwrap();
|
||||
buf
|
||||
wordcraft_geom::picture::encode_format(&image::DynamicImage::from(img), image::ImageFormat::Png).unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -266,7 +266,7 @@ fn meta_text(height: f32, dx: Vec<f32>) -> craft_metafile::Text {
|
||||
#[test]
|
||||
fn metafile_text_heights() {
|
||||
let glyphs = [(0, 500.0, 0.0, 0.0), (1, 500.0, 0.0, 0.0)];
|
||||
let em = |h| crate::metafile_text_layout(&meta_text(h, Vec::new()), 1000.0, 900.0, 300.0, &glyphs).map(|l| l.em);
|
||||
let em = |h| crate::layout_metafile_text(&meta_text(h, Vec::new()), 1000.0, 900.0, 300.0, &glyphs).map(|l| l.em);
|
||||
let near = |a: Option<f64>, b: f64| a.is_some_and(|a| (a - b).abs() < 1e-9);
|
||||
assert!(near(em(0.0), 16.0 * 1000.0 / 1200.0), "{:?}", em(0.0));
|
||||
assert!(near(em(-10.0), 10.0), "{:?}", em(-10.0));
|
||||
@@ -298,6 +298,6 @@ fn negative_crop_sides_are_no_crop() {
|
||||
#[test]
|
||||
fn metafile_text_cell_spans_backward_advances() {
|
||||
let glyphs = [(0, 500.0, 0.0, 0.0), (1, 500.0, 0.0, 0.0)];
|
||||
let lay = crate::metafile_text_layout(&meta_text(-10.0, vec![50.0, -40.0]), 1000.0, 800.0, 200.0, &glyphs).expect("a layout");
|
||||
let lay = crate::layout_metafile_text(&meta_text(-10.0, vec![50.0, -40.0]), 1000.0, 800.0, 200.0, &glyphs).expect("a layout");
|
||||
assert_eq!(lay.cell, [0.0, -8.0, 50.0, 2.0]);
|
||||
}
|
||||
Reference in new issue
Block a user