fix indent & some code

This commit is contained in:
patrick kim 2013-12-06 19:04:00 +09:00
parent ab1291f34a
commit 86e2cac8e8
7 changed files with 53 additions and 54 deletions

View file

@ -148,8 +148,7 @@ impl<E> DisplayItem<E> {
font.metrics.clone() font.metrics.clone()
}); });
let origin = text.base.bounds.origin; let origin = text.base.bounds.origin;
let baseline_origin = Point2D(origin.x, origin.y + let baseline_origin = Point2D(origin.x, origin.y + font_metrics.ascent);
font.with_borrow( |font| {font.metrics.ascent} ));
font.with_mut_borrow( |font| { font.with_mut_borrow( |font| {
font.draw_text_into_context(render_context, font.draw_text_into_context(render_context,
&text.text_run, &text.text_run,

View file

@ -195,12 +195,11 @@ impl FontGroup {
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.
let lr = self.fonts[0].with_mut_borrow(|font| { self.fonts[0].with_mut_borrow(|font| {
TextRun::new(font, text.clone(), decoration) TextRun::new(font, text.clone(), decoration)
}); })
lr
} }
} }
@ -321,8 +320,7 @@ impl<'self> Font {
let shaper = Shaper::new(self); let shaper = Shaper::new(self);
self.shaper = Some(shaper); self.shaper = Some(shaper);
let s:&'self Shaper = self.shaper.get_ref(); self.shaper.get_ref()
s
} }
pub fn get_table_for_tag(&self, tag: FontTableTag) -> Option<FontTable> { pub fn get_table_for_tag(&self, tag: FontTableTag) -> Option<FontTable> {

View file

@ -103,7 +103,7 @@ impl<'self> FontContext {
debug!("font cache miss"); debug!("font cache miss");
let result = self.create_font_instance(desc); let result = self.create_font_instance(desc);
match result.clone() { match result.clone() {
Ok(font) => { Ok(ref font) => {
self.instance_cache.insert(desc.clone(), font.clone()); self.instance_cache.insert(desc.clone(), font.clone());
}, _ => {} }, _ => {}
}; };
@ -137,27 +137,31 @@ impl<'self> FontContext {
let result = match self.font_list { let result = match self.font_list {
Some(ref mut fl) => { Some(ref mut fl) => {
let font_in_family = fl.find_font_in_family(&transformed_family_name, style); let font_in_family = fl.find_font_in_family(&transformed_family_name, style);
if font_in_family.is_some() { match font_in_family {
let font_entry = font_in_family.unwrap(); Some(font_entry) => {
let font_id = let font_id =
SelectorPlatformIdentifier(font_entry.handle.face_identifier()); SelectorPlatformIdentifier(font_entry.handle.face_identifier());
let font_desc = FontDescriptor::new((*style).clone(), font_id); let font_desc = FontDescriptor::new((*style).clone(), font_id);
Some(font_desc) Some(font_desc)
} else { },
None None => {
None
}
} }
} }
None => None, None => None,
}; };
if result.is_some() { match result {
found = true; Some(ref result) => {
let instance = self.get_font_by_descriptor(&result.unwrap()); found = true;
let instance = self.get_font_by_descriptor(result);
for font in instance.iter() { fonts.push(font.clone()); } for font in instance.iter() { fonts.push(font.clone()); }
},
_ => {}
} }
if !found { if !found {
debug!("(create font group) didn't find `{:s}`", transformed_family_name); debug!("(create font group) didn't find `{:s}`", transformed_family_name);
} }
@ -166,24 +170,25 @@ impl<'self> FontContext {
if fonts.len() == 0 { if fonts.len() == 0 {
let last_resort = FontList::get_last_resort_font_families(); let last_resort = FontList::get_last_resort_font_families();
for family in last_resort.iter() { for family in last_resort.iter() {
let result = match self.font_list { let font_desc = match self.font_list {
Some(ref fl) => fl.find_font_in_family(*family, style), Some(ref mut font_list) => {
None => None, let font_desc = {
}; let font_entry = font_list.find_font_in_family(family, style);
match font_entry {
for family in last_resort.iter() { Some(v) => {
if self.font_list.is_some() { let font_id =
let font_desc = { SelectorPlatformIdentifier(v.handle.face_identifier());
let font_list = self.font_list.get_mut_ref(); Some(FontDescriptor::new((*style).clone(), font_id))
let font_entry = font_list.find_font_in_family(family, style); },
match font_entry { None => {
Some(v) => { None
let font_id = }
SelectorPlatformIdentifier(v.handle.face_identifier()); }
Some(FontDescriptor::new((*style).clone(), font_id)) };
}, None => { font_desc
None },
} None => {
None
} }
}; };
@ -194,12 +199,11 @@ impl<'self> FontContext {
for font in instance.iter() { for font in instance.iter() {
fonts.push(font.clone()); fonts.push(font.clone());
} }
}, None => { },
} None => { }
} };
} }
} }
assert!(fonts.len() > 0); assert!(fonts.len() > 0);
// TODO(Issue #179): Split FontStyle into specified and used styles // TODO(Issue #179): Split FontStyle into specified and used styles
let used_style = (*style).clone(); let used_style = (*style).clone();

View file

@ -59,7 +59,7 @@ impl<'self> FontList {
// look up canonical name // look up canonical name
if self.family_map.contains_key(family_name) { if self.family_map.contains_key(family_name) {
//FIXME call twice!(ksh8281) //FIXME call twice!(ksh8281)
debug!("FontList: {:s} font family with name={:s}", "Found", family_name.to_str()); debug!("FontList: Found font family with name={:s}", family_name.to_str());
let s: &'self mut FontFamily = self.family_map.get_mut(family_name); let s: &'self mut FontFamily = self.family_map.get_mut(family_name);
// TODO(Issue #192: handle generic font families, like 'serif' and 'sans-serif'. // TODO(Issue #192: handle generic font families, like 'serif' and 'sans-serif'.
// if such family exists, try to match style to a font // if such family exists, try to match style to a font
@ -69,9 +69,8 @@ impl<'self> FontList {
} }
None None
} } else {
else { debug!("FontList: Couldn't find font family with name={:s}", family_name.to_str());
debug!("FontList: {:s} font family with name={:s}", "Couldn't find", family_name.to_str());
None None
} }
} }

