diff --git a/.gitmodules b/.gitmodules index 77447fe4b55..f6277876829 100644 --- a/.gitmodules +++ b/.gitmodules @@ -67,3 +67,6 @@ [submodule "src/rust-core-graphics"] path = src/rust-core-graphics url = git://github.com/mozilla-servo/rust-core-graphics.git +[submodule "src/rust-core-text"] + path = src/rust-core-text + url = git://github.com/mozilla-servo/rust-core-text.git diff --git a/configure b/configure index db2d528522c..870196ba0f7 100755 --- a/configure +++ b/configure @@ -348,7 +348,7 @@ CFG_SUBMODULES="libwapcaplet rust-wapcaplet rust-harfbuzz rust-opengles rust-azu if [ $CFG_OSTYPE = "darwin" ] then -CFG_SUBMODULES="rust-cocoa rust-io-surface rust-core-foundation rust-core-graphics ${CFG_SUBMODULES}" +CFG_SUBMODULES="rust-cocoa rust-io-surface rust-core-foundation rust-core-graphics rust-core-text ${CFG_SUBMODULES}" fi # needed because Spidermonkey configure is in non-standard location diff --git a/mk/sub.mk b/mk/sub.mk index 447e07defd0..b394bed0cfd 100644 --- a/mk/sub.mk +++ b/mk/sub.mk @@ -56,4 +56,8 @@ DEPS_rust-io-surface += \ DEPS_sharegl += \ rust-core-foundation \ rust-io-surface + +DEPS_rust-core-text += \ + rust-core-foundation \ + rust-core-graphics endif diff --git a/src/rust-core-foundation b/src/rust-core-foundation index 6ef2001b3cd..f5a7b0b57d9 160000 --- a/src/rust-core-foundation +++ b/src/rust-core-foundation @@ -1 +1 @@ -Subproject commit 6ef2001b3cddedff0a1d818845ea50f8ce18925d +Subproject commit f5a7b0b57d9927dfb66a2e43de17713980e344c0 diff --git a/src/rust-core-graphics b/src/rust-core-graphics index 6291af5e127..b0389b5fbff 160000 --- a/src/rust-core-graphics +++ b/src/rust-core-graphics @@ -1 +1 @@ -Subproject commit 6291af5e127bcaf527d689e8a93183c3288e1efe +Subproject commit b0389b5fbff058daac267caf067f2c6fae9b9a98 diff --git a/src/rust-core-text b/src/rust-core-text new file mode 160000 index 00000000000..21ad07b922e --- /dev/null +++ b/src/rust-core-text @@ -0,0 +1 @@ +Subproject commit 21ad07b922ecfb869017250f95d8c55979a17235 diff --git a/src/servo/text/native_font/quartz_native_font.rs b/src/servo/text/native_font/quartz_native_font.rs index 5326d0831d8..90d0a890457 100644 --- a/src/servo/text/native_font/quartz_native_font.rs +++ b/src/servo/text/native_font/quartz_native_font.rs @@ -1,83 +1,56 @@ +extern mod core_foundation; extern mod core_graphics; +extern mod core_text; export QuartzNativeFont, with_test_native_font, create; use font::{FontMetrics, FractionalPixel}; use au = gfx::geometry; +use cast::transmute; use libc::size_t; use ptr::null; use glyph::GlyphIndex; + +use cf = core_foundation; +use cf::base::{ + CFIndex, + CFRelease, + CFTypeRef +}; +use cf::string::UniChar; + use cg = core_graphics; +use cg::base::{CGFloat, CGAffineTransform}; use cg::data_provider::{ - CGDataProviderRef, CGDataProviderCreateWithData, + CGDataProviderRef, CGDataProviderRelease, }; use cg::font::{ - CGFontRef, CGFontCreateWithDataProvider, + CGFontRef, CGFontRelease, + CGGlyph, }; -use cast::transmute; -use coretext::CTFontRef; -use coretext::coretext::CFRelease; +use cg::geometry::CGRect; -mod coretext { - - pub type CTFontRef = *u8; - pub type UniChar = libc::c_ushort; - pub type CGGlyph = libc::c_ushort; - pub type CFIndex = libc::c_long; - - pub type CTFontOrientation = u32; - pub const kCTFontDefaultOrientation: CTFontOrientation = 0; - pub const kCTFontHorizontalOrientation: CTFontOrientation = 1; - pub const kCTFontVerticalOrientation: CTFontOrientation = 2; - - // TODO: this is actually a libc::c_float on 32bit - pub type CGFloat = libc::c_double; - - pub struct CGSize { - width: CGFloat, - height: CGFloat, - } - - pub struct CGPoint { - x: CGFloat, - y: CGFloat, - } - - pub struct CGRect { - origin: CGPoint, - size: CGSize - } - - pub type CGAffineTransform = (); - pub type CTFontDescriptorRef = *u8; - - #[nolink] - #[link_args = "-framework ApplicationServices"] - pub extern mod coretext { - pub fn CTFontCreateWithGraphicsFont(graphicsFont: CGFontRef, size: CGFloat, matrix: *CGAffineTransform, attributes: CTFontDescriptorRef) -> CTFontRef; - pub fn CTFontGetGlyphsForCharacters(font: CTFontRef, characters: *UniChar, glyphs: *CGGlyph, count: CFIndex) -> bool; - pub fn CTFontGetAdvancesForGlyphs(font: CTFontRef, orientation: CTFontOrientation, glyphs: *CGGlyph, advances: *CGSize, count: CFIndex) -> libc::c_double; - - pub fn CTFontGetSize(font: CTFontRef) -> CGFloat; - - /* metrics API */ - pub fn CTFontGetAscent(font: CTFontRef) -> CGFloat; - pub fn CTFontGetDescent(font: CTFontRef) -> CGFloat; - pub fn CTFontGetLeading(font: CTFontRef) -> CGFloat; - pub fn CTFontGetUnitsPerEm(font: CTFontRef) -> libc::c_uint; - pub fn CTFontGetUnderlinePosition(font: CTFontRef) -> CGFloat; - pub fn CTFontGetUnderlineThickness(font: CTFontRef) -> CGFloat; - pub fn CTFontGetXHeight(font: CTFontRef) -> CGFloat; - pub fn CTFontGetBoundingBox(font: CTFontRef) -> CGRect; - - pub fn CFRelease(font: CTFontRef); - } -} +use ct = core_text; +use ct::font::{ + CTFontCreateWithGraphicsFont, + CTFontRef, + CTFontGetAdvancesForGlyphs, + CTFontGetAscent, + CTFontGetBoundingBox, + CTFontGetDescent, + CTFontGetGlyphsForCharacters, + CTFontGetLeading, + CTFontGetSize, + CTFontGetUnderlinePosition, + CTFontGetUnderlineThickness, + CTFontGetXHeight, + kCTFontDefaultOrientation, +}; pub struct QuartzNativeFont { fontprov: CGDataProviderRef, @@ -89,7 +62,7 @@ pub struct QuartzNativeFont { assert self.cgfont.is_not_null(); assert self.fontprov.is_not_null(); - CFRelease(self.ctfont); + CFRelease(self.ctfont as CFTypeRef); CGFontRelease(self.cgfont); CGDataProviderRelease(self.fontprov); } @@ -111,11 +84,8 @@ fn QuartzNativeFont(fontprov: CGDataProviderRef, cgfont: CGFontRef) -> QuartzNat impl QuartzNativeFont { fn glyph_index(codepoint: char) -> Option { - - use coretext::{UniChar, CGGlyph, CFIndex}; - use coretext::coretext::{CTFontGetGlyphsForCharacters}; - assert self.ctfont.is_not_null(); + let characters: ~[UniChar] = ~[codepoint as UniChar]; let glyphs: ~[mut CGGlyph] = ~[mut 0 as CGGlyph]; let count: CFIndex = 1; @@ -136,10 +106,8 @@ impl QuartzNativeFont { } fn glyph_h_advance(glyph: GlyphIndex) -> Option { - use coretext::{CGGlyph, kCTFontDefaultOrientation}; - use coretext::coretext::{CTFontGetAdvancesForGlyphs}; - assert self.ctfont.is_not_null(); + let glyphs = ~[glyph as CGGlyph]; let advance = do vec::as_imm_buf(glyphs) |glyph_buf, _l| { CTFontGetAdvancesForGlyphs(self.ctfont, kCTFontDefaultOrientation, glyph_buf, null(), 1) @@ -149,9 +117,6 @@ impl QuartzNativeFont { } fn get_metrics() -> FontMetrics { - use coretext::CGRect; - use coretext::coretext::*; - let ctfont = self.ctfont; assert ctfont.is_not_null(); @@ -178,11 +143,9 @@ impl QuartzNativeFont { } } -fn ctfont_from_cgfont(cgfont: CGFontRef) -> coretext::CTFontRef { - use coretext::CGFloat; - use coretext::coretext::CTFontCreateWithGraphicsFont; - +fn ctfont_from_cgfont(cgfont: CGFontRef) -> CTFontRef { assert cgfont.is_not_null(); + // TODO: use actual font size here! CTFontCreateWithGraphicsFont(cgfont, 21f as CGFloat, null(), null()) }