Auto merge of #11619 - Ms2ger:freetype, r=nox

Some cleanup in gfx.

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11619)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-06-05 06:57:18 -05:00
commit d768ee5d4c
8 changed files with 22 additions and 27 deletions

View file

@ -104,8 +104,7 @@ pub mod paint_thread;
// Platform-specific implementations.
#[allow(unsafe_code)]
pub mod platform;
mod platform;
// Text
#[allow(unsafe_code)]
pub mod text;

View file

@ -23,9 +23,9 @@ use platform::font_template::FontTemplateData;
use std::sync::Arc;
use std::{mem, ptr};
use style::computed_values::{font_stretch, font_weight};
use super::c_str_to_string;
use text::glyph::GlyphId;
use text::util::{fixed_to_float, float_to_fixed};
use util::str::c_str_to_string;
fn float_to_fixed_ft(f: f64) -> i32 {
float_to_fixed(6, f)

View file

@ -2,8 +2,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#![allow(non_snake_case)]
extern crate fontconfig;
extern crate freetype;
@ -18,7 +16,7 @@ use libc::{c_char, c_int};
use std::borrow::ToOwned;
use std::ffi::CString;
use std::ptr;
use util::str::c_str_to_string;
use super::c_str_to_string;
static FC_FAMILY: &'static [u8] = b"family\0";
static FC_FILE: &'static [u8] = b"file\0";
@ -28,9 +26,9 @@ static FC_FONTFORMAT: &'static [u8] = b"fontformat\0";
pub fn for_each_available_family<F>(mut callback: F) where F: FnMut(String) {
unsafe {
let config = FcConfigGetCurrent();
let fontSet = FcConfigGetFonts(config, FcSetSystem);
for i in 0..((*fontSet).nfont as isize) {
let font = (*fontSet).fonts.offset(i);
let font_set = FcConfigGetFonts(config, FcSetSystem);
for i in 0..((*font_set).nfont as isize) {
let font = (*font_set).fonts.offset(i);
let mut family: *mut FcChar8 = ptr::null_mut();
let mut format: *mut FcChar8 = ptr::null_mut();
let mut v: c_int = 0;

View file

@ -9,7 +9,17 @@ pub use platform::freetype::{font, font_context, font_list, font_template};
pub use platform::macos::{font, font_context, font_list, font_template};
#[cfg(any(target_os = "linux", target_os = "android", target_os = "windows"))]
pub mod freetype {
mod freetype {
use libc::c_char;
use std::ffi::CStr;
use std::str;
/// Creates a String from the given null-terminated buffer.
/// Panics if the buffer does not contain UTF-8.
unsafe fn c_str_to_string(s: *const c_char) -> String {
str::from_utf8(CStr::from_ptr(s).to_bytes()).unwrap().to_owned()
}
pub mod font;
pub mod font_context;
pub mod font_list;
@ -17,7 +27,7 @@ pub mod freetype {
}
#[cfg(target_os = "macos")]
pub mod macos {
mod macos {
pub mod font;
pub mod font_context;
pub mod font_list;

View file

@ -627,6 +627,7 @@ impl<'a> GlyphStore {
/// Used for SIMD.
#[inline]
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
#[allow(unsafe_code)]
fn transmute_entry_buffer_to_u32_buffer(&self) -> &[u32] {
unsafe { mem::transmute(self.entry_buffer.as_slice()) }
}

View file

@ -2,12 +2,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* This file exists just to make it easier to import things inside of
./text/ without specifying the file they came out of imports.
Note that you still must define each of the files as a module in
servo.rc. This is not ideal and may be changed in the future. */
pub use text::shaping::Shaper;
pub use text::text_run::TextRun;

View file

@ -2,6 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#![allow(unsafe_code)]
use app_units::Au;
use euclid::Point2D;
use font::{DISABLE_KERNING_SHAPING_FLAG, Font, FontTableMethods, FontTableTag};

View file

@ -3,14 +3,11 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use app_units::Au;
use libc::c_char;
use num_traits::ToPrimitive;
use std::borrow::ToOwned;
use std::convert::AsRef;
use std::ffi::CStr;
use std::iter::{Filter, Peekable};
use std::ops::Deref;
use std::str::{Split, from_utf8};
use std::str::Split;
pub type StaticCharVec = &'static [char];
pub type StaticStringVec = &'static [&'static str];
@ -150,12 +147,6 @@ impl Deref for LowercaseString {
}
}
/// Creates a String from the given null-terminated buffer.
/// Panics if the buffer does not contain UTF-8.
pub unsafe fn c_str_to_string(s: *const c_char) -> String {
from_utf8(CStr::from_ptr(s).to_bytes()).unwrap().to_owned()
}
pub fn str_join<I, T>(strs: I, join: &str) -> String
where I: IntoIterator<Item=T>, T: AsRef<str>,
{