From 65f11dc364ece630bcecf6ef53b75697f07553a8 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Fri, 30 Jun 2023 09:59:58 +0200 Subject: [PATCH] Minor improvements --- library/src/meta/counter.rs | 4 ++-- library/src/meta/reference.rs | 2 +- src/export/render.rs | 28 ++++++++++++++++++++++------ src/ide/analyze.rs | 1 + tests/typ/compiler/hint.typ | 2 +- 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/library/src/meta/counter.rs b/library/src/meta/counter.rs index 4825bc65c..9a223b328 100644 --- a/library/src/meta/counter.rs +++ b/library/src/meta/counter.rs @@ -634,8 +634,8 @@ impl Show for DisplayElem { .numbering() .or_else(|| { let CounterKey::Selector(Selector::Elem(func, _)) = counter.0 else { - return None; - }; + return None; + }; if func == HeadingElem::func() { HeadingElem::numbering_in(styles) diff --git a/library/src/meta/reference.rs b/library/src/meta/reference.rs index c39f8ca0d..5bd044319 100644 --- a/library/src/meta/reference.rs +++ b/library/src/meta/reference.rs @@ -189,7 +189,7 @@ impl Show for RefElem { ) }) .hint(eco_format!( - "you can enable heading numbering with `#set {}(numbering: \"1.\")`?", + "you can enable heading numbering with `#set {}(numbering: \"1.\")`", elem.func().name() )) .at(span)?; diff --git a/src/export/render.rs b/src/export/render.rs index ef0fc9f22..d8115b127 100644 --- a/src/export/render.rs +++ b/src/export/render.rs @@ -5,12 +5,14 @@ use std::sync::Arc; use image::imageops::FilterType; use image::{GenericImageView, Rgba}; +use pixglyph::Bitmap; use resvg::FitTo; use tiny_skia as sk; use ttf_parser::{GlyphId, OutlineBuilder}; use usvg::{NodeExt, TreeParsing}; use crate::doc::{Frame, FrameItem, GroupItem, Meta, TextItem}; +use crate::font::Font; use crate::geom::{ self, Abs, Color, Geometry, LineCap, LineJoin, Paint, PathItem, Shape, Size, Stroke, Transform, @@ -297,10 +299,26 @@ fn render_outline_glyph( } // Rasterize the glyph with `pixglyph`. + #[comemo::memoize] + fn rasterize( + font: &Font, + id: GlyphId, + x: u32, + y: u32, + size: u32, + ) -> Option> { + let glyph = pixglyph::Glyph::load(font.ttf(), id)?; + Some(Arc::new(glyph.rasterize( + f32::from_bits(x), + f32::from_bits(y), + f32::from_bits(size), + ))) + } + // Try to retrieve a prepared glyph or prepare it from scratch if it // doesn't exist, yet. - let glyph = pixglyph::Glyph::load(text.font.ttf(), id)?; - let bitmap = glyph.rasterize(ts.tx, ts.ty, ppem); + let bitmap = + rasterize(&text.font, id, ts.tx.to_bits(), ts.ty.to_bits(), ppem.to_bits())?; // If we have a clip mask we first render to a pixmap that we then blend // with our canvas @@ -333,8 +351,6 @@ fn render_outline_glyph( sk::Transform::identity(), mask, ); - - Some(()) } else { let cw = canvas.width() as i32; let ch = canvas.height() as i32; @@ -372,9 +388,9 @@ fn render_outline_glyph( pixels[pi] = blend_src_over(applied, pixels[pi]); } } - - Some(()) } + + Some(()) } /// Render a geometrical shape into the canvas. diff --git a/src/ide/analyze.rs b/src/ide/analyze.rs index 55ec82819..dad466c18 100644 --- a/src/ide/analyze.rs +++ b/src/ide/analyze.rs @@ -89,6 +89,7 @@ pub fn analyze_labels( let Some(label) = elem.label().cloned() else { continue }; let details = elem .field("caption") + .or_else(|| elem.field("body")) .and_then(|field| match field { Value::Content(content) => Some(content), _ => None, diff --git a/tests/typ/compiler/hint.typ b/tests/typ/compiler/hint.typ index fdd5f59b3..6b60eafb8 100644 --- a/tests/typ/compiler/hint.typ +++ b/tests/typ/compiler/hint.typ @@ -25,7 +25,7 @@ = Heading // Error: 1:20-1:26 cannot reference heading without numbering -// Hint: 1:20-1:26 you can enable heading numbering with `#set heading(numbering: "1.")`? +// Hint: 1:20-1:26 you can enable heading numbering with `#set heading(numbering: "1.")` Can not be used as @intro ---