summaryrefslogtreecommitdiffstats
path: root/tiny_skia/src/backend.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tiny_skia/src/backend.rs')
-rw-r--r--tiny_skia/src/backend.rs105
1 files changed, 42 insertions, 63 deletions
diff --git a/tiny_skia/src/backend.rs b/tiny_skia/src/backend.rs
index a8add70b..ef587bac 100644
--- a/tiny_skia/src/backend.rs
+++ b/tiny_skia/src/backend.rs
@@ -1,16 +1,12 @@
-use crate::core::text;
-use crate::core::Gradient;
-use crate::core::{Background, Color, Font, Point, Rectangle, Size, Vector};
+use crate::core::{Background, Color, Gradient, Rectangle, Vector};
use crate::graphics::backend;
+use crate::graphics::text;
use crate::graphics::{Damage, Viewport};
use crate::primitive::{self, Primitive};
-use crate::Settings;
use std::borrow::Cow;
pub struct Backend {
- default_font: Font,
- default_text_size: f32,
text_pipeline: crate::text::Pipeline,
#[cfg(feature = "image")]
@@ -21,10 +17,8 @@ pub struct Backend {
}
impl Backend {
- pub fn new(settings: Settings) -> Self {
+ pub fn new() -> Self {
Self {
- default_font: settings.default_font,
- default_text_size: settings.default_text_size,
text_pipeline: crate::text::Pipeline::new(),
#[cfg(feature = "image")]
@@ -364,6 +358,32 @@ impl Backend {
}
}
}
+ Primitive::Paragraph {
+ paragraph,
+ position,
+ color,
+ } => {
+ let physical_bounds =
+ (Rectangle::new(*position, paragraph.min_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_paragraph(
+ paragraph,
+ *position + translation,
+ *color,
+ scale_factor,
+ pixels,
+ clip_mask,
+ );
+ }
Primitive::Text {
content,
bounds,
@@ -599,6 +619,12 @@ impl Backend {
}
}
+impl Default for Backend {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
fn into_color(color: Color) -> tiny_skia::Color {
tiny_skia::Color::from_rgba(color.b, color.g, color.r, color.a)
.expect("Convert color from iced to tiny_skia")
@@ -779,58 +805,8 @@ impl iced_graphics::Backend for Backend {
}
impl backend::Text for Backend {
- const ICON_FONT: Font = Font::with_name("Iced-Icons");
- const CHECKMARK_ICON: char = '\u{f00c}';
- const ARROW_DOWN_ICON: char = '\u{e800}';
-
- fn default_font(&self) -> Font {
- self.default_font
- }
-
- fn default_size(&self) -> f32 {
- self.default_text_size
- }
-
- fn measure(
- &self,
- contents: &str,
- size: f32,
- line_height: text::LineHeight,
- font: Font,
- bounds: Size,
- shaping: text::Shaping,
- ) -> Size {
- self.text_pipeline.measure(
- contents,
- size,
- line_height,
- font,
- bounds,
- shaping,
- )
- }
-
- fn hit_test(
- &self,
- contents: &str,
- size: f32,
- line_height: text::LineHeight,
- font: Font,
- bounds: Size,
- shaping: text::Shaping,
- point: Point,
- nearest_only: bool,
- ) -> Option<text::Hit> {
- self.text_pipeline.hit_test(
- contents,
- size,
- line_height,
- font,
- bounds,
- shaping,
- point,
- nearest_only,
- )
+ fn font_system(&self) -> &text::FontSystem {
+ self.text_pipeline.font_system()
}
fn load_font(&mut self, font: Cow<'static, [u8]>) {
@@ -840,7 +816,10 @@ impl backend::Text for Backend {
#[cfg(feature = "image")]
impl backend::Image for Backend {
- fn dimensions(&self, handle: &crate::core::image::Handle) -> Size<u32> {
+ fn dimensions(
+ &self,
+ handle: &crate::core::image::Handle,
+ ) -> crate::core::Size<u32> {
self.raster_pipeline.dimensions(handle)
}
}
@@ -850,7 +829,7 @@ impl backend::Svg for Backend {
fn viewport_dimensions(
&self,
handle: &crate::core::svg::Handle,
- ) -> Size<u32> {
+ ) -> crate::core::Size<u32> {
self.vector_pipeline.viewport_dimensions(handle)
}
}