[librsvg: 9/12] Don't use a special case to indicate that XmlLang is not specified




commit 9b0bd884a6626bba16f2ad343f83fbd4272815ee
Author: Federico Mena Quintero <federico gnome org>
Date:   Thu Jun 3 17:13:36 2021 -0500

    Don't use a special case to indicate that XmlLang is not specified

 src/property_defs.rs |  8 ++++----
 src/text.rs          | 16 +++-------------
 2 files changed, 7 insertions(+), 17 deletions(-)
---
diff --git a/src/property_defs.rs b/src/property_defs.rs
index 567e25d4..cb271262 100644
--- a/src/property_defs.rs
+++ b/src/property_defs.rs
@@ -944,15 +944,15 @@ impl WritingMode {
 make_property!(
     ComputedValues,
     XmlLang,
-    default: "".to_string(), // see create_pango_layout()
+    default: None,
     inherits_automatically: true,
-    newtype: String,
+    newtype: Option<String>,
     parse_impl: {
         impl Parse for XmlLang {
             fn parse<'i>(
                 parser: &mut Parser<'i, '_>,
             ) -> Result<XmlLang, ParseError<'i>> {
-                Ok(XmlLang(parser.expect_ident()?.to_string()))
+                Ok(XmlLang(Some(parser.expect_ident()?.to_string())))
             }
         }
     },
@@ -963,7 +963,7 @@ make_property!(
 fn parses_xml_lang() {
     assert_eq!(
         XmlLang::parse_str("es-MX").unwrap(),
-        XmlLang("es-MX".to_string())
+        XmlLang(Some("es-MX".to_string()))
     );
 
     assert!(XmlLang::parse_str("").is_err());
diff --git a/src/text.rs b/src/text.rs
index 58d1806d..f5ec19db 100644
--- a/src/text.rs
+++ b/src/text.rs
@@ -16,8 +16,7 @@ use crate::node::{CascadedValues, Node, NodeBorrow};
 use crate::parsers::ParseValue;
 use crate::properties::ComputedValues;
 use crate::property_defs::{
-    Direction, FontStretch, FontStyle, FontVariant, TextAnchor, UnicodeBidi, WritingMode, XmlLang,
-    XmlSpace,
+    Direction, FontStretch, FontStyle, FontVariant, TextAnchor, UnicodeBidi, WritingMode, XmlSpace,
 };
 use crate::space::{xml_space_normalize, NormalizeDefault, XmlSpaceNormalize};
 use crate::xml::Attributes;
@@ -725,12 +724,6 @@ fn to_pango_units(v: f64) -> i32 {
     (v * f64::from(pango::SCALE) + 0.5) as i32
 }
 
-impl<'a> From<&'a XmlLang> for pango::Language {
-    fn from(l: &'a XmlLang) -> pango::Language {
-        pango::Language::from_string(&l.0)
-    }
-}
-
 impl From<FontStyle> for pango::Style {
     fn from(s: FontStyle) -> pango::Style {
         match s {
@@ -821,11 +814,8 @@ fn create_pango_layout(
 ) -> pango::Layout {
     let pango_context = pango::Context::from(draw_ctx);
 
-    // See the construction of the XmlLang property
-    // We use "" there as the default value; this means that the language is not set.
-    // If the language *is* set, we can use it here.
-    if !values.xml_lang().0.is_empty() {
-        pango_context.set_language(&pango::Language::from(&values.xml_lang()));
+    if let Some(ref lang) = values.xml_lang().0 {
+        pango_context.set_language(&pango::Language::from_string(lang));
     }
 
     pango_context.set_base_gravity(pango::Gravity::from(values.writing_mode()));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]