objc2_app_kit/generated/
NSFont.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6#[cfg(feature = "objc2-core-foundation")]
7use objc2_core_foundation::*;
8#[cfg(feature = "objc2-core-graphics")]
9#[cfg(target_vendor = "apple")]
10use objc2_core_graphics::*;
11#[cfg(feature = "objc2-core-text")]
12#[cfg(target_vendor = "apple")]
13use objc2_core_text::*;
14use objc2_foundation::*;
15
16use crate::*;
17
18extern "C" {
19    /// ******* Font Matrix ********
20    ///
21    /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nsfontidentitymatrix?language=objc)
22    #[cfg(feature = "objc2-core-foundation")]
23    pub static NSFontIdentityMatrix: NonNull<CGFloat>;
24}
25
26extern_class!(
27    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsfont?language=objc)
28    #[unsafe(super(NSObject))]
29    #[derive(Debug, PartialEq, Eq, Hash)]
30    pub struct NSFont;
31);
32
33#[cfg(feature = "objc2-core-text")]
34#[cfg(target_vendor = "apple")]
35impl AsRef<NSFont> for CTFont {
36    #[inline]
37    fn as_ref(&self) -> &NSFont {
38        unsafe { &*((self as *const Self).cast()) }
39    }
40}
41
42#[cfg(feature = "objc2-core-text")]
43#[cfg(target_vendor = "apple")]
44impl AsRef<CTFont> for NSFont {
45    #[inline]
46    fn as_ref(&self) -> &CTFont {
47        unsafe { &*((self as *const Self).cast()) }
48    }
49}
50
51extern_conformance!(
52    unsafe impl NSCoding for NSFont {}
53);
54
55extern_conformance!(
56    unsafe impl NSCopying for NSFont {}
57);
58
59unsafe impl CopyingHelper for NSFont {
60    type Result = Self;
61}
62
63extern_conformance!(
64    unsafe impl NSObjectProtocol for NSFont {}
65);
66
67extern_conformance!(
68    unsafe impl NSSecureCoding for NSFont {}
69);
70
71impl NSFont {
72    extern_methods!(
73        #[cfg(feature = "objc2-core-foundation")]
74        /// ******* Factory ********
75        #[unsafe(method(fontWithName:size:))]
76        #[unsafe(method_family = none)]
77        pub fn fontWithName_size(
78            font_name: &NSString,
79            font_size: CGFloat,
80        ) -> Option<Retained<NSFont>>;
81
82        #[cfg(feature = "objc2-core-foundation")]
83        /// # Safety
84        ///
85        /// `font_matrix` must be a valid pointer.
86        #[unsafe(method(fontWithName:matrix:))]
87        #[unsafe(method_family = none)]
88        pub unsafe fn fontWithName_matrix(
89            font_name: &NSString,
90            font_matrix: NonNull<CGFloat>,
91        ) -> Option<Retained<NSFont>>;
92
93        #[cfg(all(feature = "NSFontDescriptor", feature = "objc2-core-foundation"))]
94        #[unsafe(method(fontWithDescriptor:size:))]
95        #[unsafe(method_family = none)]
96        pub fn fontWithDescriptor_size(
97            font_descriptor: &NSFontDescriptor,
98            font_size: CGFloat,
99        ) -> Option<Retained<NSFont>>;
100
101        #[cfg(feature = "NSFontDescriptor")]
102        #[unsafe(method(fontWithDescriptor:textTransform:))]
103        #[unsafe(method_family = none)]
104        pub fn fontWithDescriptor_textTransform(
105            font_descriptor: &NSFontDescriptor,
106            text_transform: Option<&NSAffineTransform>,
107        ) -> Option<Retained<NSFont>>;
108
109        #[cfg(feature = "objc2-core-foundation")]
110        /// ******* Meta Font ********
111        #[unsafe(method(userFontOfSize:))]
112        #[unsafe(method_family = none)]
113        pub fn userFontOfSize(font_size: CGFloat) -> Option<Retained<NSFont>>;
114
115        #[cfg(feature = "objc2-core-foundation")]
116        #[unsafe(method(userFixedPitchFontOfSize:))]
117        #[unsafe(method_family = none)]
118        pub fn userFixedPitchFontOfSize(font_size: CGFloat) -> Option<Retained<NSFont>>;
119
120        #[unsafe(method(setUserFont:))]
121        #[unsafe(method_family = none)]
122        pub fn setUserFont(font: Option<&NSFont>);
123
124        #[unsafe(method(setUserFixedPitchFont:))]
125        #[unsafe(method_family = none)]
126        pub fn setUserFixedPitchFont(font: Option<&NSFont>);
127
128        #[cfg(feature = "objc2-core-foundation")]
129        #[unsafe(method(systemFontOfSize:))]
130        #[unsafe(method_family = none)]
131        pub fn systemFontOfSize(font_size: CGFloat) -> Retained<NSFont>;
132
133        #[cfg(feature = "objc2-core-foundation")]
134        #[unsafe(method(boldSystemFontOfSize:))]
135        #[unsafe(method_family = none)]
136        pub fn boldSystemFontOfSize(font_size: CGFloat) -> Retained<NSFont>;
137
138        #[cfg(feature = "objc2-core-foundation")]
139        #[unsafe(method(labelFontOfSize:))]
140        #[unsafe(method_family = none)]
141        pub fn labelFontOfSize(font_size: CGFloat) -> Retained<NSFont>;
142
143        #[cfg(feature = "objc2-core-foundation")]
144        #[unsafe(method(titleBarFontOfSize:))]
145        #[unsafe(method_family = none)]
146        pub fn titleBarFontOfSize(font_size: CGFloat) -> Retained<NSFont>;
147
148        #[cfg(feature = "objc2-core-foundation")]
149        #[unsafe(method(menuFontOfSize:))]
150        #[unsafe(method_family = none)]
151        pub fn menuFontOfSize(font_size: CGFloat) -> Retained<NSFont>;
152
153        #[cfg(feature = "objc2-core-foundation")]
154        #[unsafe(method(menuBarFontOfSize:))]
155        #[unsafe(method_family = none)]
156        pub fn menuBarFontOfSize(font_size: CGFloat) -> Retained<NSFont>;
157
158        #[cfg(feature = "objc2-core-foundation")]
159        #[unsafe(method(messageFontOfSize:))]
160        #[unsafe(method_family = none)]
161        pub fn messageFontOfSize(font_size: CGFloat) -> Retained<NSFont>;
162
163        #[cfg(feature = "objc2-core-foundation")]
164        #[unsafe(method(paletteFontOfSize:))]
165        #[unsafe(method_family = none)]
166        pub fn paletteFontOfSize(font_size: CGFloat) -> Retained<NSFont>;
167
168        #[cfg(feature = "objc2-core-foundation")]
169        #[unsafe(method(toolTipsFontOfSize:))]
170        #[unsafe(method_family = none)]
171        pub fn toolTipsFontOfSize(font_size: CGFloat) -> Retained<NSFont>;
172
173        #[cfg(feature = "objc2-core-foundation")]
174        #[unsafe(method(controlContentFontOfSize:))]
175        #[unsafe(method_family = none)]
176        pub fn controlContentFontOfSize(font_size: CGFloat) -> Retained<NSFont>;
177
178        #[cfg(all(feature = "NSFontDescriptor", feature = "objc2-core-foundation"))]
179        #[unsafe(method(systemFontOfSize:weight:))]
180        #[unsafe(method_family = none)]
181        pub fn systemFontOfSize_weight(
182            font_size: CGFloat,
183            weight: NSFontWeight,
184        ) -> Retained<NSFont>;
185
186        #[cfg(all(feature = "NSFontDescriptor", feature = "objc2-core-foundation"))]
187        #[unsafe(method(monospacedDigitSystemFontOfSize:weight:))]
188        #[unsafe(method_family = none)]
189        pub fn monospacedDigitSystemFontOfSize_weight(
190            font_size: CGFloat,
191            weight: NSFontWeight,
192        ) -> Retained<NSFont>;
193
194        #[cfg(all(feature = "NSFontDescriptor", feature = "objc2-core-foundation"))]
195        #[unsafe(method(systemFontOfSize:weight:width:))]
196        #[unsafe(method_family = none)]
197        pub fn systemFontOfSize_weight_width(
198            font_size: CGFloat,
199            weight: NSFontWeight,
200            width: NSFontWidth,
201        ) -> Retained<NSFont>;
202
203        #[cfg(all(feature = "NSFontDescriptor", feature = "objc2-core-foundation"))]
204        #[unsafe(method(monospacedSystemFontOfSize:weight:))]
205        #[unsafe(method_family = none)]
206        pub fn monospacedSystemFontOfSize_weight(
207            font_size: CGFloat,
208            weight: NSFontWeight,
209        ) -> Retained<NSFont>;
210
211        #[cfg(feature = "objc2-core-foundation")]
212        #[unsafe(method(fontWithSize:))]
213        #[unsafe(method_family = none)]
214        pub fn fontWithSize(&self, font_size: CGFloat) -> Retained<NSFont>;
215
216        #[cfg(feature = "objc2-core-foundation")]
217        #[unsafe(method(systemFontSize))]
218        #[unsafe(method_family = none)]
219        pub fn systemFontSize() -> CGFloat;
220
221        #[cfg(feature = "objc2-core-foundation")]
222        #[unsafe(method(smallSystemFontSize))]
223        #[unsafe(method_family = none)]
224        pub fn smallSystemFontSize() -> CGFloat;
225
226        #[cfg(feature = "objc2-core-foundation")]
227        #[unsafe(method(labelFontSize))]
228        #[unsafe(method_family = none)]
229        pub fn labelFontSize() -> CGFloat;
230
231        #[cfg(all(feature = "NSCell", feature = "objc2-core-foundation"))]
232        #[unsafe(method(systemFontSizeForControlSize:))]
233        #[unsafe(method_family = none)]
234        pub fn systemFontSizeForControlSize(control_size: NSControlSize) -> CGFloat;
235
236        /// ******* Core font attribute ********
237        #[unsafe(method(fontName))]
238        #[unsafe(method_family = none)]
239        pub fn fontName(&self) -> Retained<NSString>;
240
241        #[cfg(feature = "objc2-core-foundation")]
242        #[unsafe(method(pointSize))]
243        #[unsafe(method_family = none)]
244        pub fn pointSize(&self) -> CGFloat;
245
246        #[cfg(feature = "objc2-core-foundation")]
247        #[unsafe(method(matrix))]
248        #[unsafe(method_family = none)]
249        pub fn matrix(&self) -> NonNull<CGFloat>;
250
251        #[unsafe(method(familyName))]
252        #[unsafe(method_family = none)]
253        pub fn familyName(&self) -> Option<Retained<NSString>>;
254
255        #[unsafe(method(displayName))]
256        #[unsafe(method_family = none)]
257        pub fn displayName(&self) -> Option<Retained<NSString>>;
258
259        #[cfg(feature = "NSFontDescriptor")]
260        #[unsafe(method(fontDescriptor))]
261        #[unsafe(method_family = none)]
262        pub fn fontDescriptor(&self) -> Retained<NSFontDescriptor>;
263
264        #[unsafe(method(textTransform))]
265        #[unsafe(method_family = none)]
266        pub fn textTransform(&self) -> Retained<NSAffineTransform>;
267
268        /// ******* Glyph coverage ********
269        #[unsafe(method(numberOfGlyphs))]
270        #[unsafe(method_family = none)]
271        pub fn numberOfGlyphs(&self) -> NSUInteger;
272
273        #[unsafe(method(mostCompatibleStringEncoding))]
274        #[unsafe(method_family = none)]
275        pub fn mostCompatibleStringEncoding(&self) -> NSStringEncoding;
276
277        #[unsafe(method(coveredCharacterSet))]
278        #[unsafe(method_family = none)]
279        pub fn coveredCharacterSet(&self) -> Retained<NSCharacterSet>;
280
281        #[unsafe(method(boundingRectForFont))]
282        #[unsafe(method_family = none)]
283        pub fn boundingRectForFont(&self) -> NSRect;
284
285        #[unsafe(method(maximumAdvancement))]
286        #[unsafe(method_family = none)]
287        pub fn maximumAdvancement(&self) -> NSSize;
288
289        #[cfg(feature = "objc2-core-foundation")]
290        #[unsafe(method(ascender))]
291        #[unsafe(method_family = none)]
292        pub fn ascender(&self) -> CGFloat;
293
294        #[cfg(feature = "objc2-core-foundation")]
295        #[unsafe(method(descender))]
296        #[unsafe(method_family = none)]
297        pub fn descender(&self) -> CGFloat;
298
299        #[cfg(feature = "objc2-core-foundation")]
300        #[unsafe(method(leading))]
301        #[unsafe(method_family = none)]
302        pub fn leading(&self) -> CGFloat;
303
304        #[cfg(feature = "objc2-core-foundation")]
305        #[unsafe(method(underlinePosition))]
306        #[unsafe(method_family = none)]
307        pub fn underlinePosition(&self) -> CGFloat;
308
309        #[cfg(feature = "objc2-core-foundation")]
310        #[unsafe(method(underlineThickness))]
311        #[unsafe(method_family = none)]
312        pub fn underlineThickness(&self) -> CGFloat;
313
314        #[cfg(feature = "objc2-core-foundation")]
315        #[unsafe(method(italicAngle))]
316        #[unsafe(method_family = none)]
317        pub fn italicAngle(&self) -> CGFloat;
318
319        #[cfg(feature = "objc2-core-foundation")]
320        #[unsafe(method(capHeight))]
321        #[unsafe(method_family = none)]
322        pub fn capHeight(&self) -> CGFloat;
323
324        #[cfg(feature = "objc2-core-foundation")]
325        #[unsafe(method(xHeight))]
326        #[unsafe(method_family = none)]
327        pub fn xHeight(&self) -> CGFloat;
328
329        #[unsafe(method(isFixedPitch))]
330        #[unsafe(method_family = none)]
331        pub fn isFixedPitch(&self) -> bool;
332
333        #[cfg(feature = "objc2-core-graphics")]
334        #[cfg(target_vendor = "apple")]
335        /// ******* Glyph metrics ********
336        ///
337        /// ******* Glyph metrics ********
338        #[unsafe(method(boundingRectForCGGlyph:))]
339        #[unsafe(method_family = none)]
340        pub fn boundingRectForCGGlyph(&self, glyph: CGGlyph) -> NSRect;
341
342        #[cfg(feature = "objc2-core-graphics")]
343        #[cfg(target_vendor = "apple")]
344        #[unsafe(method(advancementForCGGlyph:))]
345        #[unsafe(method_family = none)]
346        pub fn advancementForCGGlyph(&self, glyph: CGGlyph) -> NSSize;
347
348        #[cfg(feature = "objc2-core-graphics")]
349        #[cfg(target_vendor = "apple")]
350        /// # Safety
351        ///
352        /// - `bounds` must be a valid pointer.
353        /// - `glyphs` must be a valid pointer.
354        #[unsafe(method(getBoundingRects:forCGGlyphs:count:))]
355        #[unsafe(method_family = none)]
356        pub unsafe fn getBoundingRects_forCGGlyphs_count(
357            &self,
358            bounds: NSRectArray,
359            glyphs: NonNull<CGGlyph>,
360            glyph_count: NSUInteger,
361        );
362
363        #[cfg(feature = "objc2-core-graphics")]
364        #[cfg(target_vendor = "apple")]
365        /// # Safety
366        ///
367        /// - `advancements` must be a valid pointer.
368        /// - `glyphs` must be a valid pointer.
369        #[unsafe(method(getAdvancements:forCGGlyphs:count:))]
370        #[unsafe(method_family = none)]
371        pub unsafe fn getAdvancements_forCGGlyphs_count(
372            &self,
373            advancements: NSSizeArray,
374            glyphs: NonNull<CGGlyph>,
375            glyph_count: NSUInteger,
376        );
377
378        /// ******* NSGraphicsContext-related ********
379        #[unsafe(method(set))]
380        #[unsafe(method_family = none)]
381        pub fn set(&self);
382
383        #[cfg(feature = "NSGraphicsContext")]
384        #[unsafe(method(setInContext:))]
385        #[unsafe(method_family = none)]
386        pub fn setInContext(&self, graphics_context: &NSGraphicsContext);
387
388        /// ******* Vertical mode ********
389        #[unsafe(method(verticalFont))]
390        #[unsafe(method_family = none)]
391        pub fn verticalFont(&self) -> Retained<NSFont>;
392
393        #[unsafe(method(isVertical))]
394        #[unsafe(method_family = none)]
395        pub fn isVertical(&self) -> bool;
396    );
397}
398
399/// Methods declared on superclass `NSObject`.
400impl NSFont {
401    extern_methods!(
402        #[unsafe(method(init))]
403        #[unsafe(method_family = init)]
404        pub fn init(this: Allocated<Self>) -> Retained<Self>;
405
406        #[unsafe(method(new))]
407        #[unsafe(method_family = new)]
408        pub fn new() -> Retained<Self>;
409    );
410}
411
412impl DefaultRetained for NSFont {
413    #[inline]
414    fn default_retained() -> Retained<Self> {
415        Self::new()
416    }
417}
418
419extern "C" {
420    /// ******* Notifications ********
421    ///
422    /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nsantialiasthresholdchangednotification?language=objc)
423    pub static NSAntialiasThresholdChangedNotification: &'static NSNotificationName;
424}
425
426extern "C" {
427    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsfontsetchangednotification?language=objc)
428    pub static NSFontSetChangedNotification: &'static NSNotificationName;
429}
430
431/// ******* Deprecated API ********
432///
433/// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nsglyph?language=objc)
434pub type NSGlyph = c_uint;
435
436/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nscontrolglyph?language=objc)
437pub const NSControlGlyph: c_uint = 0x00FFFFFF;
438/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsnullglyph?language=objc)
439pub const NSNullGlyph: c_uint = 0x0;
440
441/// ******* Screen Font Rendering Mode ********
442///
443/// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nsfontrenderingmode?language=objc)
444// NS_ENUM
445#[repr(transparent)]
446#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
447pub struct NSFontRenderingMode(pub NSUInteger);
448impl NSFontRenderingMode {
449    #[doc(alias = "NSFontDefaultRenderingMode")]
450    pub const DefaultRenderingMode: Self = Self(0);
451    #[doc(alias = "NSFontAntialiasedRenderingMode")]
452    pub const AntialiasedRenderingMode: Self = Self(1);
453    #[doc(alias = "NSFontIntegerAdvancementsRenderingMode")]
454    pub const IntegerAdvancementsRenderingMode: Self = Self(2);
455    #[doc(alias = "NSFontAntialiasedIntegerAdvancementsRenderingMode")]
456    pub const AntialiasedIntegerAdvancementsRenderingMode: Self = Self(3);
457}
458
459unsafe impl Encode for NSFontRenderingMode {
460    const ENCODING: Encoding = NSUInteger::ENCODING;
461}
462
463unsafe impl RefEncode for NSFontRenderingMode {
464    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
465}
466
467/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsmultibyteglyphpacking?language=objc)
468// NS_ENUM
469#[deprecated]
470#[repr(transparent)]
471#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
472pub struct NSMultibyteGlyphPacking(pub NSUInteger);
473impl NSMultibyteGlyphPacking {
474    #[doc(alias = "NSNativeShortGlyphPacking")]
475    #[deprecated]
476    pub const NativeShortGlyphPacking: Self = Self(5);
477}
478
479unsafe impl Encode for NSMultibyteGlyphPacking {
480    const ENCODING: Encoding = NSUInteger::ENCODING;
481}
482
483unsafe impl RefEncode for NSMultibyteGlyphPacking {
484    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
485}
486
487extern "C-unwind" {
488    /// # Safety
489    ///
490    /// - `gl_buf` must be a valid pointer.
491    /// - `packed_glyphs` must be a valid pointer.
492    #[deprecated]
493    pub fn NSConvertGlyphsToPackedGlyphs(
494        gl_buf: NonNull<NSGlyph>,
495        count: NSInteger,
496        packing: NSMultibyteGlyphPacking,
497        packed_glyphs: NonNull<c_char>,
498    ) -> NSInteger;
499}
500
501/// NSFont_Deprecated.
502impl NSFont {
503    extern_methods!(
504        #[unsafe(method(glyphWithName:))]
505        #[unsafe(method_family = none)]
506        pub fn glyphWithName(&self, name: &NSString) -> NSGlyph;
507
508        #[unsafe(method(boundingRectForGlyph:))]
509        #[unsafe(method_family = none)]
510        pub fn boundingRectForGlyph(&self, glyph: NSGlyph) -> NSRect;
511
512        #[unsafe(method(advancementForGlyph:))]
513        #[unsafe(method_family = none)]
514        pub fn advancementForGlyph(&self, glyph: NSGlyph) -> NSSize;
515
516        /// # Safety
517        ///
518        /// - `bounds` must be a valid pointer.
519        /// - `glyphs` must be a valid pointer.
520        #[unsafe(method(getBoundingRects:forGlyphs:count:))]
521        #[unsafe(method_family = none)]
522        pub unsafe fn getBoundingRects_forGlyphs_count(
523            &self,
524            bounds: NSRectArray,
525            glyphs: NonNull<NSGlyph>,
526            glyph_count: NSUInteger,
527        );
528
529        /// # Safety
530        ///
531        /// - `advancements` must be a valid pointer.
532        /// - `glyphs` must be a valid pointer.
533        #[unsafe(method(getAdvancements:forGlyphs:count:))]
534        #[unsafe(method_family = none)]
535        pub unsafe fn getAdvancements_forGlyphs_count(
536            &self,
537            advancements: NSSizeArray,
538            glyphs: NonNull<NSGlyph>,
539            glyph_count: NSUInteger,
540        );
541
542        /// # Safety
543        ///
544        /// - `advancements` must be a valid pointer.
545        /// - `packed_glyphs` must be a valid pointer.
546        #[unsafe(method(getAdvancements:forPackedGlyphs:length:))]
547        #[unsafe(method_family = none)]
548        pub unsafe fn getAdvancements_forPackedGlyphs_length(
549            &self,
550            advancements: NSSizeArray,
551            packed_glyphs: NonNull<c_void>,
552            length: NSUInteger,
553        );
554
555        /// ******* Rendering mode ********
556        #[unsafe(method(printerFont))]
557        #[unsafe(method_family = none)]
558        pub fn printerFont(&self) -> Retained<NSFont>;
559
560        #[unsafe(method(screenFont))]
561        #[unsafe(method_family = none)]
562        pub fn screenFont(&self) -> Retained<NSFont>;
563
564        #[unsafe(method(screenFontWithRenderingMode:))]
565        #[unsafe(method_family = none)]
566        pub fn screenFontWithRenderingMode(
567            &self,
568            rendering_mode: NSFontRenderingMode,
569        ) -> Retained<NSFont>;
570
571        #[unsafe(method(renderingMode))]
572        #[unsafe(method_family = none)]
573        pub fn renderingMode(&self) -> NSFontRenderingMode;
574    );
575}
576
577/// NSFont_TextStyles.
578impl NSFont {
579    extern_methods!(
580        #[cfg(feature = "NSFontDescriptor")]
581        /// # Safety
582        ///
583        /// `options` generic should be of the correct type.
584        #[unsafe(method(preferredFontForTextStyle:options:))]
585        #[unsafe(method_family = none)]
586        pub unsafe fn preferredFontForTextStyle_options(
587            style: &NSFontTextStyle,
588            options: &NSDictionary<NSFontTextStyleOptionKey, AnyObject>,
589        ) -> Retained<NSFont>;
590    );
591}