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/check.h"
22#include "core/fxcrt/fx_extension.h"
23#include "core/fxcrt/fx_stream.h"
33 'W',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'W',
'W',
'R',
'W',
'W',
'R',
38 'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
43 'W',
'R',
'R',
'R',
'R',
'D',
'R',
'R',
'D',
'D',
'R',
'N',
'R',
'N',
'N',
47 'N',
'N',
'N',
'N',
'N',
'N',
'N',
'N',
'N',
'N',
'R',
'R',
'D',
'R',
'D',
51 'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
55 'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'D',
'R',
'D',
'R',
59 'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
64 'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'D',
'R',
'D',
'R',
67 'W',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
'R',
68 'R',
'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',
'W'};
79 static constexpr size_t kBufSize = 4;
80 uint8_t buf[kBufSize];
81 for (
FX_FILESIZE offset = 0; offset <= 1024; ++offset) {
82 if (!pFile->ReadBlockAtOffset(buf, offset))
85 if (memcmp(buf,
"%PDF", 4) == 0)
92 size_t src_size = orig.GetLength();
97 pdfium::span<
char> pDest = result.GetBuffer(src_size);
98 for (size_t i = 0; i < src_size; i++) {
99 if (orig[i] ==
'#' && i + 2 < src_size) {
100 pDest[out_index++] = FXSYS_HexCharToInt(orig[i + 1]) * 16 +
101 FXSYS_HexCharToInt(orig[i + 2]);
104 pDest[out_index++] = orig[i];
108 result.ReleaseBuffer(out_index);
113 pdfium::span<
const uint8_t> src_span = orig.unsigned_span();
115 for (
const auto ch : src_span) {
116 if (ch >= 0x80 || PDFCharIsWhitespace(ch) || ch ==
'#' ||
117 PDFCharIsDelimiter(ch)) {
123 if (dest_len == src_span.size()) {
129 pdfium::span<
char> dest_buf = res.GetBuffer(dest_len);
131 for (
const auto ch : src_span) {
132 if (ch >= 0x80 || PDFCharIsWhitespace(ch) || ch ==
'#' ||
133 PDFCharIsDelimiter(ch)) {
134 dest_buf[dest_len++] =
'#';
135 FXSYS_IntToTwoHexChars(ch, &dest_buf[dest_len]);
139 dest_buf[dest_len++] = ch;
142 res.ReleaseBuffer(dest_len);
149 DCHECK(pArray->size() >= nCount);
150 std::vector<
float> ret(nCount);
151 for (size_t i = 0; i < nCount; ++i)
152 ret[i] = pArray->GetFloatAt(i);
167 for (
const auto& it : locker) {
168 RetainPtr<
const CPDF_Dictionary> entry =
169 ToDictionary(it.second->GetDirect());
170 if (!ValidateDictType(entry.Get(), type))
177 return ValidateDictAllResourcesOfType(dict,
"Font");
214 for (size_t i = 0; i < p->size(); i++) {
216 if (!pElement->IsInline()) {
217 buf <<
" " << pElement->GetObjNum() <<
" 0 R";
219 buf << pElement.Get();
228 for (
const auto& it : locker) {
229 const ByteString& key = it.first;
230 const RetainPtr<CPDF_Object>& pValue = it.second;
231 buf <<
"/" << PDF_NameEncode(key);
232 if (!pValue->IsInline()) {
233 buf <<
" " << pValue->GetObjNum() <<
" 0 R ";
242 RetainPtr<
const CPDF_Stream> p(pObj->AsStream());
243 buf << p->GetDict().Get() <<
"stream\r\n";
244 auto pAcc =
pdfium::MakeRetain<CPDF_StreamAcc>(
std::move(p));
245 pAcc->LoadAllDataRaw();
246 auto span =
pdfium::as_chars(pAcc->GetSpan());
247 buf.write(span.data(), span.size());
248 buf <<
"\r\nendstream";
fxcrt::ByteString ByteString
std::vector< RetainPtr< CPDF_Object > >::const_iterator const_iterator
CPDF_DictionaryLocker(const CPDF_Dictionary *pDictionary)
bool KeyExist(const ByteString &key) const
std::map< ByteString, RetainPtr< CPDF_Object >, std::less<> > DictMap
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
bool ValidateDictOptionalType(const CPDF_Dictionary *dict, ByteStringView type)
std::optional< FX_FILESIZE > GetHeaderOffset(const RetainPtr< IFX_SeekableReadStream > &pFile)
ByteString PDF_NameDecode(ByteStringView orig)
const char kPDFCharTypes[256]
ByteString PDF_NameEncode(const ByteString &orig)
bool ValidateFontResourceDict(const CPDF_Dictionary *dict)
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)
fxcrt::ByteStringView ByteStringView