Merge branch 'main' into ng

This commit is contained in:
Martin Haug 2023-03-12 09:58:47 +01:00
commit 2720a44b96
7 changed files with 15 additions and 8 deletions

View File

@ -103,7 +103,7 @@ impl<'a> ShapedText<'a> {
for ((font, y_offset), group) in for ((font, y_offset), group) in
self.glyphs.as_ref().group_by_key(|g| (g.font.clone(), g.y_offset)) 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 let glyphs = group
.iter() .iter()
.map(|glyph| Glyph { .map(|glyph| Glyph {

View File

@ -11,7 +11,7 @@ use usvg::FitTo;
use crate::doc::{Element, Frame, Group, Meta, Text}; use crate::doc::{Element, Frame, Group, Meta, Text};
use crate::geom::{ 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}; 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 /// This renders the frame at the given number of pixels per point and returns
/// the resulting `tiny-skia` pixel buffer. /// 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 size = frame.size();
let pxw = (pixel_per_pt * size.x.to_f32()).round().max(1.0) as u32; 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 pxh = (pixel_per_pt * size.y.to_f32()).round().max(1.0) as u32;
let mut canvas = sk::Pixmap::new(pxw, pxh).unwrap(); 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); let ts = sk::Transform::from_scale(pixel_per_pt, pixel_per_pt);
render_frame(&mut canvas, ts, None, frame); render_frame(&mut canvas, ts, None, frame);
@ -432,13 +432,19 @@ impl From<Paint> for sk::Paint<'static> {
fn from(paint: Paint) -> Self { fn from(paint: Paint) -> Self {
let mut sk_paint = sk::Paint::default(); let mut sk_paint = sk::Paint::default();
let Paint::Solid(color) = paint; let Paint::Solid(color) = paint;
let c = color.to_rgba(); sk_paint.set_color(color.into());
sk_paint.set_color_rgba8(c.r, c.g, c.b, c.a);
sk_paint.anti_alias = true; sk_paint.anti_alias = true;
sk_paint 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. /// Allows to build tiny-skia paths from glyph outlines.
struct WrappedPathBuilder(sk::PathBuilder); 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

View File

@ -5,6 +5,7 @@ use iai::{black_box, main, Iai};
use typst::diag::{FileError, FileResult}; use typst::diag::{FileError, FileResult};
use typst::eval::Library; use typst::eval::Library;
use typst::font::{Font, FontBook}; use typst::font::{Font, FontBook};
use typst::geom::Color;
use typst::syntax::{Source, SourceId}; use typst::syntax::{Source, SourceId};
use typst::util::Buffer; use typst::util::Buffer;
use typst::World; use typst::World;
@ -90,7 +91,7 @@ fn bench_compile(iai: &mut Iai) {
fn bench_render(iai: &mut Iai) { fn bench_render(iai: &mut Iai) {
let world = BenchWorld::new(); let world = BenchWorld::new();
let document = typst::compile(&world, &world.source).unwrap(); 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 { struct BenchWorld {

View File

@ -690,7 +690,7 @@ fn render(frames: &[Frame]) -> sk::Pixmap {
if frame.width() > limit || frame.height() > limit { if frame.width() > limit || frame.height() > limit {
panic!("overlarge frame: {:?}", frame.size()); panic!("overlarge frame: {:?}", frame.size());
} }
typst::export::render(frame, pixel_per_pt) typst::export::render(frame, pixel_per_pt, Color::WHITE)
}) })
.collect(); .collect();