ATSUnicodeFlattening.pas 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950
  1. {
  2. File: QD/ATSUnicodeFlattening.h
  3. Contains: Public interfaces for Apple Type Services for Unicode Imaging
  4. Version: Quickdraw-285~150
  5. Copyright: © 2002-2008 by Apple Inc. all rights reserved.
  6. Bugs?: For bug reports, consult the following page on
  7. the World Wide Web:
  8. http://bugs.freepascal.org
  9. }
  10. { Pascal Translation: Peter N Lewis, <[email protected]>, 2004 }
  11. { Pascal Translation Updated: Jonas Maebe, <[email protected]>, October 2009 }
  12. { Pascal Translation Updated: Jonas Maebe, <[email protected]>, October 2012 }
  13. {
  14. Modified for use with Free Pascal
  15. Version 308
  16. Please report any bugs to <[email protected]>
  17. }
  18. {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
  19. {$mode macpas}
  20. {$modeswitch cblocks}
  21. {$packenum 1}
  22. {$macro on}
  23. {$inline on}
  24. {$calling mwpascal}
  25. {$IFNDEF FPC_DOTTEDUNITS}
  26. unit ATSUnicodeFlattening;
  27. {$ENDIF FPC_DOTTEDUNITS}
  28. interface
  29. {$setc UNIVERSAL_INTERFACES_VERSION := $0400}
  30. {$setc GAP_INTERFACES_VERSION := $0308}
  31. {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
  32. {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
  33. {$endc}
  34. {$ifc defined CPUPOWERPC and defined CPUI386}
  35. {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
  36. {$endc}
  37. {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
  38. {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
  39. {$endc}
  40. {$ifc not defined __ppc__ and defined CPUPOWERPC32}
  41. {$setc __ppc__ := 1}
  42. {$elsec}
  43. {$setc __ppc__ := 0}
  44. {$endc}
  45. {$ifc not defined __ppc64__ and defined CPUPOWERPC64}
  46. {$setc __ppc64__ := 1}
  47. {$elsec}
  48. {$setc __ppc64__ := 0}
  49. {$endc}
  50. {$ifc not defined __i386__ and defined CPUI386}
  51. {$setc __i386__ := 1}
  52. {$elsec}
  53. {$setc __i386__ := 0}
  54. {$endc}
  55. {$ifc not defined __x86_64__ and defined CPUX86_64}
  56. {$setc __x86_64__ := 1}
  57. {$elsec}
  58. {$setc __x86_64__ := 0}
  59. {$endc}
  60. {$ifc not defined __arm__ and defined CPUARM}
  61. {$setc __arm__ := 1}
  62. {$elsec}
  63. {$setc __arm__ := 0}
  64. {$endc}
  65. {$ifc not defined __arm64__ and defined CPUAARCH64}
  66. {$setc __arm64__ := 1}
  67. {$elsec}
  68. {$setc __arm64__ := 0}
  69. {$endc}
  70. {$ifc defined cpu64}
  71. {$setc __LP64__ := 1}
  72. {$elsec}
  73. {$setc __LP64__ := 0}
  74. {$endc}
  75. {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
  76. {$error Conflicting definitions for __ppc__ and __i386__}
  77. {$endc}
  78. {$ifc defined __ppc__ and __ppc__}
  79. {$setc TARGET_CPU_PPC := TRUE}
  80. {$setc TARGET_CPU_PPC64 := FALSE}
  81. {$setc TARGET_CPU_X86 := FALSE}
  82. {$setc TARGET_CPU_X86_64 := FALSE}
  83. {$setc TARGET_CPU_ARM := FALSE}
  84. {$setc TARGET_CPU_ARM64 := FALSE}
  85. {$setc TARGET_OS_MAC := TRUE}
  86. {$setc TARGET_OS_IPHONE := FALSE}
  87. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  88. {$setc TARGET_OS_EMBEDDED := FALSE}
  89. {$elifc defined __ppc64__ and __ppc64__}
  90. {$setc TARGET_CPU_PPC := FALSE}
  91. {$setc TARGET_CPU_PPC64 := TRUE}
  92. {$setc TARGET_CPU_X86 := FALSE}
  93. {$setc TARGET_CPU_X86_64 := FALSE}
  94. {$setc TARGET_CPU_ARM := FALSE}
  95. {$setc TARGET_CPU_ARM64 := FALSE}
  96. {$setc TARGET_OS_MAC := TRUE}
  97. {$setc TARGET_OS_IPHONE := FALSE}
  98. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  99. {$setc TARGET_OS_EMBEDDED := FALSE}
  100. {$elifc defined __i386__ and __i386__}
  101. {$setc TARGET_CPU_PPC := FALSE}
  102. {$setc TARGET_CPU_PPC64 := FALSE}
  103. {$setc TARGET_CPU_X86 := TRUE}
  104. {$setc TARGET_CPU_X86_64 := FALSE}
  105. {$setc TARGET_CPU_ARM := FALSE}
  106. {$setc TARGET_CPU_ARM64 := FALSE}
  107. {$ifc defined iphonesim}
  108. {$setc TARGET_OS_MAC := FALSE}
  109. {$setc TARGET_OS_IPHONE := TRUE}
  110. {$setc TARGET_IPHONE_SIMULATOR := TRUE}
  111. {$elsec}
  112. {$setc TARGET_OS_MAC := TRUE}
  113. {$setc TARGET_OS_IPHONE := FALSE}
  114. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  115. {$endc}
  116. {$setc TARGET_OS_EMBEDDED := FALSE}
  117. {$elifc defined __x86_64__ and __x86_64__}
  118. {$setc TARGET_CPU_PPC := FALSE}
  119. {$setc TARGET_CPU_PPC64 := FALSE}
  120. {$setc TARGET_CPU_X86 := FALSE}
  121. {$setc TARGET_CPU_X86_64 := TRUE}
  122. {$setc TARGET_CPU_ARM := FALSE}
  123. {$setc TARGET_CPU_ARM64 := FALSE}
  124. {$ifc defined iphonesim}
  125. {$setc TARGET_OS_MAC := FALSE}
  126. {$setc TARGET_OS_IPHONE := TRUE}
  127. {$setc TARGET_IPHONE_SIMULATOR := TRUE}
  128. {$elsec}
  129. {$setc TARGET_OS_MAC := TRUE}
  130. {$setc TARGET_OS_IPHONE := FALSE}
  131. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  132. {$endc}
  133. {$setc TARGET_OS_EMBEDDED := FALSE}
  134. {$elifc defined __arm__ and __arm__}
  135. {$setc TARGET_CPU_PPC := FALSE}
  136. {$setc TARGET_CPU_PPC64 := FALSE}
  137. {$setc TARGET_CPU_X86 := FALSE}
  138. {$setc TARGET_CPU_X86_64 := FALSE}
  139. {$setc TARGET_CPU_ARM := TRUE}
  140. {$setc TARGET_CPU_ARM64 := FALSE}
  141. {$setc TARGET_OS_MAC := FALSE}
  142. {$setc TARGET_OS_IPHONE := TRUE}
  143. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  144. {$setc TARGET_OS_EMBEDDED := TRUE}
  145. {$elifc defined __arm64__ and __arm64__}
  146. {$setc TARGET_CPU_PPC := FALSE}
  147. {$setc TARGET_CPU_PPC64 := FALSE}
  148. {$setc TARGET_CPU_X86 := FALSE}
  149. {$setc TARGET_CPU_X86_64 := FALSE}
  150. {$setc TARGET_CPU_ARM := FALSE}
  151. {$setc TARGET_CPU_ARM64 := TRUE}
  152. {$ifc defined ios}
  153. {$setc TARGET_OS_MAC := FALSE}
  154. {$setc TARGET_OS_IPHONE := TRUE}
  155. {$setc TARGET_OS_EMBEDDED := TRUE}
  156. {$elsec}
  157. {$setc TARGET_OS_MAC := TRUE}
  158. {$setc TARGET_OS_IPHONE := FALSE}
  159. {$setc TARGET_OS_EMBEDDED := FALSE}
  160. {$endc}
  161. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  162. {$elsec}
  163. {$error __ppc__ nor __ppc64__ nor __i386__ nor __x86_64__ nor __arm__ nor __arm64__ is defined.}
  164. {$endc}
  165. {$ifc defined __LP64__ and __LP64__ }
  166. {$setc TARGET_CPU_64 := TRUE}
  167. {$elsec}
  168. {$setc TARGET_CPU_64 := FALSE}
  169. {$endc}
  170. {$ifc defined FPC_BIG_ENDIAN}
  171. {$setc TARGET_RT_BIG_ENDIAN := TRUE}
  172. {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
  173. {$elifc defined FPC_LITTLE_ENDIAN}
  174. {$setc TARGET_RT_BIG_ENDIAN := FALSE}
  175. {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
  176. {$elsec}
  177. {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
  178. {$endc}
  179. {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
  180. {$setc CALL_NOT_IN_CARBON := FALSE}
  181. {$setc OLDROUTINENAMES := FALSE}
  182. {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
  183. {$setc OPAQUE_UPP_TYPES := TRUE}
  184. {$setc OTCARBONAPPLICATION := TRUE}
  185. {$setc OTKERNEL := FALSE}
  186. {$setc PM_USE_SESSION_APIS := TRUE}
  187. {$setc TARGET_API_MAC_CARBON := TRUE}
  188. {$setc TARGET_API_MAC_OS8 := FALSE}
  189. {$setc TARGET_API_MAC_OSX := TRUE}
  190. {$setc TARGET_CARBON := TRUE}
  191. {$setc TARGET_CPU_68K := FALSE}
  192. {$setc TARGET_CPU_MIPS := FALSE}
  193. {$setc TARGET_CPU_SPARC := FALSE}
  194. {$setc TARGET_OS_UNIX := FALSE}
  195. {$setc TARGET_OS_WIN32 := FALSE}
  196. {$setc TARGET_RT_MAC_68881 := FALSE}
  197. {$setc TARGET_RT_MAC_CFM := FALSE}
  198. {$setc TARGET_RT_MAC_MACHO := TRUE}
  199. {$setc TYPED_FUNCTION_POINTERS := TRUE}
  200. {$setc TYPE_BOOL := FALSE}
  201. {$setc TYPE_EXTENDED := FALSE}
  202. {$setc TYPE_LONGLONG := TRUE}
  203. {$IFDEF FPC_DOTTEDUNITS}
  204. uses MacOsApi.MacTypes,MacOsApi.ATSUnicodeTypes,MacOsApi.SFNTTypes;
  205. {$ELSE FPC_DOTTEDUNITS}
  206. uses MacTypes,ATSUnicodeTypes,SFNTTypes;
  207. {$ENDIF FPC_DOTTEDUNITS}
  208. {$endc} {not MACOSALLINCLUDE}
  209. {$ifc TARGET_OS_MAC}
  210. { ---------------------------------------------------------------------------- }
  211. { Constants }
  212. { ---------------------------------------------------------------------------- }
  213. {
  214. ATSUFlattenedDataStreamFormat is used to inform the APIs which flatten and
  215. unflatten style runs exactly what type of data that they should be generating
  216. or parsing.
  217. }
  218. {$ALIGN MAC68K}
  219. type
  220. ATSUFlattenedDataStreamFormat = UInt32;
  221. const
  222. kATSUDataStreamUnicodeStyledText = FourCharCode('ustl');
  223. {
  224. ATSUFlattenStyleRunOptions is a bitfield list of options that can be passed
  225. into the ATSUFlattenStyleRunsToStream API. Currently, there are no options.
  226. This is here for future expansion.
  227. }
  228. type
  229. ATSUFlattenStyleRunOptions = UInt32;
  230. const
  231. kATSUFlattenOptionNoOptionsMask = $00000000;
  232. {
  233. ATSUUnFlattenStyleRunOptions is a bitfield list of options that can be passed
  234. into the ATSUUnFlattenStyleRunsToStream API. Currently, there are no options.
  235. This is here for future expansion.
  236. }
  237. type
  238. ATSUUnFlattenStyleRunOptions = UInt32;
  239. const
  240. kATSUUnFlattenOptionNoOptionsMask = $00000000;
  241. { ---------------------------------------------------------------------------- }
  242. { Data Types }
  243. { ---------------------------------------------------------------------------- }
  244. {
  245. ATSUStyleRunInfo is a structure that contains an index into an array of
  246. unique ATSUStyle objects as well as the length of the run that the style run
  247. object covers. This structure is utilized by ATSUUnflattenStyleRunsFromStream()
  248. to return the style run info to the caller.
  249. }
  250. type
  251. ATSUStyleRunInfo = record
  252. runLength: UInt32;
  253. styleObjectIndex: UInt32;
  254. end;
  255. ATSUStyleRunInfoPtr = ^ATSUStyleRunInfo;
  256. { ---------------------------------------------------------------------------- }
  257. { 'ustl' structure data structures and definitions }
  258. { ---------------------------------------------------------------------------- }
  259. {
  260. The 'ustl' data structure follows this format:
  261. 1. Main Data Structure Block Header
  262. 2. Flattened Text Layout Data
  263. 3. Flattened Style Run Data
  264. 4. Flattened Style Data
  265. Per the 'ustl' spec, these structures should maintain four-byte alignment.
  266. For things that are variable width (such as font names), padding bytes must
  267. be added to ensure that this alignment is always kept.
  268. }
  269. {
  270. structure versioning - the version of the 'ustl' that the ATSUI parsing
  271. and generating functions will handle is version 2 or greater. Earlier
  272. versions were not completly specified and have been obsoleted.
  273. }
  274. const
  275. kATSFlatDataUstlVersion0 = 0;
  276. kATSFlatDataUstlVersion1 = 1;
  277. kATSFlatDataUstlVersion2 = 2;
  278. kATSFlatDataUstlCurrentVersion = kATSFlatDataUstlVersion2;
  279. { ------------------ }
  280. { Block 1 Structures }
  281. { ------------------ }
  282. {
  283. This is the main data structure block header. It describes the rest
  284. of the data and how it is structured.
  285. }
  286. type
  287. ATSFlatDataMainHeaderBlock = record
  288. { the 'ustl' version number. This needs to be the first item in the}
  289. { data block do as not to confuse parsers of earlier (and possibly}
  290. { later) versions of the spec *|}
  291. version: UInt32;
  292. { the total size of the stream in bytes, including the four bytes in}
  293. { the version above}
  294. sizeOfDataBlock: UInt32;
  295. { offset from the beginning of the stream to the flattened text layout data.}
  296. { This can be set to 0 if there are no text layouts stored in the stream.}
  297. offsetToTextLayouts: UInt32;
  298. { offset from the beginning of the stream to the flattened style run data. }
  299. { This can be set to 0 if there is no flattened style run data in the stream}
  300. offsetToStyleRuns: UInt32;
  301. { offset to the flattened style list data. This can be set to 0 if there}
  302. { is no flattened style list data}
  303. offsetToStyleList: UInt32;
  304. end;
  305. ATSFlatDataMainHeaderBlockPtr = ^ATSFlatDataMainHeaderBlock;
  306. { ------------------ }
  307. { Block 2 Structures }
  308. { ------------------ }
  309. {
  310. The Block 2 Structures are not currently used by any of ATSUI's internal parsing
  311. or packing routines. They are, however, part of the 'ustl' standard and are put
  312. here for developer conveniance, as well as to properly define the standard.
  313. }
  314. {
  315. This is the header that is attached to each flattened text layout. The
  316. number of flattened text layouts in the stucture is specified by the
  317. ATSFlatDataTextLayoutHeader structure that is below.
  318. }
  319. type
  320. ATSFlatDataTextLayoutDataHeader = record
  321. { the total size of this particular flattened text layout, including any}
  322. { padding bytes and such. }
  323. sizeOfLayoutData: UInt32;
  324. { the number of characters covered by this flattened text layout}
  325. textLayoutLength: UInt32;
  326. { the byte offset relative to the start of this structure to the flattened}
  327. { layout control data. This can be set to zero if there are no layout}
  328. { controls.}
  329. offsetToLayoutControls: UInt32;
  330. { the byte offset, relative to the start of this structure to the}
  331. { flattened line info. This can be set to zero if there is no line info }
  332. { in this layout.}
  333. offsetToLineInfo: UInt32;
  334. { if the offsetToLayoutControls is non-zero, then following this block}
  335. { there will be a ATSFlattenedLayoutDataFlattenedLayoutControlsHeader}
  336. { followed by an array of ATSFlattenedLayoutDataFlattenedLayoutControls}
  337. { structures. If the offsetToLineInfo is non-zero, then following the}
  338. { flattened layout controls will be a ATSFlatDataLineInfoHeader}
  339. { structure.}
  340. end;
  341. ATSFlatDataTextLayoutDataHeaderPtr = ^ATSFlatDataTextLayoutDataHeader;
  342. {
  343. This is the the main header for block 2. If there is a block 2, then there
  344. needs to be one of these. This structure is what the offsetToTextLayouts
  345. points to in block 1.
  346. }
  347. type
  348. ATSFlatDataTextLayoutHeader = record
  349. { the total number of flattened text layouts stored in this block.}
  350. { This must be non-zero, as if there were no flattened text layouts, the}
  351. { entire block 2 would not exist}
  352. numFlattenedTextLayouts: UInt32;
  353. { first of possibly many flattened text layouts. There should be one of}
  354. { these for each flattened text layout as determined by the}
  355. { numFlattenedTextLayouts above. }
  356. flattenedTextLayouts: array[0..0] of ATSFlatDataTextLayoutDataHeader;
  357. end;
  358. ATSFlatDataTextLayoutHeaderPtr = ^ATSFlatDataTextLayoutHeader;
  359. {
  360. This is the header for the flattened layout controls structure. This is
  361. the structure that a non-zero offsetToLayoutControls points to in the
  362. ATSFlatDataTextLayoutDataHeader
  363. }
  364. type
  365. ATSFlatDataLayoutControlsDataHeader = record
  366. { the number of flattened layout controls. It is suggested that there be}
  367. { at least one layout control to output the line direction for the layout}
  368. numberOfLayoutControls: UInt32;
  369. { first of possibly many flattened layout controls. There should be one }
  370. { of these for each layout control as determined by the}
  371. { numberOfLayoutControls above. Of course, if there are no layout controls,}
  372. { then this structure shouldn't even exist. Each attribute info structure}
  373. { in the array could be followed by additional padding bytes in order}
  374. { to maintain four-byte alignment. These padding bytes are not to be}
  375. { included in the fValueSize member of each structure. }
  376. controlArray: array[0..0] of ATSUAttributeInfo;
  377. end;
  378. ATSFlatDataLayoutControlsDataHeaderPtr = ^ATSFlatDataLayoutControlsDataHeader;
  379. type
  380. ATSFlatDataLineInfoData = record
  381. { the length of this particular line in UniChars}
  382. lineLength: UInt32;
  383. { the number of line controls applied to this line. This can be set}
  384. { to zero if there are no special line controls applied to this line.}
  385. numberOfLineControls: UInt32;
  386. { the numberOfLineControls is non-zero, then following this structure}
  387. { must be an array of ATSUAttributeInfo structures. There must be one}
  388. { ATSUAttributeInfo structure for each numberOfLineControls above.}
  389. end;
  390. ATSFlatDataLineInfoDataPtr = ^ATSFlatDataLineInfoData;
  391. {
  392. This structure is the main data header for the flattened line info data. This
  393. is what a non-zero offsetToLineInfo points to in the
  394. ATSFlatDataTextLayoutDataHeader structure above.
  395. }
  396. type
  397. ATSFlatDataLineInfoHeader = record
  398. { the number of flattened line info structures that are stored in this}
  399. { block. This value should really be equal to the number of soft line}
  400. { breaks in the layout + 1. Of course if numberOfLines is zero, then}
  401. { this structure shouldn't even be used.}
  402. numberOfLines: UInt32;
  403. { the first in a array of ATSFlatDataLineInfoData structures. There}
  404. { needs to be a ATSFlatDataLineInfoData for each numberOfLines}
  405. { specified above.}
  406. lineInfoArray: array[0..0] of ATSFlatDataLineInfoData;
  407. end;
  408. ATSFlatDataLineInfoHeaderPtr = ^ATSFlatDataLineInfoHeader;
  409. { ------------------ }
  410. { Block 3 Structures }
  411. { ------------------ }
  412. {
  413. The block 3 structures are used by ATSUI style run flattening and parsing
  414. functions, ATSUFlattenStyleRunsToStream and ATSUUnflattenStyleRunsFromStream
  415. to represent flattened style run information. These structures go hand and
  416. hand with the block 4 structures.
  417. }
  418. {
  419. This is the data header that appears before the style run data structures.
  420. This structure is what a non-zero offsetToStyleRuns in the
  421. ATSFlatDataMainHeaderBlock points to in block 1.
  422. }
  423. type
  424. ATSFlatDataStyleRunDataHeader = record
  425. { the number of style run data structures stored in this block}
  426. numberOfStyleRuns: UInt32;
  427. { the first in an array of ATSUStyleRunInfo structures. There needs to}
  428. { be a ATSUStyleRunInfo structure for each numberOfStyleRuns specified}
  429. { above. This structure is defined in ATSUnicode.h}
  430. styleRunArray: array[0..0] of ATSUStyleRunInfo;
  431. end;
  432. ATSFlatDataStyleRunDataHeaderPtr = ^ATSFlatDataStyleRunDataHeader;
  433. { ------------------ }
  434. { Block 4 Structures }
  435. { ------------------ }
  436. {
  437. The block 4 structures store flattened ATSUStyle objects. This too, is
  438. currently used by the ATSUI style run flattening and parsing functions,
  439. ATSUFlattenStyleRunsToStream and ATSUUnflattenStyleRunsFromStream.
  440. }
  441. {
  442. this structure forms the beginning of an individually flattened ATSUStyle
  443. object.
  444. }
  445. type
  446. ATSFlatDataStyleListStyleDataHeader = record
  447. { the size of this flattened style object, including these four bytes and}
  448. { any padding bytes at the end of the structure. Basically, this can be}
  449. { used to determine where the next structure in the array begins.}
  450. sizeOfStyleInfo: UInt32;
  451. { the number of attributes set in this flattened style object. This should }
  452. { be at least one for the font data, although it can be 0 if this is to be}
  453. { unspecfied.}
  454. numberOfSetAttributes: UInt32;
  455. { the number of font features set in the flattened style object. This can}
  456. { be set to 0 if there are no font features set in the style object. }
  457. numberOfSetFeatures: UInt32;
  458. { the number of font variations set in the flattened style object. This}
  459. { can be set to 0 if there are no font variations set in the style object.}
  460. numberOfSetVariations: UInt32;
  461. { after this structure header, there is the following data in this block:}
  462. { 1. if the numberOfSetAttributes is non-zero, then there will be an}
  463. { array of ATSUAttributeInfo structures immediately following the}
  464. { above header data to store the style attributes. This is a variable}
  465. { structure array. There must be one ATSUAttributeInfo for}
  466. { for each numberOfSetAttributes. If numberOfSetAttributes is zero,}
  467. { then skip to the next data section 2.}
  468. { 2. if the numberOfSetFeatures is non-zero, then there will be an array}
  469. { of ATSFlatDataStyleListFeatureData structures immediately after}
  470. { the ATSUAttributeInfo array above (if any). There must be one}
  471. { ATSFlatDataStyleListFeatureData structure for each }
  472. { numberOfSetFeatures set in the header above. If numberOfSetFeatures}
  473. { is zero, then skip to the next data section 3.}
  474. { 3. if the numberOfSetVariations is non-zero, then there will be an}
  475. { array of ATSFlatDataStyleListVariationData immediately after the}
  476. { ATSFlatDataStyleListFeatureData array above (if any). There must be}
  477. { one ATSFlatDataStyleListVariationData structure for each }
  478. { numberOfSetVariations set in the header above.}
  479. end;
  480. ATSFlatDataStyleListStyleDataHeaderPtr = ^ATSFlatDataStyleListStyleDataHeader;
  481. {
  482. this structure is the main header for this block. This structure is what a
  483. non-zero offsetToStyleList in the ATSFlatDataMainHeaderBlock points to in
  484. block 1.
  485. }
  486. type
  487. ATSFlatDataStyleListHeader = record
  488. { the total number of flattened style objects stored in this block}
  489. numberOfStyles: UInt32;
  490. { the first in an array of flattned style entries. The data stored}
  491. { in them is variably sized, so a simply array access won't do for}
  492. { iterating through these. However, there must be one of these}
  493. { ATSFlatDataStyleListStyleDataHeader structures for each }
  494. { numberOfStyles above.}
  495. styleDataArray: array[0..0] of ATSFlatDataStyleListStyleDataHeader;
  496. end;
  497. ATSFlatDataStyleListHeaderPtr = ^ATSFlatDataStyleListHeader;
  498. {
  499. this structure stores flattened font feature data. An array of these comes
  500. after the array of font data attributes (if any) if the numberOfSetFeatures is
  501. non-zero. There must be one of these structures for each numberOfSetFeatures.
  502. }
  503. type
  504. ATSFlatDataStyleListFeatureData = record
  505. { the font feature type}
  506. theFeatureType: ATSUFontFeatureType;
  507. { the font feature selector}
  508. theFeatureSelector: ATSUFontFeatureSelector;
  509. end;
  510. ATSFlatDataStyleListFeatureDataPtr = ^ATSFlatDataStyleListFeatureData;
  511. {
  512. this structure stores the flattened font variation data. An array of these
  513. comes after the array of ATSFlatDataStyleListFeatureData structures (if any)
  514. if the numberOfSetVariations is non-zero. There must be one of these
  515. structures for each numberOfSetFeatures.
  516. }
  517. type
  518. ATSFlatDataStyleListVariationData = record
  519. { the variation axis}
  520. theVariationAxis: ATSUFontVariationAxis;
  521. { the variation value}
  522. theVariationValue: ATSUFontVariationValue;
  523. end;
  524. ATSFlatDataStyleListVariationDataPtr = ^ATSFlatDataStyleListVariationData;
  525. { ------------------------ }
  526. { Flattened Font Data Info }
  527. { ------------------------ }
  528. {
  529. This is somewhat of an addendum to the 'ustl' structure above. These flattened
  530. data structures are stored in block 4 as a font attribute with the attribute
  531. tag of kATSUFontTag. They can store font data in a few different ways, such as
  532. by a FontSync reference or by simple raw font name data. Just as with the
  533. 'ustl' above, this structure must maintain four byte alignment.
  534. }
  535. { these are the currenly supported font specifiers. }
  536. type
  537. ATSFlatDataFontSpeciferType = UInt32;
  538. const
  539. { this specifier allows the storage of font data based on name data. This}
  540. { uses the stuctures below to store the actual data itself.}
  541. kATSFlattenedFontSpecifierRawNameData = FourCharCode('namd');
  542. {
  543. this is the main header for the font data. It dictates what type of data
  544. is stored. The actual data stored must match the type specified by the
  545. nameSpecType.
  546. }
  547. type
  548. ATSFlatDataFontNameDataHeader = record
  549. { the type of data that is flattened in this structure}
  550. nameSpecifierType: ATSFlatDataFontSpeciferType;
  551. { the size of the data that is flattened in this structre, not including }
  552. { any padding bytes that may be necessary to achive the four byte }
  553. { alignment of the data, unless they are specified as part of structure, }
  554. { such as with the ATSFlatDataFontSpecRawNameData structure.}
  555. nameSpecifierSize: UInt32;
  556. { after this header comes the flattened font name data which matches}
  557. { the type specified by the nameSpecifierType above. For instance, if }
  558. { the nameSpecType is kATSFlattenedFontNameSpecifierRawNameData, the}
  559. { structure that immediately follows this would be a}
  560. { ATSFlatDataFontNameRawNameDataHeader structure. }
  561. end;
  562. ATSFlatDataFontNameDataHeaderPtr = ^ATSFlatDataFontNameDataHeader;
  563. {
  564. the next two structures are only used when the nameSpecType is set to
  565. kATSFlattenedFontSpecifierRawNameData. They are setup to store multiple
  566. font name table entries for the purposes of reconstructing an ATSUFontID
  567. for (hopefully) the same font some time in the future.
  568. }
  569. { this is the structure in which raw font name data is actually stored. }
  570. type
  571. ATSFlatDataFontSpecRawNameData = record
  572. { the type of name being specified}
  573. fontNameType: FontNameCode;
  574. { the platform type of the font name, whether it be Unicode, Mac, etc. }
  575. { This should be specified if known. If not known, then specify}
  576. { kFontNoPlatform, but then all matching will be done based on the first}
  577. { font in the name table matching the other parameters.}
  578. fontNamePlatform: FontPlatformCode;
  579. { the script code of the fontÕs name based on the platform that was passed}
  580. { in above. If set to kFontNoScript, then the name will be matched based}
  581. { on the first font in the name table matching the other font name}
  582. { parameters.}
  583. fontNameScript: FontScriptCode;
  584. { the language of the font name. If set to kFontNoLanguage, then the name }
  585. { will be matched based on the first font in the name table matching the}
  586. { other font name parameters.}
  587. fontNameLanguage: FontLanguageCode;
  588. { the length of the font name in bytes, not including any padding bytes}
  589. { added to maintain the four byte alignment}
  590. fontNameLength: UInt32;
  591. { after the name length comes the actual font name data itself, plus any}
  592. { padding bytes needed to maintain the four byte alignment.}
  593. end;
  594. ATSFlatDataFontSpecRawNameDataPtr = ^ATSFlatDataFontSpecRawNameData;
  595. {
  596. this is a header structure that defines some things constant throughout
  597. the entire search for the font name, as well as the array of
  598. ATSFlatDataFontNameData structures. In order to gaurantee that the same font
  599. will be used, more than one name specifer should be stored. The standard ATSUI
  600. style run flattening and parsing functions, ATSUFlattenStyleRunsToStream and
  601. ATSUUnflattenStyleRunsFromStream. These will store both the font's full name
  602. (kFontFullName) as well as the font's manufacturer name (kFontManufacturerName)
  603. and match fonts based on both of
  604. these.
  605. }
  606. type
  607. ATSFlatDataFontSpecRawNameDataHeader = record
  608. { the number of flattened font names. There must be at least one flattened }
  609. { font name, otherwise the structure is malformed.}
  610. numberOfFlattenedNames: UInt32;
  611. { the first in an array of possibly many font name specifiers - depending}
  612. { on how specific the caller wants this. There must be one }
  613. { ATSFlatDataFontNameData structure for each numberOfFlattenedNames}
  614. { above.}
  615. nameDataArray: array[0..0] of ATSFlatDataFontSpecRawNameData;
  616. end;
  617. ATSFlatDataFontSpecRawNameDataHeaderPtr = ^ATSFlatDataFontSpecRawNameDataHeader;
  618. { ---------------------------------------------------------------------------- }
  619. { Style Flattening and Parsing Functions }
  620. { ---------------------------------------------------------------------------- }
  621. {$ifc not TARGET_CPU_64}
  622. {
  623. * ATSUFlattenStyleRunsToStream() *** DEPRECATED ***
  624. *
  625. * Deprecated:
  626. * Use CoreFoundation flattening API instead.
  627. *
  628. * Summary:
  629. * Converts a series of ATSUStyle objects and associated run info to
  630. * a flat binary representation.
  631. *
  632. * Discussion:
  633. * This function takes an array of ATSUStyle objects and style run
  634. * information and flattens the data to the specified format. The
  635. * style runs must all reference the same block of Unicode text
  636. * (usually passed separately as text in the 'utxt' format). The
  637. * style runs must also be in ascending order relative to the text
  638. * in the text block. Typically you use the function
  639. * ATSUFlattenStyleRunsFromStream by calling it twice, as follows:
  640. * (1) Provide appropriate values for the iStreamFormat,
  641. * iFlattenOptions, iNumberOfRunInfo, iRunInfoArray,
  642. * iNumberOfStyleObjects, and iStyleArray parameters. Set
  643. * iStreamBufferSize to 0, oStreamBuffer to NULL, and pass a valid
  644. * reference to a UInt32 variable in the oActualStreamBufferSize
  645. * parameter. Call the function ATSUFlattenStyleRunsToStream. On
  646. * return, oActualStreamBufferSize points to the size needed for the
  647. * buffer. (2) Allocate an appropriately-sized buffer for the
  648. * oStreamBuffer parameter and then call the function
  649. * ATSUFlattenStyleRunsToStream a second time.
  650. *
  651. * Parameters:
  652. *
  653. * iStreamFormat:
  654. * The format of the flattened data. There is only one format
  655. * supported at this time ('ustl'), so you must pass the constant
  656. * kATSUDataStreamUnicodeStyledText.
  657. *
  658. * iFlattenOptions:
  659. * The options you want to use to flatten the data. There are no
  660. * options supported at this time, so you must pass the constant
  661. * kATSUFlattenOptionNoOptionsMask.
  662. *
  663. * iNumberOfRunInfo:
  664. * The number of style run information structures passed in the
  665. * iRunInfoArray parameter. If you pass 0, ATSUI assumes there is
  666. * only one style for the entire text block passed in the
  667. * oStreamBuffer parameter. The flattened data format passed to
  668. * the iStreamFormat parameter must support the use of one style.
  669. *
  670. * iRunInfoArray:
  671. * An array of ATSUStyleRunInfo structures that describes the
  672. * style runs to be flattened. This array must contain
  673. * iNumberOfRunInfo entries. An ATSUStyleRunInfo structure
  674. * contains an index into an array of unique ATSUStyle objects and
  675. * the length of the run to which the style object applies. Each
  676. * index in the ATSUStyleRunInfo structure must reference a valid
  677. * ATSUStyle object passed in the iStyleArray parameter. You can
  678. * pass NULL, only if iNumberOfRunInfo is set to zero.
  679. *
  680. * iNumberOfStyleObjects:
  681. * The number of ATSUStyle objects in the array passed to the
  682. * iStyleArray parameter. You must pass a value that is greater
  683. * than 0.
  684. *
  685. * iStyleArray:
  686. * An array of ATSUStyle objects to be flattened. You cannot pass
  687. * NULL.
  688. *
  689. * iStreamBufferSize:
  690. * The size of the stream buffer, pointed to by the oStreamBuffer
  691. * parameter. You can pass 0only if the iStreamBufferSize
  692. * parameter is set to NULL. If you are uncertain of the size of
  693. * the array, see the Discussion.
  694. *
  695. * oStreamBuffer:
  696. * On input, a pointer to the data you want to flatten. On return,
  697. * points to the flattened data. If you pass NULL for this
  698. * parameter, no data is flattened. Instead, the size of the
  699. * buffer is calculated by ATSUI and returned in oActualStreamSize
  700. * parameter. See the Discussion for more details. You are
  701. * responsible for allocating the text buffer passed in the
  702. * oStreamBuffer parameter.
  703. *
  704. * oActualStreamBufferSize:
  705. * On return, the size of the data written to the oStreamBuffer
  706. * parameter. You can pass NULL only if the oStreamBuffer
  707. * parameter is not NULL.
  708. *
  709. * Result:
  710. * On success, noErr is returned. See MacErrors.h for possible error
  711. * codes.
  712. *
  713. * Availability:
  714. * Mac OS X: in version 10.2 and later in ApplicationServices.framework [32-bit only] but deprecated in 10.6
  715. * CarbonLib: not available in CarbonLib 1.x, is available on Mac OS X version 10.2 and later
  716. * Non-Carbon CFM: not available
  717. }
  718. function ATSUFlattenStyleRunsToStream( iStreamFormat: ATSUFlattenedDataStreamFormat; iFlattenOptions: ATSUFlattenStyleRunOptions; iNumberOfRunInfo: ItemCount; {const} iRunInfoArray: {variable-size-array} ATSUStyleRunInfoPtr; iNumberOfStyleObjects: ItemCount; {const} iStyleArray: {variable-size-array} ATSUStylePtr; iStreamBufferSize: ByteCount; oStreamBuffer: UnivPtr; oActualStreamBufferSize: ByteCountPtr ): OSStatus; external name '_ATSUFlattenStyleRunsToStream';
  719. (* AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_6 *)
  720. {
  721. * ATSUUnflattenStyleRunsFromStream() *** DEPRECATED ***
  722. *
  723. * Deprecated:
  724. * Use CoreFoundation flattening API instead.
  725. *
  726. * Summary:
  727. * Creates a series of ATSUStyle objects and associated run
  728. * information from a flat binary representation.
  729. *
  730. * Discussion:
  731. * This function extracts the ATSUI style run information from
  732. * previously-flattened data. The style objects and style run
  733. * information structures are returned in two separate arraysÑthe
  734. * array oStyleArray and the array oRunInfoArray. These arrays are
  735. * not parallel. Each ATSUStyle object in the oStyleArray is a
  736. * unique ATSUStyle object. To figure out which ATSUStyle object
  737. * belongs to which text run, the caller must parse the array of
  738. * ATSUStyleRunInfo structures. These structures contain the style
  739. * run lengths and an index into the oStyleArray. Typically you use
  740. * the function ATSUUnflattenStyleRunsFromStream by calling it
  741. * twice, as follows: (1) Provide appropriate values for the
  742. * iStreamFormat, iUnflattenOptions, and iStreamBuffer parameters.
  743. * Pass 0for the iNumberOfRunInfo and iNumberOfStyleObjects
  744. * parameters, NULL for the oRunInfoArray and oStyleArray,
  745. * parameters and valid ItemCount references for the
  746. * oActualNumberOfRunInfo and oActualNumberOfStyleObjects
  747. * parameters. On return, oActualNumberOfRunInfo and
  748. * oActualNumberOfStyleObjects point to the sizes needed to allocate
  749. * these arrays. (2) Allocate appropriately-sized arrays of
  750. * ATSUStyleRunStructures and ATSUStyle object references. Call the
  751. * function ATSUUnflattenStyleRunsFromStream a second time, passing
  752. * the newly allocated arrays in the oRunInfoArray and oStyleArray
  753. * parameters, with the iNumberOfRunInfo and iNumberOfStyleObjects
  754. * parameters set to the values you obtained from the first call.
  755. *
  756. * Parameters:
  757. *
  758. * iStreamFormat:
  759. * The format of the flattened data. There is only one format
  760. * supported at this time ('ustl'), so you must pass the constant
  761. * kATSUDataStreamUnicodeStyledText.
  762. *
  763. * iUnflattenOptions:
  764. * The options you want to use to unflatten the data. There are no
  765. * options supported at this time, so you must pass the constant
  766. * kATSUUnflattenOptionNoOptionsMask.
  767. *
  768. * iStreamBufferSize:
  769. * The size of the buffer pointed to by the iStreamBuffer
  770. * parameter. You must pass a value greater than 0.
  771. *
  772. * iStreamBuffer:
  773. * A pointer to the buffer that contains the flattened data. The
  774. * data must be of the format specified by the iStreamFormat
  775. * parameter and must be of size specified by the
  776. * iStreamBufferSize parameter. You cannot pass NULL .
  777. *
  778. * iNumberOfRunInfo:
  779. * The number of style run information structures passed in the
  780. * oRunInfoArray parameter. If you are uncertain of the number of
  781. * style run information structures, see the Discussion.
  782. *
  783. * iNumberOfStyleObjects:
  784. * The number of ATSUStyle objects in the array passed into the
  785. * iStyleArray parameter. If you are uncertain of the number of
  786. * ATSUStyle objects, see the Discussion.
  787. *
  788. * oRunInfoArray:
  789. * On return, points to an array of style run information
  790. * structures. Each structure contains a style run length and
  791. * index into the oStyleArray array. If you are uncertain of how
  792. * much memory to allocate for this array, see the Discussion. You
  793. * are responsible for disposing of the array when you no longer
  794. * need it.
  795. *
  796. * oStyleArray:
  797. * On return, a pointer to an array of the unique ATSUStyle
  798. * objects obtained from the flattened data. The indices returned
  799. * in the array oRunInfoArray are indices into this array. If you
  800. * are uncertain of how much memory to allocate for this array,
  801. * see the Discussion. You are responsible for disposing of the
  802. * array and the ATSUI style objects in the array when you no
  803. * longer need the array.
  804. *
  805. * oActualNumberOfRunInfo:
  806. * On return, points to the actual number of ATSUStyleRunInfo
  807. * structures obtained from the flattened data. The actual number
  808. * of structures is the number of entries added to the array
  809. * oRunInfoArray. You can pass NULL if you to not want to obtain
  810. * this value.
  811. *
  812. * oActualNumberOfStyleObjects:
  813. * On return, points to the actual number of unique ATSUStyle
  814. * objects obtained from the flattened data. The actual number is
  815. * the number of entries added to the oStyleArray array. You can
  816. * pass NULL if you do no want to obtain this value.
  817. *
  818. * Result:
  819. * On success, noErr is returned. See MacErrors.h for possible error
  820. * codes.
  821. *
  822. * Availability:
  823. * Mac OS X: in version 10.2 and later in ApplicationServices.framework [32-bit only] but deprecated in 10.6
  824. * CarbonLib: not available in CarbonLib 1.x, is available on Mac OS X version 10.2 and later
  825. * Non-Carbon CFM: not available
  826. }
  827. function ATSUUnflattenStyleRunsFromStream( iStreamFormat: ATSUFlattenedDataStreamFormat; iUnflattenOptions: ATSUUnFlattenStyleRunOptions; iStreamBufferSize: ByteCount; iStreamBuffer: {const} UnivPtr; iNumberOfRunInfo: ItemCount; iNumberOfStyleObjects: ItemCount; oRunInfoArray: {variable-size-array} ATSUStyleRunInfoPtr; oStyleArray: {variable-size-array} ATSUStylePtr; oActualNumberOfRunInfo: ItemCountPtr; oActualNumberOfStyleObjects: ItemCountPtr ): OSStatus; external name '_ATSUUnflattenStyleRunsFromStream';
  828. (* AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_6 *)
  829. { Functions listed beyond this point are either deprecated or not recommended }
  830. {
  831. * ATSUCopyToHandle() *** DEPRECATED ***
  832. *
  833. * Deprecated:
  834. * Use CoreFoundation flattening API instead.
  835. *
  836. * Discussion:
  837. * This function is no longer recommended. Please use
  838. * ATSUFlattenStyleRunsToStream instead.
  839. *
  840. * Availability:
  841. * Mac OS X: in version 10.0 and later in ApplicationServices.framework [32-bit only] but deprecated in 10.1
  842. * CarbonLib: in CarbonLib 1.0 and later
  843. * Non-Carbon CFM: in ATSUnicodeLib 8.5 and later
  844. }
  845. function ATSUCopyToHandle( iStyle: ATSUStyle; oStyleHandle: Handle ): OSStatus; external name '_ATSUCopyToHandle';
  846. (* AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_1 *)
  847. {
  848. * ATSUPasteFromHandle() *** DEPRECATED ***
  849. *
  850. * Deprecated:
  851. * Use CoreFoundation flattening API instead.
  852. *
  853. * Discussion:
  854. * This function is no longer recommended. Please use
  855. * ATSUUnflattenStyleRunsFromStream instead.
  856. *
  857. * Availability:
  858. * Mac OS X: in version 10.0 and later in ApplicationServices.framework [32-bit only] but deprecated in 10.1
  859. * CarbonLib: in CarbonLib 1.0 and later
  860. * Non-Carbon CFM: in ATSUnicodeLib 8.5 and later
  861. }
  862. function ATSUPasteFromHandle( iStyle: ATSUStyle; iStyleHandle: Handle ): OSStatus; external name '_ATSUPasteFromHandle';
  863. (* AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_1 *)
  864. {$endc} {not TARGET_CPU_64}
  865. {$endc} {TARGET_OS_MAC}
  866. {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
  867. end.
  868. {$endc} {not MACOSALLINCLUDE}