Move CoreText bindings into a submodule.

This commit is contained in:
Brian J. Burg 2012-10-19 14:24:38 -07:00
parent f586b0f947
commit 658edb6ec8
7 changed files with 49 additions and 78 deletions

3
.gitmodules vendored
View file

@ -67,3 +67,6 @@
[submodule "src/rust-core-graphics"] [submodule "src/rust-core-graphics"]
path = src/rust-core-graphics path = src/rust-core-graphics
url = git://github.com/mozilla-servo/rust-core-graphics.git 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

2
configure vendored
View file

@ -348,7 +348,7 @@ CFG_SUBMODULES="libwapcaplet rust-wapcaplet rust-harfbuzz rust-opengles rust-azu
if [ $CFG_OSTYPE = "darwin" ] if [ $CFG_OSTYPE = "darwin" ]
then 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 fi
# needed because Spidermonkey configure is in non-standard location # needed because Spidermonkey configure is in non-standard location

View file

@ -56,4 +56,8 @@ DEPS_rust-io-surface += \
DEPS_sharegl += \ DEPS_sharegl += \
rust-core-foundation \ rust-core-foundation \
rust-io-surface rust-io-surface
DEPS_rust-core-text += \
rust-core-foundation \
rust-core-graphics
endif endif

@ -1 +1 @@
Subproject commit 6ef2001b3cddedff0a1d818845ea50f8ce18925d Subproject commit f5a7b0b57d9927dfb66a2e43de17713980e344c0

@ -1 +1 @@
Subproject commit 6291af5e127bcaf527d689e8a93183c3288e1efe Subproject commit b0389b5fbff058daac267caf067f2c6fae9b9a98

1
src/rust-core-text Submodule

@ -0,0 +1 @@
Subproject commit 21ad07b922ecfb869017250f95d8c55979a17235

View file

