summaryrefslogtreecommitdiffstats
path: root/tiny_skia
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2023-10-24 05:34:03 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-02-02 02:24:45 +0100
commitf4d66486016076bb339a338bc589645119962d1e (patch)
treebbb9c4d996216893296cf4323857323542d6e757 /tiny_skia
parenta6e91d13d5d43796d0e6bb570fb4f010cf27921a (diff)
downloadiced-f4d66486016076bb339a338bc589645119962d1e.tar.gz
iced-f4d66486016076bb339a338bc589645119962d1e.tar.bz2
iced-f4d66486016076bb339a338bc589645119962d1e.zip
Introduce `with_transformation` to `Renderer` trait
Diffstat (limited to 'tiny_skia')
-rw-r--r--tiny_skia/src/backend.rs28
-rw-r--r--tiny_skia/src/geometry.rs4
-rw-r--r--tiny_skia/src/text.rs23
3 files changed, 39 insertions, 16 deletions
diff --git a/tiny_skia/src/backend.rs b/tiny_skia/src/backend.rs
index 9c03818f..44f5c151 100644
--- a/tiny_skia/src/backend.rs
+++ b/tiny_skia/src/backend.rs
@@ -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,
}
}
diff --git a/tiny_skia/src/geometry.rs b/tiny_skia/src/geometry.rs
index 579c153a..f7518731 100644
--- a/tiny_skia/src/geometry.rs
+++ b/tiny_skia/src/geometry.rs
@@ -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 {
diff --git a/tiny_skia/src/text.rs b/tiny_skia/src/text.rs
index 9413e311..c16037cf 100644
--- a/tiny_skia/src/text.rs
+++ b/tiny_skia/src/text.rs
@@ -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(),