7#include "core/fpdfapi/parser/fpdf_parser_utility.h"
12#include "core/fpdfapi/parser/cpdf_array.h"
13#include "core/fpdfapi/parser/cpdf_boolean.h"
14#include "core/fpdfapi/parser/cpdf_dictionary.h"
15#include "core/fpdfapi/parser/cpdf_number.h"
16#include "core/fpdfapi/parser/cpdf_reference.h"
17#include "core/fpdfapi/parser/cpdf_stream.h"
18#include "core/fpdfapi/parser/cpdf_stream_acc.h"
19#include "core/fpdfapi/parser/cpdf_string.h"
20#include "core/fpdfapi/parser/fpdf_parser_decode.h"
21#include "core/fxcrt/fx_extension.h"
22#include "core/fxcrt/fx_stream.h"
23#include "core/fxcrt/span_util.h"
24#include "third_party/base/check.h"
34 'W',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'W',
'W',
'R',
'W',
'W',
'R',
39 'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
44 'W',
'R',
'R',
'R',
'R',
'D',
'R',
'R',
'D',
'D',
'R',
'N',
'R',
'N',
'N',
48 'N',
'N',
'N',
'N',
'N',
'N',
'N',
'N',
'N',
'N',
'R',
'R',
'D',
'R',
'D',
52 'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
56 'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'D',
'R',
'D',
'R',
60 'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
65 'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'D',
'R',
'D',
'R',
68 'W',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
69 'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
70 'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
71 'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
72 'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
73 'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
74 'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
75 'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
76 'R',
'R',
'R',
'R',
'R',
'R',
'R',
'W'};
80 static constexpr size_t kBufSize = 4;
81 uint8_t buf[kBufSize];
82 for (
FX_FILESIZE offset = 0; offset <= 1024; ++offset) {
83 if (!pFile->ReadBlockAtOffset(buf, offset))
86 if (memcmp(buf,
"%PDF", 4) == 0)
93 size_t src_size = orig.GetLength();
98 pdfium::span<
char> pDest = result.GetBuffer(src_size);
99 for (size_t i = 0; i < src_size; i++) {
100 if (orig[i] ==
'#' && i + 2 < src_size) {
101 pDest[out_index++] = FXSYS_HexCharToInt(orig[i + 1]) * 16 +
102 FXSYS_HexCharToInt(orig[i + 2]);
105 pDest[out_index++] = orig[i];
109 result.ReleaseBuffer(out_index);
114 const uint8_t* src_buf =
reinterpret_cast<
const uint8_t*>(orig
.c_str());
115 int src_len = orig.GetLength();
118 for (i = 0; i < src_len; i++) {
119 uint8_t ch = src_buf[i];
127 if (dest_len == src_len)
133 pdfium::span<
char> dest_buf = res.GetBuffer(dest_len);
135 for (i = 0; i < src_len; i++) {
136 uint8_t ch = src_buf[i];
139 dest_buf[dest_len++] =
'#';
140 FXSYS_IntToTwoHexChars(ch, &dest_buf[dest_len]);
144 dest_buf[dest_len++] = ch;
147 res.ReleaseBuffer(dest_len);
154 DCHECK(pArray->size() >= nCount);
155 std::vector<
float> ret(nCount);
156 for (size_t i = 0; i < nCount; ++i)
157 ret[i] = pArray->GetFloatAt(i);
162 DCHECK(!type.IsEmpty());
167 ByteStringView type) {
172 for (
const auto& it : locker) {
173 RetainPtr<
const CPDF_Dictionary> entry =
174 ToDictionary(it.second->GetDirect());
175 if (!ValidateDictType(entry.Get(), type))
182 return ValidateDictAllResourcesOfType(dict,
"Font");
186 ByteStringView type) {
187 DCHECK(!type.IsEmpty());
219 for (size_t i = 0; i < p->size(); i++) {
221 if (!pElement->IsInline()) {
222 buf <<
" " << pElement->GetObjNum() <<
" 0 R";
224 buf << pElement.Get();
233 for (
const auto& it : locker) {
234 const ByteString& key = it.first;
235 const RetainPtr<CPDF_Object>& pValue = it.second;
236 buf <<
"/" << PDF_NameEncode(key);
237 if (!pValue->IsInline()) {
238 buf <<
" " << pValue->GetObjNum() <<
" 0 R ";
247 RetainPtr<
const CPDF_Stream> p(pObj->AsStream());
248 buf << p->GetDict().Get() <<
"stream\r\n";
249 auto pAcc = pdfium::MakeRetain<CPDF_StreamAcc>(
std::move(p));
250 pAcc->LoadAllDataRaw();
251 auto span =
fxcrt::reinterpret_span<
const char>(pAcc->GetSpan());
252 buf.write(span.data(), span.size());
253 buf <<
"\r\nendstream";
CPDF_DictionaryLocker(const CPDF_Dictionary *pDictionary)
bool KeyExist(const ByteString &key) const
ByteString GetNameFor(const ByteString &key) const
virtual Type GetType() const =0
virtual ByteString GetString() const
const CPDF_Array * AsArray() const
const CPDF_Dictionary * AsDictionary() const
const CPDF_String * AsString() const
const CPDF_Reference * AsReference() const
uint32_t GetRefObjNum() const
ByteString EncodeString() const
const char * c_str() const
bool PDFCharIsWhitespace(uint8_t c)
bool ValidateDictOptionalType(const CPDF_Dictionary *dict, ByteStringView type)
ByteString PDF_NameDecode(ByteStringView orig)
const char kPDFCharTypes[256]
ByteString PDF_NameEncode(const ByteString &orig)
bool ValidateFontResourceDict(const CPDF_Dictionary *dict)
absl::optional< FX_FILESIZE > GetHeaderOffset(const RetainPtr< IFX_SeekableReadStream > &pFile)
bool ValidateDictType(const CPDF_Dictionary *dict, ByteStringView type)
std::vector< float > ReadArrayElementsToVector(const CPDF_Array *pArray, size_t nCount)
bool ValidateDictAllResourcesOfType(const CPDF_Dictionary *dict, ByteStringView type)
bool PDFCharIsDelimiter(uint8_t c)