diff options
author | Tom Sepez <tsepez@chromium.org> | 2015-07-22 14:59:55 -0700 |
---|---|---|
committer | Tom Sepez <tsepez@chromium.org> | 2015-07-22 14:59:55 -0700 |
commit | 7cc97521db1e52d5927f5605de5f9a7102f8af40 (patch) | |
tree | df96cf98cd470e794c7817f347511f3c554c96e4 /fpdfsdk/src/pdfwindow/PWL_FontMap.cpp | |
parent | b05f1fd710496dea44b001bb905fa1c16a39bb28 (diff) | |
download | pdfium-7cc97521db1e52d5927f5605de5f9a7102f8af40.tar.xz |
Fix else-after-returns throughout pdfium.
Driven by CS search for
pcre:yes file:third_party/pdfium/ -file:pdfium/third_party/
\breturn\b[^;]*;\s*\n*\s*\}*\s*\n*\r*else
Note: Care is required to ensure the preceding block is not an else-if.
As usual, removed any tabs I saw.
R=thestig@chromium.org
Review URL: https://codereview.chromium.org/1243883003 .
Diffstat (limited to 'fpdfsdk/src/pdfwindow/PWL_FontMap.cpp')
-rw-r--r-- | fpdfsdk/src/pdfwindow/PWL_FontMap.cpp | 730 |
1 files changed, 351 insertions, 379 deletions
diff --git a/fpdfsdk/src/pdfwindow/PWL_FontMap.cpp b/fpdfsdk/src/pdfwindow/PWL_FontMap.cpp index 84b8c94363..50b321dfac 100644 --- a/fpdfsdk/src/pdfwindow/PWL_FontMap.cpp +++ b/fpdfsdk/src/pdfwindow/PWL_FontMap.cpp @@ -8,15 +8,15 @@ #include "../../include/pdfwindow/PWL_Wnd.h" #include "../../include/pdfwindow/PWL_FontMap.h" -#define DEFAULT_FONT_NAME "Helvetica" +#define DEFAULT_FONT_NAME "Helvetica" /* ------------------------------ CPWL_FontMap ------------------------------ */ CPWL_FontMap::CPWL_FontMap(IFX_SystemHandler* pSystemHandler) : - m_pPDFDoc(NULL), - m_pSystemHandler(pSystemHandler) + m_pPDFDoc(NULL), + m_pSystemHandler(pSystemHandler) { - ASSERT(m_pSystemHandler != NULL); + ASSERT(m_pSystemHandler != NULL); } CPWL_FontMap::~CPWL_FontMap() @@ -29,177 +29,167 @@ CPWL_FontMap::~CPWL_FontMap() void CPWL_FontMap::SetSystemHandler(IFX_SystemHandler* pSystemHandler) { - m_pSystemHandler = pSystemHandler; + m_pSystemHandler = pSystemHandler; } CPDF_Document* CPWL_FontMap::GetDocument() { - if (!m_pPDFDoc) - { - if (CPDF_ModuleMgr::Get()) - { - m_pPDFDoc = new CPDF_Document; - m_pPDFDoc->CreateNewDoc(); - } - } + if (!m_pPDFDoc) + { + if (CPDF_ModuleMgr::Get()) + { + m_pPDFDoc = new CPDF_Document; + m_pPDFDoc->CreateNewDoc(); + } + } - return m_pPDFDoc; + return m_pPDFDoc; } CPDF_Font* CPWL_FontMap::GetPDFFont(int32_t nFontIndex) { - if (nFontIndex >=0 && nFontIndex < m_aData.GetSize()) - { - if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex)) - { - return pData->pFont; - } - } + if (nFontIndex >=0 && nFontIndex < m_aData.GetSize()) + { + if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex)) + { + return pData->pFont; + } + } - return NULL; + return NULL; } CFX_ByteString CPWL_FontMap::GetPDFFontAlias(int32_t nFontIndex) { - if (nFontIndex >=0 && nFontIndex < m_aData.GetSize()) - { - if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex)) - { - return pData->sFontName; - } - } + if (nFontIndex >=0 && nFontIndex < m_aData.GetSize()) + { + if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex)) + { + return pData->sFontName; + } + } - return ""; + return ""; } FX_BOOL CPWL_FontMap::KnowWord(int32_t nFontIndex, FX_WORD word) { - if (nFontIndex >=0 && nFontIndex < m_aData.GetSize()) - { - if (m_aData.GetAt(nFontIndex)) - { - return CharCodeFromUnicode(nFontIndex, word) >= 0; - } - } + if (nFontIndex >=0 && nFontIndex < m_aData.GetSize()) + { + if (m_aData.GetAt(nFontIndex)) + { + return CharCodeFromUnicode(nFontIndex, word) >= 0; + } + } - return FALSE; + return FALSE; } int32_t CPWL_FontMap::GetWordFontIndex(FX_WORD word, int32_t nCharset, int32_t nFontIndex) { - if (nFontIndex > 0) - { - if (KnowWord(nFontIndex, word)) - return nFontIndex; - } - else - { - if (const CPWL_FontMap_Data* pData = GetFontMapData(0)) - { - if (nCharset == DEFAULT_CHARSET || - pData->nCharset == SYMBOL_CHARSET || - nCharset == pData->nCharset) - { - if (KnowWord(0, word)) - { - return 0; - } - } - } - } - - int32_t nNewFontIndex = -1; - - nNewFontIndex = GetFontIndex(GetNativeFontName(nCharset), nCharset, TRUE); - if (nNewFontIndex >= 0) - { - if (KnowWord(nNewFontIndex, word)) - return nNewFontIndex; - } - - nNewFontIndex = GetFontIndex("Arial Unicode MS", DEFAULT_CHARSET, FALSE); - if (nNewFontIndex >= 0) - { - if (KnowWord(nNewFontIndex, word)) - return nNewFontIndex; - } - - return -1; + if (nFontIndex > 0) + { + if (KnowWord(nFontIndex, word)) + return nFontIndex; + } + else + { + if (const CPWL_FontMap_Data* pData = GetFontMapData(0)) + { + if (nCharset == DEFAULT_CHARSET || + pData->nCharset == SYMBOL_CHARSET || + nCharset == pData->nCharset) + { + if (KnowWord(0, word)) + return 0; + } + } + } + + int32_t nNewFontIndex = GetFontIndex(GetNativeFontName(nCharset), nCharset, TRUE); + if (nNewFontIndex >= 0) + { + if (KnowWord(nNewFontIndex, word)) + return nNewFontIndex; + } + nNewFontIndex = GetFontIndex("Arial Unicode MS", DEFAULT_CHARSET, FALSE); + if (nNewFontIndex >= 0) + { + if (KnowWord(nNewFontIndex, word)) + return nNewFontIndex; + } + return -1; } int32_t CPWL_FontMap::CharCodeFromUnicode(int32_t nFontIndex, FX_WORD word) { - if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex)) - { - if (pData->pFont) - { - if (pData->pFont->IsUnicodeCompatible()) - { - int nCharCode = pData->pFont->CharCodeFromUnicode(word); - pData->pFont->GlyphFromCharCode(nCharCode); - return nCharCode; - } - else - { - if (word < 0xFF) - return word; - } - } - } - - return -1; + if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex)) + { + if (pData->pFont) + { + if (pData->pFont->IsUnicodeCompatible()) + { + int nCharCode = pData->pFont->CharCodeFromUnicode(word); + pData->pFont->GlyphFromCharCode(nCharCode); + return nCharCode; + } + if (word < 0xFF) + return word; + } + } + return -1; } CFX_ByteString CPWL_FontMap::GetNativeFontName(int32_t nCharset) { - //searching native font is slow, so we must save time - for (int32_t i=0,sz=m_aNativeFont.GetSize(); i<sz; i++) - { - if (CPWL_FontMap_Native* pData = m_aNativeFont.GetAt(i)) - { - if (pData->nCharset == nCharset) - return pData->sFontName; - } - } + //searching native font is slow, so we must save time + for (int32_t i=0,sz=m_aNativeFont.GetSize(); i<sz; i++) + { + if (CPWL_FontMap_Native* pData = m_aNativeFont.GetAt(i)) + { + if (pData->nCharset == nCharset) + return pData->sFontName; + } + } - CFX_ByteString sNew = GetNativeFont(nCharset); + CFX_ByteString sNew = GetNativeFont(nCharset); - if (!sNew.IsEmpty()) - { - CPWL_FontMap_Native* pNewData = new CPWL_FontMap_Native; - pNewData->nCharset = nCharset; - pNewData->sFontName = sNew; + if (!sNew.IsEmpty()) + { + CPWL_FontMap_Native* pNewData = new CPWL_FontMap_Native; + pNewData->nCharset = nCharset; + pNewData->sFontName = sNew; - m_aNativeFont.Add(pNewData); - } + m_aNativeFont.Add(pNewData); + } - return sNew; + return sNew; } void CPWL_FontMap::Empty() { - { - for (int32_t i=0, sz=m_aData.GetSize(); i<sz; i++) - delete m_aData.GetAt(i); + { + for (int32_t i=0, sz=m_aData.GetSize(); i<sz; i++) + delete m_aData.GetAt(i); - m_aData.RemoveAll(); - } - { - for (int32_t i=0, sz=m_aNativeFont.GetSize(); i<sz; i++) - delete m_aNativeFont.GetAt(i); + m_aData.RemoveAll(); + } + { + for (int32_t i=0, sz=m_aNativeFont.GetSize(); i<sz; i++) + delete m_aNativeFont.GetAt(i); - m_aNativeFont.RemoveAll(); - } + m_aNativeFont.RemoveAll(); + } } void CPWL_FontMap::Initial(const FX_CHAR* fontname) { - CFX_ByteString sFontName = fontname; + CFX_ByteString sFontName = fontname; - if (sFontName.IsEmpty()) - sFontName = DEFAULT_FONT_NAME; + if (sFontName.IsEmpty()) + sFontName = DEFAULT_FONT_NAME; - GetFontIndex(sFontName, ANSI_CHARSET, FALSE); + GetFontIndex(sFontName, ANSI_CHARSET, FALSE); } @@ -212,122 +202,107 @@ Symbol, ZapfDingbats */ const char* g_sDEStandardFontName[] = {"Courier", "Courier-Bold", "Courier-BoldOblique", "Courier-Oblique", - "Helvetica", "Helvetica-Bold", "Helvetica-BoldOblique", "Helvetica-Oblique", - "Times-Roman", "Times-Bold", "Times-Italic", "Times-BoldItalic", - "Symbol", "ZapfDingbats"}; + "Helvetica", "Helvetica-Bold", "Helvetica-BoldOblique", "Helvetica-Oblique", + "Times-Roman", "Times-Bold", "Times-Italic", "Times-BoldItalic", + "Symbol", "ZapfDingbats"}; -FX_BOOL CPWL_FontMap::IsStandardFont(const CFX_ByteString& sFontName) +FX_BOOL CPWL_FontMap::IsStandardFont(const CFX_ByteString& sFontName) { - for (int32_t i=0; i<14; i++) - { - if (sFontName == g_sDEStandardFontName[i]) - return TRUE; - } + for (int32_t i=0; i<14; i++) + { + if (sFontName == g_sDEStandardFontName[i]) + return TRUE; + } - return FALSE; + return FALSE; } int32_t CPWL_FontMap::FindFont(const CFX_ByteString& sFontName, int32_t nCharset) { - for (int32_t i=0,sz=m_aData.GetSize(); i<sz; i++) - { - if (CPWL_FontMap_Data* pData = m_aData.GetAt(i)) - { - if (nCharset == DEFAULT_CHARSET || nCharset == pData->nCharset) - { - if (sFontName.IsEmpty() || pData->sFontName == sFontName) - return i; - } - } - } + for (int32_t i=0,sz=m_aData.GetSize(); i<sz; i++) + { + if (CPWL_FontMap_Data* pData = m_aData.GetAt(i)) + { + if (nCharset == DEFAULT_CHARSET || nCharset == pData->nCharset) + { + if (sFontName.IsEmpty() || pData->sFontName == sFontName) + return i; + } + } + } - return -1; + return -1; } int32_t CPWL_FontMap::GetFontIndex(const CFX_ByteString& sFontName, int32_t nCharset, FX_BOOL bFind) { - int32_t nFontIndex = FindFont(EncodeFontAlias(sFontName, nCharset), nCharset); - if (nFontIndex >= 0) return nFontIndex; + int32_t nFontIndex = FindFont(EncodeFontAlias(sFontName, nCharset), nCharset); + if (nFontIndex >= 0) + return nFontIndex; -// nFontIndex = FindFont("", nCharset); -// if (nFontIndex >= 0) return nFontIndex; + CFX_ByteString sAlias; + CPDF_Font* pFont = NULL; + if (bFind) + pFont = FindFontSameCharset(sAlias, nCharset); - CFX_ByteString sAlias; - CPDF_Font* pFont = NULL; - - if (bFind) - pFont = FindFontSameCharset(sAlias, nCharset); - - if (!pFont) - { - CFX_ByteString sTemp = sFontName; - pFont = AddFontToDocument(GetDocument(), sTemp, nCharset); - - /* - if (FindFont(sAlias)) - { - sAlias = EncodeFontAlias(sTemp, nCharset); - } - else - */ - { - sAlias = EncodeFontAlias(sTemp, nCharset); - } - } - - AddedFont(pFont, sAlias); - - return AddFontData(pFont, sAlias, nCharset); + if (!pFont) + { + CFX_ByteString sTemp = sFontName; + pFont = AddFontToDocument(GetDocument(), sTemp, nCharset); + sAlias = EncodeFontAlias(sTemp, nCharset); + } + AddedFont(pFont, sAlias); + return AddFontData(pFont, sAlias, nCharset); } int32_t CPWL_FontMap::GetPWLFontIndex(FX_WORD word, int32_t nCharset) { - int32_t nFind = -1; + int32_t nFind = -1; - for (int32_t i=0,sz=m_aData.GetSize(); i<sz; i++) - { - if (CPWL_FontMap_Data* pData = m_aData.GetAt(i)) - { - if (pData->nCharset == nCharset) - { - nFind = i; - break; - } - } - } + for (int32_t i=0,sz=m_aData.GetSize(); i<sz; i++) + { + if (CPWL_FontMap_Data* pData = m_aData.GetAt(i)) + { + if (pData->nCharset == nCharset) + { + nFind = i; + break; + } + } + } - CPDF_Font* pNewFont = GetPDFFont(nFind); + CPDF_Font* pNewFont = GetPDFFont(nFind); - if (!pNewFont) return -1; + if (!pNewFont) return -1; - /* - if (CPDF_Font* pFont = GetPDFFont(nFind)) - { - PWLFont.AddWordToFontDict(pFontDict, word); - } - */ + /* + if (CPDF_Font* pFont = GetPDFFont(nFind)) + { + PWLFont.AddWordToFontDict(pFontDict, word); + } + */ - CFX_ByteString sAlias = EncodeFontAlias("Arial_Chrome", nCharset); - AddedFont(pNewFont, sAlias); + CFX_ByteString sAlias = EncodeFontAlias("Arial_Chrome", nCharset); + AddedFont(pNewFont, sAlias); - return AddFontData(pNewFont, sAlias, nCharset); + return AddFontData(pNewFont, sAlias, nCharset); } CPDF_Font* CPWL_FontMap::FindFontSameCharset(CFX_ByteString& sFontAlias, int32_t nCharset) { - return NULL; + return NULL; } int32_t CPWL_FontMap::AddFontData(CPDF_Font* pFont, const CFX_ByteString& sFontAlias, int32_t nCharset) { - CPWL_FontMap_Data* pNewData = new CPWL_FontMap_Data; - pNewData->pFont = pFont; - pNewData->sFontName = sFontAlias; - pNewData->nCharset = nCharset; + CPWL_FontMap_Data* pNewData = new CPWL_FontMap_Data; + pNewData->pFont = pFont; + pNewData->sFontName = sFontAlias; + pNewData->nCharset = nCharset; - m_aData.Add(pNewData); + m_aData.Add(pNewData); - return m_aData.GetSize() -1; + return m_aData.GetSize() -1; } void CPWL_FontMap::AddedFont(CPDF_Font* pFont, const CFX_ByteString& sFontAlias) @@ -336,253 +311,250 @@ void CPWL_FontMap::AddedFont(CPDF_Font* pFont, const CFX_ByteString& sFontAlias) CFX_ByteString CPWL_FontMap::GetFontName(int32_t nFontIndex) { - if (nFontIndex >=0 && nFontIndex < m_aData.GetSize()) - { - if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex)) - { - return pData->sFontName; - } - } + if (nFontIndex >=0 && nFontIndex < m_aData.GetSize()) + { + if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex)) + { + return pData->sFontName; + } + } - return ""; + return ""; } CFX_ByteString CPWL_FontMap::GetNativeFont(int32_t nCharset) { - CFX_ByteString sFontName; - - if (nCharset == DEFAULT_CHARSET) - nCharset = GetNativeCharset(); - sFontName = GetDefaultFontByCharset(nCharset); + if (nCharset == DEFAULT_CHARSET) + nCharset = GetNativeCharset(); - if (m_pSystemHandler) - { - if (m_pSystemHandler->FindNativeTrueTypeFont(nCharset, sFontName)) - return sFontName; + CFX_ByteString sFontName = GetDefaultFontByCharset(nCharset); + if (m_pSystemHandler) + { + if (m_pSystemHandler->FindNativeTrueTypeFont(nCharset, sFontName)) + return sFontName; - sFontName = m_pSystemHandler->GetNativeTrueTypeFont(nCharset); - } - - return sFontName; + sFontName = m_pSystemHandler->GetNativeTrueTypeFont(nCharset); + } + return sFontName; } CPDF_Font* CPWL_FontMap::AddFontToDocument(CPDF_Document* pDoc, CFX_ByteString& sFontName, uint8_t nCharset) { - if (IsStandardFont(sFontName)) - return AddStandardFont(pDoc, sFontName); - else - return AddSystemFont(pDoc, sFontName, nCharset); + if (IsStandardFont(sFontName)) + return AddStandardFont(pDoc, sFontName); + + return AddSystemFont(pDoc, sFontName, nCharset); } CPDF_Font* CPWL_FontMap::AddStandardFont(CPDF_Document* pDoc, CFX_ByteString& sFontName) { - if (!pDoc) return NULL; + if (!pDoc) return NULL; - CPDF_Font* pFont = NULL; + CPDF_Font* pFont = NULL; - if (sFontName == "ZapfDingbats") - pFont = pDoc->AddStandardFont(sFontName, NULL); - else - { - CPDF_FontEncoding fe(PDFFONT_ENCODING_WINANSI); - pFont = pDoc->AddStandardFont(sFontName, &fe); - } + if (sFontName == "ZapfDingbats") + pFont = pDoc->AddStandardFont(sFontName, NULL); + else + { + CPDF_FontEncoding fe(PDFFONT_ENCODING_WINANSI); + pFont = pDoc->AddStandardFont(sFontName, &fe); + } - return pFont; + return pFont; } CPDF_Font* CPWL_FontMap::AddSystemFont(CPDF_Document* pDoc, CFX_ByteString& sFontName, uint8_t nCharset) { - if (!pDoc) return NULL; + if (!pDoc) return NULL; - if (sFontName.IsEmpty()) sFontName = GetNativeFont(nCharset); - if (nCharset == DEFAULT_CHARSET) nCharset = GetNativeCharset(); + if (sFontName.IsEmpty()) sFontName = GetNativeFont(nCharset); + if (nCharset == DEFAULT_CHARSET) nCharset = GetNativeCharset(); - if (m_pSystemHandler) - return m_pSystemHandler->AddNativeTrueTypeFontToPDF(pDoc, sFontName, nCharset); + if (m_pSystemHandler) + return m_pSystemHandler->AddNativeTrueTypeFontToPDF(pDoc, sFontName, nCharset); - return NULL; + return NULL; } CFX_ByteString CPWL_FontMap::EncodeFontAlias(const CFX_ByteString& sFontName, int32_t nCharset) { - CFX_ByteString sPostfix; - sPostfix.Format("_%02X", nCharset); - return EncodeFontAlias(sFontName) + sPostfix; + CFX_ByteString sPostfix; + sPostfix.Format("_%02X", nCharset); + return EncodeFontAlias(sFontName) + sPostfix; } CFX_ByteString CPWL_FontMap::EncodeFontAlias(const CFX_ByteString& sFontName) { - CFX_ByteString sRet = sFontName; - sRet.Remove(' '); - return sRet; + CFX_ByteString sRet = sFontName; + sRet.Remove(' '); + return sRet; } int32_t CPWL_FontMap::GetFontMapCount() const { - return m_aData.GetSize(); + return m_aData.GetSize(); } const CPWL_FontMap_Data* CPWL_FontMap::GetFontMapData(int32_t nIndex) const { - if (nIndex >=0 && nIndex < m_aData.GetSize()) - { - return m_aData.GetAt(nIndex); - } + if (nIndex >=0 && nIndex < m_aData.GetSize()) + { + return m_aData.GetAt(nIndex); + } - return NULL; + return NULL; } int32_t CPWL_FontMap::GetNativeCharset() { - uint8_t nCharset = ANSI_CHARSET; - int32_t iCodePage = FXSYS_GetACP(); - switch (iCodePage) - { - case 932://Japan - nCharset = SHIFTJIS_CHARSET; - break; - case 936://Chinese (PRC, Singapore) - nCharset = GB2312_CHARSET; - break; - case 950://Chinese (Taiwan; Hong Kong SAR, PRC) - nCharset = GB2312_CHARSET; - break; - case 1252://Windows 3.1 Latin 1 (US, Western Europe) - nCharset = ANSI_CHARSET; - break; - case 874://Thai - nCharset = THAI_CHARSET; - break; - case 949://Korean - nCharset = HANGUL_CHARSET; - break; - case 1200://Unicode (BMP of ISO 10646) - nCharset = ANSI_CHARSET; - break; - case 1250://Windows 3.1 Eastern European - nCharset = EASTEUROPE_CHARSET; - break; - case 1251://Windows 3.1 Cyrillic - nCharset = RUSSIAN_CHARSET; - break; - case 1253://Windows 3.1 Greek - nCharset = GREEK_CHARSET; - break; - case 1254://Windows 3.1 Turkish - nCharset = TURKISH_CHARSET; - break; - case 1255://Hebrew - nCharset = HEBREW_CHARSET; - break; - case 1256://Arabic - nCharset = ARABIC_CHARSET; - break; - case 1257://Baltic - nCharset = BALTIC_CHARSET; - break; - case 1258://Vietnamese - nCharset = VIETNAMESE_CHARSET; - break; - case 1361://Korean(Johab) - nCharset = JOHAB_CHARSET; - break; - } - return nCharset; + uint8_t nCharset = ANSI_CHARSET; + int32_t iCodePage = FXSYS_GetACP(); + switch (iCodePage) + { + case 932://Japan + nCharset = SHIFTJIS_CHARSET; + break; + case 936://Chinese (PRC, Singapore) + nCharset = GB2312_CHARSET; + break; + case 950://Chinese (Taiwan; Hong Kong SAR, PRC) + nCharset = GB2312_CHARSET; + break; + case 1252://Windows 3.1 Latin 1 (US, Western Europe) + nCharset = ANSI_CHARSET; + break; + case 874://Thai + nCharset = THAI_CHARSET; + break; + case 949://Korean + nCharset = HANGUL_CHARSET; + break; + case 1200://Unicode (BMP of ISO 10646) + nCharset = ANSI_CHARSET; + break; + case 1250://Windows 3.1 Eastern European + nCharset = EASTEUROPE_CHARSET; + break; + case 1251://Windows 3.1 Cyrillic + nCharset = RUSSIAN_CHARSET; + break; + case 1253://Windows 3.1 Greek + nCharset = GREEK_CHARSET; + break; + case 1254://Windows 3.1 Turkish + nCharset = TURKISH_CHARSET; + break; + case 1255://Hebrew + nCharset = HEBREW_CHARSET; + break; + case 1256://Arabic + nCharset = ARABIC_CHARSET; + break; + case 1257://Baltic + nCharset = BALTIC_CHARSET; + break; + case 1258://Vietnamese + nCharset = VIETNAMESE_CHARSET; + break; + case 1361://Korean(Johab) + nCharset = JOHAB_CHARSET; + break; + } + return nCharset; } const CPWL_FontMap::CharsetFontMap CPWL_FontMap::defaultTTFMap[] = { - { ANSI_CHARSET, "Helvetica" }, - { GB2312_CHARSET, "SimSun" }, - { CHINESEBIG5_CHARSET, "MingLiU" }, - { SHIFTJIS_CHARSET, "MS Gothic" }, - { HANGUL_CHARSET, "Batang" }, - { RUSSIAN_CHARSET, "Arial" }, + { ANSI_CHARSET, "Helvetica" }, + { GB2312_CHARSET, "SimSun" }, + { CHINESEBIG5_CHARSET, "MingLiU" }, + { SHIFTJIS_CHARSET, "MS Gothic" }, + { HANGUL_CHARSET, "Batang" }, + { RUSSIAN_CHARSET, "Arial" }, #if _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ || _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ - { EASTEUROPE_CHARSET, "Arial" }, + { EASTEUROPE_CHARSET, "Arial" }, #else - { EASTEUROPE_CHARSET, "Tahoma" }, + { EASTEUROPE_CHARSET, "Tahoma" }, #endif - { ARABIC_CHARSET, "Arial" }, - { -1, NULL } + { ARABIC_CHARSET, "Arial" }, + { -1, NULL } }; CFX_ByteString CPWL_FontMap::GetDefaultFontByCharset(int32_t nCharset) { - int i = 0; - while (defaultTTFMap[i].charset != -1) { - if (nCharset == defaultTTFMap[i].charset) - return defaultTTFMap[i].fontname; + int i = 0; + while (defaultTTFMap[i].charset != -1) { + if (nCharset == defaultTTFMap[i].charset) + return defaultTTFMap[i].fontname; ++i; - } - return ""; + } + return ""; } int32_t CPWL_FontMap::CharSetFromUnicode(FX_WORD word, int32_t nOldCharset) { - if(m_pSystemHandler && (-1 != m_pSystemHandler->GetCharSet())) - return m_pSystemHandler->GetCharSet(); - //to avoid CJK Font to show ASCII - if (word < 0x7F) return ANSI_CHARSET; - //follow the old charset - if (nOldCharset != DEFAULT_CHARSET) return nOldCharset; + if(m_pSystemHandler && (-1 != m_pSystemHandler->GetCharSet())) + return m_pSystemHandler->GetCharSet(); + //to avoid CJK Font to show ASCII + if (word < 0x7F) return ANSI_CHARSET; + //follow the old charset + if (nOldCharset != DEFAULT_CHARSET) return nOldCharset; - //find new charset - if ((word >= 0x4E00 && word <= 0x9FA5) || - (word >= 0xE7C7 && word <= 0xE7F3) || - (word >= 0x3000 && word <= 0x303F) || - (word >= 0x2000 && word <= 0x206F)) - { - return GB2312_CHARSET; - } + //find new charset + if ((word >= 0x4E00 && word <= 0x9FA5) || + (word >= 0xE7C7 && word <= 0xE7F3) || + (word >= 0x3000 && word <= 0x303F) || + (word >= 0x2000 && word <= 0x206F)) + { + return GB2312_CHARSET; + } - if (((word >= 0x3040) && (word <= 0x309F)) || - ((word >= 0x30A0) && (word <= 0x30FF)) || - ((word >= 0x31F0) && (word <= 0x31FF)) || - ((word >= 0xFF00) && (word <= 0xFFEF)) ) - { - return SHIFTJIS_CHARSET; - } + if (((word >= 0x3040) && (word <= 0x309F)) || + ((word >= 0x30A0) && (word <= 0x30FF)) || + ((word >= 0x31F0) && (word <= 0x31FF)) || + ((word >= 0xFF00) && (word <= 0xFFEF)) ) + { + return SHIFTJIS_CHARSET; + } - if (((word >= 0xAC00) && (word <= 0xD7AF)) || - ((word >= 0x1100) && (word <= 0x11FF)) || - ((word >= 0x3130) && (word <= 0x318F))) - { - return HANGUL_CHARSET; - } + if (((word >= 0xAC00) && (word <= 0xD7AF)) || + ((word >= 0x1100) && (word <= 0x11FF)) || + ((word >= 0x3130) && (word <= 0x318F))) + { + return HANGUL_CHARSET; + } - if (word >= 0x0E00 && word <= 0x0E7F) - return THAI_CHARSET; + if (word >= 0x0E00 && word <= 0x0E7F) + return THAI_CHARSET; - if ((word >= 0x0370 && word <= 0x03FF) || - (word >= 0x1F00 && word <= 0x1FFF)) - return GREEK_CHARSET; + if ((word >= 0x0370 && word <= 0x03FF) || + (word >= 0x1F00 && word <= 0x1FFF)) + return GREEK_CHARSET; - if ((word >= 0x0600 && word <= 0x06FF) || - (word >= 0xFB50 && word <= 0xFEFC)) - return ARABIC_CHARSET; + if ((word >= 0x0600 && word <= 0x06FF) || + (word >= 0xFB50 && word <= 0xFEFC)) + return ARABIC_CHARSET; - if (word >= 0x0590 && word <= 0x05FF) - return HEBREW_CHARSET; + if (word >= 0x0590 && word <= 0x05FF) + return HEBREW_CHARSET; - if (word >= 0x0400 && word <= 0x04FF) - return RUSSIAN_CHARSET; + if (word >= 0x0400 && word <= 0x04FF) + return RUSSIAN_CHARSET; - if (word >= 0x0100 && word <= 0x024F) - return EASTEUROPE_CHARSET; + if (word >= 0x0100 && word <= 0x024F) + return EASTEUROPE_CHARSET; - if (word >= 0x1E00 && word <= 0x1EFF) - return VIETNAMESE_CHARSET; + if (word >= 0x1E00 && word <= 0x1EFF) + return VIETNAMESE_CHARSET; - return ANSI_CHARSET; + return ANSI_CHARSET; } /* ------------------------ CPWL_DocFontMap ------------------------ */ CPWL_DocFontMap::CPWL_DocFontMap(IFX_SystemHandler* pSystemHandler, CPDF_Document* pAttachedDoc) - : CPWL_FontMap(pSystemHandler), - m_pAttachedDoc(pAttachedDoc) + : CPWL_FontMap(pSystemHandler), + m_pAttachedDoc(pAttachedDoc) { } @@ -592,5 +564,5 @@ CPWL_DocFontMap::~CPWL_DocFontMap() CPDF_Document* CPWL_DocFontMap::GetDocument() { - return m_pAttachedDoc; + return m_pAttachedDoc; } |