diff options
author | bors-servo <metajack+bors@gmail.com> | 2014-10-22 03:30:36 -0600 |
---|---|---|
committer | bors-servo <metajack+bors@gmail.com> | 2014-10-22 03:30:36 -0600 |
commit | 4b508195ace7490fda08f6d40fe64165feb91edd (patch) | |
tree | fa71e2f559db91188e2883b1f29598157bcc3c89 | |
parent | 97762205ab7b77a25a1c0da765a9504176d0da73 (diff) | |
parent | 8331cfe089b0d93f0b2941b6338c3ecd5601c102 (diff) | |
download | servo-4b508195ace7490fda08f6d40fe64165feb91edd.tar.gz servo-4b508195ace7490fda08f6d40fe64165feb91edd.zip |
auto merge of #3769 : glennw/servo/font-au, r=pcwalton
-rw-r--r-- | components/gfx/font.rs | 6 | ||||
-rw-r--r-- | components/gfx/font_context.rs | 25 | ||||
-rw-r--r-- | components/gfx/platform/freetype/font.rs | 8 | ||||
-rw-r--r-- | components/gfx/platform/macos/font.rs | 4 | ||||
-rw-r--r-- | components/gfx/text/shaping/harfbuzz.rs | 2 | ||||
-rw-r--r-- | components/gfx/text/text_run.rs | 2 |
6 files changed, 24 insertions, 23 deletions
diff --git a/components/gfx/font.rs b/components/gfx/font.rs index f88d964b831..76beb89eb5a 100644 --- a/components/gfx/font.rs +++ b/components/gfx/font.rs @@ -28,7 +28,7 @@ use platform::font_template::FontTemplateData; // resources needed by the graphics layer to draw glyphs. pub trait FontHandleMethods { - fn new_from_template(fctx: &FontContextHandle, template: Arc<FontTemplateData>, pt_size: Option<f64>) + fn new_from_template(fctx: &FontContextHandle, template: Arc<FontTemplateData>, pt_size: Option<Au>) -> Result<Self,()>; fn get_template(&self) -> Arc<FontTemplateData>; fn family_name(&self) -> String; @@ -92,8 +92,8 @@ pub struct Font { pub metrics: FontMetrics, pub variant: font_variant::T, pub descriptor: FontTemplateDescriptor, - pub requested_pt_size: f64, - pub actual_pt_size: f64, + pub requested_pt_size: Au, + pub actual_pt_size: Au, pub shaper: Option<Shaper>, pub shape_cache: HashCache<String, Arc<GlyphStore>>, pub glyph_advance_cache: HashCache<u32, FractionalPixel>, diff --git a/components/gfx/font_context.rs b/components/gfx/font_context.rs index adcd9810b88..6a1ac25ccde 100644 --- a/components/gfx/font_context.rs +++ b/components/gfx/font_context.rs @@ -14,6 +14,7 @@ use font::FontHandleMethods; use platform::font::FontHandle; use servo_util::cache::HashCache; use servo_util::smallvec::{SmallVec, SmallVec1}; +use servo_util::geometry::Au; use std::rc::Rc; use std::cell::RefCell; @@ -29,14 +30,14 @@ use azure::scaled_font::FontData; #[cfg(target_os="linux")] #[cfg(target_os="android")] -fn create_scaled_font(template: &Arc<FontTemplateData>, pt_size: f64) -> ScaledFont { - ScaledFont::new(SkiaBackend, FontData(&template.bytes), pt_size as AzFloat) +fn create_scaled_font(template: &Arc<FontTemplateData>, pt_size: Au) -> ScaledFont { + ScaledFont::new(SkiaBackend, FontData(&template.bytes), pt_size.to_subpx() as AzFloat) } #[cfg(target_os="macos")] -fn create_scaled_font(template: &Arc<FontTemplateData>, pt_size: f64) -> ScaledFont { +fn create_scaled_font(template: &Arc<FontTemplateData>, pt_size: Au) -> ScaledFont { let cgfont = template.ctfont.as_ref().unwrap().copy_to_CGFont(); - ScaledFont::new(SkiaBackend, &cgfont, pt_size as AzFloat) + ScaledFont::new(SkiaBackend, &cgfont, pt_size.to_subpx() as AzFloat) } static SMALL_CAPS_SCALE_FACTOR: f64 = 0.8; // Matches FireFox (see gfxFont.h) @@ -53,7 +54,7 @@ struct FallbackFontCacheEntry { /// A cached azure font (per render task) that /// can be shared by multiple text runs. struct RenderFontCacheEntry { - pt_size: f64, + pt_size: Au, identifier: String, font: Rc<RefCell<ScaledFont>>, } @@ -89,13 +90,13 @@ impl FontContext { /// Create a font for use in layout calculations. fn create_layout_font(&self, template: Arc<FontTemplateData>, - descriptor: FontTemplateDescriptor, pt_size: f64, + descriptor: FontTemplateDescriptor, pt_size: Au, variant: font_variant::T) -> Font { // TODO: (Bug #3463): Currently we only support fake small-caps // rendering. We should also support true small-caps (where the // font supports it) in the future. let actual_pt_size = match variant { - font_variant::small_caps => pt_size * SMALL_CAPS_SCALE_FACTOR, + font_variant::small_caps => pt_size.scale_by(SMALL_CAPS_SCALE_FACTOR), font_variant::normal => pt_size, }; @@ -140,7 +141,7 @@ impl FontContext { Some(ref cached_font_ref) => { let cached_font = cached_font_ref.borrow(); if cached_font.descriptor == desc && - cached_font.requested_pt_size == style.font_size.to_subpx() && + cached_font.requested_pt_size == style.font_size && cached_font.variant == style.font_variant { fonts.push((*cached_font_ref).clone()); cache_hit = true; @@ -159,7 +160,7 @@ impl FontContext { Some(font_template) => { let layout_font = self.create_layout_font(font_template, desc.clone(), - style.font_size.to_subpx(), + style.font_size, style.font_variant); let layout_font = Rc::new(RefCell::new(layout_font)); self.layout_font_cache.push(LayoutFontCacheEntry { @@ -185,7 +186,7 @@ impl FontContext { for cached_font_entry in self.fallback_font_cache.iter() { let cached_font = cached_font_entry.font.borrow(); if cached_font.descriptor == desc && - cached_font.requested_pt_size == style.font_size.to_subpx() && + cached_font.requested_pt_size == style.font_size && cached_font.variant == style.font_variant { fonts.push(cached_font_entry.font.clone()); cache_hit = true; @@ -197,7 +198,7 @@ impl FontContext { let font_template = self.font_cache_task.get_last_resort_font_template(desc.clone()); let layout_font = self.create_layout_font(font_template, desc.clone(), - style.font_size.to_subpx(), + style.font_size, style.font_variant); let layout_font = Rc::new(RefCell::new(layout_font)); self.fallback_font_cache.push(FallbackFontCacheEntry { @@ -214,7 +215,7 @@ impl FontContext { /// reference if already used by this font context. pub fn get_render_font_from_template(&mut self, template: &Arc<FontTemplateData>, - pt_size: f64) -> Rc<RefCell<ScaledFont>> { + pt_size: Au) -> Rc<RefCell<ScaledFont>> { for cached_font in self.render_font_cache.iter() { if cached_font.pt_size == pt_size && cached_font.identifier == template.identifier { diff --git a/components/gfx/platform/freetype/font.rs b/components/gfx/platform/freetype/font.rs index 3869291246a..4bd5aded06e 100644 --- a/components/gfx/platform/freetype/font.rs +++ b/components/gfx/platform/freetype/font.rs @@ -70,7 +70,7 @@ impl Drop for FontHandle { impl FontHandleMethods for FontHandle { fn new_from_template(fctx: &FontContextHandle, template: Arc<FontTemplateData>, - pt_size: Option<f64>) + pt_size: Option<Au>) -> Result<FontHandle, ()> { let ft_ctx: FT_Library = fctx.ctx.ctx; if ft_ctx.is_null() { return Err(()); } @@ -93,7 +93,7 @@ impl FontHandleMethods for FontHandle { Err(()) => Err(()) }; - fn create_face_from_buffer(lib: FT_Library, cbuf: *const u8, cbuflen: uint, pt_size: Option<f64>) + fn create_face_from_buffer(lib: FT_Library, cbuf: *const u8, cbuflen: uint, pt_size: Option<Au>) -> Result<FT_Face, ()> { unsafe { let mut face: FT_Face = ptr::null_mut(); @@ -265,8 +265,8 @@ impl FontHandleMethods for FontHandle { } impl<'a> FontHandle { - fn set_char_size(face: FT_Face, pt_size: f64) -> Result<(), ()>{ - let char_width = float_to_fixed_ft((0.5f64 + pt_size).floor()) as FT_F26Dot6; + fn set_char_size(face: FT_Face, pt_size: Au) -> Result<(), ()>{ + let char_width = float_to_fixed_ft((0.5f64 + pt_size.to_subpx()).floor()) as FT_F26Dot6; unsafe { let result = FT_Set_Char_Size(face, char_width, 0, 0, 0); diff --git a/components/gfx/platform/macos/font.rs b/components/gfx/platform/macos/font.rs index dd48e797cd1..b621c2991ce 100644 --- a/components/gfx/platform/macos/font.rs +++ b/components/gfx/platform/macos/font.rs @@ -59,10 +59,10 @@ pub struct FontHandle { impl FontHandleMethods for FontHandle { fn new_from_template(_fctx: &FontContextHandle, template: Arc<FontTemplateData>, - pt_size: Option<f64>) + pt_size: Option<Au>) -> Result<FontHandle, ()> { let size = match pt_size { - Some(s) => s, + Some(s) => s.to_subpx(), None => 0.0 }; match template.ctfont { diff --git a/components/gfx/text/shaping/harfbuzz.rs b/components/gfx/text/shaping/harfbuzz.rs index 7640aa9e0c6..a6243b4d481 100644 --- a/components/gfx/text/shaping/harfbuzz.rs +++ b/components/gfx/text/shaping/harfbuzz.rs @@ -164,7 +164,7 @@ impl Shaper { let hb_font: *mut hb_font_t = hb_font_create(hb_face); // Set points-per-em. if zero, performs no hinting in that direction. - let pt_size = font.actual_pt_size; + let pt_size = font.actual_pt_size.to_subpx(); hb_font_set_ppem(hb_font, pt_size as c_uint, pt_size as c_uint); // Set scaling. Note that this takes 16.16 fixed point. diff --git a/components/gfx/text/text_run.rs b/components/gfx/text/text_run.rs index 4ab5aed94e0..0136b848ba5 100644 --- a/components/gfx/text/text_run.rs +++ b/components/gfx/text/text_run.rs @@ -17,7 +17,7 @@ use platform::font_template::FontTemplateData; pub struct TextRun { pub text: Arc<String>, pub font_template: Arc<FontTemplateData>, - pub actual_pt_size: f64, + pub actual_pt_size: Au, pub font_metrics: FontMetrics, /// The glyph runs that make up this text run. pub glyphs: Arc<Vec<GlyphRun>>, |