/packages/univint/src/CTTypesetter.pas
Pascal | 420 lines | 18 code | 54 blank | 348 comment | 0 complexity | 6cab0f8630fd5af33cab509ca8f57969 MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1, LGPL-3.0
1{ 2 * CTTypesetter.h 3 * CoreText 4 * 5 * Copyright (c) 2003-2012 Apple Inc. All rights reserved. 6 * 7 } 8{ Initial Pascal Translation: Jonas Maebe, <jonas@freepascal.org>, October 2009 } 9{ Pascal Translation Updated: Jonas Maebe, <jonas@freepascal.org>, October 2012 } 10{ 11 Modified for use with Free Pascal 12 Version 308 13 Please report any bugs to <gpc@microbizz.nl> 14} 15 16{$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE} 17{$mode macpas} 18{$packenum 1} 19{$macro on} 20{$inline on} 21{$calling mwpascal} 22 23unit CTTypesetter; 24interface 25{$setc UNIVERSAL_INTERFACES_VERSION := $0400} 26{$setc GAP_INTERFACES_VERSION := $0308} 27 28{$ifc not defined USE_CFSTR_CONSTANT_MACROS} 29 {$setc USE_CFSTR_CONSTANT_MACROS := TRUE} 30{$endc} 31 32{$ifc defined CPUPOWERPC and defined CPUI386} 33 {$error Conflicting initial definitions for CPUPOWERPC and CPUI386} 34{$endc} 35{$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN} 36 {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN} 37{$endc} 38 39{$ifc not defined __ppc__ and defined CPUPOWERPC32} 40 {$setc __ppc__ := 1} 41{$elsec} 42 {$setc __ppc__ := 0} 43{$endc} 44{$ifc not defined __ppc64__ and defined CPUPOWERPC64} 45 {$setc __ppc64__ := 1} 46{$elsec} 47 {$setc __ppc64__ := 0} 48{$endc} 49{$ifc not defined __i386__ and defined CPUI386} 50 {$setc __i386__ := 1} 51{$elsec} 52 {$setc __i386__ := 0} 53{$endc} 54{$ifc not defined __x86_64__ and defined CPUX86_64} 55 {$setc __x86_64__ := 1} 56{$elsec} 57 {$setc __x86_64__ := 0} 58{$endc} 59{$ifc not defined __arm__ and defined CPUARM} 60 {$setc __arm__ := 1} 61{$elsec} 62 {$setc __arm__ := 0} 63{$endc} 64 65{$ifc defined cpu64} 66 {$setc __LP64__ := 1} 67{$elsec} 68 {$setc __LP64__ := 0} 69{$endc} 70 71 72{$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__} 73 {$error Conflicting definitions for __ppc__ and __i386__} 74{$endc} 75 76{$ifc defined __ppc__ and __ppc__} 77 {$setc TARGET_CPU_PPC := TRUE} 78 {$setc TARGET_CPU_PPC64 := FALSE} 79 {$setc TARGET_CPU_X86 := FALSE} 80 {$setc TARGET_CPU_X86_64 := FALSE} 81 {$setc TARGET_CPU_ARM := FALSE} 82 {$setc TARGET_OS_MAC := TRUE} 83 {$setc TARGET_OS_IPHONE := FALSE} 84 {$setc TARGET_IPHONE_SIMULATOR := FALSE} 85 {$setc TARGET_OS_EMBEDDED := FALSE} 86{$elifc defined __ppc64__ and __ppc64__} 87 {$setc TARGET_CPU_PPC := FALSE} 88 {$setc TARGET_CPU_PPC64 := TRUE} 89 {$setc TARGET_CPU_X86 := FALSE} 90 {$setc TARGET_CPU_X86_64 := FALSE} 91 {$setc TARGET_CPU_ARM := FALSE} 92 {$setc TARGET_OS_MAC := TRUE} 93 {$setc TARGET_OS_IPHONE := FALSE} 94 {$setc TARGET_IPHONE_SIMULATOR := FALSE} 95 {$setc TARGET_OS_EMBEDDED := FALSE} 96{$elifc defined __i386__ and __i386__} 97 {$setc TARGET_CPU_PPC := FALSE} 98 {$setc TARGET_CPU_PPC64 := FALSE} 99 {$setc TARGET_CPU_X86 := TRUE} 100 {$setc TARGET_CPU_X86_64 := FALSE} 101 {$setc TARGET_CPU_ARM := FALSE} 102{$ifc defined(iphonesim)} 103 {$setc TARGET_OS_MAC := FALSE} 104 {$setc TARGET_OS_IPHONE := TRUE} 105 {$setc TARGET_IPHONE_SIMULATOR := TRUE} 106{$elsec} 107 {$setc TARGET_OS_MAC := TRUE} 108 {$setc TARGET_OS_IPHONE := FALSE} 109 {$setc TARGET_IPHONE_SIMULATOR := FALSE} 110{$endc} 111 {$setc TARGET_OS_EMBEDDED := FALSE} 112{$elifc defined __x86_64__ and __x86_64__} 113 {$setc TARGET_CPU_PPC := FALSE} 114 {$setc TARGET_CPU_PPC64 := FALSE} 115 {$setc TARGET_CPU_X86 := FALSE} 116 {$setc TARGET_CPU_X86_64 := TRUE} 117 {$setc TARGET_CPU_ARM := FALSE} 118 {$setc TARGET_OS_MAC := TRUE} 119 {$setc TARGET_OS_IPHONE := FALSE} 120 {$setc TARGET_IPHONE_SIMULATOR := FALSE} 121 {$setc TARGET_OS_EMBEDDED := FALSE} 122{$elifc defined __arm__ and __arm__} 123 {$setc TARGET_CPU_PPC := FALSE} 124 {$setc TARGET_CPU_PPC64 := FALSE} 125 {$setc TARGET_CPU_X86 := FALSE} 126 {$setc TARGET_CPU_X86_64 := FALSE} 127 {$setc TARGET_CPU_ARM := TRUE} 128 { will require compiler define when/if other Apple devices with ARM cpus ship } 129 {$setc TARGET_OS_MAC := FALSE} 130 {$setc TARGET_OS_IPHONE := TRUE} 131 {$setc TARGET_IPHONE_SIMULATOR := FALSE} 132 {$setc TARGET_OS_EMBEDDED := TRUE} 133{$elsec} 134 {$error __ppc__ nor __ppc64__ nor __i386__ nor __x86_64__ nor __arm__ is defined.} 135{$endc} 136 137{$ifc defined __LP64__ and __LP64__ } 138 {$setc TARGET_CPU_64 := TRUE} 139{$elsec} 140 {$setc TARGET_CPU_64 := FALSE} 141{$endc} 142 143{$ifc defined FPC_BIG_ENDIAN} 144 {$setc TARGET_RT_BIG_ENDIAN := TRUE} 145 {$setc TARGET_RT_LITTLE_ENDIAN := FALSE} 146{$elifc defined FPC_LITTLE_ENDIAN} 147 {$setc TARGET_RT_BIG_ENDIAN := FALSE} 148 {$setc TARGET_RT_LITTLE_ENDIAN := TRUE} 149{$elsec} 150 {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.} 151{$endc} 152{$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE} 153{$setc CALL_NOT_IN_CARBON := FALSE} 154{$setc OLDROUTINENAMES := FALSE} 155{$setc OPAQUE_TOOLBOX_STRUCTS := TRUE} 156{$setc OPAQUE_UPP_TYPES := TRUE} 157{$setc OTCARBONAPPLICATION := TRUE} 158{$setc OTKERNEL := FALSE} 159{$setc PM_USE_SESSION_APIS := TRUE} 160{$setc TARGET_API_MAC_CARBON := TRUE} 161{$setc TARGET_API_MAC_OS8 := FALSE} 162{$setc TARGET_API_MAC_OSX := TRUE} 163{$setc TARGET_CARBON := TRUE} 164{$setc TARGET_CPU_68K := FALSE} 165{$setc TARGET_CPU_MIPS := FALSE} 166{$setc TARGET_CPU_SPARC := FALSE} 167{$setc TARGET_OS_UNIX := FALSE} 168{$setc TARGET_OS_WIN32 := FALSE} 169{$setc TARGET_RT_MAC_68881 := FALSE} 170{$setc TARGET_RT_MAC_CFM := FALSE} 171{$setc TARGET_RT_MAC_MACHO := TRUE} 172{$setc TYPED_FUNCTION_POINTERS := TRUE} 173{$setc TYPE_BOOL := FALSE} 174{$setc TYPE_EXTENDED := FALSE} 175{$setc TYPE_LONGLONG := TRUE} 176uses MacTypes,CTLine,CFBase,CFDictionary,CFAttributedString; 177{$endc} {not MACOSALLINCLUDE} 178 179 180{$ALIGN POWER} 181 182 183{! 184 @header 185 186 Thread Safety Information 187 188 All functions in this header are thread safe unless otherwise specified. 189} 190 191 192{ --------------------------------------------------------------------------- } 193{ Typesetter Types } 194{ --------------------------------------------------------------------------- } 195 196type 197 CTTypesetterRef = ^__CTTypesetter; { an opaque type } 198 __CTTypesetter = record end; 199 200 201{! 202 @function CTTypesetterGetTypeID 203 @abstract Returns the CFType of the typesetter object 204} 205 206function CTTypesetterGetTypeID: CFTypeID; external name '_CTTypesetterGetTypeID'; 207(* CT_AVAILABLE_STARTING( __MAC_10_5, __IPHONE_3_2) *) 208 209 210{ --------------------------------------------------------------------------- } 211{ Typesetter Values } 212{ --------------------------------------------------------------------------- } 213 214{! 215 @const kCTTypesetterOptionDisableBidiProcessing 216 @abstract Disables bidi processing. 217 @discussion Value must be a CFBooleanRef. Default is false. 218 Normally, typesetting applies the Unicode Bidirectional 219 Algorithm as described in UAX #9. If a typesetter is created 220 with this option set to true, no directional reordering is 221 performed and any directional control characters are ignored. 222} 223 224var kCTTypesetterOptionDisableBidiProcessing: CFStringRef; external name '_kCTTypesetterOptionDisableBidiProcessing'; (* attribute const *) 225(* CT_AVAILABLE_BUT_DEPRECATED( __MAC_10_5, __MAC_10_8, __IPHONE_3_2, __IPHONE_6_0) *) 226 227{! 228 @const kCTTypesetterOptionForcedEmbeddingLevel 229 @abstract Specifies the embedding level. 230 @discussion Value must be a CFNumberRef. Default is unset. Normally, 231 typesetting applies the Unicode Bidirectional Algorithm as 232 described in UAX #9. If present, this specifies the embedding 233 level and any directional control characters are ignored. 234} 235 236var kCTTypesetterOptionForcedEmbeddingLevel: CFStringRef; external name '_kCTTypesetterOptionForcedEmbeddingLevel'; (* attribute const *) 237(* CT_AVAILABLE_STARTING( __MAC_10_5, __IPHONE_3_2) *) 238 239 240{ --------------------------------------------------------------------------- } 241{ Typesetter Creation } 242{ --------------------------------------------------------------------------- } 243 244{! 245 @function CTTypesetterCreateWithAttributedString 246 @abstract Creates an immutable typesetter object using an attributed 247 string. 248 249 @discussion The resultant typesetter can be used to create lines, perform 250 line breaking, and do other contextual analysis based on the 251 characters in the string. 252 253 @param string 254 The CFAttributedStringRef that you want to typeset. This 255 parameter must be filled in with a valid CFAttributedString. 256 257 @result This function will return a reference to a CTTypesetter if the 258 call was successful. Otherwise, it will return NULL. 259} 260 261function CTTypesetterCreateWithAttributedString( strng: CFAttributedStringRef ): CTTypesetterRef; external name '_CTTypesetterCreateWithAttributedString'; 262(* CT_AVAILABLE_STARTING( __MAC_10_5, __IPHONE_3_2) *) 263 264 265{! 266 @function CTTypesetterCreateWithAttributedStringAndOptions 267 @abstract Creates an immutable typesetter object using an attributed 268 string and a dictionary of options. 269 270 @discussion The resultant typesetter can be used to create lines, perform 271 line breaking, and do other contextual analysis based on the 272 characters in the string. 273 274 @param string 275 The CFAttributedStringRef that you want to typeset. This 276 parameter must be filled in with a valid CFAttributedString. 277 278 @param options 279 A CFDictionary of typesetter options, or NULL if there are none. 280 281 @result This function will return a reference to a CTTypesetter if the 282 call was successful. Otherwise, it will return NULL. 283} 284 285function CTTypesetterCreateWithAttributedStringAndOptions( strng: CFAttributedStringRef; options: CFDictionaryRef ): CTTypesetterRef; external name '_CTTypesetterCreateWithAttributedStringAndOptions'; 286(* CT_AVAILABLE_STARTING( __MAC_10_5, __IPHONE_3_2) *) 287 288 289{ --------------------------------------------------------------------------- } 290{ Typeset Line Creation } 291{ --------------------------------------------------------------------------- } 292 293{! 294 @function CTTypesetterCreateLineWithOffset 295 @abstract Creates an immutable line from the typesetter. 296 297 @discussion The resultant line will consist of glyphs in the correct visual 298 order, ready to draw. 299 300 @param typesetter 301 The typesetter which the line will come from. This parameter is 302 required and cannot be set to NULL. 303 304 @param stringRange 305 The string range which the line will be based on. If the length 306 portion of range is set to 0, then the typesetter will continue 307 to add glyphs to the line until it runs out of characters in the 308 string. The location and length of the range must be within the 309 bounds of the string, othewise the call will fail. 310 311 @param offset 312 The line position offset. 313 314 @result This function will return a reference to a CTLine if the call was 315 successful. Otherwise, it will return NULL. 316} 317 318function CTTypesetterCreateLineWithOffset( typesetter: CTTypesetterRef; stringRange: CFRange; offset: Float64 ): CTLineRef; external name '_CTTypesetterCreateLineWithOffset'; 319(* CT_AVAILABLE_STARTING( __MAC_10_6, __IPHONE_3_2) *) 320 321{! 322 @function CTTypesetterCreateLine 323 @abstract Equivalent to CTTypesetterCreateLineWithOffset with offset = 0.0. 324} 325 326function CTTypesetterCreateLine( typesetter: CTTypesetterRef; stringRange: CFRange ): CTLineRef; external name '_CTTypesetterCreateLine'; 327(* CT_AVAILABLE_STARTING( __MAC_10_5, __IPHONE_3_2) *) 328 329 330{ --------------------------------------------------------------------------- } 331{ Typeset Line Breaking } 332{ --------------------------------------------------------------------------- } 333 334{! 335 @function CTTypesetterSuggestLineBreakWithOffset 336 @abstract Suggests a contextual line break point based on the width 337 provided. 338 339 @discussion The line break can be triggered either by a hard break character 340 in the stream or by filling the specified width with characters. 341 342 @param typesetter 343 The typesetter which the line will come from. This parameter is 344 required and cannot be set to NULL. 345 346 @param startIndex 347 The starting point for the line break calculations. The break 348 calculations will include the character starting at startIndex. 349 350 @param width 351 The requested line break width. 352 353 @param offset 354 The line position offset. 355 356 @result The value returned is a count of the characters from startIndex 357 that would cause the line break. This value returned can be used 358 to construct a character range for CTTypesetterCreateLine. 359} 360 361function CTTypesetterSuggestLineBreakWithOffset( typesetter: CTTypesetterRef; startIndex: CFIndex; width: Float64; offset: Float64 ): CFIndex; external name '_CTTypesetterSuggestLineBreakWithOffset'; 362(* CT_AVAILABLE_STARTING( __MAC_10_6, __IPHONE_3_2) *) 363 364{! 365 @function CTTypesetterSuggestLineBreak 366 @abstract Equivalent to CTTypesetterSuggestLineBreakWithOffset with offset = 0.0. 367} 368 369function CTTypesetterSuggestLineBreak( typesetter: CTTypesetterRef; startIndex: CFIndex; width: Float64 ): CFIndex; external name '_CTTypesetterSuggestLineBreak'; 370(* CT_AVAILABLE_STARTING( __MAC_10_5, __IPHONE_3_2) *) 371 372 373{! 374 @function CTTypesetterSuggestClusterBreakWithOffset 375 @abstract Suggests a cluster line break point based on the width provided. 376 377 @discussion Suggests a typographic cluster line break point based on the width 378 provided. This cluster break is similar to a character break, 379 except that it will not break apart linguistic clusters. No other 380 contextual analysis will be done. This can be used by the caller 381 to implement a different line breaking scheme, such as 382 hyphenation. Note that a typographic cluster break can also be 383 triggered by a hard break character in the stream. 384 385 @param typesetter 386 The typesetter which the line will come from. This parameter is 387 required and cannot be set to NULL. 388 389 @param startIndex 390 The starting point for the typographic cluster break 391 calculations. The break calculations will include the character 392 starting at startIndex. 393 394 @param width 395 The requested typographic cluster break width. 396 397 @param offset 398 The line position offset. 399 400 @result The value returned is a count of the characters from startIndex 401 that would cause the cluster break. This value returned can be 402 used to construct a character range for CTTypesetterCreateLine. 403} 404 405function CTTypesetterSuggestClusterBreakWithOffset( typesetter: CTTypesetterRef; startIndex: CFIndex; width: Float64; offset: Float64 ): CFIndex; external name '_CTTypesetterSuggestClusterBreakWithOffset'; 406(* CT_AVAILABLE_STARTING( __MAC_10_6, __IPHONE_3_2) *) 407 408 409{! 410 @function CTTypesetterSuggestClusterBreak 411 @abstract Equivalent to CTTypesetterSuggestClusterBreakWithOffset with offset = 0.0. 412} 413 414function CTTypesetterSuggestClusterBreak( typesetter: CTTypesetterRef; startIndex: CFIndex; width: Float64 ): CFIndex; external name '_CTTypesetterSuggestClusterBreak'; 415(* CT_AVAILABLE_STARTING( __MAC_10_5, __IPHONE_3_2) *) 416 417{$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE} 418 419end. 420{$endc} {not MACOSALLINCLUDE}