summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2015-11-17 17:50:23 -0800
committerLei Zhang <thestig@chromium.org>2015-11-17 17:50:23 -0800
commit0c0d8bd35decd8e97fb972a932abd111b545138c (patch)
tree31ababf0085007560412309720bfbc9ac4f2b55c /core
parentc57e236578f923007fbcdac953625d46a569f213 (diff)
downloadpdfium-0c0d8bd35decd8e97fb972a932abd111b545138c.tar.xz
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. TBR=tsepez@chromium.org Review URL: https://codereview.chromium.org/1456763003 . Review URL: https://codereview.chromium.org/1456823002 . Review URL: https://codereview.chromium.org/1452843005 . (cherry picked from commit 9c62cadff466f26307bd06ed1e9df2c1b5f25a32) (cherry picked from commit 447946588d6bbd4d5bc34477a09dd983285c507e) (cherry picked from commit b2a4c976841863e89804a2643eebccf881c57584) Review URL: https://codereview.chromium.org/1457703002 .
Diffstat (limited to 'core')
-rw-r--r--core/include/fpdfdoc/fpdf_doc.h17
-rw-r--r--core/src/fpdfdoc/doc_form.cpp124
2 files changed, 27 insertions, 114 deletions
diff --git a/core/include/fpdfdoc/fpdf_doc.h b/core/include/fpdfdoc/fpdf_doc.h
index 478d6fbbdd..c270c78bcf 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);
@@ -563,10 +553,9 @@ class CPDF_InterForm : public CFX_PrivateData {
static uint8_t GetNativeCharSet();
- static CPDF_Font* AddNativeFont(uint8_t iCharSet,
- const CPDF_Document* pDocument);
+ static CPDF_Font* AddNativeFont(uint8_t iCharSet, CPDF_Document* pDocument);
- static CPDF_Font* AddNativeFont(const CPDF_Document* pDocument);
+ static CPDF_Font* AddNativeFont(CPDF_Document* pDocument);
FX_BOOL ValidateFieldName(CFX_WideString& csNewFieldName, int iType);
diff --git a/core/src/fpdfdoc/doc_form.cpp b/core/src/fpdfdoc/doc_form.cpp
index 857bf5acea..241609efbc 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_
@@ -576,34 +506,28 @@ uint8_t CPDF_InterForm::GetNativeCharSet() {
return 0;
#endif
}
+
CPDF_Font* CPDF_InterForm::AddNativeFont(uint8_t charSet,
- const CPDF_Document* pDocument) {
- if (pDocument == NULL) {
- return NULL;
- }
- CPDF_Font* pFont = NULL;
+ CPDF_Document* pDocument) {
+ if (!pDocument)
+ return nullptr;
+
#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
LOGFONTA lf;
CFX_ByteString csFontName = GetNativeFont(charSet, &lf);
if (!csFontName.IsEmpty()) {
- if (csFontName == "Helvetica") {
- pFont = AddStandardFont(pDocument, csFontName);
- } else {
- pFont = ((CPDF_Document*)pDocument)->AddWindowsFont(&lf, FALSE, TRUE);
- }
+ if (csFontName == "Helvetica")
+ return AddStandardFont(pDocument, csFontName);
+ return pDocument->AddWindowsFont(&lf, FALSE, TRUE);
}
#endif
- return pFont;
+ return nullptr;
}
-CPDF_Font* CPDF_InterForm::AddNativeFont(const CPDF_Document* pDocument) {
- if (pDocument == NULL) {
- return NULL;
- }
- CPDF_Font* pFont = NULL;
- uint8_t charSet = GetNativeCharSet();
- pFont = AddNativeFont(charSet, pDocument);
- return pFont;
+
+CPDF_Font* CPDF_InterForm::AddNativeFont(CPDF_Document* pDocument) {
+ return pDocument ? AddNativeFont(GetNativeCharSet(), pDocument) : nullptr;
}
+
FX_BOOL CPDF_InterForm::ValidateFieldName(
CFX_WideString& csNewFieldName,
int iType,