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