1use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6#[cfg(feature = "objc2-core-foundation")]
7use objc2_core_foundation::*;
8use objc2_foundation::*;
9
10use crate::*;
11
12extern_class!(
13 #[unsafe(super(NSObject))]
15 #[derive(Debug, PartialEq, Eq, Hash)]
16 pub struct NSTypesetter;
17);
18
19extern_conformance!(
20 unsafe impl NSObjectProtocol for NSTypesetter {}
21);
22
23impl NSTypesetter {
24 extern_methods!(
25 #[unsafe(method(usesFontLeading))]
26 #[unsafe(method_family = none)]
27 pub fn usesFontLeading(&self) -> bool;
28
29 #[unsafe(method(setUsesFontLeading:))]
31 #[unsafe(method_family = none)]
32 pub fn setUsesFontLeading(&self, uses_font_leading: bool);
33
34 #[cfg(feature = "NSLayoutManager")]
35 #[unsafe(method(typesetterBehavior))]
36 #[unsafe(method_family = none)]
37 pub fn typesetterBehavior(&self) -> NSTypesetterBehavior;
38
39 #[cfg(feature = "NSLayoutManager")]
40 #[unsafe(method(setTypesetterBehavior:))]
42 #[unsafe(method_family = none)]
43 pub fn setTypesetterBehavior(&self, typesetter_behavior: NSTypesetterBehavior);
44
45 #[unsafe(method(hyphenationFactor))]
46 #[unsafe(method_family = none)]
47 pub fn hyphenationFactor(&self) -> c_float;
48
49 #[unsafe(method(setHyphenationFactor:))]
51 #[unsafe(method_family = none)]
52 pub fn setHyphenationFactor(&self, hyphenation_factor: c_float);
53
54 #[cfg(feature = "objc2-core-foundation")]
55 #[unsafe(method(lineFragmentPadding))]
56 #[unsafe(method_family = none)]
57 pub fn lineFragmentPadding(&self) -> CGFloat;
58
59 #[cfg(feature = "objc2-core-foundation")]
60 #[unsafe(method(setLineFragmentPadding:))]
62 #[unsafe(method_family = none)]
63 pub fn setLineFragmentPadding(&self, line_fragment_padding: CGFloat);
64
65 #[cfg(feature = "NSFont")]
66 #[unsafe(method(substituteFontForFont:))]
67 #[unsafe(method_family = none)]
68 pub fn substituteFontForFont(&self, original_font: &NSFont) -> Retained<NSFont>;
69
70 #[cfg(all(
71 feature = "NSParagraphStyle",
72 feature = "NSText",
73 feature = "objc2-core-foundation"
74 ))]
75 #[unsafe(method(textTabForGlyphLocation:writingDirection:maxLocation:))]
76 #[unsafe(method_family = none)]
77 pub fn textTabForGlyphLocation_writingDirection_maxLocation(
78 &self,
79 glyph_location: CGFloat,
80 direction: NSWritingDirection,
81 max_location: CGFloat,
82 ) -> Option<Retained<NSTextTab>>;
83
84 #[unsafe(method(bidiProcessingEnabled))]
85 #[unsafe(method_family = none)]
86 pub fn bidiProcessingEnabled(&self) -> bool;
87
88 #[unsafe(method(setBidiProcessingEnabled:))]
90 #[unsafe(method_family = none)]
91 pub fn setBidiProcessingEnabled(&self, bidi_processing_enabled: bool);
92
93 #[unsafe(method(attributedString))]
97 #[unsafe(method_family = none)]
98 pub unsafe fn attributedString(&self) -> Option<Retained<NSAttributedString>>;
99
100 #[unsafe(method(setAttributedString:))]
106 #[unsafe(method_family = none)]
107 pub unsafe fn setAttributedString(&self, attributed_string: Option<&NSAttributedString>);
108
109 #[unsafe(method(setParagraphGlyphRange:separatorGlyphRange:))]
110 #[unsafe(method_family = none)]
111 pub fn setParagraphGlyphRange_separatorGlyphRange(
112 &self,
113 paragraph_range: NSRange,
114 paragraph_separator_range: NSRange,
115 );
116
117 #[unsafe(method(paragraphGlyphRange))]
118 #[unsafe(method_family = none)]
119 pub fn paragraphGlyphRange(&self) -> NSRange;
120
121 #[unsafe(method(paragraphSeparatorGlyphRange))]
122 #[unsafe(method_family = none)]
123 pub fn paragraphSeparatorGlyphRange(&self) -> NSRange;
124
125 #[unsafe(method(paragraphCharacterRange))]
126 #[unsafe(method_family = none)]
127 pub fn paragraphCharacterRange(&self) -> NSRange;
128
129 #[unsafe(method(paragraphSeparatorCharacterRange))]
130 #[unsafe(method_family = none)]
131 pub fn paragraphSeparatorCharacterRange(&self) -> NSRange;
132
133 #[unsafe(method(layoutParagraphAtPoint:))]
137 #[unsafe(method_family = none)]
138 pub unsafe fn layoutParagraphAtPoint(
139 &self,
140 line_fragment_origin: NSPointPointer,
141 ) -> NSUInteger;
142
143 #[unsafe(method(beginParagraph))]
144 #[unsafe(method_family = none)]
145 pub fn beginParagraph(&self);
146
147 #[unsafe(method(endParagraph))]
148 #[unsafe(method_family = none)]
149 pub fn endParagraph(&self);
150
151 #[unsafe(method(beginLineWithGlyphAtIndex:))]
152 #[unsafe(method_family = none)]
153 pub fn beginLineWithGlyphAtIndex(&self, glyph_index: NSUInteger);
154
155 #[unsafe(method(endLineWithGlyphRange:))]
156 #[unsafe(method_family = none)]
157 pub fn endLineWithGlyphRange(&self, line_glyph_range: NSRange);
158
159 #[cfg(feature = "objc2-core-foundation")]
160 #[unsafe(method(lineSpacingAfterGlyphAtIndex:withProposedLineFragmentRect:))]
161 #[unsafe(method_family = none)]
162 pub fn lineSpacingAfterGlyphAtIndex_withProposedLineFragmentRect(
163 &self,
164 glyph_index: NSUInteger,
165 rect: NSRect,
166 ) -> CGFloat;
167
168 #[cfg(feature = "objc2-core-foundation")]
169 #[unsafe(method(paragraphSpacingBeforeGlyphAtIndex:withProposedLineFragmentRect:))]
170 #[unsafe(method_family = none)]
171 pub fn paragraphSpacingBeforeGlyphAtIndex_withProposedLineFragmentRect(
172 &self,
173 glyph_index: NSUInteger,
174 rect: NSRect,
175 ) -> CGFloat;
176
177 #[cfg(feature = "objc2-core-foundation")]
178 #[unsafe(method(paragraphSpacingAfterGlyphAtIndex:withProposedLineFragmentRect:))]
179 #[unsafe(method_family = none)]
180 pub fn paragraphSpacingAfterGlyphAtIndex_withProposedLineFragmentRect(
181 &self,
182 glyph_index: NSUInteger,
183 rect: NSRect,
184 ) -> CGFloat;
185
186 #[unsafe(method(getLineFragmentRect:usedRect:forParagraphSeparatorGlyphRange:atProposedOrigin:))]
191 #[unsafe(method_family = none)]
192 pub unsafe fn getLineFragmentRect_usedRect_forParagraphSeparatorGlyphRange_atProposedOrigin(
193 &self,
194 line_fragment_rect: NSRectPointer,
195 line_fragment_used_rect: NSRectPointer,
196 paragraph_separator_glyph_range: NSRange,
197 line_origin: NSPoint,
198 );
199
200 #[unsafe(method(attributesForExtraLineFragment))]
201 #[unsafe(method_family = none)]
202 pub fn attributesForExtraLineFragment(
203 &self,
204 ) -> Retained<NSDictionary<NSAttributedStringKey, AnyObject>>;
205
206 #[cfg(feature = "NSLayoutManager")]
207 #[unsafe(method(layoutManager))]
211 #[unsafe(method_family = none)]
212 pub unsafe fn layoutManager(&self) -> Option<Retained<NSLayoutManager>>;
213
214 #[cfg(feature = "NSTextContainer")]
215 #[unsafe(method(textContainers))]
219 #[unsafe(method_family = none)]
220 pub unsafe fn textContainers(&self) -> Option<Retained<NSArray<NSTextContainer>>>;
221
222 #[cfg(feature = "NSTextContainer")]
223 #[unsafe(method(currentTextContainer))]
227 #[unsafe(method_family = none)]
228 pub unsafe fn currentTextContainer(&self) -> Option<Retained<NSTextContainer>>;
229
230 #[cfg(feature = "NSParagraphStyle")]
231 #[unsafe(method(currentParagraphStyle))]
232 #[unsafe(method_family = none)]
233 pub fn currentParagraphStyle(&self) -> Option<Retained<NSParagraphStyle>>;
234
235 #[unsafe(method(setHardInvalidation:forGlyphRange:))]
236 #[unsafe(method_family = none)]
237 pub fn setHardInvalidation_forGlyphRange(&self, flag: bool, glyph_range: NSRange);
238
239 #[cfg(feature = "NSLayoutManager")]
240 #[unsafe(method(layoutGlyphsInLayoutManager:startingAtGlyphIndex:maxNumberOfLineFragments:nextGlyphIndex:))]
244 #[unsafe(method_family = none)]
245 pub unsafe fn layoutGlyphsInLayoutManager_startingAtGlyphIndex_maxNumberOfLineFragments_nextGlyphIndex(
246 &self,
247 layout_manager: &NSLayoutManager,
248 start_glyph_index: NSUInteger,
249 max_num_lines: NSUInteger,
250 next_glyph: NonNull<NSUInteger>,
251 );
252
253 #[cfg(feature = "NSLayoutManager")]
254 #[unsafe(method(layoutCharactersInRange:forLayoutManager:maximumNumberOfLineFragments:))]
255 #[unsafe(method_family = none)]
256 pub fn layoutCharactersInRange_forLayoutManager_maximumNumberOfLineFragments(
257 &self,
258 character_range: NSRange,
259 layout_manager: &NSLayoutManager,
260 max_num_lines: NSUInteger,
261 ) -> NSRange;
262
263 #[cfg(feature = "NSLayoutManager")]
264 #[unsafe(method(printingAdjustmentInLayoutManager:forNominallySpacedGlyphRange:packedGlyphs:count:))]
268 #[unsafe(method_family = none)]
269 pub unsafe fn printingAdjustmentInLayoutManager_forNominallySpacedGlyphRange_packedGlyphs_count(
270 layout_mgr: &NSLayoutManager,
271 nominally_spaced_glyphs_range: NSRange,
272 packed_glyphs: NonNull<c_uchar>,
273 packed_glyphs_count: NSUInteger,
274 ) -> NSSize;
275
276 #[cfg(all(feature = "NSLayoutManager", feature = "objc2-core-foundation"))]
277 #[unsafe(method(baselineOffsetInLayoutManager:glyphIndex:))]
278 #[unsafe(method_family = none)]
279 pub fn baselineOffsetInLayoutManager_glyphIndex(
280 &self,
281 layout_mgr: &NSLayoutManager,
282 glyph_index: NSUInteger,
283 ) -> CGFloat;
284
285 #[unsafe(method(sharedSystemTypesetter))]
286 #[unsafe(method_family = none)]
287 pub fn sharedSystemTypesetter() -> Retained<NSTypesetter>;
288
289 #[cfg(feature = "NSLayoutManager")]
290 #[unsafe(method(sharedSystemTypesetterForBehavior:))]
291 #[unsafe(method_family = none)]
292 pub fn sharedSystemTypesetterForBehavior(
293 behavior: NSTypesetterBehavior,
294 ) -> Retained<AnyObject>;
295
296 #[cfg(feature = "NSLayoutManager")]
297 #[unsafe(method(defaultTypesetterBehavior))]
298 #[unsafe(method_family = none)]
299 pub fn defaultTypesetterBehavior() -> NSTypesetterBehavior;
300 );
301}
302
303impl NSTypesetter {
305 extern_methods!(
306 #[unsafe(method(init))]
307 #[unsafe(method_family = init)]
308 pub fn init(this: Allocated<Self>) -> Retained<Self>;
309
310 #[unsafe(method(new))]
311 #[unsafe(method_family = new)]
312 pub fn new() -> Retained<Self>;
313 );
314}
315
316impl DefaultRetained for NSTypesetter {
317 #[inline]
318 fn default_retained() -> Retained<Self> {
319 Self::new()
320 }
321}
322
323impl NSTypesetter {
325 extern_methods!(
326 #[cfg(feature = "objc2-core-foundation")]
327 #[unsafe(method(willSetLineFragmentRect:forGlyphRange:usedRect:baselineOffset:))]
333 #[unsafe(method_family = none)]
334 pub unsafe fn willSetLineFragmentRect_forGlyphRange_usedRect_baselineOffset(
335 &self,
336 line_rect: NSRectPointer,
337 glyph_range: NSRange,
338 used_rect: NSRectPointer,
339 baseline_offset: NonNull<CGFloat>,
340 );
341
342 #[unsafe(method(shouldBreakLineByWordBeforeCharacterAtIndex:))]
343 #[unsafe(method_family = none)]
344 pub fn shouldBreakLineByWordBeforeCharacterAtIndex(&self, char_index: NSUInteger) -> bool;
345
346 #[unsafe(method(shouldBreakLineByHyphenatingBeforeCharacterAtIndex:))]
347 #[unsafe(method_family = none)]
348 pub fn shouldBreakLineByHyphenatingBeforeCharacterAtIndex(
349 &self,
350 char_index: NSUInteger,
351 ) -> bool;
352
353 #[unsafe(method(hyphenationFactorForGlyphAtIndex:))]
354 #[unsafe(method_family = none)]
355 pub fn hyphenationFactorForGlyphAtIndex(&self, glyph_index: NSUInteger) -> c_float;
356
357 #[unsafe(method(hyphenCharacterForGlyphAtIndex:))]
358 #[unsafe(method_family = none)]
359 pub fn hyphenCharacterForGlyphAtIndex(&self, glyph_index: NSUInteger) -> UTF32Char;
360
361 #[cfg(feature = "NSTextContainer")]
362 #[unsafe(method(boundingBoxForControlGlyphAtIndex:forTextContainer:proposedLineFragment:glyphPosition:characterIndex:))]
363 #[unsafe(method_family = none)]
364 pub fn boundingBoxForControlGlyphAtIndex_forTextContainer_proposedLineFragment_glyphPosition_characterIndex(
365 &self,
366 glyph_index: NSUInteger,
367 text_container: &NSTextContainer,
368 proposed_rect: NSRect,
369 glyph_position: NSPoint,
370 char_index: NSUInteger,
371 ) -> NSRect;
372 );
373}
374
375impl NSTypesetter {
377 extern_methods!(
378 #[unsafe(method(characterRangeForGlyphRange:actualGlyphRange:))]
382 #[unsafe(method_family = none)]
383 pub unsafe fn characterRangeForGlyphRange_actualGlyphRange(
384 &self,
385 glyph_range: NSRange,
386 actual_glyph_range: NSRangePointer,
387 ) -> NSRange;
388
389 #[unsafe(method(glyphRangeForCharacterRange:actualCharacterRange:))]
393 #[unsafe(method_family = none)]
394 pub unsafe fn glyphRangeForCharacterRange_actualCharacterRange(
395 &self,
396 char_range: NSRange,
397 actual_char_range: NSRangePointer,
398 ) -> NSRange;
399
400 #[cfg(feature = "objc2-core-foundation")]
401 #[unsafe(method(getLineFragmentRect:usedRect:remainingRect:forStartingGlyphAtIndex:proposedRect:lineSpacing:paragraphSpacingBefore:paragraphSpacingAfter:))]
407 #[unsafe(method_family = none)]
408 pub unsafe fn getLineFragmentRect_usedRect_remainingRect_forStartingGlyphAtIndex_proposedRect_lineSpacing_paragraphSpacingBefore_paragraphSpacingAfter(
409 &self,
410 line_fragment_rect: NSRectPointer,
411 line_fragment_used_rect: NSRectPointer,
412 remaining_rect: NSRectPointer,
413 starting_glyph_index: NSUInteger,
414 proposed_rect: NSRect,
415 line_spacing: CGFloat,
416 paragraph_spacing_before: CGFloat,
417 paragraph_spacing_after: CGFloat,
418 );
419
420 #[cfg(feature = "objc2-core-foundation")]
421 #[unsafe(method(setLineFragmentRect:forGlyphRange:usedRect:baselineOffset:))]
422 #[unsafe(method_family = none)]
423 pub fn setLineFragmentRect_forGlyphRange_usedRect_baselineOffset(
424 &self,
425 fragment_rect: NSRect,
426 glyph_range: NSRange,
427 used_rect: NSRect,
428 baseline_offset: CGFloat,
429 );
430
431 #[unsafe(method(setNotShownAttribute:forGlyphRange:))]
432 #[unsafe(method_family = none)]
433 pub fn setNotShownAttribute_forGlyphRange(&self, flag: bool, glyph_range: NSRange);
434
435 #[unsafe(method(setDrawsOutsideLineFragment:forGlyphRange:))]
436 #[unsafe(method_family = none)]
437 pub fn setDrawsOutsideLineFragment_forGlyphRange(&self, flag: bool, glyph_range: NSRange);
438
439 #[cfg(feature = "objc2-core-foundation")]
440 #[unsafe(method(setLocation:withAdvancements:forStartOfGlyphRange:))]
444 #[unsafe(method_family = none)]
445 pub unsafe fn setLocation_withAdvancements_forStartOfGlyphRange(
446 &self,
447 location: NSPoint,
448 advancements: *const CGFloat,
449 glyph_range: NSRange,
450 );
451
452 #[unsafe(method(setAttachmentSize:forGlyphRange:))]
453 #[unsafe(method_family = none)]
454 pub fn setAttachmentSize_forGlyphRange(
455 &self,
456 attachment_size: NSSize,
457 glyph_range: NSRange,
458 );
459
460 #[unsafe(method(setBidiLevels:forGlyphRange:))]
464 #[unsafe(method_family = none)]
465 pub unsafe fn setBidiLevels_forGlyphRange(&self, levels: *const u8, glyph_range: NSRange);
466 );
467}
468
469#[repr(transparent)]
472#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
473pub struct NSTypesetterControlCharacterAction(pub NSUInteger);
474bitflags::bitflags! {
475 impl NSTypesetterControlCharacterAction: NSUInteger {
476 #[doc(alias = "NSTypesetterZeroAdvancementAction")]
477 const ZeroAdvancementAction = 1<<0;
478 #[doc(alias = "NSTypesetterWhitespaceAction")]
479 const WhitespaceAction = 1<<1;
480 #[doc(alias = "NSTypesetterHorizontalTabAction")]
481 const HorizontalTabAction = 1<<2;
482 #[doc(alias = "NSTypesetterLineBreakAction")]
483 const LineBreakAction = 1<<3;
484 #[doc(alias = "NSTypesetterParagraphBreakAction")]
485 const ParagraphBreakAction = 1<<4;
486 #[doc(alias = "NSTypesetterContainerBreakAction")]
487 const ContainerBreakAction = 1<<5;
488 }
489}
490
491unsafe impl Encode for NSTypesetterControlCharacterAction {
492 const ENCODING: Encoding = NSUInteger::ENCODING;
493}
494
495unsafe impl RefEncode for NSTypesetterControlCharacterAction {
496 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
497}
498
499impl NSTypesetter {
501 extern_methods!(
502 #[unsafe(method(actionForControlCharacterAtIndex:))]
503 #[unsafe(method_family = none)]
504 pub fn actionForControlCharacterAtIndex(
505 &self,
506 char_index: NSUInteger,
507 ) -> NSTypesetterControlCharacterAction;
508
509 #[cfg(all(feature = "NSFont", feature = "NSLayoutManager"))]
510 #[deprecated]
518 #[unsafe(method(getGlyphsInRange:glyphs:characterIndexes:glyphInscriptions:elasticBits:bidiLevels:))]
519 #[unsafe(method_family = none)]
520 pub unsafe fn getGlyphsInRange_glyphs_characterIndexes_glyphInscriptions_elasticBits_bidiLevels(
521 &self,
522 glyphs_range: NSRange,
523 glyph_buffer: *mut NSGlyph,
524 char_index_buffer: *mut NSUInteger,
525 inscribe_buffer: *mut NSGlyphInscription,
526 elastic_buffer: *mut Bool,
527 bidi_level_buffer: *mut c_uchar,
528 ) -> NSUInteger;
529
530 #[cfg(feature = "NSFont")]
531 #[deprecated]
535 #[unsafe(method(substituteGlyphsInRange:withGlyphs:))]
536 #[unsafe(method_family = none)]
537 pub unsafe fn substituteGlyphsInRange_withGlyphs(
538 &self,
539 glyph_range: NSRange,
540 glyphs: *mut NSGlyph,
541 );
542
543 #[cfg(feature = "NSFont")]
544 #[deprecated]
545 #[unsafe(method(insertGlyph:atGlyphIndex:characterIndex:))]
546 #[unsafe(method_family = none)]
547 pub fn insertGlyph_atGlyphIndex_characterIndex(
548 &self,
549 glyph: NSGlyph,
550 glyph_index: NSUInteger,
551 character_index: NSUInteger,
552 );
553
554 #[deprecated]
555 #[unsafe(method(deleteGlyphsInRange:))]
556 #[unsafe(method_family = none)]
557 pub fn deleteGlyphsInRange(&self, glyph_range: NSRange);
558 );
559}