mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Use atoms for font template structures.
This commit is contained in:
parent
d7cf58d6f1
commit
f8eeef0eb4
5 changed files with 27 additions and 26 deletions
|
@ -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,7 +75,7 @@ impl FontTemplate {
|
|||
};
|
||||
|
||||
FontTemplate {
|
||||
identifier: identifier.to_owned(),
|
||||
identifier: identifier,
|
||||
descriptor: None,
|
||||
weak_ref: maybe_weak_ref,
|
||||
strong_ref: maybe_strong_ref,
|
||||
|
@ -83,8 +83,8 @@ impl FontTemplate {
|
|||
}
|
||||
}
|
||||
|
||||
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,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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue