/packages/univint/src/CTFrame.pas

https://github.com/slibre/freepascal · Pascal · 492 lines · 30 code · 63 blank · 399 comment · 0 complexity · 280ff82ee6bcf00c92bf12ade5bc5967 MD5 · raw file

  1. {
  2. * CTFrame.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 CTFrame;
  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,CFArray,CFDictionary,CFBase,CFNumber,CFString,CGContext,CGGeometry,CGPath;
  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. { Frame Types }
  175. { --------------------------------------------------------------------------- }
  176. type
  177. CTFrameRef = ^__CTFrame; { an opaque type }
  178. __CTFrame = record end;
  179. {!
  180. @function CTFrameGetTypeID
  181. @abstract Returns the CFType of the frame object
  182. }
  183. function CTFrameGetTypeID: CFTypeID; external name '_CTFrameGetTypeID';
  184. (* CT_AVAILABLE_STARTING( __MAC_10_5, __IPHONE_3_2) *)
  185. { --------------------------------------------------------------------------- }
  186. { Frame Values }
  187. { --------------------------------------------------------------------------- }
  188. {!
  189. @enum CTFrameProgression
  190. @abstract These constants specify frame progression types.
  191. @discussion The lines of text within a frame may be stacked for either
  192. horizontal or vertical text. Values are enumerated for each
  193. stacking type supported by CTFrame. Frames created with a
  194. progression type specifying vertical text will rotate lines
  195. 90 degrees counterclockwise when drawing.
  196. @constant kCTFrameProgressionTopToBottom
  197. Lines are stacked top to bottom for horizontal text.
  198. @constant kCTFrameProgressionRightToLeft
  199. Lines are stacked right to left for vertical text.
  200. }
  201. const
  202. kCTFrameProgressionTopToBottom = 0;
  203. kCTFrameProgressionRightToLeft = 1;
  204. type
  205. CTFrameProgression = UInt32;
  206. {!
  207. @const kCTFrameProgressionAttributeName
  208. @abstract Specifies progression for a frame.
  209. @discussion Value must be a CFNumberRef containing a CTFrameProgression.
  210. Default is kCTFrameProgressionTopToBottom. This value determines
  211. the line stacking behavior for a frame and does not affect the
  212. appearance of the glyphs within that frame.
  213. @seealso CTFramesetterCreateFrame
  214. }
  215. var kCTFrameProgressionAttributeName: CFStringRef; external name '_kCTFrameProgressionAttributeName'; (* attribute const *)
  216. (* CT_AVAILABLE_STARTING( __MAC_10_5, __IPHONE_3_2) *)
  217. {!
  218. @enum CTFramePathFillRule
  219. @abstract These constants specify fill rule used by the frame.
  220. @discussion When a path intersects with itself, the client should specify which rule to use for deciding the
  221. area of the path.
  222. @constant kCTFramePathFillEvenOdd
  223. Text is filled in the area that would be painted if the path were given to CGContextEOFillPath.
  224. @constant kCTFramePathFillWindingNumber
  225. Text is fill in the area that would be painted if the path were given to CGContextFillPath.
  226. }
  227. const
  228. kCTFramePathFillEvenOdd = 0;
  229. kCTFramePathFillWindingNumber = 1;
  230. type
  231. CTFramePathFillRule = UInt32;
  232. {!
  233. @const kCTFramePathFillRuleAttributeName
  234. @abstract Specifies fill rule for a frame if this attribute is used at top level of frameAttributes dictionary, or specify
  235. fill rule for a clipping path if used in a dictionary contained in an array specified by kCTFrameClippingPathsAttributeName.
  236. @discussion Value must be a CFNumberRef containing kCTFramePathFillEvenOdd or kCTFramePathFillWindingNumber.
  237. Default is kCTFramePathFillEvenOdd.
  238. @seealso CTFramesetterCreateFrame
  239. }
  240. var kCTFramePathFillRuleAttributeName: CFStringRef; external name '_kCTFramePathFillRuleAttributeName'; (* attribute const *)
  241. (* CT_AVAILABLE_STARTING( __MAC_10_7, __IPHONE_4_2) *)
  242. {!
  243. @const kCTFramePathWidthAttributeName
  244. @abstract Specifies frame width if this attribute is used at top level of frameAttributes dictionary, or specify
  245. clipping path width if used in a dictionary contained in an array specified by kCTFrameClippingPathsAttributeName.
  246. @discussion Value must be a CFNumberRef specifying frame width.
  247. Default is zero.
  248. @seealso CTFramesetterCreateFrame
  249. }
  250. var kCTFramePathWidthAttributeName: CFStringRef; external name '_kCTFramePathWidthAttributeName'; (* attribute const *)
  251. (* CT_AVAILABLE_STARTING( __MAC_10_7, __IPHONE_4_2) *)
  252. {!
  253. @const kCTFrameClippingPathsAttributeName
  254. @abstract Specifies array of paths to clip frame.
  255. @discussion Value must be a CFArrayRef containing CFDictionaryRefs or CGPathRef. (CGPathRef is allowed on 10.8 or later.)
  256. Each dictionary should have a kCTFramePathClippingPathAttributeName key-value pair, and can have a kCTFramePathFillRuleAttributeName key-value pair
  257. and kCTFramePathFillRuleAttributeName key-value pair as optional parameters. In case of CGPathRef, default fill rule (kCTFramePathFillEvenOdd) and width (0.0) are used.
  258. @seealso CTFramesetterCreateFrame
  259. }
  260. var kCTFrameClippingPathsAttributeName: CFStringRef; external name '_kCTFrameClippingPathsAttributeName'; (* attribute const *)
  261. (* CT_AVAILABLE_STARTING( __MAC_10_7, __IPHONE_4_3) *)
  262. {!
  263. @const kCTFramePathClippingPathAttributeName
  264. @abstract Specifies clipping path. This attribute is valid in a dictionary contained in an array specified by kCTFrameClippingPathsAttributeName.
  265. On 10.8 or later, This attribute is also valid in frameAttributes dictionary passed to CTFramesetterCreateFrame.
  266. @discussion Value must be a CGPathRef specifying a clipping pat.
  267. @seealso kCTFrameClippingPathsAttributeName
  268. }
  269. var kCTFramePathClippingPathAttributeName: CFStringRef; external name '_kCTFramePathClippingPathAttributeName'; (* attribute const *)
  270. (* CT_AVAILABLE_STARTING( __MAC_10_7, __IPHONE_4_3) *)
  271. { --------------------------------------------------------------------------- }
  272. { Frame Accessors }
  273. { --------------------------------------------------------------------------- }
  274. {!
  275. @function CTFrameGetStringRange
  276. @abstract Returns the range of characters that were originally requested
  277. to fill the frame.
  278. @param frame
  279. The frame that you want to get the character range from.
  280. @result This function will return a CFRange containing the backing
  281. store range of characters that were originally requested
  282. to fill the frame. If the function call is not successful,
  283. then an empty range will be returned.
  284. }
  285. function CTFrameGetStringRange( frame: CTFrameRef ): CFRange; external name '_CTFrameGetStringRange';
  286. (* CT_AVAILABLE_STARTING( __MAC_10_5, __IPHONE_3_2) *)
  287. {!
  288. @function CTFrameGetVisibleStringRange
  289. @abstract Returns the range of characters that actually fit in the
  290. frame.
  291. @discussion This can be used to cascade frames, as it returns the range of
  292. characters that can be seen in the frame. The next frame would
  293. start where this frame ends.
  294. @param frame
  295. The frame that you want to get the visible character range
  296. from.
  297. @result This function will return a CFRange containing the backing
  298. store range of characters that fit into the frame. If the
  299. function call is not successful, or if no characters fit
  300. in the frame, then an empty range will be returned.
  301. }
  302. function CTFrameGetVisibleStringRange( frame: CTFrameRef ): CFRange; external name '_CTFrameGetVisibleStringRange';
  303. (* CT_AVAILABLE_STARTING( __MAC_10_5, __IPHONE_3_2) *)
  304. {!
  305. @function CTFrameGetPath
  306. @abstract Returns the path used to create the frame.
  307. @param frame
  308. The frame that you want to obtain the path from.
  309. }
  310. function CTFrameGetPath( frame: CTFrameRef ): CGPathRef; external name '_CTFrameGetPath';
  311. (* CT_AVAILABLE_STARTING( __MAC_10_5, __IPHONE_3_2) *)
  312. {!
  313. @function CTFrameGetFrameAttributes
  314. @abstract Returns the frame attributes used to create the frame.
  315. @discussion It is possible to create a frame with an attributes dictionary
  316. in order to control various aspects of the framing process.
  317. These attributes are different from the ones that are used to
  318. create an attributed string.
  319. @param frame
  320. The frame that you want to obtain the frame attributes from.
  321. @result This function will return a CFDictionary containing the
  322. frame attributes that were used to create the frame. If the
  323. frame was created without any frame attributes, this function
  324. will return NULL.
  325. }
  326. function CTFrameGetFrameAttributes( frame: CTFrameRef ): CFDictionaryRef; external name '_CTFrameGetFrameAttributes';
  327. (* CT_AVAILABLE_STARTING( __MAC_10_5, __IPHONE_3_2) *)
  328. {!
  329. @function CTFrameGetLines
  330. @abstract Returns an array of lines that make up the frame.
  331. @discussion This function will return an array of CTLine objects that are
  332. stored in the frame. These line objects can be accessed and
  333. manipulated in any way that normal line objects can be. It is
  334. possible that an empty frame exists. That is, a frame in which
  335. no lines exist. In this case, the returned array will have 0
  336. entries.
  337. @param frame
  338. The frame that you want to obtain the line array from.
  339. @result This function will return a CFArray object containing the
  340. CTLine objects that make up the frame.
  341. }
  342. function CTFrameGetLines( frame: CTFrameRef ): CFArrayRef; external name '_CTFrameGetLines';
  343. (* CT_AVAILABLE_STARTING( __MAC_10_5, __IPHONE_3_2) *)
  344. {!
  345. @function CTFrameGetLineOrigins
  346. @abstract Copies a range of line origins for a frame.
  347. @discussion This function will copy a range of CGPoint structures. Each
  348. CGPoint is the origin of the corresponding line in the array of
  349. lines returned by CTFrameGetLines, relative to the origin of the
  350. frame's path. The maximum number of line origins returned by
  351. this function is the count of the array of lines.
  352. @param frame
  353. The frame that you want to obtain the line origin array from.
  354. @param range
  355. The range of line origins you wish to copy. If the length of the
  356. range is set to 0, then the copy operation will continue from
  357. the range's start index to the last line origin.
  358. @param origins
  359. The buffer to which the origins will be copied. The buffer must
  360. have at least as many elements as specified by range's length.
  361. When using the origins to calculate measurements for a frame's
  362. contents, remember that line origins do not always correspond to
  363. line metrics; paragraph style settings can affect line origins,
  364. for one. The overall typographic bounds of a frame may generally
  365. be calculated as the difference between the top of the frame and
  366. the descent of the last line. This will obviously exclude any
  367. spacing following the last line, but such spacing has no effect
  368. on framesetting in the first place.
  369. }
  370. procedure CTFrameGetLineOrigins( frame: CTFrameRef; range: CFRange; origins: {variable-size-array} CGPointPtr ); external name '_CTFrameGetLineOrigins';
  371. (* CT_AVAILABLE_STARTING( __MAC_10_5, __IPHONE_3_2) *)
  372. {!
  373. @function CTFrameDraw
  374. @abstract Draws an entire frame to a context.
  375. @discussion This function will draw an entire frame to the context. Note
  376. that this call may leave the context in any state and does not
  377. flush it after the draw operation.
  378. @param frame
  379. The frame that you want to draw.
  380. @param context
  381. The context to draw the frame to.
  382. @result If both the frame and the context are valid, the frame will be
  383. drawn in the context.
  384. }
  385. procedure CTFrameDraw( frame: CTFrameRef; context: CGContextRef ); external name '_CTFrameDraw';
  386. (* CT_AVAILABLE_STARTING( __MAC_10_5, __IPHONE_3_2) *)
  387. {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
  388. end.
  389. {$endc} {not MACOSALLINCLUDE}