Add SVG dashing support

This commit is contained in:
Patrick Walton 2020-04-21 09:29:36 -07:00
parent 6c996981a3
commit 561582c0ac
1 changed files with 18 additions and 19 deletions

View File

@ -15,6 +15,7 @@ extern crate bitflags;
use hashbrown::HashMap; use hashbrown::HashMap;
use pathfinder_color::ColorU; use pathfinder_color::ColorU;
use pathfinder_content::dash::OutlineDash;
use pathfinder_content::fill::FillRule; use pathfinder_content::fill::FillRule;
use pathfinder_content::gradient::{ColorStop, Gradient}; use pathfinder_content::gradient::{ColorStop, Gradient};
use pathfinder_content::outline::Outline; use pathfinder_content::outline::Outline;
@ -49,17 +50,14 @@ bitflags! {
pub struct BuildResultFlags: u16 { pub struct BuildResultFlags: u16 {
const UNSUPPORTED_FILTER_NODE = 0x0001; const UNSUPPORTED_FILTER_NODE = 0x0001;
const UNSUPPORTED_IMAGE_NODE = 0x0002; const UNSUPPORTED_IMAGE_NODE = 0x0002;
const UNSUPPORTED_LINEAR_GRADIENT_NODE = 0x0004; const UNSUPPORTED_MASK_NODE = 0x0004;
const UNSUPPORTED_MASK_NODE = 0x0008; const UNSUPPORTED_PATTERN_NODE = 0x0008;
const UNSUPPORTED_PATTERN_NODE = 0x0010; const UNSUPPORTED_NESTED_SVG_NODE = 0x0010;
const UNSUPPORTED_RADIAL_GRADIENT_NODE = 0x0020; const UNSUPPORTED_MULTIPLE_CLIP_PATHS = 0x0020;
const UNSUPPORTED_NESTED_SVG_NODE = 0x0040; const UNSUPPORTED_LINK_PAINT = 0x0040;
const UNSUPPORTED_MULTIPLE_CLIP_PATHS = 0x0080; const UNSUPPORTED_FILTER_ATTR = 0x0080;
const UNSUPPORTED_LINK_PAINT = 0x0100; const UNSUPPORTED_MASK_ATTR = 0x0100;
const UNSUPPORTED_FILTER_ATTR = 0x0200; const UNSUPPORTED_GRADIENT_SPREAD_METHOD = 0x0200;
const UNSUPPORTED_MASK_ATTR = 0x0400;
const UNSUPPORTED_STROKE_DASH = 0x0800;
const UNSUPPORTED_GRADIENT_SPREAD_METHOD = 0x1000;
} }
} }
@ -159,12 +157,15 @@ impl BuiltSVG {
stroke.miterlimit.value() as f32), stroke.miterlimit.value() as f32),
}; };
if stroke.dasharray.is_some() {
self.result_flags.insert(BuildResultFlags::UNSUPPORTED_STROKE_DASH);
}
let path = UsvgPathToSegments::new(path.data.iter().cloned()); let path = UsvgPathToSegments::new(path.data.iter().cloned());
let outline = Outline::from_segments(path); let mut outline = Outline::from_segments(path);
if let Some(ref dash_array) = stroke.dasharray {
let dash_array: Vec<f32> = dash_array.iter().map(|&x| x as f32).collect();
let mut dash = OutlineDash::new(&outline, &dash_array, stroke.dashoffset);
dash.dash();
outline = dash.into_outline();
}
let mut stroke_to_fill = OutlineStrokeToFill::new(&outline, stroke_style); let mut stroke_to_fill = OutlineStrokeToFill::new(&outline, stroke_style);
stroke_to_fill.offset(); stroke_to_fill.offset();
@ -308,16 +309,14 @@ impl Display for BuildResultFlags {
static NAMES: &'static [&'static str] = &[ static NAMES: &'static [&'static str] = &[
"<filter>", "<filter>",
"<image>", "<image>",
"<linearGradient>",
"<mask>", "<mask>",
"<pattern>", "<pattern>",
"<radialGradient>",
"nested <svg>", "nested <svg>",
"multiple clip paths", "multiple clip paths",
"non-color paint", "non-color paint",
"filter attribute", "filter attribute",
"mask attribute", "mask attribute",
"stroke dash", "gradient spread method",
]; ];
} }
} }