Format the rest of gfx #21373

This commit is contained in:
kingdido999 2018-09-08 08:05:42 +08:00
parent f7630dad87
commit 3a3c4b8c8e
8 changed files with 502 additions and 401 deletions

View file

@ -26,7 +26,6 @@ pub struct FontTemplateDescriptor {
pub style: FontStyle,
}
/// FontTemplateDescriptor contains floats, which are not Eq because of NaN. However,
/// we know they will never be NaN, so we can manually implement Eq.
impl Eq for FontTemplateDescriptor {}
@ -41,14 +40,9 @@ fn style_to_number(s: &FontStyle) -> f32 {
}
}
impl FontTemplateDescriptor {
#[inline]
pub fn new(
weight: FontWeight,
stretch: FontStretch,
style: FontStyle,
) -> Self {
pub fn new(weight: FontWeight, stretch: FontStretch, style: FontStyle) -> Self {
Self {
weight,
stretch,
@ -138,7 +132,10 @@ impl FontTemplate {
}
/// Get the descriptor. Returns `None` when instantiating the data fails.
pub fn descriptor(&mut self, font_context: &FontContextHandle) -> Option<FontTemplateDescriptor> {
pub fn descriptor(
&mut self,
font_context: &FontContextHandle,
) -> Option<FontTemplateDescriptor> {
// The font template data can be unloaded when nothing is referencing
// it (via the Weak reference to the Arc above). However, if we have
// already loaded a font, store the style information about it separately,
@ -147,18 +144,22 @@ impl FontTemplate {
self.descriptor.or_else(|| {
if self.instantiate(font_context).is_err() {
return None
return None;
};
Some(self.descriptor.expect("Instantiation succeeded but no descriptor?"))
Some(
self.descriptor
.expect("Instantiation succeeded but no descriptor?"),
)
})
}
/// Get the data for creating a font if it matches a given descriptor.
pub fn data_for_descriptor(&mut self,
fctx: &FontContextHandle,
requested_desc: &FontTemplateDescriptor)
-> Option<Arc<FontTemplateData>> {
pub fn data_for_descriptor(
&mut self,
fctx: &FontContextHandle,
requested_desc: &FontTemplateDescriptor,
) -> Option<Arc<FontTemplateData>> {
self.descriptor(&fctx).and_then(|descriptor| {
if *requested_desc == descriptor {
self.data().ok()
@ -176,21 +177,20 @@ impl FontTemplate {
requested_descriptor: &FontTemplateDescriptor,
) -> Option<(Arc<FontTemplateData>, f32)> {
self.descriptor(&font_context).and_then(|descriptor| {
self.data().ok().map(|data| {
(data, descriptor.distance_from(requested_descriptor))
})
self.data()
.ok()
.map(|data| (data, descriptor.distance_from(requested_descriptor)))
})
}
fn instantiate(&mut self, font_context: &FontContextHandle) -> Result<(), ()> {
if !self.is_valid {
return Err(())
return Err(());
}
let data = self.data().map_err(|_| ())?;
let handle: Result<FontHandle, ()> = FontHandleMethods::new_from_template(font_context,
data,
None);
let handle: Result<FontHandle, ()> =
FontHandleMethods::new_from_template(font_context, data, None);
self.is_valid = handle.is_ok();
let handle = handle?;
self.descriptor = Some(FontTemplateDescriptor::new(
@ -220,7 +220,7 @@ impl FontTemplate {
};
if let Some(data) = maybe_data {
return Ok(data)
return Ok(data);
}
assert!(self.strong_ref.is_none());