Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cpdf_streamcontentparser.cpp
Go to the documentation of this file.
1// Copyright 2016 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#include "core/fpdfapi/page/cpdf_streamcontentparser.h"
8
9#include <algorithm>
10#include <map>
11#include <memory>
12#include <utility>
13#include <vector>
14
15#include "core/fpdfapi/font/cpdf_font.h"
16#include "core/fpdfapi/font/cpdf_type3font.h"
17#include "core/fpdfapi/page/cpdf_allstates.h"
18#include "core/fpdfapi/page/cpdf_docpagedata.h"
19#include "core/fpdfapi/page/cpdf_form.h"
20#include "core/fpdfapi/page/cpdf_formobject.h"
21#include "core/fpdfapi/page/cpdf_image.h"
22#include "core/fpdfapi/page/cpdf_imageobject.h"
23#include "core/fpdfapi/page/cpdf_meshstream.h"
24#include "core/fpdfapi/page/cpdf_pageobject.h"
25#include "core/fpdfapi/page/cpdf_pathobject.h"
26#include "core/fpdfapi/page/cpdf_shadingobject.h"
27#include "core/fpdfapi/page/cpdf_shadingpattern.h"
28#include "core/fpdfapi/page/cpdf_streamparser.h"
29#include "core/fpdfapi/page/cpdf_textobject.h"
30#include "core/fpdfapi/parser/cpdf_array.h"
31#include "core/fpdfapi/parser/cpdf_dictionary.h"
32#include "core/fpdfapi/parser/cpdf_document.h"
33#include "core/fpdfapi/parser/cpdf_name.h"
34#include "core/fpdfapi/parser/cpdf_number.h"
35#include "core/fpdfapi/parser/cpdf_reference.h"
36#include "core/fpdfapi/parser/cpdf_stream.h"
37#include "core/fpdfapi/parser/fpdf_parser_utility.h"
38#include "core/fxcrt/autonuller.h"
39#include "core/fxcrt/bytestring.h"
40#include "core/fxcrt/fx_safe_types.h"
41#include "core/fxcrt/scoped_set_insertion.h"
42#include "core/fxcrt/stl_util.h"
43#include "core/fxge/cfx_graphstate.h"
44#include "core/fxge/cfx_graphstatedata.h"
45#include "third_party/base/check.h"
46#include "third_party/base/containers/contains.h"
47#include "third_party/base/containers/span.h"
48#include "third_party/base/notreached.h"
49
50namespace {
51
52constexpr int kMaxFormLevel = 40;
53
54// Upper limit for the number of form XObjects within a form XObject.
55constexpr int kFormCountLimit = 8192;
56
57constexpr int kSingleCoordinatePair = 1;
58constexpr int kTensorCoordinatePairs = 16;
59constexpr int kCoonsCoordinatePairs = 12;
60constexpr int kSingleColorPerPatch = 1;
61constexpr int kQuadColorsPerPatch = 4;
62
63const char kPathOperatorSubpath = 'm';
64const char kPathOperatorLine = 'l';
65const char kPathOperatorCubicBezier1 = 'c';
66const char kPathOperatorCubicBezier2 = 'v';
67const char kPathOperatorCubicBezier3 = 'y';
68const char kPathOperatorClosePath = 'h';
69const char kPathOperatorRectangle[] = "re";
70
71using OpCodes = std::map<uint32_t, void (CPDF_StreamContentParser::*)()>;
72OpCodes* g_opcodes = nullptr;
73
74CFX_FloatRect GetShadingBBox(CPDF_ShadingPattern* pShading,
75 const CFX_Matrix& matrix) {
76 ShadingType type = pShading->GetShadingType();
77 RetainPtr<const CPDF_Stream> pStream = ToStream(pShading->GetShadingObject());
78 RetainPtr<CPDF_ColorSpace> pCS = pShading->GetCS();
79 if (!pStream || !pCS)
80 return CFX_FloatRect();
81
82 CPDF_MeshStream stream(type, pShading->GetFuncs(), std::move(pStream),
83 std::move(pCS));
84 if (!stream.Load())
85 return CFX_FloatRect();
86
87 CFX_FloatRect rect;
88 bool update_rect = false;
89 bool bGouraud = type == kFreeFormGouraudTriangleMeshShading ||
91
92 int point_count;
94 point_count = kTensorCoordinatePairs;
95 else if (type == kCoonsPatchMeshShading)
96 point_count = kCoonsCoordinatePairs;
97 else
98 point_count = kSingleCoordinatePair;
99
100 int color_count;
102 color_count = kQuadColorsPerPatch;
103 else
104 color_count = kSingleColorPerPatch;
105
106 while (!stream.IsEOF()) {
107 uint32_t flag = 0;
109 if (!stream.CanReadFlag())
110 break;
111 flag = stream.ReadFlag();
112 }
113
114 if (!bGouraud && flag) {
115 point_count -= 4;
116 color_count -= 2;
117 }
118
119 for (int i = 0; i < point_count; ++i) {
120 if (!stream.CanReadCoords())
121 break;
122
123 CFX_PointF origin = stream.ReadCoords();
124 if (update_rect) {
125 rect.UpdateRect(origin);
126 } else {
127 rect = CFX_FloatRect(origin);
128 update_rect = true;
129 }
130 }
131 FX_SAFE_UINT32 nBits = stream.Components();
132 nBits *= stream.ComponentBits();
133 nBits *= color_count;
134 if (!nBits.IsValid())
135 break;
136
137 stream.SkipBits(nBits.ValueOrDie());
138 if (bGouraud)
139 stream.ByteAlign();
140 }
141 return matrix.TransformRect(rect);
142}
143
144struct AbbrPair {
145 const char* abbr;
146 const char* full_name;
147};
148
149const AbbrPair kInlineKeyAbbr[] = {
150 {"BPC", "BitsPerComponent"}, {"CS", "ColorSpace"}, {"D", "Decode"},
151 {"DP", "DecodeParms"}, {"F", "Filter"}, {"H", "Height"},
152 {"IM", "ImageMask"}, {"I", "Interpolate"}, {"W", "Width"},
153};
154
155const AbbrPair kInlineValueAbbr[] = {
156 {"G", "DeviceGray"}, {"RGB", "DeviceRGB"},
157 {"CMYK", "DeviceCMYK"}, {"I", "Indexed"},
158 {"AHx", "ASCIIHexDecode"}, {"A85", "ASCII85Decode"},
159 {"LZW", "LZWDecode"}, {"Fl", "FlateDecode"},
160 {"RL", "RunLengthDecode"}, {"CCF", "CCITTFaxDecode"},
161 {"DCT", "DCTDecode"},
162};
163
164struct AbbrReplacementOp {
165 bool is_replace_key;
166 ByteString key;
167 ByteStringView replacement;
168};
169
170ByteStringView FindFullName(pdfium::span<const AbbrPair> table,
171 ByteStringView abbr) {
172 for (const auto& pair : table) {
173 if (pair.abbr == abbr)
174 return ByteStringView(pair.full_name);
175 }
176 return ByteStringView();
177}
178
179void ReplaceAbbr(RetainPtr<CPDF_Object> pObj);
180
181void ReplaceAbbrInDictionary(CPDF_Dictionary* pDict) {
182 std::vector<AbbrReplacementOp> replacements;
183 {
184 CPDF_DictionaryLocker locker(pDict);
185 for (const auto& it : locker) {
186 ByteString key = it.first;
187 ByteStringView fullname =
188 FindFullName(kInlineKeyAbbr, key.AsStringView());
189 if (!fullname.IsEmpty()) {
190 AbbrReplacementOp op;
191 op.is_replace_key = true;
192 op.key = std::move(key);
193 op.replacement = fullname;
194 replacements.push_back(op);
195 key = fullname;
196 }
197 RetainPtr<CPDF_Object> value = it.second;
198 if (value->IsName()) {
199 ByteString name = value->GetString();
200 fullname = FindFullName(kInlineValueAbbr, name.AsStringView());
201 if (!fullname.IsEmpty()) {
202 AbbrReplacementOp op;
203 op.is_replace_key = false;
204 op.key = key;
205 op.replacement = fullname;
206 replacements.push_back(op);
207 }
208 } else {
209 ReplaceAbbr(std::move(value));
210 }
211 }
212 }
213 for (const auto& op : replacements) {
214 if (op.is_replace_key)
215 pDict->ReplaceKey(op.key, ByteString(op.replacement));
216 else
217 pDict->SetNewFor<CPDF_Name>(op.key, ByteString(op.replacement));
218 }
219}
220
221void ReplaceAbbrInArray(CPDF_Array* pArray) {
222 for (size_t i = 0; i < pArray->size(); ++i) {
223 RetainPtr<CPDF_Object> pElement = pArray->GetMutableObjectAt(i);
224 if (pElement->IsName()) {
225 ByteString name = pElement->GetString();
226 ByteStringView fullname =
227 FindFullName(kInlineValueAbbr, name.AsStringView());
228 if (!fullname.IsEmpty())
229 pArray->SetNewAt<CPDF_Name>(i, ByteString(fullname));
230 } else {
231 ReplaceAbbr(std::move(pElement));
232 }
233 }
234}
235
236void ReplaceAbbr(RetainPtr<CPDF_Object> pObj) {
237 CPDF_Dictionary* pDict = pObj->AsMutableDictionary();
238 if (pDict) {
239 ReplaceAbbrInDictionary(pDict);
240 return;
241 }
242
243 CPDF_Array* pArray = pObj->AsMutableArray();
244 if (pArray)
245 ReplaceAbbrInArray(pArray);
246}
247
248} // namespace
249
250// static
252 CHECK(!g_opcodes);
253 g_opcodes = new OpCodes({
254 {FXBSTR_ID('"', 0, 0, 0),
255 &CPDF_StreamContentParser::Handle_NextLineShowText_Space},
256 {FXBSTR_ID('\'', 0, 0, 0),
257 &CPDF_StreamContentParser::Handle_NextLineShowText},
258 {FXBSTR_ID('B', 0, 0, 0),
259 &CPDF_StreamContentParser::Handle_FillStrokePath},
260 {FXBSTR_ID('B', '*', 0, 0),
261 &CPDF_StreamContentParser::Handle_EOFillStrokePath},
262 {FXBSTR_ID('B', 'D', 'C', 0),
263 &CPDF_StreamContentParser::Handle_BeginMarkedContent_Dictionary},
264 {FXBSTR_ID('B', 'I', 0, 0), &CPDF_StreamContentParser::Handle_BeginImage},
265 {FXBSTR_ID('B', 'M', 'C', 0),
266 &CPDF_StreamContentParser::Handle_BeginMarkedContent},
267 {FXBSTR_ID('B', 'T', 0, 0), &CPDF_StreamContentParser::Handle_BeginText},
268 {FXBSTR_ID('C', 'S', 0, 0),
269 &CPDF_StreamContentParser::Handle_SetColorSpace_Stroke},
270 {FXBSTR_ID('D', 'P', 0, 0),
271 &CPDF_StreamContentParser::Handle_MarkPlace_Dictionary},
272 {FXBSTR_ID('D', 'o', 0, 0),
273 &CPDF_StreamContentParser::Handle_ExecuteXObject},
274 {FXBSTR_ID('E', 'I', 0, 0), &CPDF_StreamContentParser::Handle_EndImage},
275 {FXBSTR_ID('E', 'M', 'C', 0),
276 &CPDF_StreamContentParser::Handle_EndMarkedContent},
277 {FXBSTR_ID('E', 'T', 0, 0), &CPDF_StreamContentParser::Handle_EndText},
278 {FXBSTR_ID('F', 0, 0, 0), &CPDF_StreamContentParser::Handle_FillPathOld},
279 {FXBSTR_ID('G', 0, 0, 0),
280 &CPDF_StreamContentParser::Handle_SetGray_Stroke},
281 {FXBSTR_ID('I', 'D', 0, 0),
282 &CPDF_StreamContentParser::Handle_BeginImageData},
283 {FXBSTR_ID('J', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetLineCap},
284 {FXBSTR_ID('K', 0, 0, 0),
285 &CPDF_StreamContentParser::Handle_SetCMYKColor_Stroke},
286 {FXBSTR_ID('M', 0, 0, 0),
287 &CPDF_StreamContentParser::Handle_SetMiterLimit},
288 {FXBSTR_ID('M', 'P', 0, 0), &CPDF_StreamContentParser::Handle_MarkPlace},
289 {FXBSTR_ID('Q', 0, 0, 0),
290 &CPDF_StreamContentParser::Handle_RestoreGraphState},
291 {FXBSTR_ID('R', 'G', 0, 0),
292 &CPDF_StreamContentParser::Handle_SetRGBColor_Stroke},
293 {FXBSTR_ID('S', 0, 0, 0), &CPDF_StreamContentParser::Handle_StrokePath},
294 {FXBSTR_ID('S', 'C', 0, 0),
295 &CPDF_StreamContentParser::Handle_SetColor_Stroke},
296 {FXBSTR_ID('S', 'C', 'N', 0),
297 &CPDF_StreamContentParser::Handle_SetColorPS_Stroke},
298 {FXBSTR_ID('T', '*', 0, 0),
299 &CPDF_StreamContentParser::Handle_MoveToNextLine},
300 {FXBSTR_ID('T', 'D', 0, 0),
301 &CPDF_StreamContentParser::Handle_MoveTextPoint_SetLeading},
302 {FXBSTR_ID('T', 'J', 0, 0),
303 &CPDF_StreamContentParser::Handle_ShowText_Positioning},
304 {FXBSTR_ID('T', 'L', 0, 0),
305 &CPDF_StreamContentParser::Handle_SetTextLeading},
306 {FXBSTR_ID('T', 'c', 0, 0),
307 &CPDF_StreamContentParser::Handle_SetCharSpace},
308 {FXBSTR_ID('T', 'd', 0, 0),
309 &CPDF_StreamContentParser::Handle_MoveTextPoint},
310 {FXBSTR_ID('T', 'f', 0, 0), &CPDF_StreamContentParser::Handle_SetFont},
311 {FXBSTR_ID('T', 'j', 0, 0), &CPDF_StreamContentParser::Handle_ShowText},
312 {FXBSTR_ID('T', 'm', 0, 0),
313 &CPDF_StreamContentParser::Handle_SetTextMatrix},
314 {FXBSTR_ID('T', 'r', 0, 0),
315 &CPDF_StreamContentParser::Handle_SetTextRenderMode},
316 {FXBSTR_ID('T', 's', 0, 0),
317 &CPDF_StreamContentParser::Handle_SetTextRise},
318 {FXBSTR_ID('T', 'w', 0, 0),
319 &CPDF_StreamContentParser::Handle_SetWordSpace},
320 {FXBSTR_ID('T', 'z', 0, 0),
321 &CPDF_StreamContentParser::Handle_SetHorzScale},
322 {FXBSTR_ID('W', 0, 0, 0), &CPDF_StreamContentParser::Handle_Clip},
323 {FXBSTR_ID('W', '*', 0, 0), &CPDF_StreamContentParser::Handle_EOClip},
324 {FXBSTR_ID('b', 0, 0, 0),
325 &CPDF_StreamContentParser::Handle_CloseFillStrokePath},
326 {FXBSTR_ID('b', '*', 0, 0),
327 &CPDF_StreamContentParser::Handle_CloseEOFillStrokePath},
328 {FXBSTR_ID('c', 0, 0, 0), &CPDF_StreamContentParser::Handle_CurveTo_123},
329 {FXBSTR_ID('c', 'm', 0, 0),
330 &CPDF_StreamContentParser::Handle_ConcatMatrix},
331 {FXBSTR_ID('c', 's', 0, 0),
332 &CPDF_StreamContentParser::Handle_SetColorSpace_Fill},
333 {FXBSTR_ID('d', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetDash},
334 {FXBSTR_ID('d', '0', 0, 0),
335 &CPDF_StreamContentParser::Handle_SetCharWidth},
336 {FXBSTR_ID('d', '1', 0, 0),
337 &CPDF_StreamContentParser::Handle_SetCachedDevice},
338 {FXBSTR_ID('f', 0, 0, 0), &CPDF_StreamContentParser::Handle_FillPath},
339 {FXBSTR_ID('f', '*', 0, 0), &CPDF_StreamContentParser::Handle_EOFillPath},
340 {FXBSTR_ID('g', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetGray_Fill},
341 {FXBSTR_ID('g', 's', 0, 0),
342 &CPDF_StreamContentParser::Handle_SetExtendGraphState},
343 {FXBSTR_ID('h', 0, 0, 0), &CPDF_StreamContentParser::Handle_ClosePath},
344 {FXBSTR_ID('i', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetFlat},
345 {FXBSTR_ID('j', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetLineJoin},
346 {FXBSTR_ID('k', 0, 0, 0),
347 &CPDF_StreamContentParser::Handle_SetCMYKColor_Fill},
348 {FXBSTR_ID('l', 0, 0, 0), &CPDF_StreamContentParser::Handle_LineTo},
349 {FXBSTR_ID('m', 0, 0, 0), &CPDF_StreamContentParser::Handle_MoveTo},
350 {FXBSTR_ID('n', 0, 0, 0), &CPDF_StreamContentParser::Handle_EndPath},
351 {FXBSTR_ID('q', 0, 0, 0),
352 &CPDF_StreamContentParser::Handle_SaveGraphState},
353 {FXBSTR_ID('r', 'e', 0, 0), &CPDF_StreamContentParser::Handle_Rectangle},
354 {FXBSTR_ID('r', 'g', 0, 0),
355 &CPDF_StreamContentParser::Handle_SetRGBColor_Fill},
356 {FXBSTR_ID('r', 'i', 0, 0),
357 &CPDF_StreamContentParser::Handle_SetRenderIntent},
358 {FXBSTR_ID('s', 0, 0, 0),
359 &CPDF_StreamContentParser::Handle_CloseStrokePath},
360 {FXBSTR_ID('s', 'c', 0, 0),
361 &CPDF_StreamContentParser::Handle_SetColor_Fill},
362 {FXBSTR_ID('s', 'c', 'n', 0),
363 &CPDF_StreamContentParser::Handle_SetColorPS_Fill},
364 {FXBSTR_ID('s', 'h', 0, 0), &CPDF_StreamContentParser::Handle_ShadeFill},
365 {FXBSTR_ID('v', 0, 0, 0), &CPDF_StreamContentParser::Handle_CurveTo_23},
366 {FXBSTR_ID('w', 0, 0, 0), &CPDF_StreamContentParser::Handle_SetLineWidth},
367 {FXBSTR_ID('y', 0, 0, 0), &CPDF_StreamContentParser::Handle_CurveTo_13},
368 });
369}
370
371// static
373 delete g_opcodes;
374 g_opcodes = nullptr;
375}
376
378 CPDF_Document* pDocument,
379 RetainPtr<CPDF_Dictionary> pPageResources,
380 RetainPtr<CPDF_Dictionary> pParentResources,
381 const CFX_Matrix* pmtContentToUser,
382 CPDF_PageObjectHolder* pObjHolder,
383 RetainPtr<CPDF_Dictionary> pResources,
384 const CFX_FloatRect& rcBBox,
385 const CPDF_AllStates* pStates,
386 CPDF_Form::RecursionState* recursion_state)
395 m_BBox(rcBBox),
397 if (pmtContentToUser)
398 m_mtContentToUser = *pmtContentToUser;
399 if (pStates) {
400 *m_pCurStates = *pStates;
401 } else {
402 m_pCurStates->mutable_general_state().Emplace();
403 m_pCurStates->mutable_graph_state().Emplace();
404 m_pCurStates->mutable_text_state().Emplace();
405 m_pCurStates->mutable_color_state().Emplace();
406 }
407
408 // Add the sentinel.
409 m_ContentMarksStack.push(std::make_unique<CPDF_ContentMarks>());
410}
411
413 ClearAllParams();
414}
415
416int CPDF_StreamContentParser::GetNextParamPos() {
417 if (m_ParamCount == kParamBufSize) {
418 m_ParamStartPos++;
419 if (m_ParamStartPos == kParamBufSize) {
420 m_ParamStartPos = 0;
421 }
422 if (m_ParamBuf[m_ParamStartPos].m_Type == ContentParam::Type::kObject)
423 m_ParamBuf[m_ParamStartPos].m_pObject.Reset();
424
425 return m_ParamStartPos;
426 }
427 int index = m_ParamStartPos + m_ParamCount;
428 if (index >= kParamBufSize) {
429 index -= kParamBufSize;
430 }
431 m_ParamCount++;
432 return index;
433}
434
435void CPDF_StreamContentParser::AddNameParam(ByteStringView bsName) {
436 ContentParam& param = m_ParamBuf[GetNextParamPos()];
437 param.m_Type = ContentParam::Type::kName;
438 param.m_Name = PDF_NameDecode(bsName);
439}
440
441void CPDF_StreamContentParser::AddNumberParam(ByteStringView str) {
442 ContentParam& param = m_ParamBuf[GetNextParamPos()];
443 param.m_Type = ContentParam::Type::kNumber;
444 param.m_Number = FX_Number(str);
445}
446
447void CPDF_StreamContentParser::AddObjectParam(RetainPtr<CPDF_Object> pObj) {
448 ContentParam& param = m_ParamBuf[GetNextParamPos()];
449 param.m_Type = ContentParam::Type::kObject;
450 param.m_pObject = std::move(pObj);
451}
452
453void CPDF_StreamContentParser::ClearAllParams() {
454 uint32_t index = m_ParamStartPos;
455 for (uint32_t i = 0; i < m_ParamCount; i++) {
456 if (m_ParamBuf[index].m_Type == ContentParam::Type::kObject)
457 m_ParamBuf[index].m_pObject.Reset();
458 index++;
459 if (index == kParamBufSize)
460 index = 0;
461 }
462 m_ParamStartPos = 0;
463 m_ParamCount = 0;
464}
465
466RetainPtr<CPDF_Object> CPDF_StreamContentParser::GetObject(uint32_t index) {
467 if (index >= m_ParamCount) {
468 return nullptr;
469 }
470 int real_index = m_ParamStartPos + m_ParamCount - index - 1;
471 if (real_index >= kParamBufSize) {
472 real_index -= kParamBufSize;
473 }
474 ContentParam& param = m_ParamBuf[real_index];
475 if (param.m_Type == ContentParam::Type::kNumber) {
476 param.m_Type = ContentParam::Type::kObject;
477 param.m_pObject =
478 param.m_Number.IsInteger()
479 ? pdfium::MakeRetain<CPDF_Number>(param.m_Number.GetSigned())
480 : pdfium::MakeRetain<CPDF_Number>(param.m_Number.GetFloat());
481 return param.m_pObject;
482 }
483 if (param.m_Type == ContentParam::Type::kName) {
484 param.m_Type = ContentParam::Type::kObject;
485 param.m_pObject = m_pDocument->New<CPDF_Name>(param.m_Name);
486 return param.m_pObject;
487 }
488 if (param.m_Type == ContentParam::Type::kObject)
489 return param.m_pObject;
490
491 NOTREACHED_NORETURN();
492}
493
494ByteString CPDF_StreamContentParser::GetString(uint32_t index) const {
495 if (index >= m_ParamCount)
496 return ByteString();
497
498 int real_index = m_ParamStartPos + m_ParamCount - index - 1;
499 if (real_index >= kParamBufSize)
500 real_index -= kParamBufSize;
501
502 const ContentParam& param = m_ParamBuf[real_index];
503 if (param.m_Type == ContentParam::Type::kName)
504 return param.m_Name;
505
506 if (param.m_Type == ContentParam::Type::kObject && param.m_pObject)
507 return param.m_pObject->GetString();
508
509 return ByteString();
510}
511
512float CPDF_StreamContentParser::GetNumber(uint32_t index) const {
513 if (index >= m_ParamCount)
514 return 0;
515
516 int real_index = m_ParamStartPos + m_ParamCount - index - 1;
517 if (real_index >= kParamBufSize)
518 real_index -= kParamBufSize;
519
520 const ContentParam& param = m_ParamBuf[real_index];
521 if (param.m_Type == ContentParam::Type::kNumber)
522 return param.m_Number.GetFloat();
523
524 if (param.m_Type == ContentParam::Type::kObject && param.m_pObject)
525 return param.m_pObject->GetNumber();
526
527 return 0;
528}
529
530std::vector<float> CPDF_StreamContentParser::GetNumbers(size_t count) const {
531 std::vector<float> values(count);
532 for (size_t i = 0; i < count; ++i)
533 values[i] = GetNumber(count - i - 1);
534 return values;
535}
536
537CFX_PointF CPDF_StreamContentParser::GetPoint(uint32_t index) const {
538 return CFX_PointF(GetNumber(index + 1), GetNumber(index));
539}
540
541CFX_Matrix CPDF_StreamContentParser::GetMatrix() const {
542 return CFX_Matrix(GetNumber(5), GetNumber(4), GetNumber(3), GetNumber(2),
543 GetNumber(1), GetNumber(0));
544}
545
546void CPDF_StreamContentParser::SetGraphicStates(CPDF_PageObject* pObj,
547 bool bColor,
548 bool bText,
549 bool bGraph) {
550 pObj->mutable_general_state() = m_pCurStates->general_state();
551 pObj->mutable_clip_path() = m_pCurStates->clip_path();
552 pObj->SetContentMarks(*m_ContentMarksStack.top());
553 if (bColor) {
554 pObj->mutable_color_state() = m_pCurStates->color_state();
555 }
556 if (bGraph) {
557 pObj->mutable_graph_state() = m_pCurStates->graph_state();
558 }
559 if (bText) {
560 pObj->mutable_text_state() = m_pCurStates->text_state();
561 }
562}
563
564void CPDF_StreamContentParser::OnOperator(ByteStringView op) {
565 auto it = g_opcodes->find(op.GetID());
566 if (it != g_opcodes->end()) {
567 (this->*it->second)();
568 }
569}
570
571void CPDF_StreamContentParser::Handle_CloseFillStrokePath() {
572 Handle_ClosePath();
573 AddPathObject(CFX_FillRenderOptions::FillType::kWinding, RenderType::kStroke);
574}
575
576void CPDF_StreamContentParser::Handle_FillStrokePath() {
577 AddPathObject(CFX_FillRenderOptions::FillType::kWinding, RenderType::kStroke);
578}
579
580void CPDF_StreamContentParser::Handle_CloseEOFillStrokePath() {
581 AddPathPointAndClose(m_PathStart, CFX_Path::Point::Type::kLine);
582 AddPathObject(CFX_FillRenderOptions::FillType::kEvenOdd, RenderType::kStroke);
583}
584
585void CPDF_StreamContentParser::Handle_EOFillStrokePath() {
586 AddPathObject(CFX_FillRenderOptions::FillType::kEvenOdd, RenderType::kStroke);
587}
588
589void CPDF_StreamContentParser::Handle_BeginMarkedContent_Dictionary() {
590 RetainPtr<CPDF_Object> pProperty = GetObject(0);
591 if (!pProperty)
592 return;
593
594 ByteString tag = GetString(1);
595 std::unique_ptr<CPDF_ContentMarks> new_marks =
596 m_ContentMarksStack.top()->Clone();
597
598 if (pProperty->IsName()) {
599 ByteString property_name = pProperty->GetString();
600 RetainPtr<CPDF_Dictionary> pHolder = FindResourceHolder("Properties");
601 if (!pHolder || !pHolder->GetDictFor(property_name))
602 return;
603 new_marks->AddMarkWithPropertiesHolder(tag, std::move(pHolder),
604 property_name);
605 } else if (pProperty->IsDictionary()) {
606 new_marks->AddMarkWithDirectDict(tag, ToDictionary(pProperty));
607 } else {
608 return;
609 }
610 m_ContentMarksStack.push(std::move(new_marks));
611}
612
613void CPDF_StreamContentParser::Handle_BeginImage() {
614 FX_FILESIZE savePos = m_pSyntax->GetPos();
615 auto pDict = m_pDocument->New<CPDF_Dictionary>();
616 while (true) {
617 CPDF_StreamParser::ElementType type = m_pSyntax->ParseNextElement();
619 if (m_pSyntax->GetWord() != "ID") {
620 m_pSyntax->SetPos(savePos);
621 return;
622 }
623 }
625 break;
626 }
627 auto word = m_pSyntax->GetWord();
628 ByteString key(word.Last(word.GetLength() - 1));
629 auto pObj = m_pSyntax->ReadNextObject(false, false, 0);
630 if (pObj && !pObj->IsInline()) {
631 pDict->SetNewFor<CPDF_Reference>(key, m_pDocument, pObj->GetObjNum());
632 } else {
633 pDict->SetFor(key, std::move(pObj));
634 }
635 }
636 ReplaceAbbr(pDict);
637 RetainPtr<const CPDF_Object> pCSObj;
638 if (pDict->KeyExist("ColorSpace")) {
639 pCSObj = pDict->GetDirectObjectFor("ColorSpace");
640 if (pCSObj->IsName()) {
641 ByteString name = pCSObj->GetString();
642 if (name != "DeviceRGB" && name != "DeviceGray" && name != "DeviceCMYK") {
643 pCSObj = FindResourceObj("ColorSpace", name);
644 if (pCSObj && pCSObj->IsInline())
645 pDict->SetFor("ColorSpace", pCSObj->Clone());
646 }
647 }
648 }
649 pDict->SetNewFor<CPDF_Name>("Subtype", "Image");
650 RetainPtr<CPDF_Stream> pStream =
651 m_pSyntax->ReadInlineStream(m_pDocument, std::move(pDict), pCSObj.Get());
652 while (true) {
653 CPDF_StreamParser::ElementType type = m_pSyntax->ParseNextElement();
655 break;
656
658 continue;
659
660 if (m_pSyntax->GetWord() == "EI")
661 break;
662 }
663 CPDF_ImageObject* pObj = AddImageFromStream(std::move(pStream), /*name=*/"");
664 // Record the bounding box of this image, so rendering code can draw it
665 // properly.
666 if (pObj && pObj->GetImage()->IsMask())
667 m_pObjectHolder->AddImageMaskBoundingBox(pObj->GetRect());
668}
669
670void CPDF_StreamContentParser::Handle_BeginMarkedContent() {
671 std::unique_ptr<CPDF_ContentMarks> new_marks =
672 m_ContentMarksStack.top()->Clone();
673 new_marks->AddMark(GetString(0));
674 m_ContentMarksStack.push(std::move(new_marks));
675}
676
677void CPDF_StreamContentParser::Handle_BeginText() {
678 m_pCurStates->set_text_matrix(CFX_Matrix());
679 OnChangeTextMatrix();
680 m_pCurStates->ResetTextPosition();
681}
682
683void CPDF_StreamContentParser::Handle_CurveTo_123() {
684 AddPathPoint(GetPoint(4), CFX_Path::Point::Type::kBezier);
685 AddPathPoint(GetPoint(2), CFX_Path::Point::Type::kBezier);
686 AddPathPoint(GetPoint(0), CFX_Path::Point::Type::kBezier);
687}
688
689void CPDF_StreamContentParser::Handle_ConcatMatrix() {
690 m_pCurStates->prepend_to_current_transformation_matrix(GetMatrix());
691 OnChangeTextMatrix();
692}
693
694void CPDF_StreamContentParser::Handle_SetColorSpace_Fill() {
695 RetainPtr<CPDF_ColorSpace> pCS = FindColorSpace(GetString(0));
696 if (!pCS)
697 return;
698
699 m_pCurStates->mutable_color_state().GetMutableFillColor()->SetColorSpace(
700 std::move(pCS));
701}
702
703void CPDF_StreamContentParser::Handle_SetColorSpace_Stroke() {
704 RetainPtr<CPDF_ColorSpace> pCS = FindColorSpace(GetString(0));
705 if (!pCS)
706 return;
707
708 m_pCurStates->mutable_color_state().GetMutableStrokeColor()->SetColorSpace(
709 std::move(pCS));
710}
711
712void CPDF_StreamContentParser::Handle_SetDash() {
713 RetainPtr<CPDF_Array> pArray = ToArray(GetObject(1));
714 if (!pArray)
715 return;
716
717 m_pCurStates->SetLineDash(pArray.Get(), GetNumber(0), 1.0f);
718}
719
720void CPDF_StreamContentParser::Handle_SetCharWidth() {
721 m_Type3Data[0] = GetNumber(1);
722 m_Type3Data[1] = GetNumber(0);
723 m_bColored = true;
724}
725
726void CPDF_StreamContentParser::Handle_SetCachedDevice() {
727 for (int i = 0; i < 6; i++) {
728 m_Type3Data[i] = GetNumber(5 - i);
729 }
730 m_bColored = false;
731}
732
733void CPDF_StreamContentParser::Handle_ExecuteXObject() {
734 ByteString name = GetString(0);
735 if (name == m_LastImageName && m_pLastImage && m_pLastImage->GetStream() &&
736 m_pLastImage->GetStream()->GetObjNum()) {
737 CPDF_ImageObject* pObj = AddLastImage();
738 // Record the bounding box of this image, so rendering code can draw it
739 // properly.
740 if (pObj && pObj->GetImage()->IsMask())
741 m_pObjectHolder->AddImageMaskBoundingBox(pObj->GetRect());
742 return;
743 }
744
745 RetainPtr<CPDF_Stream> pXObject(ToStream(FindResourceObj("XObject", name)));
746 if (!pXObject)
747 return;
748
749 ByteString type;
750 if (pXObject->GetDict())
751 type = pXObject->GetDict()->GetByteStringFor("Subtype");
752
753 if (type == "Form") {
754 if (m_RecursionState->form_count > kFormCountLimit) {
755 return;
756 }
757
758 const bool is_first = m_RecursionState->form_count == 0;
759 ++m_RecursionState->form_count;
760 AddForm(std::move(pXObject), name);
761 if (is_first) {
762 m_RecursionState->form_count = 0;
763 }
764 return;
765 }
766
767 if (type == "Image") {
768 CPDF_ImageObject* pObj =
769 pXObject->IsInline()
770 ? AddImageFromStream(ToStream(pXObject->Clone()), name)
771 : AddImageFromStreamObjNum(pXObject->GetObjNum(), name);
772
773 m_LastImageName = std::move(name);
774 if (pObj) {
775 m_pLastImage = pObj->GetImage();
776 if (m_pLastImage->IsMask())
777 m_pObjectHolder->AddImageMaskBoundingBox(pObj->GetRect());
778 }
779 }
780}
781
782void CPDF_StreamContentParser::AddForm(RetainPtr<CPDF_Stream> pStream,
783 const ByteString& name) {
784 CPDF_AllStates status;
785 status.mutable_general_state() = m_pCurStates->general_state();
786 status.mutable_graph_state() = m_pCurStates->graph_state();
787 status.mutable_color_state() = m_pCurStates->color_state();
788 status.mutable_text_state() = m_pCurStates->text_state();
789 auto form = std::make_unique<CPDF_Form>(
790 m_pDocument, m_pPageResources, std::move(pStream), m_pResources.Get());
791 form->ParseContent(&status, nullptr, m_RecursionState);
792
793 CFX_Matrix matrix =
794 m_pCurStates->current_transformation_matrix() * m_mtContentToUser;
795 auto pFormObj = std::make_unique<CPDF_FormObject>(GetCurrentStreamIndex(),
796 std::move(form), matrix);
797 pFormObj->SetResourceName(name);
798 if (!m_pObjectHolder->BackgroundAlphaNeeded() &&
799 pFormObj->form()->BackgroundAlphaNeeded()) {
800 m_pObjectHolder->SetBackgroundAlphaNeeded(true);
801 }
802 pFormObj->CalcBoundingBox();
803 SetGraphicStates(pFormObj.get(), true, true, true);
804 m_pObjectHolder->AppendPageObject(std::move(pFormObj));
805}
806
807CPDF_ImageObject* CPDF_StreamContentParser::AddImageFromStream(
808 RetainPtr<CPDF_Stream> pStream,
809 const ByteString& name) {
810 if (!pStream)
811 return nullptr;
812
813 auto pImageObj = std::make_unique<CPDF_ImageObject>(GetCurrentStreamIndex());
814 pImageObj->SetResourceName(name);
815 pImageObj->SetImage(
816 pdfium::MakeRetain<CPDF_Image>(m_pDocument, std::move(pStream)));
817
818 return AddImageObject(std::move(pImageObj));
819}
820
821CPDF_ImageObject* CPDF_StreamContentParser::AddImageFromStreamObjNum(
822 uint32_t stream_obj_num,
823 const ByteString& name) {
824 auto pImageObj = std::make_unique<CPDF_ImageObject>(GetCurrentStreamIndex());
825 pImageObj->SetResourceName(name);
826 pImageObj->SetImage(
827 CPDF_DocPageData::FromDocument(m_pDocument)->GetImage(stream_obj_num));
828
829 return AddImageObject(std::move(pImageObj));
830}
831
832CPDF_ImageObject* CPDF_StreamContentParser::AddLastImage() {
833 DCHECK(m_pLastImage);
834
835 auto pImageObj = std::make_unique<CPDF_ImageObject>(GetCurrentStreamIndex());
836 pImageObj->SetResourceName(m_LastImageName);
837 pImageObj->SetImage(CPDF_DocPageData::FromDocument(m_pDocument)
838 ->GetImage(m_pLastImage->GetStream()->GetObjNum()));
839
840 return AddImageObject(std::move(pImageObj));
841}
842
843CPDF_ImageObject* CPDF_StreamContentParser::AddImageObject(
844 std::unique_ptr<CPDF_ImageObject> pImageObj) {
845 SetGraphicStates(pImageObj.get(), pImageObj->GetImage()->IsMask(), false,
846 false);
847
848 CFX_Matrix ImageMatrix =
849 m_pCurStates->current_transformation_matrix() * m_mtContentToUser;
850 pImageObj->SetImageMatrix(ImageMatrix);
851
852 CPDF_ImageObject* pRet = pImageObj.get();
853 m_pObjectHolder->AppendPageObject(std::move(pImageObj));
854 return pRet;
855}
856
857std::vector<float> CPDF_StreamContentParser::GetColors() const {
858 DCHECK(m_ParamCount > 0);
859 return GetNumbers(m_ParamCount);
860}
861
862std::vector<float> CPDF_StreamContentParser::GetNamedColors() const {
863 DCHECK(m_ParamCount > 0);
864 const uint32_t nvalues = m_ParamCount - 1;
865 std::vector<float> values(nvalues);
866 for (size_t i = 0; i < nvalues; ++i)
867 values[i] = GetNumber(m_ParamCount - i - 1);
868 return values;
869}
870
871void CPDF_StreamContentParser::Handle_MarkPlace_Dictionary() {}
872
873void CPDF_StreamContentParser::Handle_EndImage() {}
874
875void CPDF_StreamContentParser::Handle_EndMarkedContent() {
876 // First element is a sentinel, so do not pop it, ever. This may come up if
877 // the EMCs are mismatched with the BMC/BDCs.
878 if (m_ContentMarksStack.size() > 1)
879 m_ContentMarksStack.pop();
880}
881
882void CPDF_StreamContentParser::Handle_EndText() {
883 if (m_ClipTextList.empty())
884 return;
885
886 if (TextRenderingModeIsClipMode(m_pCurStates->text_state().GetTextMode())) {
887 m_pCurStates->mutable_clip_path().AppendTexts(&m_ClipTextList);
888 }
889
890 m_ClipTextList.clear();
891}
892
893void CPDF_StreamContentParser::Handle_FillPath() {
894 AddPathObject(CFX_FillRenderOptions::FillType::kWinding, RenderType::kFill);
895}
896
897void CPDF_StreamContentParser::Handle_FillPathOld() {
898 AddPathObject(CFX_FillRenderOptions::FillType::kWinding, RenderType::kFill);
899}
900
901void CPDF_StreamContentParser::Handle_EOFillPath() {
902 AddPathObject(CFX_FillRenderOptions::FillType::kEvenOdd, RenderType::kFill);
903}
904
905void CPDF_StreamContentParser::Handle_SetGray_Fill() {
906 m_pCurStates->mutable_color_state().SetFillColor(
907 CPDF_ColorSpace::GetStockCS(CPDF_ColorSpace::Family::kDeviceGray),
908 GetNumbers(1));
909}
910
911void CPDF_StreamContentParser::Handle_SetGray_Stroke() {
912 m_pCurStates->mutable_color_state().SetStrokeColor(
913 CPDF_ColorSpace::GetStockCS(CPDF_ColorSpace::Family::kDeviceGray),
914 GetNumbers(1));
915}
916
917void CPDF_StreamContentParser::Handle_SetExtendGraphState() {
918 ByteString name = GetString(0);
919 RetainPtr<CPDF_Dictionary> pGS =
920 ToDictionary(FindResourceObj("ExtGState", name));
921 if (!pGS)
922 return;
923
924 CHECK(!name.IsEmpty());
925 m_pCurStates->mutable_general_state().AppendGraphicsResourceName(
926 std::move(name));
927 m_pCurStates->ProcessExtGS(pGS.Get(), this);
928}
929
930void CPDF_StreamContentParser::Handle_ClosePath() {
931 if (m_PathPoints.empty())
932 return;
933
934 if (m_PathStart.x != m_PathCurrent.x || m_PathStart.y != m_PathCurrent.y) {
935 AddPathPointAndClose(m_PathStart, CFX_Path::Point::Type::kLine);
936 } else {
937 m_PathPoints.back().m_CloseFigure = true;
938 }
939}
940
941void CPDF_StreamContentParser::Handle_SetFlat() {
942 m_pCurStates->mutable_general_state().SetFlatness(GetNumber(0));
943}
944
945void CPDF_StreamContentParser::Handle_BeginImageData() {}
946
947void CPDF_StreamContentParser::Handle_SetLineJoin() {
948 m_pCurStates->mutable_graph_state().SetLineJoin(
949 static_cast<CFX_GraphStateData::LineJoin>(GetInteger(0)));
950}
951
952void CPDF_StreamContentParser::Handle_SetLineCap() {
953 m_pCurStates->mutable_graph_state().SetLineCap(
954 static_cast<CFX_GraphStateData::LineCap>(GetInteger(0)));
955}
956
957void CPDF_StreamContentParser::Handle_SetCMYKColor_Fill() {
958 if (m_ParamCount != 4)
959 return;
960
961 m_pCurStates->mutable_color_state().SetFillColor(
962 CPDF_ColorSpace::GetStockCS(CPDF_ColorSpace::Family::kDeviceCMYK),
963 GetNumbers(4));
964}
965
966void CPDF_StreamContentParser::Handle_SetCMYKColor_Stroke() {
967 if (m_ParamCount != 4)
968 return;
969
970 m_pCurStates->mutable_color_state().SetStrokeColor(
971 CPDF_ColorSpace::GetStockCS(CPDF_ColorSpace::Family::kDeviceCMYK),
972 GetNumbers(4));
973}
974
975void CPDF_StreamContentParser::Handle_LineTo() {
976 if (m_ParamCount != 2)
977 return;
978
979 AddPathPoint(GetPoint(0), CFX_Path::Point::Type::kLine);
980}
981
982void CPDF_StreamContentParser::Handle_MoveTo() {
983 if (m_ParamCount != 2)
984 return;
985
986 AddPathPoint(GetPoint(0), CFX_Path::Point::Type::kMove);
987 ParsePathObject();
988}
989
990void CPDF_StreamContentParser::Handle_SetMiterLimit() {
991 m_pCurStates->mutable_graph_state().SetMiterLimit(GetNumber(0));
992}
993
994void CPDF_StreamContentParser::Handle_MarkPlace() {}
995
996void CPDF_StreamContentParser::Handle_EndPath() {
997 AddPathObject(CFX_FillRenderOptions::FillType::kNoFill, RenderType::kFill);
998}
999
1000void CPDF_StreamContentParser::Handle_SaveGraphState() {
1001 m_StateStack.push_back(std::make_unique<CPDF_AllStates>(*m_pCurStates));
1002}
1003
1004void CPDF_StreamContentParser::Handle_RestoreGraphState() {
1005 if (m_StateStack.empty())
1006 return;
1007 *m_pCurStates = *m_StateStack.back();
1008 m_StateStack.pop_back();
1009}
1010
1011void CPDF_StreamContentParser::Handle_Rectangle() {
1012 float x = GetNumber(3);
1013 float y = GetNumber(2);
1014 float w = GetNumber(1);
1015 float h = GetNumber(0);
1016 AddPathRect(x, y, w, h);
1017}
1018
1019void CPDF_StreamContentParser::AddPathRect(float x, float y, float w, float h) {
1020 AddPathPoint({x, y}, CFX_Path::Point::Type::kMove);
1021 AddPathPoint({x + w, y}, CFX_Path::Point::Type::kLine);
1022 AddPathPoint({x + w, y + h}, CFX_Path::Point::Type::kLine);
1023 AddPathPoint({x, y + h}, CFX_Path::Point::Type::kLine);
1024 AddPathPointAndClose({x, y}, CFX_Path::Point::Type::kLine);
1025}
1026
1027void CPDF_StreamContentParser::Handle_SetRGBColor_Fill() {
1028 if (m_ParamCount != 3)
1029 return;
1030
1031 m_pCurStates->mutable_color_state().SetFillColor(
1032 CPDF_ColorSpace::GetStockCS(CPDF_ColorSpace::Family::kDeviceRGB),
1033 GetNumbers(3));
1034}
1035
1036void CPDF_StreamContentParser::Handle_SetRGBColor_Stroke() {
1037 if (m_ParamCount != 3)
1038 return;
1039
1040 m_pCurStates->mutable_color_state().SetStrokeColor(
1041 CPDF_ColorSpace::GetStockCS(CPDF_ColorSpace::Family::kDeviceRGB),
1042 GetNumbers(3));
1043}
1044
1045void CPDF_StreamContentParser::Handle_SetRenderIntent() {}
1046
1047void CPDF_StreamContentParser::Handle_CloseStrokePath() {
1048 Handle_ClosePath();
1049 AddPathObject(CFX_FillRenderOptions::FillType::kNoFill, RenderType::kStroke);
1050}
1051
1052void CPDF_StreamContentParser::Handle_StrokePath() {
1053 AddPathObject(CFX_FillRenderOptions::FillType::kNoFill, RenderType::kStroke);
1054}
1055
1056void CPDF_StreamContentParser::Handle_SetColor_Fill() {
1057 int nargs = std::min(m_ParamCount, 4U);
1058 m_pCurStates->mutable_color_state().SetFillColor(nullptr, GetNumbers(nargs));
1059}
1060
1061void CPDF_StreamContentParser::Handle_SetColor_Stroke() {
1062 int nargs = std::min(m_ParamCount, 4U);
1063 m_pCurStates->mutable_color_state().SetStrokeColor(nullptr,
1064 GetNumbers(nargs));
1065}
1066
1067void CPDF_StreamContentParser::Handle_SetColorPS_Fill() {
1068 RetainPtr<CPDF_Object> pLastParam = GetObject(0);
1069 if (!pLastParam)
1070 return;
1071
1072 if (!pLastParam->IsName()) {
1073 m_pCurStates->mutable_color_state().SetFillColor(nullptr, GetColors());
1074 return;
1075 }
1076
1077 // A valid |pLastParam| implies |m_ParamCount| > 0, so GetNamedColors() call
1078 // below is safe.
1079 RetainPtr<CPDF_Pattern> pPattern = FindPattern(GetString(0));
1080 if (!pPattern)
1081 return;
1082
1083 std::vector<float> values = GetNamedColors();
1084 m_pCurStates->mutable_color_state().SetFillPattern(std::move(pPattern),
1085 values);
1086}
1087
1088void CPDF_StreamContentParser::Handle_SetColorPS_Stroke() {
1089 RetainPtr<CPDF_Object> pLastParam = GetObject(0);
1090 if (!pLastParam)
1091 return;
1092
1093 if (!pLastParam->IsName()) {
1094 m_pCurStates->mutable_color_state().SetStrokeColor(nullptr, GetColors());
1095 return;
1096 }
1097
1098 // A valid |pLastParam| implies |m_ParamCount| > 0, so GetNamedColors() call
1099 // below is safe.
1100 RetainPtr<CPDF_Pattern> pPattern = FindPattern(GetString(0));
1101 if (!pPattern)
1102 return;
1103
1104 std::vector<float> values = GetNamedColors();
1105 m_pCurStates->mutable_color_state().SetStrokePattern(std::move(pPattern),
1106 values);
1107}
1108
1109void CPDF_StreamContentParser::Handle_ShadeFill() {
1110 RetainPtr<CPDF_ShadingPattern> pShading = FindShading(GetString(0));
1111 if (!pShading)
1112 return;
1113
1114 if (!pShading->IsShadingObject() || !pShading->Load())
1115 return;
1116
1117 CFX_Matrix matrix =
1118 m_pCurStates->current_transformation_matrix() * m_mtContentToUser;
1119 auto pObj = std::make_unique<CPDF_ShadingObject>(GetCurrentStreamIndex(),
1120 pShading, matrix);
1121 SetGraphicStates(pObj.get(), false, false, false);
1122 CFX_FloatRect bbox =
1123 pObj->clip_path().HasRef() ? pObj->clip_path().GetClipBox() : m_BBox;
1124 if (pShading->IsMeshShading())
1125 bbox.Intersect(GetShadingBBox(pShading.Get(), pObj->matrix()));
1126 pObj->SetRect(bbox);
1127 m_pObjectHolder->AppendPageObject(std::move(pObj));
1128}
1129
1130void CPDF_StreamContentParser::Handle_SetCharSpace() {
1131 m_pCurStates->mutable_text_state().SetCharSpace(GetNumber(0));
1132}
1133
1134void CPDF_StreamContentParser::Handle_MoveTextPoint() {
1135 m_pCurStates->MoveTextPoint(GetPoint(0));
1136}
1137
1138void CPDF_StreamContentParser::Handle_MoveTextPoint_SetLeading() {
1139 Handle_MoveTextPoint();
1140 m_pCurStates->set_text_leading(-GetNumber(0));
1141}
1142
1143void CPDF_StreamContentParser::Handle_SetFont() {
1144 m_pCurStates->mutable_text_state().SetFontSize(GetNumber(0));
1145 RetainPtr<CPDF_Font> pFont = FindFont(GetString(1));
1146 if (pFont)
1147 m_pCurStates->mutable_text_state().SetFont(std::move(pFont));
1148}
1149
1150RetainPtr<CPDF_Dictionary> CPDF_StreamContentParser::FindResourceHolder(
1151 const ByteString& type) {
1152 if (!m_pResources)
1153 return nullptr;
1154
1155 RetainPtr<CPDF_Dictionary> pDict = m_pResources->GetMutableDictFor(type);
1156 if (pDict)
1157 return pDict;
1158
1159 if (m_pResources == m_pPageResources || !m_pPageResources)
1160 return nullptr;
1161
1162 return m_pPageResources->GetMutableDictFor(type);
1163}
1164
1166 const ByteString& type,
1167 const ByteString& name) {
1168 RetainPtr<CPDF_Dictionary> pHolder = FindResourceHolder(type);
1169 return pHolder ? pHolder->GetMutableDirectObjectFor(name) : nullptr;
1170}
1171
1173 const ByteString& name) {
1174 RetainPtr<CPDF_Dictionary> pFontDict(
1175 ToDictionary(FindResourceObj("Font", name)));
1176 if (!pFontDict) {
1177 return CPDF_Font::GetStockFont(m_pDocument, CFX_Font::kDefaultAnsiFontName);
1178 }
1179 RetainPtr<CPDF_Font> pFont = CPDF_DocPageData::FromDocument(m_pDocument)
1180 ->GetFont(std::move(pFontDict));
1181 if (pFont) {
1182 // Save `name` for later retrieval by the CPDF_TextObject that uses the
1183 // font.
1184 pFont->SetResourceName(name);
1185 if (pFont->IsType3Font()) {
1186 pFont->AsType3Font()->SetPageResources(m_pResources.Get());
1187 pFont->AsType3Font()->CheckType3FontMetrics();
1188 }
1189 }
1190 return pFont;
1191}
1192
1194 const ByteString& name) {
1195 if (name == "Pattern")
1197
1198 if (name == "DeviceGray" || name == "DeviceCMYK" || name == "DeviceRGB") {
1199 ByteString defname = "Default";
1200 defname += name.Last(name.GetLength() - 7);
1201 RetainPtr<const CPDF_Object> pDefObj =
1202 FindResourceObj("ColorSpace", defname);
1203 if (!pDefObj) {
1204 if (name == "DeviceGray") {
1207 }
1208 if (name == "DeviceRGB")
1210
1212 }
1213 return CPDF_DocPageData::FromDocument(m_pDocument)
1214 ->GetColorSpace(pDefObj.Get(), nullptr);
1215 }
1216 RetainPtr<const CPDF_Object> pCSObj = FindResourceObj("ColorSpace", name);
1217 if (!pCSObj)
1218 return nullptr;
1219 return CPDF_DocPageData::FromDocument(m_pDocument)
1220 ->GetColorSpace(pCSObj.Get(), nullptr);
1221}
1222
1224 const ByteString& name) {
1225 RetainPtr<CPDF_Object> pPattern = FindResourceObj("Pattern", name);
1226 if (!pPattern || (!pPattern->IsDictionary() && !pPattern->IsStream()))
1227 return nullptr;
1228 return CPDF_DocPageData::FromDocument(m_pDocument)
1229 ->GetPattern(std::move(pPattern), m_pCurStates->parent_matrix());
1230}
1231
1232RetainPtr<CPDF_ShadingPattern> CPDF_StreamContentParser::FindShading(
1233 const ByteString& name) {
1234 RetainPtr<CPDF_Object> pPattern = FindResourceObj("Shading", name);
1235 if (!pPattern || (!pPattern->IsDictionary() && !pPattern->IsStream()))
1236 return nullptr;
1237 return CPDF_DocPageData::FromDocument(m_pDocument)
1238 ->GetShading(std::move(pPattern), m_pCurStates->parent_matrix());
1239}
1240
1241void CPDF_StreamContentParser::AddTextObject(const ByteString* pStrs,
1242 float fInitKerning,
1243 const std::vector<float>& kernings,
1244 size_t nSegs) {
1245 RetainPtr<CPDF_Font> pFont = m_pCurStates->text_state().GetFont();
1246 if (!pFont)
1247 return;
1248
1249 if (fInitKerning != 0) {
1250 if (pFont->IsVertWriting())
1251 m_pCurStates->IncrementTextPositionY(-GetVerticalTextSize(fInitKerning));
1252 else
1253 m_pCurStates->IncrementTextPositionX(
1254 -GetHorizontalTextSize(fInitKerning));
1255 }
1256 if (nSegs == 0)
1257 return;
1258
1259 const TextRenderingMode text_mode =
1260 pFont->IsType3Font() ? TextRenderingMode::MODE_FILL
1261 : m_pCurStates->text_state().GetTextMode();
1262 {
1263 auto pText = std::make_unique<CPDF_TextObject>(GetCurrentStreamIndex());
1264 pText->SetResourceName(pFont->GetResourceName());
1265 SetGraphicStates(pText.get(), true, true, true);
1266 if (TextRenderingModeIsStrokeMode(text_mode)) {
1267 const CFX_Matrix& ctm = m_pCurStates->current_transformation_matrix();
1268 pdfium::span<float> text_ctm =
1269 pText->mutable_text_state().GetMutableCTM();
1270 text_ctm[0] = ctm.a;
1271 text_ctm[1] = ctm.c;
1272 text_ctm[2] = ctm.b;
1273 text_ctm[3] = ctm.d;
1274 }
1275 pText->SetSegments(pStrs, kernings, nSegs);
1276 pText->SetPosition(m_mtContentToUser.Transform(
1277 m_pCurStates->GetTransformedTextPosition()));
1278
1279 const CFX_PointF position =
1280 pText->CalcPositionData(m_pCurStates->text_horz_scale());
1281 m_pCurStates->IncrementTextPositionX(position.x);
1282 m_pCurStates->IncrementTextPositionY(position.y);
1283 if (TextRenderingModeIsClipMode(text_mode))
1284 m_ClipTextList.push_back(pText->Clone());
1285 m_pObjectHolder->AppendPageObject(std::move(pText));
1286 }
1287 if (!kernings.empty() && kernings[nSegs - 1] != 0) {
1288 if (pFont->IsVertWriting())
1289 m_pCurStates->IncrementTextPositionY(
1290 -GetVerticalTextSize(kernings[nSegs - 1]));
1291 else
1292 m_pCurStates->IncrementTextPositionX(
1293 -GetHorizontalTextSize(kernings[nSegs - 1]));
1294 }
1295}
1296
1297float CPDF_StreamContentParser::GetHorizontalTextSize(float fKerning) const {
1298 return GetVerticalTextSize(fKerning) * m_pCurStates->text_horz_scale();
1299}
1300
1301float CPDF_StreamContentParser::GetVerticalTextSize(float fKerning) const {
1302 return fKerning * m_pCurStates->text_state().GetFontSize() / 1000;
1303}
1304
1305int32_t CPDF_StreamContentParser::GetCurrentStreamIndex() {
1306 auto it =
1307 std::upper_bound(m_StreamStartOffsets.begin(), m_StreamStartOffsets.end(),
1308 m_pSyntax->GetPos() + m_StartParseOffset);
1309 return (it - m_StreamStartOffsets.begin()) - 1;
1310}
1311
1312void CPDF_StreamContentParser::Handle_ShowText() {
1313 ByteString str = GetString(0);
1314 if (!str.IsEmpty())
1315 AddTextObject(&str, 0, std::vector<float>(), 1);
1316}
1317
1318void CPDF_StreamContentParser::Handle_ShowText_Positioning() {
1319 RetainPtr<CPDF_Array> pArray = ToArray(GetObject(0));
1320 if (!pArray)
1321 return;
1322
1323 size_t n = pArray->size();
1324 size_t nsegs = 0;
1325 for (size_t i = 0; i < n; i++) {
1326 RetainPtr<const CPDF_Object> pDirectObject = pArray->GetDirectObjectAt(i);
1327 if (pDirectObject && pDirectObject->IsString())
1328 nsegs++;
1329 }
1330 if (nsegs == 0) {
1331 for (size_t i = 0; i < n; i++) {
1332 float fKerning = pArray->GetFloatAt(i);
1333 if (fKerning != 0)
1334 m_pCurStates->IncrementTextPositionX(-GetHorizontalTextSize(fKerning));
1335 }
1336 return;
1337 }
1338 std::vector<ByteString> strs(nsegs);
1339 std::vector<float> kernings(nsegs);
1340 size_t iSegment = 0;
1341 float fInitKerning = 0;
1342 for (size_t i = 0; i < n; i++) {
1343 RetainPtr<const CPDF_Object> pObj = pArray->GetDirectObjectAt(i);
1344 if (!pObj)
1345 continue;
1346
1347 if (pObj->IsString()) {
1348 ByteString str = pObj->GetString();
1349 if (str.IsEmpty())
1350 continue;
1351 strs[iSegment] = std::move(str);
1352 kernings[iSegment++] = 0;
1353 } else {
1354 float num = pObj->GetNumber();
1355 if (iSegment == 0)
1356 fInitKerning += num;
1357 else
1358 kernings[iSegment - 1] += num;
1359 }
1360 }
1361 AddTextObject(strs.data(), fInitKerning, kernings, iSegment);
1362}
1363
1364void CPDF_StreamContentParser::Handle_SetTextLeading() {
1365 m_pCurStates->set_text_leading(GetNumber(0));
1366}
1367
1368void CPDF_StreamContentParser::Handle_SetTextMatrix() {
1369 m_pCurStates->set_text_matrix(GetMatrix());
1370 OnChangeTextMatrix();
1371 m_pCurStates->ResetTextPosition();
1372}
1373
1374void CPDF_StreamContentParser::OnChangeTextMatrix() {
1375 CFX_Matrix text_matrix(m_pCurStates->text_horz_scale(), 0.0f, 0.0f, 1.0f,
1376 0.0f, 0.0f);
1377 text_matrix.Concat(m_pCurStates->text_matrix());
1378 text_matrix.Concat(m_pCurStates->current_transformation_matrix());
1379 text_matrix.Concat(m_mtContentToUser);
1380 pdfium::span<float> pTextMatrix =
1381 m_pCurStates->mutable_text_state().GetMutableMatrix();
1382 pTextMatrix[0] = text_matrix.a;
1383 pTextMatrix[1] = text_matrix.c;
1384 pTextMatrix[2] = text_matrix.b;
1385 pTextMatrix[3] = text_matrix.d;
1386}
1387
1388void CPDF_StreamContentParser::Handle_SetTextRenderMode() {
1389 TextRenderingMode mode;
1390 if (SetTextRenderingModeFromInt(GetInteger(0), &mode))
1391 m_pCurStates->mutable_text_state().SetTextMode(mode);
1392}
1393
1394void CPDF_StreamContentParser::Handle_SetTextRise() {
1395 m_pCurStates->set_text_rise(GetNumber(0));
1396}
1397
1398void CPDF_StreamContentParser::Handle_SetWordSpace() {
1399 m_pCurStates->mutable_text_state().SetWordSpace(GetNumber(0));
1400}
1401
1402void CPDF_StreamContentParser::Handle_SetHorzScale() {
1403 if (m_ParamCount != 1) {
1404 return;
1405 }
1406 m_pCurStates->set_text_horz_scale(GetNumber(0) / 100);
1407 OnChangeTextMatrix();
1408}
1409
1410void CPDF_StreamContentParser::Handle_MoveToNextLine() {
1411 m_pCurStates->MoveTextToNextLine();
1412}
1413
1414void CPDF_StreamContentParser::Handle_CurveTo_23() {
1415 AddPathPoint(m_PathCurrent, CFX_Path::Point::Type::kBezier);
1416 AddPathPoint(GetPoint(2), CFX_Path::Point::Type::kBezier);
1417 AddPathPoint(GetPoint(0), CFX_Path::Point::Type::kBezier);
1418}
1419
1420void CPDF_StreamContentParser::Handle_SetLineWidth() {
1421 m_pCurStates->mutable_graph_state().SetLineWidth(GetNumber(0));
1422}
1423
1424void CPDF_StreamContentParser::Handle_Clip() {
1426}
1427
1428void CPDF_StreamContentParser::Handle_EOClip() {
1430}
1431
1432void CPDF_StreamContentParser::Handle_CurveTo_13() {
1433 AddPathPoint(GetPoint(2), CFX_Path::Point::Type::kBezier);
1434 AddPathPoint(GetPoint(0), CFX_Path::Point::Type::kBezier);
1435 AddPathPoint(GetPoint(0), CFX_Path::Point::Type::kBezier);
1436}
1437
1438void CPDF_StreamContentParser::Handle_NextLineShowText() {
1439 Handle_MoveToNextLine();
1440 Handle_ShowText();
1441}
1442
1443void CPDF_StreamContentParser::Handle_NextLineShowText_Space() {
1444 m_pCurStates->mutable_text_state().SetWordSpace(GetNumber(2));
1445 m_pCurStates->mutable_text_state().SetCharSpace(GetNumber(1));
1446 Handle_NextLineShowText();
1447}
1448
1449void CPDF_StreamContentParser::Handle_Invalid() {}
1450
1451void CPDF_StreamContentParser::AddPathPoint(const CFX_PointF& point,
1452 CFX_Path::Point::Type type) {
1453 // If the path point is the same move as the previous one and neither of them
1454 // closes the path, then just skip it.
1455 if (type == CFX_Path::Point::Type::kMove && !m_PathPoints.empty() &&
1456 !m_PathPoints.back().m_CloseFigure &&
1457 m_PathPoints.back().m_Type == type && m_PathCurrent == point) {
1458 return;
1459 }
1460
1461 m_PathCurrent = point;
1462 if (type == CFX_Path::Point::Type::kMove) {
1463 m_PathStart = point;
1464 if (!m_PathPoints.empty() &&
1465 m_PathPoints.back().IsTypeAndOpen(CFX_Path::Point::Type::kMove)) {
1466 m_PathPoints.back().m_Point = point;
1467 return;
1468 }
1469 } else if (m_PathPoints.empty()) {
1470 return;
1471 }
1472 m_PathPoints.emplace_back(point, type, /*close=*/false);
1473}
1474
1475void CPDF_StreamContentParser::AddPathPointAndClose(
1476 const CFX_PointF& point,
1477 CFX_Path::Point::Type type) {
1478 m_PathCurrent = point;
1479 if (m_PathPoints.empty())
1480 return;
1481
1482 m_PathPoints.emplace_back(point, type, /*close=*/true);
1483}
1484
1485void CPDF_StreamContentParser::AddPathObject(
1487 RenderType render_type) {
1488 std::vector<CFX_Path::Point> path_points;
1489 path_points.swap(m_PathPoints);
1490 CFX_FillRenderOptions::FillType path_clip_type = m_PathClipType;
1492
1493 if (path_points.empty())
1494 return;
1495
1496 if (path_points.size() == 1) {
1497 if (path_clip_type != CFX_FillRenderOptions::FillType::kNoFill) {
1498 CPDF_Path path;
1499 path.AppendRect(0, 0, 0, 0);
1500 m_pCurStates->mutable_clip_path().AppendPathWithAutoMerge(
1501 path, CFX_FillRenderOptions::FillType::kWinding);
1502 return;
1503 }
1504
1505 CFX_Path::Point& point = path_points.front();
1506 if (point.m_Type != CFX_Path::Point::Type::kMove || !point.m_CloseFigure ||
1507 m_pCurStates->graph_state().GetLineCap() !=
1508 CFX_GraphStateData::LineCap::kRound) {
1509 return;
1510 }
1511
1512 // For round line cap only: When a path moves to a point and immediately
1513 // gets closed, we can treat it as drawing a path from this point to itself
1514 // and closing the path. This should not apply to butt line cap or
1515 // projecting square line cap since they should not be rendered.
1516 point.m_CloseFigure = false;
1517 path_points.emplace_back(point.m_Point, CFX_Path::Point::Type::kLine,
1518 /*close=*/true);
1519 }
1520
1521 if (path_points.back().IsTypeAndOpen(CFX_Path::Point::Type::kMove))
1522 path_points.pop_back();
1523
1524 CPDF_Path path;
1525 for (const auto& point : path_points) {
1526 if (point.m_CloseFigure)
1527 path.AppendPointAndClose(point.m_Point, point.m_Type);
1528 else
1529 path.AppendPoint(point.m_Point, point.m_Type);
1530 }
1531
1532 CFX_Matrix matrix =
1533 m_pCurStates->current_transformation_matrix() * m_mtContentToUser;
1534 bool bStroke = render_type == RenderType::kStroke;
1535 if (bStroke || fill_type != CFX_FillRenderOptions::FillType::kNoFill) {
1536 auto pPathObj = std::make_unique<CPDF_PathObject>(GetCurrentStreamIndex());
1537 pPathObj->set_stroke(bStroke);
1538 pPathObj->set_filltype(fill_type);
1539 pPathObj->path() = path;
1540 SetGraphicStates(pPathObj.get(), true, false, true);
1541 pPathObj->SetPathMatrix(matrix);
1542 m_pObjectHolder->AppendPageObject(std::move(pPathObj));
1543 }
1544 if (path_clip_type != CFX_FillRenderOptions::FillType::kNoFill) {
1545 if (!matrix.IsIdentity())
1546 path.Transform(matrix);
1547 m_pCurStates->mutable_clip_path().AppendPathWithAutoMerge(path,
1548 path_clip_type);
1549 }
1550}
1551
1553 pdfium::span<const uint8_t> pData,
1554 uint32_t start_offset,
1555 uint32_t max_cost,
1556 const std::vector<uint32_t>& stream_start_offsets) {
1557 DCHECK(start_offset < pData.size());
1558
1559 // Parsing will be done from within |pDataStart|.
1560 pdfium::span<const uint8_t> pDataStart = pData.subspan(start_offset);
1561 m_StartParseOffset = start_offset;
1562 if (m_RecursionState->parsed_set.size() > kMaxFormLevel ||
1563 pdfium::Contains(m_RecursionState->parsed_set, pDataStart.data())) {
1564 return fxcrt::CollectionSize<uint32_t>(pDataStart);
1565 }
1566
1567 m_StreamStartOffsets = stream_start_offsets;
1568
1569 ScopedSetInsertion<const uint8_t*> scoped_insert(
1570 &m_RecursionState->parsed_set, pDataStart.data());
1571
1572 uint32_t init_obj_count = m_pObjectHolder->GetPageObjectCount();
1573 AutoNuller<std::unique_ptr<CPDF_StreamParser>> auto_clearer(&m_pSyntax);
1574 m_pSyntax = std::make_unique<CPDF_StreamParser>(
1575 pDataStart, m_pDocument->GetByteStringPool());
1576
1577 while (true) {
1578 uint32_t cost = m_pObjectHolder->GetPageObjectCount() - init_obj_count;
1579 if (max_cost && cost >= max_cost) {
1580 break;
1581 }
1582 switch (m_pSyntax->ParseNextElement()) {
1583 case CPDF_StreamParser::ElementType::kEndOfData:
1584 return m_pSyntax->GetPos();
1585 case CPDF_StreamParser::ElementType::kKeyword:
1586 OnOperator(m_pSyntax->GetWord());
1587 ClearAllParams();
1588 break;
1589 case CPDF_StreamParser::ElementType::kNumber:
1590 AddNumberParam(m_pSyntax->GetWord());
1591 break;
1593 auto word = m_pSyntax->GetWord();
1594 AddNameParam(word.Last(word.GetLength() - 1));
1595 break;
1596 }
1597 default:
1598 AddObjectParam(m_pSyntax->GetObject());
1599 }
1600 }
1601 return m_pSyntax->GetPos();
1602}
1603
1604void CPDF_StreamContentParser::ParsePathObject() {
1605 float params[6] = {};
1606 int nParams = 0;
1607 int last_pos = m_pSyntax->GetPos();
1608 while (true) {
1609 CPDF_StreamParser::ElementType type = m_pSyntax->ParseNextElement();
1610 bool bProcessed = true;
1611 switch (type) {
1613 return;
1615 ByteStringView strc = m_pSyntax->GetWord();
1616 int len = strc.GetLength();
1617 if (len == 1) {
1618 switch (strc[0]) {
1619 case kPathOperatorSubpath:
1620 AddPathPoint({params[0], params[1]},
1622 nParams = 0;
1623 break;
1624 case kPathOperatorLine:
1625 AddPathPoint({params[0], params[1]},
1627 nParams = 0;
1628 break;
1629 case kPathOperatorCubicBezier1:
1630 AddPathPoint({params[0], params[1]},
1632 AddPathPoint({params[2], params[3]},
1634 AddPathPoint({params[4], params[5]},
1636 nParams = 0;
1637 break;
1638 case kPathOperatorCubicBezier2:
1639 AddPathPoint(m_PathCurrent, CFX_Path::Point::Type::kBezier);
1640 AddPathPoint({params[0], params[1]},
1642 AddPathPoint({params[2], params[3]},
1644 nParams = 0;
1645 break;
1646 case kPathOperatorCubicBezier3:
1647 AddPathPoint({params[0], params[1]},
1649 AddPathPoint({params[2], params[3]},
1651 AddPathPoint({params[2], params[3]},
1653 nParams = 0;
1654 break;
1655 case kPathOperatorClosePath:
1656 Handle_ClosePath();
1657 nParams = 0;
1658 break;
1659 default:
1660 bProcessed = false;
1661 break;
1662 }
1663 } else if (len == 2) {
1664 if (strc[0] == kPathOperatorRectangle[0] &&
1665 strc[1] == kPathOperatorRectangle[1]) {
1666 AddPathRect(params[0], params[1], params[2], params[3]);
1667 nParams = 0;
1668 } else {
1669 bProcessed = false;
1670 }
1671 } else {
1672 bProcessed = false;
1673 }
1674 if (bProcessed) {
1675 last_pos = m_pSyntax->GetPos();
1676 }
1677 break;
1678 }
1680 if (nParams == 6)
1681 break;
1682
1683 FX_Number number(m_pSyntax->GetWord());
1684 params[nParams++] = number.GetFloat();
1685 break;
1686 }
1687 default:
1688 bProcessed = false;
1689 }
1690 if (!bProcessed) {
1691 m_pSyntax->SetPos(last_pos);
1692 return;
1693 }
1694 }
1695}
1696
1697// static
1699 ByteStringView abbr) {
1700 return FindFullName(kInlineKeyAbbr, abbr);
1701}
1702
1703// static
1705 ByteStringView abbr) {
1706 return FindFullName(kInlineValueAbbr, abbr);
1707}
1708
1709CPDF_StreamContentParser::ContentParam::ContentParam() = default;
1710
1711CPDF_StreamContentParser::ContentParam::~ContentParam() = default;
CFX_FloatRect(const CFX_FloatRect &that)=default
constexpr CFX_FloatRect()=default
void UpdateRect(const CFX_PointF &point)
void Intersect(const CFX_FloatRect &other_rect)
CFX_FloatRect & operator=(const CFX_FloatRect &that)=default
CFX_Matrix & operator=(const CFX_Matrix &other)=default
CFX_FloatRect TransformRect(const CFX_FloatRect &rect) const
CFX_Matrix(float a1, float b1, float c1, float d1, float e1, float f1)
bool IsIdentity() const
void Concat(const CFX_Matrix &right)
bool m_CloseFigure
Definition cfx_path.h:35
static RetainPtr< CPDF_ColorSpace > GetStockCS(Family family)
CPDF_DictionaryLocker(const CPDF_Dictionary *pDictionary)
uint32_t ComponentBits() const
bool CanReadCoords() const
bool CanReadFlag() const
void SkipBits(uint32_t nbits)
void AppendRect(float left, float bottom, float right, float top)
Definition cpdf_path.cpp:53
void Transform(const CFX_Matrix &matrix)
Definition cpdf_path.cpp:41
ShadingType GetShadingType() const
CPDF_StreamContentParser(CPDF_Document *pDoc, RetainPtr< CPDF_Dictionary > pPageResources, RetainPtr< CPDF_Dictionary > pParentResources, const CFX_Matrix *pmtContentToUser, CPDF_PageObjectHolder *pObjHolder, RetainPtr< CPDF_Dictionary > pResources, const CFX_FloatRect &rcBBox, const CPDF_AllStates *pStates, CPDF_Form::RecursionState *parse_state)
uint32_t Parse(pdfium::span< const uint8_t > pData, uint32_t start_offset, uint32_t max_cost, const std::vector< uint32_t > &stream_start_offsets)
static ByteStringView FindValueAbbreviationForTesting(ByteStringView abbr)
RetainPtr< CPDF_Font > FindFont(const ByteString &name)
static ByteStringView FindKeyAbbreviationForTesting(ByteStringView abbr)
float GetFloat() const
bool operator==(const char *ptr) const
bool IsEmpty() const
Definition bytestring.h:119
bool operator!=(const char *ptr) const
Definition bytestring.h:130
@ kCoonsPatchMeshShading
@ kTensorProductPatchMeshShading
@ kLatticeFormGouraudTriangleMeshShading
@ kFreeFormGouraudTriangleMeshShading
bool TextRenderingModeIsStrokeMode(const TextRenderingMode &mode)
TextRenderingMode
#define FX_FILESIZE
Definition fx_types.h:19
#define CHECK(cvref)