Introduce with_transformation to Renderer trait
This commit is contained in:
parent
a6e91d13d5
commit
f4d6648601
31 changed files with 161 additions and 118 deletions
|
|
@ -1,9 +1,11 @@
|
|||
use tiny_skia::Size;
|
||||
|
||||
use crate::core::{Background, Color, Gradient, Rectangle, Vector};
|
||||
use crate::core::{
|
||||
Background, Color, Gradient, Rectangle, Transformation, Vector,
|
||||
};
|
||||
use crate::graphics::backend;
|
||||
use crate::graphics::text;
|
||||
use crate::graphics::{Transformation, Viewport};
|
||||
use crate::graphics::Viewport;
|
||||
use crate::primitive::{self, Primitive};
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
|
@ -459,11 +461,12 @@ impl Backend {
|
|||
|
||||
self.text_pipeline.draw_paragraph(
|
||||
paragraph,
|
||||
*position * transformation,
|
||||
*position,
|
||||
*color,
|
||||
scale_factor * transformation.scale_factor(),
|
||||
scale_factor,
|
||||
pixels,
|
||||
clip_mask,
|
||||
transformation,
|
||||
);
|
||||
}
|
||||
Primitive::Editor {
|
||||
|
|
@ -484,11 +487,12 @@ impl Backend {
|
|||
|
||||
self.text_pipeline.draw_editor(
|
||||
editor,
|
||||
*position * transformation,
|
||||
*position,
|
||||
*color,
|
||||
scale_factor,
|
||||
pixels,
|
||||
clip_mask,
|
||||
transformation,
|
||||
);
|
||||
}
|
||||
Primitive::Text {
|
||||
|
|
@ -515,7 +519,7 @@ impl Backend {
|
|||
|
||||
self.text_pipeline.draw_cached(
|
||||
content,
|
||||
*bounds * transformation,
|
||||
*bounds,
|
||||
*color,
|
||||
*size,
|
||||
*line_height,
|
||||
|
|
@ -523,9 +527,10 @@ impl Backend {
|
|||
*horizontal_alignment,
|
||||
*vertical_alignment,
|
||||
*shaping,
|
||||
scale_factor * transformation.scale_factor(),
|
||||
scale_factor,
|
||||
pixels,
|
||||
clip_mask,
|
||||
transformation,
|
||||
);
|
||||
}
|
||||
Primitive::RawText(text::Raw {
|
||||
|
|
@ -550,11 +555,12 @@ impl Backend {
|
|||
|
||||
self.text_pipeline.draw_raw(
|
||||
&buffer,
|
||||
*position * transformation,
|
||||
*position,
|
||||
*color,
|
||||
scale_factor,
|
||||
pixels,
|
||||
clip_mask,
|
||||
transformation,
|
||||
);
|
||||
}
|
||||
#[cfg(feature = "image")]
|
||||
|
|
@ -769,13 +775,15 @@ fn into_color(color: Color) -> tiny_skia::Color {
|
|||
}
|
||||
|
||||
fn into_transform(transformation: Transformation) -> tiny_skia::Transform {
|
||||
let translation = transformation.translation();
|
||||
|
||||
tiny_skia::Transform {
|
||||
sx: transformation.scale_factor(),
|
||||
kx: 0.0,
|
||||
ky: 0.0,
|
||||
sy: transformation.scale_factor(),
|
||||
tx: transformation.translation_x(),
|
||||
ty: transformation.translation_y(),
|
||||
tx: translation.x,
|
||||
ty: translation.y,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
use crate::core::text::LineHeight;
|
||||
use crate::core::{Pixels, Point, Rectangle, Size, Vector};
|
||||
use crate::core::{Pixels, Point, Rectangle, Size, Transformation, Vector};
|
||||
use crate::graphics::geometry::fill::{self, Fill};
|
||||
use crate::graphics::geometry::stroke::{self, Stroke};
|
||||
use crate::graphics::geometry::{Path, Style, Text};
|
||||
use crate::graphics::{Gradient, Transformation};
|
||||
use crate::graphics::Gradient;
|
||||
use crate::primitive::{self, Primitive};
|
||||
|
||||
pub struct Frame {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
use crate::core::alignment;
|
||||
use crate::core::text::{LineHeight, Shaping};
|
||||
use crate::core::{Color, Font, Pixels, Point, Rectangle, Size};
|
||||
use crate::core::{
|
||||
Color, Font, Pixels, Point, Rectangle, Size, Transformation,
|
||||
};
|
||||
use crate::graphics::text::cache::{self, Cache};
|
||||
use crate::graphics::text::editor;
|
||||
use crate::graphics::text::font_system;
|
||||
|
|
@ -42,6 +44,7 @@ impl Pipeline {
|
|||
scale_factor: f32,
|
||||
pixels: &mut tiny_skia::PixmapMut<'_>,
|
||||
clip_mask: Option<&tiny_skia::Mask>,
|
||||
transformation: Transformation,
|
||||
) {
|
||||
use crate::core::text::Paragraph as _;
|
||||
|
||||
|
|
@ -62,6 +65,7 @@ impl Pipeline {
|
|||
scale_factor,
|
||||
pixels,
|
||||
clip_mask,
|
||||
transformation,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -73,6 +77,7 @@ impl Pipeline {
|
|||
scale_factor: f32,
|
||||
pixels: &mut tiny_skia::PixmapMut<'_>,
|
||||
clip_mask: Option<&tiny_skia::Mask>,
|
||||
transformation: Transformation,
|
||||
) {
|
||||
use crate::core::text::Editor as _;
|
||||
|
||||
|
|
@ -93,6 +98,7 @@ impl Pipeline {
|
|||
scale_factor,
|
||||
pixels,
|
||||
clip_mask,
|
||||
transformation,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -110,6 +116,7 @@ impl Pipeline {
|
|||
scale_factor: f32,
|
||||
pixels: &mut tiny_skia::PixmapMut<'_>,
|
||||
clip_mask: Option<&tiny_skia::Mask>,
|
||||
transformation: Transformation,
|
||||
) {
|
||||
let line_height = f32::from(line_height.to_absolute(size));
|
||||
|
||||
|
|
@ -145,6 +152,7 @@ impl Pipeline {
|
|||
scale_factor,
|
||||
pixels,
|
||||
clip_mask,
|
||||
transformation,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -156,6 +164,7 @@ impl Pipeline {
|
|||
scale_factor: f32,
|
||||
pixels: &mut tiny_skia::PixmapMut<'_>,
|
||||
clip_mask: Option<&tiny_skia::Mask>,
|
||||
transformation: Transformation,
|
||||
) {
|
||||
let mut font_system = font_system().write().expect("Write font system");
|
||||
|
||||
|
|
@ -172,6 +181,7 @@ impl Pipeline {
|
|||
scale_factor,
|
||||
pixels,
|
||||
clip_mask,
|
||||
transformation,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -192,8 +202,9 @@ fn draw(
|
|||
scale_factor: f32,
|
||||
pixels: &mut tiny_skia::PixmapMut<'_>,
|
||||
clip_mask: Option<&tiny_skia::Mask>,
|
||||
transformation: Transformation,
|
||||
) {
|
||||
let bounds = bounds * scale_factor;
|
||||
let bounds = bounds * transformation * scale_factor;
|
||||
|
||||
let x = match horizontal_alignment {
|
||||
alignment::Horizontal::Left => bounds.x,
|
||||
|
|
@ -211,7 +222,8 @@ fn draw(
|
|||
|
||||
for run in buffer.layout_runs() {
|
||||
for glyph in run.glyphs {
|
||||
let physical_glyph = glyph.physical((x, y), scale_factor);
|
||||
let physical_glyph = glyph
|
||||
.physical((x, y), scale_factor * transformation.scale_factor());
|
||||
|
||||
if let Some((buffer, placement)) = glyph_cache.allocate(
|
||||
physical_glyph.cache_key,
|
||||
|
|
@ -229,7 +241,10 @@ fn draw(
|
|||
pixels.draw_pixmap(
|
||||
physical_glyph.x + placement.left,
|
||||
physical_glyph.y - placement.top
|
||||
+ (run.line_y * scale_factor).round() as i32,
|
||||
+ (run.line_y
|
||||
* scale_factor
|
||||
* transformation.scale_factor())
|
||||
.round() as i32,
|
||||
pixmap,
|
||||
&tiny_skia::PixmapPaint::default(),
|
||||
tiny_skia::Transform::identity(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue