From 9822f5d96b4dc24d78553a3883f084f0cb9887c5 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 5 Apr 2013 16:12:24 -0700 Subject: [PATCH] Refactor the Linux font stuff --- src/servo-gfx/font.rs | 8 +-- src/servo-gfx/font_context.rs | 11 ++- src/servo-gfx/font_list.rs | 9 +-- .../{freetype_impl => platform/linux}/font.rs | 69 +++++-------------- .../linux}/font_context.rs | 24 +++---- .../linux}/font_list.rs | 38 ++++++---- src/servo-gfx/servo_gfx.rc | 11 --- 7 files changed, 62 insertions(+), 108 deletions(-) rename src/servo-gfx/{freetype_impl => platform/linux}/font.rs (88%) rename src/servo-gfx/{freetype_impl => platform/linux}/font_context.rs (73%) rename src/servo-gfx/{fontconfig => platform/linux}/font_list.rs (78%) diff --git a/src/servo-gfx/font.rs b/src/servo-gfx/font.rs index ec7f98a9462..354239bfd82 100644 --- a/src/servo-gfx/font.rs +++ b/src/servo-gfx/font.rs @@ -16,8 +16,6 @@ use azure::scaled_font::ScaledFont; use azure::azure_hl::{BackendType, ColorPattern}; use geom::{Point2D, Rect, Size2D}; -#[cfg(target_os = "linux")] -use freetype_impl; use native; // FontHandle encapsulates access to the platform's font API, @@ -29,7 +27,7 @@ use native; pub type FontHandle = platform::font::QuartzFontHandle; #[cfg(target_os = "linux")] -pub type FontHandle = freetype_impl::font::FreeTypeFontHandle; +pub type FontHandle = platform::font::FreeTypeFontHandle; pub trait FontHandleMethods { // an identifier usable by FontContextHandle to recreate this FontHandle. @@ -65,7 +63,7 @@ pub impl FontHandle { buf: ~[u8], style: &SpecifiedFontStyle) -> Result { - freetype_impl::font::FreeTypeFontHandle::new_from_buffer(fctx, @buf, style) + platform::font::FreeTypeFontHandle::new_from_buffer(fctx, @buf, style) } } @@ -94,7 +92,7 @@ impl FontTableTagConversions for FontTableTag { pub type FontTable = platform::font::QuartzFontTable; #[cfg(target_os = "linux")] -pub type FontTable = freetype_impl::font::FreeTypeFontTable; +pub type FontTable = platform::font::FreeTypeFontTable; pub trait FontTableMethods { fn with_buffer(&self, &fn(*u8, uint)); diff --git a/src/servo-gfx/font_context.rs b/src/servo-gfx/font_context.rs index 733af2ebe1b..bfc96f37a4d 100644 --- a/src/servo-gfx/font_context.rs +++ b/src/servo-gfx/font_context.rs @@ -1,5 +1,8 @@ +//! The font context. + use font::{Font, FontDescriptor, FontGroup, FontStyle, SelectorPlatformIdentifier}; use font::{SelectorStubDummy, SpecifiedFontStyle, UsedFontStyle}; +use font_context; use font_list::FontList; use native::FontHandle; use platform; @@ -9,10 +12,6 @@ use util::cache::MonoCache; use azure::azure_hl::BackendType; use core::hashmap::HashMap; -#[cfg(target_os = "linux")] -use freetype_impl; -use font_context; - // TODO(Issue #164): delete, and get default font from font list static TEST_FONT: [u8, ..33004] = include_bin!("JosefinSans-SemiBold.ttf"); @@ -37,7 +36,7 @@ pub fn dummy_style() -> FontStyle { type FontContextHandle = platform::font_context::QuartzFontContextHandle; #[cfg(target_os = "linux")] -type FontContextHandle = freetype_impl::font_context::FreeTypeFontContextHandle; +type FontContextHandle = platform::font_context::FreeTypeFontContextHandle; pub trait FontContextHandleMethods { fn clone(&self) -> FontContextHandle; @@ -54,7 +53,7 @@ pub impl FontContextHandle { #[cfg(target_os = "linux")] pub fn new() -> FontContextHandle { - freetype_impl::font_context::FreeTypeFontContextHandle::new() + platform::font_context::FreeTypeFontContextHandle::new() } } diff --git a/src/servo-gfx/font_list.rs b/src/servo-gfx/font_list.rs index 218d57741ad..32413043db1 100644 --- a/src/servo-gfx/font_list.rs +++ b/src/servo-gfx/font_list.rs @@ -4,20 +4,17 @@ use font::{CSSFontWeight, SpecifiedFontStyle}; use gfx_font::FontHandleMethods; use gfx_font::FontHandleMethods; use native::FontHandle; +use native; use platform; use util::time::time; use core::hashmap::HashMap; -#[cfg(target_os = "linux")] -use fontconfig; -use native; - #[cfg(target_os = "macos")] type FontListHandle = platform::font_list::QuartzFontListHandle; #[cfg(target_os = "linux")] -type FontListHandle = fontconfig::font_list::FontconfigFontListHandle; +type FontListHandle = platform::font_list::FontconfigFontListHandle; pub impl FontListHandle { #[cfg(target_os = "macos")] @@ -27,7 +24,7 @@ pub impl FontListHandle { #[cfg(target_os = "linux")] pub fn new(fctx: &native::FontContextHandle) -> Result { - Ok(fontconfig::font_list::FontconfigFontListHandle::new(fctx)) + Ok(platform::font_list::FontconfigFontListHandle::new(fctx)) } } diff --git a/src/servo-gfx/freetype_impl/font.rs b/src/servo-gfx/platform/linux/font.rs similarity index 88% rename from src/servo-gfx/freetype_impl/font.rs rename to src/servo-gfx/platform/linux/font.rs index 234ffaeb00e..f09034cf4a0 100644 --- a/src/servo-gfx/freetype_impl/font.rs +++ b/src/servo-gfx/platform/linux/font.rs @@ -1,59 +1,28 @@ +//! Linux (FreeType) representation of fonts. + extern mod freetype; -use native; -use freetype_impl::font_context::FreeTypeFontContextHandle; -use gfx_font::{ - CSSFontWeight, - FontHandleMethods, - FontMetrics, - FontTable, - FontTableMethods, - FontTableTag, - FractionalPixel, - SpecifiedFontStyle, - UsedFontStyle, - FontWeight100, - FontWeight200, - FontWeight300, - FontWeight400, - FontWeight500, - FontWeight600, - FontWeight700, - FontWeight800, - FontWeight900, -}; -use geometry; use geometry::Au; +use geometry; +use gfx_font::{CSSFontWeight, FontHandleMethods, FontMetrics, FontTable, FontTableMethods}; +use gfx_font::{FontTableTag, FractionalPixel, SpecifiedFontStyle, UsedFontStyle, FontWeight100}; +use gfx_font::{FontWeight200, FontWeight300, FontWeight400, FontWeight500, FontWeight600}; +use gfx_font::{FontWeight700, FontWeight800, FontWeight900}; +use native; +use platform::font_context::FreeTypeFontContextHandle; use text::glyph::GlyphIndex; use text::util::{float_to_fixed, fixed_to_float}; -use self::freetype::freetype::{ - FTErrorMethods, - FT_F26Dot6, - FT_Face, - FT_FaceRec, - FT_GlyphSlot, - FT_Library, - FT_Long, - FT_ULong, - FT_SizeRec, - FT_UInt, - FT_Size_Metrics, - FT_STYLE_FLAG_ITALIC, - FT_STYLE_FLAG_BOLD, - ft_sfnt_os2 -}; -use self::freetype::freetype::bindgen::{ - FT_New_Memory_Face, - FT_Done_Face, - FT_Get_Char_Index, - FT_Get_Postscript_Name, - FT_Load_Glyph, - FT_Set_Char_Size, - FT_New_Face, - FT_Get_Sfnt_Table -}; -use self::freetype::tt_os2::TT_OS2; +use platform::font::freetype::freetype::bindgen::{FT_Get_Char_Index, FT_Get_Postscript_Name}; +use platform::font::freetype::freetype::bindgen::{FT_Load_Glyph, FT_Set_Char_Size}; +use platform::font::freetype::freetype::bindgen::{FT_New_Face, FT_Get_Sfnt_Table}; +use platform::font::freetype::freetype::bindgen::{FT_New_Memory_Face, FT_Done_Face}; +use platform::font::freetype::freetype::{FTErrorMethods, FT_F26Dot6, FT_Face, FT_FaceRec}; +use platform::font::freetype::freetype::{FT_GlyphSlot, FT_Library, FT_Long, FT_ULong}; +use platform::font::freetype::freetype::{FT_STYLE_FLAG_ITALIC, FT_STYLE_FLAG_BOLD}; +use platform::font::freetype::freetype::{FT_SizeRec, FT_UInt, FT_Size_Metrics}; +use platform::font::freetype::freetype::{ft_sfnt_os2}; +use platform::font::freetype::tt_os2::TT_OS2; fn float_to_fixed_ft(f: float) -> i32 { float_to_fixed(6, f) diff --git a/src/servo-gfx/freetype_impl/font_context.rs b/src/servo-gfx/platform/linux/font_context.rs similarity index 73% rename from src/servo-gfx/freetype_impl/font_context.rs rename to src/servo-gfx/platform/linux/font_context.rs index 98b5615bbaf..b81278b53e7 100644 --- a/src/servo-gfx/freetype_impl/font_context.rs +++ b/src/servo-gfx/platform/linux/font_context.rs @@ -1,22 +1,13 @@ extern mod freetype; extern mod fontconfig; -use self::freetype::freetype::{ - FTErrorMethods, - FT_Library, -}; -use self::freetype::freetype::bindgen::{ - FT_Init_FreeType, - FT_Done_FreeType -}; -use fontconfig::font_list::path_from_identifier; +use gfx_font::{FontHandle, UsedFontStyle}; +use platform::font::FreeTypeFontHandle; +use platform::font_context::FontContextHandleMethods; +use platform::font_list::path_from_identifier; -use gfx_font::{ - FontHandle, - UsedFontStyle, -}; -use font_context::FontContextHandleMethods; -use freetype_impl::font::FreeTypeFontHandle; +use platform::font_context::freetype::freetype::{FTErrorMethods, FT_Library}; +use platform::font_context::freetype::freetype::bindgen::{FT_Done_FreeType, FT_Init_FreeType}; struct FreeTypeLibraryHandle { ctx: FT_Library, @@ -50,7 +41,8 @@ impl FontContextHandleMethods for FreeTypeFontContextHandle { FreeTypeFontContextHandle { ctx: self.ctx } } - fn create_font_from_identifier(&self, name: ~str, style: UsedFontStyle) -> Result { + fn create_font_from_identifier(&self, name: ~str, style: UsedFontStyle) + -> Result { debug!("Creating font handle for %s", name); do path_from_identifier(name).chain |file_name| { debug!("Opening font face %s", file_name); diff --git a/src/servo-gfx/fontconfig/font_list.rs b/src/servo-gfx/platform/linux/font_list.rs similarity index 78% rename from src/servo-gfx/fontconfig/font_list.rs rename to src/servo-gfx/platform/linux/font_list.rs index 6ab2668b1f6..79027fb8d84 100644 --- a/src/servo-gfx/fontconfig/font_list.rs +++ b/src/servo-gfx/platform/linux/font_list.rs @@ -1,25 +1,34 @@ +//! Font list implementation for Linux (fontconfig). + extern mod freetype; extern mod fontconfig; use gfx_font::FontHandleMethods; -use gfx_font_list::{FontEntry, FontFamily, FontFamilyMap}; use gfx_font_context::FontContextHandleMethods; -use freetype_impl::font_context::FreeTypeFontContextHandle; -use freetype_impl::font::FreeTypeFontHandle; -use self::fontconfig::fontconfig::{FcChar8, FcResultMatch, FcSetSystem, - FcResultNoMatch, FcMatchPattern}; -use self::fontconfig::fontconfig::bindgen::{ - FcConfigGetCurrent, FcConfigGetFonts, FcPatternGetString, - FcPatternDestroy, FcFontSetDestroy, FcConfigSubstitute, - FcDefaultSubstitute, FcPatternCreate, FcPatternAddString, - FcFontMatch, FcFontSetList, FcObjectSetCreate, FcObjectSetDestroy, - FcObjectSetAdd, FcPatternGetInteger -}; +use gfx_font_list::{FontEntry, FontFamily, FontFamilyMap}; +use native; +use platform::font::FreeTypeFontHandle; +use platform::font_context::FreeTypeFontContextHandle; use core::hashmap::HashMap; use core::libc::c_int; use core::ptr::Ptr; -use native; +use platform::font_context::fontconfig::fontconfig::bindgen::{FcConfigGetCurrent}; +use platform::font_context::fontconfig::fontconfig::bindgen::{FcConfigGetFonts}; +use platform::font_context::fontconfig::fontconfig::bindgen::{FcDefaultSubstitute}; +use platform::font_context::fontconfig::fontconfig::bindgen::{FcPatternCreate}; +use platform::font_context::fontconfig::fontconfig::bindgen::{FcFontSetDestroy}; +use platform::font_context::fontconfig::fontconfig::bindgen::{FcConfigSubstitute}; +use platform::font_context::fontconfig::fontconfig::bindgen::{FcFontSetList}; +use platform::font_context::fontconfig::fontconfig::bindgen::{FcObjectSetCreate}; +use platform::font_context::fontconfig::fontconfig::bindgen::{FcObjectSetDestroy}; +use platform::font_context::fontconfig::fontconfig::bindgen::{FcObjectSetAdd}; +use platform::font_context::fontconfig::fontconfig::bindgen::{FcPatternAddString, FcFontMatch}; +use platform::font_context::fontconfig::fontconfig::bindgen::{FcPatternGetInteger}; +use platform::font_context::fontconfig::fontconfig::bindgen::{FcPatternGetString}; +use platform::font_context::fontconfig::fontconfig::bindgen::{FcPatternDestroy}; +use platform::font_context::fontconfig::fontconfig::{FcChar8, FcResultMatch, FcSetSystem}; +use platform::font_context::fontconfig::fontconfig::{FcMatchPattern, FcResultNoMatch}; pub struct FontconfigFontListHandle { fctx: FreeTypeFontContextHandle, @@ -99,7 +108,8 @@ pub impl FontconfigFontListHandle { debug!("variation file: %?", file); debug!("variation index: %?", index); - let font_handle = FreeTypeFontHandle::new_from_file_unstyled(&self.fctx, file); + let font_handle = FreeTypeFontHandle::new_from_file_unstyled(&self.fctx, + file); let font_handle = font_handle.unwrap(); debug!("Creating new FontEntry for face: %s", font_handle.face_name()); diff --git a/src/servo-gfx/servo_gfx.rc b/src/servo-gfx/servo_gfx.rc index 29ab186f97d..66d697aa465 100644 --- a/src/servo-gfx/servo_gfx.rc +++ b/src/servo-gfx/servo_gfx.rc @@ -44,17 +44,6 @@ pub mod native; #[path="platform/mod.rs"] pub mod platform; -#[cfg(target_os = "linux")] -pub mod freetype_impl { - pub mod font; - pub mod font_context; -} - -#[cfg(target_os = "linux")] -pub mod fontconfig { - pub mod font_list; -} - // Images pub mod image { pub mod base;