 Chromium Code Reviews
 Chromium Code Reviews Issue 1407583004:
  Changes to master to more closely match XFA.  (Closed) 
  Base URL: https://pdfium.googlesource.com/pdfium.git@master
    
  
    Issue 1407583004:
  Changes to master to more closely match XFA.  (Closed) 
  Base URL: https://pdfium.googlesource.com/pdfium.git@master| 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) { | |
| 
Tom Sepez
2015/10/13 21:53:45
note: if we put this (and an equivalent GetDocFrom
 | |
| 13 return static_cast<CPDF_Page*>(page); | |
| 14 } | |
| 15 | |
| 12 void SetBoundingBox(CPDF_Page* page, | 16 void SetBoundingBox(CPDF_Page* page, | 
| 13 const CFX_ByteStringC& key, | 17 const CFX_ByteStringC& key, | 
| 14 float left, | 18 float left, | 
| 15 float bottom, | 19 float bottom, | 
| 16 float right, | 20 float right, | 
| 17 float top) { | 21 float top) { | 
| 18 CPDF_Dictionary* pPageDict = page->m_pFormDict; | 22 CPDF_Dictionary* pPageDict = page->m_pFormDict; | 
| 19 CPDF_Array* pBoundingBoxArray = new CPDF_Array; | 23 CPDF_Array* pBoundingBoxArray = new CPDF_Array; | 
| 20 pBoundingBoxArray->Add(new CPDF_Number(left)); | 24 pBoundingBoxArray->Add(new CPDF_Number(left)); | 
| 21 pBoundingBoxArray->Add(new CPDF_Number(bottom)); | 25 pBoundingBoxArray->Add(new CPDF_Number(bottom)); | 
| (...skipping 20 matching lines...) Expand all Loading... | |
| 42 return TRUE; | 46 return TRUE; | 
| 43 } | 47 } | 
| 44 | 48 | 
| 45 } // namespace | 49 } // namespace | 
| 46 | 50 | 
| 47 DLLEXPORT void STDCALL FPDFPage_SetMediaBox(FPDF_PAGE page, | 51 DLLEXPORT void STDCALL FPDFPage_SetMediaBox(FPDF_PAGE page, | 
| 48 float left, | 52 float left, | 
| 49 float bottom, | 53 float bottom, | 
| 50 float right, | 54 float right, | 
| 51 float top) { | 55 float top) { | 
| 52 if (!page) | 56 CPDF_Page* pPage = GetPageFromFPDFPage(page); | 
| 57 if (!pPage) | |
| 53 return; | 58 return; | 
| 54 | 59 | 
| 55 SetBoundingBox(static_cast<CPDF_Page*>(page), "MediaBox", left, bottom, right, | 60 SetBoundingBox(pPage, "MediaBox", left, bottom, right, top); | 
| 56 top); | |
| 57 } | 61 } | 
| 58 | 62 | 
| 59 DLLEXPORT void STDCALL FPDFPage_SetCropBox(FPDF_PAGE page, | 63 DLLEXPORT void STDCALL FPDFPage_SetCropBox(FPDF_PAGE page, | 
| 60 float left, | 64 float left, | 
| 61 float bottom, | 65 float bottom, | 
| 62 float right, | 66 float right, | 
| 63 float top) { | 67 float top) { | 
| 64 if (!page) | 68 CPDF_Page* pPage = GetPageFromFPDFPage(page); | 
| 69 if (!pPage) | |
| 65 return; | 70 return; | 
| 66 | 71 | 
| 67 SetBoundingBox(static_cast<CPDF_Page*>(page), "CropBox", left, bottom, right, | 72 SetBoundingBox(pPage, "CropBox", left, bottom, right, top); | 
| 68 top); | |
| 69 } | 73 } | 
| 70 | 74 | 
| 71 DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GetMediaBox(FPDF_PAGE page, | 75 DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GetMediaBox(FPDF_PAGE page, | 
| 72 float* left, | 76 float* left, | 
| 73 float* bottom, | 77 float* bottom, | 
| 74 float* right, | 78 float* right, | 
| 75 float* top) { | 79 float* top) { | 
| 76 return page && GetBoundingBox(static_cast<CPDF_Page*>(page), "MediaBox", left, | 80 CPDF_Page* pPage = GetPageFromFPDFPage(page); | 
| 77 bottom, right, top); | 81 return pPage && GetBoundingBox(pPage, "MediaBox", left, bottom, right, top); | 
| 78 } | 82 } | 
| 79 | 83 | 
| 80 DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GetCropBox(FPDF_PAGE page, | 84 DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GetCropBox(FPDF_PAGE page, | 
| 81 float* left, | 85 float* left, | 
| 82 float* bottom, | 86 float* bottom, | 
| 83 float* right, | 87 float* right, | 
| 84 float* top) { | 88 float* top) { | 
| 85 return page && GetBoundingBox(static_cast<CPDF_Page*>(page), "CropBox", left, | 89 CPDF_Page* pPage = GetPageFromFPDFPage(page); | 
| 86 bottom, right, top); | 90 return pPage && GetBoundingBox(pPage, "CropBox", left, bottom, right, top); | 
| 87 } | 91 } | 
| 88 | 92 | 
| 89 DLLEXPORT FPDF_BOOL STDCALL FPDFPage_TransFormWithClip(FPDF_PAGE page, | 93 DLLEXPORT FPDF_BOOL STDCALL FPDFPage_TransFormWithClip(FPDF_PAGE page, | 
| 90 FS_MATRIX* matrix, | 94 FS_MATRIX* matrix, | 
| 91 FS_RECTF* clipRect) { | 95 FS_RECTF* clipRect) { | 
| 92 if (!page) | 96 CPDF_Page* pPage = GetPageFromFPDFPage(page); | 
| 97 if (!pPage) | |
| 93 return FALSE; | 98 return FALSE; | 
| 94 | 99 | 
| 95 CFX_ByteTextBuf textBuf; | 100 CFX_ByteTextBuf textBuf; | 
| 96 textBuf << "q "; | 101 textBuf << "q "; | 
| 97 CFX_FloatRect rect(clipRect->left, clipRect->bottom, clipRect->right, | 102 CFX_FloatRect rect(clipRect->left, clipRect->bottom, clipRect->right, | 
| 98 clipRect->top); | 103 clipRect->top); | 
| 99 rect.Normalize(); | 104 rect.Normalize(); | 
| 100 CFX_ByteString bsClipping; | 105 CFX_ByteString bsClipping; | 
| 101 bsClipping.Format("%f %f %f %f re W* n ", rect.left, rect.bottom, | 106 bsClipping.Format("%f %f %f %f re W* n ", rect.left, rect.bottom, | 
| 102 rect.Width(), rect.Height()); | 107 rect.Width(), rect.Height()); | 
| 103 textBuf << bsClipping; | 108 textBuf << bsClipping; | 
| 104 | 109 | 
| 105 CFX_ByteString bsMatix; | 110 CFX_ByteString bsMatix; | 
| 106 bsMatix.Format("%f %f %f %f %f %f cm ", matrix->a, matrix->b, matrix->c, | 111 bsMatix.Format("%f %f %f %f %f %f cm ", matrix->a, matrix->b, matrix->c, | 
| 107 matrix->d, matrix->e, matrix->f); | 112 matrix->d, matrix->e, matrix->f); | 
| 108 textBuf << bsMatix; | 113 textBuf << bsMatix; | 
| 109 | 114 | 
| 110 CPDF_Page* pPage = (CPDF_Page*)page; | |
| 111 CPDF_Dictionary* pPageDic = pPage->m_pFormDict; | 115 CPDF_Dictionary* pPageDic = pPage->m_pFormDict; | 
| 112 CPDF_Object* pContentObj = pPageDic ? pPageDic->GetElement("Contents") : NULL; | 116 CPDF_Object* pContentObj = pPageDic ? pPageDic->GetElement("Contents") : NULL; | 
| 113 if (!pContentObj) | 117 if (!pContentObj) | 
| 114 pContentObj = pPageDic ? pPageDic->GetArray("Contents") : NULL; | 118 pContentObj = pPageDic ? pPageDic->GetArray("Contents") : NULL; | 
| 115 if (!pContentObj) | 119 if (!pContentObj) | 
| 116 return FALSE; | 120 return FALSE; | 
| 117 | 121 | 
| 118 CPDF_Dictionary* pDic = new CPDF_Dictionary; | 122 CPDF_Dictionary* pDic = new CPDF_Dictionary; | 
| 119 CPDF_Stream* pStream = new CPDF_Stream(NULL, 0, pDic); | 123 CPDF_Stream* pStream = new CPDF_Stream(NULL, 0, pDic); | 
| 120 pStream->SetData(textBuf.GetBuffer(), textBuf.GetSize(), FALSE, FALSE); | 124 pStream->SetData(textBuf.GetBuffer(), textBuf.GetSize(), FALSE, FALSE); | 
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 256 if (pPoints[i].m_Flag & FXPT_CLOSEFIGURE) | 260 if (pPoints[i].m_Flag & FXPT_CLOSEFIGURE) | 
| 257 buf << " l h\n"; | 261 buf << " l h\n"; | 
| 258 else | 262 else | 
| 259 buf << " l\n"; | 263 buf << " l\n"; | 
| 260 } | 264 } | 
| 261 } | 265 } | 
| 262 } | 266 } | 
| 263 | 267 | 
| 264 DLLEXPORT void STDCALL FPDFPage_InsertClipPath(FPDF_PAGE page, | 268 DLLEXPORT void STDCALL FPDFPage_InsertClipPath(FPDF_PAGE page, | 
| 265 FPDF_CLIPPATH clipPath) { | 269 FPDF_CLIPPATH clipPath) { | 
| 266 if (!page) | 270 CPDF_Page* pPage = GetPageFromFPDFPage(page); | 
| 271 if (!pPage) | |
| 267 return; | 272 return; | 
| 268 CPDF_Page* pPage = (CPDF_Page*)page; | 273 | 
| 269 CPDF_Dictionary* pPageDic = pPage->m_pFormDict; | 274 CPDF_Dictionary* pPageDic = pPage->m_pFormDict; | 
| 270 CPDF_Object* pContentObj = pPageDic ? pPageDic->GetElement("Contents") : NULL; | 275 CPDF_Object* pContentObj = pPageDic ? pPageDic->GetElement("Contents") : NULL; | 
| 271 if (!pContentObj) | 276 if (!pContentObj) | 
| 272 pContentObj = pPageDic ? pPageDic->GetArray("Contents") : NULL; | 277 pContentObj = pPageDic ? pPageDic->GetArray("Contents") : NULL; | 
| 273 if (!pContentObj) | 278 if (!pContentObj) | 
| 274 return; | 279 return; | 
| 275 | 280 | 
| 276 CFX_ByteTextBuf strClip; | 281 CFX_ByteTextBuf strClip; | 
| 277 CPDF_ClipPath* pClipPath = (CPDF_ClipPath*)clipPath; | 282 CPDF_ClipPath* pClipPath = (CPDF_ClipPath*)clipPath; | 
| 278 FX_DWORD i; | 283 FX_DWORD i; | 
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 } else if (pDirectObj->GetType() == PDFOBJ_STREAM) { | 319 } else if (pDirectObj->GetType() == PDFOBJ_STREAM) { | 
| 315 pContentArray = new CPDF_Array(); | 320 pContentArray = new CPDF_Array(); | 
| 316 pContentArray->AddReference(pDoc, pStream->GetObjNum()); | 321 pContentArray->AddReference(pDoc, pStream->GetObjNum()); | 
| 317 pContentArray->AddReference(pDoc, pDirectObj->GetObjNum()); | 322 pContentArray->AddReference(pDoc, pDirectObj->GetObjNum()); | 
| 318 pPageDic->SetAtReference("Contents", pDoc, | 323 pPageDic->SetAtReference("Contents", pDoc, | 
| 319 pDoc->AddIndirectObject(pContentArray)); | 324 pDoc->AddIndirectObject(pContentArray)); | 
| 320 } | 325 } | 
| 321 } | 326 } | 
| 322 } | 327 } | 
| 323 } | 328 } | 
| OLD | NEW |