servo: Merge #15018 - gfx: Use proper freetype bindings (from emilio:freetype); r=jdm

<!-- Please describe your changes on the following line: -->

Needs https://github.com/servo/rust-freetype/pull/48, and https://github.com/servo/webrender/pull/716

Source-Repo: https://github.com/servo/servo
Source-Revision: c8c38249a3ee38e72e4a427b05ab96b95d08f8fa
This commit is contained in:
Emilio Cobos Álvarez 2017-01-16 13:01:59 -08:00
parent b973c771f4
commit 706baa3dd4
4 changed files with 32 additions and 31 deletions

22
servo/Cargo.lock generated
View File

@ -91,15 +91,15 @@ dependencies = [
[[package]]
name = "azure"
version = "0.9.2"
source = "git+https://github.com/servo/rust-azure#a6219cee8d273528207b42353a6c153e69ece5ff"
version = "0.10.0"
source = "git+https://github.com/servo/rust-azure#d5aa52563e620be05aa52727ce52065ac54b0751"
dependencies = [
"cmake 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)",
"core-foundation 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"core-graphics 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"core-text 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)",
"freetype 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"freetype 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
@ -258,7 +258,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
name = "canvas"
version = "0.0.1"
dependencies = [
"azure 0.9.2 (git+https://github.com/servo/rust-azure)",
"azure 0.10.0 (git+https://github.com/servo/rust-azure)",
"canvas_traits 0.0.1",
"cssparser 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)",
@ -840,7 +840,7 @@ dependencies = [
[[package]]
name = "freetype"
version = "0.1.3"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
@ -930,7 +930,7 @@ dependencies = [
"euclid 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
"fontsan 0.3.2 (git+https://github.com/servo/fontsan)",
"freetype 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"freetype 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx_traits 0.0.1",
"harfbuzz-sys 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
@ -3227,7 +3227,7 @@ dependencies = [
[[package]]
name = "webrender"
version = "0.11.1"
source = "git+https://github.com/servo/webrender#d19cf18d2957d706594ca3d6f31207c01b11d45d"
source = "git+https://github.com/servo/webrender#347339d760bca40cd4b35deccaf31abf70996db4"
dependencies = [
"app_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bincode 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -3239,7 +3239,7 @@ dependencies = [
"dwrote 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
"freetype 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"freetype 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gleam 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
@ -3253,7 +3253,7 @@ dependencies = [
[[package]]
name = "webrender_traits"
version = "0.11.0"
source = "git+https://github.com/servo/webrender#d19cf18d2957d706594ca3d6f31207c01b11d45d"
source = "git+https://github.com/servo/webrender#347339d760bca40cd4b35deccaf31abf70996db4"
dependencies = [
"app_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
@ -3393,7 +3393,7 @@ dependencies = [
"checksum aster 0.34.0 (registry+https://github.com/rust-lang/crates.io-index)" = "88bb8ecdf6a7eaddb7bfd872ebf5e085d343ca42ce98c582dba8046e3450b524"
"checksum atomic_refcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fb2dcb6e6d35f20276943cc04bb98e538b348d525a04ac79c10021561d202f21"
"checksum audio-video-metadata 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "03da2550cb89fe3faf218c179261c26cf7891c4234707c15f5d09ebb32ae2400"
"checksum azure 0.9.2 (git+https://github.com/servo/rust-azure)" = "<none>"
"checksum azure 0.10.0 (git+https://github.com/servo/rust-azure)" = "<none>"
"checksum backtrace 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "346d7644f0b5f9bc73082d3b2236b69a05fd35cce0cfa3724e184e6a5c9e2a2f"
"checksum backtrace-sys 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3602e8d8c43336088a8505fa55cae2b3884a9be29440863a11528a42f46f6bb7"
"checksum bincode 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9fbba641f73d3e74a5431d4a6d9e42a70bcce76d466d796c852ba1db31ba41bc"
@ -3457,7 +3457,7 @@ dependencies = [
"checksum flate2 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "3eeb481e957304178d2e782f2da1257f1434dfecbae883bafb61ada2a9fea3bb"
"checksum fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6cc484842f1e2884faf56f529f960cc12ad8c71ce96cc7abba0a067c98fee344"
"checksum fontsan 0.3.2 (git+https://github.com/servo/fontsan)" = "<none>"
"checksum freetype 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "812b23abc34a2cd1e1a0635a8d65e9bc83f2dd6e7879b92683ed0b9faaa629e5"
"checksum freetype 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fde23272c687e4570aefec06cb71174ec0f5284b725deac4e77ba2665d635faf"
"checksum fs2 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "bcd414e5a1a979b931bb92f41b7a54106d3f6d2e6c253e9ce943b7cd468251ef"
"checksum futf 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e7a9689380a2553b51c564b3d9178075c68ebd0b397972c783acfd28b46c28ad"
"checksum gaol 0.0.1 (git+https://github.com/servo/gaol)" = "<none>"

View File

@ -53,7 +53,7 @@ core-graphics = "0.4"
core-text = "2.0"
[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies]
freetype = "0.1.3"
freetype = "0.2"
servo-fontconfig = "0.2.1"
[target.'cfg(any(target_arch = "x86_64", target_arch = "aarch64"))'.dependencies]

View File

@ -7,20 +7,20 @@ extern crate freetype;
use app_units::Au;
use font::{FontHandleMethods, FontMetrics, FontTableMethods};
use font::{FontTableTag, FractionalPixel, GPOS, GSUB, KERN};
use freetype::freetype::{FTErrorMethods, FT_F26Dot6, FT_Face, FT_FaceRec};
use freetype::freetype::{FT_Done_Face, FT_New_Memory_Face};
use freetype::freetype::{FT_F26Dot6, FT_Face, FT_FaceRec};
use freetype::freetype::{FT_Get_Char_Index, FT_Get_Postscript_Name};
use freetype::freetype::{FT_Get_Kerning, FT_Get_Sfnt_Table, FT_Load_Sfnt_Table};
use freetype::freetype::{FT_GlyphSlot, FT_Library, FT_Long, FT_ULong};
use freetype::freetype::{FT_KERNING_DEFAULT, FT_STYLE_FLAG_BOLD, FT_STYLE_FLAG_ITALIC};
use freetype::freetype::{FT_Kerning_Mode, FT_STYLE_FLAG_BOLD, FT_STYLE_FLAG_ITALIC};
use freetype::freetype::{FT_Load_Glyph, FT_Set_Char_Size};
use freetype::freetype::{FT_SizeRec, FT_Size_Metrics, FT_UInt, struct_FT_Vector_};
use freetype::freetype::ft_sfnt_os2;
use freetype::freetype::{FT_SizeRec, FT_Size_Metrics, FT_UInt, FT_Vector};
use freetype::freetype::FT_Sfnt_Tag;
use freetype::tt_os2::TT_OS2;
use libc::c_char;
use platform::font_context::FontContextHandle;
use platform::font_template::FontTemplateData;
use std::{mem, ptr};
use std::os::raw::{c_char, c_long};
use std::sync::Arc;
use style::computed_values::{font_stretch, font_weight};
use super::c_str_to_string;
@ -121,15 +121,15 @@ impl FontHandleMethods for FontHandle {
}
}
fn is_italic(&self) -> bool {
unsafe { (*self.face).style_flags & FT_STYLE_FLAG_ITALIC != 0 }
unsafe { (*self.face).style_flags & FT_STYLE_FLAG_ITALIC as c_long != 0 }
}
fn boldness(&self) -> font_weight::T {
let default_weight = font_weight::T::Weight400;
if unsafe { (*self.face).style_flags & FT_STYLE_FLAG_BOLD == 0 } {
if unsafe { (*self.face).style_flags & FT_STYLE_FLAG_BOLD as c_long == 0 } {
default_weight
} else {
unsafe {
let os2 = FT_Get_Sfnt_Table(self.face, ft_sfnt_os2) as *mut TT_OS2;
let os2 = FT_Get_Sfnt_Table(self.face, FT_Sfnt_Tag::FT_SFNT_OS2) as *mut TT_OS2;
let valid = !os2.is_null() && (*os2).version != 0xffff;
if valid {
let weight =(*os2).usWeightClass;
@ -172,9 +172,11 @@ impl FontHandleMethods for FontHandle {
fn glyph_h_kerning(&self, first_glyph: GlyphId, second_glyph: GlyphId)
-> FractionalPixel {
assert!(!self.face.is_null());
let mut delta = struct_FT_Vector_ { x: 0, y: 0 };
let mut delta = FT_Vector { x: 0, y: 0 };
unsafe {
FT_Get_Kerning(self.face, first_glyph, second_glyph, FT_KERNING_DEFAULT, &mut delta);
FT_Get_Kerning(self.face, first_glyph, second_glyph,
FT_Kerning_Mode::FT_KERNING_DEFAULT as FT_UInt,
&mut delta);
}
fixed_to_float_ft(delta.x as i32)
}
@ -196,7 +198,7 @@ impl FontHandleMethods for FontHandle {
let advance = advance as i32;
Some(fixed_to_float_ft(advance) as FractionalPixel)
} else {
debug!("Unable to load glyph {}. reason: {}", glyph, res);
debug!("Unable to load glyph {}. reason: {:?}", glyph, res);
None
}
}
@ -226,7 +228,7 @@ impl FontHandleMethods for FontHandle {
let mut strikeout_offset = Au(0);
let mut x_height = Au(0);
unsafe {
let os2 = FT_Get_Sfnt_Table(face, ft_sfnt_os2) as *mut TT_OS2;
let os2 = FT_Get_Sfnt_Table(face, FT_Sfnt_Tag::FT_SFNT_OS2) as *mut TT_OS2;
let valid = !os2.is_null() && (*os2).version != 0xffff;
if valid {
strikeout_size = self.font_units_to_au((*os2).yStrikeoutSize as f64);

View File

@ -3,15 +3,14 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use alloc::heap;
use freetype::freetype::FTErrorMethods;
use freetype::freetype::FT_Add_Default_Modules;
use freetype::freetype::FT_Done_Library;
use freetype::freetype::FT_Library;
use freetype::freetype::FT_Memory;
use freetype::freetype::FT_MemoryRec_;
use freetype::freetype::FT_New_Library;
use freetype::freetype::struct_FT_MemoryRec_;
use heapsize::{HeapSizeOf, heap_size_of};
use libc::{c_long, c_void};
use std::os::raw::{c_long, c_void};
use std::ptr;
use std::rc::Rc;
@ -118,11 +117,11 @@ impl FontContextHandle {
let user = Box::into_raw(box User {
size: 0,
});
let mem = Box::into_raw(box struct_FT_MemoryRec_ {
let mem = Box::into_raw(box FT_MemoryRec_ {
user: user as *mut c_void,
alloc: ft_alloc,
free: ft_free,
realloc: ft_realloc,
alloc: Some(ft_alloc),
free: Some(ft_free),
realloc: Some(ft_realloc),
});
unsafe {
let mut ctx: FT_Library = ptr::null_mut();