⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chnconv_dll.cpp

📁 This software performs code conversion of Chinese characters, including GB2312/GBK and BIG5. It a
💻 CPP
📖 第 1 页 / 共 5 页
字号:
         }

         // 僼僅儞僩偺暥帤僙僢僩庢摼
         if ( ! strheadcmp ( szTag, szCharsetTag ) && isdigit ( *( szTag + strlen ( szCharsetTag ) ) ) ) {
            pDepthInfo->nCharset = atoi ( szTag + strlen ( szCharsetTag ) ) ;
            goto PROCEDURE_OUTPUT_TAG ;
         }

         // 僼僅儞僩忣曬僽儘僢僋偺張棟
         if ( ! ( pDepthInfo->dwAttributes & RTF_FONT_TABLE ) ) {
            if ( ! strcmp ( szTag, szFontTableTag ) ) {
               pDepthInfo->dwAttributes |= RTF_FONT_TABLE ;
               goto PROCEDURE_OUTPUT_TAG ;
            }
         }
         if ( pDepthInfo->dwAttributes & RTF_FONT_TABLE && pDepthInfo->dwAttributes & RTF_HIDDEN ) {
            if ( ! strcmp ( szTag, szFontAltTag ) ) {
               pDepthInfo->dwAttributes |= RTF_FONT_ALT ;
               goto PROCEDURE_OUTPUT_TAG ;
            }
         }

         // 僼傿乕儖僪偺張棟
         if ( ! ( pDepthInfo->dwAttributes & RTF_FIELD ) ) {
            if ( ! strcmp ( szTag, szFieldTag ) ) {
               pDepthInfo->dwAttributes |= RTF_FIELD ;
               goto PROCEDURE_OUTPUT_TAG ;
            }
         }
         else {
            if ( ! strcmp ( szTag, szFieldInstTag ) ) {
               pDepthInfo->dwAttributes |= RTF_FIELD_INST ;
               pDepthInfo->dwAttributes &= ~ RTF_HIDDEN ;
#if FIELD_DETECT
               ClearStoredCharsA ( Field ) ;
               IsFieldInstHidden = 0 ;
#endif
               goto PROCEDURE_OUTPUT_TAG ;
            }
            if ( ! strcmp ( szTag, szFieldResultTag ) ) {
               pDepthInfo->dwAttributes &= ~ RTF_FIELD_INST ;
               pDepthInfo->dwAttributes |= RTF_HIDDEN ;
               goto PROCEDURE_OUTPUT_TAG ;
            }
         }

         // 僥僉僗僩儃僢僋僗偺僥僉僗僩懏惈
         if ( ! ( pDepthInfo->dwAttributes & RTF_SHAPE ) ) {
            if ( ! strcmp ( szTag, szShapeTag ) ) {
               pDepthInfo->dwAttributes |= RTF_SHAPE ;
               goto PROCEDURE_OUTPUT_TAG ;
            }
         }
         else {
            if ( ! strcmp ( szTag, szShapeTextTag ) ) {
               pDepthInfo->dwAttributes &= ~ RTF_HIDDEN ;
               goto PROCEDURE_OUTPUT_TAG ;
            }
            if ( ! ( pDepthInfo->dwAttributes & RTF_SHAPE_RESULT ) ) {
               if ( ! strcmp ( szTag, szShapeResultTag ) ) {
                  pDepthInfo->dwAttributes |= RTF_SHAPE_RESULT ;
                  goto PROCEDURE_OUTPUT_TAG ;
               }
            }
            else {
               if ( ! strcmp ( szTag, szShapeResultTextTag ) ) {
                  pDepthInfo->dwAttributes &= ~ RTF_HIDDEN ;
                  goto PROCEDURE_OUTPUT_TAG ;
               }
            }
         }

         // 塀偟暥帤偺張棟
         if ( ! ( pDepthInfo->dwAttributes & RTF_HIDDEN ) ) {
            for ( int nCount = 0 ; nCount < HIDDEN_TAG_LIST_MAX ; nCount ++ ) {
               if ( ! strcmp ( szTag, HiddenTagList [ nCount ] ) ) {
                  pDepthInfo->dwAttributes |= RTF_HIDDEN ;
                  goto PROCEDURE_OUTPUT_TAG ;
               }
            }
         }

         // 暥摢専嵏
         if ( ! IsRtfFormat ) {
            if ( strheadcmp ( szTag, szRtfTag ) ) { pData->nError = CONV_ERROR_FORMAT ; goto CAUGHT_ERROR ; }
            IsRtfFormat = 1 ;
            goto PROCEDURE_OUTPUT_TAG ;
         }

         // 婛掕偺僐乕僪儁乕僕偺庢摼
         if ( ! strheadcmp ( szTag, szAnsiCpgTag ) && isdigit ( *( szTag + strlen ( szAnsiCpgTag ) ) ) ) {
            pDepthInfo->nDefaultCodePage = atoi ( szTag + strlen ( szAnsiCpgTag ) ) ;
            goto PROCEDURE_OUTPUT_TAG ;
         }

         // 僞僌弌椡僾儘僔乕僕儍
         PROCEDURE_OUTPUT_TAG :

         if ( pDepthInfo->nIncreaseDepth ) {
            StreamWrite ( BRACE_END, pData->StreamOut ) ;
            pDepthInfo->nIncreaseDepth = 0 ;
         }

         StreamWrite ( ESCAPE, pData->StreamOut ) ;
         StreamWriteString ( szTag, pData->StreamOut ) ;
         // 僞僌偺屻傠偺僗儁乕僗堦偮傪張棟
         if ( ( C = StreamRead ( pData->StreamIn ) ) == EOF ) break ;
         if ( C != 0x20 ) StreamUnread ( C, pData->StreamIn ) ;
         else             StreamWrite ( C, pData->StreamOut ) ;
         continue ;
      }


      // 暥帤偑捈愙偐偳偆偐
      IsCodeDirect = 1 ;
      IsCharacterHexa = 0 ;


      // 暥帤弌椡僾儘僔乕僕儍
      PROCEDURE_OUTPUT_CHAR :

      if ( ! IsRtfFormat ) { pData->nError = CONV_ERROR_FORMAT ; goto CAUGHT_ERROR ; }

      // 夵峴傪憲傞
      if ( C == '\r' || C == '\n' ) {
         StreamWrite ( C, pData->StreamOut ) ;
         continue ;
      }


      // Surrogate Pair
      if ( cUnicodeLead ) {
         if ( cUnicode && IsLowSurrogate ( cUnicode ) ) {
            cUnicode = MAKE_UNICODE_SCALAR ( cUnicodeLead, cUnicode ) ;
            cUnicodeLead = 0 ;
         }
         else {
            StreamWriteFormat ( pData->StreamOut, "\\uc%u\\u%hd \\\'%02x", 1, (short) cUnicodeLead, '?' ) ;
            cUnicodeLead = 0 ;
         }
      }
      else {
         if ( cUnicode && IsHighSurrogate ( cUnicode ) ) {
            cUnicodeLead = cUnicode ;
            cUnicode = 0 ;
            continue ;
         }
      }


      // 僐乕僪儁乕僕傪庢摼
      if ( pDepthInfo->dwAttributes & RTF_FONT_TABLE ) nCurrentCodePage = CharsetToCodePage ( pDepthInfo->nCharset ) ;
      else if ( pDepthInfo->nFont < 0 )                nCurrentCodePage = GetFontTableValue ( & FontTableInfo, pDepthInfo->nAltFont, pDepthInfo->nDefaultCodePage ) ;   // 捠忢偼巊傢傟側偄
      else                                             nCurrentCodePage = GetFontTableValue ( & FontTableInfo, pDepthInfo->nFont, pDepthInfo->nDefaultCodePage ) ;


