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

@ -1,18 +1,17 @@
//! Build and draw geometry.
use crate::core::svg;
use crate::core::text::LineHeight;
use crate::core::{
Color, Pixels, Point, Radians, Rectangle, Size, Transformation, Vector,
self, Pixels, Point, Radians, Rectangle, Size, Svg, Transformation, Vector,
};
use crate::graphics::cache::{self, Cached};
use crate::graphics::color;
use crate::graphics::geometry::fill::{self, Fill};
use crate::graphics::geometry::{
self, Image, LineCap, LineDash, LineJoin, Path, Stroke, Style,
self, LineCap, LineDash, LineJoin, Path, Stroke, Style,
};
use crate::graphics::gradient::{self, Gradient};
use crate::graphics::mesh::{self, Mesh};
use crate::graphics::{self, Text};
use crate::graphics::{Image, Text};
use crate::text;
use crate::triangle;
@ -26,7 +25,7 @@ use std::sync::Arc;
pub enum Geometry {
Live {
meshes: Vec<Mesh>,
images: Vec<graphics::Image>,
images: Vec<Image>,
text: Vec<Text>,
},
Cached(Cache),
@ -35,7 +34,7 @@ pub enum Geometry {
#[derive(Debug, Clone)]
pub struct Cache {
pub meshes: Option<triangle::Cache>,
pub images: Option<Arc<[graphics::Image]>>,
pub images: Option<Arc<[Image]>>,
pub text: Option<text::Cache>,
}
@ -98,7 +97,7 @@ pub struct Frame {
clip_bounds: Rectangle,
buffers: BufferStack,
meshes: Vec<Mesh>,
images: Vec<graphics::Image>,
images: Vec<Image>,
text: Vec<Text>,
transforms: Transforms,
fill_tessellator: tessellation::FillTessellator,
@ -292,7 +291,7 @@ impl geometry::frame::Backend for Frame {
height: f32::INFINITY,
};
self.text.push(graphics::Text::Cached {
self.text.push(Text::Cached {
content: text.content,
bounds,
color: text.color,
@ -376,7 +375,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) =
@ -384,27 +383,18 @@ impl geometry::frame::Backend for Frame {
image.rotation += external_rotation;
self.images.push(graphics::Image::Raster(image, bounds));
self.images.push(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) =
self.transforms.current.transform_rectangle(bounds);
self.images.push(graphics::Image::Vector {
handle: handle.clone(),
color,
bounds,
rotation: rotation + external_rotation,
opacity,
});
svg.rotation += external_rotation;
self.images.push(Image::Vector(svg, bounds));
}
}