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