Skip to content

Commit

Permalink
Document the Au struct and add similar font metrics debug as mac
Browse files Browse the repository at this point in the history
  • Loading branch information
dhedlund committed Dec 9, 2013
1 parent 76e3b34 commit 00e3a21
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/components/gfx/platform/android/font.rs
Expand Up @@ -244,7 +244,7 @@ impl FontHandleMethods for FontHandle {
}
}

return FontMetrics {
let metrics = FontMetrics {
underline_size: underline_size,
underline_offset: underline_offset,
strikeout_size: strikeout_size,
Expand All @@ -255,7 +255,10 @@ impl FontHandleMethods for FontHandle {
ascent: ascent,
descent: -descent, // linux font's seem to use the opposite sign from mac
max_advance: max_advance
}
};

debug!("Font metrics (@{:f} pt): {:?}", geometry::to_pt(em_size), metrics);
return metrics;
}

fn get_table_for_tag(&self, _: FontTableTag) -> Option<FontTable> {
Expand Down
7 changes: 5 additions & 2 deletions src/components/gfx/platform/linux/font.rs
Expand Up @@ -243,7 +243,7 @@ impl FontHandleMethods for FontHandle {
}
}

return FontMetrics {
let metrics = FontMetrics {
underline_size: underline_size,
underline_offset: underline_offset,
strikeout_size: strikeout_size,
Expand All @@ -254,7 +254,10 @@ impl FontHandleMethods for FontHandle {
ascent: ascent,
descent: -descent, // linux font's seem to use the opposite sign from mac
max_advance: max_advance
}
};

debug!("Font metrics (@{:f} pt): {:?}", geometry::to_pt(em_size), metrics);
return metrics;
}

fn get_table_for_tag(&self, _: FontTableTag) -> Option<FontTable> {
Expand Down
8 changes: 8 additions & 0 deletions src/components/util/geometry.rs
Expand Up @@ -9,6 +9,9 @@ use geom::size::Size2D;
use std::num::{NumCast, One, Zero};
use std::fmt;

// An Au is an "App Unit" and represents 1/60th of a CSS pixel. It was
// originally proposed in 2002 as a standard unit of measure in Gecko.
// See https://bugzilla.mozilla.org/show_bug.cgi?id=177805 for more info.
pub struct Au(i32);

// We don't use #[deriving] here for inlining.
Expand Down Expand Up @@ -225,3 +228,8 @@ pub fn from_pt(pt: f64) -> Au {
from_px((pt / 72f64 * 96f64) as int)
}

// assumes 72 points per inch, and 96 px per inch
pub fn to_pt(au: Au) -> f64 {
(*au as f64) / 60f64 * 72f64 / 96f64
}

0 comments on commit 00e3a21

Please sign in to comment.