OLD | NEW |
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" | 7 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" |
8 | 8 |
9 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" | 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" |
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h" | 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h" |
11 #include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" | 11 #include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" |
12 | 12 |
13 CPDF_Stream::CPDF_Stream(uint8_t* pData, FX_DWORD size, CPDF_Dictionary* pDict) | 13 CPDF_Stream::CPDF_Stream(uint8_t* pData, uint32_t size, CPDF_Dictionary* pDict) |
14 : m_pDict(pDict), | 14 : m_pDict(pDict), |
15 m_dwSize(size), | 15 m_dwSize(size), |
16 m_GenNum(kMemoryBasedGenNum), | 16 m_GenNum(kMemoryBasedGenNum), |
17 m_pDataBuf(pData) {} | 17 m_pDataBuf(pData) {} |
18 | 18 |
19 CPDF_Stream::~CPDF_Stream() { | 19 CPDF_Stream::~CPDF_Stream() { |
20 if (IsMemoryBased()) | 20 if (IsMemoryBased()) |
21 FX_Free(m_pDataBuf); | 21 FX_Free(m_pDataBuf); |
22 | 22 |
23 if (m_pDict) | 23 if (m_pDict) |
(...skipping 27 matching lines...) Expand all Loading... |
51 m_pDict = pDict; | 51 m_pDict = pDict; |
52 } | 52 } |
53 if (IsMemoryBased()) | 53 if (IsMemoryBased()) |
54 FX_Free(m_pDataBuf); | 54 FX_Free(m_pDataBuf); |
55 | 55 |
56 m_GenNum = 0; | 56 m_GenNum = 0; |
57 m_pFile = nullptr; | 57 m_pFile = nullptr; |
58 } | 58 } |
59 | 59 |
60 void CPDF_Stream::InitStream(uint8_t* pData, | 60 void CPDF_Stream::InitStream(uint8_t* pData, |
61 FX_DWORD size, | 61 uint32_t size, |
62 CPDF_Dictionary* pDict) { | 62 CPDF_Dictionary* pDict) { |
63 InitStreamInternal(pDict); | 63 InitStreamInternal(pDict); |
64 m_GenNum = kMemoryBasedGenNum; | 64 m_GenNum = kMemoryBasedGenNum; |
65 m_pDataBuf = FX_Alloc(uint8_t, size); | 65 m_pDataBuf = FX_Alloc(uint8_t, size); |
66 if (pData) | 66 if (pData) |
67 FXSYS_memcpy(m_pDataBuf, pData, size); | 67 FXSYS_memcpy(m_pDataBuf, pData, size); |
68 | 68 |
69 m_dwSize = size; | 69 m_dwSize = size; |
70 if (m_pDict) | 70 if (m_pDict) |
71 m_pDict->SetAtInteger("Length", size); | 71 m_pDict->SetAtInteger("Length", size); |
72 } | 72 } |
73 | 73 |
74 CPDF_Object* CPDF_Stream::Clone(FX_BOOL bDirect) const { | 74 CPDF_Object* CPDF_Stream::Clone(FX_BOOL bDirect) const { |
75 CPDF_StreamAcc acc; | 75 CPDF_StreamAcc acc; |
76 acc.LoadAllData(this, TRUE); | 76 acc.LoadAllData(this, TRUE); |
77 FX_DWORD streamSize = acc.GetSize(); | 77 uint32_t streamSize = acc.GetSize(); |
78 CPDF_Dictionary* pDict = GetDict(); | 78 CPDF_Dictionary* pDict = GetDict(); |
79 if (pDict) | 79 if (pDict) |
80 pDict = ToDictionary(pDict->Clone(bDirect)); | 80 pDict = ToDictionary(pDict->Clone(bDirect)); |
81 | 81 |
82 return new CPDF_Stream(acc.DetachData(), streamSize, pDict); | 82 return new CPDF_Stream(acc.DetachData(), streamSize, pDict); |
83 } | 83 } |
84 | 84 |
85 void CPDF_Stream::SetData(const uint8_t* pData, | 85 void CPDF_Stream::SetData(const uint8_t* pData, |
86 FX_DWORD size, | 86 uint32_t size, |
87 FX_BOOL bCompressed, | 87 FX_BOOL bCompressed, |
88 FX_BOOL bKeepBuf) { | 88 FX_BOOL bKeepBuf) { |
89 if (IsMemoryBased()) | 89 if (IsMemoryBased()) |
90 FX_Free(m_pDataBuf); | 90 FX_Free(m_pDataBuf); |
91 m_GenNum = kMemoryBasedGenNum; | 91 m_GenNum = kMemoryBasedGenNum; |
92 | 92 |
93 if (bKeepBuf) { | 93 if (bKeepBuf) { |
94 m_pDataBuf = const_cast<uint8_t*>(pData); | 94 m_pDataBuf = const_cast<uint8_t*>(pData); |
95 } else { | 95 } else { |
96 m_pDataBuf = FX_Alloc(uint8_t, size); | 96 m_pDataBuf = FX_Alloc(uint8_t, size); |
97 if (pData) { | 97 if (pData) { |
98 FXSYS_memcpy(m_pDataBuf, pData, size); | 98 FXSYS_memcpy(m_pDataBuf, pData, size); |
99 } | 99 } |
100 } | 100 } |
101 m_dwSize = size; | 101 m_dwSize = size; |
102 if (!m_pDict) | 102 if (!m_pDict) |
103 m_pDict = new CPDF_Dictionary; | 103 m_pDict = new CPDF_Dictionary; |
104 m_pDict->SetAtInteger("Length", size); | 104 m_pDict->SetAtInteger("Length", size); |
105 if (!bCompressed) { | 105 if (!bCompressed) { |
106 m_pDict->RemoveAt("Filter"); | 106 m_pDict->RemoveAt("Filter"); |
107 m_pDict->RemoveAt("DecodeParms"); | 107 m_pDict->RemoveAt("DecodeParms"); |
108 } | 108 } |
109 } | 109 } |
110 | 110 |
111 FX_BOOL CPDF_Stream::ReadRawData(FX_FILESIZE offset, | 111 FX_BOOL CPDF_Stream::ReadRawData(FX_FILESIZE offset, |
112 uint8_t* buf, | 112 uint8_t* buf, |
113 FX_DWORD size) const { | 113 uint32_t size) const { |
114 if (!IsMemoryBased() && m_pFile) | 114 if (!IsMemoryBased() && m_pFile) |
115 return m_pFile->ReadBlock(buf, offset, size); | 115 return m_pFile->ReadBlock(buf, offset, size); |
116 | 116 |
117 if (m_pDataBuf) | 117 if (m_pDataBuf) |
118 FXSYS_memcpy(buf, m_pDataBuf + offset, size); | 118 FXSYS_memcpy(buf, m_pDataBuf + offset, size); |
119 | 119 |
120 return TRUE; | 120 return TRUE; |
121 } | 121 } |
122 | 122 |
123 void CPDF_Stream::InitStreamFromFile(IFX_FileRead* pFile, | 123 void CPDF_Stream::InitStreamFromFile(IFX_FileRead* pFile, |
124 CPDF_Dictionary* pDict) { | 124 CPDF_Dictionary* pDict) { |
125 InitStreamInternal(pDict); | 125 InitStreamInternal(pDict); |
126 m_pFile = pFile; | 126 m_pFile = pFile; |
127 m_dwSize = (FX_DWORD)pFile->GetSize(); | 127 m_dwSize = (uint32_t)pFile->GetSize(); |
128 if (m_pDict) | 128 if (m_pDict) |
129 m_pDict->SetAtInteger("Length", m_dwSize); | 129 m_pDict->SetAtInteger("Length", m_dwSize); |
130 } | 130 } |
131 | 131 |
132 CFX_WideString CPDF_Stream::GetUnicodeText() const { | 132 CFX_WideString CPDF_Stream::GetUnicodeText() const { |
133 CPDF_StreamAcc stream; | 133 CPDF_StreamAcc stream; |
134 stream.LoadAllData(this, FALSE); | 134 stream.LoadAllData(this, FALSE); |
135 return PDF_DecodeText(stream.GetData(), stream.GetSize()); | 135 return PDF_DecodeText(stream.GetData(), stream.GetSize()); |
136 } | 136 } |
137 | 137 |
OLD | NEW |