/packages/univint/src/CTTypesetter.pas

https://github.com/slibre/freepascal · Pascal · 420 lines · 18 code · 54 blank · 348 comment · 0 complexity · 6cab0f8630fd5af33cab509ca8f57969 MD5 · raw file

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