Introduce Svg struct in core::svg

This commit is contained in:
Héctor Ramón Jiménez 2024-08-04 04:52:55 +02:00
parent 8708101c89
commit d4b08462e5
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
18 changed files with 146 additions and 257 deletions

View file

@ -580,13 +580,7 @@ impl Engine {
);
}
#[cfg(feature = "svg")]
Image::Vector {
handle,
color,
bounds,
rotation,
opacity,
} => {
Image::Vector(svg, bounds) => {
let physical_bounds = *bounds * _transformation;
if !_clip_bounds.intersects(&physical_bounds) {
@ -597,7 +591,7 @@ impl Engine {
.then_some(_clip_mask as &_);
let center = physical_bounds.center();
let radians = f32::from(*rotation);
let radians = f32::from(svg.rotation);
let transform = into_transform(_transformation).post_rotate_at(
radians.to_degrees(),
@ -606,10 +600,10 @@ impl Engine {
);
self.vector_pipeline.draw(
handle,
*color,
&svg.handle,
svg.color,
physical_bounds,
*opacity,
svg.opacity,
_pixels,
transform,
clip_mask,

View file

@ -1,11 +1,10 @@
use crate::core::svg;
use crate::core::text::LineHeight;
use crate::core::{Color, Pixels, Point, Radians, Rectangle, Size, Vector};
use crate::core::{self, Pixels, Point, Radians, Rectangle, Size, Svg, Vector};
use crate::graphics::cache::{self, Cached};
use crate::graphics::geometry::fill::{self, Fill};
use crate::graphics::geometry::stroke::{self, Stroke};
use crate::graphics::geometry::{self, Image, Path, Style};
use crate::graphics::{self, Gradient, Text};
use crate::graphics::geometry::{self, Path, Style};
use crate::graphics::{self, Gradient, Image, Text};
use crate::Primitive;
use std::rc::Rc;
@ -282,7 +281,7 @@ impl geometry::frame::Backend for Frame {
}
}
fn draw_image(&mut self, bounds: Rectangle, image: impl Into<Image>) {
fn draw_image(&mut self, bounds: Rectangle, image: impl Into<core::Image>) {
let mut image = image.into();
let (bounds, external_rotation) =
@ -293,24 +292,15 @@ impl geometry::frame::Backend for Frame {
self.images.push(graphics::Image::Raster(image, bounds));
}
fn draw_svg(
&mut self,
handle: &svg::Handle,
bounds: Rectangle,
color: Option<Color>,
rotation: Radians,
opacity: f32,
) {
fn draw_svg(&mut self, bounds: Rectangle, svg: impl Into<Svg>) {
let mut svg = svg.into();
let (bounds, external_rotation) =
transform_rectangle(bounds, self.transform);
self.images.push(graphics::Image::Vector {
handle: handle.clone(),
bounds,
color,
rotation: rotation + external_rotation,
opacity,
});
svg.rotation += external_rotation;
self.images.push(Image::Vector(svg, bounds));
}
}

View file

@ -1,7 +1,6 @@
use crate::core::renderer::Quad;
use crate::core::svg;
use crate::core::{
self, Background, Color, Point, Radians, Rectangle, Transformation,
self, Background, Color, Point, Rectangle, Svg, Transformation,
};
use crate::graphics::damage;
use crate::graphics::layer;
@ -119,23 +118,10 @@ impl Layer {
pub fn draw_image(&mut self, image: Image, transformation: Transformation) {
match image {
Image::Raster(raster, bounds) => {
self.draw_raster(raster.clone(), bounds, transformation);
self.draw_raster(raster, bounds, transformation);
}
Image::Vector {
handle,
color,
bounds,
rotation,
opacity,
} => {
self.draw_svg(
handle.clone(),
color,
bounds,
transformation,
rotation,
opacity,
);
Image::Vector(svg, bounds) => {
self.draw_svg(svg, bounds, transformation);
}
}
}
@ -153,20 +139,11 @@ impl Layer {
pub fn draw_svg(
&mut self,
handle: svg::Handle,
color: Option<Color>,
svg: Svg,
bounds: Rectangle,
transformation: Transformation,
rotation: Radians,
opacity: f32,
) {
let svg = Image::Vector {
handle,
color,
bounds: bounds * transformation,
rotation,
opacity,
};
let svg = Image::Vector(svg, bounds * transformation);
self.images.push(svg);
}

View file

@ -396,23 +396,9 @@ impl core::svg::Renderer for Renderer {
self.engine.vector_pipeline.viewport_dimensions(handle)
}
fn draw_svg(
&mut self,
handle: core::svg::Handle,
color: Option<Color>,
bounds: Rectangle,
rotation: core::Radians,
opacity: f32,
) {
fn draw_svg(&mut self, svg: core::Svg, bounds: Rectangle) {
let (layer, transformation) = self.layers.current_mut();
layer.draw_svg(
handle,
color,
bounds,
transformation,
rotation,
opacity,
);
layer.draw_svg(svg, bounds, transformation);
}
}