mirror of
https://github.com/typst/typst
synced 2025-05-13 12:36:23 +08:00
Merge branch 'main' into ng
This commit is contained in:
commit
2720a44b96
@ -103,7 +103,7 @@ impl<'a> ShapedText<'a> {
|
||||
for ((font, y_offset), group) in
|
||||
self.glyphs.as_ref().group_by_key(|g| (g.font.clone(), g.y_offset))
|
||||
{
|
||||
let pos = Point::new(offset, top + shift + y_offset.at(self.size));
|
||||
let pos = Point::new(offset, top + shift - y_offset.at(self.size));
|
||||
let glyphs = group
|
||||
.iter()
|
||||
.map(|glyph| Glyph {
|
||||
|
@ -11,7 +11,7 @@ use usvg::FitTo;
|
||||
|
||||
use crate::doc::{Element, Frame, Group, Meta, Text};
|
||||
use crate::geom::{
|
||||
self, Abs, Geometry, Paint, PathElement, Shape, Size, Stroke, Transform,
|
||||
self, Abs, Color, Geometry, Paint, PathElement, Shape, Size, Stroke, Transform,
|
||||
};
|
||||
use crate::image::{DecodedImage, Image};
|
||||
|
||||
@ -19,13 +19,13 @@ use crate::image::{DecodedImage, Image};
|
||||
///
|
||||
/// This renders the frame at the given number of pixels per point and returns
|
||||
/// the resulting `tiny-skia` pixel buffer.
|
||||
pub fn render(frame: &Frame, pixel_per_pt: f32) -> sk::Pixmap {
|
||||
pub fn render(frame: &Frame, pixel_per_pt: f32, fill: Color) -> sk::Pixmap {
|
||||
let size = frame.size();
|
||||
let pxw = (pixel_per_pt * size.x.to_f32()).round().max(1.0) as u32;
|
||||
let pxh = (pixel_per_pt * size.y.to_f32()).round().max(1.0) as u32;
|
||||
|
||||
let mut canvas = sk::Pixmap::new(pxw, pxh).unwrap();
|
||||
canvas.fill(sk::Color::WHITE);
|
||||
canvas.fill(fill.into());
|
||||
|
||||
let ts = sk::Transform::from_scale(pixel_per_pt, pixel_per_pt);
|
||||
render_frame(&mut canvas, ts, None, frame);
|
||||
@ -432,13 +432,19 @@ impl From<Paint> for sk::Paint<'static> {
|
||||
fn from(paint: Paint) -> Self {
|
||||
let mut sk_paint = sk::Paint::default();
|
||||
let Paint::Solid(color) = paint;
|
||||
let c = color.to_rgba();
|
||||
sk_paint.set_color_rgba8(c.r, c.g, c.b, c.a);
|
||||
sk_paint.set_color(color.into());
|
||||
sk_paint.anti_alias = true;
|
||||
sk_paint
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Color> for sk::Color {
|
||||
fn from(color: Color) -> Self {
|
||||
let c = color.to_rgba();
|
||||
sk::Color::from_rgba8(c.r, c.g, c.b, c.a)
|
||||
}
|
||||
}
|
||||
|
||||
/// Allows to build tiny-skia paths from glyph outlines.
|
||||
struct WrappedPathBuilder(sk::PathBuilder);
|
||||
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 105 KiB After Width: | Height: | Size: 105 KiB |
Binary file not shown.
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 25 KiB |
Binary file not shown.
Before Width: | Height: | Size: 46 KiB After Width: | Height: | Size: 46 KiB |
@ -5,6 +5,7 @@ use iai::{black_box, main, Iai};
|
||||
use typst::diag::{FileError, FileResult};
|
||||
use typst::eval::Library;
|
||||
use typst::font::{Font, FontBook};
|
||||
use typst::geom::Color;
|
||||
use typst::syntax::{Source, SourceId};
|
||||
use typst::util::Buffer;
|
||||
use typst::World;
|
||||
@ -90,7 +91,7 @@ fn bench_compile(iai: &mut Iai) {
|
||||
fn bench_render(iai: &mut Iai) {
|
||||
let world = BenchWorld::new();
|
||||
let document = typst::compile(&world, &world.source).unwrap();
|
||||
iai.run(|| typst::export::render(&document.pages[0], 1.0))
|
||||
iai.run(|| typst::export::render(&document.pages[0], 1.0, Color::WHITE))
|
||||
}
|
||||
|
||||
struct BenchWorld {
|
||||
|
@ -690,7 +690,7 @@ fn render(frames: &[Frame]) -> sk::Pixmap {
|
||||
if frame.width() > limit || frame.height() > limit {
|
||||
panic!("overlarge frame: {:?}", frame.size());
|
||||
}
|
||||
typst::export::render(frame, pixel_per_pt)
|
||||
typst::export::render(frame, pixel_per_pt, Color::WHITE)
|
||||
})
|
||||
.collect();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user