Skip to content

Commit 7a267bc

Browse files
author
bors-servo
authored
Auto merge of #58 - algesten:font_path, r=jdm
font_path may be null Given PR #57, we can quite easily get `CTFontDescriptor` that returns `null` for the `font_path`. In the default font chains I've seen at least two fonts that are part of the chains but we can't get the `font_path`. Interestingly the font names and family names are prefixed with a `.` as if to indicate they are internal: ".Apple Symbols Fallback", ".Noto Sans Universal", This is a breaking change, so may be undesirable, but I think it requires discussion. Here's the full fallback list for `Menlo` and language `en`. ``` "Monaco", ".Apple Symbols Fallback", "Lucida Grande", "Courier New", "Ayuthaya", "Kailasa", "PingFang SC", "PingFang TC", "Hiragino Sans", "Hiragino Sans GB", "Apple SD Gothic Neo", "PingFang HK", "Kohinoor Bangla", "Kohinoor Devanagari", "Gujarati Sangam MN", "Gurmukhi MN", "Kannada Sangam MN", "Khmer Sangam MN", "Lao Sangam MN", "Malayalam Sangam MN", "Myanmar Sangam MN", "Oriya Sangam MN", "Sinhala Sangam MN", "Tamil Sangam MN", "Kohinoor Telugu", "Mshtakan", "Euphemia UCAS", "Plantagenet Cherokee", ".Noto Sans Universal", "Apple Color Emoji" ``` <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/core-text-rs/58) <!-- Reviewable:end -->
2 parents f527a1f + 2e97ea2 commit 7a267bc

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/font_descriptor.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,15 +271,17 @@ impl CTFontDescriptor {
271271
value.expect("A font must have a non-null display name.")
272272
}
273273

274-
pub fn font_path(&self) -> String {
274+
pub fn font_path(&self) -> Option<String> {
275275
unsafe {
276276
let value = CTFontDescriptorCopyAttribute(self.obj, kCTFontURLAttribute);
277-
assert!(!value.is_null());
277+
if (value.is_null()) {
278+
return None;
279+
}
278280

279281
let value: CFType = TCFType::wrap_under_get_rule(value);
280282
assert!(value.instance_of::<CFURLRef,CFURL>());
281283
let url: CFURL = TCFType::wrap_under_get_rule(mem::transmute(value.as_CFTypeRef()));
282-
format!("{:?}", url)
284+
Some(format!("{:?}", url))
283285
}
284286
}
285287
}
@@ -297,7 +299,7 @@ pub fn debug_descriptor(desc: &CTFontDescriptor) {
297299
println!("name: {}", desc.font_name());
298300
println!("style: {}", desc.style_name());
299301
println!("display: {}", desc.display_name());
300-
println!("path: {}", desc.font_path());
302+
println!("path: {:?}", desc.font_path());
301303
desc.show();
302304
}
303305

0 commit comments

Comments
 (0)