objc2_core_text/generated/CTRun.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::cell::UnsafeCell;
4use core::ffi::*;
5use core::marker::{PhantomData, PhantomPinned};
6use core::ptr::NonNull;
7#[cfg(feature = "objc2")]
8use objc2::__framework_prelude::*;
9use objc2_core_foundation::*;
10#[cfg(feature = "objc2-core-graphics")]
11use objc2_core_graphics::*;
12
13use crate::*;
14
15/// [Apple's documentation](https://developer.apple.com/documentation/coretext/ctrun?language=objc)
16#[repr(C)]
17pub struct CTRun {
18 inner: [u8; 0],
19 _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
20}
21
22cf_type!(
23 #[encoding_name = "__CTRun"]
24 unsafe impl CTRun {}
25);
26
27/// A bitfield passed back by CTRunGetStatus that is used to
28/// indicate the disposition of the run.
29///
30///
31/// The run has no special attributes.
32///
33///
34/// When set, the run is right to left.
35///
36///
37/// When set, the run has been reordered in some way such that
38/// the string indices associated with the glyphs are no longer
39/// strictly increasing (for left to right runs) or decreasing
40/// (for right to left runs).
41///
42///
43/// When set, the run requires a specific text matrix to be set
44/// in the current CG context for proper drawing.
45///
46/// See also [Apple's documentation](https://developer.apple.com/documentation/coretext/ctrunstatus?language=objc)
47// NS_OPTIONS
48#[repr(transparent)]
49#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
50pub struct CTRunStatus(pub u32);
51bitflags::bitflags! {
52 impl CTRunStatus: u32 {
53 #[doc(alias = "kCTRunStatusNoStatus")]
54 const NoStatus = 0;
55 #[doc(alias = "kCTRunStatusRightToLeft")]
56 const RightToLeft = 1<<0;
57 #[doc(alias = "kCTRunStatusNonMonotonic")]
58 const NonMonotonic = 1<<1;
59 #[doc(alias = "kCTRunStatusHasNonIdentityMatrix")]
60 const HasNonIdentityMatrix = 1<<2;
61 }
62}
63
64#[cfg(feature = "objc2")]
65unsafe impl Encode for CTRunStatus {
66 const ENCODING: Encoding = u32::ENCODING;
67}
68
69#[cfg(feature = "objc2")]
70unsafe impl RefEncode for CTRunStatus {
71 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
72}
73
74unsafe impl ConcreteType for CTRun {
75 /// Returns the CFType of the run object
76 #[doc(alias = "CTRunGetTypeID")]
77 #[inline]
78 fn type_id() -> CFTypeID {
79 extern "C-unwind" {
80 fn CTRunGetTypeID() -> CFTypeID;
81 }
82 unsafe { CTRunGetTypeID() }
83 }
84}
85
86extern "C-unwind" {
87 /// Gets the glyph count for the run.
88 ///
89 ///
90 /// Parameter `run`: The run whose glyph count you wish to access.
91 ///
92 ///
93 /// Returns: The number of glyphs that the run contains. It is totally
94 /// possible that this function could return a value of zero,
95 /// indicating that there are no glyphs in this run.
96 pub fn CTRunGetGlyphCount(run: &CTRun) -> CFIndex;
97}
98
99/// Returns the attribute dictionary that was used to create the
100/// glyph run.
101///
102///
103/// This dictionary returned is either the same exact one that was
104/// set as an attribute dictionary on the original attributed string
105/// or a dictionary that has been manufactured by the layout engine.
106/// Attribute dictionaries can be manufactured in the case of font
107/// substitution or if they are missing critical attributes.
108///
109///
110/// Parameter `run`: The run whose attributes you wish to access.
111///
112///
113/// Returns: The attribute dictionary.
114#[inline]
115pub unsafe extern "C-unwind" fn CTRunGetAttributes(run: &CTRun) -> CFRetained<CFDictionary> {
116 extern "C-unwind" {
117 fn CTRunGetAttributes(run: &CTRun) -> Option<NonNull<CFDictionary>>;
118 }
119 let ret = unsafe { CTRunGetAttributes(run) };
120 let ret = ret.expect("function was marked as returning non-null, but actually returned NULL");
121 unsafe { CFRetained::retain(ret) }
122}
123
124extern "C-unwind" {
125 /// Returns the run's status.
126 ///
127 ///
128 /// In addition to attributes, runs also have status that can be
129 /// used to expedite certain operations. Knowing the direction and
130 /// ordering of a run's glyphs can aid in string index analysis,
131 /// whereas knowing whether the positions reference the identity
132 /// text matrix can avoid expensive comparisons. Note that this
133 /// status is provided as a convenience, since this information is
134 /// not strictly necessary but can certainly be helpful.
135 ///
136 ///
137 /// Parameter `run`: The run whose status you wish to access.
138 ///
139 ///
140 /// Returns: The run's status.
141 pub fn CTRunGetStatus(run: &CTRun) -> CTRunStatus;
142}
143
144extern "C-unwind" {
145 /// Returns a direct pointer for the glyph array stored in the run.
146 ///
147 ///
148 /// The glyph array will have a length equal to the value returned by
149 /// CTRunGetGlyphCount. The caller should be prepared for this
150 /// function to return NULL even if there are glyphs in the stream.
151 /// Should this function return NULL, the caller will need to
152 /// allocate their own buffer and call CTRunGetGlyphs to fetch the
153 /// glyphs.
154 ///
155 ///
156 /// Parameter `run`: The run whose glyphs you wish to access.
157 ///
158 ///
159 /// Returns: A valid pointer to an array of CGGlyph structures or NULL.
160 #[cfg(feature = "objc2-core-graphics")]
161 pub fn CTRunGetGlyphsPtr(run: &CTRun) -> *const CGGlyph;
162}
163
164extern "C-unwind" {
165 /// Copies a range of glyphs into user-provided buffer.
166 ///
167 ///
168 /// Parameter `run`: The run whose glyphs you wish to copy.
169 ///
170 ///
171 /// Parameter `range`: The range of glyphs to be copied, with the entire range having a
172 /// location of 0 and a length of CTRunGetGlyphCount. If the length
173 /// of the range is set to 0, then the operation will continue from
174 /// the range's start index to the end of the run.
175 ///
176 ///
177 /// Parameter `buffer`: The buffer where the glyphs will be copied to. The buffer must be
178 /// allocated to at least the value specified by the range's length.
179 #[cfg(feature = "objc2-core-graphics")]
180 pub fn CTRunGetGlyphs(run: &CTRun, range: CFRange, buffer: NonNull<CGGlyph>);
181}
182
183extern "C-unwind" {
184 /// Returns a direct pointer for the glyph position array stored in
185 /// the run.
186 ///
187 ///
188 /// The glyph positions in a run are relative to the origin of the
189 /// line containing the run. The position array will have a length
190 /// equal to the value returned by CTRunGetGlyphCount. The caller
191 /// should be prepared for this function to return NULL even if there
192 /// are glyphs in the stream. Should this function return NULL, the
193 /// caller will need to allocate their own buffer and call
194 /// CTRunGetPositions to fetch the positions.
195 ///
196 ///
197 /// Parameter `run`: The run whose positions you wish to access.
198 ///
199 ///
200 /// Returns: A valid pointer to an array of CGPoint structures or NULL.
201 pub fn CTRunGetPositionsPtr(run: &CTRun) -> *const CGPoint;
202}
203
204extern "C-unwind" {
205 /// Copies a range of glyph positions into a user-provided buffer.
206 ///
207 ///
208 /// The glyph positions in a run are relative to the origin of the
209 /// line containing the run.
210 ///
211 ///
212 /// Parameter `run`: The run whose positions you wish to copy.
213 ///
214 ///
215 /// Parameter `range`: The range of glyph positions to be copied, with the entire range
216 /// having a location of 0 and a length of CTRunGetGlyphCount. If the
217 /// length of the range is set to 0, then the operation will continue
218 /// from the range's start index to the end of the run.
219 ///
220 ///
221 /// Parameter `buffer`: The buffer where the glyph positions will be copied to. The buffer
222 /// must be allocated to at least the value specified by the range's
223 /// length.
224 pub fn CTRunGetPositions(run: &CTRun, range: CFRange, buffer: NonNull<CGPoint>);
225}
226
227extern "C-unwind" {
228 /// Returns a direct pointer for the glyph advance array stored in
229 /// the run.
230 ///
231 ///
232 /// The advance array will have a length equal to the value returned
233 /// by CTRunGetGlyphCount. The caller should be prepared for this
234 /// function to return NULL even if there are glyphs in the stream.
235 /// Should this function return NULL, the caller will need to
236 /// allocate their own buffer and call CTRunGetAdvances to fetch the
237 /// advances. Note that advances alone are not sufficient for correctly
238 /// positioning glyphs in a line, as a run may have a non-identity
239 /// matrix or the initial glyph in a line may have a non-zero origin;
240 /// callers should consider using positions instead.
241 ///
242 ///
243 /// Parameter `run`: The run whose advances you wish to access.
244 ///
245 ///
246 /// Returns: A valid pointer to an array of CGSize structures or NULL.
247 pub fn CTRunGetAdvancesPtr(run: &CTRun) -> *const CGSize;
248}
249
250extern "C-unwind" {
251 /// Copies a range of glyph advances into a user-provided buffer.
252 ///
253 ///
254 /// Parameter `run`: The run whose advances you wish to copy.
255 ///
256 ///
257 /// Parameter `range`: The range of glyph advances to be copied, with the entire range
258 /// having a location of 0 and a length of CTRunGetGlyphCount. If the
259 /// length of the range is set to 0, then the operation will continue
260 /// from the range's start index to the end of the run.
261 ///
262 ///
263 /// Parameter `buffer`: The buffer where the glyph advances will be copied to. The buffer
264 /// must be allocated to at least the value specified by the range's
265 /// length.
266 pub fn CTRunGetAdvances(run: &CTRun, range: CFRange, buffer: NonNull<CGSize>);
267}
268
269extern "C-unwind" {
270 /// Returns a direct pointer for the string indices stored in the run.
271 ///
272 ///
273 /// The indices are the character indices that originally spawned the
274 /// glyphs that make up the run. They can be used to map the glyphs in
275 /// the run back to the characters in the backing store. The string
276 /// indices array will have a length equal to the value returned by
277 /// CTRunGetGlyphCount. The caller should be prepared for this
278 /// function to return NULL even if there are glyphs in the stream.
279 /// Should this function return NULL, the caller will need to allocate
280 /// their own buffer and call CTRunGetStringIndices to fetch the
281 /// indices.
282 ///
283 ///
284 /// Parameter `run`: The run whose string indices you wish to access.
285 ///
286 ///
287 /// Returns: A valid pointer to an array of CFIndex structures or NULL.
288 pub fn CTRunGetStringIndicesPtr(run: &CTRun) -> *const CFIndex;
289}
290
291extern "C-unwind" {
292 /// Copies a range of string indices into a user-provided buffer.
293 ///
294 ///
295 /// The indices are the character indices that originally spawned the
296 /// glyphs that make up the run. They can be used to map the glyphs
297 /// in the run back to the characters in the backing store.
298 ///
299 ///
300 /// Parameter `run`: The run whose string indices you wish to copy.
301 ///
302 ///
303 /// Parameter `range`: The range of string indices to be copied, with the entire range
304 /// having a location of 0 and a length of CTRunGetGlyphCount. If the
305 /// length of the range is set to 0, then the operation will continue
306 /// from the range's start index to the end of the run.
307 ///
308 ///
309 /// Parameter `buffer`: The buffer where the string indices will be copied to. The buffer
310 /// must be allocated to at least the value specified by the range's
311 /// length.
312 pub fn CTRunGetStringIndices(run: &CTRun, range: CFRange, buffer: NonNull<CFIndex>);
313}
314
315extern "C-unwind" {
316 /// Gets the range of characters that originally spawned the glyphs
317 /// in the run.
318 ///
319 ///
320 /// Parameter `run`: The run whose string range you wish to access.
321 ///
322 ///
323 /// Returns: Returns the range of characters that originally spawned the
324 /// glyphs. If run is invalid, this will return an empty range.
325 pub fn CTRunGetStringRange(run: &CTRun) -> CFRange;
326}
327
328extern "C-unwind" {
329 /// Gets the typographic bounds of the run.
330 ///
331 ///
332 /// Parameter `run`: The run that you want to calculate the typographic bounds for.
333 ///
334 ///
335 /// Parameter `range`: The range of glyphs to be measured, with the entire range having
336 /// a location of 0 and a length of CTRunGetGlyphCount. If the length
337 /// of the range is set to 0, then the operation will continue from
338 /// the range's start index to the end of the run.
339 ///
340 ///
341 /// Parameter `ascent`: Upon return, this parameter will contain the ascent of the run.
342 /// This may be set to NULL if not needed.
343 ///
344 ///
345 /// Parameter `descent`: Upon return, this parameter will contain the descent of the run.
346 /// This may be set to NULL if not needed.
347 ///
348 ///
349 /// Parameter `leading`: Upon return, this parameter will contain the leading of the run.
350 /// This may be set to NULL if not needed.
351 ///
352 ///
353 /// Returns: The typographic width of the run. If run or range is
354 /// invalid, then this function will always return zero.
355 pub fn CTRunGetTypographicBounds(
356 run: &CTRun,
357 range: CFRange,
358 ascent: *mut CGFloat,
359 descent: *mut CGFloat,
360 leading: *mut CGFloat,
361 ) -> c_double;
362}
363
364extern "C-unwind" {
365 /// Calculates the image bounds for a glyph range.
366 ///
367 ///
368 /// The image bounds for a run is the union of all non-empty glyph
369 /// bounding rects, each positioned as it would be if drawn using
370 /// CTRunDraw using the current context (for clients linked against
371 /// macOS High Sierra or iOS 11 and later) or the text position of
372 /// the supplied context (for all others). Note that the result is
373 /// ideal and does not account for raster coverage due to rendering.
374 /// This function is purely a convenience for using glyphs as an
375 /// image and should not be used for typographic purposes.
376 ///
377 ///
378 /// Parameter `run`: The run that you want to calculate the image bounds for.
379 ///
380 ///
381 /// Parameter `context`: The context which the image bounds will be calculated for or NULL,
382 /// in which case the bounds are relative to CGPointZero.
383 ///
384 ///
385 /// Parameter `range`: The range of glyphs to be measured, with the entire range having
386 /// a location of 0 and a length of CTRunGetGlyphCount. If the length
387 /// of the range is set to 0, then the operation will continue from
388 /// the range's start index to the end of the run.
389 ///
390 ///
391 /// Returns: A rect that tightly encloses the paths of the run's glyphs. The
392 /// rect origin will match the drawn position of the requested range;
393 /// that is, it will be translated by the supplied context's text
394 /// position and the positions of the individual glyphs. If the run
395 /// or range is invalid, CGRectNull will be returned.
396 ///
397 ///
398 /// See also: CTRunGetTypographicBounds
399 #[cfg(feature = "objc2-core-graphics")]
400 pub fn CTRunGetImageBounds(run: &CTRun, context: Option<&CGContext>, range: CFRange) -> CGRect;
401}
402
403extern "C-unwind" {
404 /// Returns the text matrix needed to draw this run.
405 ///
406 ///
407 /// To properly draw the glyphs in a run, the fields 'tx' and 'ty' of
408 /// the CGAffineTransform returned by this function should be set to
409 /// the current text position.
410 ///
411 ///
412 /// Parameter `run`: The run object from which to get the text matrix.
413 ///
414 ///
415 /// Returns: A CGAffineTransform.
416 pub fn CTRunGetTextMatrix(run: &CTRun) -> CGAffineTransform;
417}
418
419extern "C-unwind" {
420 /// Copies a range of base advances and/or origins into user-provided
421 /// buffers.
422 ///
423 ///
424 /// A run's base advances and origins determine the positions of its
425 /// glyphs but require additional processing before being used for
426 /// drawing. Similar to the advances returned by CTRunGetAdvances,
427 /// base advances are the displacement from the origin of a glyph
428 /// to the origin of the next glyph, except base advances do not
429 /// include any positioning the font layout tables may have done
430 /// relative to another glyph (such as a mark relative to its base).
431 /// The actual position of the current glyph is determined by the
432 /// displacement of its origin from the starting position, and the
433 /// position of the next glyph by the displacement of the current
434 /// glyph's base advance from the starting position.
435 ///
436 ///
437 /// Parameter `runRef`: The run whose base advances and/or origins you wish to copy.
438 ///
439 ///
440 /// Parameter `range`: The range of values to be copied. If the length of the
441 /// range is set to 0, then the copy operation will continue from the
442 /// range's start index to the end of the run.
443 ///
444 ///
445 /// Parameter `advancesBuffer`: The buffer where the base advances will be copied to, or NULL.
446 /// If not NULL, the buffer must allow for at least as many elements
447 /// as specified by the range's length.
448 ///
449 ///
450 /// Parameter `originsBuffer`: The buffer where the origins will be copied to, or NULL. If not
451 /// NULL, the buffer must allow for at least as many elements as
452 /// specified by the range's length.
453 pub fn CTRunGetBaseAdvancesAndOrigins(
454 run_ref: &CTRun,
455 range: CFRange,
456 advances_buffer: *mut CGSize,
457 origins_buffer: *mut CGPoint,
458 );
459}
460
461extern "C-unwind" {
462 /// Draws a complete run or part of one.
463 ///
464 ///
465 /// This is a convenience call, since the run could also be drawn by
466 /// accessing its glyphs, positions, and text matrix. Unlike when
467 /// drawing the entire line containing the run with CTLineDraw, the
468 /// run's underline (if any) will not be drawn, since the underline's
469 /// appearance may depend on other runs in the line. This call may
470 /// leave the graphics context in any state and does not flush the
471 /// context after drawing. This call also expects a text matrix with
472 /// `y` values increasing from bottom to top; a flipped text matrix
473 /// may result in misplaced diacritics.
474 ///
475 ///
476 /// Parameter `run`: The run that you want to draw.
477 ///
478 ///
479 /// Parameter `context`: The context to draw the run to.
480 ///
481 ///
482 /// Parameter `range`: The range of glyphs to be drawn, with the entire range having a
483 /// location of 0 and a length of CTRunGetGlyphCount. If the length
484 /// of the range is set to 0, then the operation will continue from
485 /// the range's start index to the end of the run.
486 #[cfg(feature = "objc2-core-graphics")]
487 pub fn CTRunDraw(run: &CTRun, context: &CGContext, range: CFRange);
488}