rust-mobile / ndk

Rust bindings to the Android NDK
Apache License 2.0
1.14k stars 112 forks source link

ndk: Add bindings for AFont #397

Closed paxbun closed 1 year ago

paxbun commented 1 year ago

This PR provides bindings for AFont, AFontMatcher, and ASystemFontIterator and some helper structs for the better abstraction of some parts of the OpenType specification.

Example:

for font in ndk::font::SystemFontIterator::new().unwrap() {
  log::debug!("Font: {}", font.path().display());
  for idx in 0..font.axis_count() {
    log::debug!("  Axis {idx} ({}): {}", font.axis_tag_at(idx), font.axis_value_at(idx));
  }
  log::debug!("  Collection Idx: {}", font.collection_index());
  log::debug!("  Locale: {:?}", font.locale());
  log::debug!("  Weight: {}", font.weight());
  log::debug!("  Is Italic: {}", font.is_italic());
}

Result (Tested on Galaxy Tab S8): image

paxbun commented 1 year ago

TODOs

MarijnS95 commented 1 year ago

Nice! I'll pull in the bindings regeneration via #370, and then have a look at this.

MarijnS95 commented 1 year ago

@paxbun just a quick heads-up that I haven't been able to catch up to this before leaving for a while. I hope that's not a problem and I'll do my very best to pick this up in about 2 weekes, apologies for all the delays :crossed_fingers:

MarijnS95 commented 1 year ago

By the way, a friendly request to not reply Fixed! to every review comment in what is hopefully the last round of changes so that we can merge this in. My notification inbox is filled with those messages while lacking context, and GitHub uses the "Resolve conversation" button for that.

MarijnS95 commented 1 year ago

@paxbun any updates or should I apply the remaining comments/remarks/suggestions and merge this? I'd like to get the "breaking" changes imposed by the ndk-sys regen in and publish all these crates soon-ish™.

paxbun commented 1 year ago

@MarijnS95 I think I mostly applied your suggestion, and I also checked whether there are any ffi::* functions not wrapped. I also added constructors that constly panic to AxisTag.

MarijnS95 commented 1 year ago

Note that I reported the header issues at https://github.com/android/ndk/issues/1920, because surface_control.h (which I need and am writing a wrapper for) has the same (and many more C++-like) issues.

Hopefully we can drop the workarounds when upstream picks them up.

paxbun commented 1 year ago

I applied all the suggestions you mentioned! (except for the axis tag one)