summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-05-25 22:58:39 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-05-25 22:58:39 +0000
commitdf93cd35530e7b8dd67abde8d199c36c3fae76be (patch)
treecc760bdcc560f0ad448db5a2d01de01d6ba8d1c7
parent2aa4b2f3928ccd8393f60db8f7b740c75f4e8a8d (diff)
downloadpdfium-df93cd35530e7b8dd67abde8d199c36c3fae76be.tar.xz
Replace some #ifdef PDF_ENABLE_XFA with runtime checks.
Abstract GetUserPermissions() differences via new virtual method. Abstract GetPageCount() differences via existing virtual method. Remove unused ReadHeader() form for non-xfa. Remove unused FindSubstFontByUnicode() for xfa. Remove unused FXFONT_EXACTMATCH Change-Id: I0a3de01a9841db86fcbc96991d3fa2682393b9ad Reviewed-on: https://pdfium-review.googlesource.com/32831 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
-rw-r--r--core/fpdfapi/parser/cpdf_document.cpp13
-rw-r--r--core/fpdfapi/parser/cpdf_document.h1
-rw-r--r--core/fxcodec/codec/ccodec_jpegmodule.h4
-rw-r--r--core/fxcodec/codec/fx_codec_jpeg.cpp9
-rw-r--r--core/fxge/cfx_fontmapper.cpp39
-rw-r--r--core/fxge/cfx_fontmapper.h7
-rw-r--r--core/fxge/fx_font.h3
-rw-r--r--fpdfsdk/cpdfsdk_formfillenvironment.cpp7
-rw-r--r--fpdfsdk/fpdfxfa/cpdfxfa_context.cpp5
-rw-r--r--fpdfsdk/fpdfxfa/cpdfxfa_context.h1
10 files changed, 16 insertions, 73 deletions
diff --git a/core/fpdfapi/parser/cpdf_document.cpp b/core/fpdfapi/parser/cpdf_document.cpp
index 5479a06174..7968d1b019 100644
--- a/core/fpdfapi/parser/cpdf_document.cpp
+++ b/core/fpdfapi/parser/cpdf_document.cpp
@@ -464,15 +464,10 @@ int CPDF_Document::RetrievePageCount() {
}
uint32_t CPDF_Document::GetUserPermissions() const {
- // https://bugs.chromium.org/p/pdfium/issues/detail?id=499
- if (!m_pParser) {
-#ifndef PDF_ENABLE_XFA
- return 0;
-#else // PDF_ENABLE_XFA
- return 0xFFFFFFFF;
-#endif
- }
- return m_pParser->GetPermissions();
+ if (m_pParser)
+ return m_pParser->GetPermissions();
+
+ return m_pExtension ? m_pExtension->GetUserPermissions() : 0;
}
CPDF_Font* CPDF_Document::LoadFont(CPDF_Dictionary* pFontDict) {
diff --git a/core/fpdfapi/parser/cpdf_document.h b/core/fpdfapi/parser/cpdf_document.h
index 013eded765..c2774b163a 100644
--- a/core/fpdfapi/parser/cpdf_document.h
+++ b/core/fpdfapi/parser/cpdf_document.h
@@ -49,6 +49,7 @@ class CPDF_Document : public CPDF_IndirectObjectHolder {
virtual CPDF_Document* GetPDFDoc() const = 0;
virtual int GetPageCount() const = 0;
virtual void DeletePage(int page_index) = 0;
+ virtual uint32_t GetUserPermissions() const = 0;
};
explicit CPDF_Document(std::unique_ptr<CPDF_Parser> pParser);
diff --git a/core/fxcodec/codec/ccodec_jpegmodule.h b/core/fxcodec/codec/ccodec_jpegmodule.h
index aed01bda9b..06cd2242c2 100644
--- a/core/fxcodec/codec/ccodec_jpegmodule.h
+++ b/core/fxcodec/codec/ccodec_jpegmodule.h
@@ -45,9 +45,7 @@ class CCodec_JpegModule {
std::unique_ptr<Context> Start();
void Input(Context* pContext, const uint8_t* src_buf, uint32_t src_size);
-#ifndef PDF_ENABLE_XFA
- int ReadHeader(Context* pContext, int* width, int* height, int* nComps);
-#else // PDF_ENABLE_XFA
+#ifdef PDF_ENABLE_XFA
int ReadHeader(Context* pContext,
int* width,
int* height,
diff --git a/core/fxcodec/codec/fx_codec_jpeg.cpp b/core/fxcodec/codec/fx_codec_jpeg.cpp
index 7a73f4e55e..f0b8d66d3a 100644
--- a/core/fxcodec/codec/fx_codec_jpeg.cpp
+++ b/core/fxcodec/codec/fx_codec_jpeg.cpp
@@ -451,12 +451,6 @@ int CCodec_JpegModule::ReadHeader(Context* pContext,
int* height,
int* nComps,
CFX_DIBAttribute* pAttribute) {
-#else // PDF_ENABLE_XFA
-int CCodec_JpegModule::ReadHeader(Context* pContext,
- int* width,
- int* height,
- int* nComps) {
-#endif // PDF_ENABLE_XFA
auto* ctx = static_cast<CJpegContext*>(pContext);
int ret = jpeg_read_header(&ctx->m_Info, true);
if (ret == JPEG_SUSPENDED)
@@ -467,11 +461,10 @@ int CCodec_JpegModule::ReadHeader(Context* pContext,
*width = ctx->m_Info.image_width;
*height = ctx->m_Info.image_height;
*nComps = ctx->m_Info.num_components;
-#ifdef PDF_ENABLE_XFA
JpegLoadAttribute(&ctx->m_Info, pAttribute);
-#endif
return 0;
}
+#endif // PDF_ENABLE_XFA
bool CCodec_JpegModule::StartScanline(Context* pContext, int down_scale) {
auto* ctx = static_cast<CJpegContext*>(pContext);
diff --git a/core/fxge/cfx_fontmapper.cpp b/core/fxge/cfx_fontmapper.cpp
index f44e7aab69..b9a8eac1a1 100644
--- a/core/fxge/cfx_fontmapper.cpp
+++ b/core/fxge/cfx_fontmapper.cpp
@@ -611,10 +611,6 @@ FXFT_Face CFX_FontMapper::FindSubstFont(const ByteString& name,
void* hFont = m_pFontInfo->MapFont(weight, bItalic, Charset, PitchFamily,
family.c_str());
if (!hFont) {
-#ifdef PDF_ENABLE_XFA
- if (flags & FXFONT_EXACTMATCH)
- return nullptr;
-#endif // PDF_ENABLE_XFA
if (bCJK) {
bItalic = italic_angle != 0;
weight = old_weight;
@@ -697,41 +693,6 @@ FXFT_Face CFX_FontMapper::FindSubstFont(const ByteString& name,
return face;
}
-#ifdef PDF_ENABLE_XFA
-FXFT_Face CFX_FontMapper::FindSubstFontByUnicode(uint32_t dwUnicode,
- uint32_t flags,
- int weight,
- int italic_angle) {
- if (!m_pFontInfo)
- return nullptr;
-
- bool bItalic = (flags & FXFONT_ITALIC) != 0;
- int PitchFamily = 0;
- UpdatePitchFamily(flags, &PitchFamily);
- void* hFont =
- m_pFontInfo->MapFontByUnicode(dwUnicode, weight, bItalic, PitchFamily);
- if (!hFont)
- return nullptr;
-
- uint32_t ttc_size = m_pFontInfo->GetFontData(hFont, 0x74746366, nullptr, 0);
- uint32_t font_size = m_pFontInfo->GetFontData(hFont, 0, nullptr, 0);
- if (font_size == 0 && ttc_size == 0) {
- m_pFontInfo->DeleteFont(hFont);
- return nullptr;
- }
- FXFT_Face face = nullptr;
- if (ttc_size) {
- face = GetCachedTTCFace(hFont, 0x74746366, ttc_size, font_size);
- } else {
- ByteString SubstName;
- m_pFontInfo->GetFaceName(hFont, &SubstName);
- face = GetCachedFace(hFont, SubstName, weight, bItalic, font_size);
- }
- m_pFontInfo->DeleteFont(hFont);
- return face;
-}
-#endif // PDF_ENABLE_XFA
-
int CFX_FontMapper::GetFaceSize() const {
return pdfium::CollectionSize<int>(m_FaceArray);
}
diff --git a/core/fxge/cfx_fontmapper.h b/core/fxge/cfx_fontmapper.h
index 215eec97c2..15bd9f0279 100644
--- a/core/fxge/cfx_fontmapper.h
+++ b/core/fxge/cfx_fontmapper.h
@@ -34,12 +34,7 @@ class CFX_FontMapper {
int italic_angle,
int CharsetCP,
CFX_SubstFont* pSubstFont);
-#ifdef PDF_ENABLE_XFA
- FXFT_Face FindSubstFontByUnicode(uint32_t dwUnicode,
- uint32_t flags,
- int weight,
- int italic_angle);
-#endif // PDF_ENABLE_XFA
+
bool IsBuiltinFace(const FXFT_Face face) const;
int GetFaceSize() const;
ByteString GetFaceName(int index) const { return m_FaceArray[index].name; }
diff --git a/core/fxge/fx_font.h b/core/fxge/fx_font.h
index cee870f62a..3e0751dbe8 100644
--- a/core/fxge/fx_font.h
+++ b/core/fxge/fx_font.h
@@ -49,9 +49,6 @@ using CFX_TypeFace = SkTypeface;
/* Other font flags */
#define FXFONT_USEEXTERNATTR 0x80000
#define FXFONT_CIDFONT 0x100000
-#ifdef PDF_ENABLE_XFA
-#define FXFONT_EXACTMATCH 0x80000000
-#endif // PDF_ENABLE_XFA
#define GET_TT_SHORT(w) (uint16_t)(((w)[0] << 8) | (w)[1])
#define GET_TT_LONG(w) \
diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.cpp b/fpdfsdk/cpdfsdk_formfillenvironment.cpp
index 49a4a601d5..a0859a225a 100644
--- a/fpdfsdk/cpdfsdk_formfillenvironment.cpp
+++ b/fpdfsdk/cpdfsdk_formfillenvironment.cpp
@@ -719,11 +719,8 @@ CPDFXFA_Context* CPDFSDK_FormFillEnvironment::GetXFAContext() const {
#endif // PDF_ENABLE_XFA
int CPDFSDK_FormFillEnvironment::GetPageCount() const {
-#ifdef PDF_ENABLE_XFA
- return GetXFAContext()->GetPageCount();
-#else
- return m_pCPDFDoc->GetPageCount();
-#endif
+ CPDF_Document::Extension* pExtension = m_pCPDFDoc->GetExtension();
+ return pExtension ? pExtension->GetPageCount() : m_pCPDFDoc->GetPageCount();
}
bool CPDFSDK_FormFillEnvironment::GetPermissions(int nFlag) const {
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
index 84fcb37d16..3b10f0d51e 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
@@ -203,6 +203,11 @@ void CPDFXFA_Context::DeletePage(int page_index) {
m_XFAPageList[page_index].Reset();
}
+uint32_t CPDFXFA_Context::GetUserPermissions() const {
+ // See https://bugs.chromium.org/p/pdfium/issues/detail?id=499
+ return 0xFFFFFFFF;
+}
+
void CPDFXFA_Context::ClearChangeMark() {
if (m_pFormFillEnv)
m_pFormFillEnv->ClearChangeMark();
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_context.h b/fpdfsdk/fpdfxfa/cpdfxfa_context.h
index c7fe02d8fb..a01990cce4 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_context.h
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_context.h
@@ -62,6 +62,7 @@ class CPDFXFA_Context : public CPDF_Document::Extension,
CPDF_Document* GetPDFDoc() const override;
int GetPageCount() const override;
void DeletePage(int page_index) override;
+ uint32_t GetUserPermissions() const override;
// IFXA_AppProvider:
WideString GetLanguage() override;