View file

@ -52,7 +52,7 @@ impl FontContextHandle {
None => { None => {
let ctx: FT_Library = ptr::null(); let ctx: FT_Library = ptr::null();
let result = FT_Init_FreeType(ptr::to_unsafe_ptr(&ctx)); let result = FT_Init_FreeType(ptr::to_unsafe_ptr(&ctx));
if !result.succeeded() { fail!(); } if !result.succeeded() { fail!("Unable to initialize FreeType library"); }
ft_pointer = Some(ctx); ft_pointer = Some(ctx);
font_context_ref_count = font_context_ref_count + 1; font_context_ref_count = font_context_ref_count + 1;
FontContextHandle { FontContextHandle {
@ -68,7 +68,7 @@ impl FontContextHandleMethods for FontContextHandle {
fn clone(&self) -> FontContextHandle { fn clone(&self) -> FontContextHandle {
unsafe { unsafe {
font_context_ref_count = font_context_ref_count + 1; font_context_ref_count = font_context_ref_count + 1;
FontContextHandle{ FontContextHandle {
ctx: self.ctx.clone() ctx: self.ctx.clone()
} }
} }

View file

@ -955,7 +955,7 @@ impl Box {
self.position.mutate().ptr.size.width = image_width self.position.mutate().ptr.size.width = image_width
} }
ScannedTextBox(_) => { ScannedTextBox(_) => {
// Scanned text boxes will have already had their widths assigned by this point.
} }
UnscannedTextBox(_) => fail!("Unscanned text boxes should have been scanned by now!"), UnscannedTextBox(_) => fail!("Unscanned text boxes should have been scanned by now!"),
} }

View file

@ -188,11 +188,10 @@ 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 {
let font = { fontgroup.with_borrow( |fg| {
fontgroup.with_borrow( |fg| fg.fonts[0].clone()) fg.fonts[0].with_mut_borrow( |font| {
}; Some(@TextRun::new(font, run_str.clone(), decoration))
font.with_mut_borrow( |font| { })
Some(@TextRun::new(font, run_str.clone(), decoration))
}) })
} else { } else {
None None