mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
style: Use a user defined type for font weight everywhere.
Bug: 1436048 Reviewed-by: emilio
This commit is contained in:
parent
156ef81878
commit
245d848508
4 changed files with 18 additions and 7 deletions
|
@ -25,7 +25,7 @@ impl<'a> ToNsCssValue for &'a FamilyName {
|
|||
|
||||
impl ToNsCssValue for font_weight::T {
|
||||
fn convert(self, nscssvalue: &mut nsCSSValue) {
|
||||
nscssvalue.set_integer(self.0 as i32)
|
||||
nscssvalue.set_font_weight(self.0)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ impl<'a> ToNsCssValue for &'a FontWeight {
|
|||
match *self {
|
||||
FontWeight::Normal => nscssvalue.set_enum(structs::NS_FONT_WEIGHT_NORMAL as i32),
|
||||
FontWeight::Bold => nscssvalue.set_enum(structs::NS_FONT_WEIGHT_BOLD as i32),
|
||||
FontWeight::Weight(weight) => nscssvalue.set_integer(weight.0 as i32),
|
||||
FontWeight::Weight(weight) => nscssvalue.set_font_weight(weight.0),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -177,6 +177,11 @@ impl nsCSSValue {
|
|||
self.set_string_from_atom_internal(s, nsCSSUnit::eCSSUnit_Local_Font);
|
||||
}
|
||||
|
||||
/// Set to a font weight
|
||||
pub fn set_font_weight(&mut self, w: u16) {
|
||||
unsafe { bindings::Gecko_CSSValue_SetFontWeight(self, w as f32) }
|
||||
}
|
||||
|
||||
fn set_int_internal(&mut self, value: i32, unit: nsCSSUnit) {
|
||||
unsafe { bindings::Gecko_CSSValue_SetInt(self, value, unit) }
|
||||
}
|
||||
|
|
|
@ -25,6 +25,8 @@ use gecko_bindings::bindings::Gecko_CopyFontFamilyFrom;
|
|||
use gecko_bindings::bindings::Gecko_CopyImageValueFrom;
|
||||
use gecko_bindings::bindings::Gecko_CopyListStyleImageFrom;
|
||||
use gecko_bindings::bindings::Gecko_EnsureImageLayersLength;
|
||||
use gecko_bindings::bindings::Gecko_FontWeight_SetFloat;
|
||||
use gecko_bindings::bindings::Gecko_FontWeight_ToFloat;
|
||||
use gecko_bindings::bindings::Gecko_SetCursorArrayLength;
|
||||
use gecko_bindings::bindings::Gecko_SetCursorImageValue;
|
||||
use gecko_bindings::bindings::Gecko_StyleTransition_SetUnsupportedProperty;
|
||||
|
@ -2599,13 +2601,15 @@ fn static_assert() {
|
|||
}
|
||||
|
||||
pub fn set_font_weight(&mut self, v: longhands::font_weight::computed_value::T) {
|
||||
self.gecko.mFont.weight = v.0;
|
||||
unsafe { Gecko_FontWeight_SetFloat(&mut self.gecko.mFont.weight, v.0 as f32) };
|
||||
}
|
||||
${impl_simple_copy('font_weight', 'mFont.weight')}
|
||||
|
||||
pub fn clone_font_weight(&self) -> longhands::font_weight::computed_value::T {
|
||||
debug_assert!(self.gecko.mFont.weight <= ::std::u16::MAX);
|
||||
longhands::font_weight::computed_value::T(self.gecko.mFont.weight)
|
||||
let weight: f32 = unsafe { Gecko_FontWeight_ToFloat(self.gecko.mFont.weight) };
|
||||
debug_assert!(weight >= 0.0 &&
|
||||
weight <= ::std::u16::MAX as f32);
|
||||
longhands::font_weight::computed_value::T(weight as u16)
|
||||
}
|
||||
|
||||
${impl_simple_type_with_conversion("font_synthesis", "mFont.synthesis")}
|
||||
|
|
|
@ -75,10 +75,12 @@ impl FontWeight {
|
|||
}
|
||||
|
||||
/// Convert from an Gecko weight
|
||||
pub fn from_gecko_weight(weight: u16) -> Self {
|
||||
#[cfg(feature = "gecko")]
|
||||
pub fn from_gecko_weight(weight: structs::FontWeight) -> Self {
|
||||
// we allow a wider range of weights than is parseable
|
||||
// because system fonts may provide custom values
|
||||
FontWeight(weight)
|
||||
let weight = unsafe { bindings::Gecko_FontWeight_ToFloat(weight) };
|
||||
FontWeight(weight as u16)
|
||||
}
|
||||
|
||||
/// Weither this weight is bold
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue