mirror of
https://github.com/typst/typst
synced 2025-05-15 01:25:28 +08:00
Minor improvements
This commit is contained in:
parent
82b893ec0e
commit
65f11dc364
@ -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)?;
|
||||||
|
@ -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,10 +388,10 @@ 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.
|
||||||
fn render_shape(
|
fn render_shape(
|
||||||
|
@ -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,
|
||||||
|
@ -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
|
||||||
|
|
||||||
---
|
---
|
||||||
|
Loading…
x
Reference in New Issue
Block a user