[librsvg: 2/22] Add line-height to SpecifiedValues and ComputedValues
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 2/22] Add line-height to SpecifiedValues and ComputedValues
- Date: Wed, 1 Jul 2020 00:03:12 +0000 (UTC)
commit e341f0d06e268a9dba526a4b48ef2ba0354b86a6
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Jun 24 15:23:43 2020 -0500
Add line-height to SpecifiedValues and ComputedValues
For now this requires a special case in the make_properties! macro.
The markup5ever crate does not support "line-height" out of the box
yet; see https://github.com/servo/html5ever/pull/422.
So, we add a special case for property names that are not supported
yet in markup5ever. Ugly but it works.
rsvg_internals/src/properties.rs | 47 ++++++++++++++++++++++++++++++++++++-
rsvg_internals/src/property_defs.rs | 11 ++++++++-
2 files changed, 56 insertions(+), 2 deletions(-)
---
diff --git a/rsvg_internals/src/properties.rs b/rsvg_internals/src/properties.rs
index 6eda64cf..61aee616 100644
--- a/rsvg_internals/src/properties.rs
+++ b/rsvg_internals/src/properties.rs
@@ -3,7 +3,7 @@
use cssparser::{
self, BasicParseErrorKind, DeclarationListParser, ParseErrorKind, Parser, ParserInput, ToCss,
};
-use markup5ever::{expanded_name, local_name, namespace_url, ns, QualName};
+use markup5ever::{expanded_name, local_name, namespace_url, ns, ExpandedName, LocalName, QualName};
use std::collections::HashSet;
use crate::css::{DeclParser, Declaration, Origin};
@@ -125,6 +125,12 @@ macro_rules! make_properties {
$($long_str:tt => $long_field:ident: $long_name:ident,)+
}
+ // These are for when expanded_name!("" "foo") is not defined yet
+ // in markup5ever. We create an ExpandedName by hand in that case.
+ longhands_not_supported_by_markup5ever: {
+ $($long_m5e_str:tt => $long_m5e_field:ident: $long_m5e_name:ident,)+
+ }
+
non_properties: {
$($nonprop_field:ident: $nonprop_name:ident,)+
}
@@ -139,6 +145,7 @@ macro_rules! make_properties {
enum PropertyId {
$($short_name,)+
$($long_name,)+
+ $($long_m5e_name,)+
$($nonprop_name,)+
UnsetProperty,
@@ -159,6 +166,7 @@ macro_rules! make_properties {
// we put all the properties here; these are for SpecifiedValues
$($short_name(SpecifiedValue<$short_name>),)+
$($long_name(SpecifiedValue<$long_name>),)+
+ $($long_m5e_name(SpecifiedValue<$long_m5e_name>),)+
$($nonprop_name(SpecifiedValue<$nonprop_name>),)+
}
@@ -167,6 +175,10 @@ macro_rules! make_properties {
$long_name($long_name),
)+
+ $(
+ $long_m5e_name($long_m5e_name),
+ )+
+
$(
$nonprop_name($nonprop_name),
)+
@@ -178,6 +190,10 @@ macro_rules! make_properties {
$long_field: $long_name,
)+
+ $(
+ $long_m5e_field: $long_m5e_name,
+ )+
+
$(
$nonprop_field: $nonprop_name,
)+
@@ -187,6 +203,7 @@ macro_rules! make_properties {
fn get_property_id(&self) -> PropertyId {
match *self {
$(ParsedProperty::$long_name(_) => PropertyId::$long_name,)+
+ $(ParsedProperty::$long_m5e_name(_) => PropertyId::$long_m5e_name,)+
$(ParsedProperty::$short_name(_) => PropertyId::$short_name,)+
$(ParsedProperty::$nonprop_name(_) => PropertyId::$nonprop_name,)+
}
@@ -197,6 +214,7 @@ macro_rules! make_properties {
match id {
$(PropertyId::$long_name => ParsedProperty::$long_name(Unspecified),)+
+ $(PropertyId::$long_m5e_name => ParsedProperty::$long_m5e_name(Unspecified),)+
$(PropertyId::$short_name => ParsedProperty::$short_name(Unspecified),)+
$(PropertyId::$nonprop_name => ParsedProperty::$nonprop_name(Unspecified),)+
@@ -216,6 +234,16 @@ macro_rules! make_properties {
}
)+
+ $(
+ pub fn $long_m5e_field(&self) -> $long_m5e_name {
+ if let ComputedValue::$long_m5e_name(v) = self.get_value(PropertyId::$long_m5e_name) {
+ v
+ } else {
+ unreachable!();
+ }
+ }
+ )+
+
$(
pub fn $nonprop_field(&self) -> $nonprop_name {
if let ComputedValue::$nonprop_name(v) = self.get_value(PropertyId::$nonprop_name) {
@@ -229,6 +257,7 @@ macro_rules! make_properties {
fn set_value(&mut self, computed: ComputedValue) {
match computed {
$(ComputedValue::$long_name(v) => self.$long_field = v,)+
+ $(ComputedValue::$long_m5e_name(v) => self.$long_m5e_field = v,)+
$(ComputedValue::$nonprop_name(v) => self.$nonprop_field = v,)+
}
}
@@ -241,6 +270,10 @@ macro_rules! make_properties {
PropertyId::$long_name =>
ComputedValue::$long_name(self.$long_field.clone()),
)+
+ $(
+ PropertyId::$long_m5e_name =>
+ ComputedValue::$long_m5e_name(self.$long_m5e_field.clone()),
+ )+
$(
PropertyId::$nonprop_name =>
ComputedValue::$nonprop_name(self.$nonprop_field.clone()),
@@ -261,6 +294,14 @@ macro_rules! make_properties {
Ok(ParsedProperty::$long_name(parse_input(input)?)),
)+
+ $(
+ e if e == ExpandedName {
+ ns: &ns!(),
+ local: &LocalName::from($long_m5e_str),
+ } =>
+ Ok(ParsedProperty::$long_m5e_name(parse_input(input)?)),
+ )+
+
$(
expanded_name!("", $short_str) => {
if accept_shorthands {
@@ -335,6 +376,10 @@ make_properties! {
"writing-mode" => writing_mode : WritingMode,
}
+ longhands_not_supported_by_markup5ever: {
+ "line-height" => line_height : LineHeight,
+ }
+
// These are not properties, but presentation attributes. However,
// both xml:lang and xml:space *do* inherit. We are abusing the
// property inheritance code for these XML-specific attributes.
diff --git a/rsvg_internals/src/property_defs.rs b/rsvg_internals/src/property_defs.rs
index 61e7ad3e..d0fe05a9 100644
--- a/rsvg_internals/src/property_defs.rs
+++ b/rsvg_internals/src/property_defs.rs
@@ -4,7 +4,7 @@ use cssparser::{Parser, Token};
use crate::dasharray::Dasharray;
use crate::error::*;
-use crate::font_props::{FontSizeSpec, FontWeightSpec, LetterSpacingSpec, MultiFontFamily};
+use crate::font_props::{FontSizeSpec, FontWeightSpec, LetterSpacingSpec, LineHeightSpec, MultiFontFamily};
use crate::iri::IRI;
use crate::length::*;
use crate::paint_server::PaintServer;
@@ -342,6 +342,15 @@ make_property!(
}
);
+// https://drafts.csswg.org/css2/visudet.html#propdef-line-height
+make_property!(
+ ComputedValues,
+ LineHeight,
+ default: LineHeightSpec::Normal,
+ inherits_automatically: true,
+ newtype_parse: LineHeightSpec,
+);
+
// https://www.w3.org/TR/SVG/filters.html#LightingColorProperty
make_property!(
ComputedValues,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]