diff options
Diffstat (limited to 'core/src/fxcrt')
-rw-r--r-- | core/src/fxcrt/extension.h | 38 | ||||
-rw-r--r-- | core/src/fxcrt/fx_arabic.cpp | 1078 | ||||
-rw-r--r-- | core/src/fxcrt/fx_arabic.h | 175 | ||||
-rw-r--r-- | core/src/fxcrt/fx_extension.cpp | 49 | ||||
-rw-r--r-- | core/src/fxcrt/fx_xml_parser.cpp | 4 |
5 files changed, 1341 insertions, 3 deletions
diff --git a/core/src/fxcrt/extension.h b/core/src/fxcrt/extension.h index c23a2e3369..05aad67e40 100644 --- a/core/src/fxcrt/extension.h +++ b/core/src/fxcrt/extension.h @@ -26,6 +26,44 @@ public: virtual FX_BOOL Truncate(FX_FILESIZE szFile) = 0; }; IFXCRT_FileAccess* FXCRT_FileAccess_Create(); +class CFX_CRTFileAccess : public IFX_FileAccess, public CFX_Object +{ +public: + CFX_CRTFileAccess() : m_RefCount(0) {} + + virtual void Release() + { + if (--m_RefCount == 0) + delete this; + } + + IFX_FileAccess* Retain() + { + m_RefCount++; + return (IFX_FileAccess*)this; + } + + virtual FX_BOOL Init(FX_WSTR wsPath) + { + m_path = wsPath; + m_RefCount = 1; + return TRUE; + } + + virtual void GetPath(CFX_WideString& wsPath) + { + wsPath = m_path; + } + + virtual IFX_FileStream* CreateFileStream(FX_DWORD dwModes) + { + return FX_CreateFileStream(m_path, dwModes); + } + +protected: + CFX_WideString m_path; + FX_DWORD m_RefCount; +}; class CFX_CRTFileStream FX_FINAL : public IFX_FileStream, public CFX_Object { public: diff --git a/core/src/fxcrt/fx_arabic.cpp b/core/src/fxcrt/fx_arabic.cpp index 583ce817cf..dd5d1d81bd 100644 --- a/core/src/fxcrt/fx_arabic.cpp +++ b/core/src/fxcrt/fx_arabic.cpp @@ -7,6 +7,1084 @@ #include "../../include/fxcrt/fx_ext.h" #include "fx_arabic.h" extern const FX_DWORD gs_FX_TextLayout_CodeProperties[65536]; +#ifdef __cplusplus +extern "C" { +#endif +static const FX_ARBFORMTABLE g_FX_ArabicFormTables[] = { + {0xFE81, 0xFE82, 0xFE81, 0xFE82}, + {0xFE83, 0xFE84, 0xFE83, 0xFE84}, + {0xFE85, 0xFE86, 0xFE85, 0xFE86}, + {0xFE87, 0xFE88, 0xFE87, 0xFE88}, + {0xFE89, 0xFE8A, 0xFE8B, 0xFE8C}, + {0xFE8D, 0xFE8E, 0xFE8D, 0xFE8E}, + {0xFE8F, 0xFE90, 0xFE91, 0xFE92}, + {0xFE93, 0xFE94, 0xFE93, 0xFE94}, + {0xFE95, 0xFE96, 0xFE97, 0xFE98}, + {0xFE99, 0xFE9A, 0xFE9B, 0xFE9C}, + {0xFE9D, 0xFE9E, 0xFE9F, 0xFEA0}, + {0xFEA1, 0xFEA2, 0xFEA3, 0xFEA4}, + {0xFEA5, 0xFEA6, 0xFEA7, 0xFEA8}, + {0xFEA9, 0xFEAA, 0xFEA9, 0xFEAA}, + {0xFEAB, 0xFEAC, 0xFEAB, 0xFEAC}, + {0xFEAD, 0xFEAE, 0xFEAD, 0xFEAE}, + {0xFEAF, 0xFEB0, 0xFEAF, 0xFEB0}, + {0xFEB1, 0xFEB2, 0xFEB3, 0xFEB4}, + {0xFEB5, 0xFEB6, 0xFEB7, 0xFEB8}, + {0xFEB9, 0xFEBA, 0xFEBB, 0xFEBC}, + {0xFEBD, 0xFEBE, 0xFEBF, 0xFEC0}, + {0xFEC1, 0xFEC2, 0xFEC3, 0xFEC4}, + {0xFEC5, 0xFEC6, 0xFEC7, 0xFEC8}, + {0xFEC9, 0xFECA, 0xFECB, 0xFECC}, + {0xFECD, 0xFECE, 0xFECF, 0xFED0}, + {0x063B, 0x063B, 0x063B, 0x063B}, + {0x063C, 0x063C, 0x063C, 0x063C}, + {0x063D, 0x063D, 0x063D, 0x063D}, + {0x063E, 0x063E, 0x063E, 0x063E}, + {0x063F, 0x063F, 0x063F, 0x063F}, + {0x0640, 0x0640, 0x0640, 0x0640}, + {0xFED1, 0xFED2, 0xFED3, 0xFED4}, + {0xFED5, 0xFED6, 0xFED7, 0xFED8}, + {0xFED9, 0xFEDA, 0xFEDB, 0xFEDC}, + {0xFEDD, 0xFEDE, 0xFEDF, 0xFEE0}, + {0xFEE1, 0xFEE2, 0xFEE3, 0xFEE4}, + {0xFEE5, 0xFEE6, 0xFEE7, 0xFEE8}, + {0xFEE9, 0xFEEA, 0xFEEB, 0xFEEC}, + {0xFEED, 0xFEEE, 0xFEED, 0xFEEE}, + {0xFEEF, 0xFEF0, 0xFBFE, 0xFBFF}, + {0xFEF1, 0xFEF2, 0xFEF3, 0xFEF4}, + {0x064B, 0x064B, 0x064B, 0x064B}, + {0x064C, 0x064C, 0x064C, 0x064C}, + {0x064D, 0x064D, 0x064D, 0x064D}, + {0x064E, 0x064E, 0x064E, 0x064E}, + {0x064F, 0x064F, 0x064F, 0x064F}, + {0x0650, 0x0650, 0x0650, 0x0650}, + {0x0651, 0x0651, 0x0651, 0x0651}, + {0x0652, 0x0652, 0x0652, 0x0652}, + {0x0653, 0x0653, 0x0653, 0x0653}, + {0x0654, 0x0654, 0x0654, 0x0654}, + {0x0655, 0x0655, 0x0655, 0x0655}, + {0x0656, 0x0656, 0x0656, 0x0656}, + {0x0657, 0x0657, 0x0657, 0x0657}, + {0x0658, 0x0658, 0x0658, 0x0658}, + {0x0659, 0x0659, 0x0659, 0x0659}, + {0x065A, 0x065A, 0x065A, 0x065A}, + {0x065B, 0x065B, 0x065B, 0x065B}, + {0x065C, 0x065C, 0x065C, 0x065C}, + {0x065D, 0x065D, 0x065D, 0x065D}, + {0x065E, 0x065E, 0x065E, 0x065E}, + {0x065F, 0x065F, 0x065F, 0x065F}, + {0x0660, 0x0660, 0x0660, 0x0660}, + {0x0661, 0x0661, 0x0661, 0x0661}, + {0x0662, 0x0662, 0x0662, 0x0662}, + {0x0663, 0x0663, 0x0663, 0x0663}, + {0x0664, 0x0664, 0x0664, 0x0664}, + {0x0665, 0x0665, 0x0665, 0x0665}, + {0x0666, 0x0666, 0x0666, 0x0666}, + {0x0667, 0x0667, 0x0667, 0x0667}, + {0x0668, 0x0668, 0x0668, 0x0668}, + {0x0669, 0x0669, 0x0669, 0x0669}, + {0x066A, 0x066A, 0x066A, 0x066A}, + {0x066B, 0x066B, 0x066B, 0x066B}, + {0x066C, 0x066C, 0x066C, 0x066C}, + {0x066D, 0x066D, 0x066D, 0x066D}, + {0x066E, 0x066E, 0x066E, 0x066E}, + {0x066F, 0x066F, 0x066F, 0x066F}, + {0x0670, 0x0670, 0x0670, 0x0670}, + {0xFB50, 0xFB51, 0xFB50, 0xFB51}, + {0x0672, 0x0672, 0x0672, 0x0672}, + {0x0673, 0x0673, 0x0673, 0x0673}, + {0x0674, 0x0674, 0x0674, 0x0674}, + {0x0675, 0x0675, 0x0675, 0x0675}, + {0x0676, 0x0676, 0x0676, 0x0676}, + {0x0677, 0x0677, 0x0677, 0x0677}, + {0x0678, 0x0678, 0x0678, 0x0678}, + {0xFB66, 0xFB67, 0xFB68, 0xFB69}, + {0xFB5E, 0xFB5F, 0xFB60, 0xFB61}, + {0xFB52, 0xFB53, 0xFB54, 0xFB55}, + {0x067C, 0x067C, 0x067C, 0x067C}, + {0x067D, 0x067D, 0x067D, 0x067D}, + {0xFB56, 0xFB57, 0xFB58, 0xFB59}, + {0xFB62, 0xFB63, 0xFB64, 0xFB65}, + {0xFB5A, 0xFB5B, 0xFB5C, 0xFB5D}, + {0x0681, 0x0681, 0x0681, 0x0681}, + {0x0682, 0x0682, 0x0682, 0x0682}, + {0xFB76, 0xFB77, 0xFB78, 0xFB79}, + {0xFB72, 0xFB73, 0xFB74, 0xFB75}, + {0x0685, 0x0685, 0x0685, 0x0685}, + {0xFB7A, 0xFB7B, 0xFB7C, 0xFB7D}, + {0xFB7E, 0xFB7F, 0xFB80, 0xFB81}, + {0xFB88, 0xFB89, 0xFB88, 0xFB89}, + {0x0689, 0x0689, 0x0689, 0x0689}, + {0x068A, 0x068A, 0x068A, 0x068A}, + {0x068B, 0x068B, 0x068B, 0x068B}, + {0xFB84, 0xFB85, 0xFB84, 0xFB85}, + {0xFB82, 0xFB83, 0xFB82, 0xFB83}, + {0xFB86, 0xFB87, 0xFB86, 0xFB87}, + {0x068F, 0x068F, 0x068F, 0x068F}, + {0x0690, 0x0690, 0x0690, 0x0690}, + {0xFB8C, 0xFB8D, 0xFB8C, 0xFB8D}, + {0x0692, 0x0692, 0x0692, 0x0692}, + {0x0693, 0x0693, 0x0693, 0x0693}, + {0x0694, 0x0694, 0x0694, 0x0694}, + {0x0695, 0x0695, 0x0695, 0x0695}, + {0x0696, 0x0696, 0x0696, 0x0696}, + {0x0697, 0x0697, 0x0697, 0x0697}, + {0xFB8A, 0xFB8B, 0xFB8A, 0xFB8B}, + {0x0699, 0x0699, 0x0699, 0x0699}, + {0x069A, 0x069A, 0x069A, 0x069A}, + {0x069B, 0x069B, 0x069B, 0x069B}, + {0x069C, 0x069C, 0x069C, 0x069C}, + {0x069D, 0x069D, 0x069D, 0x069D}, + {0x069E, 0x069E, 0x069E, 0x069E}, + {0x069F, 0x069F, 0x069F, 0x069F}, + {0x06A0, 0x06A0, 0x06A0, 0x06A0}, + {0x06A1, 0x06A1, 0x06A1, 0x06A1}, + {0x06A2, 0x06A2, 0x06A2, 0x06A2}, + {0x06A3, 0x06A3, 0x06A3, 0x06A3}, + {0xFB6A, 0xFB6B, 0xFB6C, 0xFB6D}, + {0x06A5, 0x06A5, 0x06A5, 0x06A5}, + {0xFB6E, 0xFB6F, 0xFB70, 0xFB71}, + {0x06A7, 0x06A7, 0x06A7, 0x06A7}, + {0x06A8, 0x06A8, 0x06A8, 0x06A8}, + {0xFB8E, 0xFB8F, 0xFB90, 0xFB91}, + {0x06AA, 0x06AA, 0x06AA, 0x06AA}, + {0x06AB, 0x06AB, 0x06AB, 0x06AB}, + {0x06AC, 0x06AC, 0x06AC, 0x06AC}, + {0xFBD3, 0xFBD4, 0xFBD5, 0xFBD6}, + {0x06AE, 0x06AE, 0x06AE, 0x06AE}, + {0xFB92, 0xFB93, 0xFB94, 0xFB95}, + {0x06B0, 0x06B0, 0x06B0, 0x06B0}, + {0xFB9A, 0xFB9B, 0xFB9C, 0xFB9D}, + {0x06B2, 0x06B2, 0x06B2, 0x06B2}, + {0xFB96, 0xFB97, 0xFB98, 0xFB99}, + {0x06B4, 0x06B4, 0x06B4, 0x06B4}, + {0x06B5, 0x06B5, 0x06B5, 0x06B5}, + {0x06B6, 0x06B6, 0x06B6, 0x06B6}, + {0x06B7, 0x06B7, 0x06B7, 0x06B7}, + {0x06B8, 0x06B8, 0x06B8, 0x06B8}, + {0x06B9, 0x06B9, 0x06B9, 0x06B9}, + {0xFB9E, 0xFB9F, 0xFBE8, 0xFBE9}, + {0xFBA0, 0xFBA1, 0xFBA2, 0xFBA3}, + {0x06BC, 0x06BC, 0x06BC, 0x06BC}, + {0x06BD, 0x06BD, 0x06BD, 0x06BD}, + {0xFBAA, 0xFBAB, 0xFBAC, 0xFBAD}, + {0x06BF, 0x06BF, 0x06BF, 0x06BF}, + {0xFBA4, 0xFBA5, 0xFBA4, 0xFBA5}, + {0xFBA6, 0xFBA7, 0xFBA8, 0xFBA9}, + {0x06C2, 0x06C2, 0x06C2, 0x06C2}, + {0x06C3, 0x06C3, 0x06C3, 0x06C3}, + {0x06C4, 0x06C4, 0x06C4, 0x06C4}, + {0xFBE0, 0xFBE1, 0xFBE0, 0xFBE1}, + {0xFBD9, 0xFBDA, 0xFBD9, 0xFBDA}, + {0xFBD7, 0xFBD8, 0xFBD7, 0xFBD8}, + {0xFBDB, 0xFBDC, 0xFBDB, 0xFBDC}, + {0xFBE2, 0xFBE3, 0xFBE2, 0xFBE3}, + {0x06CA, 0x06CA, 0x06CA, 0x06CA}, + {0xFBDE, 0xFBDF, 0xFBDE, 0xFBDF}, + {0xFBFC, 0xFBFD, 0xFBFE, 0xFBFF}, + {0x06CD, 0x06CD, 0x06CD, 0x06CD}, + {0x06CE, 0x06CE, 0x06CE, 0x06CE}, + {0x06CF, 0x06CF, 0x06CF, 0x06CF}, + {0xFBE4, 0xFBE5, 0xFBE6, 0xFBE7}, + {0x06D1, 0x06D1, 0x06D1, 0x06D1}, + {0xFBAE, 0xFBAF, 0xFBAE, 0xFBAF}, + {0xFBB0, 0xFBB1, 0xFBB0, 0xFBB1}, + {0x06D4, 0x06D4, 0x06D4, 0x06D4}, + {0x06D5, 0x06D5, 0x06D5, 0x06D5}, +}; +static const FX_ARAALEF gs_FX_AlefTable[] = { + {0x0622, 0xFEF5}, + {0x0623, 0xFEF7}, + {0x0625, 0xFEF9}, + {0x0627, 0xFEFB}, +}; +static const FX_ARASHADDA gs_FX_ShaddaTable[] = { + {0x064C, 0xFC5E}, + {0x064D, 0xFC5F}, + {0x064E, 0xFC60}, + {0x064F, 0xFC61}, + {0x0650, 0xFC62}, +}; +FX_LPCARBFORMTABLE FX_GetArabicFormTable(FX_WCHAR unicode) +{ + if (unicode < 0x622 || unicode > 0x6d5) { + return NULL; + } + return g_FX_ArabicFormTables + unicode - 0x622; +} +FX_WCHAR FX_GetArabicFromAlefTable(FX_WCHAR alef) +{ + static const FX_INT32 s_iAlefCount = sizeof(gs_FX_AlefTable) / sizeof(FX_ARAALEF); + for (FX_INT32 iStart = 0; iStart < s_iAlefCount; iStart ++) { + const FX_ARAALEF &v = gs_FX_AlefTable[iStart]; + if (v.wAlef == alef) { + return v.wIsolated; + } + } + return alef; +} +FX_WCHAR FX_GetArabicFromShaddaTable(FX_WCHAR shadda) +{ + static const FX_INT32 s_iShaddaCount = sizeof(gs_FX_ShaddaTable) / sizeof(FX_ARASHADDA); + for (FX_INT32 iStart = 0; iStart < s_iShaddaCount; iStart ++) { + const FX_ARASHADDA &v = gs_FX_ShaddaTable[iStart]; + if (v.wShadda == shadda) { + return v.wIsolated; + } + } + return shadda; +} +#ifdef __cplusplus +}; +#endif +IFX_ArabicChar* IFX_ArabicChar::Create() +{ + return FX_NEW CFX_ArabicChar; +} +FX_BOOL CFX_ArabicChar::IsArabicChar(FX_WCHAR wch) const +{ + FX_DWORD dwRet = (gs_FX_TextLayout_CodeProperties[(FX_WORD)wch] & FX_CHARTYPEBITSMASK); + return dwRet >= FX_CHARTYPE_ArabicAlef; +} +FX_BOOL CFX_ArabicChar::IsArabicFormChar(FX_WCHAR wch) const +{ + return (gs_FX_TextLayout_CodeProperties[(FX_WORD)wch] & FX_CHARTYPEBITSMASK) == FX_CHARTYPE_ArabicForm; +} +FX_WCHAR CFX_ArabicChar::GetFormChar(FX_WCHAR wch, FX_WCHAR prev, FX_WCHAR next) const +{ + CFX_Char c(wch, gs_FX_TextLayout_CodeProperties[(FX_WORD)wch]); + CFX_Char p(prev, gs_FX_TextLayout_CodeProperties[(FX_WORD)prev]); + CFX_Char n(next, gs_FX_TextLayout_CodeProperties[(FX_WORD)next]); + return GetFormChar(&c, &p, &n); +} +FX_WCHAR CFX_ArabicChar::GetFormChar(const CFX_Char *cur, const CFX_Char *prev, const CFX_Char *next) const +{ + FX_CHARTYPE eCur; + FX_WCHAR wCur; + FX_LPCARBFORMTABLE ft = ParseChar(cur, wCur, eCur); + if (eCur < FX_CHARTYPE_ArabicAlef || eCur >= FX_CHARTYPE_ArabicNormal) { + return wCur; + } + FX_CHARTYPE ePrev; + FX_WCHAR wPrev; + ParseChar(prev, wPrev, ePrev); + if (wPrev == 0x0644 && eCur == FX_CHARTYPE_ArabicAlef) { + return 0xFEFF; + } + FX_CHARTYPE eNext; + FX_WCHAR wNext; + ParseChar(next, wNext, eNext); + FX_BOOL bAlef = (eNext == FX_CHARTYPE_ArabicAlef && wCur == 0x644); + if (ePrev < FX_CHARTYPE_ArabicAlef) { + if (bAlef) { + return FX_GetArabicFromAlefTable(wNext); + } else { + return (eNext < FX_CHARTYPE_ArabicAlef) ? ft->wIsolated : ft->wInitial; + } + } else { + if (bAlef) { + wCur = FX_GetArabicFromAlefTable(wNext); + return (ePrev != FX_CHARTYPE_ArabicDistortion) ? wCur : ++ wCur; + } else if (ePrev == FX_CHARTYPE_ArabicAlef || ePrev == FX_CHARTYPE_ArabicSpecial) { + return (eNext < FX_CHARTYPE_ArabicAlef) ? ft->wIsolated : ft->wInitial; + } else { + return (eNext < FX_CHARTYPE_ArabicAlef) ? ft->wFinal : ft->wMedial; + } + } +} +FX_LPCARBFORMTABLE CFX_ArabicChar::ParseChar(const CFX_Char *pTC, FX_WCHAR &wChar, FX_CHARTYPE &eType) const +{ + if (pTC == NULL) { + eType = FX_CHARTYPE_Unknown; + wChar = 0xFEFF; + return NULL; + } + eType = (FX_CHARTYPE)pTC->GetCharType(); + wChar = (FX_WCHAR)pTC->m_wCharCode; + FX_LPCARBFORMTABLE pFT = FX_GetArabicFormTable(wChar); + if (pFT == NULL || eType >= FX_CHARTYPE_ArabicNormal) { + eType = FX_CHARTYPE_Unknown; + } + return pFT; +} +void FX_BidiReverseString(CFX_WideString &wsText, FX_INT32 iStart, FX_INT32 iCount) +{ + FXSYS_assert(iStart > -1 && iStart < wsText.GetLength()); + FXSYS_assert(iCount >= 0 && iStart + iCount <= wsText.GetLength()); + FX_WCHAR wch; + FX_LPWSTR pStart = (FX_LPWSTR)(FX_LPCWSTR)wsText; + pStart += iStart; + FX_LPWSTR pEnd = pStart + iCount - 1; + while (pStart < pEnd) { + wch = *pStart; + *pStart ++ = *pEnd; + *pEnd -- = wch; + } +} +void FX_BidiSetDeferredRun(CFX_Int32Array &values, FX_INT32 iStart, FX_INT32 iCount, FX_INT32 iValue) +{ + FXSYS_assert(iStart > -1 && iStart <= values.GetSize()); + FXSYS_assert(iStart - iCount > -1); + for (FX_INT32 i = iStart - 1; i >= iStart - iCount; i --) { + values.SetAt(i, iValue); + } +} +const FX_INT32 gc_FX_BidiNTypes[] = { + FX_BIDICLASS_N, + FX_BIDICLASS_L, + FX_BIDICLASS_R, + FX_BIDICLASS_AN, + FX_BIDICLASS_EN, + FX_BIDICLASS_AL, + FX_BIDICLASS_NSM, + FX_BIDICLASS_CS, + FX_BIDICLASS_ES, + FX_BIDICLASS_ET, + FX_BIDICLASS_BN, + FX_BIDICLASS_BN, + FX_BIDICLASS_N, + FX_BIDICLASS_B, + FX_BIDICLASS_RLO, + FX_BIDICLASS_RLE, + FX_BIDICLASS_LRO, + FX_BIDICLASS_LRE, + FX_BIDICLASS_PDF, + FX_BIDICLASS_ON, +}; +void FX_BidiClassify(const CFX_WideString &wsText, CFX_Int32Array &classes, FX_BOOL bWS) +{ + FXSYS_assert(wsText.GetLength() == classes.GetSize()); + FX_INT32 iCount = wsText.GetLength(); + FX_LPCWSTR pwsStart = (FX_LPCWSTR)wsText; + FX_WCHAR wch; + FX_INT32 iCls; + if (bWS) { + for (FX_INT32 i = 0; i < iCount; i ++) { + wch = *pwsStart ++; + iCls = ((gs_FX_TextLayout_CodeProperties[(FX_WORD)wch] & FX_BIDICLASSBITSMASK) >> FX_BIDICLASSBITS); + classes.SetAt(i, iCls); + } + } else { + for (FX_INT32 i = 0; i < iCount; i ++) { + wch = *pwsStart ++; + iCls = ((gs_FX_TextLayout_CodeProperties[(FX_WORD)wch] & FX_BIDICLASSBITSMASK) >> FX_BIDICLASSBITS); + classes.SetAt(i, gc_FX_BidiNTypes[iCls]); + } + } +} +FX_INT32 FX_BidiResolveExplicit(FX_INT32 iBaseLevel, FX_INT32 iDirection, CFX_Int32Array &classes, CFX_Int32Array &levels, FX_INT32 iStart, FX_INT32 iCount, FX_INT32 iNest) +{ + FXSYS_assert(iBaseLevel >= 0 && iBaseLevel <= FX_BIDIMAXLEVEL && iNest >= 0); + FXSYS_assert(classes.GetSize() == levels.GetSize()); + FXSYS_assert(iStart >= 0 && iStart < classes.GetSize()); + FXSYS_assert(iCount >= 0 && iStart + iCount <= classes.GetSize()); + if (iCount < 1) { + return 0; + } +#if 0 + FX_INT32 iLastNest = iNest; +#endif + FX_INT32 iSize = classes.GetSize(); + FX_INT32 i = iStart, iCur, iCls; + for (; i < iSize && iCount > 0; i ++, iCount --) { + iCur = iCls = classes.GetAt(i); +#if 0 + switch (iCls) { + case FX_BIDICLASS_LRO: + case FX_BIDICLASS_LRE: + classes.SetAt(i, FX_BIDICLASS_BN); + iCls = FX_BIDICLASS_BN; + iNest ++; + if (FX_BidiGreaterEven(iBaseLevel) <= MAX_LEVEL) { + FX_INT32 iLevel = FX_BidiGreaterEven(iBaseLevel); + levels.SetAt(i, iLevel); + i += FX_BidiResolveExplicit(iLevel, + (iCls == FX_BIDICLASS_LRE ? FX_BIDICLASS_N : FX_BIDICLASS_L), + classes, + levels, + i + 1, + iCount - 1, + iNest); + iNest --; + continue; + } + break; + case FX_BIDICLASS_RLO: + case FX_BIDICLASS_RLE: + classes.SetAt(i, FX_BIDICLASS_BN); + iCls = FX_BIDICLASS_BN; + iNest ++; + if (FX_BidiGreaterOdd(iBaseLevel) <= MAX_LEVEL) { + FX_INT32 iLevel = FX_BidiGreaterOdd(iBaseLevel); + levels.SetAt(i, iLevel); + i += FX_BidiResolveExplicit(iLevel, + (iCls == FX_BIDICLASS_RLE ? FX_BIDICLASS_N : FX_BIDICLASS_R), + classes, + levels, + i + 1, + iCount - 1, + iNest); + iNest --; + continue; + } + break; + case FX_BIDICLASS_PDF: + classes.SetAt(i, FX_BIDICLASS_BN); + iCls = FX_BIDICLASS_BN; + if (iNest) { + if (iLastNest < iNest) { + iNest --; + } else { + iSize = i; + } + } + break; + } + iCur = iCls; +#endif + if (iDirection != FX_BIDICLASS_N) { + iCls = iDirection; + } + if (iCur != FX_BIDICLASS_BN) { + classes.SetAt(i, iCls); + } + levels.SetAt(i, iBaseLevel); + } + return i - iStart; +} +const FX_INT32 gc_FX_BidiWeakStates[][10] = { + {FX_BWSao, FX_BWSxl, FX_BWSxr, FX_BWScn, FX_BWScn, FX_BWSxa, FX_BWSxa, FX_BWSao, FX_BWSao, FX_BWSao}, + {FX_BWSro, FX_BWSxl, FX_BWSxr, FX_BWSra, FX_BWSre, FX_BWSxa, FX_BWSxr, FX_BWSro, FX_BWSro, FX_BWSrt}, + {FX_BWSlo, FX_BWSxl, FX_BWSxr, FX_BWSla, FX_BWSle, FX_BWSxa, FX_BWSxl, FX_BWSlo, FX_BWSlo, FX_BWSlt}, + {FX_BWSao, FX_BWSxl, FX_BWSxr, FX_BWScn, FX_BWScn, FX_BWSxa, FX_BWSao, FX_BWSao, FX_BWSao, FX_BWSao}, + {FX_BWSro, FX_BWSxl, FX_BWSxr, FX_BWSra, FX_BWSre, FX_BWSxa, FX_BWSro, FX_BWSro, FX_BWSro, FX_BWSrt}, + {FX_BWSlo, FX_BWSxl, FX_BWSxr, FX_BWSla, FX_BWSle, FX_BWSxa, FX_BWSlo, FX_BWSlo, FX_BWSlo, FX_BWSlt}, + {FX_BWSro, FX_BWSxl, FX_BWSxr, FX_BWSra, FX_BWSre, FX_BWSxa, FX_BWSrt, FX_BWSro, FX_BWSro, FX_BWSrt}, + {FX_BWSlo, FX_BWSxl, FX_BWSxr, FX_BWSla, FX_BWSle, FX_BWSxa, FX_BWSlt, FX_BWSlo, FX_BWSlo, FX_BWSlt}, + {FX_BWSao, FX_BWSxl, FX_BWSxr, FX_BWScn, FX_BWScn, FX_BWSxa, FX_BWScn, FX_BWSac, FX_BWSao, FX_BWSao}, + {FX_BWSro, FX_BWSxl, FX_BWSxr, FX_BWSra, FX_BWSre, FX_BWSxa, FX_BWSra, FX_BWSrc, FX_BWSro, FX_BWSrt}, + {FX_BWSro, FX_BWSxl, FX_BWSxr, FX_BWSra, FX_BWSre, FX_BWSxa, FX_BWSre, FX_BWSrs, FX_BWSrs, FX_BWSret}, + {FX_BWSlo, FX_BWSxl, FX_BWSxr, FX_BWSla, FX_BWSle, FX_BWSxa, FX_BWSla, FX_BWSlc, FX_BWSlo, FX_BWSlt}, + {FX_BWSlo, FX_BWSxl, FX_BWSxr, FX_BWSla, FX_BWSle, FX_BWSxa, FX_BWSle, FX_BWSls, FX_BWSls, FX_BWSlet}, + {FX_BWSao, FX_BWSxl, FX_BWSxr, FX_BWScn, FX_BWScn, FX_BWSxa, FX_BWSao, FX_BWSao, FX_BWSao, FX_BWSao}, + {FX_BWSro, FX_BWSxl, FX_BWSxr, FX_BWSra, FX_BWSre, FX_BWSxa, FX_BWSro, FX_BWSro, FX_BWSro, FX_BWSrt}, + {FX_BWSro, FX_BWSxl, FX_BWSxr, FX_BWSra, FX_BWSre, FX_BWSxa, FX_BWSro, FX_BWSro, FX_BWSro, FX_BWSrt}, + {FX_BWSlo, FX_BWSxl, FX_BWSxr, FX_BWSla, FX_BWSle, FX_BWSxa, FX_BWSlo, FX_BWSlo, FX_BWSlo, FX_BWSlt}, + {FX_BWSlo, FX_BWSxl, FX_BWSxr, FX_BWSla, FX_BWSle, FX_BWSxa, FX_BWSlo, FX_BWSlo, FX_BWSlo, FX_BWSlt}, + {FX_BWSro, FX_BWSxl, FX_BWSxr, FX_BWSra, FX_BWSre, FX_BWSxa, FX_BWSret, FX_BWSro, FX_BWSro, FX_BWSret}, + {FX_BWSlo, FX_BWSxl, FX_BWSxr, FX_BWSla, FX_BWSle, FX_BWSxa, FX_BWSlet, FX_BWSlo, FX_BWSlo, FX_BWSlet}, +}; +const FX_INT32 gc_FX_BidiWeakActions[][10] = { + {FX_BWAxxx, FX_BWAxxx, FX_BWAxxx, FX_BWAxxx, FX_BWAxxA, FX_BWAxxR, FX_BWAxxR, FX_BWAxxN, FX_BWAxxN, FX_BWAxxN}, + {FX_BWAxxx, FX_BWAxxx, FX_BWAxxx, FX_BWAxxx, FX_BWAxxE, FX_BWAxxR, FX_BWAxxR, FX_BWAxxN, FX_BWAxxN, FX_BWAxIx}, + {FX_BWAxxx, FX_BWAxxx, FX_BWAxxx, FX_BWAxxx, FX_BWAxxL, FX_BWAxxR, FX_BWAxxL, FX_BWAxxN, FX_BWAxxN, FX_BWAxIx}, + {FX_BWAxxx, FX_BWAxxx, FX_BWAxxx, FX_BWAxxx, FX_BWAxxA, FX_BWAxxR, FX_BWAxxN, FX_BWAxxN, FX_BWAxxN, FX_BWAxxN}, + {FX_BWAxxx, FX_BWAxxx, FX_BWAxxx, FX_BWAxxx, FX_BWAxxE, FX_BWAxxR, FX_BWAxxN, FX_BWAxxN, FX_BWAxxN, FX_BWAxIx}, + {FX_BWAxxx, FX_BWAxxx, FX_BWAxxx, FX_BWAxxx, FX_BWAxxL, FX_BWAxxR, FX_BWAxxN, FX_BWAxxN, FX_BWAxxN, FX_BWAxIx}, + {FX_BWANxx, FX_BWANxx, FX_BWANxx, FX_BWANxx, FX_BWAExE, FX_BWANxR, FX_BWAxIx, FX_BWANxN, FX_BWANxN, FX_BWAxIx}, + {FX_BWANxx, FX_BWANxx, FX_BWANxx, FX_BWANxx, FX_BWALxL, FX_BWANxR, FX_BWAxIx, FX_BWANxN, FX_BWANxN, FX_BWAxIx}, + {FX_BWAxxx, FX_BWAxxx, FX_BWAxxx, FX_BWAxxx, FX_BWAxxA, FX_BWAxxR, FX_BWAxxA, FX_BWAxIx, FX_BWAxxN, FX_BWAxxN}, + {FX_BWAxxx, FX_BWAxxx, FX_BWAxxx, FX_BWAxxx, FX_BWAxxE, FX_BWAxxR, FX_BWAxxA, FX_BWAxIx, FX_BWAxxN, FX_BWAxIx}, + {FX_BWAxxx, FX_BWAxxx, FX_BWAxxx, FX_BWAxxx, FX_BWAxxE, FX_BWAxxR, FX_BWAxxE, FX_BWAxIx, FX_BWAxIx, FX_BWAxxE}, + {FX_BWAxxx, FX_BWAxxx, FX_BWAxxx, FX_BWAxxx, FX_BWAxxL, FX_BWAxxR, FX_BWAxxA, FX_BWAxIx, FX_BWAxxN, FX_BWAxIx}, + {FX_BWAxxx, FX_BWAxxx, FX_BWAxxx, FX_BWAxxx, FX_BWAxxL, FX_BWAxxR, FX_BWAxxL, FX_BWAxIx, FX_BWAxIx, FX_BWAxxL}, + {FX_BWANxx, FX_BWANxx, FX_BWANxx, FX_BWAAxx, FX_BWAAxA, FX_BWANxR, FX_BWANxN, FX_BWANxN, FX_BWANxN, FX_BWANxN}, + {FX_BWANxx, FX_BWANxx, FX_BWANxx, FX_BWAAxx, FX_BWANxE, FX_BWANxR, FX_BWANxN, FX_BWANxN, FX_BWANxN, FX_BWANIx}, + {FX_BWANxx, FX_BWANxx, FX_BWANxx, FX_BWANxx, FX_BWAExE, FX_BWANxR, FX_BWANxN, FX_BWANxN, FX_BWANxN, FX_BWANIx}, + {FX_BWANxx, FX_BWANxx, FX_BWANxx, FX_BWAAxx, FX_BWANxL, FX_BWANxR, FX_BWANxN, FX_BWANxN, FX_BWANxN, FX_BWANIx}, + {FX_BWANxx, FX_BWANxx, FX_BWANxx, FX_BWANxx, FX_BWALxL, FX_BWANxR, FX_BWANxN, FX_BWANxN, FX_BWANxN, FX_BWANIx}, + {FX_BWAxxx, FX_BWAxxx, FX_BWAxxx, FX_BWAxxx, FX_BWAxxE, FX_BWAxxR, FX_BWAxxE, FX_BWAxxN, FX_BWAxxN, FX_BWAxxE}, + {FX_BWAxxx, FX_BWAxxx, FX_BWAxxx, FX_BWAxxx, FX_BWAxxL, FX_BWAxxR, FX_BWAxxL, FX_BWAxxN, FX_BWAxxN, FX_BWAxxL}, +}; +void FX_BidiResolveWeak(FX_INT32 iBaseLevel, CFX_Int32Array &classes, CFX_Int32Array &levels) +{ + FXSYS_assert(iBaseLevel >= 0 && iBaseLevel <= FX_BIDIMAXLEVEL); + FXSYS_assert(classes.GetSize() == levels.GetSize()); + FX_INT32 iSize = classes.GetSize(); + if (iSize < 1) { + return; + } + iSize --; + FX_INT32 iLevelCur = iBaseLevel; + FX_INT32 iState = FX_IsOdd(iBaseLevel) ? FX_BWSxr : FX_BWSxl; + FX_INT32 i = 0, iCount = 0, iClsCur, iClsRun, iClsNew, iAction; + for (; i <= iSize; i ++) { + iClsCur = classes.GetAt(i); +#if 0 + if (iClsCur == FX_BIDICLASS_BN) { + levels.SetAt(i, iLevelCur); + if (i == iSize && iLevelCur != iBaseLevel) { + iClsCur = FX_BidiDirection(iLevelCur); + classes.SetAt(i, iClsCur); + } else if (i < iSize) { + FX_INT32 iLevelNext, iLevelNew; + iClsNew = classes.GetAt(i + 1); + iLevelNext = levels.GetAt(i + 1); + if (iClsNew != FX_BIDICLASS_BN && iLevelCur != iLevelNext) { + iLevelNew = iLevelNext; + if (iLevelCur > iLevelNew) { + iLevelNew = iLevelCur; + } + levels.SetAt(i, iLevelNew); + iClsCur = FX_BidiDirection(iLevelNew); + classes.SetAt(i, iClsCur); + iLevelCur = iLevelNext; + } else { + if (iCount) { + iCount ++; + } + continue; + } + } else { + if (iCount) { + iCount ++; + } + continue; + } + } +#endif + FXSYS_assert(iClsCur <= FX_BIDICLASS_BN); + iAction = gc_FX_BidiWeakActions[iState][iClsCur]; + iClsRun = FX_BidiGetDeferredType(iAction); + if (iClsRun != FX_BIDIWEAKACTION_XX && iCount > 0) { + FX_BidiSetDeferredRun(classes, i, iCount, iClsRun); + iCount = 0; + } + iClsNew = FX_BidiGetResolvedType(iAction); + if (iClsNew != FX_BIDIWEAKACTION_XX) { + classes.SetAt(i, iClsNew); + } + if (FX_BIDIWEAKACTION_IX & iAction) { + iCount ++; + } + iState = gc_FX_BidiWeakStates[iState][iClsCur]; + } + iClsCur = FX_BidiDirection(iLevelCur); + iClsRun = FX_BidiGetDeferredType(gc_FX_BidiWeakActions[iState][iClsCur]); + if (iClsRun != FX_BIDIWEAKACTION_XX && iCount > 0) { + FX_BidiSetDeferredRun(classes, i, iCount, iClsRun); + } +} +const FX_INT32 gc_FX_BidiNeutralStates[][5] = { + {FX_BNSrn, FX_BNSl, FX_BNSr, FX_BNSr, FX_BNSr}, + {FX_BNSln, FX_BNSl, FX_BNSr, FX_BNSa, FX_BNSl}, + {FX_BNSrn, FX_BNSl, FX_BNSr, FX_BNSr, FX_BNSr}, + {FX_BNSln, FX_BNSl, FX_BNSr, FX_BNSa, FX_BNSl}, + {FX_BNSna, FX_BNSl, FX_BNSr, FX_BNSa, FX_BNSl}, + {FX_BNSna, FX_BNSl, FX_BNSr, FX_BNSa, FX_BNSl}, +}; +const FX_INT32 gc_FX_BidiNeutralActions[][5] = { + {FX_BNAIn, 0, 0, 0, 0 }, + {FX_BNAIn, 0, 0, 0, FX_BCL }, + {FX_BNAIn, FX_BNAEn, FX_BNARn, FX_BNARn, FX_BNARn }, + {FX_BNAIn, FX_BNALn, FX_BNAEn, FX_BNAEn, FX_BNALnL }, + {FX_BNAIn, 0, 0, 0, FX_BCL }, + {FX_BNAIn, FX_BNAEn, FX_BNARn, FX_BNARn, FX_BNAEn }, +}; +FX_INT32 FX_BidiGetDeferredNeutrals(FX_INT32 iAction, FX_INT32 iLevel) +{ + iAction = (iAction >> 4) & 0xF; + if (iAction == (FX_BIDINEUTRALACTION_En >> 4)) { + return FX_BidiDirection(iLevel); + } else { + return iAction; + } +} +FX_INT32 FX_BidiGetResolvedNeutrals(FX_INT32 iAction) +{ + iAction = (iAction & 0xF); + if (iAction == FX_BIDINEUTRALACTION_In) { + return 0; + } else { + return iAction; + } +} +void FX_BidiResolveNeutrals(FX_INT32 iBaseLevel, CFX_Int32Array &classes, const CFX_Int32Array &levels) +{ + FXSYS_assert(iBaseLevel >= 0 && iBaseLevel <= FX_BIDIMAXLEVEL); + FXSYS_assert(classes.GetSize() == levels.GetSize()); + FX_INT32 iSize = classes.GetSize(); + if (iSize < 1) { + return; + } + iSize --; + FX_INT32 iLevel = iBaseLevel; + FX_INT32 iState = FX_IsOdd(iBaseLevel) ? FX_BNSr : FX_BNSl; + FX_INT32 i = 0, iCount = 0, iClsCur, iClsRun, iClsNew, iAction; + for (; i <= iSize; i ++) { + iClsCur = classes.GetAt(i); + if (iClsCur == FX_BIDICLASS_BN) { + if (iCount) { + iCount ++; + } + continue; + } + FXSYS_assert(iClsCur < FX_BIDICLASS_AL); + iAction = gc_FX_BidiNeutralActions[iState][iClsCur]; + iClsRun = FX_BidiGetDeferredNeutrals(iAction, iLevel); + if (iClsRun != FX_BIDICLASS_N && iCount > 0) { + FX_BidiSetDeferredRun(classes, i, iCount, iClsRun); + iCount = 0; + } + iClsNew = FX_BidiGetResolvedNeutrals(iAction); + if (iClsNew != FX_BIDICLASS_N) { + classes.SetAt(i, iClsNew); + } + if (FX_BIDINEUTRALACTION_In & iAction) { + iCount ++; + } + iState = gc_FX_BidiNeutralStates[iState][iClsCur]; + iLevel = levels.GetAt(i); + } + iClsCur = FX_BidiDirection(iLevel); + iClsRun = FX_BidiGetDeferredNeutrals(gc_FX_BidiNeutralActions[iState][iClsCur], iLevel); + if (iClsRun != FX_BIDICLASS_N && iCount > 0) { + FX_BidiSetDeferredRun(classes, i, iCount, iClsRun); + } +} +const FX_INT32 gc_FX_BidiAddLevel[][4] = { + {0, 1, 2, 2}, + {1, 0, 1, 1}, +}; +void FX_BidiResolveImplicit(const CFX_Int32Array &classes, CFX_Int32Array &levels) +{ + FXSYS_assert(classes.GetSize() == levels.GetSize()); + FX_INT32 iSize = classes.GetSize(); + if (iSize < 1) { + return; + } + iSize --; + FX_INT32 iCls, iLevel; + for (FX_INT32 i = 0; i <= iSize; i ++) { + iCls = classes.GetAt(i); + if (iCls == FX_BIDICLASS_BN) { + continue; + } + FXSYS_assert(iCls > FX_BIDICLASS_ON && iCls < FX_BIDICLASS_AL); + iLevel = levels.GetAt(i); + iLevel += gc_FX_BidiAddLevel[FX_IsOdd(iLevel)][iCls - 1]; + levels.SetAt(i, iLevel); + } +} +void FX_BidiResolveWhitespace(FX_INT32 iBaseLevel, const CFX_Int32Array &classes, CFX_Int32Array &levels) +{ + FXSYS_assert(iBaseLevel >= 0 && iBaseLevel <= FX_BIDIMAXLEVEL); + FXSYS_assert(classes.GetSize() == levels.GetSize()); + FX_INT32 iSize = classes.GetSize(); + if (iSize < 1) { + return; + } + iSize --; + FX_INT32 iLevel = iBaseLevel; + FX_INT32 i = 0, iCount = 0; + for (; i <= iSize; i ++) { + switch(classes.GetAt(i)) { + case FX_BIDICLASS_WS: + iCount ++; + break; + case FX_BIDICLASS_RLE: + case FX_BIDICLASS_LRE: + case FX_BIDICLASS_LRO: + case FX_BIDICLASS_RLO: + case FX_BIDICLASS_PDF: + case FX_BIDICLASS_BN: + levels.SetAt(i, iLevel); + iCount ++; + break; + case FX_BIDICLASS_S: + case FX_BIDICLASS_B: + if (iCount > 0) { + FX_BidiSetDeferredRun(levels, i, iCount, iBaseLevel); + } + levels.SetAt(i, iBaseLevel); + iCount = 0; + break; + default: + iCount = 0; + break; + } + iLevel = levels.GetAt(i); + } + if (iCount > 0) { + FX_BidiSetDeferredRun(levels, i, iCount, iBaseLevel); + } +} +FX_INT32 FX_BidiReorderLevel(FX_INT32 iBaseLevel, CFX_WideString &wsText, const CFX_Int32Array &levels, FX_INT32 iStart, FX_BOOL bReverse) +{ + FXSYS_assert(iBaseLevel >= 0 && iBaseLevel <= FX_BIDIMAXLEVEL); + FXSYS_assert(wsText.GetLength() == levels.GetSize()); + FXSYS_assert(iStart >= 0 && iStart < wsText.GetLength()); + FX_INT32 iSize = wsText.GetLength(); + if (iSize < 1) { + return 0; + } + bReverse = bReverse || FX_IsOdd(iBaseLevel); + FX_INT32 i = iStart, iLevel; + for (; i < iSize; i ++) { + if ((iLevel = levels.GetAt(i)) == iBaseLevel) { + continue; + } + if (iLevel < iBaseLevel) { + break; + } + i += FX_BidiReorderLevel(iBaseLevel + 1, wsText, levels, i, bReverse) - 1; + } + FX_INT32 iCount = i - iStart; + if (bReverse && iCount > 1) { + FX_BidiReverseString(wsText, iStart, iCount); + } + return iCount; +} +void FX_BidiReorder(FX_INT32 iBaseLevel, CFX_WideString &wsText, const CFX_Int32Array &levels) +{ + FXSYS_assert(iBaseLevel >= 0 && iBaseLevel <= FX_BIDIMAXLEVEL); + FXSYS_assert(wsText.GetLength() == levels.GetSize()); + FX_INT32 iSize = wsText.GetLength(); + if (iSize < 1) { + return; + } + FX_INT32 i = 0; + while (i < iSize) { + i += FX_BidiReorderLevel(iBaseLevel, wsText, levels, i, FALSE); + } +} +void FX_BidiLine(CFX_WideString &wsText, FX_INT32 iBaseLevel) +{ + FX_INT32 iLength = wsText.GetLength(); + if (iLength < 2) { + return; + } + CFX_Int32Array classes, levels; + classes.SetAtGrow(iLength - 1, 0); + levels.SetAtGrow(iLength - 1, 0); + FX_BidiClassify(wsText, classes, FALSE); + FX_BidiResolveExplicit(iBaseLevel, FX_BIDICLASS_N, classes, levels, 0, iLength, 0); + FX_BidiResolveWeak(iBaseLevel, classes, levels); + FX_BidiResolveNeutrals(iBaseLevel, classes, levels); + FX_BidiResolveImplicit(classes, levels); + FX_BidiClassify(wsText, classes, TRUE); + FX_BidiResolveWhitespace(iBaseLevel, classes, levels); + FX_BidiReorder(iBaseLevel, wsText, levels); + classes.RemoveAll(); + levels.RemoveAll(); +} +template<class baseType> +class CFX_BidiLineTemplate +{ +public: + void FX_BidiReverseString(CFX_ArrayTemplate<baseType> &chars, FX_INT32 iStart, FX_INT32 iCount) + { + FXSYS_assert(iStart > -1 && iStart < chars.GetSize()); + FXSYS_assert(iCount >= 0 && iStart + iCount <= chars.GetSize()); + baseType *pStart, *pEnd; + FX_INT32 iEnd = iStart + iCount - 1, iTemp; + while (iStart < iEnd) { + pStart = chars.GetDataPtr(iStart ++); + pEnd = chars.GetDataPtr(iEnd --); + iTemp = pStart->m_iBidiPos; + pStart->m_iBidiPos = pEnd->m_iBidiPos; + pEnd->m_iBidiPos = iTemp; + } + } + void FX_BidiSetDeferredRun(CFX_ArrayTemplate<baseType> &chars, FX_BOOL bClass, FX_INT32 iStart, FX_INT32 iCount, FX_INT32 iValue) + { + FXSYS_assert(iStart > -1 && iStart <= chars.GetSize()); + FXSYS_assert(iStart - iCount > -1); + baseType *pTC; + FX_INT32 iLast = iStart - iCount; + if (bClass) { + for (FX_INT32 i = iStart - 1; i >= iLast; i --) { + pTC = chars.GetDataPtr(i); + pTC->m_iBidiClass = (FX_INT16)iValue; + } + } else { + for (FX_INT32 i = iStart - 1; i >= iLast; i --) { + pTC = chars.GetDataPtr(i); + pTC->m_iBidiLevel = (FX_INT16)iValue; + } + } + } + void FX_BidiClassify(CFX_ArrayTemplate<baseType> &chars, FX_INT32 iCount, FX_BOOL bWS) + { + FXSYS_assert(iCount > -1 && iCount <= chars.GetSize()); + baseType *pTC; + if (bWS) { + for (FX_INT32 i = 0; i < iCount; i ++) { + pTC = chars.GetDataPtr(i); + pTC->m_iBidiClass = (FX_INT16)(pTC->m_dwCharProps & FX_BIDICLASSBITSMASK) >> FX_BIDICLASSBITS; + } + } else { + for (FX_INT32 i = 0; i < iCount; i ++) { + pTC = chars.GetDataPtr(i); + pTC->m_iBidiClass = (FX_INT16)gc_FX_BidiNTypes[(pTC->m_dwCharProps & FX_BIDICLASSBITSMASK) >> FX_BIDICLASSBITS]; + } + } + } + void FX_BidiResolveExplicit(CFX_ArrayTemplate<baseType> &chars, FX_INT32 iCount, FX_INT32 iBaseLevel) + { + FXSYS_assert(iCount > -1 && iCount <= chars.GetSize()); + FXSYS_assert(iBaseLevel >= 0 && iBaseLevel <= FX_BIDIMAXLEVEL); + if (iCount < 1) { + return; + } + baseType *pTC; + for (FX_INT32 i = 0; i < iCount; i ++) { + pTC = chars.GetDataPtr(i); + pTC->m_iBidiLevel = (FX_INT16)iBaseLevel; + } + } + void FX_BidiResolveWeak(CFX_ArrayTemplate<baseType> &chars, FX_INT32 iCount, FX_INT32 iBaseLevel) + { + FXSYS_assert(iCount > -1 && iCount <= chars.GetSize()); + iCount --; + if (iCount < 1) { + return; + } + baseType *pTC, *pTCNext; + FX_INT32 iLevelCur = iBaseLevel; + FX_INT32 iState = FX_IsOdd(iBaseLevel) ? FX_BWSxr : FX_BWSxl; + FX_INT32 i = 0, iNum = 0, iClsCur, iClsRun, iClsNew, iAction; + for (; i <= iCount; i ++) { + pTC = chars.GetDataPtr(i); + iClsCur = pTC->m_iBidiClass; + if (iClsCur == FX_BIDICLASS_BN) { + pTC->m_iBidiLevel = (FX_INT16)iLevelCur; + if (i == iCount && iLevelCur != iBaseLevel) { + iClsCur = FX_BidiDirection(iLevelCur); + pTC->m_iBidiClass = (FX_INT16)iClsCur; + } else if (i < iCount) { + pTCNext = chars.GetDataPtr(i + 1); + FX_INT32 iLevelNext, iLevelNew; + iClsNew = pTCNext->m_iBidiClass; + iLevelNext = pTCNext->m_iBidiLevel; + if (iClsNew != FX_BIDICLASS_BN && iLevelCur != iLevelNext) { + iLevelNew = iLevelNext; + if (iLevelCur > iLevelNew) { + iLevelNew = iLevelCur; + } + pTC->m_iBidiLevel = (FX_INT16)iLevelNew; + iClsCur = FX_BidiDirection(iLevelNew); + pTC->m_iBidiClass = (FX_INT16)iClsCur; + iLevelCur = iLevelNext; + } else { + if (iNum > 0) { + iNum ++; + } + continue; + } + } else { + if (iNum > 0) { + iNum ++; + } + continue; + } + } + FXSYS_assert(iClsCur <= FX_BIDICLASS_BN); + iAction = gc_FX_BidiWeakActions[iState][iClsCur]; + iClsRun = FX_BidiGetDeferredType(iAction); + if (iClsRun != FX_BIDIWEAKACTION_XX && iNum > 0) { + FX_BidiSetDeferredRun(chars, TRUE, i, iNum, iClsRun); + iNum = 0; + } + iClsNew = FX_BidiGetResolvedType(iAction); + if (iClsNew != FX_BIDIWEAKACTION_XX) { + pTC->m_iBidiClass = (FX_INT16)iClsNew; + } + if (FX_BIDIWEAKACTION_IX & iAction) { + iNum ++; + } + iState = gc_FX_BidiWeakStates[iState][iClsCur]; + } + if (iNum > 0) { + iClsCur = FX_BidiDirection(iBaseLevel); + iClsRun = FX_BidiGetDeferredType(gc_FX_BidiWeakActions[iState][iClsCur]); + if (iClsRun != FX_BIDIWEAKACTION_XX) { + FX_BidiSetDeferredRun(chars, TRUE, i, iNum, iClsRun); + } + } + } + void FX_BidiResolveNeutrals(CFX_ArrayTemplate<baseType> &chars, FX_INT32 iCount, FX_INT32 iBaseLevel) + { + FXSYS_assert(iCount > -1 && iCount <= chars.GetSize()); + FXSYS_assert(iBaseLevel >= 0 && iBaseLevel <= FX_BIDIMAXLEVEL); + iCount --; + if (iCount < 1) { + return; + } + baseType *pTC; + FX_INT32 iLevel = iBaseLevel; + FX_INT32 iState = FX_IsOdd(iBaseLevel) ? FX_BNSr : FX_BNSl; + FX_INT32 i = 0, iNum = 0, iClsCur, iClsRun, iClsNew, iAction; + for (; i <= iCount; i ++) { + pTC = chars.GetDataPtr(i); + iClsCur = pTC->m_iBidiClass; + if (iClsCur == FX_BIDICLASS_BN) { + if (iNum) { + iNum ++; + } + continue; + } + FXSYS_assert(iClsCur < FX_BIDICLASS_AL); + iAction = gc_FX_BidiNeutralActions[iState][iClsCur]; + iClsRun = FX_BidiGetDeferredNeutrals(iAction, iLevel); + if (iClsRun != FX_BIDICLASS_N && iNum > 0) { + FX_BidiSetDeferredRun(chars, TRUE, i, iNum, iClsRun); + iNum = 0; + } + iClsNew = FX_BidiGetResolvedNeutrals(iAction); + if (iClsNew != FX_BIDICLASS_N) { + pTC->m_iBidiClass = (FX_INT16)iClsNew; + } + if (FX_BIDINEUTRALACTION_In & iAction) { + iNum ++; + } + iState = gc_FX_BidiNeutralStates[iState][iClsCur]; + iLevel = pTC->m_iBidiLevel; + } + if (iNum > 0) { + iClsCur = FX_BidiDirection(iLevel); + iClsRun = FX_BidiGetDeferredNeutrals(gc_FX_BidiNeutralActions[iState][iClsCur], iLevel); + if (iClsRun != FX_BIDICLASS_N) { + FX_BidiSetDeferredRun(chars, TRUE, i, iNum, iClsRun); + } + } + } + void FX_BidiResolveImplicit(CFX_ArrayTemplate<baseType> &chars, FX_INT32 iCount) + { + FXSYS_assert(iCount > -1 && iCount <= chars.GetSize()); + baseType *pTC; + FX_INT32 iCls, iLevel; + for (FX_INT32 i = 0; i < iCount; i ++) { + pTC = chars.GetDataPtr(i); + iCls = pTC->m_iBidiClass; + if (iCls == FX_BIDICLASS_BN) { + continue; + } + FXSYS_assert(iCls > FX_BIDICLASS_ON && iCls < FX_BIDICLASS_AL); + iLevel = pTC->m_iBidiLevel; + iLevel += gc_FX_BidiAddLevel[FX_IsOdd(iLevel)][iCls - 1]; + pTC->m_iBidiLevel = (FX_INT16)iLevel; + } + } + void FX_BidiResolveWhitespace(CFX_ArrayTemplate<baseType> &chars, FX_INT32 iCount, FX_INT32 iBaseLevel) + { + FXSYS_assert(iCount > -1 && iCount <= chars.GetSize()); + FXSYS_assert(iBaseLevel >= 0 && iBaseLevel <= FX_BIDIMAXLEVEL); + if (iCount < 1) { + return; + } + iCount --; + FX_INT32 iLevel = iBaseLevel; + FX_INT32 i = 0, iNum = 0; + baseType *pTC; + for (; i <= iCount; i ++) { + pTC = chars.GetDataPtr(i); + switch(pTC->m_iBidiClass) { + case FX_BIDICLASS_WS: + iNum ++; + break; + case FX_BIDICLASS_RLE: + case FX_BIDICLASS_LRE: + case FX_BIDICLASS_LRO: + case FX_BIDICLASS_RLO: + case FX_BIDICLASS_PDF: + case FX_BIDICLASS_BN: + pTC->m_iBidiLevel = (FX_INT16)iLevel; + iNum ++; + break; + case FX_BIDICLASS_S: + case FX_BIDICLASS_B: + if (iNum > 0) { + FX_BidiSetDeferredRun(chars, FALSE, i, iNum, iBaseLevel); + } + pTC->m_iBidiLevel = (FX_INT16)iBaseLevel; + iNum = 0; + break; + default: + iNum = 0; + break; + } + iLevel = pTC->m_iBidiLevel; + } + if (iNum > 0) { + FX_BidiSetDeferredRun(chars, FALSE, i, iNum, iBaseLevel); + } + } + FX_INT32 FX_BidiReorderLevel(CFX_ArrayTemplate<baseType> &chars, FX_INT32 iCount, FX_INT32 iBaseLevel, FX_INT32 iStart, FX_BOOL bReverse) + { + FXSYS_assert(iCount > -1 && iCount <= chars.GetSize()); + FXSYS_assert(iBaseLevel >= 0 && iBaseLevel <= FX_BIDIMAXLEVEL); + FXSYS_assert(iStart >= 0 && iStart < iCount); + if (iCount < 1) { + return 0; + } + baseType *pTC; + bReverse = bReverse || FX_IsOdd(iBaseLevel); + FX_INT32 i = iStart, iLevel; + for (; i < iCount; i ++) { + pTC = chars.GetDataPtr(i); + if ((iLevel = pTC->m_iBidiLevel) == iBaseLevel) { + continue; + } + if (iLevel < iBaseLevel) { + break; + } + i += FX_BidiReorderLevel(chars, iCount, iBaseLevel + 1, i, bReverse) - 1; + } + FX_INT32 iNum = i - iStart; + if (bReverse && iNum > 1) { + FX_BidiReverseString(chars, iStart, iNum); + } + return iNum; + } + void FX_BidiReorder(CFX_ArrayTemplate<baseType> &chars, FX_INT32 iCount, FX_INT32 iBaseLevel) + { + FXSYS_assert(iCount > -1 && iCount <= chars.GetSize()); + FXSYS_assert(iBaseLevel >= 0 && iBaseLevel <= FX_BIDIMAXLEVEL); + FX_INT32 i = 0; + while (i < iCount) { + i += FX_BidiReorderLevel(chars, iCount, iBaseLevel, i, FALSE); + } + } + void FX_BidiPosition(CFX_ArrayTemplate<baseType> &chars, FX_INT32 iCount) + { + FXSYS_assert(iCount > -1 && iCount <= chars.GetSize()); + baseType *pTC; + FX_INT32 i = 0; + while (i < iCount) { + pTC = chars.GetDataPtr(i); + pTC = chars.GetDataPtr(pTC->m_iBidiPos); + pTC->m_iBidiOrder = i ++; + } + } + + void FX_BidiLine(CFX_ArrayTemplate<baseType> &chars, FX_INT32 iCount, FX_INT32 iBaseLevel) + { + FXSYS_assert(iCount > -1 && iCount <= chars.GetSize()); + if (iCount < 2) { + return; + } + FX_BidiClassify(chars, iCount, FALSE); + FX_BidiResolveExplicit(chars, iCount, iBaseLevel); + FX_BidiResolveWeak(chars, iCount, iBaseLevel); + FX_BidiResolveNeutrals(chars, iCount, iBaseLevel); + FX_BidiResolveImplicit(chars, iCount); + FX_BidiClassify(chars, iCount, TRUE); + FX_BidiResolveWhitespace(chars, iCount, iBaseLevel); + FX_BidiReorder(chars, iCount, iBaseLevel); + FX_BidiPosition(chars, iCount); + } +}; +void FX_BidiLine(CFX_TxtCharArray &chars, FX_INT32 iCount, FX_INT32 iBaseLevel) +{ + CFX_BidiLineTemplate<CFX_TxtChar> blt; + blt.FX_BidiLine(chars, iCount, iBaseLevel); +} +void FX_BidiLine(CFX_RTFCharArray &chars, FX_INT32 iCount, FX_INT32 iBaseLevel) +{ + CFX_BidiLineTemplate<CFX_RTFChar> blt; + blt.FX_BidiLine(chars, iCount, iBaseLevel); +} IFX_BidiChar* IFX_BidiChar::Create() { return FX_NEW CFX_BidiChar; diff --git a/core/src/fxcrt/fx_arabic.h b/core/src/fxcrt/fx_arabic.h index c404449af0..e44bfb8142 100644 --- a/core/src/fxcrt/fx_arabic.h +++ b/core/src/fxcrt/fx_arabic.h @@ -6,7 +6,180 @@ #ifndef _FX_ARABIC_IMP #define _FX_ARABIC_IMP -class CFX_BidiChar FX_FINAL : public IFX_BidiChar, public CFX_Object +typedef struct _FX_ARABICCHARRANGE { + FX_WCHAR wStart; + FX_WCHAR wEnd; +} FX_ARABICCHARRANGE; +class CFX_ArabicChar : public IFX_ArabicChar, public CFX_Object +{ +public: + virtual void Release() + { + delete this; + } + virtual FX_BOOL IsArabicChar(FX_WCHAR wch) const; + virtual FX_BOOL IsArabicFormChar(FX_WCHAR wch) const; + + virtual FX_WCHAR GetFormChar(FX_WCHAR wch, FX_WCHAR prev = 0, FX_WCHAR next = 0) const; + virtual FX_WCHAR GetFormChar(const CFX_Char *cur, const CFX_Char *prev, const CFX_Char *next) const; +protected: + FX_LPCARBFORMTABLE ParseChar(const CFX_Char *pTC, FX_WCHAR &wChar, FX_CHARTYPE &eType) const; +}; +void FX_BidiReverseString(CFX_WideString &wsText, FX_INT32 iStart, FX_INT32 iCount); +void FX_BidiSetDeferredRun(CFX_Int32Array &values, FX_INT32 iStart, FX_INT32 iCount, FX_INT32 iValue); +#define FX_BCON FX_BIDICLASS_ON +#define FX_BCL FX_BIDICLASS_L +#define FX_BCR FX_BIDICLASS_R +#define FX_BCAN FX_BIDICLASS_AN +#define FX_BCEN FX_BIDICLASS_EN +#define FX_BCAL FX_BIDICLASS_AL +#define FX_BCNSM FX_BIDICLASS_NSM +#define FX_BCCS FX_BIDICLASS_CS +#define FX_BCES FX_BIDICLASS_ES +#define FX_BCET FX_BIDICLASS_ET +#define FX_BCBN FX_BIDICLASS_BN +#define FX_BCS FX_BIDICLASS_S +#define FX_BCWS FX_BIDICLASS_WS +#define FX_BCB FX_BIDICLASS_B +#define FX_BCRLO FX_BIDICLASS_RLO +#define FX_BCRLE FX_BIDICLASS_RLE +#define FX_BCLRO FX_BIDICLASS_LRO +#define FX_BCLRE FX_BIDICLASS_LRE +#define FX_BCPDF FX_BIDICLASS_PDF +#define FX_BCN FX_BIDICLASS_N +void FX_BidiClassify(const CFX_WideString &wsText, CFX_Int32Array &classes, FX_BOOL bWS = FALSE); +#define FX_BIDIMAXLEVEL 61 +#define FX_BidiGreaterEven(a) (FX_IsOdd(a) ? ((a) + 1) : ((a) + 2)) +#define FX_BidiGreaterOdd(a) (FX_IsOdd(a) ? ((a) + 2) : ((a) + 1)) +FX_INT32 FX_BidiResolveExplicit(FX_INT32 iBaseLevel, FX_INT32 iDirection, CFX_Int32Array &classes, CFX_Int32Array &levels, FX_INT32 iStart, FX_INT32 iCount, FX_INT32 iNest = 0); +#define FX_BidiDirection(a) (FX_IsOdd(a) ? FX_BIDICLASS_R : FX_BIDICLASS_L) +enum FX_BIDIWEAKSTATE { + FX_BIDIWEAKSTATE_xa = 0, + FX_BIDIWEAKSTATE_xr, + FX_BIDIWEAKSTATE_xl, + FX_BIDIWEAKSTATE_ao, + FX_BIDIWEAKSTATE_ro, + FX_BIDIWEAKSTATE_lo, + FX_BIDIWEAKSTATE_rt, + FX_BIDIWEAKSTATE_lt, + FX_BIDIWEAKSTATE_cn, + FX_BIDIWEAKSTATE_ra, + FX_BIDIWEAKSTATE_re, + FX_BIDIWEAKSTATE_la, + FX_BIDIWEAKSTATE_le, + FX_BIDIWEAKSTATE_ac, + FX_BIDIWEAKSTATE_rc, + FX_BIDIWEAKSTATE_rs, + FX_BIDIWEAKSTATE_lc, + FX_BIDIWEAKSTATE_ls, + FX_BIDIWEAKSTATE_ret, + FX_BIDIWEAKSTATE_let, +}; +#define FX_BWSxa FX_BIDIWEAKSTATE_xa +#define FX_BWSxr FX_BIDIWEAKSTATE_xr +#define FX_BWSxl FX_BIDIWEAKSTATE_xl +#define FX_BWSao FX_BIDIWEAKSTATE_ao +#define FX_BWSro FX_BIDIWEAKSTATE_ro +#define FX_BWSlo FX_BIDIWEAKSTATE_lo +#define FX_BWSrt FX_BIDIWEAKSTATE_rt +#define FX_BWSlt FX_BIDIWEAKSTATE_lt +#define FX_BWScn FX_BIDIWEAKSTATE_cn +#define FX_BWSra FX_BIDIWEAKSTATE_ra +#define FX_BWSre FX_BIDIWEAKSTATE_re +#define FX_BWSla FX_BIDIWEAKSTATE_la +#define FX_BWSle FX_BIDIWEAKSTATE_le +#define FX_BWSac FX_BIDIWEAKSTATE_ac +#define FX_BWSrc FX_BIDIWEAKSTATE_rc +#define FX_BWSrs FX_BIDIWEAKSTATE_rs +#define FX_BWSlc FX_BIDIWEAKSTATE_lc +#define FX_BWSls FX_BIDIWEAKSTATE_ls +#define FX_BWSret FX_BIDIWEAKSTATE_ret +#define FX_BWSlet FX_BIDIWEAKSTATE_let +enum FX_BIDIWEAKACTION { + FX_BIDIWEAKACTION_IX = 0x100, + FX_BIDIWEAKACTION_XX = 0x0F, + FX_BIDIWEAKACTION_xxx = (0x0F << 4) + 0x0F, + FX_BIDIWEAKACTION_xIx = 0x100 + FX_BIDIWEAKACTION_xxx, + FX_BIDIWEAKACTION_xxN = (0x0F << 4) + FX_BIDICLASS_ON, + FX_BIDIWEAKACTION_xxE = (0x0F << 4) + FX_BIDICLASS_EN, + FX_BIDIWEAKACTION_xxA = (0x0F << 4) + FX_BIDICLASS_AN, + FX_BIDIWEAKACTION_xxR = (0x0F << 4) + FX_BIDICLASS_R, + FX_BIDIWEAKACTION_xxL = (0x0F << 4) + FX_BIDICLASS_L, + FX_BIDIWEAKACTION_Nxx = (FX_BIDICLASS_ON << 4) + 0x0F, + FX_BIDIWEAKACTION_Axx = (FX_BIDICLASS_AN << 4) + 0x0F, + FX_BIDIWEAKACTION_ExE = (FX_BIDICLASS_EN << 4) + FX_BIDICLASS_EN, + FX_BIDIWEAKACTION_NIx = (FX_BIDICLASS_ON << 4) + 0x0F + 0x100, + FX_BIDIWEAKACTION_NxN = (FX_BIDICLASS_ON << 4) + FX_BIDICLASS_ON, + FX_BIDIWEAKACTION_NxR = (FX_BIDICLASS_ON << 4) + FX_BIDICLASS_R, + FX_BIDIWEAKACTION_NxE = (FX_BIDICLASS_ON << 4) + FX_BIDICLASS_EN, + FX_BIDIWEAKACTION_AxA = (FX_BIDICLASS_AN << 4) + FX_BIDICLASS_AN, + FX_BIDIWEAKACTION_NxL = (FX_BIDICLASS_ON << 4) + FX_BIDICLASS_L, + FX_BIDIWEAKACTION_LxL = (FX_BIDICLASS_L << 4) + FX_BIDICLASS_L, + FX_BIDIWEAKACTION_xIL = (0x0F << 4) + FX_BIDICLASS_L + 0x100, + FX_BIDIWEAKACTION_AxR = (FX_BIDICLASS_AN << 4) + FX_BIDICLASS_R, + FX_BIDIWEAKACTION_Lxx = (FX_BIDICLASS_L << 4) + 0x0F, +}; +#define FX_BWAIX FX_BIDIWEAKACTION_IX +#define FX_BWAXX FX_BIDIWEAKACTION_XX +#define FX_BWAxxx FX_BIDIWEAKACTION_xxx +#define FX_BWAxIx FX_BIDIWEAKACTION_xIx +#define FX_BWAxxN FX_BIDIWEAKACTION_xxN +#define FX_BWAxxE FX_BIDIWEAKACTION_xxE +#define FX_BWAxxA FX_BIDIWEAKACTION_xxA +#define FX_BWAxxR FX_BIDIWEAKACTION_xxR +#define FX_BWAxxL FX_BIDIWEAKACTION_xxL +#define FX_BWANxx FX_BIDIWEAKACTION_Nxx +#define FX_BWAAxx FX_BIDIWEAKACTION_Axx +#define FX_BWAExE FX_BIDIWEAKACTION_ExE +#define FX_BWANIx FX_BIDIWEAKACTION_NIx +#define FX_BWANxN FX_BIDIWEAKACTION_NxN +#define FX_BWANxR FX_BIDIWEAKACTION_NxR +#define FX_BWANxE FX_BIDIWEAKACTION_NxE +#define FX_BWAAxA FX_BIDIWEAKACTION_AxA +#define FX_BWANxL FX_BIDIWEAKACTION_NxL +#define FX_BWALxL FX_BIDIWEAKACTION_LxL +#define FX_BWAxIL FX_BIDIWEAKACTION_xIL +#define FX_BWAAxR FX_BIDIWEAKACTION_AxR +#define FX_BWALxx FX_BIDIWEAKACTION_Lxx +#define FX_BidiGetDeferredType(a) (((a) >> 4) & 0x0F) +#define FX_BidiGetResolvedType(a) ((a) & 0x0F) +void FX_BidiResolveWeak(FX_INT32 iBaseLevel, CFX_Int32Array &classes, CFX_Int32Array &levels); +enum FX_BIDINEUTRALSTATE { + FX_BIDINEUTRALSTATE_r = 0, + FX_BIDINEUTRALSTATE_l, + FX_BIDINEUTRALSTATE_rn, + FX_BIDINEUTRALSTATE_ln, + FX_BIDINEUTRALSTATE_a, + FX_BIDINEUTRALSTATE_na, +}; +#define FX_BNSr FX_BIDINEUTRALSTATE_r +#define FX_BNSl FX_BIDINEUTRALSTATE_l +#define FX_BNSrn FX_BIDINEUTRALSTATE_rn +#define FX_BNSln FX_BIDINEUTRALSTATE_ln +#define FX_BNSa FX_BIDINEUTRALSTATE_a +#define FX_BNSna FX_BIDINEUTRALSTATE_na +enum FX_BIDINEUTRALACTION { + FX_BIDINEUTRALACTION_nL = FX_BIDICLASS_L, + FX_BIDINEUTRALACTION_En = (FX_BIDICLASS_AN << 4), + FX_BIDINEUTRALACTION_Rn = (FX_BIDICLASS_R << 4), + FX_BIDINEUTRALACTION_Ln = (FX_BIDICLASS_L << 4), + FX_BIDINEUTRALACTION_In = FX_BIDIWEAKACTION_IX, + FX_BIDINEUTRALACTION_LnL = (FX_BIDICLASS_L << 4) + FX_BIDICLASS_L, +}; +#define FX_BNAnL FX_BIDINEUTRALACTION_nL +#define FX_BNAEn FX_BIDINEUTRALACTION_En +#define FX_BNARn FX_BIDINEUTRALACTION_Rn +#define FX_BNALn FX_BIDINEUTRALACTION_Ln +#define FX_BNAIn FX_BIDINEUTRALACTION_In +#define FX_BNALnL FX_BIDINEUTRALACTION_LnL +FX_INT32 FX_BidiGetDeferredNeutrals(FX_INT32 iAction, FX_INT32 iLevel); +FX_INT32 FX_BidiGetResolvedNeutrals(FX_INT32 iAction); +void FX_BidiResolveNeutrals(FX_INT32 iBaseLevel, CFX_Int32Array &classes, const CFX_Int32Array &levels); +void FX_BidiResolveImplicit(const CFX_Int32Array &classes, CFX_Int32Array &levels); +void FX_BidiResolveWhitespace(FX_INT32 iBaseLevel, const CFX_Int32Array &classes, CFX_Int32Array &levels); +FX_INT32 FX_BidiReorderLevel(FX_INT32 iBaseLevel, CFX_WideString &wsText, const CFX_Int32Array &levels, FX_INT32 iStart, FX_BOOL bReverse = FALSE); +void FX_BidiReorder(FX_INT32 iBaseLevel, CFX_WideString &wsText, const CFX_Int32Array &levels); +class CFX_BidiChar : public IFX_BidiChar, public CFX_Object { public: CFX_BidiChar(); diff --git a/core/src/fxcrt/fx_extension.cpp b/core/src/fxcrt/fx_extension.cpp index 7ff6b062b4..330c675457 100644 --- a/core/src/fxcrt/fx_extension.cpp +++ b/core/src/fxcrt/fx_extension.cpp @@ -80,6 +80,18 @@ FX_BOOL FX_File_Truncate(FX_HFILE hFile, FX_FILESIZE szFile) FXSYS_assert(hFile != NULL); return ((IFXCRT_FileAccess*)hFile)->Truncate(szFile); } +IFX_FileAccess* FX_CreateDefaultFileAccess(FX_WSTR wsPath)
+{
+ if (wsPath.GetLength() == 0)
+ return NULL;
+
+ CFX_CRTFileAccess* pFA = NULL;
+ pFA = FX_NEW CFX_CRTFileAccess;
+ if (NULL == pFA) return NULL;
+
+ pFA->Init(wsPath);
+ return pFA;
+}
IFX_FileStream* FX_CreateFileStream(FX_LPCSTR filename, FX_DWORD dwModes) { IFXCRT_FileAccess* pFA = FXCRT_FileAccess_Create(); @@ -383,3 +395,40 @@ void FX_Random_GenerateCrypto(FX_LPDWORD pBuffer, FX_INT32 iCount) #ifdef __cplusplus } #endif +#ifdef __cplusplus
+extern "C" {
+#endif
+void FX_GUID_CreateV4(FX_LPGUID pGUID)
+{
+#if (_FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN32_MOBILE_ || _FX_OS_ == _FX_WIN64_)
+#ifdef _FX_WINAPI_PARTITION_DESKTOP_
+ if (!FX_GenerateCryptoRandom((FX_LPDWORD)pGUID, 4)) {
+ FX_Random_GenerateMT((FX_LPDWORD)pGUID, 4);
+ }
+#else
+ FX_Random_GenerateMT((FX_LPDWORD)pGUID, 4);
+#endif
+#else
+ FX_Random_GenerateMT((FX_LPDWORD)pGUID, 4);
+#endif
+ FX_BYTE &b = ((FX_LPBYTE)pGUID)[6];
+ b = (b & 0x0F) | 0x40;
+}
+FX_LPCSTR gs_FX_pHexChars = "0123456789ABCDEF";
+void FX_GUID_ToString(FX_LPCGUID pGUID, CFX_ByteString &bsStr, FX_BOOL bSeparator)
+{
+ FX_LPSTR pBuf = bsStr.GetBuffer(40);
+ FX_BYTE b;
+ for (FX_INT32 i = 0; i < 16; i ++) {
+ b = ((FX_LPCBYTE)pGUID)[i];
+ *pBuf ++ = gs_FX_pHexChars[b >> 4];
+ *pBuf ++ = gs_FX_pHexChars[b & 0x0F];
+ if (bSeparator && (i == 3 || i == 5 || i == 7 || i == 9)) {
+ *pBuf ++ = L'-';
+ }
+ }
+ bsStr.ReleaseBuffer(bSeparator ? 36 : 32);
+}
+#ifdef __cplusplus
+}
+#endif
diff --git a/core/src/fxcrt/fx_xml_parser.cpp b/core/src/fxcrt/fx_xml_parser.cpp index 05fc7d5fbe..bd418b2d08 100644 --- a/core/src/fxcrt/fx_xml_parser.cpp +++ b/core/src/fxcrt/fx_xml_parser.cpp @@ -672,7 +672,7 @@ FX_BOOL CXML_Element::GetAttrValue(FX_BSTR name, CFX_WideString& attribute) cons FX_XML_SplitQualifiedName(name, bsSpace, bsName); const CFX_WideString* pValue = m_AttrMap.Lookup(bsSpace, bsName); if (pValue) { - attribute = CFX_WideString((FX_LPCWSTR)pValue, pValue->GetLength()); + attribute = CFX_WideString((FX_LPCWSTR)*pValue, pValue->GetLength()); return TRUE; } return FALSE; @@ -681,7 +681,7 @@ FX_BOOL CXML_Element::GetAttrValue(FX_BSTR space, FX_BSTR name, CFX_WideString& { const CFX_WideString* pValue = m_AttrMap.Lookup(space, name); if (pValue) { - attribute = CFX_WideString((FX_LPCWSTR)pValue, pValue->GetLength()); + attribute = CFX_WideString((FX_LPCWSTR)*pValue, pValue->GetLength()); return TRUE; } return FALSE; |