Minor improvements

This commit is contained in:
Laurenz 2023-06-30 09:59:58 +02:00
parent 82b893ec0e
commit 65f11dc364
5 changed files with 27 additions and 10 deletions

View File

@ -634,8 +634,8 @@ impl Show for DisplayElem {
.numbering() .numbering()
.or_else(|| { .or_else(|| {
let CounterKey::Selector(Selector::Elem(func, _)) = counter.0 else { let CounterKey::Selector(Selector::Elem(func, _)) = counter.0 else {
return None; return None;
}; };
if func == HeadingElem::func() { if func == HeadingElem::func() {
HeadingElem::numbering_in(styles) HeadingElem::numbering_in(styles)

View File

@ -189,7 +189,7 @@ impl Show for RefElem {
) )
}) })
.hint(eco_format!( .hint(eco_format!(
"you can enable heading numbering with `#set {}(numbering: \"1.\")`?", "you can enable heading numbering with `#set {}(numbering: \"1.\")`",
elem.func().name() elem.func().name()
)) ))
.at(span)?; .at(span)?;

View File

@ -5,12 +5,14 @@ use std::sync::Arc;
use image::imageops::FilterType; use image::imageops::FilterType;
use image::{GenericImageView, Rgba}; use image::{GenericImageView, Rgba};
use pixglyph::Bitmap;
use resvg::FitTo; use resvg::FitTo;
use tiny_skia as sk; use tiny_skia as sk;
use ttf_parser::{GlyphId, OutlineBuilder}; use ttf_parser::{GlyphId, OutlineBuilder};
use usvg::{NodeExt, TreeParsing}; use usvg::{NodeExt, TreeParsing};
use crate::doc::{Frame, FrameItem, GroupItem, Meta, TextItem}; use crate::doc::{Frame, FrameItem, GroupItem, Meta, TextItem};
use crate::font::Font;
use crate::geom::{ use crate::geom::{
self, Abs, Color, Geometry, LineCap, LineJoin, Paint, PathItem, Shape, Size, Stroke, self, Abs, Color, Geometry, LineCap, LineJoin, Paint, PathItem, Shape, Size, Stroke,
Transform, Transform,
@ -297,10 +299,26 @@ fn render_outline_glyph(
} }
// Rasterize the glyph with `pixglyph`. // Rasterize the glyph with `pixglyph`.
#[comemo::memoize]
fn rasterize(
font: &Font,
id: GlyphId,
x: u32,
y: u32,
size: u32,
) -> Option<Arc<Bitmap>> {
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 // Try to retrieve a prepared glyph or prepare it from scratch if it
// doesn't exist, yet. // doesn't exist, yet.
let glyph = pixglyph::Glyph::load(text.font.ttf(), id)?; let bitmap =
let bitmap = glyph.rasterize(ts.tx, ts.ty, ppem); 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 // If we have a clip mask we first render to a pixmap that we then blend
// with our canvas // with our canvas
@ -333,8 +351,6 @@ fn render_outline_glyph(
sk::Transform::identity(), sk::Transform::identity(),
mask, mask,
); );
Some(())
} else { } else {
let cw = canvas.width() as i32; let cw = canvas.width() as i32;
let ch = canvas.height() as i32; let ch = canvas.height() as i32;
@ -372,9 +388,9 @@ fn render_outline_glyph(
pixels[pi] = blend_src_over(applied, pixels[pi]); pixels[pi] = blend_src_over(applied, pixels[pi]);
} }
} }
Some(())
} }
Some(())
} }
/// Render a geometrical shape into the canvas. /// Render a geometrical shape into the canvas.

View File

@ -89,6 +89,7 @@ pub fn analyze_labels(
let Some(label) = elem.label().cloned() else { continue }; let Some(label) = elem.label().cloned() else { continue };
let details = elem let details = elem
.field("caption") .field("caption")
.or_else(|| elem.field("body"))
.and_then(|field| match field { .and_then(|field| match field {
Value::Content(content) => Some(content), Value::Content(content) => Some(content),
_ => None, _ => None,

View File

@ -25,7 +25,7 @@
= Heading <intro> = Heading <intro>
// Error: 1:20-1:26 cannot reference heading without numbering // 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 Can not be used as @intro
--- ---