mirror of
https://github.com/servo/servo.git
synced 2025-06-24 17:14:33 +01:00
Write some code that draws text on mac
This commit is contained in:
parent
04024b6af1
commit
69dc65fecc
4 changed files with 162 additions and 8 deletions
|
@ -1 +1 @@
|
|||
Subproject commit b101e938bc1eb7a13cb4a9aa6fb52ab650fed71b
|
||||
Subproject commit 8ce13fb34d98fe14be42fb0bda31bd9b6ab86dfe
|
|
@ -1 +1 @@
|
|||
Subproject commit cff7503084162cc68598e059fa46ec634bc994fe
|
||||
Subproject commit 478f61bb68feea43c22c9b88f52393ea15908dae
|
|
@ -147,8 +147,160 @@ fn draw_display_list(
|
|||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
fn draw_some_text(_draw_target: AzDrawTargetRef) {
|
||||
// FIXME: Don't know how to draw text on mac yet
|
||||
mod cocoa {
|
||||
use cocoa;
|
||||
export cocoa;
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
fn draw_some_text(draw_target: AzDrawTargetRef) {
|
||||
|
||||
import az = azure;
|
||||
import azbg = azure::bindgen;
|
||||
import ft = azure::freetype;
|
||||
import ftbg = azure::freetype::bindgen;
|
||||
import cairo = azure::cairo;
|
||||
import cairobg = azure::cairo::bindgen;
|
||||
//import cairoftbg = azure::cairo_ft::bindgen;
|
||||
import libc::types::common::c99::uint16_t;
|
||||
import libc::types::common::c99::uint32_t;
|
||||
import cocoa::cocoa;
|
||||
import cocoa::cg::CGDataProviderRef;
|
||||
import cocoa::cg::cg::{
|
||||
CGDataProviderCreateWithData,
|
||||
CGDataProviderRelease,
|
||||
CGFontCreateWithDataProvider
|
||||
};
|
||||
import cairoqbg = azure::cairo_quartz::bindgen;
|
||||
|
||||
/*impl methods for ft::FT_Error {
|
||||
fn for_sure() { assert self == 0 as ft::FT_Error }
|
||||
}*/
|
||||
|
||||
//let library: ft::FT_Library = ptr::null();
|
||||
//ftbg::FT_Init_FreeType(ptr::addr_of(library)).for_sure();
|
||||
|
||||
let fontbin = #include_bin("JosefinSans-SemiBold.ttf");
|
||||
|
||||
let fontprov = vec::as_buf(fontbin) {|buf|
|
||||
CGDataProviderCreateWithData(ptr::null(),
|
||||
unsafe { unsafe::reinterpret_cast(buf) },
|
||||
fontbin.len(),
|
||||
ptr::null())
|
||||
};
|
||||
|
||||
let cgfont = CGFontCreateWithDataProvider(fontprov);
|
||||
|
||||
/*let face: ft::FT_Face = ptr::null();
|
||||
vec::as_buf(fontbin) {|buf|
|
||||
ftbg::FT_New_Memory_Face(library, buf, fontbin.len() as ft::FT_Long,
|
||||
0, ptr::addr_of(face)).for_sure();
|
||||
}
|
||||
|
||||
unsafe {
|
||||
#debug("num_glyphs %?", (*face).num_glyphs);
|
||||
#debug("family_name %?",
|
||||
str::unsafe::from_c_str((*face).family_name));
|
||||
#debug("style_name %?",
|
||||
str::unsafe::from_c_str((*face).style_name));
|
||||
}
|
||||
|
||||
let cface = cairoftbg::cairo_ft_font_face_create_for_ft_face(
|
||||
face, 0 as libc::c_int);
|
||||
assert cface.is_not_null();
|
||||
*/
|
||||
|
||||
let cface = cairoqbg::cairo_quartz_font_face_create_for_cgfont(cgfont);
|
||||
|
||||
let fontmatrix: cairo::cairo_matrix_t = {
|
||||
xx: 0 as libc::c_double,
|
||||
yx: 0 as libc::c_double,
|
||||
xy: 0 as libc::c_double,
|
||||
yy: 0 as libc::c_double,
|
||||
x0: 0 as libc::c_double,
|
||||
y0: 0 as libc::c_double
|
||||
};
|
||||
cairobg::cairo_matrix_init_identity(ptr::addr_of(fontmatrix));
|
||||
cairobg::cairo_matrix_scale(ptr::addr_of(fontmatrix), 300f as libc::c_double, 400f as libc::c_double);
|
||||
|
||||
let idmatrix: cairo::cairo_matrix_t = {
|
||||
xx: 0 as libc::c_double,
|
||||
yx: 0 as libc::c_double,
|
||||
xy: 0 as libc::c_double,
|
||||
yy: 0 as libc::c_double,
|
||||
x0: 0 as libc::c_double,
|
||||
y0: 0 as libc::c_double
|
||||
};
|
||||
cairobg::cairo_matrix_init_identity(ptr::addr_of(idmatrix));
|
||||
|
||||
let options = cairobg::cairo_font_options_create();
|
||||
|
||||
let cfont = cairobg::cairo_scaled_font_create(
|
||||
cface, ptr::addr_of(fontmatrix), ptr::addr_of(idmatrix), options);
|
||||
assert cfont.is_not_null();
|
||||
assert cairobg::cairo_scaled_font_status(cfont) == 0 as cairo::cairo_status_t;
|
||||
cairobg::cairo_font_face_destroy(cface);
|
||||
cairobg::cairo_font_options_destroy(options);
|
||||
|
||||
let nfont: az::AzNativeFont = {
|
||||
mType: az::AZ_NATIVE_FONT_CAIRO_FONT_FACE,
|
||||
mFont: ptr::null()
|
||||
};
|
||||
|
||||
let azfont = azbg::AzCreateScaledFontWithCairo(
|
||||
ptr::addr_of(nfont),
|
||||
20f as az::AzFloat,
|
||||
cfont);
|
||||
assert azfont.is_not_null();
|
||||
cairobg::cairo_scaled_font_destroy(cfont);
|
||||
|
||||
let color = {
|
||||
r: 1f as AzFloat,
|
||||
g: 0f as AzFloat,
|
||||
b: 0.5f as AzFloat,
|
||||
a: 1f as AzFloat
|
||||
};
|
||||
let pattern = AzCreateColorPattern(ptr::addr_of(color));
|
||||
assert pattern.is_not_null();
|
||||
|
||||
let options: az::AzDrawOptions = {
|
||||
mAlpha: 1f as az::AzFloat,
|
||||
fields: 0 as uint16_t
|
||||
};
|
||||
|
||||
let glyphidx = 40 as uint32_t;//ftbg::FT_Get_Char_Index(face, 'w' as ft::FT_ULong);
|
||||
|
||||
#debug("glyph: %?", glyphidx);
|
||||
|
||||
for int::range(0, 3) {|i|
|
||||
let glyphs: [az::AzGlyph] = [
|
||||
{
|
||||
mIndex: glyphidx,
|
||||
mPosition: {
|
||||
x: (100 + 250 * i) as az::AzFloat,
|
||||
y: 600 as az::AzFloat
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
let glyphbuf: az::AzGlyphBuffer = unsafe {{
|
||||
mGlyphs: vec::unsafe::to_ptr(glyphs),
|
||||
mNumGlyphs: 1 as uint32_t
|
||||
}};
|
||||
|
||||
AzDrawTargetFillGlyphs(draw_target,
|
||||
azfont,
|
||||
ptr::addr_of(glyphbuf),
|
||||
pattern,
|
||||
ptr::addr_of(options),
|
||||
ptr::null());
|
||||
}
|
||||
|
||||
azbg::AzReleaseColorPattern(pattern);
|
||||
azbg::AzReleaseScaledFont(azfont);
|
||||
//ftbg::FT_Done_Face(face).for_sure();
|
||||
//ftbg::FT_Done_FreeType(library).for_sure();
|
||||
CGDataProviderRelease(fontprov);
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue