From 9c62cadff466f26307bd06ed1e9df2c1b5f25a32 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Tue, 17 Nov 2015 17:20:41 -0800 Subject: Make CPDF_InterForm::AddStandardFont take a non-const document pointer. Instead of taking a const pointer, and then casting away the const-ness. Also remove similar, but dead CPDF_InterForm methods. R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1456763003 . --- core/include/fpdfdoc/fpdf_doc.h | 12 +----- core/src/fpdfdoc/doc_form.cpp | 92 +++++------------------------------------ 2 files changed, 12 insertions(+), 92 deletions(-) diff --git a/core/include/fpdfdoc/fpdf_doc.h b/core/include/fpdfdoc/fpdf_doc.h index c7a85ef9b9..fd85fda4b9 100644 --- a/core/include/fpdfdoc/fpdf_doc.h +++ b/core/include/fpdfdoc/fpdf_doc.h @@ -544,17 +544,7 @@ class CPDF_InterForm : public CFX_PrivateData { int iMinLen = 2, const FX_CHAR* csPrefix = ""); - static CPDF_Font* AddSystemDefaultFont(const CPDF_Document* pDocument); - - static CPDF_Font* AddSystemFont(const CPDF_Document* pDocument, - CFX_ByteString csFontName, - uint8_t iCharSet = 1); - - static CPDF_Font* AddSystemFont(const CPDF_Document* pDocument, - CFX_WideString csFontName, - uint8_t iCharSet = 1); - - static CPDF_Font* AddStandardFont(const CPDF_Document* pDocument, + static CPDF_Font* AddStandardFont(CPDF_Document* pDocument, CFX_ByteString csFontName); static CFX_ByteString GetNativeFont(uint8_t iCharSet, void* pLogFont = NULL); diff --git a/core/src/fpdfdoc/doc_form.cpp b/core/src/fpdfdoc/doc_form.cpp index 857bf5acea..421f02fa3f 100644 --- a/core/src/fpdfdoc/doc_form.cpp +++ b/core/src/fpdfdoc/doc_form.cpp @@ -385,89 +385,19 @@ static FX_BOOL RetrieveStockFont(int iFontObject, return FALSE; } #endif -CPDF_Font* CPDF_InterForm::AddSystemDefaultFont( - const CPDF_Document* pDocument) { - if (pDocument == NULL) { - return NULL; - } - CPDF_Font* pFont = NULL; -#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ - LOGFONTA lf; - FX_BOOL bRet; - bRet = RetrieveStockFont(DEFAULT_GUI_FONT, 255, lf); - if (!bRet) { - bRet = RetrieveStockFont(SYSTEM_FONT, 255, lf); - } - if (bRet) { - pFont = ((CPDF_Document*)pDocument)->AddWindowsFont(&lf, FALSE, TRUE); - } -#endif - return pFont; -} -CPDF_Font* CPDF_InterForm::AddSystemFont(const CPDF_Document* pDocument, - CFX_ByteString csFontName, - uint8_t iCharSet) { - if (pDocument == NULL || csFontName.IsEmpty()) { - return NULL; - } -#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ - if (iCharSet == 1) { - iCharSet = GetNativeCharSet(); - } - HFONT hFont = ::CreateFontA( - 0, 0, 0, 0, 0, 0, 0, 0, iCharSet, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, - DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, csFontName.c_str()); - if (hFont != NULL) { - LOGFONTA lf; - memset(&lf, 0, sizeof(LOGFONTA)); - ::GetObjectA(hFont, sizeof(LOGFONTA), &lf); - ::DeleteObject(hFont); - if (strlen(lf.lfFaceName) > 0) { - return ((CPDF_Document*)pDocument)->AddWindowsFont(&lf, FALSE, TRUE); - } - } -#endif - return NULL; -} -CPDF_Font* CPDF_InterForm::AddSystemFont(const CPDF_Document* pDocument, - CFX_WideString csFontName, - uint8_t iCharSet) { - if (pDocument == NULL || csFontName.IsEmpty()) { - return NULL; - } -#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ - if (iCharSet == 1) { - iCharSet = GetNativeCharSet(); - } - HFONT hFont = ::CreateFontW( - 0, 0, 0, 0, 0, 0, 0, 0, iCharSet, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, - DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, csFontName.c_str()); - if (hFont != NULL) { - LOGFONTA lf; - memset(&lf, 0, sizeof(LOGFONTA)); - ::GetObject(hFont, sizeof(LOGFONTA), &lf); - ::DeleteObject(hFont); - if (strlen(lf.lfFaceName) > 0) { - return ((CPDF_Document*)pDocument)->AddWindowsFont(&lf, FALSE, TRUE); - } - } -#endif - return NULL; -} -CPDF_Font* CPDF_InterForm::AddStandardFont(const CPDF_Document* pDocument, + +CPDF_Font* CPDF_InterForm::AddStandardFont(CPDF_Document* pDocument, CFX_ByteString csFontName) { - if (pDocument == NULL || csFontName.IsEmpty()) { - return NULL; - } - CPDF_Font* pFont = NULL; - if (csFontName == "ZapfDingbats") { - pFont = ((CPDF_Document*)pDocument)->AddStandardFont(csFontName, NULL); - } else { - CPDF_FontEncoding encoding(PDFFONT_ENCODING_WINANSI); - pFont = ((CPDF_Document*)pDocument)->AddStandardFont(csFontName, &encoding); - } - return pFont; + if (!pDocument || csFontName.IsEmpty()) + return nullptr; + + if (csFontName == "ZapfDingbats") + return pDocument->AddStandardFont(csFontName.c_str(), nullptr); + + CPDF_FontEncoding encoding(PDFFONT_ENCODING_WINANSI); + return pDocument->AddStandardFont(csFontName.c_str(), &encoding); } + CFX_ByteString CPDF_InterForm::GetNativeFont(uint8_t charSet, void* pLogFont) { CFX_ByteString csFontName; #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ -- cgit v1.2.3