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

多媒体编程

开发平台:

Visual C++

  1. /*
  2.      File:       UnicodeConverter.h
  3.  
  4.      Contains:   Types, constants, and prototypes for Unicode Converter
  5.  
  6.      Version:    Technology: Mac OS 9.0
  7.                  Release:    QuickTime 6.0.2
  8.  
  9.      Copyright:  (c) 1994-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 __UNICODECONVERTER__
  18. #define __UNICODECONVERTER__
  19. #ifndef __MACTYPES__
  20. #include "MacTypes.h"
  21. #endif
  22. #ifndef __TEXTCOMMON__
  23. #include "TextCommon.h"
  24. #endif
  25. #ifndef __MIXEDMODE__
  26. #include "MixedMode.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. /* Unicode conversion contexts: */
  45. typedef struct OpaqueTextToUnicodeInfo*  TextToUnicodeInfo;
  46. typedef struct OpaqueUnicodeToTextInfo*  UnicodeToTextInfo;
  47. typedef struct OpaqueUnicodeToTextRunInfo*  UnicodeToTextRunInfo;
  48. typedef const TextToUnicodeInfo         ConstTextToUnicodeInfo;
  49. typedef const UnicodeToTextInfo         ConstUnicodeToTextInfo;
  50. /* UnicodeMapVersion type & values */
  51. typedef SInt32                          UnicodeMapVersion;
  52. enum {
  53.     kUnicodeUseLatestMapping    = -1,
  54.     kUnicodeUseHFSPlusMapping   = 4
  55. };
  56. /* Types used in conversion */
  57. struct UnicodeMapping {
  58.     TextEncoding                    unicodeEncoding;
  59.     TextEncoding                    otherEncoding;
  60.     UnicodeMapVersion               mappingVersion;
  61. };
  62. typedef struct UnicodeMapping           UnicodeMapping;
  63. typedef UnicodeMapping *                UnicodeMappingPtr;
  64. typedef const UnicodeMapping *          ConstUnicodeMappingPtr;
  65. /* Control flags for ConvertFromUnicodeToText and ConvertFromTextToUnicode */
  66. enum {
  67.     kUnicodeUseFallbacksBit     = 0,
  68.     kUnicodeKeepInfoBit         = 1,
  69.     kUnicodeDirectionalityBits  = 2,
  70.     kUnicodeVerticalFormBit     = 4,
  71.     kUnicodeLooseMappingsBit    = 5,
  72.     kUnicodeStringUnterminatedBit = 6,
  73.     kUnicodeTextRunBit          = 7,
  74.     kUnicodeKeepSameEncodingBit = 8,
  75.     kUnicodeForceASCIIRangeBit  = 9,
  76.     kUnicodeNoHalfwidthCharsBit = 10,
  77.     kUnicodeTextRunHeuristicsBit = 11
  78. };
  79. enum {
  80.     kUnicodeUseFallbacksMask    = 1L << kUnicodeUseFallbacksBit,
  81.     kUnicodeKeepInfoMask        = 1L << kUnicodeKeepInfoBit,
  82.     kUnicodeDirectionalityMask  = 3L << kUnicodeDirectionalityBits,
  83.     kUnicodeVerticalFormMask    = 1L << kUnicodeVerticalFormBit,
  84.     kUnicodeLooseMappingsMask   = 1L << kUnicodeLooseMappingsBit,
  85.     kUnicodeStringUnterminatedMask = 1L << kUnicodeStringUnterminatedBit,
  86.     kUnicodeTextRunMask         = 1L << kUnicodeTextRunBit,
  87.     kUnicodeKeepSameEncodingMask = 1L << kUnicodeKeepSameEncodingBit,
  88.     kUnicodeForceASCIIRangeMask = 1L << kUnicodeForceASCIIRangeBit,
  89.     kUnicodeNoHalfwidthCharsMask = 1L << kUnicodeNoHalfwidthCharsBit,
  90.     kUnicodeTextRunHeuristicsMask = 1L << kUnicodeTextRunHeuristicsBit
  91. };
  92. /* Values for kUnicodeDirectionality field */
  93. enum {
  94.     kUnicodeDefaultDirection    = 0,
  95.     kUnicodeLeftToRight         = 1,
  96.     kUnicodeRightToLeft         = 2
  97. };
  98. /* Directionality masks for control flags */
  99. enum {
  100.     kUnicodeDefaultDirectionMask = kUnicodeDefaultDirection << kUnicodeDirectionalityBits,
  101.     kUnicodeLeftToRightMask     = kUnicodeLeftToRight << kUnicodeDirectionalityBits,
  102.     kUnicodeRightToLeftMask     = kUnicodeRightToLeft << kUnicodeDirectionalityBits
  103. };
  104. /* Control flags for TruncateForUnicodeToText: */
  105. /*
  106.    Now TruncateForUnicodeToText uses control flags from the same set as used by
  107.    ConvertFromTextToUnicode, ConvertFromUnicodeToText, etc., but only
  108.    kUnicodeStringUnterminatedMask is meaningful for TruncateForUnicodeToText.
  109.    
  110.    Previously two special control flags were defined for TruncateForUnicodeToText:
  111.         kUnicodeTextElementSafeBit = 0
  112.         kUnicodeRestartSafeBit = 1
  113.    However, neither of these was implemented.
  114.    Instead of implementing kUnicodeTextElementSafeBit, we now use
  115.    kUnicodeStringUnterminatedMask since it accomplishes the same thing and avoids
  116.    having special flags just for TruncateForUnicodeToText
  117.    Also, kUnicodeRestartSafeBit is unnecessary, since restart-safeness is handled by
  118.    setting kUnicodeKeepInfoBit with ConvertFromUnicodeToText.
  119.    If TruncateForUnicodeToText is called with one or both of the old special control
  120.    flags set (bits 0 or 1), it will not generate a paramErr, but the old bits have no
  121.    effect on its operation.
  122. */
  123. /* Filter bits for filter field in QueryUnicodeMappings and CountUnicodeMappings: */
  124. enum {
  125.     kUnicodeMatchUnicodeBaseBit = 0,
  126.     kUnicodeMatchUnicodeVariantBit = 1,
  127.     kUnicodeMatchUnicodeFormatBit = 2,
  128.     kUnicodeMatchOtherBaseBit   = 3,
  129.     kUnicodeMatchOtherVariantBit = 4,
  130.     kUnicodeMatchOtherFormatBit = 5
  131. };
  132. enum {
  133.     kUnicodeMatchUnicodeBaseMask = 1L << kUnicodeMatchUnicodeBaseBit,
  134.     kUnicodeMatchUnicodeVariantMask = 1L << kUnicodeMatchUnicodeVariantBit,
  135.     kUnicodeMatchUnicodeFormatMask = 1L << kUnicodeMatchUnicodeFormatBit,
  136.     kUnicodeMatchOtherBaseMask  = 1L << kUnicodeMatchOtherBaseBit,
  137.     kUnicodeMatchOtherVariantMask = 1L << kUnicodeMatchOtherVariantBit,
  138.     kUnicodeMatchOtherFormatMask = 1L << kUnicodeMatchOtherFormatBit
  139. };
  140. /* Control flags for SetFallbackUnicodeToText */
  141. enum {
  142.     kUnicodeFallbackSequencingBits = 0
  143. };
  144. enum {
  145.     kUnicodeFallbackSequencingMask = 3L << kUnicodeFallbackSequencingBits,
  146.     kUnicodeFallbackInterruptSafeMask = 1L << 2                 /* To indicate that caller fallback routine doesn't move memory*/
  147. };
  148. /* values for kUnicodeFallbackSequencing field */
  149. enum {
  150.     kUnicodeFallbackDefaultOnly = 0L,
  151.     kUnicodeFallbackCustomOnly  = 1L,
  152.     kUnicodeFallbackDefaultFirst = 2L,
  153.     kUnicodeFallbackCustomFirst = 3L
  154. };
  155. /* Caller-supplied entry point to a fallback handler */
  156. typedef CALLBACK_API( OSStatus , UnicodeToTextFallbackProcPtr )(UniChar *iSrcUniStr, ByteCount iSrcUniStrLen, ByteCount *oSrcConvLen, TextPtr oDestStr, ByteCount iDestStrLen, ByteCount *oDestConvLen, LogicalAddress iInfoPtr, ConstUnicodeMappingPtr iUnicodeMappingPtr);
  157. typedef STACK_UPP_TYPE(UnicodeToTextFallbackProcPtr)            UnicodeToTextFallbackUPP;
  158. #if OPAQUE_UPP_TYPES
  159.     EXTERN_API(UnicodeToTextFallbackUPP)
  160.     NewUnicodeToTextFallbackUPP    (UnicodeToTextFallbackProcPtr userRoutine);
  161.     EXTERN_API(void)
  162.     DisposeUnicodeToTextFallbackUPP    (UnicodeToTextFallbackUPP userUPP);
  163.     EXTERN_API(OSStatus)
  164.     InvokeUnicodeToTextFallbackUPP    (UniChar *            iSrcUniStr,
  165.                                     ByteCount               iSrcUniStrLen,
  166.                                     ByteCount *             oSrcConvLen,
  167.                                     TextPtr                 oDestStr,
  168.                                     ByteCount               iDestStrLen,
  169.                                     ByteCount *             oDestConvLen,
  170.                                     LogicalAddress          iInfoPtr,
  171.                                     ConstUnicodeMappingPtr  iUnicodeMappingPtr,
  172.                                     UnicodeToTextFallbackUPP userUPP);
  173. #else
  174.     enum { uppUnicodeToTextFallbackProcInfo = 0x003FFFF0 };         /* pascal 4_bytes Func(4_bytes, 4_bytes, 4_bytes, 4_bytes, 4_bytes, 4_bytes, 4_bytes, 4_bytes) */
  175.     #define NewUnicodeToTextFallbackUPP(userRoutine)                (UnicodeToTextFallbackUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppUnicodeToTextFallbackProcInfo, GetCurrentArchitecture())
  176.     #define DisposeUnicodeToTextFallbackUPP(userUPP)                DisposeRoutineDescriptor(userUPP)
  177.     #define InvokeUnicodeToTextFallbackUPP(iSrcUniStr, iSrcUniStrLen, oSrcConvLen, oDestStr, iDestStrLen, oDestConvLen, iInfoPtr, iUnicodeMappingPtr, userUPP)  (OSStatus)CALL_EIGHT_PARAMETER_UPP((userUPP), uppUnicodeToTextFallbackProcInfo, (iSrcUniStr), (iSrcUniStrLen), (oSrcConvLen), (oDestStr), (iDestStrLen), (oDestConvLen), (iInfoPtr), (iUnicodeMappingPtr))
  178. #endif
  179. /* support for pre-Carbon UPP routines: NewXXXProc and CallXXXProc */
  180. #define NewUnicodeToTextFallbackProc(userRoutine)               NewUnicodeToTextFallbackUPP(userRoutine)
  181. #define CallUnicodeToTextFallbackProc(userRoutine, iSrcUniStr, iSrcUniStrLen, oSrcConvLen, oDestStr, iDestStrLen, oDestConvLen, iInfoPtr, iUnicodeMappingPtr) InvokeUnicodeToTextFallbackUPP(iSrcUniStr, iSrcUniStrLen, oSrcConvLen, oDestStr, iDestStrLen, oDestConvLen, iInfoPtr, iUnicodeMappingPtr, userRoutine)
  182. /* Function prototypes */
  183. #if TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  184. /*
  185.     Routine to Initialize the Unicode Converter and cleanup once done with it. 
  186.     These routines must be called from Static Library clients.
  187. */
  188. #if CALL_NOT_IN_CARBON
  189. EXTERN_API( OSStatus )
  190. InitializeUnicodeConverter      (StringPtr              TECFileName);
  191. EXTERN_API( void )
  192. TerminateUnicodeConverter       (void);
  193. /* Note: the old names (InitializeUnicode, TerminateUnicode) for the above are still exported.*/
  194. #endif  /* CALL_NOT_IN_CARBON */
  195. #endif  /* TARGET_CPU_68K && !TARGET_RT_MAC_CFM */
  196. EXTERN_API( OSStatus )
  197. CreateTextToUnicodeInfo         (ConstUnicodeMappingPtr  iUnicodeMapping,
  198.                                  TextToUnicodeInfo *    oTextToUnicodeInfo);
  199. EXTERN_API( OSStatus )
  200. CreateTextToUnicodeInfoByEncoding (TextEncoding         iEncoding,
  201.                                  TextToUnicodeInfo *    oTextToUnicodeInfo);
  202. EXTERN_API( OSStatus )
  203. CreateUnicodeToTextInfo         (ConstUnicodeMappingPtr  iUnicodeMapping,
  204.                                  UnicodeToTextInfo *    oUnicodeToTextInfo);
  205. EXTERN_API( OSStatus )
  206. CreateUnicodeToTextInfoByEncoding (TextEncoding         iEncoding,
  207.                                  UnicodeToTextInfo *    oUnicodeToTextInfo);
  208. EXTERN_API( OSStatus )
  209. CreateUnicodeToTextRunInfo      (ItemCount              iNumberOfMappings,
  210.                                  const UnicodeMapping   iUnicodeMappings[],
  211.                                  UnicodeToTextRunInfo * oUnicodeToTextInfo);
  212. EXTERN_API( OSStatus )
  213. CreateUnicodeToTextRunInfoByEncoding (ItemCount         iNumberOfEncodings,
  214.                                  const TextEncoding     iEncodings[],
  215.                                  UnicodeToTextRunInfo * oUnicodeToTextInfo);
  216. EXTERN_API( OSStatus )
  217. CreateUnicodeToTextRunInfoByScriptCode (ItemCount       iNumberOfScriptCodes,
  218.                                  const ScriptCode       iScripts[],
  219.                                  UnicodeToTextRunInfo * oUnicodeToTextInfo);
  220. /* Change the TextToUnicodeInfo to another mapping. */
  221. EXTERN_API( OSStatus )
  222. ChangeTextToUnicodeInfo         (TextToUnicodeInfo      ioTextToUnicodeInfo,
  223.                                  ConstUnicodeMappingPtr  iUnicodeMapping);
  224. /* Change the UnicodeToTextInfo to another mapping. */
  225. EXTERN_API( OSStatus )
  226. ChangeUnicodeToTextInfo         (UnicodeToTextInfo      ioUnicodeToTextInfo,
  227.                                  ConstUnicodeMappingPtr  iUnicodeMapping);
  228. EXTERN_API( OSStatus )
  229. DisposeTextToUnicodeInfo        (TextToUnicodeInfo *    ioTextToUnicodeInfo);
  230. EXTERN_API( OSStatus )
  231. DisposeUnicodeToTextInfo        (UnicodeToTextInfo *    ioUnicodeToTextInfo);
  232. EXTERN_API( OSStatus )
  233. DisposeUnicodeToTextRunInfo     (UnicodeToTextRunInfo * ioUnicodeToTextRunInfo);
  234. EXTERN_API( OSStatus )
  235. ConvertFromTextToUnicode        (TextToUnicodeInfo      iTextToUnicodeInfo,
  236.                                  ByteCount              iSourceLen,
  237.                                  ConstLogicalAddress    iSourceStr,
  238.                                  OptionBits             iControlFlags,
  239.                                  ItemCount              iOffsetCount,
  240.                                  ByteOffset             iOffsetArray[], /* can be NULL */
  241.                                  ItemCount *            oOffsetCount, /* can be NULL */
  242.                                  ByteOffset             oOffsetArray[], /* can be NULL */
  243.                                  ByteCount              iOutputBufLen,
  244.                                  ByteCount *            oSourceRead,
  245.                                  ByteCount *            oUnicodeLen,
  246.                                  UniCharArrayPtr        oUnicodeStr);
  247. EXTERN_API( OSStatus )
  248. ConvertFromUnicodeToText        (UnicodeToTextInfo      iUnicodeToTextInfo,
  249.                                  ByteCount              iUnicodeLen,
  250.                                  ConstUniCharArrayPtr   iUnicodeStr,
  251.                                  OptionBits             iControlFlags,
  252.                                  ItemCount              iOffsetCount,
  253.                                  ByteOffset             iOffsetArray[], /* can be NULL */
  254.                                  ItemCount *            oOffsetCount, /* can be NULL */
  255.                                  ByteOffset             oOffsetArray[], /* can be NULL */
  256.                                  ByteCount              iOutputBufLen,
  257.                                  ByteCount *            oInputRead,
  258.                                  ByteCount *            oOutputLen,
  259.                                  LogicalAddress         oOutputStr);
  260. EXTERN_API( OSStatus )
  261. ConvertFromUnicodeToTextRun     (UnicodeToTextRunInfo   iUnicodeToTextInfo,
  262.                                  ByteCount              iUnicodeLen,
  263.                                  ConstUniCharArrayPtr   iUnicodeStr,
  264.                                  OptionBits             iControlFlags,
  265.                                  ItemCount              iOffsetCount,
  266.                                  ByteOffset             iOffsetArray[], /* can be NULL */
  267.                                  ItemCount *            oOffsetCount, /* can be NULL */
  268.                                  ByteOffset             oOffsetArray[], /* can be NULL */
  269.                                  ByteCount              iOutputBufLen,
  270.                                  ByteCount *            oInputRead,
  271.                                  ByteCount *            oOutputLen,
  272.                                  LogicalAddress         oOutputStr,
  273.                                  ItemCount              iEncodingRunBufLen,
  274.                                  ItemCount *            oEncodingRunOutLen,
  275.                                  TextEncodingRun        oEncodingRuns[]);
  276. EXTERN_API( OSStatus )
  277. ConvertFromUnicodeToScriptCodeRun (UnicodeToTextRunInfo  iUnicodeToTextInfo,
  278.                                  ByteCount              iUnicodeLen,
  279.                                  ConstUniCharArrayPtr   iUnicodeStr,
  280.                                  OptionBits             iControlFlags,
  281.                                  ItemCount              iOffsetCount,
  282.                                  ByteOffset             iOffsetArray[], /* can be NULL */
  283.                                  ItemCount *            oOffsetCount, /* can be NULL */
  284.                                  ByteOffset             oOffsetArray[], /* can be NULL */
  285.                                  ByteCount              iOutputBufLen,
  286.                                  ByteCount *            oInputRead,
  287.                                  ByteCount *            oOutputLen,
  288.                                  LogicalAddress         oOutputStr,
  289.                                  ItemCount              iScriptRunBufLen,
  290.                                  ItemCount *            oScriptRunOutLen,
  291.                                  ScriptCodeRun          oScriptCodeRuns[]);
  292. /* Truncate a multibyte string at a safe place. */
  293. EXTERN_API( OSStatus )
  294. TruncateForTextToUnicode        (ConstTextToUnicodeInfo  iTextToUnicodeInfo,
  295.                                  ByteCount              iSourceLen,
  296.                                  ConstLogicalAddress    iSourceStr,
  297.                                  ByteCount              iMaxLen,
  298.                                  ByteCount *            oTruncatedLen);
  299. /* Truncate a Unicode string at a safe place. */
  300. EXTERN_API( OSStatus )
  301. TruncateForUnicodeToText        (ConstUnicodeToTextInfo  iUnicodeToTextInfo,
  302.                                  ByteCount              iSourceLen,
  303.                                  ConstUniCharArrayPtr   iSourceStr,
  304.                                  OptionBits             iControlFlags,
  305.                                  ByteCount              iMaxLen,
  306.                                  ByteCount *            oTruncatedLen);
  307. /* Convert a Pascal string to Unicode string. */
  308. EXTERN_API( OSStatus )
  309. ConvertFromPStringToUnicode     (TextToUnicodeInfo      iTextToUnicodeInfo,
  310.                                  ConstStr255Param       iPascalStr,
  311.                                  ByteCount              iOutputBufLen,
  312.                                  ByteCount *            oUnicodeLen,
  313.                                  UniCharArrayPtr        oUnicodeStr);
  314. /* Convert a Unicode string to Pascal string. */
  315. EXTERN_API( OSStatus )
  316. ConvertFromUnicodeToPString     (UnicodeToTextInfo      iUnicodeToTextInfo,
  317.                                  ByteCount              iUnicodeLen,
  318.                                  ConstUniCharArrayPtr   iUnicodeStr,
  319.                                  Str255                 oPascalStr);
  320. /* Count the available conversion mappings. */
  321. EXTERN_API( OSStatus )
  322. CountUnicodeMappings            (OptionBits             iFilter,
  323.                                  ConstUnicodeMappingPtr  iFindMapping,
  324.                                  ItemCount *            oActualCount);
  325. /* Get a list of the available conversion mappings. */
  326. EXTERN_API( OSStatus )
  327. QueryUnicodeMappings            (OptionBits             iFilter,
  328.                                  ConstUnicodeMappingPtr  iFindMapping,
  329.                                  ItemCount              iMaxCount,
  330.                                  ItemCount *            oActualCount,
  331.                                  UnicodeMapping         oReturnedMappings[]);
  332. /* Setup the fallback handler for converting Unicode To Text. */
  333. EXTERN_API( OSStatus )
  334. SetFallbackUnicodeToText        (UnicodeToTextInfo      iUnicodeToTextInfo,
  335.                                  UnicodeToTextFallbackUPP  iFallback,
  336.                                  OptionBits             iControlFlags,
  337.                                  LogicalAddress         iInfoPtr);
  338. /* Setup the fallback handler for converting Unicode To TextRuns. */
  339. EXTERN_API( OSStatus )
  340. SetFallbackUnicodeToTextRun     (UnicodeToTextRunInfo   iUnicodeToTextRunInfo,
  341.                                  UnicodeToTextFallbackUPP  iFallback,
  342.                                  OptionBits             iControlFlags,
  343.                                  LogicalAddress         iInfoPtr);
  344. #if PRAGMA_STRUCT_ALIGN
  345.     #pragma options align=reset
  346. #elif PRAGMA_STRUCT_PACKPUSH
  347.     #pragma pack(pop)
  348. #elif PRAGMA_STRUCT_PACK
  349.     #pragma pack()
  350. #endif
  351. #ifdef PRAGMA_IMPORT_OFF
  352. #pragma import off
  353. #elif PRAGMA_IMPORT
  354. #pragma import reset
  355. #endif
  356. #ifdef __cplusplus
  357. }
  358. #endif
  359. #endif /* __UNICODECONVERTER__ */