Skip to content

Commit

Permalink
Support font-family in geckolib
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrubeck committed Jun 8, 2016
1 parent 280bfc9 commit 670309e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
9 changes: 9 additions & 0 deletions ports/geckolib/gecko_bindings/bindings.rs
Expand Up @@ -32,6 +32,9 @@ use structs::SheetParsingMode;
use structs::nsMainThreadPtrHandle;
use structs::nsMainThreadPtrHolder;
use structs::nscolor;
use structs::nsFont;
use structs::FontFamilyList;
use structs::FontFamilyType;
use heapsize::HeapSizeOf;
unsafe impl Send for nsStyleFont {}
unsafe impl Sync for nsStyleFont {}
Expand Down Expand Up @@ -185,6 +188,12 @@ extern "C" {
aString:
*const ::std::os::raw::c_char,
aLength: u32) -> bool;
pub fn Gecko_FontFamilyList_Clear(aList: *mut FontFamilyList);
pub fn Gecko_FontFamilyList_AppendNamed(aList: *mut FontFamilyList,
aName: *mut nsIAtom);
pub fn Gecko_FontFamilyList_AppendGeneric(list: *mut FontFamilyList,
familyType: FontFamilyType);
pub fn Gecko_CopyFontFamilyFrom(dst: *mut nsFont, src: *const nsFont);
pub fn Gecko_SetListStyleType(style_struct: *mut nsStyleList, type_: u32);
pub fn Gecko_CopyListStyleTypeFrom(dst: *mut nsStyleList,
src: *const nsStyleList);
Expand Down
3 changes: 2 additions & 1 deletion ports/geckolib/gecko_bindings/tools/regen_bindings.sh
Expand Up @@ -51,7 +51,8 @@ do
done

# Other mapped types.
for TYPE in SheetParsingMode nsMainThreadPtrHandle nsMainThreadPtrHolder nscolor
for TYPE in SheetParsingMode nsMainThreadPtrHandle nsMainThreadPtrHolder nscolor nsFont \
FontFamilyList FontFamilyType
do
MAP_GECKO_TYPES=$MAP_GECKO_TYPES"-blacklist-type $TYPE "
MAP_GECKO_TYPES=$MAP_GECKO_TYPES"-raw-line 'use structs::$TYPE;' "
Expand Down
39 changes: 37 additions & 2 deletions ports/geckolib/properties.mako.rs
Expand Up @@ -20,7 +20,9 @@ use gecko_bindings::bindings::{Gecko_CopyMozBindingFrom, Gecko_CopyListStyleType
use gecko_bindings::bindings::{Gecko_SetMozBinding, Gecko_SetListStyleType};
use gecko_bindings::bindings::{Gecko_SetNullImageValue, Gecko_SetGradientImageValue};
use gecko_bindings::bindings::{Gecko_CreateGradient};
use gecko_bindings::bindings::{Gecko_CopyImageValueFrom};
use gecko_bindings::bindings::{Gecko_CopyImageValueFrom, Gecko_CopyFontFamilyFrom};
use gecko_bindings::bindings::{Gecko_FontFamilyList_AppendGeneric, Gecko_FontFamilyList_AppendNamed};
use gecko_bindings::bindings::{Gecko_FontFamilyList_Clear};
use gecko_bindings::structs;
use glue::ArcHelpers;
use std::fmt::{self, Debug};
Expand Down Expand Up @@ -604,7 +606,40 @@ fn static_assert() {
}
</%self:impl_trait>

<%self:impl_trait style_struct_name="Font" skip_longhands="font-style font-size font-weight" skip_additionals="*">
<%self:impl_trait style_struct_name="Font"
skip_longhands="font-family font-style font-size font-weight"
skip_additionals="*">

fn set_font_family(&mut self, v: longhands::font_family::computed_value::T) {
use style::properties::longhands::font_family::computed_value::FontFamily;
use gecko_bindings::structs::FontFamilyType;

let list = &mut self.gecko.mFont.fontlist;
unsafe { Gecko_FontFamilyList_Clear(list); }

for family in &v.0 {
match *family {
FontFamily::FamilyName(ref name) => {
unsafe { Gecko_FontFamilyList_AppendNamed(list, name.as_ptr()); }
}
FontFamily::Generic(ref name) => {
let family_type =
if name == &atom!("serif") { FontFamilyType::eFamily_serif }
else if name == &atom!("sans-serif") { FontFamilyType::eFamily_sans_serif }
else if name == &atom!("cursive") { FontFamilyType::eFamily_cursive }
else if name == &atom!("fantasy") { FontFamilyType::eFamily_fantasy }
else if name == &atom!("monospace") { FontFamilyType::eFamily_monospace }
else { panic!("Unknown generic font family") };
unsafe { Gecko_FontFamilyList_AppendGeneric(list, family_type); }
}
}
}
}

fn copy_font_family_from(&mut self, other: &Self) {
unsafe { Gecko_CopyFontFamilyFrom(&mut self.gecko.mFont, &other.gecko.mFont); }
}

<%call expr="impl_keyword('font_style', 'mFont.style',
data.longhands_by_name['font-style'].keyword, need_clone=False)"></%call>

Expand Down

0 comments on commit 670309e

Please sign in to comment.