~[] to Vec in FontStyle and FontGroup

This commit is contained in:
Matt Murphy 2014-04-19 09:31:57 -05:00 committed by Ms2ger
parent b1d0dac50d
commit 7447ed69e3
5 changed files with 16 additions and 16 deletions

View file

@ -54,7 +54,7 @@ impl BufferKey {
/// A helper struct to keep track of buffers in the HashMap /// A helper struct to keep track of buffers in the HashMap
struct BufferValue<T> { struct BufferValue<T> {
/// An array of buffers, all the same size /// An array of buffers, all the same size
buffers: ~[T], buffers: Vec<T>,
/// The counter when this size was last requested /// The counter when this size was last requested
last_action: uint, last_action: uint,
} }
@ -86,7 +86,7 @@ impl<T: Tile> BufferMap<T> {
// use lazy insertion function to prevent unnecessary allocation // use lazy insertion function to prevent unnecessary allocation
let counter = &self.counter; let counter = &self.counter;
self.map.find_or_insert_with(new_key, |_| BufferValue { self.map.find_or_insert_with(new_key, |_| BufferValue {
buffers: ~[], buffers: Vec::new(),
last_action: *counter last_action: *counter
}).buffers.push(new_buffer); }).buffers.push(new_buffer);

View file

@ -101,7 +101,7 @@ pub struct FontStyle {
pub pt_size: f64, pub pt_size: f64,
pub weight: font_weight::T, pub weight: font_weight::T,
pub style: font_style::T, pub style: font_style::T,
pub families: ~[~str], pub families: Vec<~str>,
// TODO(Issue #198): font-stretch, text-decoration, font-variant, size-adjust // TODO(Issue #198): font-stretch, text-decoration, font-variant, size-adjust
} }
@ -143,15 +143,15 @@ pub enum FontSelector {
// The ordering of font instances is mainly decided by the CSS // The ordering of font instances is mainly decided by the CSS
// 'font-family' property. The last font is a system fallback font. // 'font-family' property. The last font is a system fallback font.
pub struct FontGroup { pub struct FontGroup {
pub families: ~[~str], pub families: Vec<~str>,
// style of the first western font in group, which is // style of the first western font in group, which is
// used for purposes of calculating text run metrics. // used for purposes of calculating text run metrics.
pub style: UsedFontStyle, pub style: UsedFontStyle,
pub fonts: ~[Rc<RefCell<Font>>] pub fonts: Vec<Rc<RefCell<Font>>>
} }
impl FontGroup { impl FontGroup {
pub fn new(families: ~[~str], style: &UsedFontStyle, fonts: ~[Rc<RefCell<Font>>]) -> FontGroup { pub fn new(families: Vec<~str>, style: &UsedFontStyle, fonts: Vec<Rc<RefCell<Font>>>) -> FontGroup {
FontGroup { FontGroup {
families: families, families: families,
style: (*style).clone(), style: (*style).clone(),
@ -160,14 +160,14 @@ impl FontGroup {
} }
pub fn teardown(&mut self) { pub fn teardown(&mut self) {
self.fonts = ~[]; self.fonts = Vec::new();
} }
pub fn create_textrun(&self, text: ~str, decoration: text_decoration::T) -> TextRun { pub fn create_textrun(&self, text: ~str, decoration: text_decoration::T) -> TextRun {
assert!(self.fonts.len() > 0); assert!(self.fonts.len() > 0);
// TODO(Issue #177): Actually fall back through the FontGroup when a font is unsuitable. // TODO(Issue #177): Actually fall back through the FontGroup when a font is unsuitable.
TextRun::new(&mut *self.fonts[0].borrow_mut(), text.clone(), decoration) TextRun::new(&mut *self.fonts.get(0).borrow_mut(), text.clone(), decoration)
} }
} }

View file

@ -116,7 +116,7 @@ impl FontContext {
} }
fn create_font_group(&mut self, style: &SpecifiedFontStyle) -> Rc<RefCell<FontGroup>> { fn create_font_group(&mut self, style: &SpecifiedFontStyle) -> Rc<RefCell<FontGroup>> {
let mut fonts = ~[]; let mut fonts = Vec::new();
debug!("(create font group) --- starting ---"); debug!("(create font group) --- starting ---");
@ -200,7 +200,7 @@ impl FontContext {
Rc::new( Rc::new(
RefCell::new( RefCell::new(
FontGroup::new(style.families.to_owned(), &used_style, fonts))) FontGroup::new(style.families.clone(), &used_style, fonts)))
} }
fn create_font_instance(&self, desc: &FontDescriptor) -> Result<Rc<RefCell<Font>>, ()> { fn create_font_instance(&self, desc: &FontDescriptor) -> Result<Rc<RefCell<Font>>, ()> {

View file

@ -225,7 +225,7 @@ impl TextRunScanner {
// sequence. If no clump takes ownership, however, it will leak. // sequence. If no clump takes ownership, however, it will leak.
let clump = self.clump; let clump = self.clump;
let run = if clump.length() != 0 && run_str.len() > 0 { let run = if clump.length() != 0 && run_str.len() > 0 {
Some(Arc::new(~TextRun::new(&mut *fontgroup.borrow().fonts[0].borrow_mut(), Some(Arc::new(~TextRun::new(&mut *fontgroup.borrow().fonts.get(0).borrow_mut(),
run_str.clone(), decoration))) run_str.clone(), decoration)))
} else { } else {
None None
@ -267,7 +267,7 @@ impl TextRunScanner {
pub fn font_metrics_for_style(font_context: &mut FontContext, font_style: &FontStyle) pub fn font_metrics_for_style(font_context: &mut FontContext, font_style: &FontStyle)
-> FontMetrics { -> FontMetrics {
let fontgroup = font_context.get_resolved_font_for_style(font_style); let fontgroup = font_context.get_resolved_font_for_style(font_style);
fontgroup.borrow().fonts[0].borrow().metrics.clone() fontgroup.borrow().fonts.get(0).borrow().metrics.clone()
} }
/// Converts a computed style to a font style used for rendering. /// Converts a computed style to a font style used for rendering.

View file

@ -705,10 +705,10 @@ pub mod longhands {
// Fantasy, // Fantasy,
// Monospace, // Monospace,
} }
pub type T = ~[FontFamily]; pub type T = Vec<FontFamily>;
} }
pub type SpecifiedValue = computed_value::T; pub type SpecifiedValue = computed_value::T;
#[inline] pub fn get_initial_value() -> computed_value::T { ~[FamilyName(~"serif")] } #[inline] pub fn get_initial_value() -> computed_value::T { vec!(FamilyName(~"serif")) }
/// <familiy-name># /// <familiy-name>#
/// <familiy-name> = <string> | [ <ident>+ ] /// <familiy-name> = <string> | [ <ident>+ ]
/// TODO: <generic-familiy> /// TODO: <generic-familiy>
@ -716,7 +716,7 @@ pub mod longhands {
from_iter(input.skip_whitespace()) from_iter(input.skip_whitespace())
} }
pub fn from_iter<'a>(mut iter: SkipWhitespaceIterator<'a>) -> Option<SpecifiedValue> { pub fn from_iter<'a>(mut iter: SkipWhitespaceIterator<'a>) -> Option<SpecifiedValue> {
let mut result = ~[]; let mut result = Vec::new();
macro_rules! add( macro_rules! add(
($value: expr, $b: expr) => { ($value: expr, $b: expr) => {
{ {
@ -743,7 +743,7 @@ pub mod longhands {
// "fantasy" => add!(Fantasy, break 'outer), // "fantasy" => add!(Fantasy, break 'outer),
// "monospace" => add!(Monospace, break 'outer), // "monospace" => add!(Monospace, break 'outer),
_ => { _ => {
let mut idents = ~[value.as_slice()]; let mut idents = vec!(value.as_slice());
loop { loop {
match iter.next() { match iter.next() {
Some(&Ident(ref value)) => idents.push(value.as_slice()), Some(&Ident(ref value)) => idents.push(value.as_slice()),