summaryrefslogtreecommitdiffstats
path: root/tiny_skia/src/backend.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-01-19 20:41:52 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-01-19 20:41:52 +0100
commit1781068e1c3a65551db1e832fdbaddba99124051 (patch)
tree60e0b3854cc0541712572fbb0e56f14435951ea9 /tiny_skia/src/backend.rs
parent41dec5bd203ff5b1574a33a17d5f7358ae1beea2 (diff)
parent7ae7fcb89855002519bab752fd3686106ce448db (diff)
downloadiced-1781068e1c3a65551db1e832fdbaddba99124051.tar.gz
iced-1781068e1c3a65551db1e832fdbaddba99124051.tar.bz2
iced-1781068e1c3a65551db1e832fdbaddba99124051.zip
Merge branch 'master' into remove-vertex-indexing
Diffstat (limited to 'tiny_skia/src/backend.rs')
-rw-r--r--tiny_skia/src/backend.rs102
1 files changed, 82 insertions, 20 deletions
diff --git a/tiny_skia/src/backend.rs b/tiny_skia/src/backend.rs
index 65aca4b0..d1393b4d 100644
--- a/tiny_skia/src/backend.rs
+++ b/tiny_skia/src/backend.rs
@@ -1,7 +1,7 @@
use crate::core::{Background, Color, Gradient, Rectangle, Vector};
use crate::graphics::backend;
use crate::graphics::text;
-use crate::graphics::{Damage, Viewport};
+use crate::graphics::Viewport;
use crate::primitive::{self, Primitive};
use std::borrow::Cow;
@@ -362,11 +362,10 @@ impl Backend {
paragraph,
position,
color,
+ clip_bounds: text_clip_bounds,
} => {
let physical_bounds =
- (Rectangle::new(*position, paragraph.min_bounds)
- + translation)
- * scale_factor;
+ (*text_clip_bounds + translation) * scale_factor;
if !clip_bounds.intersects(&physical_bounds) {
return;
@@ -384,6 +383,31 @@ impl Backend {
clip_mask,
);
}
+ Primitive::Editor {
+ editor,
+ position,
+ color,
+ clip_bounds: text_clip_bounds,
+ } => {
+ let physical_bounds =
+ (*text_clip_bounds + translation) * scale_factor;
+
+ if !clip_bounds.intersects(&physical_bounds) {
+ return;
+ }
+
+ let clip_mask = (!physical_bounds.is_within(&clip_bounds))
+ .then_some(clip_mask as &_);
+
+ self.text_pipeline.draw_editor(
+ editor,
+ *position + translation,
+ *color,
+ scale_factor,
+ pixels,
+ clip_mask,
+ );
+ }
Primitive::Text {
content,
bounds,
@@ -394,9 +418,10 @@ impl Backend {
horizontal_alignment,
vertical_alignment,
shaping,
+ clip_bounds: text_clip_bounds,
} => {
let physical_bounds =
- (primitive.bounds() + translation) * scale_factor;
+ (*text_clip_bounds + translation) * scale_factor;
if !clip_bounds.intersects(&physical_bounds) {
return;
@@ -420,8 +445,41 @@ impl Backend {
clip_mask,
);
}
+ Primitive::RawText(text::Raw {
+ buffer,
+ position,
+ color,
+ clip_bounds: text_clip_bounds,
+ }) => {
+ let Some(buffer) = buffer.upgrade() else {
+ return;
+ };
+
+ let physical_bounds =
+ (*text_clip_bounds + translation) * scale_factor;
+
+ if !clip_bounds.intersects(&physical_bounds) {
+ return;
+ }
+
+ let clip_mask = (!physical_bounds.is_within(&clip_bounds))
+ .then_some(clip_mask as &_);
+
+ self.text_pipeline.draw_raw(
+ &buffer,
+ *position + translation,
+ *color,
+ scale_factor,
+ pixels,
+ clip_mask,
+ );
+ }
#[cfg(feature = "image")]
- Primitive::Image { handle, bounds } => {
+ Primitive::Image {
+ handle,
+ filter_method,
+ bounds,
+ } => {
let physical_bounds = (*bounds + translation) * scale_factor;
if !clip_bounds.intersects(&physical_bounds) {
@@ -437,8 +495,14 @@ impl Backend {
)
.post_scale(scale_factor, scale_factor);
- self.raster_pipeline
- .draw(handle, *bounds, pixels, transform, clip_mask);
+ self.raster_pipeline.draw(
+ handle,
+ *filter_method,
+ *bounds,
+ pixels,
+ transform,
+ clip_mask,
+ );
}
#[cfg(not(feature = "image"))]
Primitive::Image { .. } => {
@@ -479,7 +543,6 @@ impl Backend {
path,
paint,
rule,
- transform,
}) => {
let bounds = path.bounds();
@@ -502,9 +565,11 @@ impl Backend {
path,
paint,
*rule,
- transform
- .post_translate(translation.x, translation.y)
- .post_scale(scale_factor, scale_factor),
+ tiny_skia::Transform::from_translate(
+ translation.x,
+ translation.y,
+ )
+ .post_scale(scale_factor, scale_factor),
clip_mask,
);
}
@@ -512,7 +577,6 @@ impl Backend {
path,
paint,
stroke,
- transform,
}) => {
let bounds = path.bounds();
@@ -535,9 +599,11 @@ impl Backend {
path,
paint,
stroke,
- transform
- .post_translate(translation.x, translation.y)
- .post_scale(scale_factor, scale_factor),
+ tiny_skia::Transform::from_translate(
+ translation.x,
+ translation.y,
+ )
+ .post_scale(scale_factor, scale_factor),
clip_mask,
);
}
@@ -803,10 +869,6 @@ impl iced_graphics::Backend for Backend {
}
impl backend::Text for Backend {
- fn font_system(&self) -> &text::FontSystem {
- self.text_pipeline.font_system()
- }
-
fn load_font(&mut self, font: Cow<'static, [u8]>) {
self.text_pipeline.load_font(font);
}