Skip to content

Commit

Permalink
Auto merge of #16564 - Manishearth:stylo-sys-2, r=xidorn
Browse files Browse the repository at this point in the history
stylo: Support system fonts

r=xidorn https://bugzilla.mozilla.org/show_bug.cgi?id=1349417

(take 2, we backed out the last one due to heap hazards)
  • Loading branch information
bors-servo committed Apr 21, 2017
2 parents 2b5c17c + 8bfcc69 commit 97c14f0
Show file tree
Hide file tree
Showing 11 changed files with 860 additions and 193 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,8 +8,10 @@

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 nsstring::nsAString;
use precomputed_hash::PrecomputedHash;
use std::borrow::{Cow, Borrow};
use std::char::{self, DecodeUtf16};
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
12 changes: 12 additions & 0 deletions components/style/properties/data.py
Expand Up @@ -13,6 +13,13 @@
ALL_SIDES = [(side, False) for side in PHYSICAL_SIDES] + [(side, True) for side in LOGICAL_SIDES]
ALL_SIZES = [(size, False) for size in PHYSICAL_SIZES] + [(size, True) for size in LOGICAL_SIZES]

SYSTEM_FONT_LONGHANDS = """font_family font_size font_style
font_variant_caps font_stretch font_kerning
font_variant_position font_weight
font_size_adjust font_variant_alternates
font_variant_ligatures font_variant_east_asian
font_variant_numeric font_language_override""".split()


def maybe_moz_logical_alias(product, side, prop):
if product == "gecko" and side[1]:
Expand All @@ -33,6 +40,11 @@ def to_camel_case(ident):
return re.sub("(^|_|-)([a-z])", lambda m: m.group(2).upper(), ident.strip("_").strip("-"))


def to_camel_case_lower(ident):
camel = to_camel_case(ident)
return camel[0].lower() + camel[1:]


def parse_aliases(value):
aliases = {}
for pair in value.split():
Expand Down
99 changes: 21 additions & 78 deletions components/style/properties/gecko.mako.rs
Expand Up @@ -95,6 +95,8 @@ 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)>,
/// The cached system font. See longhand/font.mako.rs
pub cached_system_font: Option<longhands::system_font::ComputedSystemFont>,
}

impl ComputedValues {
Expand All @@ -104,6 +106,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 +129,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 +143,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 Expand Up @@ -294,27 +299,6 @@ def set_gecko_property(ffi_name, expr):
}
</%def>

<%def name="impl_bitflags_setter(ident, gecko_ffi_name, bit_map, gecko_bit_prefix, cast_type='u8')">
#[allow(non_snake_case)]
pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
% for gecko_bit in bit_map.values():
use gecko_bindings::structs::${gecko_bit_prefix}${gecko_bit};
% endfor

let mut bits: ${cast_type} = 0;
// FIXME: if we ensure that the Servo bitflags storage is the same
// as Gecko's one, we can just copy it.
% for servo_bit, gecko_bit in bit_map.iteritems():
if v.contains(longhands::${ident}::${servo_bit}) {
bits |= ${gecko_bit_prefix}${gecko_bit} as ${cast_type};
}
% endfor

self.gecko.${gecko_ffi_name} = bits as ${cast_type};
}
</%def>


/// Convert a Servo color into an nscolor; with currentColor as 0
///
/// Call sites will need to be updated after https://bugzilla.mozilla.org/show_bug.cgi?id=760345
Expand Down Expand Up @@ -1590,74 +1574,33 @@ fn static_assert() {
}
${impl_simple_copy('font_language_override', 'mFont.languageOverride')}

<% font_variant_alternates_map = { "HISTORICAL_FORMS": "HISTORICAL",
"STYLISTIC": "STYLISTIC",
"STYLESET": "STYLESET",
"CHARACTER_VARIANT": "CHARACTER_VARIANT",
"SWASH": "SWASH",
"ORNAMENTS": "ORNAMENTS",
"ANNOTATION": "ANNOTATION" } %>
// FIXME: Set alternateValues as well.
// self.gecko.mFont.alternateValues = xxx;
${impl_bitflags_setter('font_variant_alternates',
'mFont.variantAlternates',
font_variant_alternates_map,
'NS_FONT_VARIANT_ALTERNATES_',
cast_type='u16')}
pub fn set_font_variant_alternates(&mut self, v: longhands::font_variant_alternates::computed_value::T) {
self.gecko.mFont.variantAlternates = v.to_gecko_keyword()
}

