blob: 6d19a6b43085679339c6321b7daa5b22b46f8d3c [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// Copyright 2014 PDFium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Lei Zhangb4e7f302015-11-06 15:52:32 -08007#include "public/fpdf_transformpage.h"
8
dsinclair41872fa2016-10-04 11:29:35 -07009#include "core/fpdfapi/page/cpdf_clippath.h"
10#include "core/fpdfapi/page/cpdf_page.h"
11#include "core/fpdfapi/page/cpdf_pageobject.h"
12#include "core/fpdfapi/page/cpdf_path.h"
dsinclair488b7ad2016-10-04 11:55:50 -070013#include "core/fpdfapi/parser/cpdf_array.h"
14#include "core/fpdfapi/parser/cpdf_document.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"
dsinclair74a34fc2016-09-29 16:41:42 -070018#include "core/fxge/cfx_pathdata.h"
dsinclair114e46a2016-09-29 17:18:21 -070019#include "fpdfsdk/fsdk_define.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070020
Lei Zhang6ac0d2f2015-10-02 10:08:48 -070021namespace {
22
Lei Zhang6ac0d2f2015-10-02 10:08:48 -070023void SetBoundingBox(CPDF_Page* page,
tsepez71a452f2016-05-13 17:51:27 -070024 const CFX_ByteString& key,
Lei Zhang6ac0d2f2015-10-02 10:08:48 -070025 float left,
26 float bottom,
27 float right,
28 float top) {
tsepez0e606b52016-11-18 16:22:41 -080029 CPDF_Array* pBoundingBoxArray = page->m_pFormDict->SetNewFor<CPDF_Array>(key);
tsepez8a3aa452016-11-16 12:26:06 -080030 pBoundingBoxArray->AddNew<CPDF_Number>(left);
31 pBoundingBoxArray->AddNew<CPDF_Number>(bottom);
32 pBoundingBoxArray->AddNew<CPDF_Number>(right);
33 pBoundingBoxArray->AddNew<CPDF_Number>(top);
Lei Zhang6ac0d2f2015-10-02 10:08:48 -070034}
35
tsepez71a452f2016-05-13 17:51:27 -070036bool GetBoundingBox(CPDF_Page* page,
37 const CFX_ByteString& key,
38 float* left,
39 float* bottom,
40 float* right,
41 float* top) {
dsinclair38fd8442016-09-15 10:15:32 -070042 CPDF_Array* pArray = page->m_pFormDict->GetArrayFor(key);
Lei Zhang6ac0d2f2015-10-02 10:08:48 -070043 if (!pArray)
tsepez71a452f2016-05-13 17:51:27 -070044 return false;
Lei Zhang6ac0d2f2015-10-02 10:08:48 -070045
Wei Li9b761132016-01-29 15:44:20 -080046 *left = pArray->GetFloatAt(0);
47 *bottom = pArray->GetFloatAt(1);
48 *right = pArray->GetFloatAt(2);
49 *top = pArray->GetFloatAt(3);
tsepez71a452f2016-05-13 17:51:27 -070050 return true;
Lei Zhang6ac0d2f2015-10-02 10:08:48 -070051}
52
53} // namespace
54
Nico Weber9d8ec5a2015-08-04 13:00:21 -070055DLLEXPORT void STDCALL FPDFPage_SetMediaBox(FPDF_PAGE page,
56 float left,
57 float bottom,
58 float right,
59 float top) {
Tom Sepezdb0be962015-10-16 14:00:21 -070060 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070061 if (!pPage)
62 return;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070063
Lei Zhang6ac0d2f2015-10-02 10:08:48 -070064 SetBoundingBox(pPage, "MediaBox", left, bottom, right, top);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070065}
66
Nico Weber9d8ec5a2015-08-04 13:00:21 -070067DLLEXPORT void STDCALL FPDFPage_SetCropBox(FPDF_PAGE page,
68 float left,
69 float bottom,
70 float right,
71 float top) {
Tom Sepezdb0be962015-10-16 14:00:21 -070072 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070073 if (!pPage)
74 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070075
Lei Zhang6ac0d2f2015-10-02 10:08:48 -070076 SetBoundingBox(pPage, "CropBox", left, bottom, right, top);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070077}
78
Nico Weber9d8ec5a2015-08-04 13:00:21 -070079DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GetMediaBox(FPDF_PAGE page,
80 float* left,
81 float* bottom,
82 float* right,
83 float* top) {
Tom Sepezdb0be962015-10-16 14:00:21 -070084 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Lei Zhang6ac0d2f2015-10-02 10:08:48 -070085 return pPage && GetBoundingBox(pPage, "MediaBox", left, bottom, right, top);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070086}
87
Nico Weber9d8ec5a2015-08-04 13:00:21 -070088DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GetCropBox(FPDF_PAGE page,
89 float* left,
90 float* bottom,
91 float* right,
92 float* top) {
Tom Sepezdb0be962015-10-16 14:00:21 -070093 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Lei Zhang6ac0d2f2015-10-02 10:08:48 -070094 return pPage && GetBoundingBox(pPage, "CropBox", left, bottom, right, top);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070095}
96
Nico Weber9d8ec5a2015-08-04 13:00:21 -070097DLLEXPORT FPDF_BOOL STDCALL FPDFPage_TransFormWithClip(FPDF_PAGE page,
98 FS_MATRIX* matrix,
99 FS_RECTF* clipRect) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700100 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700101 if (!pPage)
tsepez4cf55152016-11-02 14:37:54 -0700102 return false;
Bo Xufdc00a72014-10-28 23:03:33 -0700103
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700104 CFX_ByteTextBuf textBuf;
105 textBuf << "q ";
106 CFX_FloatRect rect(clipRect->left, clipRect->bottom, clipRect->right,
107 clipRect->top);
108 rect.Normalize();
109 CFX_ByteString bsClipping;
110 bsClipping.Format("%f %f %f %f re W* n ", rect.left, rect.bottom,
111 rect.Width(), rect.Height());
112 textBuf << bsClipping;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700113
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700114 CFX_ByteString bsMatix;
115 bsMatix.Format("%f %f %f %f %f %f cm ", matrix->a, matrix->b, matrix->c,
116 matrix->d, matrix->e, matrix->f);
117 textBuf << bsMatix;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700118
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700119 CPDF_Dictionary* pPageDic = pPage->m_pFormDict;
Dan Sinclair2b11dc12015-10-22 15:02:06 -0400120 CPDF_Object* pContentObj =
dsinclair38fd8442016-09-15 10:15:32 -0700121 pPageDic ? pPageDic->GetObjectFor("Contents") : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700122 if (!pContentObj)
dsinclair38fd8442016-09-15 10:15:32 -0700123 pContentObj = pPageDic ? pPageDic->GetArrayFor("Contents") : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700124 if (!pContentObj)
tsepez4cf55152016-11-02 14:37:54 -0700125 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700126
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700127 CPDF_Document* pDoc = pPage->m_pDocument;
128 if (!pDoc)
tsepez4cf55152016-11-02 14:37:54 -0700129 return false;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700130
tsepez9e05ee12016-11-21 13:19:10 -0800131 CPDF_Stream* pStream = pDoc->NewIndirect<CPDF_Stream>(
132 nullptr, 0,
133 pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool()));
tsepez698c5712016-09-28 16:47:07 -0700134 pStream->SetData(textBuf.GetBuffer(), textBuf.GetSize());
tsepez70c4afd2016-11-15 11:33:44 -0800135
tsepez9e05ee12016-11-21 13:19:10 -0800136 CPDF_Stream* pEndStream = pDoc->NewIndirect<CPDF_Stream>(
137 nullptr, 0,
138 pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool()));
tsepeze6db16e2016-09-19 10:45:09 -0700139 pEndStream->SetData((const uint8_t*)" Q", 2);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700140
Dan Sinclair2b11dc12015-10-22 15:02:06 -0400141 CPDF_Array* pContentArray = nullptr;
weilidb444d22016-06-02 15:48:15 -0700142 CPDF_Array* pArray = ToArray(pContentObj);
143 if (pArray) {
Dan Sinclair2b11dc12015-10-22 15:02:06 -0400144 pContentArray = pArray;
tsepez8a3aa452016-11-16 12:26:06 -0800145 pContentArray->InsertNewAt<CPDF_Reference>(0, pDoc, pStream->GetObjNum());
146 pContentArray->AddNew<CPDF_Reference>(pDoc, pEndStream->GetObjNum());
Dan Sinclairbf81c142015-10-26 16:54:39 -0400147 } else if (CPDF_Reference* pReference = ToReference(pContentObj)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700148 CPDF_Object* pDirectObj = pReference->GetDirect();
Dan Sinclair2b11dc12015-10-22 15:02:06 -0400149 if (pDirectObj) {
weilidb444d22016-06-02 15:48:15 -0700150 CPDF_Array* pObjArray = pDirectObj->AsArray();
151 if (pObjArray) {
152 pContentArray = pObjArray;
tsepez8a3aa452016-11-16 12:26:06 -0800153 pContentArray->InsertNewAt<CPDF_Reference>(0, pDoc,
154 pStream->GetObjNum());
155 pContentArray->AddNew<CPDF_Reference>(pDoc, pEndStream->GetObjNum());
Dan Sinclairaa435ba2015-10-22 16:45:48 -0400156 } else if (pDirectObj->IsStream()) {
tsepez70c4afd2016-11-15 11:33:44 -0800157 pContentArray = pDoc->NewIndirect<CPDF_Array>();
tsepez8a3aa452016-11-16 12:26:06 -0800158 pContentArray->AddNew<CPDF_Reference>(pDoc, pStream->GetObjNum());
159 pContentArray->AddNew<CPDF_Reference>(pDoc, pDirectObj->GetObjNum());
160 pContentArray->AddNew<CPDF_Reference>(pDoc, pEndStream->GetObjNum());
tsepez0e606b52016-11-18 16:22:41 -0800161 pPageDic->SetNewFor<CPDF_Reference>("Contents", pDoc,
162 pContentArray->GetObjNum());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700163 }
164 }
165 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700166
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700167 // Need to transform the patterns as well.
dsinclair38fd8442016-09-15 10:15:32 -0700168 CPDF_Dictionary* pRes = pPageDic->GetDictFor("Resources");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700169 if (pRes) {
dsinclair38fd8442016-09-15 10:15:32 -0700170 CPDF_Dictionary* pPattenDict = pRes->GetDictFor("Pattern");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700171 if (pPattenDict) {
Oliver Chang3f1c71f2016-01-11 08:45:31 -0800172 for (const auto& it : *pPattenDict) {
tsepez0e606b52016-11-18 16:22:41 -0800173 CPDF_Object* pObj = it.second.get();
Dan Sinclairbf81c142015-10-26 16:54:39 -0400174 if (pObj->IsReference())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700175 pObj = pObj->GetDirect();
Dan Sinclairaa435ba2015-10-22 16:45:48 -0400176
Oliver Chang3f1c71f2016-01-11 08:45:31 -0800177 CPDF_Dictionary* pDict = nullptr;
Dan Sinclairaa435ba2015-10-22 16:45:48 -0400178 if (pObj->IsDictionary())
Dan Sinclairf1251c12015-10-20 16:24:45 -0400179 pDict = pObj->AsDictionary();
weilidb444d22016-06-02 15:48:15 -0700180 else if (CPDF_Stream* pObjStream = pObj->AsStream())
181 pDict = pObjStream->GetDict();
Dan Sinclairaa435ba2015-10-22 16:45:48 -0400182 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700183 continue;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700184
dsinclair38fd8442016-09-15 10:15:32 -0700185 CFX_Matrix m = pDict->GetMatrixFor("Matrix");
Tom Sepez60d909e2015-12-10 15:34:55 -0800186 CFX_Matrix t = *(CFX_Matrix*)matrix;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700187 m.Concat(t);
dsinclair38fd8442016-09-15 10:15:32 -0700188 pDict->SetMatrixFor("Matrix", m);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700189 }
190 }
191 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700192
tsepez4cf55152016-11-02 14:37:54 -0700193 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700194}
195
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700196DLLEXPORT void STDCALL
197FPDFPageObj_TransformClipPath(FPDF_PAGEOBJECT page_object,
198 double a,
199 double b,
200 double c,
201 double d,
202 double e,
203 double f) {
204 CPDF_PageObject* pPageObj = (CPDF_PageObject*)page_object;
Lei Zhang412e9082015-12-14 18:34:00 -0800205 if (!pPageObj)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700206 return;
Tom Sepez60d909e2015-12-10 15:34:55 -0800207 CFX_Matrix matrix((FX_FLOAT)a, (FX_FLOAT)b, (FX_FLOAT)c, (FX_FLOAT)d,
208 (FX_FLOAT)e, (FX_FLOAT)f);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700209
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700210 // Special treatment to shading object, because the ClipPath for shading
211 // object is already transformed.
Wei Li7cf13c92016-02-19 11:53:03 -0800212 if (!pPageObj->IsShading())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700213 pPageObj->TransformClipPath(matrix);
214 pPageObj->TransformGeneralState(matrix);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700215}
216
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700217DLLEXPORT FPDF_CLIPPATH STDCALL FPDF_CreateClipPath(float left,
218 float bottom,
219 float right,
220 float top) {
tsepezfc1d16f2016-09-02 15:45:22 -0700221 CPDF_Path Path;
222 Path.AppendRect(left, bottom, right, top);
223
Tom Sepezae51c812015-08-05 12:34:06 -0700224 CPDF_ClipPath* pNewClipPath = new CPDF_ClipPath();
tsepez4cf55152016-11-02 14:37:54 -0700225 pNewClipPath->AppendPath(Path, FXFILL_ALTERNATE, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700226 return pNewClipPath;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700227}
228
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700229DLLEXPORT void STDCALL FPDF_DestroyClipPath(FPDF_CLIPPATH clipPath) {
230 delete (CPDF_ClipPath*)clipPath;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700231}
232
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700233void OutputPath(CFX_ByteTextBuf& buf, CPDF_Path path) {
tsepez7d2a8d92016-06-08 11:51:23 -0700234 const CFX_PathData* pPathData = path.GetObject();
Lei Zhang412e9082015-12-14 18:34:00 -0800235 if (!pPathData)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700236 return;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700237
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700238 FX_PATHPOINT* pPoints = pPathData->GetPoints();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700239
tsepez59601432016-08-29 14:26:57 -0700240 if (path.IsRect()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700241 buf << (pPoints[0].m_PointX) << " " << (pPoints[0].m_PointY) << " "
242 << (pPoints[2].m_PointX - pPoints[0].m_PointX) << " "
243 << (pPoints[2].m_PointY - pPoints[0].m_PointY) << " re\n";
244 return;
245 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700246
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700247 CFX_ByteString temp;
248 for (int i = 0; i < pPathData->GetPointCount(); i++) {
249 buf << (pPoints[i].m_PointX) << " " << (pPoints[i].m_PointY);
Nicolas Pena79365f72017-02-07 14:21:36 -0500250 FXPT_TYPE point_type = pPoints[i].m_Type;
251 if (point_type == FXPT_TYPE::MoveTo) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700252 buf << " m\n";
Nicolas Pena79365f72017-02-07 14:21:36 -0500253 } else if (point_type == FXPT_TYPE::BezierTo) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700254 buf << " " << (pPoints[i + 1].m_PointX) << " "
255 << (pPoints[i + 1].m_PointY) << " " << (pPoints[i + 2].m_PointX)
256 << " " << (pPoints[i + 2].m_PointY);
Nicolas Pena79365f72017-02-07 14:21:36 -0500257 if (pPoints[i + 2].m_CloseFigure)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700258 buf << " c h\n";
259 else
260 buf << " c\n";
261 i += 2;
Nicolas Pena79365f72017-02-07 14:21:36 -0500262 } else if (point_type == FXPT_TYPE::LineTo) {
263 if (pPoints[i].m_CloseFigure)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700264 buf << " l h\n";
265 else
266 buf << " l\n";
267 }
268 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700269}
270
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700271DLLEXPORT void STDCALL FPDFPage_InsertClipPath(FPDF_PAGE page,
272 FPDF_CLIPPATH clipPath) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700273 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700274 if (!pPage)
275 return;
Lei Zhang6ac0d2f2015-10-02 10:08:48 -0700276
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700277 CPDF_Dictionary* pPageDic = pPage->m_pFormDict;
Dan Sinclair2b11dc12015-10-22 15:02:06 -0400278 CPDF_Object* pContentObj =
dsinclair38fd8442016-09-15 10:15:32 -0700279 pPageDic ? pPageDic->GetObjectFor("Contents") : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700280 if (!pContentObj)
dsinclair38fd8442016-09-15 10:15:32 -0700281 pContentObj = pPageDic ? pPageDic->GetArrayFor("Contents") : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700282 if (!pContentObj)
283 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700284
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700285 CFX_ByteTextBuf strClip;
286 CPDF_ClipPath* pClipPath = (CPDF_ClipPath*)clipPath;
tsepezc3255f52016-03-25 14:52:27 -0700287 uint32_t i;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700288 for (i = 0; i < pClipPath->GetPathCount(); i++) {
289 CPDF_Path path = pClipPath->GetPath(i);
290 int iClipType = pClipPath->GetClipType(i);
tsepez59601432016-08-29 14:26:57 -0700291 if (path.GetPointCount() == 0) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700292 // Empty clipping (totally clipped out)
293 strClip << "0 0 m W n ";
294 } else {
295 OutputPath(strClip, path);
296 if (iClipType == FXFILL_WINDING)
297 strClip << "W n\n";
298 else
299 strClip << "W* n\n";
300 }
301 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700302 CPDF_Document* pDoc = pPage->m_pDocument;
303 if (!pDoc)
304 return;
tsepezbb577af2016-09-21 19:10:19 -0700305
tsepez9e05ee12016-11-21 13:19:10 -0800306 CPDF_Stream* pStream = pDoc->NewIndirect<CPDF_Stream>(
307 nullptr, 0,
308 pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool()));
tsepez698c5712016-09-28 16:47:07 -0700309 pStream->SetData(strClip.GetBuffer(), strClip.GetSize());
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700310
weilidb444d22016-06-02 15:48:15 -0700311 CPDF_Array* pArray = ToArray(pContentObj);
312 if (pArray) {
tsepez8a3aa452016-11-16 12:26:06 -0800313 pArray->InsertNewAt<CPDF_Reference>(0, pDoc, pStream->GetObjNum());
314 return;
315 }
316 CPDF_Reference* pReference = ToReference(pContentObj);
317 if (!pReference)
318 return;
319
320 CPDF_Object* pDirectObj = pReference->GetDirect();
321 if (!pDirectObj)
322 return;
323
324 CPDF_Array* pObjArray = pDirectObj->AsArray();
325 if (pObjArray) {
326 pObjArray->InsertNewAt<CPDF_Reference>(0, pDoc, pStream->GetObjNum());
327 return;
328 }
329 if (pDirectObj->IsStream()) {
330 CPDF_Array* pContentArray = pDoc->NewIndirect<CPDF_Array>();
331 pContentArray->AddNew<CPDF_Reference>(pDoc, pStream->GetObjNum());
332 pContentArray->AddNew<CPDF_Reference>(pDoc, pDirectObj->GetObjNum());
tsepez0e606b52016-11-18 16:22:41 -0800333 pPageDic->SetNewFor<CPDF_Reference>("Contents", pDoc,
334 pContentArray->GetObjNum());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700335 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700336}