From ab22f7ac45681e253c1917d07324fdca23e31e85 Mon Sep 17 00:00:00 2001 From: Yash Joshi <77540753+yashjoshi-dotcom@users.noreply.github.com> Date: Thu, 28 Aug 2025 11:12:24 +0530 Subject: [PATCH] core-text: Add has_table method wrapping CTFontHasTable (#739) * core-text:Add has_table method wrapping CTFontHasTable * Fix Build by make lifetimes explicit * fix clippy lints in array.rs and propertylist.rs --- core-foundation/src/array.rs | 2 +- core-foundation/src/propertylist.rs | 2 +- core-text/src/font.rs | 6 ++++++ core-text/src/run.rs | 6 +++--- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/core-foundation/src/array.rs b/core-foundation/src/array.rs index 6864d40..1b3cc7e 100644 --- a/core-foundation/src/array.rs +++ b/core-foundation/src/array.rs @@ -242,7 +242,7 @@ mod tests { use crate::string::{CFString, CFStringRef}; let cf_string = CFString::from_static_string("alongerstring"); - let array: CFArray = CFArray::from_CFTypes(&[cf_string.clone()]).into_untyped(); + let array: CFArray = CFArray::from_CFTypes(std::slice::from_ref(&cf_string)).into_untyped(); let cf_strings = array .iter() diff --git a/core-foundation/src/propertylist.rs b/core-foundation/src/propertylist.rs index 45eac8c..1f22c26 100644 --- a/core-foundation/src/propertylist.rs +++ b/core-foundation/src/propertylist.rs @@ -96,7 +96,7 @@ impl CFPropertyListSubClass for crate::boolean::CFBoolean {} impl CFPropertyListSubClass for crate::number::CFNumber {} declare_TCFType! { - /// A CFPropertyList struct. This is superclass to [`CFData`], [`CFString`], [`CFArray`], + /// A `CFPropertyList` struct. This is superclass to [`CFData`], [`CFString`], [`CFArray`], /// [`CFDictionary`], [`CFDate`], [`CFBoolean`], and [`CFNumber`]. /// /// This superclass type does not have its own `CFTypeID`, instead each instance has the `CFTypeID` diff --git a/core-text/src/font.rs b/core-text/src/font.rs index 4b9a815..4f2dca2 100644 --- a/core-text/src/font.rs +++ b/core-text/src/font.rs @@ -438,6 +438,10 @@ impl CTFont { CTFontGetVerticalTranslationsForGlyphs(self.0, orientation, glyphs, translations, count) } + pub fn has_table(&self, tag: u32) -> bool { + unsafe { CTFontHasTable(self.0, tag as CTFontTableTag) } + } + pub fn get_font_table(&self, tag: u32) -> Option { unsafe { let result = CTFontCopyTable( @@ -805,6 +809,8 @@ extern "C" { ) -> CFDataRef; fn CTFontGetTypeID() -> CFTypeID; + + fn CTFontHasTable(font: CTFontRef, table: CTFontTableTag) -> bool; } #[test] diff --git a/core-text/src/run.rs b/core-text/src/run.rs index 07407ba..f06bdb3 100644 --- a/core-text/src/run.rs +++ b/core-text/src/run.rs @@ -44,7 +44,7 @@ impl CTRun { unsafe { CTRunGetGlyphCount(self.0) } } - pub fn glyphs(&self) -> Cow<[CGGlyph]> { + pub fn glyphs(&self) -> Cow<'_, [CGGlyph]> { unsafe { // CTRunGetGlyphsPtr can return null under some not understood circumstances. // If it does the Apple documentation tells us to allocate our own buffer and call @@ -64,7 +64,7 @@ impl CTRun { } } - pub fn positions(&self) -> Cow<[CGPoint]> { + pub fn positions(&self) -> Cow<'_, [CGPoint]> { unsafe { // CTRunGetPositionsPtr can return null under some not understood circumstances. // If it does the Apple documentation tells us to allocate our own buffer and call @@ -112,7 +112,7 @@ impl CTRun { } } - pub fn string_indices(&self) -> Cow<[CFIndex]> { + pub fn string_indices(&self) -> Cow<'_, [CFIndex]> { unsafe { // CTRunGetStringIndicesPtr can return null under some not understood circumstances. // If it does the Apple documentation tells us to allocate our own buffer and call