Hoist all extern mod directives to the top level

This improves compile time and makes `use` directives look cleaner.
This commit is contained in:
Patrick Walton 2013-04-05 18:38:17 -07:00
parent a535f22146
commit 8972f52b2b
8 changed files with 105 additions and 117 deletions

View file

@ -1,7 +1,5 @@
//! Linux (FreeType) representation of fonts.
extern mod freetype;
use font::{CSSFontWeight, FontHandleMethods, FontMetrics, FontTable, FontTableMethods};
use font::{FontTableTag, FractionalPixel, SpecifiedFontStyle, UsedFontStyle, FontWeight100};
use font::{FontWeight200, FontWeight300, FontWeight400, FontWeight500, FontWeight600};
@ -12,16 +10,16 @@ use platform::font_context::{FreeTypeFontContextHandle, FontContextHandle};
use text::glyph::GlyphIndex;
use text::util::{float_to_fixed, fixed_to_float};
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;
use freetype::freetype::bindgen::{FT_Get_Char_Index, FT_Get_Postscript_Name};
use freetype::freetype::bindgen::{FT_Load_Glyph, FT_Set_Char_Size};
use freetype::freetype::bindgen::{FT_New_Face, FT_Get_Sfnt_Table};
use freetype::freetype::bindgen::{FT_New_Memory_Face, FT_Done_Face};
use freetype::freetype::{FTErrorMethods, FT_F26Dot6, FT_Face, FT_FaceRec};
use freetype::freetype::{FT_GlyphSlot, FT_Library, FT_Long, FT_ULong};
use freetype::freetype::{FT_STYLE_FLAG_ITALIC, FT_STYLE_FLAG_BOLD};
use freetype::freetype::{FT_SizeRec, FT_UInt, FT_Size_Metrics};
use freetype::freetype::{ft_sfnt_os2};
use freetype::tt_os2::TT_OS2;
pub use FontHandle = platform::linux::font::FreeTypeFontHandle;
pub use FontTable = platform::linux::font::FreeTypeFontTable;

View file

@ -1,13 +1,10 @@
extern mod freetype;
extern mod fontconfig;
use font::{FontHandle, UsedFontStyle};
use platform::font::FreeTypeFontHandle;
use platform::font_context::FontContextHandleMethods;
use platform::font_list::path_from_identifier;
use platform::font_context::freetype::freetype::{FTErrorMethods, FT_Library};
use platform::font_context::freetype::freetype::bindgen::{FT_Done_FreeType, FT_Init_FreeType};
use freetype::freetype::{FTErrorMethods, FT_Library};
use freetype::freetype::bindgen::{FT_Done_FreeType, FT_Init_FreeType};
pub use FontContextHandle = platform::linux::FreeTypeFontContextHandle;

View file

