mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Move CoreText bindings into a submodule.
This commit is contained in:
parent
f586b0f947
commit
658edb6ec8
7 changed files with 49 additions and 78 deletions
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -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
|
||||
|
|
2
configure
vendored
2
configure
vendored
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 6ef2001b3cddedff0a1d818845ea50f8ce18925d
|
||||
Subproject commit f5a7b0b57d9927dfb66a2e43de17713980e344c0
|
|
@ -1 +1 @@
|
|||
Subproject commit 6291af5e127bcaf527d689e8a93183c3288e1efe
|
||||
Subproject commit b0389b5fbff058daac267caf067f2c6fae9b9a98
|
1
src/rust-core-text
Submodule
1
src/rust-core-text
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 21ad07b922ecfb869017250f95d8c55979a17235
|
|
@ -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<GlyphIndex> {
|
||||
|
||||
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<FractionalPixel> {
|
||||
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())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue