Skip to content

Commit

Permalink
Merge pull request servo#11 from pcwalton/webrender
Browse files Browse the repository at this point in the history
Support native fonts again post-e10s.
  • Loading branch information
glennw committed Dec 1, 2015
2 parents c09bb23 + d4dfc7b commit 3ca8182
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 42 deletions.
2 changes: 1 addition & 1 deletion components/gfx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ git = "https://github.com/servo/ipc-channel"
git = "https://github.com/glennw/webrender_traits"

[target.x86_64-apple-darwin.dependencies]
core-foundation = "0.1"
core-foundation = "0.2"
core-graphics = "0.1"

[target.i686-unknown-linux-gnu.dependencies.fontconfig]
Expand Down
7 changes: 5 additions & 2 deletions components/gfx/font_cache_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,11 @@ impl FontCache {
occupied.into_mut()
}
Entry::Vacant(vacant) => {
let bytes = template.bytes();
let font_key = webrender_api.add_raw_font(bytes);
let font_key = match (template.bytes_if_in_memory(), template.native_font()) {
(Some(bytes), _) => webrender_api.add_raw_font(bytes),
(None, Some(native_font)) => webrender_api.add_native_font(native_font),
(None, None) => webrender_api.add_raw_font(template.bytes().clone()),
};
vacant.insert(font_key)
}
};
Expand Down
12 changes: 12 additions & 0 deletions components/gfx/platform/freetype/font_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use std::fs::File;
use std::io::Read;
use string_cache::Atom;
use webrender_traits::NativeFontHandle;

/// Platform specific font representation for Linux.
/// The identifier is an absolute path, and the bytes
Expand Down Expand Up @@ -42,4 +43,15 @@ impl FontTemplateData {
pub fn bytes(&self) -> Vec<u8> {
self.bytes.clone()
}

/// Returns a clone of the bytes in this font if they are in memory. This function never
/// performs disk I/O.
pub fn bytes_if_in_memory(&self) -> Option<Vec<u8>> {
Some(self.bytes())
}

/// Returns the native font that underlies this font template, if applicable.
pub fn native_font(&self) -> Option<NativeFontHandle> {
None
}
}
42 changes: 26 additions & 16 deletions components/gfx/platform/macos/font_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,33 @@ impl FontTemplateData {
/// Returns a clone of the data in this font. This is a hugely expensive operation which
/// performs synchronous disk I/O and should never be done lightly.
pub fn bytes(&self) -> Vec<u8> {
match self.font_data {
Some(ref font_data) => font_data.clone(),
None => {
let path =
Url::parse(&*self.ctfont()
.expect("No Core Text font available!")
.url()
.expect("No URL for Core Text font!")
.get_string()
.to_string()).expect("Couldn't parse Core Text font URL!")
.to_file_path()
.expect("Core Text font didn't name a path!");
let mut bytes = Vec::new();
File::open(path).expect("Couldn't open font file!").read_to_end(&mut bytes).unwrap();
bytes
}
match self.bytes_if_in_memory() {
Some(font_data) => return font_data,
None => {}
}

let path = Url::parse(&*self.ctfont()
.expect("No Core Text font available!")
.url()
.expect("No URL for Core Text font!")
.get_string()
.to_string()).expect("Couldn't parse Core Text font URL!")
.to_file_path()
.expect("Core Text font didn't name a path!");
let mut bytes = Vec::new();
File::open(path).expect("Couldn't open font file!").read_to_end(&mut bytes).unwrap();
bytes
}

/// Returns a clone of the bytes in this font if they are in memory. This function never
/// performs disk I/O.
pub fn bytes_if_in_memory(&self) -> Option<Vec<u8>> {
self.font_data.clone()
}

/// Returns the native font that underlies this font template, if applicable.
pub fn native_font(&self) -> Option<CGFont> {
self.ctfont().map(|ctfont| ctfont.copy_to_CGFont())
}
}

Expand Down
2 changes: 1 addition & 1 deletion components/msg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ serde_macros = "0.6"
url = "0.5"

[target.x86_64-apple-darwin.dependencies]
core-foundation = "0.1"
core-foundation = "0.2"

[target.x86_64-apple-darwin.dependencies.io-surface]
git = "https://github.com/servo/io-surface-rs"
56 changes: 37 additions & 19 deletions components/servo/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ports/cef/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ git = "https://github.com/servo/rust-stb-image"
[target.x86_64-apple-darwin.dependencies]
objc = "0.1"
cocoa = "0.1"
core-foundation = "0.1"
core-foundation = "0.2"
core-graphics = "0.1"
cgl = "0.1"

Expand Down
3 changes: 1 addition & 2 deletions ports/glutin/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use glutin;
use glutin::{Api, ElementState, Event, GlRequest, MouseButton, VirtualKeyCode, MouseScrollDelta};
use layers::geometry::DevicePixel;
use layers::platform::surface::NativeDisplay;
use libc::c_void;
#[cfg(feature = "window")]
use msg::constellation_msg::{KeyState, NONE, CONTROL, SHIFT, ALT, SUPER};
use msg::constellation_msg::{self, Key};
Expand Down Expand Up @@ -158,7 +157,7 @@ impl Window {

#[cfg(not(target_os = "android"))]
fn load_gl_functions(window: &glutin::Window) {
gl::load_with(|s| window.get_proc_address(s) as *const c_void);
gl::load_with(|s| window.get_proc_address(s) as *const _);
}

#[cfg(target_os = "android")]
Expand Down

0 comments on commit 3ca8182

Please sign in to comment.