Skip to content

Commit

Permalink
fix indent & some code
Browse files Browse the repository at this point in the history
  • Loading branch information
ksh8281 committed Dec 7, 2013
1 parent ab1291f commit 86e2cac
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 54 deletions.
3 changes: 1 addition & 2 deletions src/components/gfx/display_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ impl<E> DisplayItem<E> {
font.metrics.clone()
});
let origin = text.base.bounds.origin;
let baseline_origin = Point2D(origin.x, origin.y +
font.with_borrow( |font| {font.metrics.ascent} ));
let baseline_origin = Point2D(origin.x, origin.y + font_metrics.ascent);
font.with_mut_borrow( |font| {
font.draw_text_into_context(render_context,
&text.text_run,
Expand Down
10 changes: 4 additions & 6 deletions src/components/gfx/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,11 @@ impl FontGroup {

pub fn create_textrun(&self, text: ~str, decoration: text_decoration::T) -> TextRun {
assert!(self.fonts.len() > 0);

// 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)
});
lr
})
}
}

Expand Down Expand Up @@ -321,8 +320,7 @@ impl<'self> Font {

let shaper = Shaper::new(self);
self.shaper = Some(shaper);
let s:&'self Shaper = self.shaper.get_ref();
s
self.shaper.get_ref()
}

pub fn get_table_for_tag(&self, tag: FontTableTag) -> Option<FontTable> {
Expand Down
72 changes: 38 additions & 34 deletions src/components/gfx/font_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl<'self> FontContext {
debug!("font cache miss");
let result = self.create_font_instance(desc);
match result.clone() {
Ok(font) => {
Ok(ref font) => {
self.instance_cache.insert(desc.clone(), font.clone());
}, _ => {}
};
Expand Down Expand Up @@ -137,27 +137,31 @@ impl<'self> FontContext {
let result = match self.font_list {
Some(ref mut fl) => {
let font_in_family = fl.find_font_in_family(&transformed_family_name, style);
if font_in_family.is_some() {
let font_entry = font_in_family.unwrap();
let font_id =
SelectorPlatformIdentifier(font_entry.handle.face_identifier());
match font_in_family {
Some(font_entry) => {
let font_id =
SelectorPlatformIdentifier(font_entry.handle.face_identifier());
let font_desc = FontDescriptor::new((*style).clone(), font_id);
Some(font_desc)
} else {
None
},
None => {
None
}
}
}
None => None,
};

if result.is_some() {
found = true;
let instance = self.get_font_by_descriptor(&result.unwrap());
match result {
Some(ref result) => {
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 {
debug!("(create font group) didn't find `{:s}`", transformed_family_name);
}
Expand All @@ -166,24 +170,25 @@ impl<'self> FontContext {
if fonts.len() == 0 {
let last_resort = FontList::get_last_resort_font_families();
for family in last_resort.iter() {
let result = match self.font_list {
Some(ref fl) => fl.find_font_in_family(*family, style),
None => None,
};

for family in last_resort.iter() {
if self.font_list.is_some() {
let font_desc = {
let font_list = self.font_list.get_mut_ref();
let font_entry = font_list.find_font_in_family(family, style);
match font_entry {
Some(v) => {
let font_id =
SelectorPlatformIdentifier(v.handle.face_identifier());
Some(FontDescriptor::new((*style).clone(), font_id))
}, None => {
None
}
let font_desc = match self.font_list {
Some(ref mut font_list) => {
let font_desc = {
let font_entry = font_list.find_font_in_family(family, style);
match font_entry {
Some(v) => {
let font_id =
SelectorPlatformIdentifier(v.handle.face_identifier());
Some(FontDescriptor::new((*style).clone(), font_id))
},
None => {
None
}
}
};
font_desc
},
None => {
None
}
};

Expand All @@ -194,12 +199,11 @@ impl<'self> FontContext {
for font in instance.iter() {
fonts.push(font.clone());
}
}, None => {
}
}
},
None => { }
};
}
}

assert!(fonts.len() > 0);
// TODO(Issue #179): Split FontStyle into specified and used styles
let used_style = (*style).clone();
Expand Down
7 changes: 3 additions & 4 deletions src/components/gfx/font_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl<'self> FontList {
// look up canonical name
if self.family_map.contains_key(family_name) {
//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);
// TODO(Issue #192: handle generic font families, like 'serif' and 'sans-serif'.
// if such family exists, try to match style to a font
Expand All @@ -69,9 +69,8 @@ impl<'self> FontList {
}

None
}
else {
debug!("FontList: {:s} font family with name={:s}", "Couldn't find", family_name.to_str());
} else {
debug!("FontList: Couldn't find font family with name={:s}", family_name.to_str());
None
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/gfx/platform/linux/font_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl FontContextHandle {
None => {
let ctx: FT_Library = ptr::null();
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);
font_context_ref_count = font_context_ref_count + 1;
FontContextHandle {
Expand All @@ -68,7 +68,7 @@ impl FontContextHandleMethods for FontContextHandle {
fn clone(&self) -> FontContextHandle {
unsafe {
font_context_ref_count = font_context_ref_count + 1;
FontContextHandle{
FontContextHandle {
ctx: self.ctx.clone()
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/main/layout/box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ impl Box {
self.position.mutate().ptr.size.width = image_width
}
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!"),
}
Expand Down
9 changes: 4 additions & 5 deletions src/components/main/layout/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,10 @@ impl TextRunScanner {
// sequence. If no clump takes ownership, however, it will leak.
let clump = self.clump;
let run = if clump.length() != 0 && run_str.len() > 0 {
let font = {
fontgroup.with_borrow( |fg| fg.fonts[0].clone())
};
font.with_mut_borrow( |font| {
Some(@TextRun::new(font, run_str.clone(), decoration))
fontgroup.with_borrow( |fg| {
fg.fonts[0].with_mut_borrow( |font| {
Some(@TextRun::new(font, run_str.clone(), decoration))
})
})
} else {
None
Expand Down

0 comments on commit 86e2cac

Please sign in to comment.