From 951662848f5a4321eb95776c3b83e4e228a4ff6c Mon Sep 17 00:00:00 2001 From: Daisuke Akatsuka Date: Tue, 5 Sep 2017 15:56:15 +0900 Subject: [PATCH] Implement clone_font_variation_settings method --- components/style/properties/gecko.mako.rs | 157 +++++++++------------- 1 file changed, 64 insertions(+), 93 deletions(-) diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 3eae30f6f9eb..de1503ad5faf 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -5,7 +5,7 @@ // `data` comes from components/style/properties.mako.rs; see build.rs for more details. <%! - from data import to_rust_ident, to_camel_case + from data import to_rust_ident, to_camel_case, to_camel_case_lower from data import Keyword %> <%namespace name="helpers" file="/helpers.mako.rs" /> @@ -1070,6 +1070,67 @@ impl Clone for ${style_struct.gecko_struct_name} { } +<%def name="impl_font_settings(ident, tag_type)"> + <% + gecko_ffi_name = to_camel_case_lower(ident) + %> + + pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) { + use values::generics::FontSettings; + + let current_settings = &mut self.gecko.mFont.${gecko_ffi_name}; + current_settings.clear_pod(); + + match v { + FontSettings::Normal => (), // do nothing, length is already 0 + + FontSettings::Tag(other_settings) => { + unsafe { current_settings.set_len_pod(other_settings.len() as u32) }; + + for (current, other) in current_settings.iter_mut().zip(other_settings) { + current.mTag = other.tag; + current.mValue = other.value.0; + } + } + }; + } + + pub fn copy_${ident}_from(&mut self, other: &Self) { + let current_settings = &mut self.gecko.mFont.${gecko_ffi_name}; + let other_settings = &other.gecko.mFont.${gecko_ffi_name}; + let settings_length = other_settings.len() as u32; + + current_settings.clear_pod(); + unsafe { current_settings.set_len_pod(settings_length) }; + + for (current, other) in current_settings.iter_mut().zip(other_settings.iter()) { + current.mTag = other.mTag; + current.mValue = other.mValue; + } + } + + pub fn reset_${ident}(&mut self, other: &Self) { + self.copy_${ident}_from(other) + } + + pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T { + use values::generics::{FontSettings, FontSettingTag, ${tag_type}} ; + + if self.gecko.mFont.${gecko_ffi_name}.len() == 0 { + FontSettings::Normal + } else { + FontSettings::Tag( + self.gecko.mFont.${gecko_ffi_name}.iter().map(|gecko_font_setting| { + FontSettingTag { + tag: gecko_font_setting.mTag, + value: ${tag_type}(gecko_font_setting.mValue), + } + }).collect() + ) + } + } + + <%def name="raw_impl_trait(style_struct, skip_longhands='', skip_additionals='')"> <% longhands = [x for x in style_struct.longhands @@ -2069,98 +2130,8 @@ fn static_assert() { skip_longhands="${skip_font_longhands}" skip_additionals="*"> - pub fn set_font_feature_settings(&mut self, v: longhands::font_feature_settings::computed_value::T) { - use values::generics::FontSettings; - - let current_settings = &mut self.gecko.mFont.fontFeatureSettings; - current_settings.clear_pod(); - - match v { - FontSettings::Normal => (), // do nothing, length is already 0 - - FontSettings::Tag(feature_settings) => { - unsafe { current_settings.set_len_pod(feature_settings.len() as u32) }; - - for (current, feature) in current_settings.iter_mut().zip(feature_settings) { - current.mTag = feature.tag; - current.mValue = feature.value.0; - } - } - }; - } - - pub fn copy_font_feature_settings_from(&mut self, other: &Self) { - let current_settings = &mut self.gecko.mFont.fontFeatureSettings; - let feature_settings = &other.gecko.mFont.fontFeatureSettings; - let settings_length = feature_settings.len() as u32; - - current_settings.clear_pod(); - unsafe { current_settings.set_len_pod(settings_length) }; - - for (current, feature) in current_settings.iter_mut().zip(feature_settings.iter()) { - current.mTag = feature.mTag; - current.mValue = feature.mValue; - } - } - - pub fn reset_font_feature_settings(&mut self, other: &Self) { - self.copy_font_feature_settings_from(other) - } - - pub fn clone_font_feature_settings(&self) -> longhands::font_feature_settings::computed_value::T { - use values::generics::{FontSettings, FontSettingTag, FontSettingTagInt} ; - - if self.gecko.mFont.fontFeatureSettings.len() == 0 { - FontSettings::Normal - } else { - FontSettings::Tag( - self.gecko.mFont.fontFeatureSettings.iter().map(|gecko_font_feature_setting| { - FontSettingTag { - tag: gecko_font_feature_setting.mTag, - value: FontSettingTagInt(gecko_font_feature_setting.mValue), - } - }).collect() - ) - } - } - - pub fn set_font_variation_settings(&mut self, v: longhands::font_variation_settings::computed_value::T) { - use values::generics::FontSettings; - - let current_settings = &mut self.gecko.mFont.fontVariationSettings; - current_settings.clear_pod(); - - match v { - FontSettings::Normal => (), // do nothing, length is already 0 - - FontSettings::Tag(feature_settings) => { - unsafe { current_settings.set_len_pod(feature_settings.len() as u32) }; - - for (current, feature) in current_settings.iter_mut().zip(feature_settings) { - current.mTag = feature.tag; - current.mValue = feature.value.0; - } - } - }; - } - - pub fn copy_font_variation_settings_from(&mut self, other: &Self ) { - let current_settings = &mut self.gecko.mFont.fontVariationSettings; - let feature_settings = &other.gecko.mFont.fontVariationSettings; - let settings_length = feature_settings.len() as u32; - - current_settings.clear_pod(); - unsafe { current_settings.set_len_pod(settings_length) }; - - for (current, feature) in current_settings.iter_mut().zip(feature_settings.iter()) { - current.mTag = feature.mTag; - current.mValue = feature.mValue; - } - } - - pub fn reset_font_variation_settings(&mut self, other: &Self) { - self.copy_font_variation_settings_from(other) - } + <% impl_font_settings("font_feature_settings", "FontSettingTagInt") %> + <% impl_font_settings("font_variation_settings", "FontSettingTagFloat") %> pub fn fixup_none_generic(&mut self, device: &Device) { self.gecko.mFont.systemFont = false;