| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 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 "../include/fsdk_define.h" | 7 #include "../include/fsdk_define.h" |
| 8 #include "../include/fpdf_transformpage.h" | 8 #include "../include/fpdf_transformpage.h" |
| 9 | 9 |
| 10 DLLEXPORT void STDCALL FPDFPage_SetMediaBox(FPDF_PAGE page, float left, float bo
ttom, float right, float top) | 10 DLLEXPORT void STDCALL FPDFPage_SetMediaBox(FPDF_PAGE page, float left, float bo
ttom, float right, float top) |
| 11 { | 11 { |
| 12 if(!page) | 12 if(!page) |
| 13 return; | 13 return; |
| 14 |
| 14 CPDF_Page* pPage = (CPDF_Page*)page; | 15 CPDF_Page* pPage = (CPDF_Page*)page; |
| 15 CPDF_Dictionary* pPageDict = pPage->m_pFormDict; | 16 CPDF_Dictionary* pPageDict = pPage->m_pFormDict; |
| 16 » CPDF_Array* pMediaBoxArray = FX_NEW CPDF_Array; | 17 » CPDF_Array* pMediaBoxArray = new CPDF_Array; |
| 17 » pMediaBoxArray->Add(FX_NEW CPDF_Number(left)); | 18 » pMediaBoxArray->Add(new CPDF_Number(left)); |
| 18 » pMediaBoxArray->Add(FX_NEW CPDF_Number(bottom)); | 19 » pMediaBoxArray->Add(new CPDF_Number(bottom)); |
| 19 » pMediaBoxArray->Add(FX_NEW CPDF_Number(FX_FLOAT(right))); | 20 » pMediaBoxArray->Add(new CPDF_Number(FX_FLOAT(right))); |
| 20 » pMediaBoxArray->Add(FX_NEW CPDF_Number(FX_FLOAT(top))); | 21 » pMediaBoxArray->Add(new CPDF_Number(FX_FLOAT(top))); |
| 21 » | |
| 22 pPageDict->SetAt("MediaBox", pMediaBoxArray); | 22 pPageDict->SetAt("MediaBox", pMediaBoxArray); |
| 23 } | 23 } |
| 24 | 24 |
| 25 | 25 |
| 26 DLLEXPORT void STDCALL FPDFPage_SetCropBox(FPDF_PAGE page, float left, float bot
tom, float right, float top) | 26 DLLEXPORT void STDCALL FPDFPage_SetCropBox(FPDF_PAGE page, float left, float bot
tom, float right, float top) |
| 27 { | 27 { |
| 28 if(!page) | 28 if(!page) |
| 29 return; | 29 return; |
| 30 |
| 30 CPDF_Page* pPage = (CPDF_Page*)page; | 31 CPDF_Page* pPage = (CPDF_Page*)page; |
| 31 CPDF_Dictionary* pPageDict = pPage->m_pFormDict; | 32 CPDF_Dictionary* pPageDict = pPage->m_pFormDict; |
| 32 » CPDF_Array* pCropBoxArray = FX_NEW CPDF_Array; | 33 » CPDF_Array* pCropBoxArray = new CPDF_Array; |
| 33 » pCropBoxArray->Add(FX_NEW CPDF_Number(left)); | 34 » pCropBoxArray->Add(new CPDF_Number(left)); |
| 34 » pCropBoxArray->Add(FX_NEW CPDF_Number(bottom)); | 35 » pCropBoxArray->Add(new CPDF_Number(bottom)); |
| 35 » pCropBoxArray->Add(FX_NEW CPDF_Number(FX_FLOAT(right))); | 36 » pCropBoxArray->Add(new CPDF_Number(FX_FLOAT(right))); |
| 36 » pCropBoxArray->Add(FX_NEW CPDF_Number(FX_FLOAT(top))); | 37 » pCropBoxArray->Add(new CPDF_Number(FX_FLOAT(top))); |
| 37 » | |
| 38 » | |
| 39 pPageDict->SetAt("CropBox", pCropBoxArray); | 38 pPageDict->SetAt("CropBox", pCropBoxArray); |
| 40 } | 39 } |
| 41 | 40 |
| 42 | 41 |
| 43 DLLEXPORT FX_BOOL STDCALL FPDFPage_GetMediaBox(FPDF_PAGE page, float* left, floa
t* bottom, float* right, float* top) | 42 DLLEXPORT FX_BOOL STDCALL FPDFPage_GetMediaBox(FPDF_PAGE page, float* left, floa
t* bottom, float* right, float* top) |
| 44 { | 43 { |
| 45 if(!page) | 44 if(!page) |
| 46 return FALSE; | 45 return FALSE; |
| 47 CPDF_Page* pPage = (CPDF_Page*)page; | 46 CPDF_Page* pPage = (CPDF_Page*)page; |
| 48 CPDF_Dictionary* pPageDict = pPage->m_pFormDict; | 47 CPDF_Dictionary* pPageDict = pPage->m_pFormDict; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 94 |
| 96 | 95 |
| 97 CPDF_Page* pPage = (CPDF_Page*)page; | 96 CPDF_Page* pPage = (CPDF_Page*)page; |
| 98 CPDF_Dictionary* pPageDic = pPage->m_pFormDict; | 97 CPDF_Dictionary* pPageDic = pPage->m_pFormDict; |
| 99 CPDF_Object* pContentObj = pPageDic ? pPageDic->GetElement("Contents") :
NULL; | 98 CPDF_Object* pContentObj = pPageDic ? pPageDic->GetElement("Contents") :
NULL; |
| 100 if(!pContentObj) | 99 if(!pContentObj) |
| 101 pContentObj = pPageDic ? pPageDic->GetArray("Contents") : NULL; | 100 pContentObj = pPageDic ? pPageDic->GetArray("Contents") : NULL; |
| 102 if(!pContentObj) | 101 if(!pContentObj) |
| 103 return FALSE; | 102 return FALSE; |
| 104 | 103 |
| 105 » CPDF_Dictionary* pDic = FX_NEW CPDF_Dictionary; | 104 » CPDF_Dictionary* pDic = new CPDF_Dictionary; |
| 106 » CPDF_Stream* pStream = FX_NEW CPDF_Stream(NULL,0, pDic); | 105 » CPDF_Stream* pStream = new CPDF_Stream(NULL,0, pDic); |
| 107 pStream->SetData(textBuf.GetBuffer(), textBuf.GetSize(), FALSE, FALSE); | 106 pStream->SetData(textBuf.GetBuffer(), textBuf.GetSize(), FALSE, FALSE); |
| 108 CPDF_Document* pDoc = pPage->m_pDocument; | 107 CPDF_Document* pDoc = pPage->m_pDocument; |
| 109 if(!pDoc) | 108 if(!pDoc) |
| 110 return FALSE; | 109 return FALSE; |
| 111 pDoc->AddIndirectObject(pStream); | 110 pDoc->AddIndirectObject(pStream); |
| 112 | 111 |
| 113 » pDic = FX_NEW CPDF_Dictionary; | 112 » pDic = new CPDF_Dictionary; |
| 114 » CPDF_Stream* pEndStream = FX_NEW CPDF_Stream(NULL,0, pDic); | 113 » CPDF_Stream* pEndStream = new CPDF_Stream(NULL,0, pDic); |
| 115 pEndStream->SetData((FX_LPCBYTE)" Q", 2, FALSE, FALSE); | 114 pEndStream->SetData((FX_LPCBYTE)" Q", 2, FALSE, FALSE); |
| 116 pDoc->AddIndirectObject(pEndStream); | 115 pDoc->AddIndirectObject(pEndStream); |
| 117 | 116 |
| 118 CPDF_Array* pContentArray = NULL; | 117 CPDF_Array* pContentArray = NULL; |
| 119 if (pContentObj && pContentObj->GetType() == PDFOBJ_ARRAY) | 118 if (pContentObj && pContentObj->GetType() == PDFOBJ_ARRAY) |
| 120 { | 119 { |
| 121 pContentArray = (CPDF_Array*)pContentObj; | 120 pContentArray = (CPDF_Array*)pContentObj; |
| 122 » » CPDF_Reference* pRef = FX_NEW CPDF_Reference(pDoc, pStream->GetO
bjNum()); | 121 » » CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjN
um()); |
| 123 pContentArray->InsertAt(0, pRef); | 122 pContentArray->InsertAt(0, pRef); |
| 124 pContentArray->AddReference(pDoc,pEndStream); | 123 pContentArray->AddReference(pDoc,pEndStream); |
| 125 | 124 |
| 126 } | 125 } |
| 127 else if(pContentObj && pContentObj->GetType() == PDFOBJ_REFERENCE) | 126 else if(pContentObj && pContentObj->GetType() == PDFOBJ_REFERENCE) |
| 128 { | 127 { |
| 129 CPDF_Reference* pReference = (CPDF_Reference*)pContentObj; | 128 CPDF_Reference* pReference = (CPDF_Reference*)pContentObj; |
| 130 CPDF_Object* pDirectObj = pReference->GetDirect(); | 129 CPDF_Object* pDirectObj = pReference->GetDirect(); |
| 131 if(pDirectObj != NULL) | 130 if(pDirectObj != NULL) |
| 132 { | 131 { |
| 133 if(pDirectObj->GetType() == PDFOBJ_ARRAY) | 132 if(pDirectObj->GetType() == PDFOBJ_ARRAY) |
| 134 { | 133 { |
| 135 pContentArray = (CPDF_Array*)pDirectObj; | 134 pContentArray = (CPDF_Array*)pDirectObj; |
| 136 » » » » CPDF_Reference* pRef = FX_NEW CPDF_Reference(pDo
c, pStream->GetObjNum()); | 135 » » » » CPDF_Reference* pRef = new CPDF_Reference(pDoc,
pStream->GetObjNum()); |
| 137 pContentArray->InsertAt(0, pRef); | 136 pContentArray->InsertAt(0, pRef); |
| 138 pContentArray->AddReference(pDoc,pEndStream); | 137 pContentArray->AddReference(pDoc,pEndStream); |
| 139 | |
| 140 } | 138 } |
| 141 else if(pDirectObj->GetType() == PDFOBJ_STREAM) | 139 else if(pDirectObj->GetType() == PDFOBJ_STREAM) |
| 142 { | 140 { |
| 143 » » » » pContentArray = FX_NEW CPDF_Array(); | 141 » » » » pContentArray = new CPDF_Array(); |
| 144 pContentArray->AddReference(pDoc,pStream->GetObj
Num()); | 142 pContentArray->AddReference(pDoc,pStream->GetObj
Num()); |
| 145 pContentArray->AddReference(pDoc,pDirectObj->Get
ObjNum()); | 143 pContentArray->AddReference(pDoc,pDirectObj->Get
ObjNum()); |
| 146 pContentArray->AddReference(pDoc, pEndStream); | 144 pContentArray->AddReference(pDoc, pEndStream); |
| 147 pPageDic->SetAtReference("Contents", pDoc, pDoc-
>AddIndirectObject(pContentArray)); | 145 pPageDic->SetAtReference("Contents", pDoc, pDoc-
>AddIndirectObject(pContentArray)); |
| 148 } | 146 } |
| 149 } | 147 } |
| 150 » }» | 148 » } |
| 151 | 149 |
| 152 //Need to transform the patterns as well. | 150 //Need to transform the patterns as well. |
| 153 CPDF_Dictionary* pRes = pPageDic->GetDict(FX_BSTRC("Resources")); | 151 CPDF_Dictionary* pRes = pPageDic->GetDict(FX_BSTRC("Resources")); |
| 154 if(pRes) | 152 if(pRes) |
| 155 { | 153 { |
| 156 CPDF_Dictionary* pPattenDict = pRes->GetDict(FX_BSTRC("Pattern")
); | 154 CPDF_Dictionary* pPattenDict = pRes->GetDict(FX_BSTRC("Pattern")
); |
| 157 if(pPattenDict) | 155 if(pPattenDict) |
| 158 { | 156 { |
| 159 FX_POSITION pos = pPattenDict->GetStartPos(); | 157 FX_POSITION pos = pPattenDict->GetStartPos(); |
| 160 while(pos) | 158 while(pos) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 | 193 |
| 196 //Special treatment to shading object, because the ClipPath for shading
object is already transformed. | 194 //Special treatment to shading object, because the ClipPath for shading
object is already transformed. |
| 197 if(pPageObj->m_Type != PDFPAGE_SHADING) | 195 if(pPageObj->m_Type != PDFPAGE_SHADING) |
| 198 pPageObj->TransformClipPath(matrix); | 196 pPageObj->TransformClipPath(matrix); |
| 199 pPageObj->TransformGeneralState(matrix); | 197 pPageObj->TransformGeneralState(matrix); |
| 200 } | 198 } |
| 201 | 199 |
| 202 | 200 |
| 203 DLLEXPORT FPDF_CLIPPATH STDCALL FPDF_CreateClipPath(float left, float bottom, fl
oat right, float top) | 201 DLLEXPORT FPDF_CLIPPATH STDCALL FPDF_CreateClipPath(float left, float bottom, fl
oat right, float top) |
| 204 { | 202 { |
| 205 » CPDF_ClipPath* pNewClipPath = FX_NEW CPDF_ClipPath(); | 203 » CPDF_ClipPath* pNewClipPath = new CPDF_ClipPath(); |
| 206 pNewClipPath->GetModify(); | 204 pNewClipPath->GetModify(); |
| 207 CPDF_Path Path; | 205 CPDF_Path Path; |
| 208 Path.GetModify(); | 206 Path.GetModify(); |
| 209 Path.AppendRect(left, bottom, right, top); | 207 Path.AppendRect(left, bottom, right, top); |
| 210 pNewClipPath->AppendPath(Path, FXFILL_ALTERNATE, FALSE); | 208 pNewClipPath->AppendPath(Path, FXFILL_ALTERNATE, FALSE); |
| 211 return pNewClipPath; | 209 return pNewClipPath; |
| 212 } | 210 } |
| 213 | 211 |
| 214 DLLEXPORT void STDCALL FPDF_DestroyClipPath(FPDF_CLIPPATH clipPath) | 212 DLLEXPORT void STDCALL FPDF_DestroyClipPath(FPDF_CLIPPATH clipPath) |
| 215 { | 213 { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 // Empty clipping (totally clipped out) | 274 // Empty clipping (totally clipped out) |
| 277 strClip << "0 0 m W n "; | 275 strClip << "0 0 m W n "; |
| 278 } else { | 276 } else { |
| 279 OutputPath(strClip, path); | 277 OutputPath(strClip, path); |
| 280 if (iClipType == FXFILL_WINDING) | 278 if (iClipType == FXFILL_WINDING) |
| 281 strClip << "W n\n"; | 279 strClip << "W n\n"; |
| 282 else | 280 else |
| 283 strClip << "W* n\n"; | 281 strClip << "W* n\n"; |
| 284 } | 282 } |
| 285 } | 283 } |
| 286 » CPDF_Dictionary* pDic = FX_NEW CPDF_Dictionary; | 284 » CPDF_Dictionary* pDic = new CPDF_Dictionary; |
| 287 » CPDF_Stream* pStream = FX_NEW CPDF_Stream(NULL,0, pDic); | 285 » CPDF_Stream* pStream = new CPDF_Stream(NULL,0, pDic); |
| 288 pStream->SetData(strClip.GetBuffer(), strClip.GetSize(), FALSE, FALSE); | 286 pStream->SetData(strClip.GetBuffer(), strClip.GetSize(), FALSE, FALSE); |
| 289 CPDF_Document* pDoc = pPage->m_pDocument; | 287 CPDF_Document* pDoc = pPage->m_pDocument; |
| 290 if(!pDoc) | 288 if(!pDoc) |
| 291 return; | 289 return; |
| 292 pDoc->AddIndirectObject(pStream); | 290 pDoc->AddIndirectObject(pStream); |
| 293 | 291 |
| 294 CPDF_Array* pContentArray = NULL; | 292 CPDF_Array* pContentArray = NULL; |
| 295 if (pContentObj && pContentObj->GetType() == PDFOBJ_ARRAY) | 293 if (pContentObj && pContentObj->GetType() == PDFOBJ_ARRAY) |
| 296 { | 294 { |
| 297 pContentArray = (CPDF_Array*)pContentObj; | 295 pContentArray = (CPDF_Array*)pContentObj; |
| 298 » » CPDF_Reference* pRef = FX_NEW CPDF_Reference(pDoc, pStream->GetO
bjNum()); | 296 » » CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjN
um()); |
| 299 pContentArray->InsertAt(0, pRef); | 297 pContentArray->InsertAt(0, pRef); |
| 300 | |
| 301 } | 298 } |
| 302 else if(pContentObj && pContentObj->GetType() == PDFOBJ_REFERENCE) | 299 else if(pContentObj && pContentObj->GetType() == PDFOBJ_REFERENCE) |
| 303 { | 300 { |
| 304 CPDF_Reference* pReference = (CPDF_Reference*)pContentObj; | 301 CPDF_Reference* pReference = (CPDF_Reference*)pContentObj; |
| 305 CPDF_Object* pDirectObj = pReference->GetDirect(); | 302 CPDF_Object* pDirectObj = pReference->GetDirect(); |
| 306 if(pDirectObj != NULL) | 303 if(pDirectObj != NULL) |
| 307 { | 304 { |
| 308 if(pDirectObj->GetType() == PDFOBJ_ARRAY) | 305 if(pDirectObj->GetType() == PDFOBJ_ARRAY) |
| 309 { | 306 { |
| 310 pContentArray = (CPDF_Array*)pDirectObj; | 307 pContentArray = (CPDF_Array*)pDirectObj; |
| 311 » » » » CPDF_Reference* pRef = FX_NEW CPDF_Reference(pDo
c, pStream->GetObjNum()); | 308 » » » » CPDF_Reference* pRef = new CPDF_Reference(pDoc,
pStream->GetObjNum()); |
| 312 pContentArray->InsertAt(0, pRef); | 309 pContentArray->InsertAt(0, pRef); |
| 313 | |
| 314 } | 310 } |
| 315 else if(pDirectObj->GetType() == PDFOBJ_STREAM) | 311 else if(pDirectObj->GetType() == PDFOBJ_STREAM) |
| 316 { | 312 { |
| 317 » » » » pContentArray = FX_NEW CPDF_Array(); | 313 » » » » pContentArray = new CPDF_Array(); |
| 318 pContentArray->AddReference(pDoc,pStream->GetObj
Num()); | 314 pContentArray->AddReference(pDoc,pStream->GetObj
Num()); |
| 319 pContentArray->AddReference(pDoc,pDirectObj->Get
ObjNum()); | 315 pContentArray->AddReference(pDoc,pDirectObj->Get
ObjNum()); |
| 320 pPageDic->SetAtReference("Contents", pDoc, pDoc-
>AddIndirectObject(pContentArray)); | 316 pPageDic->SetAtReference("Contents", pDoc, pDoc-
>AddIndirectObject(pContentArray)); |
| 321 } | 317 } |
| 322 } | 318 } |
| 323 » }» | 319 » } |
| 324 } | 320 } |
| 325 | 321 |
| OLD | NEW |