diff options
author | thestig <thestig@chromium.org> | 2016-06-21 14:38:27 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-06-21 14:38:28 -0700 |
commit | 907a5223ea5abd09878de20cc74c59ebd0d6c3c8 (patch) | |
tree | 7dba8b090eda4f65da57d1979bdb02cedd273055 /fpdfsdk | |
parent | 56a8b1944d555ed65dda97164b702a9a657485ca (diff) | |
download | pdfium-907a5223ea5abd09878de20cc74c59ebd0d6c3c8.tar.xz |
Use FXFONT defines in place of integers.
Fix nits along the way.
Review-Url: https://codereview.chromium.org/2083943003
Diffstat (limited to 'fpdfsdk')
-rw-r--r-- | fpdfsdk/cfx_systemhandler.cpp | 19 | ||||
-rw-r--r-- | fpdfsdk/cfx_systemhandler.h | 9 | ||||
-rw-r--r-- | fpdfsdk/formfiller/cba_fontmap.cpp | 27 | ||||
-rw-r--r-- | fpdfsdk/formfiller/cffl_combobox.cpp | 2 | ||||
-rw-r--r-- | fpdfsdk/formfiller/cffl_textfield.cpp | 2 | ||||
-rw-r--r-- | fpdfsdk/fpdf_sysfontinfo.cpp | 61 | ||||
-rw-r--r-- | fpdfsdk/pdfwindow/PWL_Edit.cpp | 2 | ||||
-rw-r--r-- | fpdfsdk/pdfwindow/PWL_FontMap.cpp | 6 |
8 files changed, 61 insertions, 67 deletions
diff --git a/fpdfsdk/cfx_systemhandler.cpp b/fpdfsdk/cfx_systemhandler.cpp index c0fd140c9b..d6ec4f0cf0 100644 --- a/fpdfsdk/cfx_systemhandler.cpp +++ b/fpdfsdk/cfx_systemhandler.cpp @@ -6,6 +6,8 @@ #include "fpdfsdk/cfx_systemhandler.h" +#include <memory> + #include "core/fxge/include/fx_ge.h" #include "fpdfsdk/formfiller/cffl_formfiller.h" #include "fpdfsdk/include/fsdk_mgr.h" @@ -13,13 +15,13 @@ namespace { int CharSet2CP(int charset) { - if (charset == 128) + if (charset == FXFONT_SHIFTJIS_CHARSET) return 932; - if (charset == 134) + if (charset == FXFONT_GB2312_CHARSET) return 936; - if (charset == 129) + if (charset == FXFONT_HANGEUL_CHARSET) return 949; - if (charset == 136) + if (charset == FXFONT_CHINESEBIG5_CHARSET) return 950; return 0; } @@ -78,8 +80,7 @@ bool CFX_SystemHandler::IsSelectionImplemented() const { return false; } -bool CFX_SystemHandler::FindNativeTrueTypeFont(int32_t nCharset, - CFX_ByteString sFontFaceName) { +bool CFX_SystemHandler::FindNativeTrueTypeFont(CFX_ByteString sFontFaceName) { CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); if (!pFontMgr) return false; @@ -106,11 +107,9 @@ CPDF_Font* CFX_SystemHandler::AddNativeTrueTypeFontToPDF( if (!pDoc) return nullptr; - CFX_Font* pFXFont = new CFX_Font(); + std::unique_ptr<CFX_Font> pFXFont(new CFX_Font); pFXFont->LoadSubst(sFontFaceName, TRUE, 0, 0, 0, CharSet2CP(nCharset), FALSE); - CPDF_Font* pFont = pDoc->AddFont(pFXFont, nCharset, FALSE); - delete pFXFont; - return pFont; + return pDoc->AddFont(pFXFont.get(), nCharset, FALSE); } int32_t CFX_SystemHandler::SetTimer(int32_t uElapse, diff --git a/fpdfsdk/cfx_systemhandler.h b/fpdfsdk/cfx_systemhandler.h index e77120adef..76da223310 100644 --- a/fpdfsdk/cfx_systemhandler.h +++ b/fpdfsdk/cfx_systemhandler.h @@ -49,8 +49,7 @@ class CPDFDoc_Environment; class CFX_SystemHandler { public: - explicit CFX_SystemHandler(CPDFDoc_Environment* pEnv) - : m_pEnv(pEnv), m_nCharSet(-1) {} + explicit CFX_SystemHandler(CPDFDoc_Environment* pEnv) : m_pEnv(pEnv) {} ~CFX_SystemHandler() {} void InvalidateRect(FX_HWND hWnd, FX_RECT rect); @@ -59,7 +58,7 @@ class CFX_SystemHandler { void SetCursor(int32_t nCursorType); - bool FindNativeTrueTypeFont(int32_t nCharset, CFX_ByteString sFontFaceName); + bool FindNativeTrueTypeFont(CFX_ByteString sFontFaceName); CPDF_Font* AddNativeTrueTypeFontToPDF(CPDF_Document* pDoc, CFX_ByteString sFontFaceName, uint8_t nCharset); @@ -71,12 +70,8 @@ class CFX_SystemHandler { FX_SYSTEMTIME GetLocalTime(); - int32_t GetCharSet() const { return m_nCharSet; } - void SetCharSet(int32_t nCharSet) { m_nCharSet = nCharSet; } - private: CPDFDoc_Environment* const m_pEnv; - int m_nCharSet; }; #endif // FPDFSDK_CFX_SYSTEMHANDLER_H_ diff --git a/fpdfsdk/formfiller/cba_fontmap.cpp b/fpdfsdk/formfiller/cba_fontmap.cpp index 9102b7bf9a..b8c8865d44 100644 --- a/fpdfsdk/formfiller/cba_fontmap.cpp +++ b/fpdfsdk/formfiller/cba_fontmap.cpp @@ -79,24 +79,23 @@ void CBA_FontMap::SetDefaultFont(CPDF_Font* pFont, CPDF_Font* CBA_FontMap::FindFontSameCharset(CFX_ByteString& sFontAlias, int32_t nCharset) { - if (m_pAnnotDict->GetStringBy("Subtype") == "Widget") { - CPDF_Document* pDocument = GetDocument(); - CPDF_Dictionary* pRootDict = pDocument->GetRoot(); - if (!pRootDict) - return nullptr; + if (m_pAnnotDict->GetStringBy("Subtype") != "Widget") + return nullptr; - CPDF_Dictionary* pAcroFormDict = pRootDict->GetDictBy("AcroForm"); - if (!pAcroFormDict) - return nullptr; + CPDF_Document* pDocument = GetDocument(); + CPDF_Dictionary* pRootDict = pDocument->GetRoot(); + if (!pRootDict) + return nullptr; - CPDF_Dictionary* pDRDict = pAcroFormDict->GetDictBy("DR"); - if (!pDRDict) - return nullptr; + CPDF_Dictionary* pAcroFormDict = pRootDict->GetDictBy("AcroForm"); + if (!pAcroFormDict) + return nullptr; - return FindResFontSameCharset(pDRDict, sFontAlias, nCharset); - } + CPDF_Dictionary* pDRDict = pAcroFormDict->GetDictBy("DR"); + if (!pDRDict) + return nullptr; - return nullptr; + return FindResFontSameCharset(pDRDict, sFontAlias, nCharset); } CPDF_Document* CBA_FontMap::GetDocument() { diff --git a/fpdfsdk/formfiller/cffl_combobox.cpp b/fpdfsdk/formfiller/cffl_combobox.cpp index d489a243d9..262c485138 100644 --- a/fpdfsdk/formfiller/cffl_combobox.cpp +++ b/fpdfsdk/formfiller/cffl_combobox.cpp @@ -257,7 +257,7 @@ void CFFL_ComboBox::OnSetFocus(CPWL_Wnd* pWnd) { if (pWnd->GetClassName() == PWL_CLASSNAME_EDIT) { CPWL_Edit* pEdit = (CPWL_Edit*)pWnd; - pEdit->SetCharSet(134); + pEdit->SetCharSet(FXFONT_GB2312_CHARSET); pEdit->SetCodePage(936); pEdit->SetReadyToInput(); diff --git a/fpdfsdk/formfiller/cffl_textfield.cpp b/fpdfsdk/formfiller/cffl_textfield.cpp index be1f36b697..4f32f42ac7 100644 --- a/fpdfsdk/formfiller/cffl_textfield.cpp +++ b/fpdfsdk/formfiller/cffl_textfield.cpp @@ -269,7 +269,7 @@ void CFFL_TextField::OnSetFocus(CPWL_Wnd* pWnd) { ASSERT(m_pApp); if (pWnd->GetClassName() == PWL_CLASSNAME_EDIT) { CPWL_Edit* pEdit = (CPWL_Edit*)pWnd; - pEdit->SetCharSet(134); + pEdit->SetCharSet(FXFONT_GB2312_CHARSET); pEdit->SetCodePage(936); pEdit->SetReadyToInput(); diff --git a/fpdfsdk/fpdf_sysfontinfo.cpp b/fpdfsdk/fpdf_sysfontinfo.cpp index 2a309d9785..b149726839 100644 --- a/fpdfsdk/fpdf_sysfontinfo.cpp +++ b/fpdfsdk/fpdf_sysfontinfo.cpp @@ -33,25 +33,25 @@ class CFX_ExternalFontInfo final : public IFX_SystemFontInfo { int pitch_family, const FX_CHAR* family, int& iExact) override { - if (m_pInfo->MapFont) - return m_pInfo->MapFont(m_pInfo, weight, bItalic, charset, pitch_family, - family, &iExact); - return nullptr; + if (!m_pInfo->MapFont) + return nullptr; + return m_pInfo->MapFont(m_pInfo, weight, bItalic, charset, pitch_family, + family, &iExact); } void* GetFont(const FX_CHAR* family) override { - if (m_pInfo->GetFont) - return m_pInfo->GetFont(m_pInfo, family); - return nullptr; + if (!m_pInfo->GetFont) + return nullptr; + return m_pInfo->GetFont(m_pInfo, family); } uint32_t GetFontData(void* hFont, uint32_t table, uint8_t* buffer, uint32_t size) override { - if (m_pInfo->GetFontData) - return m_pInfo->GetFontData(m_pInfo, hFont, table, buffer, size); - return 0; + if (!m_pInfo->GetFontData) + return 0; + return m_pInfo->GetFontData(m_pInfo, hFont, table, buffer, size); } FX_BOOL GetFaceName(void* hFont, CFX_ByteString& name) override { @@ -68,11 +68,11 @@ class CFX_ExternalFontInfo final : public IFX_SystemFontInfo { } FX_BOOL GetFontCharset(void* hFont, int& charset) override { - if (m_pInfo->GetFontCharset) { - charset = m_pInfo->GetFontCharset(m_pInfo, hFont); - return TRUE; - } - return FALSE; + if (!m_pInfo->GetFontCharset) + return FALSE; + + charset = m_pInfo->GetFontCharset(m_pInfo, hFont); + return TRUE; } void DeleteFont(void* hFont) override { @@ -87,7 +87,8 @@ class CFX_ExternalFontInfo final : public IFX_SystemFontInfo { DLLEXPORT void STDCALL FPDF_AddInstalledFont(void* mapper, const char* name, int charset) { - ((CFX_FontMapper*)mapper)->AddInstalledFont(name, charset); + CFX_FontMapper* pMapper = reinterpret_cast<CFX_FontMapper*>(mapper); + pMapper->AddInstalledFont(name, charset); } DLLEXPORT void STDCALL FPDF_SetSystemFontInfo(FPDF_SYSFONTINFO* pFontInfoExt) { @@ -114,8 +115,8 @@ static void DefaultRelease(struct _FPDF_SYSFONTINFO* pThis) { } static void DefaultEnumFonts(struct _FPDF_SYSFONTINFO* pThis, void* pMapper) { - ((FPDF_SYSFONTINFO_DEFAULT*)pThis) - ->m_pFontInfo->EnumFontList((CFX_FontMapper*)pMapper); + auto* pDefault = static_cast<FPDF_SYSFONTINFO_DEFAULT*>(pThis); + pDefault->m_pFontInfo->EnumFontList((CFX_FontMapper*)pMapper); } static void* DefaultMapFont(struct _FPDF_SYSFONTINFO* pThis, @@ -125,13 +126,14 @@ static void* DefaultMapFont(struct _FPDF_SYSFONTINFO* pThis, int pitch_family, const char* family, int* bExact) { - return ((FPDF_SYSFONTINFO_DEFAULT*)pThis) - ->m_pFontInfo->MapFont(weight, bItalic, charset, pitch_family, family, - *bExact); + auto* pDefault = static_cast<FPDF_SYSFONTINFO_DEFAULT*>(pThis); + return pDefault->m_pFontInfo->MapFont(weight, bItalic, charset, pitch_family, + family, *bExact); } void* DefaultGetFont(struct _FPDF_SYSFONTINFO* pThis, const char* family) { - return ((FPDF_SYSFONTINFO_DEFAULT*)pThis)->m_pFontInfo->GetFont(family); + auto* pDefault = static_cast<FPDF_SYSFONTINFO_DEFAULT*>(pThis); + return pDefault->m_pFontInfo->GetFont(family); } static unsigned long DefaultGetFontData(struct _FPDF_SYSFONTINFO* pThis, @@ -139,8 +141,8 @@ static unsigned long DefaultGetFontData(struct _FPDF_SYSFONTINFO* pThis, unsigned int table, unsigned char* buffer, unsigned long buf_size) { - return ((FPDF_SYSFONTINFO_DEFAULT*)pThis) - ->m_pFontInfo->GetFontData(hFont, table, buffer, buf_size); + auto* pDefault = static_cast<FPDF_SYSFONTINFO_DEFAULT*>(pThis); + return pDefault->m_pFontInfo->GetFontData(hFont, table, buffer, buf_size); } static unsigned long DefaultGetFaceName(struct _FPDF_SYSFONTINFO* pThis, @@ -148,8 +150,8 @@ static unsigned long DefaultGetFaceName(struct _FPDF_SYSFONTINFO* pThis, char* buffer, unsigned long buf_size) { CFX_ByteString name; - if (!((FPDF_SYSFONTINFO_DEFAULT*)pThis) - ->m_pFontInfo->GetFaceName(hFont, name)) + auto* pDefault = static_cast<FPDF_SYSFONTINFO_DEFAULT*>(pThis); + if (!pDefault->m_pFontInfo->GetFaceName(hFont, name)) return 0; if (name.GetLength() >= (long)buf_size) return name.GetLength() + 1; @@ -159,14 +161,15 @@ static unsigned long DefaultGetFaceName(struct _FPDF_SYSFONTINFO* pThis, static int DefaultGetFontCharset(struct _FPDF_SYSFONTINFO* pThis, void* hFont) { int charset; - if (!((FPDF_SYSFONTINFO_DEFAULT*)pThis) - ->m_pFontInfo->GetFontCharset(hFont, charset)) + auto* pDefault = static_cast<FPDF_SYSFONTINFO_DEFAULT*>(pThis); + if (!pDefault->m_pFontInfo->GetFontCharset(hFont, charset)) return 0; return charset; } static void DefaultDeleteFont(struct _FPDF_SYSFONTINFO* pThis, void* hFont) { - ((FPDF_SYSFONTINFO_DEFAULT*)pThis)->m_pFontInfo->DeleteFont(hFont); + auto* pDefault = static_cast<FPDF_SYSFONTINFO_DEFAULT*>(pThis); + pDefault->m_pFontInfo->DeleteFont(hFont); } DLLEXPORT FPDF_SYSFONTINFO* STDCALL FPDF_GetDefaultSystemFontInfo() { diff --git a/fpdfsdk/pdfwindow/PWL_Edit.cpp b/fpdfsdk/pdfwindow/PWL_Edit.cpp index 21d4b033ab..e7a4ac9dd3 100644 --- a/fpdfsdk/pdfwindow/PWL_Edit.cpp +++ b/fpdfsdk/pdfwindow/PWL_Edit.cpp @@ -464,7 +464,7 @@ void CPWL_Edit::OnKillFocus() { m_pEdit->SelectNone(); SetCaret(FALSE, CFX_FloatPoint(0.0f, 0.0f), CFX_FloatPoint(0.0f, 0.0f)); - SetCharSet(0); + SetCharSet(FXFONT_ANSI_CHARSET); if (!IsReadOnly()) { if (IPWL_FocusHandler* pFocusHandler = GetFocusHandler()) diff --git a/fpdfsdk/pdfwindow/PWL_FontMap.cpp b/fpdfsdk/pdfwindow/PWL_FontMap.cpp index d4eab01cfd..e810ec6a8c 100644 --- a/fpdfsdk/pdfwindow/PWL_FontMap.cpp +++ b/fpdfsdk/pdfwindow/PWL_FontMap.cpp @@ -281,10 +281,10 @@ CFX_ByteString CPWL_FontMap::GetNativeFont(int32_t nCharset) { CFX_ByteString sFontName = GetDefaultFontByCharset(nCharset); if (m_pSystemHandler) { - if (m_pSystemHandler->FindNativeTrueTypeFont(nCharset, sFontName)) + if (m_pSystemHandler->FindNativeTrueTypeFont(sFontName)) return sFontName; - sFontName = ""; + sFontName.clear(); } return sFontName; } @@ -437,8 +437,6 @@ CFX_ByteString CPWL_FontMap::GetDefaultFontByCharset(int32_t nCharset) { } int32_t CPWL_FontMap::CharSetFromUnicode(uint16_t 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; |