Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

577 lines
21 KiB

  1. /*
  2. File: UnicodeUtilities.h
  3. Contains: Types, constants, prototypes for Unicode Utilities (Unicode input and text utils)
  4. Version: QuickTime 7.3
  5. Copyright: (c) 2007 (c) 1997-2001 by Apple Computer, Inc., all rights reserved.
  6. Bugs?: For bug reports, consult the following page on
  7. the World Wide Web:
  8. http://developer.apple.com/bugreporter/
  9. */
  10. #ifndef __UNICODEUTILITIES__
  11. #define __UNICODEUTILITIES__
  12. #ifndef __MACTYPES__
  13. #include <MacTypes.h>
  14. #endif
  15. #ifndef __MACLOCALES__
  16. #include <MacLocales.h>
  17. #endif
  18. #ifndef __TEXTCOMMON__
  19. #include <TextCommon.h>
  20. #endif
  21. #if PRAGMA_ONCE
  22. #pragma once
  23. #endif
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. #if PRAGMA_IMPORT
  28. #pragma import on
  29. #endif
  30. #if PRAGMA_STRUCT_ALIGN
  31. #pragma options align=mac68k
  32. #elif PRAGMA_STRUCT_PACKPUSH
  33. #pragma pack(push, 2)
  34. #elif PRAGMA_STRUCT_PACK
  35. #pragma pack(2)
  36. #endif
  37. /*
  38. -------------------------------------------------------------------------------------------------
  39. CONSTANTS & DATA STRUCTURES for UCKeyTranslate & UCKeyboardLayout ('uchr' resource)
  40. -------------------------------------------------------------------------------------------------
  41. */
  42. /*
  43. -------------------------------------------------------------------------------------------------
  44. UCKeyOutput & related stuff
  45. The interpretation of UCKeyOutput depends on bits 15-14.
  46. If they are 01, then bits 0-13 are an index in UCKeyStateRecordsIndex (resource-wide list).
  47. If they are 10, then bits 0-13 are an index in UCKeySequenceDataIndex (resource-wide list),
  48. or if UCKeySequenceDataIndex is not present or the index is beyond the end of the list,
  49. then bits 0-15 are a single Unicode character.
  50. Otherwise, bits 0-15 are a single Unicode character; a value of 0xFFFE-0xFFFF means no character
  51. output.
  52. UCKeyCharSeq is similar, but does not support indices in UCKeyStateRecordsIndex. For bits 15-14:
  53. If they are 10, then bits 0-13 are an index in UCKeySequenceDataIndex (resource-wide list),
  54. or if UCKeySequenceDataIndex is not present or the index is beyond the end of the list,
  55. then bits 0-15 are a single Unicode character.
  56. Otherwise, bits 0-15 are a single Unicode character; a value of 0xFFFE-0xFFFF means no character
  57. output.
  58. -------------------------------------------------------------------------------------------------
  59. */
  60. typedef UInt16 UCKeyOutput;
  61. typedef UInt16 UCKeyCharSeq;
  62. enum {
  63. kUCKeyOutputStateIndexMask = 0x4000,
  64. kUCKeyOutputSequenceIndexMask = 0x8000,
  65. kUCKeyOutputTestForIndexMask = 0xC000, /* test bits 14-15*/
  66. kUCKeyOutputGetIndexMask = 0x3FFF /* get bits 0-13*/
  67. };
  68. /*
  69. -------------------------------------------------------------------------------------------------
  70. UCKeyStateRecord & related stuff
  71. The UCKeyStateRecord information is used as follows. If the current state is zero,
  72. output stateZeroCharData and set the state to stateZeroNextState. If the current state
  73. is non-zero and there is an entry for it in stateEntryData, then output the corresponding
  74. charData and set the state to nextState. Otherwise, output the state terminator from
  75. UCKeyStateTerminators for the current state (or nothing if there is no UCKeyStateTerminators
  76. table or it has no entry for the current state), then output stateZeroCharData and set the
  77. state to stateZeroNextState.
  78. -------------------------------------------------------------------------------------------------
  79. */
  80. struct UCKeyStateRecord {
  81. UCKeyCharSeq stateZeroCharData;
  82. UInt16 stateZeroNextState;
  83. UInt16 stateEntryCount;
  84. UInt16 stateEntryFormat;
  85. /* This is followed by an array of stateEntryCount elements*/
  86. /* in the specified format. Here we just show a dummy array.*/
  87. UInt32 stateEntryData[1];
  88. };
  89. typedef struct UCKeyStateRecord UCKeyStateRecord;
  90. /*
  91. Here are the codes for entry formats currently defined.
  92. Each entry maps from curState to charData and nextState.
  93. */
  94. enum {
  95. kUCKeyStateEntryTerminalFormat = 0x0001,
  96. kUCKeyStateEntryRangeFormat = 0x0002
  97. };
  98. /*
  99. For UCKeyStateEntryTerminal -
  100. nextState is always 0, so we don't have a field for it
  101. */
  102. struct UCKeyStateEntryTerminal {
  103. UInt16 curState;
  104. UCKeyCharSeq charData;
  105. };
  106. typedef struct UCKeyStateEntryTerminal UCKeyStateEntryTerminal;
  107. /*
  108. For UCKeyStateEntryRange -
  109. If curState >= curStateStart and curState <= curStateStart+curStateRange,
  110. then it matches the entry, and we transform charData and nextState as follows:
  111. If charData < 0xFFFE, then charData += (curState-curStateStart)*deltaMultiplier
  112. If nextState != 0, then nextState += (curState-curStateStart)*deltaMultiplier
  113. */
  114. struct UCKeyStateEntryRange {
  115. UInt16 curStateStart;
  116. UInt8 curStateRange;
  117. UInt8 deltaMultiplier;
  118. UCKeyCharSeq charData;
  119. UInt16 nextState;
  120. };
  121. typedef struct UCKeyStateEntryRange UCKeyStateEntryRange;
  122. /*
  123. -------------------------------------------------------------------------------------------------
  124. UCKeyboardLayout & related stuff
  125. The UCKeyboardLayout struct given here is only for the resource header. It specifies
  126. offsets to the various subtables which each have their own structs, given below.
  127. The keyboardTypeHeadList array selects table offsets that depend on keyboardType. The
  128. first entry in keyboardTypeHeadList is the default entry, which will be used if the
  129. keyboardType passed to UCKeyTranslate does not match any other entry - i.e. does not fall
  130. within the range keyboardTypeFirst..keyboardTypeLast for some entry. The first entry
  131. should have keyboardTypeFirst = keyboardTypeLast = 0.
  132. -------------------------------------------------------------------------------------------------
  133. */
  134. struct UCKeyboardTypeHeader {
  135. UInt32 keyboardTypeFirst; /* first keyboardType in this entry*/
  136. UInt32 keyboardTypeLast; /* last keyboardType in this entry*/
  137. ByteOffset keyModifiersToTableNumOffset; /* required*/
  138. ByteOffset keyToCharTableIndexOffset; /* required*/
  139. ByteOffset keyStateRecordsIndexOffset; /* 0 => no table*/
  140. ByteOffset keyStateTerminatorsOffset; /* 0 => no table*/
  141. ByteOffset keySequenceDataIndexOffset; /* 0 => no table*/
  142. };
  143. typedef struct UCKeyboardTypeHeader UCKeyboardTypeHeader;
  144. struct UCKeyboardLayout {
  145. /* header only; other tables accessed via offsets*/
  146. UInt16 keyLayoutHeaderFormat; /* =kUCKeyLayoutHeaderFormat*/
  147. UInt16 keyLayoutDataVersion; /* 0x0100 = 1.0, 0x0110 = 1.1, etc.*/
  148. ByteOffset keyLayoutFeatureInfoOffset; /* may be 0 */
  149. ItemCount keyboardTypeCount; /* Dimension for keyboardTypeHeadList[] */
  150. UCKeyboardTypeHeader keyboardTypeList[1];
  151. };
  152. typedef struct UCKeyboardLayout UCKeyboardLayout;
  153. /* -------------------------------------------------------------------------------------------------*/
  154. struct UCKeyLayoutFeatureInfo {
  155. UInt16 keyLayoutFeatureInfoFormat; /* =kUCKeyLayoutFeatureInfoFormat*/
  156. UInt16 reserved;
  157. UniCharCount maxOutputStringLength; /* longest possible output string*/
  158. };
  159. typedef struct UCKeyLayoutFeatureInfo UCKeyLayoutFeatureInfo;
  160. /* -------------------------------------------------------------------------------------------------*/
  161. struct UCKeyModifiersToTableNum {
  162. UInt16 keyModifiersToTableNumFormat; /* =kUCKeyModifiersToTableNumFormat*/
  163. UInt16 defaultTableNum; /* For modifier combos not in tableNum[]*/
  164. ItemCount modifiersCount; /* Dimension for tableNum[]*/
  165. UInt8 tableNum[1];
  166. /* Then there is padding to a 4-byte boundary with bytes containing 0, if necessary.*/
  167. };
  168. typedef struct UCKeyModifiersToTableNum UCKeyModifiersToTableNum;
  169. /* -------------------------------------------------------------------------------------------------*/
  170. struct UCKeyToCharTableIndex {
  171. UInt16 keyToCharTableIndexFormat; /* =kUCKeyToCharTableIndexFormat*/
  172. UInt16 keyToCharTableSize; /* Max keyCode (128 for ADB keyboards)*/
  173. ItemCount keyToCharTableCount; /* Dimension for keyToCharTableOffsets[] (usually 6 to 12 tables)*/
  174. ByteOffset keyToCharTableOffsets[1];
  175. /* Each offset in keyToCharTableOffsets is from the beginning of the resource to a*/
  176. /* table as follows:*/
  177. /* UCKeyOutput keyToCharData[keyToCharTableSize];*/
  178. /* These tables follow the UCKeyToCharTableIndex.*/
  179. /* Then there is padding to a 4-byte boundary with bytes containing 0, if necessary.*/
  180. };
  181. typedef struct UCKeyToCharTableIndex UCKeyToCharTableIndex;
  182. /* -------------------------------------------------------------------------------------------------*/
  183. struct UCKeyStateRecordsIndex {
  184. UInt16 keyStateRecordsIndexFormat; /* =kUCKeyStateRecordsIndexFormat*/
  185. UInt16 keyStateRecordCount; /* Dimension for keyStateRecordOffsets[]*/
  186. ByteOffset keyStateRecordOffsets[1];
  187. /* Each offset in keyStateRecordOffsets is from the beginning of the resource to a*/
  188. /* UCKeyStateRecord. These UCKeyStateRecords follow the keyStateRecordOffsets[] array.*/
  189. /* Then there is padding to a 4-byte boundary with bytes containing 0, if necessary.*/
  190. };
  191. typedef struct UCKeyStateRecordsIndex UCKeyStateRecordsIndex;
  192. /* -------------------------------------------------------------------------------------------------*/
  193. struct UCKeyStateTerminators {
  194. UInt16 keyStateTerminatorsFormat; /* =kUCKeyStateTerminatorsFormat*/
  195. UInt16 keyStateTerminatorCount; /* Dimension for keyStateTerminators[] (# of nonzero states)*/
  196. UCKeyCharSeq keyStateTerminators[1];
  197. /* Note: keyStateTerminators[0] is terminator for state 1, etc.*/
  198. /* Then there is padding to a 4-byte boundary with bytes containing 0, if necessary.*/
  199. };
  200. typedef struct UCKeyStateTerminators UCKeyStateTerminators;
  201. /* -------------------------------------------------------------------------------------------------*/
  202. struct UCKeySequenceDataIndex {
  203. UInt16 keySequenceDataIndexFormat; /* =kUCKeySequenceDataIndexFormat*/
  204. UInt16 charSequenceCount; /* Dimension of charSequenceOffsets[] is charSequenceCount+1*/
  205. UInt16 charSequenceOffsets[1];
  206. /* Each offset in charSequenceOffsets is in bytes, from the beginning of*/
  207. /* UCKeySequenceDataIndex to a sequence of UniChars; the next offset indicates the*/
  208. /* end of the sequence. The UniChar sequences follow the UCKeySequenceDataIndex.*/
  209. /* Then there is padding to a 4-byte boundary with bytes containing 0, if necessary.*/
  210. };
  211. typedef struct UCKeySequenceDataIndex UCKeySequenceDataIndex;
  212. /* -------------------------------------------------------------------------------------------------*/
  213. /* Current format codes for the various tables (bits 12-15 indicate which table)*/
  214. enum {
  215. kUCKeyLayoutHeaderFormat = 0x1002,
  216. kUCKeyLayoutFeatureInfoFormat = 0x2001,
  217. kUCKeyModifiersToTableNumFormat = 0x3001,
  218. kUCKeyToCharTableIndexFormat = 0x4001,
  219. kUCKeyStateRecordsIndexFormat = 0x5001,
  220. kUCKeyStateTerminatorsFormat = 0x6001,
  221. kUCKeySequenceDataIndexFormat = 0x7001
  222. };
  223. /*
  224. -------------------------------------------------------------------------------------------------
  225. Constants for keyAction parameter in UCKeyTranslate()
  226. -------------------------------------------------------------------------------------------------
  227. */
  228. enum {
  229. kUCKeyActionDown = 0, /* key is going down*/
  230. kUCKeyActionUp = 1, /* key is going up*/
  231. kUCKeyActionAutoKey = 2, /* auto-key down*/
  232. kUCKeyActionDisplay = 3 /* get information for key display (as in Key Caps) */
  233. };
  234. /*
  235. -------------------------------------------------------------------------------------------------
  236. Bit assignments & masks for keyTranslateOptions parameter in UCKeyTranslate()
  237. -------------------------------------------------------------------------------------------------
  238. */
  239. enum {
  240. kUCKeyTranslateNoDeadKeysBit = 0 /* Prevents setting any new dead-key states*/
  241. };
  242. enum {
  243. kUCKeyTranslateNoDeadKeysMask = 1L << kUCKeyTranslateNoDeadKeysBit
  244. };
  245. /*
  246. -------------------------------------------------------------------------------------------------
  247. CONSTANTS & DATA STRUCTURES for Unicode Collation
  248. -------------------------------------------------------------------------------------------------
  249. */
  250. /* constant for LocaleOperationClass*/
  251. enum {
  252. kUnicodeCollationClass = FOUR_CHAR_CODE('ucol')
  253. };
  254. typedef struct OpaqueCollatorRef* CollatorRef;
  255. typedef UInt32 UCCollateOptions;
  256. enum {
  257. /* Sensitivity options*/
  258. kUCCollateComposeInsensitiveMask = 1L << 1,
  259. kUCCollateWidthInsensitiveMask = 1L << 2,
  260. kUCCollateCaseInsensitiveMask = 1L << 3,
  261. kUCCollateDiacritInsensitiveMask = 1L << 4, /* Other general options */
  262. kUCCollatePunctuationSignificantMask = 1L << 15, /* Number-handling options */
  263. kUCCollateDigitsOverrideMask = 1L << 16,
  264. kUCCollateDigitsAsNumberMask = 1L << 17
  265. };
  266. enum {
  267. kUCCollateStandardOptions = kUCCollateComposeInsensitiveMask | kUCCollateWidthInsensitiveMask
  268. };
  269. /*
  270. Special values to specify various invariant orders for UCCompareTextNoLocale.
  271. These values use the high 8 bits of UCCollateOptions.
  272. */
  273. enum {
  274. kUCCollateTypeHFSExtended = 1
  275. };
  276. /* These constants are used for masking and shifting the invariant order type.*/
  277. enum {
  278. kUCCollateTypeSourceMask = 0x000000FF,
  279. kUCCollateTypeShiftBits = 24
  280. };
  281. enum {
  282. kUCCollateTypeMask = kUCCollateTypeSourceMask << kUCCollateTypeShiftBits
  283. };
  284. typedef UInt32 UCCollationValue;
  285. /*
  286. -------------------------------------------------------------------------------------------------
  287. CONSTANTS & DATA STRUCTURES for Unicode TextBreak
  288. -------------------------------------------------------------------------------------------------
  289. */
  290. /* constant for LocaleOperationClass*/
  291. enum {
  292. kUnicodeTextBreakClass = FOUR_CHAR_CODE('ubrk')
  293. };
  294. typedef struct OpaqueTextBreakLocatorRef* TextBreakLocatorRef;
  295. typedef UInt32 UCTextBreakType;
  296. enum {
  297. kUCTextBreakCharMask = 1L << 0,
  298. kUCTextBreakClusterMask = 1L << 2,
  299. kUCTextBreakWordMask = 1L << 4,
  300. kUCTextBreakLineMask = 1L << 6
  301. };
  302. typedef UInt32 UCTextBreakOptions;
  303. enum {
  304. kUCTextBreakLeadingEdgeMask = 1L << 0,
  305. kUCTextBreakGoBackwardsMask = 1L << 1,
  306. kUCTextBreakIterateMask = 1L << 2
  307. };
  308. /*
  309. -------------------------------------------------------------------------------------------------
  310. FUNCTION PROTOTYPES
  311. -------------------------------------------------------------------------------------------------
  312. */
  313. /*
  314. * UCKeyTranslate()
  315. *
  316. * Availability:
  317. * Non-Carbon CFM: in UnicodeUtilitiesCoreLib 8.5 and later
  318. * CarbonLib: in CarbonLib 1.0 and later
  319. * Mac OS X: in version 10.0 and later
  320. */
  321. EXTERN_API( OSStatus )
  322. UCKeyTranslate(
  323. const UCKeyboardLayout * keyLayoutPtr,
  324. UInt16 virtualKeyCode,
  325. UInt16 keyAction,
  326. UInt32 modifierKeyState,
  327. UInt32 keyboardType,
  328. OptionBits keyTranslateOptions,
  329. UInt32 * deadKeyState,
  330. UniCharCount maxStringLength,
  331. UniCharCount * actualStringLength,
  332. UniChar unicodeString[]);
  333. /* Standard collation functions*/
  334. /*
  335. * UCCreateCollator()
  336. *
  337. * Availability:
  338. * Non-Carbon CFM: in UnicodeUtilitiesLib 8.6 and later
  339. * CarbonLib: in CarbonLib 1.0 and later
  340. * Mac OS X: in version 10.0 and later
  341. */
  342. EXTERN_API_C( OSStatus )
  343. UCCreateCollator(
  344. LocaleRef locale,
  345. LocaleOperationVariant opVariant,
  346. UCCollateOptions options,
  347. CollatorRef * collatorRef);
  348. /*
  349. * UCGetCollationKey()
  350. *
  351. * Availability:
  352. * Non-Carbon CFM: in UnicodeUtilitiesLib 8.6 and later
  353. * CarbonLib: in CarbonLib 1.0 and later
  354. * Mac OS X: in version 10.0 and later
  355. */
  356. EXTERN_API_C( OSStatus )
  357. UCGetCollationKey(
  358. CollatorRef collatorRef,
  359. const UniChar * textPtr,
  360. UniCharCount textLength,
  361. ItemCount maxKeySize,
  362. ItemCount * actualKeySize,
  363. UCCollationValue collationKey[]);
  364. /*
  365. * UCCompareCollationKeys()
  366. *
  367. * Availability:
  368. * Non-Carbon CFM: in UnicodeUtilitiesCoreLib 8.6 and later
  369. * CarbonLib: in CarbonLib 1.0 and later
  370. * Mac OS X: in version 10.0 and later
  371. */
  372. EXTERN_API_C( OSStatus )
  373. UCCompareCollationKeys(
  374. const UCCollationValue * key1Ptr,
  375. ItemCount key1Length,
  376. const UCCollationValue * key2Ptr,
  377. ItemCount key2Length,
  378. Boolean * equivalent,
  379. SInt32 * order);
  380. /*
  381. * UCCompareText()
  382. *
  383. * Availability:
  384. * Non-Carbon CFM: in UnicodeUtilitiesLib 8.6 and later
  385. * CarbonLib: in CarbonLib 1.0 and later
  386. * Mac OS X: in version 10.0 and later
  387. */
  388. EXTERN_API_C( OSStatus )
  389. UCCompareText(
  390. CollatorRef collatorRef,
  391. const UniChar * text1Ptr,
  392. UniCharCount text1Length,
  393. const UniChar * text2Ptr,
  394. UniCharCount text2Length,
  395. Boolean * equivalent,
  396. SInt32 * order);
  397. /*
  398. * UCDisposeCollator()
  399. *
  400. * Availability:
  401. * Non-Carbon CFM: in UnicodeUtilitiesLib 8.6 and later
  402. * CarbonLib: in CarbonLib 1.0 and later
  403. * Mac OS X: in version 10.0 and later
  404. */
  405. EXTERN_API_C( OSStatus )
  406. UCDisposeCollator(CollatorRef * collatorRef);
  407. /* Simple collation using default locale*/
  408. /*
  409. * UCCompareTextDefault()
  410. *
  411. * Availability:
  412. * Non-Carbon CFM: in UnicodeUtilitiesLib 8.6 and later
  413. * CarbonLib: in CarbonLib 1.0 and later
  414. * Mac OS X: in version 10.0 and later
  415. */
  416. EXTERN_API_C( OSStatus )
  417. UCCompareTextDefault(
  418. UCCollateOptions options,
  419. const UniChar * text1Ptr,
  420. UniCharCount text1Length,
  421. const UniChar * text2Ptr,
  422. UniCharCount text2Length,
  423. Boolean * equivalent,
  424. SInt32 * order);
  425. /* Simple locale-independent collation*/
  426. /*
  427. * UCCompareTextNoLocale()
  428. *
  429. * Availability:
  430. * Non-Carbon CFM: in UnicodeUtilitiesCoreLib 8.6 and later
  431. * CarbonLib: in CarbonLib 1.0 and later
  432. * Mac OS X: in version 10.0 and later
  433. */
  434. EXTERN_API_C( OSStatus )
  435. UCCompareTextNoLocale(
  436. UCCollateOptions options,
  437. const UniChar * text1Ptr,
  438. UniCharCount text1Length,
  439. const UniChar * text2Ptr,
  440. UniCharCount text2Length,
  441. Boolean * equivalent,
  442. SInt32 * order);
  443. /* Standard text break (text boundary) functions*/
  444. /*
  445. * UCCreateTextBreakLocator()
  446. *
  447. * Availability:
  448. * Non-Carbon CFM: in UnicodeUtilitiesLib 9.0 and later
  449. * CarbonLib: in CarbonLib 1.0 and later
  450. * Mac OS X: in version 10.0 and later
  451. */
  452. EXTERN_API_C( OSStatus )
  453. UCCreateTextBreakLocator(
  454. LocaleRef locale,
  455. LocaleOperationVariant opVariant,
  456. UCTextBreakType breakTypes,
  457. TextBreakLocatorRef * breakRef);
  458. /*
  459. * UCFindTextBreak()
  460. *
  461. * Availability:
  462. * Non-Carbon CFM: in UnicodeUtilitiesLib 9.0 and later
  463. * CarbonLib: in CarbonLib 1.0 and later
  464. * Mac OS X: in version 10.0 and later
  465. */
  466. EXTERN_API_C( OSStatus )
  467. UCFindTextBreak(
  468. TextBreakLocatorRef breakRef,
  469. UCTextBreakType breakType,
  470. UCTextBreakOptions options,
  471. const UniChar * textPtr,
  472. UniCharCount textLength,
  473. UniCharArrayOffset startOffset,
  474. UniCharArrayOffset * breakOffset);
  475. /*
  476. * UCDisposeTextBreakLocator()
  477. *
  478. * Availability:
  479. * Non-Carbon CFM: in UnicodeUtilitiesLib 9.0 and later
  480. * CarbonLib: in CarbonLib 1.0 and later
  481. * Mac OS X: in version 10.0 and later
  482. */
  483. EXTERN_API_C( OSStatus )
  484. UCDisposeTextBreakLocator(TextBreakLocatorRef * breakRef);
  485. #if PRAGMA_STRUCT_ALIGN
  486. #pragma options align=reset
  487. #elif PRAGMA_STRUCT_PACKPUSH
  488. #pragma pack(pop)
  489. #elif PRAGMA_STRUCT_PACK
  490. #pragma pack()
  491. #endif
  492. #ifdef PRAGMA_IMPORT_OFF
  493. #pragma import off
  494. #elif PRAGMA_IMPORT
  495. #pragma import reset
  496. #endif
  497. #ifdef __cplusplus
  498. }
  499. #endif
  500. #endif /* __UNICODEUTILITIES__ */