mirror of
https://github.com/servo/servo.git
synced 2025-08-08 15:05:35 +01:00
A few clean ups for Au type
This commit is contained in:
parent
7a3d2c8cb4
commit
5684a75187
3 changed files with 25 additions and 51 deletions
|
@ -25,12 +25,26 @@ use std::ptr;
|
|||
use std::sync::Arc;
|
||||
use style::computed_values::{font_stretch, font_weight};
|
||||
use text::glyph::GlyphId;
|
||||
use util::geometry::{Au, px_to_pt};
|
||||
use util::geometry::Au;
|
||||
|
||||
pub struct FontTable {
|
||||
data: CFData,
|
||||
}
|
||||
|
||||
// assumes 72 points per inch, and 96 px per inch
|
||||
fn px_to_pt(px: f64) -> f64 {
|
||||
px / 96. * 72.
|
||||
}
|
||||
|
||||
// assumes 72 points per inch, and 96 px per inch
|
||||
fn pt_to_px(pt: f64) -> f64 {
|
||||
pt / 72. * 96.
|
||||
}
|
||||
|
||||
fn au_from_pt(pt: f64) -> Au {
|
||||
Au::from_f64_px(pt_to_px(pt))
|
||||
}
|
||||
|
||||
impl FontTable {
|
||||
pub fn wrap(data: CFData) -> FontTable {
|
||||
FontTable { data: data }
|
||||
|
@ -161,27 +175,27 @@ impl FontHandleMethods for FontHandle {
|
|||
let scale = px_to_pt(self.ctfont.pt_size() as f64) / (ascent + descent);
|
||||
let line_gap = (ascent + descent + leading + 0.5).floor();
|
||||
|
||||
let max_advance_width = Au::from_pt(bounding_rect.size.width as f64);
|
||||
let max_advance_width = au_from_pt(bounding_rect.size.width as f64);
|
||||
let average_advance = self.glyph_index('0')
|
||||
.and_then(|idx| self.glyph_h_advance(idx))
|
||||
.map(|advance| Au::from_f64_px(advance))
|
||||
.unwrap_or(max_advance_width);
|
||||
|
||||
let metrics = FontMetrics {
|
||||
underline_size: Au::from_pt(self.ctfont.underline_thickness() as f64),
|
||||
underline_size: au_from_pt(self.ctfont.underline_thickness() as f64),
|
||||
// TODO(Issue #201): underline metrics are not reliable. Have to pull out of font table
|
||||
// directly.
|
||||
//
|
||||
// see also: https://bugs.webkit.org/show_bug.cgi?id=16768
|
||||
// see also: https://bugreports.qt-project.org/browse/QTBUG-13364
|
||||
underline_offset: Au::from_pt(self.ctfont.underline_position() as f64),
|
||||
underline_offset: au_from_pt(self.ctfont.underline_position() as f64),
|
||||
strikeout_size: Au(0), // FIXME(Issue #942)
|
||||
strikeout_offset: Au(0), // FIXME(Issue #942)
|
||||
leading: Au::from_pt(leading),
|
||||
x_height: Au::from_pt(self.ctfont.x_height() as f64),
|
||||
leading: au_from_pt(leading),
|
||||
x_height: au_from_pt(self.ctfont.x_height() as f64),
|
||||
em_size: em_size,
|
||||
ascent: Au::from_pt(ascent * scale),
|
||||
descent: Au::from_pt(descent * scale),
|
||||
ascent: au_from_pt(ascent * scale),
|
||||
descent: au_from_pt(descent * scale),
|
||||
max_advance: max_advance_width,
|
||||
average_advance: average_advance,
|
||||
line_gap: Au::from_f64_px(line_gap),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue