style: Move fixed-point font types to Rust

Now that cbindgen and rust support const generics, it seems more simple.

This centralizes all the relevant font constants etc in rust and avoids
conversions when going from rust to C++ and vice versa.

Differential Revision: https://phabricator.services.mozilla.com/D148847
This commit is contained in:
Emilio Cobos Álvarez 2022-06-13 00:59:23 +00:00 committed by Martin Robinson
parent 48749641d3
commit dcafbde256
10 changed files with 401 additions and 326 deletions

View file

@ -895,57 +895,9 @@ fn static_assert() {
}
}
pub fn set_font_weight(&mut self, v: longhands::font_weight::computed_value::T) {
unsafe { bindings::Gecko_FontWeight_SetFloat(&mut self.gecko.mFont.weight, v.0) };
}
${impl_simple_copy('font_weight', 'mFont.weight')}
pub fn clone_font_weight(&self) -> longhands::font_weight::computed_value::T {
let weight: f32 = unsafe {
bindings::Gecko_FontWeight_ToFloat(self.gecko.mFont.weight)
};
longhands::font_weight::computed_value::T(weight)
}
pub fn set_font_stretch(&mut self, v: longhands::font_stretch::computed_value::T) {
unsafe {
bindings::Gecko_FontStretch_SetFloat(
&mut self.gecko.mFont.stretch,
v.value(),
)
};
}
${impl_simple_copy('font_stretch', 'mFont.stretch')}
pub fn clone_font_stretch(&self) -> longhands::font_stretch::computed_value::T {
use crate::values::computed::font::FontStretch;
use crate::values::computed::Percentage;
use crate::values::generics::NonNegative;
let stretch =
unsafe { bindings::Gecko_FontStretch_ToFloat(self.gecko.mFont.stretch) };
debug_assert!(stretch >= 0.);
FontStretch(NonNegative(Percentage(stretch)))
}
pub fn set_font_style(&mut self, v: longhands::font_style::computed_value::T) {
use crate::values::generics::font::FontStyle;
let s = &mut self.gecko.mFont.style;
unsafe {
match v {
FontStyle::Normal => bindings::Gecko_FontSlantStyle_SetNormal(s),
FontStyle::Italic => bindings::Gecko_FontSlantStyle_SetItalic(s),
FontStyle::Oblique(ref angle) => {
bindings::Gecko_FontSlantStyle_SetOblique(s, angle.0.degrees())
}
}
}
}
${impl_simple_copy('font_style', 'mFont.style')}
pub fn clone_font_style(&self) -> longhands::font_style::computed_value::T {
use crate::values::computed::font::FontStyle;
FontStyle::from_gecko(self.gecko.mFont.style)
}
${impl_simple('font_weight', 'mFont.weight')}
${impl_simple('font_stretch', 'mFont.stretch')}
${impl_simple('font_style', 'mFont.style')}
${impl_simple_type_with_conversion("font_synthesis", "mFont.synthesis")}

View file

@ -352,11 +352,10 @@ pub mod system_font {
fn to_computed_value(&self, cx: &Context) -> Self::ComputedValue {
use crate::gecko_bindings::bindings;
use crate::gecko_bindings::structs::nsFont;
use std::mem;
use crate::values::computed::Percentage;
use crate::values::computed::font::FontSize;
use crate::values::specified::font::KeywordInfo;
use crate::values::computed::font::{FontSize, FontStretch, FontStyle};
use crate::values::generics::NonNegative;
use std::mem;
let mut system = mem::MaybeUninit::<nsFont>::uninit();
let system = unsafe {
@ -368,20 +367,15 @@ pub mod system_font {
);
&mut *system.as_mut_ptr()
};
let font_weight = longhands::font_weight::computed_value::T::from_gecko_weight(system.weight);
let font_stretch = FontStretch(NonNegative(Percentage(unsafe {
bindings::Gecko_FontStretch_ToFloat(system.stretch)
})));
let font_style = FontStyle::from_gecko(system.style);
let ret = ComputedSystemFont {
font_family: system.family.clone(),
font_size: FontSize {
size: NonNegative(cx.maybe_zoom_text(system.size.0)),
keyword_info: KeywordInfo::none()
},
font_weight,
font_stretch,
font_style,
font_weight: system.weight,
font_stretch: system.stretch,
font_style: system.style,
font_size_adjust: system.sizeAdjust,
% for kwprop in kw_font_props:
${kwprop}: longhands::${kwprop}::computed_value::T::from_gecko_keyword(