Skip to content

Commit

Permalink
Bug 1903546 - fix non-scaling-stroke r=emilio
Browse files Browse the repository at this point in the history
This implements w3c/svgwg#582 and therefore mostly reverts bug 1904891

Differential Revision: https://phabricator.services.mozilla.com/D216303
  • Loading branch information
longsonr committed Jul 11, 2024
1 parent 5ce79ad commit dfc6a83
Showing 1 changed file with 4 additions and 87 deletions.
91 changes: 4 additions & 87 deletions style/values/specified/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,104 +420,21 @@ impl Parse for DProperty {
)]
#[css(bitflags(single = "none", mixed = "non-scaling-stroke"))]
#[repr(C)]
/// Values for vector-effect:
/// https://svgwg.org/svg2-draft/coords.html#VectorEffects
pub struct VectorEffectType(u8);
pub struct VectorEffect(u8);
bitflags! {
impl VectorEffectType: u8 {
impl VectorEffect: u8 {
/// `none`
const NONE = 0;
/// `non-scaling-stroke`
const NON_SCALING_STROKE = 1 << 0;
}
}

#[allow(missing_docs)]
impl VectorEffectType {
pub fn is_none(&self) -> bool {
*self == VectorEffectType::NONE
}
}

#[derive(
Clone,
Copy,
Debug,
Default,
Eq,
MallocSizeOf,
Parse,
PartialEq,
SpecifiedValueInfo,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)]
#[repr(C)]
/// co-ordinate space for vector-effect:
/// https://svgwg.org/svg2-draft/coords.html#VectorEffects
pub enum CoordinateSpace {
#[default]
/// `viewport`
Viewport,
/// `screen`
Screen,
}

#[allow(missing_docs)]
impl CoordinateSpace {
pub fn is_viewport(&self) -> bool {
*self == Self::Viewport
}
}

#[derive(
Clone,
Copy,
Debug,
MallocSizeOf,
PartialEq,
SpecifiedValueInfo,
ToCss,
ToComputedValue,
ToResolvedValue,
ToShmem,
)]
#[repr(C)]
/// Specified value for the vector-effect property.
/// (The spec grammar gives
/// `none | [ non-scaling-stroke | non-scaling-size | non-rotation | fixed-position ]+ [ viewport | screen ]?`.)
/// https://svgwg.org/svg2-draft/coords.html#VectorEffects
pub struct VectorEffect {
/// none or non-scaling-stroke
pub effect_type: VectorEffectType,
/// screen or viewport
#[css(skip_if = "CoordinateSpace::is_viewport")]
pub coordinate_space: CoordinateSpace,
}

#[allow(missing_docs)]
impl VectorEffect {
/// Returns the initial value of vector-effect
#[inline]
pub fn none() -> Self {
Self {
effect_type: VectorEffectType::NONE,
coordinate_space: CoordinateSpace::Viewport,
}
}
}

impl Parse for VectorEffect {
fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
let effect_type = VectorEffectType::parse(context, input)?;
if effect_type.is_none() {
return Ok(Self::none());
}
let coordinate_space = input.try_parse(CoordinateSpace::parse).unwrap_or(CoordinateSpace::Viewport);
Ok(Self { effect_type, coordinate_space })
Self::NONE
}
}

0 comments on commit dfc6a83

Please sign in to comment.