#if FIELD_DETECT
      // 僼傿乕儖僪傪専嵏
      if ( pDepthInfo->dwAttributes & RTF_FIELD_INST ) {
         if ( IsCodeDirect && C == '\"' ) {
            int C2 ;
            if ( ( C2 = StreamRead ( pData->StreamIn ) ) == EOF ) break ;
            StreamUnread ( C2, pData->StreamIn ) ;

            char *szField = GetStoredCharsA ( Field ) ;
            if ( 0 ) {     // for debug
               StreamWriteFormat ( pData->StreamOut, "[%s]", szField ) ;
               StreamWriteFormat ( pData->StreamOut, "[%s]", GetLastKeyword ( szField ) ) ;
            }
            if ( IsFieldInstHidden || ! strheadcmp ( GetFirstKeyword ( szField ), szFieldEqTag ) && ! strheadcmp ( GetLastKeyword ( szField ), szFieldAsteriskTag ) && C2 == 'F' ) {
               IsFieldInstHidden = ! IsFieldInstHidden ;
               continue ;
            }
         }
         StoreCharsA ( C, Field ) ;
         if ( IsFieldInstHidden ) continue ;
      }
#endif


      // 僼僅儞僩僥乕僽儖偺張棟
      if ( pDepthInfo->dwAttributes & RTF_FONT_TABLE ) {
         if ( C == ';' ) {

            char *szFontName = GetStoredCharsA ( FontName ) ;
            char *szAltFontName = GetStoredCharsA ( AltFontName ) ;

            if ( pDepthInfo->nFont > nFontMax ) nFontMax = pDepthInfo->nFont ;

            if ( nCurrentCodePage == ( pData->nDstCodePage & CP_DEFINE_CODEPAGE ) ) {
               if ( ! strcmp ( szFontName, szDstFont ) )       nDstFont = pDepthInfo->nFont ;
               if ( ! strcmp ( szFontName, szDstGothicFont ) ) nDstGothicFont = pDepthInfo->nFont ;
            }
            if ( nCurrentCodePage == CP_JAPANESE ) {
               if ( ! strcmp ( szFontName, szKgFont ) )         nKgFont = pDepthInfo->nFont ;
               if ( ! strcmp ( szFontName, szKgGothicFont ) )   nKgGothicFont = pDepthInfo->nFont ;
               if ( ! strcmp ( szFontName, szCwnfFont ) )       nCwnfFont = pDepthInfo->nFont ;
               if ( ! strcmp ( szFontName, szCwnfGothicFont ) ) nCwnfGothicFont = pDepthInfo->nFont ;
               if ( ! strcmp ( szFontName, szNh3pFont ) )       nNh3pFont = pDepthInfo->nFont ;
            }
            if ( nCurrentCodePage == CP_ANSI_EUROPEAN ) {
               if ( ! strcmp ( szFontName, pData->szPinyinFont ) )       nPinyinFont = pDepthInfo->nFont ;
               if ( ! strcmp ( szFontName, pData->szPinyinGothicFont ) ) nPinyinGothicFont = pDepthInfo->nFont ;
            }

            char *szPseudoFontName = szFontName ;
            if ( *szPseudoFontName == '@' ) szPseudoFontName ++ ;

            // 僼僅儞僩柤偺夝庍
            nCurrentCodePage = FontNameToPseudoCodePage ( nCurrentCodePage, szPseudoFontName ) ;
            if ( ( nCurrentCodePage & ( CP_DEFINE_CODEPAGE | CP_DEFINE_PSEUDOCODE ) ) == pData->nSrcCodePage ) IsExistSrcFont = 1 ;

            // CW7
            if ( ( nCurrentCodePage & ( CP_DEFINE_CODEPAGE | CP_DEFINE_PSEUDOCODE ) ) == CP_JAPANESE_CW ) {
               if ( IsAsciiString ( szPseudoFontName ) ) {
                  const char *szLocalizedName = GetLocalizedFontName ( CodePageToCharset ( CP_JAPANESE ), szPseudoFontName, NULL ) ;
                  if ( szLocalizedName && strcmp ( szAltFontName, szLocalizedName ) ) WriteAltFontName ( szLocalizedName, CP_JAPANESE, pData->StreamOut ) ;
               }
               else {
                  const char *szEnglishName = GetEnglishFontName ( CodePageToCharset ( CP_JAPANESE ), szPseudoFontName, NULL ) ;
                  if ( szEnglishName && strcmp ( szAltFontName, szEnglishName ) ) WriteAltFontName ( szEnglishName, CP_JAPANESE, pData->StreamOut ) ;
               }
            }

            ClearStoredCharsA ( FontName ) ;
            ClearStoredCharsA ( AltFontName ) ;

            // 曄姺寢壥傪斀塮
            SetFontTableValue ( & FontTableInfo, pDepthInfo->nFont, nCurrentCodePage ) ;
         }
         // 僼僅儞僩柤偺庢摼
         else {
            if ( pDepthInfo->dwAttributes & RTF_HIDDEN ) {
               if ( pDepthInfo->dwAttributes & RTF_FONT_ALT ) {
                  AltFontName = StoreCharsA ( C & 0xFF, AltFontName ) ;
                  if ( AltFontName == STOREDCHARS_ERROR ) { pData->nError = CONV_ERROR_MEMORY ; goto CAUGHT_ERROR ; }
               }
            }
            else {
               FontName = StoreCharsA ( C & 0xFF, FontName ) ;
               if ( FontName == STOREDCHARS_ERROR ) { pData->nError = CONV_ERROR_MEMORY ; goto CAUGHT_ERROR ; }
            }
         }
      }


      // 俀僶僀僩暥帤偺侾僶僀僩栚偐偳偆偐傪専嵏
      if ( ! cLeadChar && ismbblead_cp ( C, nCurrentCodePage & CP_DEFINE_CODEPAGE ) ) {
         cLeadChar = C ;
         continue ;
      }

      // 俀僶僀僩暥帤偺俀僶僀僩栚傪張棟
      if ( cLeadChar ) {
         C = ( cLeadChar << 8 ) | C ;
         cLeadChar = 0 ;
      }


      // 尵岅忣曬傪弌椡
      if ( ( pDepthInfo->dwAttributes & ( RTF_FONT_TABLE | RTF_HIDDEN | RTF_LANG ) ) == RTF_LANG ) {
         if ( ( nCurrentCodePage & ( CP_DEFINE_CODEPAGE | CP_DEFINE_PSEUDOCODE ) ) == pData->nSrcCodePage ) {
            pDepthInfo->nLang = nDstLang ;
            pDepthInfo->nLangFe = nDstLangFe ;
            pDepthInfo->nLangFeNp = nDstLangFeNp ;
         }
         WriteLangInfo ( pDepthInfo->nLang, pDepthInfo->nLangFe, pDepthInfo->nLangFeNp, pData->StreamOut ) ;
         pDepthInfo->dwAttributes &= ~ RTF_LANG ;
      }


      // 暥帤傪曄姺
      if ( ! ( pDepthInfo->dwAttributes & ( RTF_FONT_TABLE | RTF_HIDDEN ) ) && ( nCurrentCodePage & ( CP_DEFINE_CODEPAGE | CP_DEFINE_PSEUDOCODE ) ) == pData->nSrcCodePage ) {

         // 捠忢偼巊傢傟側偄
         if ( pDepthInfo->nFont < 0 && pDepthInfo->nAltFont > 0 ) {
            StreamWriteFormat ( pData->StreamOut, "\\f%u ", GetNewFontNumber ( pData, nCurrentCodePage, nDstFont, nDstGothicFont, nKgFont, nKgGothicFont, nCwnfFont, nCwnfGothicFont, NULL ) ) ;
            pDepthInfo->nFont = pDepthInfo->nAltFont ;
         }

         // 擮偺偨傔
         if ( cUnicode && ! ( pData->dwConversionMode & CONVMODE_NO_USE_UNICODE ) ) {
            int cTmp = ConvertCharacterEx ( cUnicode, CP_UTF16, nCurrentCodePage & CP_DEFINE_CODEPAGE ) ;
            if ( cTmp ) {
               C = cTmp ;
               cUnicode = 0 ;
            }
         }

         int cSaved = C ;
         if ( ( nCurrentCodePage & CP_DEFINE_CODEPAGE ) == CP_JAPANESE ) {
            cUnicode = 0 ;                               // 媅帡僐乕僪偺 Unicode 巜掕傪柍岠偵偡傞
            if ( C != 0xEEF9 ) C = SjisNec2ibm ( C ) ;   // NEC->IBM
         }

         int nIncreaseDepth = 0 ;

         // 傑偢嵟弶偵儐乕僓巜掕偺曄姺
         int cResult = ConvertByUserDefinition ( C, & cUnicode, pData ) ;

         // 僥乕僽儖偱曄姺偱偒側偄傕偺傪 Unicode 偵捈愙曄姺
         if ( ! cResult && ! cUnicode ) {
            if ( ! ( pData->dwConversionMode & CONVMODE_NO_USE_UNICODE ) ) {
               if ( ConvertChineseCharacter == Cw2gb || ConvertChineseCharacter == Cw2big5 )        cUnicode = Kg2uc_NoGbOnly ( C ) ;
               else if ( ConvertChineseCharacter == Cwn2gb || ConvertChineseCharacter == Cwn2big5 ) cUnicode = Cwn2uc_NoGbOnly ( C ) ;
               if ( cUnicode ) cResult = '?' ;
            }
         }

         // 曄姺偺儊僀儞
         if ( ! cResult && ! cUnicode ) {
            if ( C < 0x100 || ismbbtrail_cp ( C & 0xFF, nCurrentCodePage & CP_DEFINE_CODEPAGE ) ) {
               if ( nCurrentCodePage & CP_FANTI ) cResult = ConvertChineseCharacterFanti ( C, pData->dwConversionMode ) ;
               else                               cResult = ConvertChineseCharacter ( C, pData->dwConversionMode ) ;
            }
         }

         // HKSCS
         if ( ! cResult && ! cUnicode ) {
            if ( ! ( pData->dwConversionMode & CONVMODE_NO_USE_UNICODE ) ) {
               if ( ( nCurrentCodePage & ( CP_DEFINE_CODEPAGE | CP_DEFINE_OPTIONAL ) ) == CP_CHINESE_TRADITIONAL_HK ) {
                  int cUnicodePua = GaijiToUnicode ( C, pData->nSrcCodePage & CP_DEFINE_CODEPAGE ) ;
                  cUnicode = HkscsUni2uni ( cUnicodePua, TRUE ) ;
               }
            }
         }

         // 奜帤
         if ( ! cResult && ! cUnicode ) {
            if ( ( pData->nSrcCodePage & CP_DEFINE_CODEPAGE ) != CP_JAPANESE && ( pData->nDstCodePage & CP_DEFINE_CODEPAGE ) != CP_JAPANESE ) {
               cUnicode = GaijiToUnicode ( C, pData->nSrcCodePage & CP_DEFINE_CODEPAGE ) ;
               cResult = UnicodeToGaiji ( cUnicode, pData->nDstCodePage & CP_DEFINE_CODEPAGE ) ;
               if ( pData->nSrcCodePage == CP_CHINESE_SIMPLIFIED && C >= 0xFE50 && C <= 0xFEA0 ) cResult = 0 ;
               if ( pData->nDstCodePage == CP_CHINESE_SIMPLIFIED

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -