Skip to content

Commit

Permalink
Implement basic last-resort font selection.
Browse files Browse the repository at this point in the history
  • Loading branch information
Caitlin Potter committed Jun 10, 2013
1 parent 8ee1b5f commit 24ef69d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/components/gfx/font_context.rs
Expand Up @@ -112,14 +112,14 @@ pub impl<'self> FontContext {

debug!("(create font group) --- starting ---");

let list = self.get_font_list();

// TODO(Issue #193): make iteration over 'font-family' more robust.
for str::each_split_char(style.families, ',') |family| {
let family_name = str::trim(family);
let transformed_family_name = self.transform_family(family_name);
debug!("(create font group) transformed family is `%s`", transformed_family_name);

let list = self.get_font_list();

let result = list.find_font_in_family(transformed_family_name, style);
let mut found = false;
for result.each |font_entry| {
Expand All @@ -134,6 +134,16 @@ pub impl<'self> FontContext {
}
}

let last_resort = FontList::get_last_resort_font_families();

for last_resort.each |family| {
let result = list.find_font_in_family(*family,style);
for result.each |font_entry| {
let instance = Font::new_from_existing_handle(self, &font_entry.handle, style, self.backend);
do result::iter(&instance) |font: &@mut Font| { fonts.push(*font); }
}
}

assert!(fonts.len() > 0);
// TODO(Issue #179): Split FontStyle into specified and used styles
let used_style = copy *style;
Expand Down
6 changes: 6 additions & 0 deletions src/components/gfx/font_list.rs
Expand Up @@ -19,6 +19,7 @@ pub type FontFamilyMap = HashMap<~str, @mut FontFamily>;
trait FontListHandleMethods {
fn get_available_families(&self, fctx: &FontContextHandle) -> FontFamilyMap;
fn load_variations_for_family(&self, family: @mut FontFamily);
fn get_last_resort_font_families() -> ~[~str];
}

/// The platform-independent font list abstraction.
Expand Down Expand Up @@ -86,6 +87,11 @@ pub impl FontList {
// TODO(Issue #188): look up localized font family names if canonical name not found
family.map(|f| **f)
}

pub fn get_last_resort_font_families() -> ~[~str] {
let last_resort = FontListHandle::get_last_resort_font_families();
last_resort
}
}

// Holds a specific font family, and the various
Expand Down
4 changes: 4 additions & 0 deletions src/components/gfx/platform/linux/font_list.rs
Expand Up @@ -125,6 +125,10 @@ pub impl FontListHandle {
FcObjectSetDestroy(object_set);
}
}

fn get_last_resort_font_families() -> ~[~str] {
~[~"Arial"]
}
}

struct AutoPattern {
Expand Down
4 changes: 4 additions & 0 deletions src/components/gfx/platform/macos/font_list.rs
Expand Up @@ -55,4 +55,8 @@ pub impl FontListHandle {
family.entries.push(entry)
}
}

fn get_last_resort_font_families() -> ~[~str] {
~[~"Arial Unicode MS",~"Arial"]
}
}

5 comments on commit 24ef69d

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from jdm
at caitp@24ef69d

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging caitp/servo/issue-479 = 24ef69d into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

caitp/servo/issue-479 = 24ef69d merged ok, testing candidate = 3203b33

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 3203b33

Please sign in to comment.