UnicodeUtilities.h
上传用户:xjjlds
上传日期:2015-12-05
资源大小:22823k
文件大小:22k
源码类别:

多媒体编程

开发平台:

Visual C++

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