#[allow(non_snake_case)]
pub fn copy_font_variant_alternates_from(&mut self, other: &Self) {
self.gecko.mFont.variantAlternates = other.gecko.mFont.variantAlternates;
// FIXME: Copy alternateValues as well.
// self.gecko.mFont.alternateValues = other.gecko.mFont.alternateValues;
}

// servo_bit: gecko_bit
<% font_variant_ligatures_map = { "NONE": "NONE",
"COMMON_LIGATURES": "COMMON",
"NO_COMMON_LIGATURES": "NO_COMMON",
"DISCRETIONARY_LIGATURES": "DISCRETIONARY",
"NO_DISCRETIONARY_LIGATURES": "NO_DISCRETIONARY",
"HISTORICAL_LIGATURES": "HISTORICAL",
"NO_HISTORICAL_LIGATURES": "NO_HISTORICAL",
"CONTEXTUAL": "CONTEXTUAL",
"NO_CONTEXTUAL": "NO_CONTEXTUAL" } %>
${impl_bitflags_setter('font_variant_ligatures',
'mFont.variantLigatures',
font_variant_ligatures_map,
'NS_FONT_VARIANT_LIGATURES_',
cast_type='u16')}
pub fn set_font_variant_ligatures(&mut self, v: longhands::font_variant_ligatures::computed_value::T) {
self.gecko.mFont.variantLigatures = v.to_gecko_keyword()
}

${impl_simple_copy('font_variant_ligatures', 'mFont.variantLigatures')}

// servo_bit: gecko_bit
<% font_variant_east_asian_map = { "JIS78": "JIS78",
"JIS83": "JIS83",
"JIS90": "JIS90",
"JIS04": "JIS04",
"SIMPLIFIED": "SIMPLIFIED",
"TRADITIONAL": "TRADITIONAL",
"FULL_WIDTH": "FULL_WIDTH",
"PROPORTIONAL_WIDTH": "PROP_WIDTH",
"RUBY": "RUBY" } %>
${impl_bitflags_setter('font_variant_east_asian',
'mFont.variantEastAsian',
font_variant_east_asian_map,
'NS_FONT_VARIANT_EAST_ASIAN_',
cast_type='u16')}
pub fn set_font_variant_east_asian(&mut self, v: longhands::font_variant_east_asian::computed_value::T) {
self.gecko.mFont.variantEastAsian = v.to_gecko_keyword()
}

${impl_simple_copy('font_variant_east_asian', 'mFont.variantEastAsian')}

// servo_bit: gecko_bit
<% font_variant_numeric_map = { "LINING_NUMS": "LINING",
"OLDSTYLE_NUMS": "OLDSTYLE",
"PROPORTIONAL_NUMS": "PROPORTIONAL",
"TABULAR_NUMS": "TABULAR",
"DIAGONAL_FRACTIONS": "DIAGONAL_FRACTIONS",
"STACKED_FRACTIONS": "STACKED_FRACTIONS",
"SLASHED_ZERO": "SLASHZERO",
"ORDINAL": "ORDINAL" } %>
${impl_bitflags_setter('font_variant_numeric',
'mFont.variantNumeric',
font_variant_numeric_map,
'NS_FONT_VARIANT_NUMERIC_')}
pub fn set_font_variant_numeric(&mut self, v: longhands::font_variant_numeric::computed_value::T) {
self.gecko.mFont.variantNumeric = v.to_gecko_keyword()
}

${impl_simple_copy('font_variant_numeric', 'mFont.variantNumeric')}
</%self:impl_trait>

Expand Down

0 comments on commit 97c14f0

Please sign in to comment.