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 "../../public/fpdf_transformpage.h" | 7 #include "../../public/fpdf_transformpage.h" |
8 #include "../include/fsdk_define.h" | 8 #include "../include/fsdk_define.h" |
9 #include "../include/fpdfxfa/fpdfxfa_doc.h" | 9 #include "../include/fpdfxfa/fpdfxfa_doc.h" |
10 #include "../include/fpdfxfa/fpdfxfa_page.h" | 10 #include "../include/fpdfxfa/fpdfxfa_page.h" |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 CPDF_Page* GetPageFromFPDFPage(FPDF_PAGE page) { | |
15 return page ? static_cast<CPDFXFA_Page*>(page)->GetPDFPage() : nullptr; | |
16 } | |
17 | |
18 void SetBoundingBox(CPDF_Page* page, | 14 void SetBoundingBox(CPDF_Page* page, |
19 const CFX_ByteStringC& key, | 15 const CFX_ByteStringC& key, |
20 float left, | 16 float left, |
21 float bottom, | 17 float bottom, |
22 float right, | 18 float right, |
23 float top) { | 19 float top) { |
24 CPDF_Dictionary* pPageDict = page->m_pFormDict; | 20 CPDF_Dictionary* pPageDict = page->m_pFormDict; |
25 CPDF_Array* pBoundingBoxArray = new CPDF_Array; | 21 CPDF_Array* pBoundingBoxArray = new CPDF_Array; |
26 pBoundingBoxArray->Add(new CPDF_Number(left)); | 22 pBoundingBoxArray->Add(new CPDF_Number(left)); |
27 pBoundingBoxArray->Add(new CPDF_Number(bottom)); | 23 pBoundingBoxArray->Add(new CPDF_Number(bottom)); |
(...skipping 20 matching lines...) Expand all Loading... |
48 return TRUE; | 44 return TRUE; |
49 } | 45 } |
50 | 46 |
51 } // namespace | 47 } // namespace |
52 | 48 |
53 DLLEXPORT void STDCALL FPDFPage_SetMediaBox(FPDF_PAGE page, | 49 DLLEXPORT void STDCALL FPDFPage_SetMediaBox(FPDF_PAGE page, |
54 float left, | 50 float left, |
55 float bottom, | 51 float bottom, |
56 float right, | 52 float right, |
57 float top) { | 53 float top) { |
58 CPDF_Page* pPage = GetPageFromFPDFPage(page); | 54 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
59 if (!pPage) | 55 if (!pPage) |
60 return; | 56 return; |
61 | 57 |
62 SetBoundingBox(pPage, "MediaBox", left, bottom, right, top); | 58 SetBoundingBox(pPage, "MediaBox", left, bottom, right, top); |
63 } | 59 } |
64 | 60 |
65 DLLEXPORT void STDCALL FPDFPage_SetCropBox(FPDF_PAGE page, | 61 DLLEXPORT void STDCALL FPDFPage_SetCropBox(FPDF_PAGE page, |
66 float left, | 62 float left, |
67 float bottom, | 63 float bottom, |
68 float right, | 64 float right, |
69 float top) { | 65 float top) { |
70 CPDF_Page* pPage = GetPageFromFPDFPage(page); | 66 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
71 if (!pPage) | 67 if (!pPage) |
72 return; | 68 return; |
73 | 69 |
74 SetBoundingBox(pPage, "CropBox", left, bottom, right, top); | 70 SetBoundingBox(pPage, "CropBox", left, bottom, right, top); |
75 } | 71 } |
76 | 72 |
77 DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GetMediaBox(FPDF_PAGE page, | 73 DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GetMediaBox(FPDF_PAGE page, |
78 float* left, | 74 float* left, |
79 float* bottom, | 75 float* bottom, |
80 float* right, | 76 float* right, |
81 float* top) { | 77 float* top) { |
82 CPDF_Page* pPage = GetPageFromFPDFPage(page); | 78 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
83 return pPage && GetBoundingBox(pPage, "MediaBox", left, bottom, right, top); | 79 return pPage && GetBoundingBox(pPage, "MediaBox", left, bottom, right, top); |
84 } | 80 } |
85 | 81 |
86 DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GetCropBox(FPDF_PAGE page, | 82 DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GetCropBox(FPDF_PAGE page, |
87 float* left, | 83 float* left, |
88 float* bottom, | 84 float* bottom, |
89 float* right, | 85 float* right, |
90 float* top) { | 86 float* top) { |
91 CPDF_Page* pPage = GetPageFromFPDFPage(page); | 87 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
92 return pPage && GetBoundingBox(pPage, "CropBox", left, bottom, right, top); | 88 return pPage && GetBoundingBox(pPage, "CropBox", left, bottom, right, top); |
93 } | 89 } |
94 | 90 |
95 DLLEXPORT FPDF_BOOL STDCALL FPDFPage_TransFormWithClip(FPDF_PAGE page, | 91 DLLEXPORT FPDF_BOOL STDCALL FPDFPage_TransFormWithClip(FPDF_PAGE page, |
96 FS_MATRIX* matrix, | 92 FS_MATRIX* matrix, |
97 FS_RECTF* clipRect) { | 93 FS_RECTF* clipRect) { |
98 CPDF_Page* pPage = GetPageFromFPDFPage(page); | 94 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
99 if (!pPage) | 95 if (!pPage) |
100 return FALSE; | 96 return FALSE; |
101 | 97 |
102 CFX_ByteTextBuf textBuf; | 98 CFX_ByteTextBuf textBuf; |
103 textBuf << "q "; | 99 textBuf << "q "; |
104 CFX_FloatRect rect(clipRect->left, clipRect->bottom, clipRect->right, | 100 CFX_FloatRect rect(clipRect->left, clipRect->bottom, clipRect->right, |
105 clipRect->top); | 101 clipRect->top); |
106 rect.Normalize(); | 102 rect.Normalize(); |
107 CFX_ByteString bsClipping; | 103 CFX_ByteString bsClipping; |
108 bsClipping.Format("%f %f %f %f re W* n ", rect.left, rect.bottom, | 104 bsClipping.Format("%f %f %f %f re W* n ", rect.left, rect.bottom, |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 if (pPoints[i].m_Flag & FXPT_CLOSEFIGURE) | 257 if (pPoints[i].m_Flag & FXPT_CLOSEFIGURE) |
262 buf << " l h\n"; | 258 buf << " l h\n"; |
263 else | 259 else |
264 buf << " l\n"; | 260 buf << " l\n"; |
265 } | 261 } |
266 } | 262 } |
267 } | 263 } |
268 | 264 |
269 DLLEXPORT void STDCALL FPDFPage_InsertClipPath(FPDF_PAGE page, | 265 DLLEXPORT void STDCALL FPDFPage_InsertClipPath(FPDF_PAGE page, |
270 FPDF_CLIPPATH clipPath) { | 266 FPDF_CLIPPATH clipPath) { |
271 CPDF_Page* pPage = GetPageFromFPDFPage(page); | 267 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
272 if (!pPage) | 268 if (!pPage) |
273 return; | 269 return; |
274 | 270 |
275 CPDF_Dictionary* pPageDic = pPage->m_pFormDict; | 271 CPDF_Dictionary* pPageDic = pPage->m_pFormDict; |
276 CPDF_Object* pContentObj = pPageDic ? pPageDic->GetElement("Contents") : NULL; | 272 CPDF_Object* pContentObj = pPageDic ? pPageDic->GetElement("Contents") : NULL; |
277 if (!pContentObj) | 273 if (!pContentObj) |
278 pContentObj = pPageDic ? pPageDic->GetArray("Contents") : NULL; | 274 pContentObj = pPageDic ? pPageDic->GetArray("Contents") : NULL; |
279 if (!pContentObj) | 275 if (!pContentObj) |
280 return; | 276 return; |
281 | 277 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 } else if (pDirectObj->GetType() == PDFOBJ_STREAM) { | 316 } else if (pDirectObj->GetType() == PDFOBJ_STREAM) { |
321 pContentArray = new CPDF_Array(); | 317 pContentArray = new CPDF_Array(); |
322 pContentArray->AddReference(pDoc, pStream->GetObjNum()); | 318 pContentArray->AddReference(pDoc, pStream->GetObjNum()); |
323 pContentArray->AddReference(pDoc, pDirectObj->GetObjNum()); | 319 pContentArray->AddReference(pDoc, pDirectObj->GetObjNum()); |
324 pPageDic->SetAtReference("Contents", pDoc, | 320 pPageDic->SetAtReference("Contents", pDoc, |
325 pDoc->AddIndirectObject(pContentArray)); | 321 pDoc->AddIndirectObject(pContentArray)); |
326 } | 322 } |
327 } | 323 } |
328 } | 324 } |
329 } | 325 } |
OLD | NEW |