Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 45 additions & 13 deletions src/font_family.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,54 +26,86 @@ impl FontFamily {
(*self.native.get()).as_raw()
}

#[deprecated(note = "Use `family_name` instead.")]
pub fn name(&self) -> String {
self.family_name().unwrap()
}

pub fn family_name(&self) -> Result<String, HRESULT> {
let mut family_names: *mut IDWriteLocalizedStrings = ptr::null_mut();
unsafe {
let mut family_names: *mut IDWriteLocalizedStrings = ptr::null_mut();
let hr = (*self.native.get()).GetFamilyNames(&mut family_names);
assert!(hr == 0);

get_locale_string(&mut ComPtr::from_raw(family_names))
if hr != 0 {
return Err(hr);
}
Ok(get_locale_string(&mut ComPtr::from_raw(family_names)))
}
}

#[deprecated(note = "Use `first_matching_font` instead.")]
pub fn get_first_matching_font(
&self,
weight: FontWeight,
stretch: FontStretch,
style: FontStyle,
) -> Font {
self.first_matching_font(weight, stretch, style).unwrap()
}

pub fn first_matching_font(
&self,
weight: FontWeight,
stretch: FontStretch,
style: FontStyle,
) -> Result<Font, HRESULT> {
let mut font: *mut IDWriteFont = ptr::null_mut();
unsafe {
let mut font: *mut IDWriteFont = ptr::null_mut();
let hr = (*self.native.get()).GetFirstMatchingFont(
weight.t(),
stretch.t(),
style.t(),
&mut font,
);
assert!(hr == 0);
Font::take(ComPtr::from_raw(font))
if hr != 0 {
return Err(hr);
}
Ok(Font::take(ComPtr::from_raw(font)))
}
}

#[deprecated(note = "Use `font_collection` instead.")]
pub fn get_font_collection(&self) -> FontCollection {
self.font_collection().unwrap()
}

pub fn font_collection(&self) -> Result<FontCollection, HRESULT> {
let mut collection: *mut IDWriteFontCollection = ptr::null_mut();
unsafe {
let mut collection: *mut IDWriteFontCollection = ptr::null_mut();
let hr = (*self.native.get()).GetFontCollection(&mut collection);
assert!(hr == 0);
FontCollection::take(ComPtr::from_raw(collection))
if hr != 0 {
return Err(hr);
}
Ok(FontCollection::take(ComPtr::from_raw(collection)))
}
}

pub fn get_font_count(&self) -> u32 {
unsafe { (*self.native.get()).GetFontCount() }
}

#[deprecated(note = "Use `font` instead.")]
pub fn get_font(&self, index: u32) -> Font {
self.font(index).unwrap()
}

pub fn font(&self, index: u32) -> Result<Font, HRESULT> {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little unsure about the name font for this method. Any suggestions? font_from_index maybe?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

font_at_index or font_from_index both sound good to me.

let mut font: *mut IDWriteFont = ptr::null_mut();
unsafe {
let mut font: *mut IDWriteFont = ptr::null_mut();
let hr = (*self.native.get()).GetFont(index, &mut font);
assert!(hr == 0);
Font::take(ComPtr::from_raw(font))
if hr != 0 {
return Err(hr);
}
Ok(Font::take(ComPtr::from_raw(font)))
}
}
}