Skip to content

Commit

Permalink
stylo: Add basic system font support, use for font-size and font-family
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Apr 18, 2017
1 parent 2b353e0 commit 2c5ac9f
Show file tree
Hide file tree
Showing 9 changed files with 260 additions and 11 deletions.
2 changes: 1 addition & 1 deletion components/script/dom/element.rs
Expand Up @@ -468,7 +468,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
hints.push(from_declaration(
shared_lock,
PropertyDeclaration::FontFamily(
font_family::computed_value::T(vec![
font_family::SpecifiedValue::Values(vec![
font_family::computed_value::FontFamily::from_atom(
font_family)]))));
}
Expand Down
11 changes: 11 additions & 0 deletions components/style/gecko_bindings/bindings.rs
Expand Up @@ -695,6 +695,9 @@ extern "C" {
pub fn Gecko_Atomize(aString: *const ::std::os::raw::c_char, aLength: u32)
-> *mut nsIAtom;
}
extern "C" {
pub fn Gecko_Atomize16(aString: *const nsAString) -> *mut nsIAtom;
}
extern "C" {
pub fn Gecko_AddRefAtom(aAtom: *mut nsIAtom);
}
Expand Down Expand Up @@ -731,6 +734,14 @@ extern "C" {
extern "C" {
pub fn Gecko_CopyFontFamilyFrom(dst: *mut nsFont, src: *const nsFont);
}
extern "C" {
pub fn Gecko_nsFont_InitSystem(dst: *mut nsFont, font_id: i32,
font: *const nsStyleFont,
pres_context: RawGeckoPresContextBorrowed);
}
extern "C" {
pub fn Gecko_nsFont_Destroy(dst: *mut nsFont);
}
extern "C" {
pub fn Gecko_SetImageOrientation(aVisibility: *mut nsStyleVisibility,
aRadians: f64, aFlip: bool);
Expand Down
13 changes: 13 additions & 0 deletions components/style/gecko_string_cache/mod.rs
Expand Up @@ -8,9 +8,11 @@

use gecko_bindings::bindings::Gecko_AddRefAtom;
use gecko_bindings::bindings::Gecko_Atomize;
use gecko_bindings::bindings::Gecko_Atomize16;
use gecko_bindings::bindings::Gecko_ReleaseAtom;
use gecko_bindings::structs::nsIAtom;
use precomputed_hash::PrecomputedHash;
use nsstring::nsAString;
use std::borrow::{Cow, Borrow};
use std::char::{self, DecodeUtf16};
use std::fmt::{self, Write};
Expand Down Expand Up @@ -281,6 +283,17 @@ impl<'a> From<&'a str> for Atom {
}
}

impl<'a> From<&'a nsAString> for Atom {
#[inline]
fn from(string: &nsAString) -> Atom {
unsafe {
Atom(WeakAtom::new(
Gecko_Atomize16(string)
))
}
}
}

impl<'a> From<Cow<'a, str>> for Atom {
#[inline]
fn from(string: Cow<'a, str>) -> Atom {
Expand Down
4 changes: 4 additions & 0 deletions components/style/properties/gecko.mako.rs
Expand Up @@ -95,6 +95,7 @@ pub struct ComputedValues {
/// When this is Some, we compute font sizes by computing the keyword against
/// the generic font, and then multiplying it by the ratio.
pub font_size_keyword: Option<(longhands::font_size::KeywordSize, f32)>,
pub cached_system_font: Option<longhands::system_font::ComputedSystemFont>,
}

impl ComputedValues {
Expand All @@ -104,6 +105,7 @@ impl ComputedValues {
writing_mode: parent.writing_mode,
root_font_size: parent.root_font_size,
font_size_keyword: parent.font_size_keyword,
cached_system_font: None,
% for style_struct in data.style_structs:
% if style_struct.inherited:
${style_struct.ident}: parent.${style_struct.ident}.clone(),
Expand All @@ -126,6 +128,7 @@ impl ComputedValues {
custom_properties: custom_properties,
writing_mode: writing_mode,
root_font_size: root_font_size,
cached_system_font: None,
font_size_keyword: font_size_keyword,
% for style_struct in data.style_structs:
${style_struct.ident}: ${style_struct.ident},
Expand All @@ -139,6 +142,7 @@ impl ComputedValues {
writing_mode: WritingMode::empty(), // FIXME(bz): This seems dubious
root_font_size: longhands::font_size::get_initial_value(), // FIXME(bz): Also seems dubious?
font_size_keyword: Some((Default::default(), 1.)),
cached_system_font: None,
% for style_struct in data.style_structs:
${style_struct.ident}: style_structs::${style_struct.name}::default(pres_context),
% endfor
Expand Down
5 changes: 5 additions & 0 deletions components/style/properties/helpers.mako.rs
Expand Up @@ -265,6 +265,11 @@
<% maybe_wm = ", wm" if property.logical else "" %>
match *value {
DeclaredValue::Value(ref specified_value) => {
% if property.ident in "font_size font_family".split() and product == "gecko":
if let Some(sf) = specified_value.get_system() {
longhands::system_font::resolve_system_font(sf, context);
}
% endif
let computed = specified_value.to_computed_value(context);
% if property.ident == "font_size":
if let longhands::font_size::SpecifiedValue::Keyword(kw, fraction)
Expand Down
Expand Up @@ -358,7 +358,7 @@ impl AnimationValue {
}

/// Construct an AnimationValue from a property declaration
pub fn from_declaration(decl: &PropertyDeclaration, context: &Context, initial: &ComputedValues) -> Option<Self> {
pub fn from_declaration(decl: &PropertyDeclaration, context: &mut Context, initial: &ComputedValues) -> Option<Self> {
use error_reporting::StdoutErrorReporter;
use properties::LonghandId;
use properties::DeclaredValue;
Expand All @@ -367,6 +367,11 @@ impl AnimationValue {
% for prop in data.longhands:
% if prop.animatable:
PropertyDeclaration::${prop.camel_case}(ref val) => {
% if prop.ident in "font_size font_family".split() and product == "gecko":
if let Some(sf) = val.get_system() {
longhands::system_font::resolve_system_font(sf, context);
}
% endif
Some(AnimationValue::${prop.camel_case}(val.to_computed_value(context)))
},
% endif
Expand Down

0 comments on commit 2c5ac9f

Please sign in to comment.