@ -1,7 +1,5 @@
//! Font list implementation for Linux (fontconfig).
extern mod freetype;
extern mod fontconfig;
use font::FontHandleMethods;
use font_context::FontContextHandleMethods;
@ -12,22 +10,22 @@ use platform::font_context::{FontContextHandle, FreeTypeFontContextHandle};
use core::hashmap::HashMap;
use core::libc::c_int;
use core::ptr::Ptr;
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};
use fontconfig::fontconfig::bindgen::{FcConfigGetCurrent};
use fontconfig::fontconfig::bindgen::{FcConfigGetFonts};
use fontconfig::fontconfig::bindgen::{FcDefaultSubstitute};
use fontconfig::fontconfig::bindgen::{FcPatternCreate};
use fontconfig::fontconfig::bindgen::{FcFontSetDestroy};
use fontconfig::fontconfig::bindgen::{FcConfigSubstitute};
use fontconfig::fontconfig::bindgen::{FcFontSetList};
use fontconfig::fontconfig::bindgen::{FcObjectSetCreate};
use fontconfig::fontconfig::bindgen::{FcObjectSetDestroy};
use fontconfig::fontconfig::bindgen::{FcObjectSetAdd};
use fontconfig::fontconfig::bindgen::{FcPatternAddString, FcFontMatch};
use fontconfig::fontconfig::bindgen::{FcPatternGetInteger};
use fontconfig::fontconfig::bindgen::{FcPatternGetString};
use fontconfig::fontconfig::bindgen::{FcPatternDestroy};
use fontconfig::fontconfig::{FcChar8, FcResultMatch, FcSetSystem};
use fontconfig::fontconfig::{FcMatchPattern, FcResultNoMatch};
pub struct FontconfigFontListHandle {
fctx: FreeTypeFontContextHandle,

View file

@ -1,28 +1,24 @@
//! Implementation of Quartz (CoreGraphics) fonts.
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 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;
use platform::macos::font::core_graphics::data_provider::CGDataProvider;
use platform::macos::font::core_graphics::font::{CGFont, CGGlyph};
use platform::macos::font::core_graphics::geometry::CGRect;
use platform::macos::font::core_text::font::{CTFont, CTFontMethods, CTFontMethodsPrivate};
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 core_foundation::base::{CFIndex, CFWrapper};
use core_foundation::data::CFData;
use core_foundation::string::UniChar;
use core_graphics::data_provider::CGDataProvider;
use core_graphics::font::{CGFont, CGGlyph};
use core_graphics::geometry::CGRect;
use core_graphics;
use core_text::font::{CTFont, CTFontMethods, CTFontMethodsPrivate};
use core_text::font_descriptor::{SymbolicTraitAccessors, TraitAccessors};
use core_text::font_descriptor::{kCTFontDefaultOrientation};
use core_text;
pub struct FontTable {
data: CFData,
@ -74,13 +70,11 @@ impl FontHandleMethods for FontHandle {
fn new_from_buffer(_: &FontContextHandle, buf: ~[u8], style: &SpecifiedFontStyle)
-> Result<FontHandle, ()> {
let fontprov : CGDataProvider = vec::as_imm_buf(buf, |cbuf, len| {
platform::macos::font::core_graphics::data_provider::new_from_buffer(cbuf, len)
core_graphics::data_provider::new_from_buffer(cbuf, len)
});
let cgfont = platform::macos::font::core_graphics::font::create_with_data_provider(
&fontprov);
let ctfont = platform::macos::font::core_text::font::new_from_CGFont(&cgfont,
style.pt_size);
let cgfont = core_graphics::font::create_with_data_provider(&fontprov);
let ctfont = core_text::font::new_from_CGFont(&cgfont, style.pt_size);
let result = Ok(FontHandle {
cgfont: Some(cgfont),

View file

@ -1,11 +1,8 @@
extern mod core_foundation;
extern mod core_graphics;
extern mod core_text;
use font::UsedFontStyle;
use font_context::FontContextHandleMethods;
use platform::macos::font::FontHandle;
use platform;
use core_text;
pub struct FontContextHandle {
ctx: ()
@ -29,9 +26,7 @@ impl FontContextHandleMethods for FontContextHandle {
name: ~str,
style: UsedFontStyle)
-> Result<FontHandle, ()> {
let ctfont_result = platform::macos::font_context::core_text::font::new_from_name(
name,
style.pt_size);
let ctfont_result = core_text::font::new_from_name(name, style.pt_size);
do result::chain(ctfont_result) |ctfont| {
FontHandle::new_from_CTFont(self, ctfont)
}

View file

@ -1,18 +1,17 @@
extern mod core_foundation;
extern mod core_text;
//! Mac OS-specific bindings to the native font list (called a "font collection" in Core Text).
use font::FontHandleMethods;
use font_context::FontContextHandleMethods;
use font_list::{FontEntry, FontFamily, FontFamilyMap};
use platform::macos::font::FontHandle;
use platform::macos::font_context::FontContextHandle;
use platform::macos::font_list::core_foundation::array::CFArray;
use platform::macos::font_list::core_foundation::base::CFWrapper;
use platform::macos::font_list::core_foundation::string::{CFString, CFStringRef};
use platform::macos::font_list::core_text::font_collection::CTFontCollectionMethods;
use platform::macos::font_list::core_text::font_descriptor::CTFontDescriptorRef;
use platform;
use core_foundation::array::CFArray;
use core_foundation::base::CFWrapper;
use core_foundation::string::{CFString, CFStringRef};
use core_text::font_collection::CTFontCollectionMethods;
use core_text::font_descriptor::CTFontDescriptorRef;
use core_text;
use core::hashmap::HashMap;
@ -28,8 +27,7 @@ pub impl FontListHandle {
}
fn get_available_families(&self) -> FontFamilyMap {
let family_names: CFArray<CFStringRef> =
platform::macos::font_list::core_text::font_collection::get_family_names();
let family_names: CFArray<CFStringRef> = core_text::font_collection::get_family_names();
let mut family_map : FontFamilyMap = HashMap::new();
for family_names.each |&strref: &CFStringRef| {
let family_name = CFString::wrap_extern(strref).to_str();
@ -46,13 +44,10 @@ pub impl FontListHandle {
let family_name = &fam.family_name;
debug!("Looking for faces of family: %s", *family_name);
let family_collection =
platform::macos::font_list::core_text::font_collection::create_for_family(
*family_name);
let family_collection = core_text::font_collection::create_for_family(*family_name);
for family_collection.get_descriptors().each |descref: &CTFontDescriptorRef| {
let desc = CFWrapper::wrap_shared(*descref);
let font = platform::macos::font_list::core_text::font::new_from_descriptor(&desc,
0.0);
let font = core_text::font::new_from_descriptor(&desc, 0.0);
let handle = result::unwrap(FontHandle::new_from_CTFont(&self.fctx, font));
debug!("Creating new FontEntry for face: %s", handle.face_name());

View file

@ -12,6 +12,19 @@ extern mod http_client;
extern mod stb_image;
extern mod std;
// Eventually we would like the shaper to be pluggable, as many operating systems have their own
// shapers. For now, however, this is a hard dependency.
extern mod harfbuzz;
// Linux-specific library dependencies
#[cfg(target_os="linux")] extern mod fontconfig;
#[cfg(target_os="linux")] extern mod freetype;
// Mac OS-specific library dependencies
#[cfg(target_os="macos")] extern mod core_foundation;
#[cfg(target_os="macos")] extern mod core_graphics;
#[cfg(target_os="macos")] extern mod core_text;
priv mod render_context;
// Rendering

View file

@ -1,7 +1,5 @@
//! Performs shaping with HarfBuzz.
extern mod harfbuzz;
use font::{Font, FontHandleMethods, FontTableMethods, FontTableTag};
use geometry::Au;
use platform::font::FontTable;
@ -15,42 +13,42 @@ use core::libc::{c_uint, c_int, c_void, c_char};
use core::ptr::null;
use core::util::ignore;
use geom::Point2D;
use text::shaping::harfbuzz::harfbuzz::bindgen::{hb_blob_create, hb_face_create_for_tables};
use text::shaping::harfbuzz::harfbuzz::bindgen::{hb_buffer_add_utf8, hb_shape};
use text::shaping::harfbuzz::harfbuzz::bindgen::{hb_buffer_create};
use text::shaping::harfbuzz::harfbuzz::bindgen::{hb_buffer_destroy, hb_buffer_add_utf8};
use text::shaping::harfbuzz::harfbuzz::bindgen::{hb_buffer_get_glyph_infos};
use text::shaping::harfbuzz::harfbuzz::bindgen::{hb_buffer_get_glyph_positions};
use text::shaping::harfbuzz::harfbuzz::bindgen::{hb_buffer_get_glyph_positions};
use text::shaping::harfbuzz::harfbuzz::bindgen::{hb_buffer_set_direction};
use text::shaping::harfbuzz::harfbuzz::bindgen::{hb_buffer_set_direction};
use text::shaping::harfbuzz::harfbuzz::bindgen::{hb_face_destroy, hb_font_create};
use text::shaping::harfbuzz::harfbuzz::bindgen::{hb_face_destroy};
use text::shaping::harfbuzz::harfbuzz::bindgen::{hb_font_create, hb_font_destroy};
use text::shaping::harfbuzz::harfbuzz::bindgen::{hb_font_destroy, hb_buffer_create};
use text::shaping::harfbuzz::harfbuzz::bindgen::{hb_font_funcs_create, hb_font_funcs_destroy};
use text::shaping::harfbuzz::harfbuzz::bindgen::{hb_font_funcs_create};
use text::shaping::harfbuzz::harfbuzz::bindgen::{hb_font_funcs_destroy};
use text::shaping::harfbuzz::harfbuzz::bindgen::{hb_font_funcs_set_glyph_func};
use text::shaping::harfbuzz::harfbuzz::bindgen::{hb_font_funcs_set_glyph_func};
use text::shaping::harfbuzz::harfbuzz::bindgen::{hb_font_funcs_set_glyph_h_advance_func};
use text::shaping::harfbuzz::harfbuzz::bindgen::{hb_font_funcs_set_glyph_h_advance_func};
use text::shaping::harfbuzz::harfbuzz::bindgen::{hb_font_set_funcs};
use text::shaping::harfbuzz::harfbuzz::bindgen::{hb_font_set_funcs};
use text::shaping::harfbuzz::harfbuzz::bindgen::{hb_font_set_ppem, hb_font_set_scale};
use text::shaping::harfbuzz::harfbuzz::bindgen::{hb_font_set_ppem};
use text::shaping::harfbuzz::harfbuzz::bindgen::{hb_font_set_scale};
use text::shaping::harfbuzz::harfbuzz::bindgen::{hb_shape, hb_buffer_get_glyph_infos};
use text::shaping::harfbuzz::harfbuzz::{HB_MEMORY_MODE_READONLY, HB_DIRECTION_LTR, hb_blob_t};
use text::shaping::harfbuzz::harfbuzz::{HB_MEMORY_MODE_READONLY, HB_DIRECTION_LTR};
use text::shaping::harfbuzz::harfbuzz::{hb_blob_t, hb_face_t, hb_font_t, hb_font_funcs_t};
use text::shaping::harfbuzz::harfbuzz::{hb_buffer_t, hb_codepoint_t, hb_bool_t};
use text::shaping::harfbuzz::harfbuzz::{hb_face_t, hb_font_t};
use text::shaping::harfbuzz::harfbuzz::{hb_font_funcs_t, hb_buffer_t, hb_codepoint_t};
use text::shaping::harfbuzz::harfbuzz::{hb_glyph_info_t, hb_position_t};
use text::shaping::harfbuzz::harfbuzz::{hb_glyph_position_t, hb_glyph_info_t};
use text::shaping::harfbuzz::harfbuzz::{hb_glyph_position_t};
use text::shaping::harfbuzz::harfbuzz::{hb_position_t, hb_tag_t};
use harfbuzz::bindgen::{hb_blob_create, hb_face_create_for_tables};
use harfbuzz::bindgen::{hb_buffer_add_utf8, hb_shape};
use harfbuzz::bindgen::{hb_buffer_create};
use harfbuzz::bindgen::{hb_buffer_destroy, hb_buffer_add_utf8};
use harfbuzz::bindgen::{hb_buffer_get_glyph_infos};
use harfbuzz::bindgen::{hb_buffer_get_glyph_positions};
use harfbuzz::bindgen::{hb_buffer_get_glyph_positions};
use harfbuzz::bindgen::{hb_buffer_set_direction};
use harfbuzz::bindgen::{hb_buffer_set_direction};
use harfbuzz::bindgen::{hb_face_destroy, hb_font_create};
use harfbuzz::bindgen::{hb_face_destroy};
use harfbuzz::bindgen::{hb_font_create, hb_font_destroy};
use harfbuzz::bindgen::{hb_font_destroy, hb_buffer_create};
use harfbuzz::bindgen::{hb_font_funcs_create, hb_font_funcs_destroy};
use harfbuzz::bindgen::{hb_font_funcs_create};
use harfbuzz::bindgen::{hb_font_funcs_destroy};
use harfbuzz::bindgen::{hb_font_funcs_set_glyph_func};
use harfbuzz::bindgen::{hb_font_funcs_set_glyph_func};
use harfbuzz::bindgen::{hb_font_funcs_set_glyph_h_advance_func};
use harfbuzz::bindgen::{hb_font_funcs_set_glyph_h_advance_func};
use harfbuzz::bindgen::{hb_font_set_funcs};
use harfbuzz::bindgen::{hb_font_set_funcs};
use harfbuzz::bindgen::{hb_font_set_ppem, hb_font_set_scale};
use harfbuzz::bindgen::{hb_font_set_ppem};
use harfbuzz::bindgen::{hb_font_set_scale};
use harfbuzz::bindgen::{hb_shape, hb_buffer_get_glyph_infos};
use harfbuzz::{HB_MEMORY_MODE_READONLY, HB_DIRECTION_LTR, hb_blob_t};
use harfbuzz::{HB_MEMORY_MODE_READONLY, HB_DIRECTION_LTR};
use harfbuzz::{hb_blob_t, hb_face_t, hb_font_t, hb_font_funcs_t};
use harfbuzz::{hb_buffer_t, hb_codepoint_t, hb_bool_t};
use harfbuzz::{hb_face_t, hb_font_t};
use harfbuzz::{hb_font_funcs_t, hb_buffer_t, hb_codepoint_t};
use harfbuzz::{hb_glyph_info_t, hb_position_t};
use harfbuzz::{hb_glyph_position_t, hb_glyph_info_t};
use harfbuzz::{hb_glyph_position_t};
use harfbuzz::{hb_position_t, hb_tag_t};
static NO_GLYPH: i32 = -1;
static CONTINUATION_BYTE: i32 = -2;