Skip to content

Commit

Permalink
Add more gradient tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurenzV committed Nov 3, 2023
1 parent 8b13687 commit 49f3c06
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 12 deletions.
20 changes: 20 additions & 0 deletions crates/resvg/tests/integration/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,26 @@ use crate::render;
#[test] fn structure_transform_translate_without_Y() { assert_eq!(render("tests/structure/transform/translate-without-Y"), 0); }
#[test] fn structure_transform_translate() { assert_eq!(render("tests/structure/transform/translate"), 0); }
#[test] fn structure_transform_zeroed_matrix() { assert_eq!(render("tests/structure/transform/zeroed-matrix"), 0); }
#[test] fn structure_transform_origin_bottom() { assert_eq!(render("tests/structure/transform-origin/bottom"), 0); }
#[test] fn structure_transform_origin_center() { assert_eq!(render("tests/structure/transform-origin/center"), 0); }
#[test] fn structure_transform_origin_keyword_length() { assert_eq!(render("tests/structure/transform-origin/keyword-length"), 0); }
#[test] fn structure_transform_origin_left() { assert_eq!(render("tests/structure/transform-origin/left"), 0); }
#[test] fn structure_transform_origin_length_percent() { assert_eq!(render("tests/structure/transform-origin/length-percent"), 0); }
#[test] fn structure_transform_origin_length_px() { assert_eq!(render("tests/structure/transform-origin/length-px"), 0); }
#[test] fn structure_transform_origin_no_transform() { assert_eq!(render("tests/structure/transform-origin/no-transform"), 0); }
#[test] fn structure_transform_origin_on_clippath() { assert_eq!(render("tests/structure/transform-origin/on-clippath"), 0); }
#[test] fn structure_transform_origin_on_gradient_user_space_on_use() { assert_eq!(render("tests/structure/transform-origin/on-gradient-user-space-on-use"), 0); }
#[test] fn structure_transform_origin_on_group() { assert_eq!(render("tests/structure/transform-origin/on-group"), 0); }
#[test] fn structure_transform_origin_on_image() { assert_eq!(render("tests/structure/transform-origin/on-image"), 0); }
#[test] fn structure_transform_origin_on_pattern_user_space_on_use() { assert_eq!(render("tests/structure/transform-origin/on-pattern-user-space-on-use"), 0); }
#[test] fn structure_transform_origin_on_shape() { assert_eq!(render("tests/structure/transform-origin/on-shape"), 0); }
#[test] fn structure_transform_origin_on_text_path() { assert_eq!(render("tests/structure/transform-origin/on-text-path"), 0); }
#[test] fn structure_transform_origin_on_text() { assert_eq!(render("tests/structure/transform-origin/on-text"), 0); }
#[test] fn structure_transform_origin_right_bottom() { assert_eq!(render("tests/structure/transform-origin/right-bottom"), 0); }
#[test] fn structure_transform_origin_right() { assert_eq!(render("tests/structure/transform-origin/right"), 0); }
#[test] fn structure_transform_origin_top_left() { assert_eq!(render("tests/structure/transform-origin/top-left"), 0); }
#[test] fn structure_transform_origin_top() { assert_eq!(render("tests/structure/transform-origin/top"), 0); }
#[test] fn structure_transform_origin_transform_on_parent() { assert_eq!(render("tests/structure/transform-origin/transform-on-parent"), 0); }
#[test] fn structure_use_cSS_rules() { assert_eq!(render("tests/structure/use/cSS-rules"), 0); }
#[test] fn structure_use_complex_style_resolving_order() { assert_eq!(render("tests/structure/use/complex-style-resolving-order"), 0); }
#[test] fn structure_use_display_inheritance() { assert_eq!(render("tests/structure/use/display-inheritance"), 0); }
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 22 additions & 10 deletions crates/usvg-parser/src/paint_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use strict_num::PositiveF32;
use svgtypes::{Length, LengthUnit as Unit};
use usvg_tree::*;

use crate::converter::SvgColorExt;
use crate::converter::{resolve_transform_origin, SvgColorExt};
use crate::svgtree::{AId, EId, SvgNode};
use crate::{converter, OptionLog};

Expand Down Expand Up @@ -53,9 +53,13 @@ fn convert_linear(node: SvgNode, state: &converter::State) -> Option<ServerOrCol
}

let units = convert_units(node, AId::GradientUnits, Units::ObjectBoundingBox);
let transform = resolve_attr(node, AId::GradientTransform)
.attribute(AId::GradientTransform)
.unwrap_or_default();
let transform = resolve_transform_origin(
node,
state,
resolve_attr(node, AId::GradientTransform)
.attribute(AId::GradientTransform)
.unwrap_or_default(),
);

let gradient = LinearGradient {
id: node.element_id().to_string(),
Expand Down Expand Up @@ -121,9 +125,13 @@ fn convert_radial(node: SvgNode, state: &converter::State) -> Option<ServerOrCol
);
let fx = resolve_number(node, AId::Fx, units, state, Length::new_number(cx as f64));
let fy = resolve_number(node, AId::Fy, units, state, Length::new_number(cy as f64));
let transform = resolve_attr(node, AId::GradientTransform)
.attribute(AId::GradientTransform)
.unwrap_or_default();
let transform = resolve_transform_origin(
node,
state,
resolve_attr(node, AId::GradientTransform)
.attribute(AId::GradientTransform)
.unwrap_or_default(),
);

let gradient = RadialGradient {
id: node.element_id().to_string(),
Expand Down Expand Up @@ -165,9 +173,13 @@ fn convert_pattern(
let units = convert_units(node, AId::PatternUnits, Units::ObjectBoundingBox);
let content_units = convert_units(node, AId::PatternContentUnits, Units::UserSpaceOnUse);

let transform = resolve_attr(node, AId::PatternTransform)
.attribute(AId::PatternTransform)
.unwrap_or_default();
let transform = resolve_transform_origin(
node,
state,
resolve_attr(node, AId::PatternTransform)
.attribute(AId::PatternTransform)
.unwrap_or_default(),
);

let rect = NonZeroRect::from_xywh(
resolve_number(node, AId::X, units, state, Length::zero()),
Expand Down
5 changes: 3 additions & 2 deletions crates/usvg-parser/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use kurbo::{ParamCurve, ParamCurveArclen};
use svgtypes::{Length, LengthUnit};
use usvg_tree::*;

use crate::converter::resolve_transform_origin;
use crate::svgtree::{AId, EId, FromValue, SvgNode};
use crate::{converter, style};
use crate::converter::resolve_transform_origin;

impl<'a, 'input: 'a> FromValue<'a, 'input> for usvg_tree::TextAnchor {
fn parse(_: SvgNode, _: AId, value: &str) -> Option<Self> {
Expand Down Expand Up @@ -338,7 +338,8 @@ fn resolve_text_flow(node: SvgNode, state: &converter::State) -> Option<TextFlow
let path = crate::shapes::convert(linked_node, state)?;

// The reference path's transform needs to be applied
let path = if let Some(mut node_transform) = linked_node.attribute::<Transform>(AId::Transform) {
let path = if let Some(mut node_transform) = linked_node.attribute::<Transform>(AId::Transform)
{
node_transform = resolve_transform_origin(linked_node, state, node_transform);
let mut path_copy = path.as_ref().clone();
path_copy = path_copy.transform(node_transform)?;
Expand Down

0 comments on commit 49f3c06

Please sign in to comment.