Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use atoms for font template structures. #6606

Merged
merged 1 commit into from Jul 12, 2015
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Use atoms for font template structures.

  • Loading branch information
gw3583 committed Jul 12, 2015
commit f8eeef0eb4106043ee6fe217ea3c4dedfb7144ab
@@ -61,9 +61,9 @@ impl FontFamily {
None
}

fn add_template(&mut self, identifier: &str, maybe_data: Option<Vec<u8>>) {
fn add_template(&mut self, identifier: Atom, maybe_data: Option<Vec<u8>>) {
for template in self.templates.iter() {
if template.identifier() == identifier {
if *template.identifier() == identifier {
return;
}
}
@@ -140,7 +140,7 @@ impl FontCache {
match maybe_resource {
Ok((_, bytes)) => {
let family = &mut self.web_families.get_mut(&family_name).unwrap();
family.add_template(&url.to_string(), Some(bytes));
family.add_template(Atom::from_slice(&url.to_string()), Some(bytes));
},
Err(_) => {
debug!("Failed to load web font: family={:?} url={}", family_name, url);
@@ -150,7 +150,7 @@ impl FontCache {
Source::Local(ref local_family_name) => {
let family = &mut self.web_families.get_mut(&family_name).unwrap();
get_variations_for_family(&local_family_name, |path| {
family.add_template(&path, None);
family.add_template(Atom::from_slice(&path), None);
});
}
}
@@ -192,7 +192,7 @@ impl FontCache {

if s.templates.len() == 0 {
get_variations_for_family(family_name, |path| {
s.add_template(&path, None);
s.add_template(Atom::from_slice(&path), None);
});
}

@@ -14,6 +14,7 @@ use fnv::FnvHasher;
use platform::font::FontHandle;
use platform::font_template::FontTemplateData;
use smallvec::SmallVec8;
use string_cache::Atom;
use util::cache::HashCache;
use util::geometry::Au;
use util::mem::HeapSizeOf;
@@ -60,7 +61,7 @@ struct FallbackFontCacheEntry {
/// can be shared by multiple text runs.
struct PaintFontCacheEntry {
pt_size: Au,
identifier: String,
identifier: Atom,
font: Rc<RefCell<ScaledFont>>,
}

@@ -261,9 +262,9 @@ impl FontContext {
/// Create a paint font for use with azure. May return a cached
/// reference if already used by this font context.
pub fn get_paint_font_from_template(&mut self,
template: &Arc<FontTemplateData>,
pt_size: Au)
-> Rc<RefCell<ScaledFont>> {
template: &Arc<FontTemplateData>,
pt_size: Au)
-> Rc<RefCell<ScaledFont>> {
for cached_font in self.paint_font_cache.iter() {
if cached_font.pt_size == pt_size &&
cached_font.identifier == template.identifier {
@@ -6,8 +6,8 @@ use font::FontHandleMethods;
use platform::font_context::FontContextHandle;
use platform::font::FontHandle;
use platform::font_template::FontTemplateData;
use string_cache::Atom;

use std::borrow::ToOwned;
use std::sync::{Arc, Weak};
use style::computed_values::{font_stretch, font_weight};

@@ -46,7 +46,7 @@ impl PartialEq for FontTemplateDescriptor {
/// font instance handles. It contains a unique
/// FontTemplateData structure that is platform specific.
pub struct FontTemplate {
identifier: String,
identifier: Atom,
descriptor: Option<FontTemplateDescriptor>,
weak_ref: Option<Weak<FontTemplateData>>,
// GWTODO: Add code path to unset the strong_ref for web fonts!
@@ -58,9 +58,9 @@ pub struct FontTemplate {
/// is common, regardless of the number of instances of
/// this font handle per thread.
impl FontTemplate {
pub fn new(identifier: &str, maybe_bytes: Option<Vec<u8>>) -> FontTemplate {
pub fn new(identifier: Atom, maybe_bytes: Option<Vec<u8>>) -> FontTemplate {
let maybe_data = match maybe_bytes {
Some(_) => Some(FontTemplateData::new(identifier, maybe_bytes)),
Some(_) => Some(FontTemplateData::new(identifier.clone(), maybe_bytes)),
None => None,
};

@@ -75,16 +75,16 @@ impl FontTemplate {
};

FontTemplate {
identifier: identifier.to_owned(),
identifier: identifier,
descriptor: None,
weak_ref: maybe_weak_ref,
strong_ref: maybe_strong_ref,
is_valid: true,
}
}

pub fn identifier<'a>(&'a self) -> &'a str {
&*self.identifier
pub fn identifier(&self) -> &Atom {
&self.identifier
}

/// Get the data for creating a font if it matches a given descriptor.
@@ -158,7 +158,7 @@ impl FontTemplate {
}

assert!(self.strong_ref.is_none());
let template_data = Arc::new(FontTemplateData::new(&self.identifier, None));
let template_data = Arc::new(FontTemplateData::new(self.identifier.clone(), None));
self.weak_ref = Some(template_data.downgrade());
template_data
}
@@ -2,28 +2,28 @@
* 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
/// field is the loaded data that can be passed to
/// 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,
}
}
}
@@ -7,23 +7,23 @@ 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
/// CTFont object is cached here for use by the
/// 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>>
}

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())
}
};

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.