@ -1,83 +1,56 @@
extern mod core_foundation;
extern mod core_graphics; extern mod core_graphics;
extern mod core_text;
export QuartzNativeFont, with_test_native_font, create; export QuartzNativeFont, with_test_native_font, create;
use font::{FontMetrics, FractionalPixel}; use font::{FontMetrics, FractionalPixel};
use au = gfx::geometry; use au = gfx::geometry;
use cast::transmute;
use libc::size_t; use libc::size_t;
use ptr::null; use ptr::null;
use glyph::GlyphIndex; use glyph::GlyphIndex;
use cf = core_foundation;
use cf::base::{
CFIndex,
CFRelease,
CFTypeRef
};
use cf::string::UniChar;
use cg = core_graphics; use cg = core_graphics;
use cg::base::{CGFloat, CGAffineTransform};
use cg::data_provider::{ use cg::data_provider::{
CGDataProviderRef,
CGDataProviderCreateWithData, CGDataProviderCreateWithData,
CGDataProviderRef,
CGDataProviderRelease, CGDataProviderRelease,
}; };
use cg::font::{ use cg::font::{
CGFontRef,
CGFontCreateWithDataProvider, CGFontCreateWithDataProvider,
CGFontRef,
CGFontRelease, CGFontRelease,
CGGlyph,
}; };
use cast::transmute; use cg::geometry::CGRect;
use coretext::CTFontRef;
use coretext::coretext::CFRelease;
mod coretext { use ct = core_text;
use ct::font::{
pub type CTFontRef = *u8; CTFontCreateWithGraphicsFont,
pub type UniChar = libc::c_ushort; CTFontRef,
pub type CGGlyph = libc::c_ushort; CTFontGetAdvancesForGlyphs,
pub type CFIndex = libc::c_long; CTFontGetAscent,
CTFontGetBoundingBox,
pub type CTFontOrientation = u32; CTFontGetDescent,
pub const kCTFontDefaultOrientation: CTFontOrientation = 0; CTFontGetGlyphsForCharacters,
pub const kCTFontHorizontalOrientation: CTFontOrientation = 1; CTFontGetLeading,
pub const kCTFontVerticalOrientation: CTFontOrientation = 2; CTFontGetSize,
CTFontGetUnderlinePosition,
// TODO: this is actually a libc::c_float on 32bit CTFontGetUnderlineThickness,
pub type CGFloat = libc::c_double; CTFontGetXHeight,
kCTFontDefaultOrientation,
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);
}
}
pub struct QuartzNativeFont { pub struct QuartzNativeFont {
fontprov: CGDataProviderRef, fontprov: CGDataProviderRef,
@ -89,7 +62,7 @@ pub struct QuartzNativeFont {
assert self.cgfont.is_not_null(); assert self.cgfont.is_not_null();
assert self.fontprov.is_not_null(); assert self.fontprov.is_not_null();
CFRelease(self.ctfont); CFRelease(self.ctfont as CFTypeRef);
CGFontRelease(self.cgfont); CGFontRelease(self.cgfont);
CGDataProviderRelease(self.fontprov); CGDataProviderRelease(self.fontprov);
} }
@ -111,11 +84,8 @@ fn QuartzNativeFont(fontprov: CGDataProviderRef, cgfont: CGFontRef) -> QuartzNat
impl QuartzNativeFont { impl QuartzNativeFont {
fn glyph_index(codepoint: char) -> Option<GlyphIndex> { fn glyph_index(codepoint: char) -> Option<GlyphIndex> {
use coretext::{UniChar, CGGlyph, CFIndex};
use coretext::coretext::{CTFontGetGlyphsForCharacters};
assert self.ctfont.is_not_null(); assert self.ctfont.is_not_null();
let characters: ~[UniChar] = ~[codepoint as UniChar]; let characters: ~[UniChar] = ~[codepoint as UniChar];
let glyphs: ~[mut CGGlyph] = ~[mut 0 as CGGlyph]; let glyphs: ~[mut CGGlyph] = ~[mut 0 as CGGlyph];
let count: CFIndex = 1; let count: CFIndex = 1;
@ -136,10 +106,8 @@ impl QuartzNativeFont {
} }
fn glyph_h_advance(glyph: GlyphIndex) -> Option<FractionalPixel> { fn glyph_h_advance(glyph: GlyphIndex) -> Option<FractionalPixel> {
use coretext::{CGGlyph, kCTFontDefaultOrientation};
use coretext::coretext::{CTFontGetAdvancesForGlyphs};
assert self.ctfont.is_not_null(); assert self.ctfont.is_not_null();
let glyphs = ~[glyph as CGGlyph]; let glyphs = ~[glyph as CGGlyph];
let advance = do vec::as_imm_buf(glyphs) |glyph_buf, _l| { let advance = do vec::as_imm_buf(glyphs) |glyph_buf, _l| {
CTFontGetAdvancesForGlyphs(self.ctfont, kCTFontDefaultOrientation, glyph_buf, null(), 1) CTFontGetAdvancesForGlyphs(self.ctfont, kCTFontDefaultOrientation, glyph_buf, null(), 1)
@ -149,9 +117,6 @@ impl QuartzNativeFont {
} }
fn get_metrics() -> FontMetrics { fn get_metrics() -> FontMetrics {
use coretext::CGRect;
use coretext::coretext::*;
let ctfont = self.ctfont; let ctfont = self.ctfont;
assert ctfont.is_not_null(); assert ctfont.is_not_null();
@ -178,11 +143,9 @@ impl QuartzNativeFont {
} }
} }
fn ctfont_from_cgfont(cgfont: CGFontRef) -> coretext::CTFontRef { fn ctfont_from_cgfont(cgfont: CGFontRef) -> CTFontRef {
use coretext::CGFloat;
use coretext::coretext::CTFontCreateWithGraphicsFont;
assert cgfont.is_not_null(); assert cgfont.is_not_null();
// TODO: use actual font size here! // TODO: use actual font size here!
CTFontCreateWithGraphicsFont(cgfont, 21f as CGFloat, null(), null()) CTFontCreateWithGraphicsFont(cgfont, 21f as CGFloat, null(), null())
} }