[librsvg: 3/4] Parse writing-mode values from the CSS Writing Modes 3 specification
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 3/4] Parse writing-mode values from the CSS Writing Modes 3 specification
- Date: Tue, 5 Oct 2021 02:12:06 +0000 (UTC)
commit 25834ec93af1238aafdde29414d09427e5b2bc2c
Author: Federico Mena Quintero <federico gnome org>
Date: Fri Sep 24 18:49:08 2021 -0500
Parse writing-mode values from the CSS Writing Modes 3 specification
The values lr, lr-tb, rl, rl-tb, tb, tb-rl are made obsolete in SVG2,
and replaced with horizontal-tb, vertical-rl, vertical-lr.
The old values are computed into the new ones per
https://www.w3.org/TR/css-writing-modes-3/#block-flow
Regretfully this commit adds another case to the make_property! macro,
as I'd like to use the "identifiers" machinery here, but specify a
custom compute() implementation.
Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/597>
src/property_defs.rs | 46 ++++++++++++++++++++++++++++++++++------------
src/property_macros.rs | 27 ++++++++++++++++++++++++++-
src/text.rs | 15 +++++++--------
3 files changed, 67 insertions(+), 21 deletions(-)
---
diff --git a/src/property_defs.rs b/src/property_defs.rs
index b1407712..6eb8c713 100644
--- a/src/property_defs.rs
+++ b/src/property_defs.rs
@@ -1029,28 +1029,50 @@ make_property!(
make_property!(
/// `writing-mode` property.
///
- /// https://www.w3.org/TR/SVG/text.html#WritingModeProperty
- ///
/// https://www.w3.org/TR/css-writing-modes-3/#block-flow
+ /// https://svgwg.org/svg2-draft/text.html#WritingModeProperty
+ /// https://www.w3.org/TR/SVG/text.html#WritingModeProperty
///
/// See the comments in the SVG2 spec for how the SVG1.1 values must be translated
/// into CSS Writing Modes 3 values.
WritingMode,
- default: LrTb,
- inherits_automatically: true,
+ default: HorizontalTb,
+ identifiers: {
+ "horizontal-tb" => HorizontalTb,
+ "vertical-rl" => VerticalRl,
+ "vertical-lr" => VerticalLr,
+ "lr" => Lr,
+ "lr-tb" => LrTb,
+ "rl" => Rl,
+ "rl-tb" => RlTb,
+ "tb" => Tb,
+ "tb-rl" => TbRl,
+ },
+ property_impl: {
+ impl Property for WritingMode {
+ fn inherits_automatically() -> bool {
+ true
+ }
- identifiers:
- "lr" => Lr,
- "lr-tb" => LrTb,
- "rl" => Rl,
- "rl-tb" => RlTb,
- "tb" => Tb,
- "tb-rl" => TbRl,
+ fn compute(&self, _v: &ComputedValues) -> Self {
+ use WritingMode::*;
+
+ // Translate SVG1.1 compatibility values to SVG2 / CSS Writing Modes 3.
+ match *self {
+ Lr | LrTb | Rl | RlTb => HorizontalTb,
+ Tb | TbRl => VerticalRl,
+ _ => *self,
+ }
+ }
+ }
+ }
);
impl WritingMode {
pub fn is_horizontal(self) -> bool {
- !matches!(self, WritingMode::Tb | WritingMode::TbRl)
+ use WritingMode::*;
+
+ matches!(self, HorizontalTb | Lr | LrTb | Rl | RlTb)
}
}
diff --git a/src/property_macros.rs b/src/property_macros.rs
index bb3fea85..28aa61e4 100644
--- a/src/property_macros.rs
+++ b/src/property_macros.rs
@@ -134,6 +134,32 @@ macro_rules! make_property {
}
};
+ ($(#[$attr:meta])*
+ $name: ident,
+ default: $default: ident,
+ identifiers: { $($str_prop: expr => $variant: ident,)+ },
+ property_impl: { $prop: item }
+ ) => {
+ $(#[$attr])*
+ #[derive(Debug, Copy, Clone, PartialEq)]
+ #[repr(C)]
+ pub enum $name {
+ $($variant),+
+ }
+
+ impl_default!($name, $name::$default);
+ $prop
+
+ impl crate::parsers::Parse for $name {
+ fn parse<'i>(parser: &mut ::cssparser::Parser<'i, '_>) -> Result<$name,
crate::error::ParseError<'i>> {
+ Ok(parse_identifiers!(
+ parser,
+ $($str_prop => $name::$variant,)+
+ )?)
+ }
+ }
+ };
+
($(#[$attr:meta])*
$name: ident,
default: $default: expr,
@@ -183,7 +209,6 @@ macro_rules! make_property {
$parse
};
- // pending - only BaselineShift
($(#[$attr:meta])*
$name: ident,
default: $default: expr,
diff --git a/src/text.rs b/src/text.rs
index ee612ed4..46baef3b 100644
--- a/src/text.rs
+++ b/src/text.rs
@@ -812,22 +812,21 @@ impl From<Direction> for pango::Alignment {
impl From<WritingMode> for pango::Direction {
fn from(m: WritingMode) -> pango::Direction {
+ use WritingMode::*;
match m {
- WritingMode::LrTb | WritingMode::Lr | WritingMode::Tb | WritingMode::TbRl => {
- pango::Direction::Ltr
- }
- WritingMode::RlTb | WritingMode::Rl => pango::Direction::Rtl,
+ HorizontalTb | VerticalRl | VerticalLr | LrTb | Lr | Tb | TbRl => pango::Direction::Ltr,
+ RlTb | Rl => pango::Direction::Rtl,
}
}
}
impl From<WritingMode> for pango::Gravity {
fn from(m: WritingMode) -> pango::Gravity {
+ use WritingMode::*;
match m {
- WritingMode::Tb | WritingMode::TbRl => pango::Gravity::East,
- WritingMode::LrTb | WritingMode::Lr | WritingMode::RlTb | WritingMode::Rl => {
- pango::Gravity::South
- }
+ HorizontalTb | LrTb | Lr | RlTb | Rl => pango::Gravity::South,
+ VerticalRl | Tb | TbRl => pango::Gravity::East,
+ VerticalLr => pango::Gravity::West,
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]