mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Refactor the Linux font stuff
This commit is contained in:
parent
f372c9c5c3
commit
9822f5d96b
7 changed files with 62 additions and 108 deletions
|
@ -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<FontHandle, ()> {
|
||||
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));
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<FontListHandle, ()> {
|
||||
Ok(fontconfig::font_list::FontconfigFontListHandle::new(fctx))
|
||||
Ok(platform::font_list::FontconfigFontListHandle::new(fctx))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
|
@ -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<FontHandle, ()> {
|
||||
fn create_font_from_identifier(&self, name: ~str, style: UsedFontStyle)
|
||||
-> Result<FontHandle, ()> {
|
||||
debug!("Creating font handle for %s", name);
|
||||
do path_from_identifier(name).chain |file_name| {
|
||||
debug!("Opening font face %s", file_name);
|
|
@ -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());
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue