From da3c4c8cd1b39e1a5f77b1fd8d30828e9675cf62 Mon Sep 17 00:00:00 2001 From: Leon Teichroeb Date: Sat, 12 Oct 2024 13:52:41 +0200 Subject: [PATCH] Add failing test for #252 --- tests/tests.rs | 58 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/tests/tests.rs b/tests/tests.rs index 6f4d83b..25fe61c 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -778,7 +778,7 @@ pub fn rasterize_glyph_with_full_hinting() { RasterizationOptions::Bilevel, ) .unwrap(); - let origin = -raster_rect.origin().to_f32(); + let origin: Vector2F = -raster_rect.origin().to_f32(); let mut canvas = Canvas::new(raster_rect.size(), Format::A8); font.rasterize_glyph( &mut canvas, @@ -808,6 +808,61 @@ pub fn rasterize_glyph_with_full_hinting() { } } +// https://github.com/servo/font-kit/issues/252 +// Panic when targeting Canvas larger than glyph with SubpixelAa option in Freetype. +#[cfg(all( + feature = "source", + any( + not(any(target_os = "macos", target_os = "ios", target_family = "windows")), + feature = "loader-freetype-default" + ) +))] +#[test] +pub fn rasterize_glyph_with_full_hinting_subpixel() { + let font = SystemSource::new() + .select_best_match(&[FamilyName::SansSerif], &Properties::new()) + .unwrap() + .load() + .unwrap(); + let glyph_id = font.glyph_for_char('L').unwrap(); + let size = 32.0; + let raster_rect = font + .raster_bounds( + glyph_id, + size, + Transform2F::default(), + HintingOptions::Full(size), + RasterizationOptions::SubpixelAa, + ) + .unwrap(); + let origin: Vector2F = -raster_rect.origin().to_f32(); + let mut canvas = Canvas::new(raster_rect.size(), Format::Rgb24); + font.rasterize_glyph( + &mut canvas, + glyph_id, + size, + Transform2F::from_translation(origin), + HintingOptions::Full(size), + RasterizationOptions::SubpixelAa, + ) + .unwrap(); + check_L_shape(&canvas); + + // Test with larger canvas + let mut canvas = Canvas::new(Vector2I::new(100, 100), Format::Rgb24); + font.rasterize_glyph( + &mut canvas, + glyph_id, + size, + Transform2F::from_translation(origin), + HintingOptions::Full(size), + RasterizationOptions::SubpixelAa, + ) + .unwrap(); + check_L_shape(&canvas); +} + + #[cfg(all(feature = "source", target_family = "windows"))] #[test] pub fn rasterize_glyph() { @@ -888,6 +943,7 @@ pub fn rasterize_empty_glyph_on_empty_canvas() { .unwrap(); } + #[cfg(feature = "source")] #[test] pub fn font_transform() {