Skip to content

Use more objc2 framework crates #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

madsmtm
Copy link
Contributor

@madsmtm madsmtm commented May 12, 2025

Remove a few unnecessary dependencies, update objc2, and use more of the framework crates from that.

Motivation: The core-foundation, core-text and core-graphics crates are being deprecated, see servo/core-foundation-rs#729.

It'd be nice if we could get a release after this.

madsmtm added 3 commits May 12, 2025 16:54
Use objc2-core-foundation, objc2-core-text and objc2-core-graphics.
Copy link
Member

@chrisduerr chrisduerr left a comment

Choose a reason for hiding this comment

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

Just out of curiosity, but did you write this patch entirely by hand?

ct_descriptor: desc,
}
fn new(desc: &CTFontDescriptor) -> Descriptor {
let style_name = unsafe { desc.attribute(kCTFontStyleNameAttribute) }
Copy link
Member

Choose a reason for hiding this comment

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

This is a rather unusual unsafe usage, I think I'd prefer it being assigned to its own variable over chaining off its scope block.

Also what exactly makes this unsafe? I'd assume it's due to the parameter potentially not existing? Might be a good idea to have a safety comment on it.

Comment on lines +84 to +86
let name = CFString::from_static_str("Apple Symbols");
let apple_symbols = unsafe { CTFont::with_name(&name, size, ptr::null_mut()) };
fallbacks.push(Font { ct_font: apple_symbols, fallbacks: Vec::new() });
Copy link
Member

Choose a reason for hiding this comment

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

What if the font doesn't exist? It looks like previously we were handling failure here.

let list = ct_cascade_list_for_languages(ct_font, &langarr);
let list =
unsafe { ct_font.default_cascade_list_for_languages(Some(langarr.as_opaque())) }.unwrap();
// CFArray of CTFontDescriptorRef.
Copy link
Member

Choose a reason for hiding this comment

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

Not really necessary it's already obvious in the signature.

Comment on lines +230 to +232
let Some(attr_val) = (unsafe { fontdesc.attribute(kCTFontEnabledAttribute) }) else {
return false;
};
Copy link
Member

Choose a reason for hiding this comment

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

No let else. Please use a match statement.

Comment on lines +234 to +236
let Ok(attr_val) = attr_val.downcast::<CFNumber>() else {
return false;
};
Copy link
Member

Choose a reason for hiding this comment

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

Again, please don't use let else.

if let Some(descriptors) = descriptors {
for descriptor in descriptors.iter() {
out.push(Descriptor::new(descriptor.clone()));
// CFArray of CTFontDescriptorRef (i think).
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// CFArray of CTFontDescriptorRef (i think).

Was never really a good comment. I think? Really? 😄

}
}

out
}

pub fn create_for_family(family: &str) -> Option<CFRetained<CTFontCollection>> {
Copy link
Member

Choose a reason for hiding this comment

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

A doc comment would go a long way on this function.

Comment on lines +391 to +399
let glyphs = [glyph_index as CGGlyph];
let bounds = unsafe {
self.ct_font.bounding_rects_for_glyphs(
CTFontOrientation::Default,
NonNull::from(&glyphs[0]),
ptr::null_mut(),
1,
)
};
Copy link
Member

Choose a reason for hiding this comment

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

Sorry but what's the point of creating an array just to immediately go and only retrieve its first element?

Comment on lines +464 to +465
NonNull::from(&[glyph_index as CGGlyph][0]),
NonNull::from(&[rasterization_origin][0]),
Copy link
Member

Choose a reason for hiding this comment

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

Again, why are we creating arrays just to immediately access their only element?

Comment on lines +74 to +85
.field(
"render_mode",
&match self.render_mode {
freetype::RenderMode::Normal => "Normal",
freetype::RenderMode::Light => "Light",
freetype::RenderMode::Mono => "Mono",
freetype::RenderMode::Lcd => "Lcd",
freetype::RenderMode::LcdV => "LcdV",
freetype::RenderMode::Max => "Max",
freetype::RenderMode::Sdf => "Sdf",
},
)
Copy link
Member

Choose a reason for hiding this comment

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

Did cargo fmt change this for you? It's certainly not an improvement and I'm not sure why it would have changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants