summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/fxcrt/extension.h80
-rw-r--r--core/fxcrt/fx_extension.cpp166
-rw-r--r--fpdfsdk/fpdfeditimg.cpp2
-rw-r--r--fpdfsdk/fpdfview.cpp68
-rw-r--r--fpdfsdk/fsdk_define.h16
5 files changed, 170 insertions, 162 deletions
diff --git a/core/fxcrt/extension.h b/core/fxcrt/extension.h
index ca2fc3c5b7..b62f67772b 100644
--- a/core/fxcrt/extension.h
+++ b/core/fxcrt/extension.h
@@ -34,86 +34,6 @@ class IFXCRT_FileAccess {
virtual bool Truncate(FX_FILESIZE szFile) = 0;
};
-#ifdef PDF_ENABLE_XFA
-class CFX_CRTFileAccess : public IFX_FileAccess {
- public:
- CFX_CRTFileAccess();
- ~CFX_CRTFileAccess() override;
-
- // IFX_FileAccess
- void Release() override;
- IFX_FileAccess* Retain() override;
- void GetPath(CFX_WideString& wsPath) override;
- IFX_SeekableStream* CreateFileStream(uint32_t dwModes) override;
-
- bool Init(const CFX_WideStringC& wsPath);
-
- protected:
- CFX_WideString m_path;
- uint32_t m_RefCount;
-};
-#endif // PDF_ENABLE_XFA
-
-class CFX_CRTFileStream final : public IFX_SeekableStream {
- public:
- explicit CFX_CRTFileStream(std::unique_ptr<IFXCRT_FileAccess> pFA);
- ~CFX_CRTFileStream() override;
-
- // IFX_SeekableStream:
- IFX_SeekableStream* Retain() override;
- void Release() override;
- FX_FILESIZE GetSize() override;
- bool IsEOF() override;
- FX_FILESIZE GetPosition() override;
- bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override;
- size_t ReadBlock(void* buffer, size_t size) override;
- bool WriteBlock(const void* buffer, FX_FILESIZE offset, size_t size) override;
- bool Flush() override;
-
- protected:
- std::unique_ptr<IFXCRT_FileAccess> m_pFile;
- uint32_t m_dwCount;
-};
-
-#define FX_MEMSTREAM_BlockSize (64 * 1024)
-#define FX_MEMSTREAM_Consecutive 0x01
-#define FX_MEMSTREAM_TakeOver 0x02
-
-class CFX_MemoryStream final : public IFX_MemoryStream {
- public:
- explicit CFX_MemoryStream(bool bConsecutive);
- CFX_MemoryStream(uint8_t* pBuffer, size_t nSize, bool bTakeOver);
- ~CFX_MemoryStream() override;
-
- // IFX_MemoryStream
- IFX_SeekableStream* Retain() override;
- void Release() override;
- FX_FILESIZE GetSize() override;
- bool IsEOF() override;
- FX_FILESIZE GetPosition() override;
- bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override;
- size_t ReadBlock(void* buffer, size_t size) override;
- bool WriteBlock(const void* buffer, FX_FILESIZE offset, size_t size) override;
- bool Flush() override;
- bool IsConsecutive() const override;
- void EstimateSize(size_t nInitSize, size_t nGrowSize) override;
- uint8_t* GetBuffer() const override;
- void AttachBuffer(uint8_t* pBuffer,
- size_t nSize,
- bool bTakeOver = false) override;
- void DetachBuffer() override;
-
- protected:
- CFX_ArrayTemplate<uint8_t*> m_Blocks;
- uint32_t m_dwCount;
- size_t m_nTotalSize;
- size_t m_nCurSize;
- size_t m_nCurPos;
- size_t m_nGrowSize;
- uint32_t m_dwFlags;
- bool ExpandBlocks(size_t size);
-};
-
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/core/fxcrt/fx_extension.cpp b/core/fxcrt/fx_extension.cpp
index 6bf61f1fb5..aa3841e31c 100644
--- a/core/fxcrt/fx_extension.cpp
+++ b/core/fxcrt/fx_extension.cpp
@@ -19,8 +19,28 @@
#include <ctime>
#endif
+namespace {
+
#ifdef PDF_ENABLE_XFA
+class CFX_CRTFileAccess : public IFX_FileAccess {
+ public:
+ CFX_CRTFileAccess();
+ ~CFX_CRTFileAccess() override;
+
+ // IFX_FileAccess
+ void Release() override;
+ IFX_FileAccess* Retain() override;
+ void GetPath(CFX_WideString& wsPath) override;
+ IFX_SeekableStream* CreateFileStream(uint32_t dwModes) override;
+
+ bool Init(const CFX_WideStringC& wsPath);
+
+ private:
+ CFX_WideString m_path;
+ uint32_t m_RefCount;
+};
+
CFX_CRTFileAccess::CFX_CRTFileAccess() : m_RefCount(0) {}
CFX_CRTFileAccess::~CFX_CRTFileAccess() {}
@@ -51,10 +71,112 @@ bool CFX_CRTFileAccess::Init(const CFX_WideStringC& wsPath) {
#endif // PDF_ENABLE_XFA
+class CFX_CRTFileStream final : public IFX_SeekableStream {
+ public:
+ explicit CFX_CRTFileStream(std::unique_ptr<IFXCRT_FileAccess> pFA);
+ ~CFX_CRTFileStream() override;
+
+ // IFX_SeekableStream:
+ IFX_SeekableStream* Retain() override;
+ void Release() override;
+ FX_FILESIZE GetSize() override;
+ bool IsEOF() override;
+ FX_FILESIZE GetPosition() override;
+ bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override;
+ size_t ReadBlock(void* buffer, size_t size) override;
+ bool WriteBlock(const void* buffer, FX_FILESIZE offset, size_t size) override;
+ bool Flush() override;
+
+ private:
+ std::unique_ptr<IFXCRT_FileAccess> m_pFile;
+ uint32_t m_dwCount;
+};
+
CFX_CRTFileStream::CFX_CRTFileStream(std::unique_ptr<IFXCRT_FileAccess> pFA)
: m_pFile(std::move(pFA)), m_dwCount(1) {}
CFX_CRTFileStream::~CFX_CRTFileStream() {}
+IFX_SeekableStream* CFX_CRTFileStream::Retain() {
+ m_dwCount++;
+ return this;
+}
+
+void CFX_CRTFileStream::Release() {
+ uint32_t nCount = --m_dwCount;
+ if (!nCount)
+ delete this;
+}
+
+FX_FILESIZE CFX_CRTFileStream::GetSize() {
+ return m_pFile->GetSize();
+}
+
+bool CFX_CRTFileStream::IsEOF() {
+ return GetPosition() >= GetSize();
+}
+
+FX_FILESIZE CFX_CRTFileStream::GetPosition() {
+ return m_pFile->GetPosition();
+}
+
+bool CFX_CRTFileStream::ReadBlock(void* buffer,
+ FX_FILESIZE offset,
+ size_t size) {
+ return m_pFile->ReadPos(buffer, size, offset) > 0;
+}
+
+size_t CFX_CRTFileStream::ReadBlock(void* buffer, size_t size) {
+ return m_pFile->Read(buffer, size);
+}
+
+bool CFX_CRTFileStream::WriteBlock(const void* buffer,
+ FX_FILESIZE offset,
+ size_t size) {
+ return !!m_pFile->WritePos(buffer, size, offset);
+}
+
+bool CFX_CRTFileStream::Flush() {
+ return m_pFile->Flush();
+}
+
+#define FX_MEMSTREAM_BlockSize (64 * 1024)
+#define FX_MEMSTREAM_Consecutive 0x01
+#define FX_MEMSTREAM_TakeOver 0x02
+
+class CFX_MemoryStream final : public IFX_MemoryStream {
+ public:
+ explicit CFX_MemoryStream(bool bConsecutive);
+ CFX_MemoryStream(uint8_t* pBuffer, size_t nSize, bool bTakeOver);
+ ~CFX_MemoryStream() override;
+
+ // IFX_MemoryStream
+ IFX_SeekableStream* Retain() override;
+ void Release() override;
+ FX_FILESIZE GetSize() override;
+ bool IsEOF() override;
+ FX_FILESIZE GetPosition() override;
+ bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override;
+ size_t ReadBlock(void* buffer, size_t size) override;
+ bool WriteBlock(const void* buffer, FX_FILESIZE offset, size_t size) override;
+ bool Flush() override;
+ bool IsConsecutive() const override;
+ void EstimateSize(size_t nInitSize, size_t nGrowSize) override;
+ uint8_t* GetBuffer() const override;
+ void AttachBuffer(uint8_t* pBuffer,
+ size_t nSize,
+ bool bTakeOver = false) override;
+ void DetachBuffer() override;
+
+ private:
+ CFX_ArrayTemplate<uint8_t*> m_Blocks;
+ uint32_t m_dwCount;
+ size_t m_nTotalSize;
+ size_t m_nCurSize;
+ size_t m_nCurPos;
+ size_t m_nGrowSize;
+ uint32_t m_dwFlags;
+ bool ExpandBlocks(size_t size);
+};
CFX_MemoryStream::CFX_MemoryStream(bool bConsecutive)
: m_dwCount(1),
@@ -283,49 +405,7 @@ bool CFX_MemoryStream::ExpandBlocks(size_t size) {
return true;
}
-IFX_SeekableStream* CFX_CRTFileStream::Retain() {
- m_dwCount++;
- return this;
-}
-
-void CFX_CRTFileStream::Release() {
- uint32_t nCount = --m_dwCount;
- if (!nCount) {
- delete this;
- }
-}
-
-FX_FILESIZE CFX_CRTFileStream::GetSize() {
- return m_pFile->GetSize();
-}
-
-bool CFX_CRTFileStream::IsEOF() {
- return GetPosition() >= GetSize();
-}
-
-FX_FILESIZE CFX_CRTFileStream::GetPosition() {
- return m_pFile->GetPosition();
-}
-
-bool CFX_CRTFileStream::ReadBlock(void* buffer,
- FX_FILESIZE offset,
- size_t size) {
- return m_pFile->ReadPos(buffer, size, offset) > 0;
-}
-
-size_t CFX_CRTFileStream::ReadBlock(void* buffer, size_t size) {
- return m_pFile->Read(buffer, size);
-}
-
-bool CFX_CRTFileStream::WriteBlock(const void* buffer,
- FX_FILESIZE offset,
- size_t size) {
- return !!m_pFile->WritePos(buffer, size, offset);
-}
-
-bool CFX_CRTFileStream::Flush() {
- return m_pFile->Flush();
-}
+} // namespace
#ifdef PDF_ENABLE_XFA
IFX_FileAccess* FX_CreateDefaultFileAccess(const CFX_WideStringC& wsPath) {
diff --git a/fpdfsdk/fpdfeditimg.cpp b/fpdfsdk/fpdfeditimg.cpp
index da9f2b3909..2c869ac624 100644
--- a/fpdfsdk/fpdfeditimg.cpp
+++ b/fpdfsdk/fpdfeditimg.cpp
@@ -32,7 +32,7 @@ FPDFImageObj_LoadJpegFile(FPDF_PAGE* pages,
if (!image_object || !fileAccess || !pages)
return false;
- IFX_SeekableReadStream* pFile = new CPDF_CustomAccess(fileAccess);
+ IFX_SeekableReadStream* pFile = MakeSeekableReadStream(fileAccess);
CPDF_ImageObject* pImgObj = reinterpret_cast<CPDF_ImageObject*>(image_object);
for (int index = 0; index < nCount; index++) {
CPDF_Page* pPage = CPDFPageFromFPDFPage(pages[index]);
diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp
index 633cbe879e..449433ed90 100644
--- a/fpdfsdk/fpdfview.cpp
+++ b/fpdfsdk/fpdfview.cpp
@@ -117,6 +117,47 @@ void RenderPageImpl(CPDF_PageRenderContext* pContext,
pContext->m_pDevice->RestoreState(false);
}
+class CPDF_CustomAccess final : public IFX_SeekableReadStream {
+ public:
+ explicit CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess);
+ ~CPDF_CustomAccess() override {}
+
+ // IFX_SeekableReadStream
+ FX_FILESIZE GetSize() override;
+ void Release() override;
+ bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override;
+
+ private:
+ FPDF_FILEACCESS m_FileAccess;
+};
+
+CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess)
+ : m_FileAccess(*pFileAccess) {}
+
+FX_FILESIZE CPDF_CustomAccess::GetSize() {
+ return m_FileAccess.m_FileLen;
+}
+
+void CPDF_CustomAccess::Release() {
+ delete this;
+}
+
+bool CPDF_CustomAccess::ReadBlock(void* buffer,
+ FX_FILESIZE offset,
+ size_t size) {
+ if (offset < 0)
+ return false;
+
+ FX_SAFE_FILESIZE newPos = pdfium::base::checked_cast<FX_FILESIZE>(size);
+ newPos += offset;
+ if (!newPos.IsValid() ||
+ newPos.ValueOrDie() > static_cast<FX_FILESIZE>(m_FileAccess.m_FileLen)) {
+ return false;
+ }
+ return !!m_FileAccess.m_GetBlock(m_FileAccess.m_Param, offset,
+ reinterpret_cast<uint8_t*>(buffer), size);
+}
+
} // namespace
UnderlyingDocumentType* UnderlyingFromFPDFDocument(FPDF_DOCUMENT doc) {
@@ -246,31 +287,8 @@ bool CFPDF_FileStream::Flush() {
}
#endif // PDF_ENABLE_XFA
-CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess)
- : m_FileAccess(*pFileAccess) {}
-
-FX_FILESIZE CPDF_CustomAccess::GetSize() {
- return m_FileAccess.m_FileLen;
-}
-
-void CPDF_CustomAccess::Release() {
- delete this;
-}
-
-bool CPDF_CustomAccess::ReadBlock(void* buffer,
- FX_FILESIZE offset,
- size_t size) {
- if (offset < 0)
- return false;
-
- FX_SAFE_FILESIZE newPos = pdfium::base::checked_cast<FX_FILESIZE>(size);
- newPos += offset;
- if (!newPos.IsValid() ||
- newPos.ValueOrDie() > static_cast<FX_FILESIZE>(m_FileAccess.m_FileLen)) {
- return false;
- }
- return !!m_FileAccess.m_GetBlock(m_FileAccess.m_Param, offset,
- reinterpret_cast<uint8_t*>(buffer), size);
+IFX_SeekableReadStream* MakeSeekableReadStream(FPDF_FILEACCESS* pFileAccess) {
+ return new CPDF_CustomAccess(pFileAccess);
}
// 0 bit: FPDF_POLICY_MACHINETIME_ACCESS
diff --git a/fpdfsdk/fsdk_define.h b/fpdfsdk/fsdk_define.h
index 3a75c84500..d878e54963 100644
--- a/fpdfsdk/fsdk_define.h
+++ b/fpdfsdk/fsdk_define.h
@@ -25,19 +25,9 @@ class CPDF_Page;
class CPDF_PageRenderContext;
class IFSDK_PAUSE_Adapter;
-class CPDF_CustomAccess final : public IFX_SeekableReadStream {
- public:
- explicit CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess);
- ~CPDF_CustomAccess() override {}
-
- // IFX_SeekableReadStream
- FX_FILESIZE GetSize() override;
- void Release() override;
- bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override;
-
- private:
- FPDF_FILEACCESS m_FileAccess;
-};
+// Layering prevents fxcrt from knowing about FPDF_FILEACCESS, so this can't
+// be a static method of IFX_SeekableReadStream.
+IFX_SeekableReadStream* MakeSeekableReadStream(FPDF_FILEACCESS* pFileAccess);
#ifdef PDF_ENABLE_XFA
class CFPDF_FileStream : public IFX_SeekableStream {