Use atoms for font template structures.

This commit is contained in:
Glenn Watson 2015-07-13 08:00:28 +10:00
parent d7cf58d6f1
commit f8eeef0eb4
5 changed files with 27 additions and 26 deletions

View file

@ -2,9 +2,9 @@
* 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/. */
use std::borrow::ToOwned;
use std::fs::File;
use std::io::Read;
use string_cache::Atom;
/// Platform specific font representation for Linux.
/// The identifier is an absolute path, and the bytes
@ -12,18 +12,18 @@ use std::io::Read;
/// freetype and azure directly.
pub struct FontTemplateData {
pub bytes: Vec<u8>,
pub identifier: String,
pub identifier: Atom,
}
impl FontTemplateData {
pub fn new(identifier: &str, font_data: Option<Vec<u8>>) -> FontTemplateData {
pub fn new(identifier: Atom, font_data: Option<Vec<u8>>) -> FontTemplateData {
let bytes = match font_data {
Some(bytes) => {
bytes
},
None => {
// TODO: Handle file load failure!
let mut file = File::open(identifier).unwrap();
let mut file = File::open(identifier.as_slice()).unwrap();
let mut buffer = vec![];
file.read_to_end(&mut buffer).unwrap();
buffer
@ -32,7 +32,7 @@ impl FontTemplateData {
FontTemplateData {
bytes: bytes,
identifier: identifier.to_owned(),
identifier: identifier,
}
}
}

View file

@ -7,7 +7,7 @@ use core_graphics::font::CGFont;
use core_text::font::CTFont;
use core_text;
use std::borrow::ToOwned;
use string_cache::Atom;
/// Platform specific font representation for mac.
/// The identifier is a PostScript font name. The
@ -15,7 +15,7 @@ use std::borrow::ToOwned;
/// paint functions that create CGFont references.
pub struct FontTemplateData {
pub ctfont: Option<CTFont>,
pub identifier: String,
pub identifier: Atom,
pub font_data: Option<Vec<u8>>
}
@ -23,7 +23,7 @@ unsafe impl Send for FontTemplateData {}
unsafe impl Sync for FontTemplateData {}
impl FontTemplateData {
pub fn new(identifier: &str, font_data: Option<Vec<u8>>) -> FontTemplateData {
pub fn new(identifier: Atom, font_data: Option<Vec<u8>>) -> FontTemplateData {
let ctfont = match font_data {
Some(ref bytes) => {
let fontprov = CGDataProvider::from_buffer(bytes);
@ -34,7 +34,7 @@ impl FontTemplateData {
}
},
None => {
Some(core_text::font::new_from_name(identifier, 0.0).unwrap())
Some(core_text::font::new_from_name(identifier.as_slice(), 0.0).unwrap())
}
};