diff --git a/src/servo-gfx/font_list.rs b/src/servo-gfx/font_list.rs index 7a6ddae6570..cb3da78155f 100644 --- a/src/servo-gfx/font_list.rs +++ b/src/servo-gfx/font_list.rs @@ -1,7 +1,6 @@ //! Implementation of the list of fonts. -use font::{CSSFontWeight, SpecifiedFontStyle}; -use gfx_font::FontHandleMethods; +use font::{CSSFontWeight, FontHandleMethods, SpecifiedFontStyle}; use platform::font::FontHandle; use platform::font_context::FontContextHandle; use platform::font_list::FontListHandle; @@ -16,6 +15,7 @@ trait FontListHandleMethods { fn load_variations_for_family(&self, family: @mut FontFamily); } +/// The platform-independent font list abstraction. pub struct FontList { family_map: FontFamilyMap, handle: FontListHandle, @@ -29,7 +29,7 @@ pub impl FontList { family_map: HashMap::new(), }; list.refresh(fctx); - return list; + list } priv fn refresh(&mut self, _: &FontContextHandle) { @@ -46,19 +46,24 @@ pub impl FontList { family_name: &str, style: &SpecifiedFontStyle) -> Option<@FontEntry> { let family = self.find_family(family_name); - let mut result : Option<@FontEntry> = None; // TODO(Issue #192: handle generic font families, like 'serif' and 'sans-serif'. // if such family exists, try to match style to a font + let mut result: Option<@FontEntry> = None; for family.each |fam| { result = fam.find_font_for_style(&self.handle, style); } - let decision = if result.is_some() { "Found" } else { "Couldn't find" }; + let decision = if result.is_some() { + "Found" + } else { + "Couldn't find" + }; + debug!("FontList: %s font face in family[%s] matching style", decision, family_name); - return result; + result } priv fn find_family(&self, family_name: &str) -> Option<@mut FontFamily> { @@ -79,23 +84,23 @@ pub struct FontFamily { entries: ~[@FontEntry], } -pub impl FontFamily { - fn new(family_name: &str) -> FontFamily { +impl FontFamily { + pub fn new(family_name: &str) -> FontFamily { FontFamily { family_name: str::from_slice(family_name), entries: ~[], } } - priv fn load_family_variations(@mut self, list: &FontListHandle) { + fn load_family_variations(@mut self, list: &FontListHandle) { let this : &mut FontFamily = self; // FIXME: borrow checker workaround if this.entries.len() > 0 { return; } list.load_variations_for_family(self); assert!(this.entries.len() > 0); } - fn find_font_for_style(@mut self, list: &FontListHandle, style: &SpecifiedFontStyle) - -> Option<@FontEntry> { + pub fn find_font_for_style(@mut self, list: &FontListHandle, style: &SpecifiedFontStyle) + -> Option<@FontEntry> { self.load_family_variations(list); // TODO(Issue #189): optimize lookup for @@ -104,7 +109,7 @@ pub impl FontFamily { // TODO(Issue #190): if not in the fast path above, do // expensive matching of weights, etc. - let this : &mut FontFamily = self; // FIXME: borrow checker workaround + let this: &mut FontFamily = self; // FIXME: borrow checker workaround for this.entries.each |entry| { if (style.weight.is_bold() == entry.is_bold()) && (style.italic == entry.is_italic()) { @@ -113,15 +118,15 @@ pub impl FontFamily { } } - return None; + None } } -// This struct summarizes an available font's features. In the future, -// this will include fiddly settings such as special font table handling. - -// In the common case, each FontFamily will have a singleton FontEntry, or -// it will have the standard four faces: Normal, Bold, Italic, BoldItalic. +/// This struct summarizes an available font's features. In the future, this will include fiddly +/// settings such as special font table handling. +/// +/// In the common case, each FontFamily will have a singleton FontEntry, or it will have the +/// standard four faces: Normal, Bold, Italic, BoldItalic. pub struct FontEntry { family: @mut FontFamily, face_name: ~str, @@ -131,8 +136,8 @@ pub struct FontEntry { // TODO: array of OpenType features, etc. } -pub impl FontEntry { - fn new(family: @mut FontFamily, handle: FontHandle) -> FontEntry { +impl FontEntry { + pub fn new(family: @mut FontFamily, handle: FontHandle) -> FontEntry { FontEntry { family: family, face_name: handle.face_name(), @@ -142,11 +147,11 @@ pub impl FontEntry { } } - fn is_bold(&self) -> bool { + pub fn is_bold(&self) -> bool { self.weight.is_bold() } - fn is_italic(&self) -> bool { + pub fn is_italic(&self) -> bool { self.italic } } diff --git a/src/servo-gfx/platform/linux/font.rs b/src/servo-gfx/platform/linux/font.rs index 6fa22fad275..9a4a1e3e360 100644 --- a/src/servo-gfx/platform/linux/font.rs +++ b/src/servo-gfx/platform/linux/font.rs @@ -2,12 +2,12 @@ extern mod freetype; +use font::{CSSFontWeight, FontHandleMethods, FontMetrics, FontTable, FontTableMethods}; +use font::{FontTableTag, FractionalPixel, SpecifiedFontStyle, UsedFontStyle, FontWeight100}; +use font::{FontWeight200, FontWeight300, FontWeight400, FontWeight500, FontWeight600}; +use font::{FontWeight700, FontWeight800, FontWeight900}; 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 platform::font_context::{FreeTypeFontContextHandle, FontContextHandle}; use text::glyph::GlyphIndex; use text::util::{float_to_fixed, fixed_to_float}; @@ -99,7 +99,7 @@ pub impl FreeTypeFontHandle { } pub fn new_from_file_unstyled(fctx: &FreeTypeFontContextHandle, file: ~str) - -> Result { + -> Result { let ft_ctx: FT_Library = fctx.ctx.ctx; if ft_ctx.is_null() { return Err(()); } @@ -270,7 +270,7 @@ impl FontHandleMethods for FreeTypeFontHandle { } } - fn get_table_for_tag(&self, _tag: FontTableTag) -> Option { + fn get_table_for_tag(&self, _: FontTableTag) -> Option { None } } @@ -283,7 +283,6 @@ pub impl FreeTypeFontHandle { } priv fn font_units_to_au(&self, value: float) -> Au { - let face = self.get_face_rec(); // face.size is a *c_void in the bindings, presumably to avoid @@ -300,3 +299,4 @@ pub impl FreeTypeFontHandle { return geometry::from_frac_px(value * x_scale); } } + diff --git a/src/servo-gfx/platform/linux/font_context.rs b/src/servo-gfx/platform/linux/font_context.rs index c809f89d225..24456530d1a 100644 --- a/src/servo-gfx/platform/linux/font_context.rs +++ b/src/servo-gfx/platform/linux/font_context.rs @@ -1,7 +1,7 @@ extern mod freetype; extern mod fontconfig; -use gfx_font::{FontHandle, UsedFontStyle}; +use font::{FontHandle, UsedFontStyle}; use platform::font::FreeTypeFontHandle; use platform::font_context::FontContextHandleMethods; use platform::font_list::path_from_identifier; diff --git a/src/servo-gfx/platform/linux/font_list.rs b/src/servo-gfx/platform/linux/font_list.rs index d7dcc80d1df..809d6ed62fc 100644 --- a/src/servo-gfx/platform/linux/font_list.rs +++ b/src/servo-gfx/platform/linux/font_list.rs @@ -3,9 +3,9 @@ extern mod freetype; extern mod fontconfig; -use gfx_font::FontHandleMethods; -use gfx_font_context::FontContextHandleMethods; -use gfx_font_list::{FontEntry, FontFamily, FontFamilyMap}; +use font::FontHandleMethods; +use font_context::FontContextHandleMethods; +use font_list::{FontEntry, FontFamily, FontFamilyMap}; use platform::font::FreeTypeFontHandle; use platform::font_context::{FontContextHandle, FreeTypeFontContextHandle}; diff --git a/src/servo-gfx/platform/macos/font.rs b/src/servo-gfx/platform/macos/font.rs index 9706aa110ae..d735a637f58 100644 --- a/src/servo-gfx/platform/macos/font.rs +++ b/src/servo-gfx/platform/macos/font.rs @@ -4,11 +4,15 @@ extern mod core_foundation; extern mod core_graphics; extern mod core_text; +use font::{CSSFontWeight, FontHandleMethods, FontMetrics, FontTableMethods}; +use font::{FontTableTag, FontWeight100, FontWeight200, FontWeight300, FontWeight400}; +use font::{FontWeight500, FontWeight600, FontWeight700, FontWeight800, FontWeight900}; +use font::{FractionalPixel, SpecifiedFontStyle}; use geometry::Au; -use gfx_font::{CSSFontWeight, FontHandleMethods, FontMetrics, FontTableMethods}; -use gfx_font::{FontTableTag, FontWeight100, FontWeight200, FontWeight300, FontWeight400}; -use gfx_font::{FontWeight500, FontWeight600, FontWeight700, FontWeight800, FontWeight900}; -use gfx_font::{FractionalPixel, SpecifiedFontStyle}; +use platform::macos::font_context::FontContextHandle; +use platform; +use text::glyph::GlyphIndex; + use platform::macos::font::core_foundation::base::{CFIndex, CFWrapper}; use platform::macos::font::core_foundation::data::CFData; use platform::macos::font::core_foundation::string::UniChar; @@ -19,9 +23,6 @@ use platform::macos::font::core_text::font::{CTFont, CTFontMethods, CTFontMethod use platform::macos::font::core_text::font_descriptor::{SymbolicTraitAccessors}; use platform::macos::font::core_text::font_descriptor::{TraitAccessors}; use platform::macos::font::core_text::font_descriptor::{kCTFontDefaultOrientation}; -use platform::macos::font_context::FontContextHandle; -use platform; -use text::glyph::GlyphIndex; pub struct FontTable { data: CFData, diff --git a/src/servo-gfx/platform/macos/font_context.rs b/src/servo-gfx/platform/macos/font_context.rs index aacd51cdcb9..a8558fd4bb4 100644 --- a/src/servo-gfx/platform/macos/font_context.rs +++ b/src/servo-gfx/platform/macos/font_context.rs @@ -2,9 +2,8 @@ extern mod core_foundation; extern mod core_graphics; extern mod core_text; -use gfx_font::UsedFontStyle; -use gfx_font_context::FontContextHandleMethods; - +use font::UsedFontStyle; +use font_context::FontContextHandleMethods; use platform::macos::font::FontHandle; use platform; diff --git a/src/servo-gfx/platform/macos/font_list.rs b/src/servo-gfx/platform/macos/font_list.rs index 0c7bbfe4f37..a56f5a5f86c 100644 --- a/src/servo-gfx/platform/macos/font_list.rs +++ b/src/servo-gfx/platform/macos/font_list.rs @@ -1,9 +1,9 @@ extern mod core_foundation; extern mod core_text; -use gfx_font::FontHandleMethods; -use gfx_font_context::FontContextHandleMethods; -use gfx_font_list::{FontEntry, FontFamily, FontFamilyMap}; +use font::FontHandleMethods; +use font_context::FontContextHandleMethods; +use font_list::{FontEntry, FontFamily, FontFamilyMap}; use platform::macos::font::FontHandle; use platform::macos::font_context::FontContextHandle; diff --git a/src/servo-gfx/servo_gfx.rc b/src/servo-gfx/servo_gfx.rc index caeef9d9cdd..614ce9134b3 100644 --- a/src/servo-gfx/servo_gfx.rc +++ b/src/servo-gfx/servo_gfx.rc @@ -1,3 +1,5 @@ +//! Graphics and resource loading module for Servo. + #[link(name = "servo_gfx", vers = "0.1", uuid = "0106bb54-6ea9-45bf-a39e-a738621f15e5", @@ -10,14 +12,6 @@ extern mod http_client; extern mod stb_image; extern mod std; -pub use servo_util = util; -pub use gfx_font = font; -pub use gfx_font_context = font_context; -pub use gfx_font_list = font_list; -pub use servo_gfx_font = font; -pub use servo_gfx_font_list = font_list; -pub use servo_gfx_util = util; - priv mod render_context; // Rendering @@ -71,3 +65,4 @@ pub mod util { pub mod url; pub mod vec; } + diff --git a/src/servo-gfx/text/glyph.rs b/src/servo-gfx/text/glyph.rs index 7a91c5e128d..21005dda13b 100644 --- a/src/servo-gfx/text/glyph.rs +++ b/src/servo-gfx/text/glyph.rs @@ -1,8 +1,10 @@ -use geometry::Au; -use servo_gfx_util::range::Range; -use servo_gfx_util::vec::*; +//! A platform-independent representation of a glyph. +use geometry::Au; use geometry; +use util::range::Range; +use util::vec::*; + use core; use core::cmp::{Ord, Eq}; use core::num::NumCast; @@ -10,20 +12,19 @@ use core::u16; use geom::point::Point2D; use std::sort; - -// GlyphEntry is a port of Gecko's CompressedGlyph scheme for storing -// glyph data compactly. -// -// In the common case (reasonable glyph advances, no offsets from the -// font em-box, and one glyph per character), we pack glyph advance, -// glyph id, and some flags into a single u32. -// -// In the uncommon case (multiple glyphs per unicode character, large -// glyph index/advance, or glyph offsets), we pack the glyph count -// into GlyphEntry, and store the other glyph information in -// DetailedGlyphStore. +/// GlyphEntry is a port of Gecko's CompressedGlyph scheme for storing +/// glyph data compactly. +/// +/// In the common case (reasonable glyph advances, no offsets from the +/// font em-box, and one glyph per character), we pack glyph advance, +/// glyph id, and some flags into a single u32. +/// +/// In the uncommon case (multiple glyphs per unicode character, large +/// glyph index/advance, or glyph offsets), we pack the glyph count +/// into GlyphEntry, and store the other glyph information in +/// DetailedGlyphStore. struct GlyphEntry { - value : u32 + value: u32 } fn GlyphEntry(value: u32) -> GlyphEntry { GlyphEntry { value: value } } diff --git a/src/servo-gfx/text/harfbuzz/shaper.rs b/src/servo-gfx/text/harfbuzz/shaper.rs index 52424bb430e..8c250b5a038 100644 --- a/src/servo-gfx/text/harfbuzz/shaper.rs +++ b/src/servo-gfx/text/harfbuzz/shaper.rs @@ -4,12 +4,11 @@ use geom::Point2D; use geometry::Au; -use font::{Font, FontTableMethods, FontTableTag}; +use font::{Font, FontHandleMethods, FontTableMethods, FontTableTag}; use platform::font::FontTable; use text::glyph::{GlyphStore, GlyphIndex, GlyphData}; use text::shaper::ShaperMethods; -use gfx_font::{FontHandleMethods, FontTableMethods}; use util::range::Range; diff --git a/src/servo-gfx/text/shaper.rs b/src/servo-gfx/text/shaper.rs index b5f3d322931..429f6b1d9c0 100644 --- a/src/servo-gfx/text/shaper.rs +++ b/src/servo-gfx/text/shaper.rs @@ -1,10 +1,9 @@ -/** -Shaper encapsulates a specific shaper, such as Harfbuzz, -Uniscribe, Pango, or Coretext. +//! Shaper encapsulates a specific shaper, such as Harfbuzz, +/// Uniscribe, Pango, or Coretext. +/// +/// Currently, only harfbuzz bindings are implemented. -Currently, only harfbuzz bindings are implemented. -*/ -use gfx_font::Font; +use font::Font; use text::glyph::GlyphStore; use text::harfbuzz; diff --git a/src/servo-gfx/text/text_run.rs b/src/servo-gfx/text/text_run.rs index 694d8236e77..00a48b892cf 100644 --- a/src/servo-gfx/text/text_run.rs +++ b/src/servo-gfx/text/text_run.rs @@ -1,17 +1,20 @@ +//! The text run abstraction. A text run is a word-wrapped line of text of the same font family, +/// style, and size. + +use font::{Font, FontDescriptor, RunMetrics}; use font_context::FontContext; use geometry::Au; use text::glyph::{BreakTypeNormal, GlyphStore}; -use servo_gfx_font::{Font, FontDescriptor, RunMetrics}; -use servo_gfx_util::range::Range; +use util::range::Range; +/// A text run. pub struct TextRun { text: ~str, font: @mut Font, glyphs: GlyphStore, } -// This is a hack until TextRuns are normally sendable, or -// we instead use ARC everywhere. +/// This is a hack until TextRuns are normally sendable, or we instead use ARC everywhere. pub struct SendableTextRun { text: ~str, font: FontDescriptor,