summaryrefslogtreecommitdiff
path: root/xfa/fgas
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-04-18 16:35:55 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-04-18 20:50:08 +0000
commitbf510b7c520bccbd2edf5bb3e2f91b125ebfd6d7 (patch)
tree6ffafd1e5fcc767f5a4160d290e0b5f72d2ce271 /xfa/fgas
parentfdf7d4092a5fa9c79bbb4a626a4d3d087053ae2c (diff)
downloadpdfium-bf510b7c520bccbd2edf5bb3e2f91b125ebfd6d7.tar.xz
Rename IFGAS_Stream to CFGAS_Stream
This CL replaces IFGAS_Stream with the only implementation CFGAS_Stream. The CreateReadStream and CreateWriteStream methods are removed in favour of calling MakeRetain directly. Change-Id: I882a89258f642e24fc3d631587db05652bd53ded Reviewed-on: https://pdfium-review.googlesource.com/4210 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Nicolás Peña <npm@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'xfa/fgas')
-rw-r--r--xfa/fgas/crt/cfgas_stream.cpp (renamed from xfa/fgas/crt/ifgas_stream.cpp)105
-rw-r--r--xfa/fgas/crt/cfgas_stream.h54
-rw-r--r--xfa/fgas/crt/ifgas_stream.h44
-rw-r--r--xfa/fgas/font/cfgas_fontmgr.h2
-rw-r--r--xfa/fgas/font/cfgas_gefont.h4
5 files changed, 83 insertions, 126 deletions
diff --git a/xfa/fgas/crt/ifgas_stream.cpp b/xfa/fgas/crt/cfgas_stream.cpp
index 7a90626fe8..809c19bdae 100644
--- a/xfa/fgas/crt/ifgas_stream.cpp
+++ b/xfa/fgas/crt/cfgas_stream.cpp
@@ -4,7 +4,7 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-#include "xfa/fgas/crt/ifgas_stream.h"
+#include "xfa/fgas/crt/cfgas_stream.h"
#if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN32_MOBILE_ || \
_FX_OS_ == _FX_WIN64_
@@ -12,6 +12,7 @@
#endif
#include <algorithm>
+#include <limits>
#include <memory>
#include <utility>
#include <vector>
@@ -23,39 +24,6 @@
namespace {
-class CFGAS_Stream : public IFGAS_Stream {
- public:
- template <typename T, typename... Args>
- friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args);
-
- // IFGAS_Stream
- FX_FILESIZE GetLength() const override { return m_pStream->GetSize(); }
- FX_FILESIZE GetPosition() override { return m_iPosition; }
- FX_STRSIZE GetBOMLength() const override { return std::max(0, m_wBOMLength); }
- FX_STRSIZE ReadString(wchar_t* pStr,
- FX_STRSIZE iMaxLength,
- bool* bEOS) override;
- void Seek(FX_STREAMSEEK eSeek, FX_FILESIZE iOffset) override;
- bool IsEOF() const override { return m_iPosition >= GetLength(); }
- void WriteString(const CFX_WideStringC& str) override;
- uint16_t GetCodePage() const override { return m_wCodePage; }
- void SetCodePage(uint16_t wCodePage) override;
-
- private:
- CFGAS_Stream(const CFX_RetainPtr<IFX_SeekableStream>& stream,
- bool isWriteSteam);
- ~CFGAS_Stream() override;
-
- FX_STRSIZE ReadData(uint8_t* pBuffer, FX_STRSIZE iBufferSize);
- void WriteData(const CFX_WideStringC& str);
-
- uint16_t m_wCodePage;
- FX_STRSIZE m_wBOMLength;
- bool m_IsWriteStream;
- FX_FILESIZE m_iPosition;
- CFX_RetainPtr<IFX_SeekableStream> m_pStream;
-};
-
// Returns {src bytes consumed, dst bytes produced}.
std::pair<FX_STRSIZE, FX_STRSIZE> UTF8Decode(const char* pSrc,
FX_STRSIZE srcLen,
@@ -161,6 +129,8 @@ void SwapByteOrder(wchar_t* pStr, FX_STRSIZE iLength) {
}
}
+} // namespace
+
#if _FX_ENDIAN_ == _FX_LITTLE_ENDIAN_
#define BOM_MASK 0x00FFFFFF
#define BOM_UTF8 0x00BFBBEF
@@ -190,7 +160,7 @@ CFGAS_Stream::CFGAS_Stream(const CFX_RetainPtr<IFX_SeekableStream>& stream,
}
FX_FILESIZE iPosition = GetPosition();
- Seek(FX_STREAMSEEK_Begin, 0);
+ Seek(CFGAS_Stream::Pos::Begin, 0);
uint32_t bom;
ReadData(reinterpret_cast<uint8_t*>(&bom), 3);
@@ -213,18 +183,21 @@ CFGAS_Stream::CFGAS_Stream(const CFX_RetainPtr<IFX_SeekableStream>& stream,
}
}
- Seek(FX_STREAMSEEK_Begin,
+ Seek(CFGAS_Stream::Pos::Begin,
std::max(static_cast<FX_FILESIZE>(m_wBOMLength), iPosition));
}
+CFGAS_Stream::CFGAS_Stream(uint8_t* data, FX_STRSIZE size)
+ : CFGAS_Stream(IFX_MemoryStream::Create(data, size), false) {}
+
CFGAS_Stream::~CFGAS_Stream() {}
-void CFGAS_Stream::Seek(FX_STREAMSEEK eSeek, FX_FILESIZE iOffset) {
+void CFGAS_Stream::Seek(CFGAS_Stream::Pos eSeek, FX_FILESIZE iOffset) {
switch (eSeek) {
- case FX_STREAMSEEK_Begin:
+ case CFGAS_Stream::Pos::Begin:
m_iPosition = iOffset;
break;
- case FX_STREAMSEEK_Current:
+ case CFGAS_Stream::Pos::Current:
m_iPosition += iOffset;
break;
}
@@ -300,7 +273,7 @@ FX_STRSIZE CFGAS_Stream::ReadString(wchar_t* pStr,
FX_STRSIZE iSrc = 0;
std::tie(iSrc, iMaxLength) = UTF8Decode(
reinterpret_cast<const char*>(buf.data()), iLen, pStr, iMaxLength);
- Seek(FX_STREAMSEEK_Current, iSrc - iLen);
+ Seek(CFGAS_Stream::Pos::Current, iSrc - iLen);
} else {
iMaxLength = 0;
}
@@ -310,48 +283,22 @@ FX_STRSIZE CFGAS_Stream::ReadString(wchar_t* pStr,
return iMaxLength;
}
-void CFGAS_Stream::WriteData(const CFX_WideStringC& str) {
- if (!m_IsWriteStream || str.GetLength() == 0)
- return;
- if (m_pStream->WriteBlock(str.c_str(), m_iPosition,
- str.GetLength() * sizeof(wchar_t))) {
- pdfium::base::CheckedNumeric<FX_STRSIZE> new_pos = m_iPosition;
- new_pos += str.GetLength() * sizeof(wchar_t);
- // TODO(dsinclair): Not sure what to do if we over flow ....
- if (!new_pos.IsValid())
- return;
-
- m_iPosition = new_pos.ValueOrDie();
- }
-}
-
void CFGAS_Stream::WriteString(const CFX_WideStringC& str) {
- if (!m_IsWriteStream)
- return;
- if (str.GetLength() == 0)
+ if (!m_IsWriteStream || str.GetLength() == 0 ||
+ m_wCodePage != FX_CODEPAGE_UTF8) {
return;
- if (m_wCodePage != FX_CODEPAGE_UTF8)
+ }
+ if (!m_pStream->WriteBlock(str.c_str(), m_iPosition,
+ str.GetLength() * sizeof(wchar_t))) {
return;
+ }
- WriteData(str);
-}
-
-} // namespace
-
-// static
-CFX_RetainPtr<IFGAS_Stream> IFGAS_Stream::CreateReadStream(
- const CFX_RetainPtr<IFX_SeekableStream>& pFileRead) {
- if (!pFileRead)
- return nullptr;
-
- return pdfium::MakeRetain<CFGAS_Stream>(pFileRead, false);
-}
-
-// static
-CFX_RetainPtr<IFGAS_Stream> IFGAS_Stream::CreateWriteStream(
- const CFX_RetainPtr<IFX_SeekableStream>& pFileWrite) {
- if (!pFileWrite)
- return nullptr;
+ pdfium::base::CheckedNumeric<FX_STRSIZE> new_pos = m_iPosition;
+ new_pos += str.GetLength() * sizeof(wchar_t);
+ if (!new_pos.IsValid()) {
+ m_iPosition = std::numeric_limits<FX_STRSIZE>::max();
+ return;
+ }
- return pdfium::MakeRetain<CFGAS_Stream>(pFileWrite, true);
+ m_iPosition = new_pos.ValueOrDie();
}
diff --git a/xfa/fgas/crt/cfgas_stream.h b/xfa/fgas/crt/cfgas_stream.h
new file mode 100644
index 0000000000..5d2e5e6242
--- /dev/null
+++ b/xfa/fgas/crt/cfgas_stream.h
@@ -0,0 +1,54 @@
+// Copyright 2017 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef XFA_FGAS_CRT_CFGAS_STREAM_H_
+#define XFA_FGAS_CRT_CFGAS_STREAM_H_
+
+#include <algorithm>
+
+#include "core/fxcrt/cfx_retain_ptr.h"
+#include "core/fxcrt/fx_stream.h"
+#include "core/fxcrt/fx_system.h"
+
+class CFGAS_Stream : public CFX_Retainable {
+ public:
+ enum class Pos {
+ Begin = 0,
+ Current,
+ };
+
+ template <typename T, typename... Args>
+ friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args);
+
+ FX_FILESIZE GetLength() const { return m_pStream->GetSize(); }
+ FX_FILESIZE GetPosition() { return m_iPosition; }
+ FX_STRSIZE GetBOMLength() const { return std::max(0, m_wBOMLength); }
+ bool IsEOF() const { return m_iPosition >= GetLength(); }
+
+ void Seek(CFGAS_Stream::Pos eSeek, FX_FILESIZE iOffset);
+ FX_STRSIZE ReadString(wchar_t* pStr, FX_STRSIZE iMaxLength, bool* bEOS);
+
+ void WriteString(const CFX_WideStringC& str);
+
+ uint16_t GetCodePage() const { return m_wCodePage; }
+ void SetCodePage(uint16_t wCodePage);
+
+ private:
+ CFGAS_Stream(const CFX_RetainPtr<IFX_SeekableStream>& stream,
+ bool isWriteSteam);
+ CFGAS_Stream(uint8_t* data, FX_STRSIZE size);
+ ~CFGAS_Stream() override;
+
+ FX_STRSIZE ReadData(uint8_t* pBuffer, FX_STRSIZE iBufferSize);
+
+ uint16_t m_wCodePage;
+ FX_STRSIZE m_wBOMLength;
+ bool m_IsWriteStream;
+ FX_FILESIZE m_iPosition;
+ CFX_RetainPtr<IFX_SeekableStream> m_pStream;
+};
+
+#endif // XFA_FGAS_CRT_CFGAS_STREAM_H_
diff --git a/xfa/fgas/crt/ifgas_stream.h b/xfa/fgas/crt/ifgas_stream.h
deleted file mode 100644
index acc9f1c4eb..0000000000
--- a/xfa/fgas/crt/ifgas_stream.h
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef XFA_FGAS_CRT_IFGAS_STREAM_H_
-#define XFA_FGAS_CRT_IFGAS_STREAM_H_
-
-#include "core/fxcrt/cfx_retain_ptr.h"
-#include "core/fxcrt/fx_stream.h"
-#include "core/fxcrt/fx_system.h"
-
-enum FX_STREAMSEEK {
- FX_STREAMSEEK_Begin = 0,
- FX_STREAMSEEK_Current,
-};
-
-class IFGAS_Stream : public CFX_Retainable {
- public:
- static CFX_RetainPtr<IFGAS_Stream> CreateReadStream(
- const CFX_RetainPtr<IFX_SeekableStream>& pFileRead);
- static CFX_RetainPtr<IFGAS_Stream> CreateWriteStream(
- const CFX_RetainPtr<IFX_SeekableStream>& pFileWrite);
-
- virtual FX_FILESIZE GetLength() const = 0;
- virtual FX_FILESIZE GetPosition() = 0;
- virtual FX_STRSIZE GetBOMLength() const = 0;
-
- virtual void Seek(FX_STREAMSEEK eSeek, FX_FILESIZE iOffset) = 0;
-
- virtual FX_STRSIZE ReadString(wchar_t* pStr,
- FX_STRSIZE iMaxLength,
- bool* bEOS) = 0;
- virtual void WriteString(const CFX_WideStringC& str) = 0;
-
- virtual uint16_t GetCodePage() const = 0;
- virtual void SetCodePage(uint16_t wCodePage) = 0;
-
- protected:
- virtual bool IsEOF() const = 0;
-};
-
-#endif // XFA_FGAS_CRT_IFGAS_STREAM_H_
diff --git a/xfa/fgas/font/cfgas_fontmgr.h b/xfa/fgas/font/cfgas_fontmgr.h
index c0b59f4dd7..8a3705335e 100644
--- a/xfa/fgas/font/cfgas_fontmgr.h
+++ b/xfa/fgas/font/cfgas_fontmgr.h
@@ -18,7 +18,7 @@
#include "core/fxge/cfx_fontmapper.h"
#include "core/fxge/fx_freetype.h"
#include "core/fxge/ifx_systemfontinfo.h"
-#include "xfa/fgas/crt/ifgas_stream.h"
+#include "xfa/fgas/crt/cfgas_stream.h"
#define FX_FONTSTYLE_Normal 0x00
#define FX_FONTSTYLE_FixedPitch 0x01
diff --git a/xfa/fgas/font/cfgas_gefont.h b/xfa/fgas/font/cfgas_gefont.h
index 14029be1e0..6c9f2a168d 100644
--- a/xfa/fgas/font/cfgas_gefont.h
+++ b/xfa/fgas/font/cfgas_gefont.h
@@ -67,7 +67,7 @@ class CFGAS_GEFont : public CFX_Retainable {
uint32_t dwFontStyles,
uint16_t wCodePage);
bool LoadFontInternal(const uint8_t* pBuffer, int32_t length);
- bool LoadFontInternal(const CFX_RetainPtr<IFGAS_Stream>& pFontStream,
+ bool LoadFontInternal(const CFX_RetainPtr<CFGAS_Stream>& pFontStream,
bool bSaveStream);
#endif
bool LoadFontInternal(CFX_Font* pExternalFont);
@@ -95,7 +95,7 @@ class CFGAS_GEFont : public CFX_Retainable {
CFX_RetainPtr<CFGAS_GEFont> m_pSrcFont; // Only set by ctor, so no cycles.
CFGAS_FontMgr* const m_pFontMgr;
bool m_bExternalFont;
- CFX_RetainPtr<IFGAS_Stream> m_pStream;
+ CFX_RetainPtr<CFGAS_Stream> m_pStream;
CFX_RetainPtr<IFX_SeekableReadStream> m_pFileRead;
std::unique_ptr<CFX_UnicodeEncoding> m_pFontEncoding;
std::map<wchar_t, int32_t> m_CharWidthMap;