diff --git a/Makefile.in b/Makefile.in index 88adc212601..3ea31fca4b6 100644 --- a/Makefile.in +++ b/Makefile.in @@ -30,6 +30,7 @@ SERVO_DEPS = \ $(NULL) CHECK_DEPS = CLEAN_DEPS = +AZURE_DEPS = ifeq ($(OSTYPE),darwin) SERVO_DEPS += src/rust-cocoa/libcocoa.dummy @@ -37,6 +38,7 @@ ifeq ($(OSTYPE),darwin) # doesn't work neither does servo CHECK_DEPS += check-rust-cocoa CLEAN_DEPS += clean-rust-cocoa + AZURE_DEPS += src/rust-cocoa/libcocoa.dummy endif SERVO_DEPS += \ @@ -91,8 +93,8 @@ src/rust-harfbuzz/libharfbuzz.dummy: src/harfbuzz/src/.libs/libharfbuzz.a src/rust-mozjs/libmozjs.dummy: src/mozjs/libjs_static.a $(MAKE) -C src/rust-mozjs RUSTFLAGS="-L ../mozjs/" -src/rust-azure/libazure.dummy: - $(MAKE) -C src/rust-azure +src/rust-azure/libazure.dummy: $(AZURE_DEPS) + RUSTFLAGS="-L ../rust-cocoa" $(MAKE) -C src/rust-azure src/rust-sdl/libsdl.dummy: $(MAKE) -C src/rust-sdl @@ -117,8 +119,8 @@ check-rust-mozjs: src/mozjs/libjs_static.a $(MAKE) check -C src/rust-mozjs RUSTFLAGS="-L ../mozjs/" .PHONY: check-rust-azure -check-rust-azure: - $(MAKE) check -C src/rust-azure +check-rust-azure: $(AZURE_DEPS) + RUSTFLAGS="-L ../rust-cocoa" $(MAKE) check -C src/rust-azure .PHONY: check-rust-sdl check-rust-sdl: diff --git a/src/rust-azure b/src/rust-azure index b101e938bc1..8ce13fb34d9 160000 --- a/src/rust-azure +++ b/src/rust-azure @@ -1 +1 @@ -Subproject commit b101e938bc1eb7a13cb4a9aa6fb52ab650fed71b +Subproject commit 8ce13fb34d98fe14be42fb0bda31bd9b6ab86dfe diff --git a/src/rust-cocoa b/src/rust-cocoa index cff75030841..478f61bb68f 160000 --- a/src/rust-cocoa +++ b/src/rust-cocoa @@ -1 +1 @@ -Subproject commit cff7503084162cc68598e059fa46ec634bc994fe +Subproject commit 478f61bb68feea43c22c9b88f52393ea15908dae diff --git a/src/servo/gfx/renderer.rs b/src/servo/gfx/renderer.rs index 3bf73af81ce..e715bab0f59 100644 --- a/src/servo/gfx/renderer.rs +++ b/src/servo/gfx/renderer.rs @@ -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")]