diff --git a/src/rust-azure b/src/rust-azure index 4fc1f2a7f87..77f4431772c 160000 --- a/src/rust-azure +++ b/src/rust-azure @@ -1 +1 @@ -Subproject commit 4fc1f2a7f87c44dd87cb05815001dd4f09470231 +Subproject commit 77f4431772c9beb954b87b1f08580d3f13db3023 diff --git a/src/servo/gfx/JosefinSans-SemiBold.ttf b/src/servo/gfx/JosefinSans-SemiBold.ttf new file mode 100644 index 00000000000..f58d378543e Binary files /dev/null and b/src/servo/gfx/JosefinSans-SemiBold.ttf differ diff --git a/src/servo/gfx/OFL.txt b/src/servo/gfx/OFL.txt new file mode 100644 index 00000000000..d0a273c523b --- /dev/null +++ b/src/servo/gfx/OFL.txt @@ -0,0 +1,93 @@ +Copyright (c) 2009, 2010, 2011 Daniel Johnson (). + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/src/servo/gfx/renderer.rs b/src/servo/gfx/renderer.rs index f296d7f6d74..d8f09b1e953 100644 --- a/src/servo/gfx/renderer.rs +++ b/src/servo/gfx/renderer.rs @@ -32,7 +32,9 @@ fn renderer(sink: S) -> chan { #debug("renderer: got render request"); let draw_target = draw_target_ch.recv(); #debug("renderer: rendering"); + clear(draw_target); draw_display_list(draw_target, display_list); + draw_some_text(draw_target); #debug("renderer: returning surface"); sink.draw(draw_target_ch, draw_target); } @@ -127,8 +129,6 @@ fn draw_display_list( draw_target: AzDrawTargetRef, display_list: dl::display_list ) { - clear(draw_target); - for display_list.each {|item| #debug["drawing %?", item]; @@ -146,6 +146,135 @@ fn draw_display_list( } } +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; + + 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 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 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 = 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(); +} + fn clear(draw_target: AzDrawTargetRef) { let black_color = { diff --git a/src/servo/layout/base.rs b/src/servo/layout/base.rs index 69da2aaf93b..80bcda82db3 100644 --- a/src/servo/layout/base.rs +++ b/src/servo/layout/base.rs @@ -9,7 +9,7 @@ import image::base::image; import /*layout::*/block::block_layout_methods; import /*layout::*/inline::inline_layout_methods; import /*layout::*/style::style::*; -import /*layout::*/text::{text_box, text_layout_methods}; +import /*layout::*/text::*; import util::tree; enum box_kind { diff --git a/src/servo/layout/inline.rs b/src/servo/layout/inline.rs index 928d6ab802c..d7f3ee43861 100644 --- a/src/servo/layout/inline.rs +++ b/src/servo/layout/inline.rs @@ -4,7 +4,7 @@ import dom::rcu; import dom::rcu::reader_methods; import gfx::geom::au; import /*layout::*/base::*; // FIXME: Can't get around import *; resolve bug. -import /*layout::*/style::style::*; +import /*layout::*/style::style::*; // ditto import util::tree; #[doc="The main reflow routine for inline layout."] diff --git a/src/servo/platform/osmain.rs b/src/servo/platform/osmain.rs index 8cb5c86abd6..4131e6cfc86 100644 --- a/src/servo/platform/osmain.rs +++ b/src/servo/platform/osmain.rs @@ -69,6 +69,7 @@ fn mainloop(po: port) { assert surfaces.s1.surf.az_target == dt; let sdl_surf = surfaces.s1.surf.sdl_surf; + cairo_surface_flush(surfaces.s1.surf.cairo_surf); sdl::video::unlock_surface(sdl_surf); sdl::video::blit_surface(sdl_surf, ptr::null(), screen, ptr::null());