mirror of
https://github.com/servo/servo.git
synced 2025-08-15 02:15:33 +01:00
style: Refactor font-feature-settings and font-variation-settings.
This fixes all known issues with serialization and parsing of these two properties, and in particular calc handling and such: https://bugzilla.mozilla.org/show_bug.cgi?id=1434692 https://bugzilla.mozilla.org/show_bug.cgi?id=1434724 Also does a fair amount of cleanup and all that, which was needed.
This commit is contained in:
parent
09398d42af
commit
3b34d734e6
11 changed files with 270 additions and 261 deletions
|
@ -1426,29 +1426,21 @@ impl Clone for ${style_struct.gecko_struct_name} {
|
|||
}
|
||||
</%def>
|
||||
|
||||
<%def name="impl_font_settings(ident, tag_type)">
|
||||
<%def name="impl_font_settings(ident, tag_type, value_type, gecko_value_type)">
|
||||
<%
|
||||
gecko_ffi_name = to_camel_case_lower(ident)
|
||||
%>
|
||||
|
||||
pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
|
||||
use values::generics::font::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
|
||||
unsafe { current_settings.set_len_pod(v.0.len() as u32) };
|
||||
|
||||
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.0;
|
||||
current.mValue = other.value.0;
|
||||
}
|
||||
}
|
||||
};
|
||||
for (current, other) in current_settings.iter_mut().zip(v.0.iter()) {
|
||||
current.mTag = other.tag.0;
|
||||
current.mValue = other.value as ${gecko_value_type};
|
||||
}
|
||||
}
|
||||
|
||||
pub fn copy_${ident}_from(&mut self, other: &Self) {
|
||||
|
@ -1470,21 +1462,17 @@ impl Clone for ${style_struct.gecko_struct_name} {
|
|||
}
|
||||
|
||||
pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T {
|
||||
use values::generics::font::{FontSettings, FontSettingTag, ${tag_type}};
|
||||
use values::generics::font::{FontSettings, ${tag_type}};
|
||||
use values::specified::font::FontTag;
|
||||
|
||||
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: FontTag(gecko_font_setting.mTag),
|
||||
value: ${tag_type}(gecko_font_setting.mValue),
|
||||
}
|
||||
}).collect()
|
||||
)
|
||||
}
|
||||
FontSettings(
|
||||
self.gecko.mFont.${gecko_ffi_name}.iter().map(|gecko_font_setting| {
|
||||
${tag_type} {
|
||||
tag: FontTag(gecko_font_setting.mTag),
|
||||
value: gecko_font_setting.mValue as ${value_type},
|
||||
}
|
||||
}).collect::<Vec<_>>().into_boxed_slice()
|
||||
)
|
||||
}
|
||||
</%def>
|
||||
|
||||
|
@ -2338,8 +2326,10 @@ fn static_assert() {
|
|||
<%self:impl_trait style_struct_name="Font"
|
||||
skip_longhands="${skip_font_longhands}">
|
||||
|
||||
<% impl_font_settings("font_feature_settings", "FontSettingTagInt") %>
|
||||
<% impl_font_settings("font_variation_settings", "FontSettingTagFloat") %>
|
||||
// Negative numbers are invalid at parse time, but <integer> is still an
|
||||
// i32.
|
||||
<% impl_font_settings("font_feature_settings", "FeatureTagValue", "i32", "u32") %>
|
||||
<% impl_font_settings("font_variation_settings", "VariationValue", "f32", "f32") %>
|
||||
|
||||
pub fn fixup_none_generic(&mut self, device: &Device) {
|
||||
self.gecko.mFont.systemFont = false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue