| 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 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, |
| 11 { | 11 float left, |
| 12 if(!page) | 12 float bottom, |
| 13 return; | 13 float right, |
| 14 | 14 float top) { |
| 15 CPDF_Page* pPage = (CPDF_Page*)page; | 15 if (!page) |
| 16 CPDF_Dictionary* pPageDict = pPage->m_pFormDict; | 16 return; |
| 17 CPDF_Array* pMediaBoxArray = new CPDF_Array; | 17 |
| 18 pMediaBoxArray->Add(new CPDF_Number(left)); | 18 CPDF_Page* pPage = (CPDF_Page*)page; |
| 19 pMediaBoxArray->Add(new CPDF_Number(bottom)); | 19 CPDF_Dictionary* pPageDict = pPage->m_pFormDict; |
| 20 pMediaBoxArray->Add(new CPDF_Number(FX_FLOAT(right))); | 20 CPDF_Array* pMediaBoxArray = new CPDF_Array; |
| 21 pMediaBoxArray->Add(new CPDF_Number(FX_FLOAT(top))); | 21 pMediaBoxArray->Add(new CPDF_Number(left)); |
| 22 pPageDict->SetAt("MediaBox", pMediaBoxArray); | 22 pMediaBoxArray->Add(new CPDF_Number(bottom)); |
| 23 } | 23 pMediaBoxArray->Add(new CPDF_Number(FX_FLOAT(right))); |
| 24 | 24 pMediaBoxArray->Add(new CPDF_Number(FX_FLOAT(top))); |
| 25 | 25 pPageDict->SetAt("MediaBox", pMediaBoxArray); |
| 26 DLLEXPORT void STDCALL FPDFPage_SetCropBox(FPDF_PAGE page, float left, float bot
tom, float right, float top) | 26 } |
| 27 { | 27 |
| 28 if(!page) | 28 DLLEXPORT void STDCALL FPDFPage_SetCropBox(FPDF_PAGE page, |
| 29 return; | 29 float left, |
| 30 | 30 float bottom, |
| 31 CPDF_Page* pPage = (CPDF_Page*)page; | 31 float right, |
| 32 CPDF_Dictionary* pPageDict = pPage->m_pFormDict; | 32 float top) { |
| 33 CPDF_Array* pCropBoxArray = new CPDF_Array; | 33 if (!page) |
| 34 pCropBoxArray->Add(new CPDF_Number(left)); | 34 return; |
| 35 pCropBoxArray->Add(new CPDF_Number(bottom)); | 35 |
| 36 pCropBoxArray->Add(new CPDF_Number(FX_FLOAT(right))); | 36 CPDF_Page* pPage = (CPDF_Page*)page; |
| 37 pCropBoxArray->Add(new CPDF_Number(FX_FLOAT(top))); | 37 CPDF_Dictionary* pPageDict = pPage->m_pFormDict; |
| 38 pPageDict->SetAt("CropBox", pCropBoxArray); | 38 CPDF_Array* pCropBoxArray = new CPDF_Array; |
| 39 } | 39 pCropBoxArray->Add(new CPDF_Number(left)); |
| 40 | 40 pCropBoxArray->Add(new CPDF_Number(bottom)); |
| 41 | 41 pCropBoxArray->Add(new CPDF_Number(FX_FLOAT(right))); |
| 42 DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GetMediaBox(FPDF_PAGE page, float* left, fl
oat* bottom, float* right, float* top) | 42 pCropBoxArray->Add(new CPDF_Number(FX_FLOAT(top))); |
| 43 { | 43 pPageDict->SetAt("CropBox", pCropBoxArray); |
| 44 if(!page) | 44 } |
| 45 return FALSE; | 45 |
| 46 CPDF_Page* pPage = (CPDF_Page*)page; | 46 DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GetMediaBox(FPDF_PAGE page, |
| 47 CPDF_Dictionary* pPageDict = pPage->m_pFormDict; | 47 float* left, |
| 48 CPDF_Array* pArray = pPageDict->GetArray("MediaBox"); | 48 float* bottom, |
| 49 if(pArray) | 49 float* right, |
| 50 { | 50 float* top) { |
| 51 *left = pArray->GetFloat(0); | 51 if (!page) |
| 52 *bottom = pArray->GetFloat(1); | 52 return FALSE; |
| 53 *right = pArray->GetFloat(2); | 53 CPDF_Page* pPage = (CPDF_Page*)page; |
| 54 *top = pArray->GetFloat(3); | 54 CPDF_Dictionary* pPageDict = pPage->m_pFormDict; |
| 55 return TRUE; | 55 CPDF_Array* pArray = pPageDict->GetArray("MediaBox"); |
| 56 } | 56 if (pArray) { |
| 57 return FALSE; | 57 *left = pArray->GetFloat(0); |
| 58 } | 58 *bottom = pArray->GetFloat(1); |
| 59 | 59 *right = pArray->GetFloat(2); |
| 60 DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GetCropBox(FPDF_PAGE page, float* left, flo
at* bottom, float* right, float* top) | 60 *top = pArray->GetFloat(3); |
| 61 { | 61 return TRUE; |
| 62 if(!page) | 62 } |
| 63 return FALSE; | 63 return FALSE; |
| 64 CPDF_Page* pPage = (CPDF_Page*)page; | 64 } |
| 65 CPDF_Dictionary* pPageDict = pPage->m_pFormDict; | 65 |
| 66 CPDF_Array* pArray = pPageDict->GetArray("CropBox"); | 66 DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GetCropBox(FPDF_PAGE page, |
| 67 if(pArray) | 67 float* left, |
| 68 { | 68 float* bottom, |
| 69 *left = pArray->GetFloat(0); | 69 float* right, |
| 70 *bottom = pArray->GetFloat(1); | 70 float* top) { |
| 71 *right = pArray->GetFloat(2); | 71 if (!page) |
| 72 *top = pArray->GetFloat(3); | 72 return FALSE; |
| 73 return TRUE; | 73 CPDF_Page* pPage = (CPDF_Page*)page; |
| 74 } | 74 CPDF_Dictionary* pPageDict = pPage->m_pFormDict; |
| 75 return FALSE; | 75 CPDF_Array* pArray = pPageDict->GetArray("CropBox"); |
| 76 } | 76 if (pArray) { |
| 77 | 77 *left = pArray->GetFloat(0); |
| 78 DLLEXPORT FPDF_BOOL STDCALL FPDFPage_TransFormWithClip(FPDF_PAGE page, FS_MATRIX
* matrix, FS_RECTF* clipRect) | 78 *bottom = pArray->GetFloat(1); |
| 79 { | 79 *right = pArray->GetFloat(2); |
| 80 if(!page) | 80 *top = pArray->GetFloat(3); |
| 81 return FALSE; | 81 return TRUE; |
| 82 | 82 } |
| 83 CFX_ByteTextBuf textBuf; | 83 return FALSE; |
| 84 textBuf<<"q "; | 84 } |
| 85 CFX_FloatRect rect(clipRect->left, clipRect->bottom, clipRect->right, cl
ipRect->top); | 85 |
| 86 rect.Normalize(); | 86 DLLEXPORT FPDF_BOOL STDCALL FPDFPage_TransFormWithClip(FPDF_PAGE page, |
| 87 CFX_ByteString bsClipping; | 87 FS_MATRIX* matrix, |
| 88 bsClipping.Format("%f %f %f %f re W* n ", rect.left, rect.bottom, rect.W
idth(), rect.Height()); | 88 FS_RECTF* clipRect) { |
| 89 textBuf<<bsClipping; | 89 if (!page) |
| 90 | 90 return FALSE; |
| 91 CFX_ByteString bsMatix; | 91 |
| 92 bsMatix.Format("%f %f %f %f %f %f cm ", matrix->a, matrix->b,matrix->c,m
atrix->d,matrix->e,matrix->f); | 92 CFX_ByteTextBuf textBuf; |
| 93 textBuf<<bsMatix; | 93 textBuf << "q "; |
| 94 | 94 CFX_FloatRect rect(clipRect->left, clipRect->bottom, clipRect->right, |
| 95 | 95 clipRect->top); |
| 96 CPDF_Page* pPage = (CPDF_Page*)page; | 96 rect.Normalize(); |
| 97 CPDF_Dictionary* pPageDic = pPage->m_pFormDict; | 97 CFX_ByteString bsClipping; |
| 98 CPDF_Object* pContentObj = pPageDic ? pPageDic->GetElement("Contents") :
NULL; | 98 bsClipping.Format("%f %f %f %f re W* n ", rect.left, rect.bottom, |
| 99 if(!pContentObj) | 99 rect.Width(), rect.Height()); |
| 100 pContentObj = pPageDic ? pPageDic->GetArray("Contents") : NULL; | 100 textBuf << bsClipping; |
| 101 if(!pContentObj) | 101 |
| 102 return FALSE; | 102 CFX_ByteString bsMatix; |
| 103 | 103 bsMatix.Format("%f %f %f %f %f %f cm ", matrix->a, matrix->b, matrix->c, |
| 104 CPDF_Dictionary* pDic = new CPDF_Dictionary; | 104 matrix->d, matrix->e, matrix->f); |
| 105 CPDF_Stream* pStream = new CPDF_Stream(NULL,0, pDic); | 105 textBuf << bsMatix; |
| 106 pStream->SetData(textBuf.GetBuffer(), textBuf.GetSize(), FALSE, FALSE); | 106 |
| 107 CPDF_Document* pDoc = pPage->m_pDocument; | 107 CPDF_Page* pPage = (CPDF_Page*)page; |
| 108 if(!pDoc) | 108 CPDF_Dictionary* pPageDic = pPage->m_pFormDict; |
| 109 return FALSE; | 109 CPDF_Object* pContentObj = pPageDic ? pPageDic->GetElement("Contents") : NULL; |
| 110 pDoc->AddIndirectObject(pStream); | 110 if (!pContentObj) |
| 111 | 111 pContentObj = pPageDic ? pPageDic->GetArray("Contents") : NULL; |
| 112 pDic = new CPDF_Dictionary; | 112 if (!pContentObj) |
| 113 CPDF_Stream* pEndStream = new CPDF_Stream(NULL,0, pDic); | 113 return FALSE; |
| 114 pEndStream->SetData((const uint8_t*)" Q", 2, FALSE, FALSE); | 114 |
| 115 pDoc->AddIndirectObject(pEndStream); | 115 CPDF_Dictionary* pDic = new CPDF_Dictionary; |
| 116 | 116 CPDF_Stream* pStream = new CPDF_Stream(NULL, 0, pDic); |
| 117 CPDF_Array* pContentArray = NULL; | 117 pStream->SetData(textBuf.GetBuffer(), textBuf.GetSize(), FALSE, FALSE); |
| 118 if (pContentObj && pContentObj->GetType() == PDFOBJ_ARRAY) | 118 CPDF_Document* pDoc = pPage->m_pDocument; |
| 119 { | 119 if (!pDoc) |
| 120 pContentArray = (CPDF_Array*)pContentObj; | 120 return FALSE; |
| 121 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjN
um()); | 121 pDoc->AddIndirectObject(pStream); |
| 122 pContentArray->InsertAt(0, pRef); | 122 |
| 123 pContentArray->AddReference(pDoc,pEndStream); | 123 pDic = new CPDF_Dictionary; |
| 124 | 124 CPDF_Stream* pEndStream = new CPDF_Stream(NULL, 0, pDic); |
| 125 } | 125 pEndStream->SetData((const uint8_t*)" Q", 2, FALSE, FALSE); |
| 126 else if(pContentObj && pContentObj->GetType() == PDFOBJ_REFERENCE) | 126 pDoc->AddIndirectObject(pEndStream); |
| 127 { | 127 |
| 128 CPDF_Reference* pReference = (CPDF_Reference*)pContentObj; | 128 CPDF_Array* pContentArray = NULL; |
| 129 CPDF_Object* pDirectObj = pReference->GetDirect(); | 129 if (pContentObj && pContentObj->GetType() == PDFOBJ_ARRAY) { |
| 130 if(pDirectObj != NULL) | 130 pContentArray = (CPDF_Array*)pContentObj; |
| 131 { | 131 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); |
| 132 if(pDirectObj->GetType() == PDFOBJ_ARRAY) | 132 pContentArray->InsertAt(0, pRef); |
| 133 { | 133 pContentArray->AddReference(pDoc, pEndStream); |
| 134 pContentArray = (CPDF_Array*)pDirectObj; | 134 |
| 135 CPDF_Reference* pRef = new CPDF_Reference(pDoc,
pStream->GetObjNum()); | 135 } else if (pContentObj && pContentObj->GetType() == PDFOBJ_REFERENCE) { |
| 136 pContentArray->InsertAt(0, pRef); | 136 CPDF_Reference* pReference = (CPDF_Reference*)pContentObj; |
| 137 pContentArray->AddReference(pDoc,pEndStream); | 137 CPDF_Object* pDirectObj = pReference->GetDirect(); |
| 138 } | 138 if (pDirectObj != NULL) { |
| 139 else if(pDirectObj->GetType() == PDFOBJ_STREAM) | 139 if (pDirectObj->GetType() == PDFOBJ_ARRAY) { |
| 140 { | 140 pContentArray = (CPDF_Array*)pDirectObj; |
| 141 pContentArray = new CPDF_Array(); | 141 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); |
| 142 pContentArray->AddReference(pDoc,pStream->GetObj
Num()); | 142 pContentArray->InsertAt(0, pRef); |
| 143 pContentArray->AddReference(pDoc,pDirectObj->Get
ObjNum()); | 143 pContentArray->AddReference(pDoc, pEndStream); |
| 144 pContentArray->AddReference(pDoc, pEndStream); | 144 } else if (pDirectObj->GetType() == PDFOBJ_STREAM) { |
| 145 pPageDic->SetAtReference("Contents", pDoc, pDoc-
>AddIndirectObject(pContentArray)); | 145 pContentArray = new CPDF_Array(); |
| 146 } | 146 pContentArray->AddReference(pDoc, pStream->GetObjNum()); |
| 147 } | 147 pContentArray->AddReference(pDoc, pDirectObj->GetObjNum()); |
| 148 } | 148 pContentArray->AddReference(pDoc, pEndStream); |
| 149 | 149 pPageDic->SetAtReference("Contents", pDoc, |
| 150 //Need to transform the patterns as well. | 150 pDoc->AddIndirectObject(pContentArray)); |
| 151 CPDF_Dictionary* pRes = pPageDic->GetDict(FX_BSTRC("Resources")); | 151 } |
| 152 if(pRes) | 152 } |
| 153 { | 153 } |
| 154 CPDF_Dictionary* pPattenDict = pRes->GetDict(FX_BSTRC("Pattern")
); | 154 |
| 155 if(pPattenDict) | 155 // Need to transform the patterns as well. |
| 156 { | 156 CPDF_Dictionary* pRes = pPageDic->GetDict(FX_BSTRC("Resources")); |
| 157 FX_POSITION pos = pPattenDict->GetStartPos(); | 157 if (pRes) { |
| 158 while(pos) | 158 CPDF_Dictionary* pPattenDict = pRes->GetDict(FX_BSTRC("Pattern")); |
| 159 { | 159 if (pPattenDict) { |
| 160 CPDF_Dictionary* pDict = NULL; | 160 FX_POSITION pos = pPattenDict->GetStartPos(); |
| 161 CFX_ByteString key; | 161 while (pos) { |
| 162 CPDF_Object* pObj = pPattenDict->GetNextElement(
pos, key); | 162 CPDF_Dictionary* pDict = NULL; |
| 163 if(pObj->GetType() == PDFOBJ_REFERENCE) | 163 CFX_ByteString key; |
| 164 pObj = pObj->GetDirect(); | 164 CPDF_Object* pObj = pPattenDict->GetNextElement(pos, key); |
| 165 if(pObj->GetType() == PDFOBJ_DICTIONARY) | 165 if (pObj->GetType() == PDFOBJ_REFERENCE) |
| 166 { | 166 pObj = pObj->GetDirect(); |
| 167 pDict = (CPDF_Dictionary*)pObj; | 167 if (pObj->GetType() == PDFOBJ_DICTIONARY) { |
| 168 } | 168 pDict = (CPDF_Dictionary*)pObj; |
| 169 else if(pObj->GetType() == PDFOBJ_STREAM) | 169 } else if (pObj->GetType() == PDFOBJ_STREAM) { |
| 170 { | 170 pDict = ((CPDF_Stream*)pObj)->GetDict(); |
| 171 pDict = ((CPDF_Stream*)pObj)->GetDict(); | 171 } else |
| 172 } | 172 continue; |
| 173 else | 173 |
| 174 continue; | 174 CFX_AffineMatrix m = pDict->GetMatrix(FX_BSTRC("Matrix")); |
| 175 | 175 CFX_AffineMatrix t = *(CFX_AffineMatrix*)matrix; |
| 176 CFX_AffineMatrix m = pDict->GetMatrix(FX_BSTRC("
Matrix")); | 176 m.Concat(t); |
| 177 CFX_AffineMatrix t = *(CFX_AffineMatrix*)matrix; | 177 pDict->SetAtMatrix(FX_BSTRC("Matrix"), m); |
| 178 m.Concat(t); | 178 } |
| 179 pDict->SetAtMatrix(FX_BSTRC("Matrix"), m); | 179 } |
| 180 } | 180 } |
| 181 } | 181 |
| 182 } | 182 return TRUE; |
| 183 | 183 } |
| 184 return TRUE; | 184 |
| 185 } | 185 DLLEXPORT void STDCALL |
| 186 | 186 FPDFPageObj_TransformClipPath(FPDF_PAGEOBJECT page_object, |
| 187 DLLEXPORT void STDCALL FPDFPageObj_TransformClipPath(FPDF_PAGEOBJECT page_object
,double a, double b, double c, double d, double e, double f) | 187 double a, |
| 188 { | 188 double b, |
| 189 CPDF_PageObject* pPageObj = (CPDF_PageObject*)page_object; | 189 double c, |
| 190 if(pPageObj == NULL) | 190 double d, |
| 191 return; | 191 double e, |
| 192 CFX_AffineMatrix matrix((FX_FLOAT)a,(FX_FLOAT)b,(FX_FLOAT)c,(FX_FLOAT)d,
(FX_FLOAT)e,(FX_FLOAT)f); | 192 double f) { |
| 193 | 193 CPDF_PageObject* pPageObj = (CPDF_PageObject*)page_object; |
| 194 //Special treatment to shading object, because the ClipPath for shading
object is already transformed. | 194 if (pPageObj == NULL) |
| 195 if(pPageObj->m_Type != PDFPAGE_SHADING) | 195 return; |
| 196 pPageObj->TransformClipPath(matrix); | 196 CFX_AffineMatrix matrix((FX_FLOAT)a, (FX_FLOAT)b, (FX_FLOAT)c, (FX_FLOAT)d, |
| 197 pPageObj->TransformGeneralState(matrix); | 197 (FX_FLOAT)e, (FX_FLOAT)f); |
| 198 } | 198 |
| 199 | 199 // Special treatment to shading object, because the ClipPath for shading |
| 200 | 200 // object is already transformed. |
| 201 DLLEXPORT FPDF_CLIPPATH STDCALL FPDF_CreateClipPath(float left, float bottom, fl
oat right, float top) | 201 if (pPageObj->m_Type != PDFPAGE_SHADING) |
| 202 { | 202 pPageObj->TransformClipPath(matrix); |
| 203 CPDF_ClipPath* pNewClipPath = new CPDF_ClipPath(); | 203 pPageObj->TransformGeneralState(matrix); |
| 204 pNewClipPath->GetModify(); | 204 } |
| 205 CPDF_Path Path; | 205 |
| 206 Path.GetModify(); | 206 DLLEXPORT FPDF_CLIPPATH STDCALL FPDF_CreateClipPath(float left, |
| 207 Path.AppendRect(left, bottom, right, top); | 207 float bottom, |
| 208 pNewClipPath->AppendPath(Path, FXFILL_ALTERNATE, FALSE); | 208 float right, |
| 209 return pNewClipPath; | 209 float top) { |
| 210 } | 210 CPDF_ClipPath* pNewClipPath = new CPDF_ClipPath(); |
| 211 | 211 pNewClipPath->GetModify(); |
| 212 DLLEXPORT void STDCALL FPDF_DestroyClipPath(FPDF_CLIPPATH clipPath) | 212 CPDF_Path Path; |
| 213 { | 213 Path.GetModify(); |
| 214 delete (CPDF_ClipPath*)clipPath; | 214 Path.AppendRect(left, bottom, right, top); |
| 215 } | 215 pNewClipPath->AppendPath(Path, FXFILL_ALTERNATE, FALSE); |
| 216 | 216 return pNewClipPath; |
| 217 void OutputPath(CFX_ByteTextBuf& buf, CPDF_Path path) | 217 } |
| 218 { | 218 |
| 219 const CFX_PathData* pPathData = path; | 219 DLLEXPORT void STDCALL FPDF_DestroyClipPath(FPDF_CLIPPATH clipPath) { |
| 220 if (pPathData == NULL) return; | 220 delete (CPDF_ClipPath*)clipPath; |
| 221 | 221 } |
| 222 FX_PATHPOINT* pPoints = pPathData->GetPoints(); | 222 |
| 223 | 223 void OutputPath(CFX_ByteTextBuf& buf, CPDF_Path path) { |
| 224 if (path.IsRect()) { | 224 const CFX_PathData* pPathData = path; |
| 225 buf << (pPoints[0].m_PointX) << " " << (pPoints[0].m_PointY) <<
" " | 225 if (pPathData == NULL) |
| 226 << (pPoints[2].m_PointX - pPoints[0].m_PointX) << " " | 226 return; |
| 227 << (pPoints[2].m_PointY - pPoints[0].m_PointY) << " re\n
"; | 227 |
| 228 return; | 228 FX_PATHPOINT* pPoints = pPathData->GetPoints(); |
| 229 } | 229 |
| 230 | 230 if (path.IsRect()) { |
| 231 CFX_ByteString temp; | 231 buf << (pPoints[0].m_PointX) << " " << (pPoints[0].m_PointY) << " " |
| 232 for (int i = 0; i < pPathData->GetPointCount(); i ++) { | 232 << (pPoints[2].m_PointX - pPoints[0].m_PointX) << " " |
| 233 buf << (pPoints[i].m_PointX) << " " << (pPoints[i].m_PointY); | 233 << (pPoints[2].m_PointY - pPoints[0].m_PointY) << " re\n"; |
| 234 int point_type = pPoints[i].m_Flag & FXPT_TYPE; | 234 return; |
| 235 if (point_type == FXPT_MOVETO) | 235 } |
| 236 buf << " m\n"; | 236 |
| 237 else if (point_type == FXPT_BEZIERTO) { | 237 CFX_ByteString temp; |
| 238 buf << " " << (pPoints[i+1].m_PointX) << " " << (pPoints
[i+1].m_PointY) << " " << | 238 for (int i = 0; i < pPathData->GetPointCount(); i++) { |
| 239 (pPoints[i+2].m_PointX) << " " << (pPoints[i+2].
m_PointY); | 239 buf << (pPoints[i].m_PointX) << " " << (pPoints[i].m_PointY); |
| 240 if (pPoints[i+2].m_Flag & FXPT_CLOSEFIGURE) | 240 int point_type = pPoints[i].m_Flag & FXPT_TYPE; |
| 241 buf << " c h\n"; | 241 if (point_type == FXPT_MOVETO) |
| 242 else | 242 buf << " m\n"; |
| 243 buf << " c\n"; | 243 else if (point_type == FXPT_BEZIERTO) { |
| 244 i += 2; | 244 buf << " " << (pPoints[i + 1].m_PointX) << " " |
| 245 } else if (point_type == FXPT_LINETO) { | 245 << (pPoints[i + 1].m_PointY) << " " << (pPoints[i + 2].m_PointX) |
| 246 if (pPoints[i].m_Flag & FXPT_CLOSEFIGURE) | 246 << " " << (pPoints[i + 2].m_PointY); |
| 247 buf << " l h\n"; | 247 if (pPoints[i + 2].m_Flag & FXPT_CLOSEFIGURE) |
| 248 else | 248 buf << " c h\n"; |
| 249 buf << " l\n"; | 249 else |
| 250 } | 250 buf << " c\n"; |
| 251 } | 251 i += 2; |
| 252 } | 252 } else if (point_type == FXPT_LINETO) { |
| 253 | 253 if (pPoints[i].m_Flag & FXPT_CLOSEFIGURE) |
| 254 DLLEXPORT void STDCALL FPDFPage_InsertClipPath(FPDF_PAGE page,FPDF_CLIPPATH clip
Path) | 254 buf << " l h\n"; |
| 255 { | 255 else |
| 256 if(!page) | 256 buf << " l\n"; |
| 257 return; | 257 } |
| 258 CPDF_Page* pPage = (CPDF_Page*)page; | 258 } |
| 259 CPDF_Dictionary* pPageDic = pPage->m_pFormDict; | 259 } |
| 260 CPDF_Object* pContentObj = pPageDic ? pPageDic->GetElement("Contents") :
NULL; | 260 |
| 261 if(!pContentObj) | 261 DLLEXPORT void STDCALL FPDFPage_InsertClipPath(FPDF_PAGE page, |
| 262 pContentObj = pPageDic ? pPageDic->GetArray("Contents") : NULL; | 262 FPDF_CLIPPATH clipPath) { |
| 263 if(!pContentObj) | 263 if (!page) |
| 264 return; | 264 return; |
| 265 | 265 CPDF_Page* pPage = (CPDF_Page*)page; |
| 266 CFX_ByteTextBuf strClip; | 266 CPDF_Dictionary* pPageDic = pPage->m_pFormDict; |
| 267 CPDF_ClipPath* pClipPath = (CPDF_ClipPath*)clipPath; | 267 CPDF_Object* pContentObj = pPageDic ? pPageDic->GetElement("Contents") : NULL; |
| 268 FX_DWORD i; | 268 if (!pContentObj) |
| 269 for (i = 0; i < pClipPath->GetPathCount(); i ++) { | 269 pContentObj = pPageDic ? pPageDic->GetArray("Contents") : NULL; |
| 270 CPDF_Path path = pClipPath->GetPath(i); | 270 if (!pContentObj) |
| 271 int iClipType = pClipPath->GetClipType(i); | 271 return; |
| 272 if (path.GetPointCount() == 0) { | 272 |
| 273 // Empty clipping (totally clipped out) | 273 CFX_ByteTextBuf strClip; |
| 274 strClip << "0 0 m W n "; | 274 CPDF_ClipPath* pClipPath = (CPDF_ClipPath*)clipPath; |
| 275 } else { | 275 FX_DWORD i; |
| 276 OutputPath(strClip, path); | 276 for (i = 0; i < pClipPath->GetPathCount(); i++) { |
| 277 if (iClipType == FXFILL_WINDING) | 277 CPDF_Path path = pClipPath->GetPath(i); |
| 278 strClip << "W n\n"; | 278 int iClipType = pClipPath->GetClipType(i); |
| 279 else | 279 if (path.GetPointCount() == 0) { |
| 280 strClip << "W* n\n"; | 280 // Empty clipping (totally clipped out) |
| 281 } | 281 strClip << "0 0 m W n "; |
| 282 } | 282 } else { |
| 283 CPDF_Dictionary* pDic = new CPDF_Dictionary; | 283 OutputPath(strClip, path); |
| 284 CPDF_Stream* pStream = new CPDF_Stream(NULL,0, pDic); | 284 if (iClipType == FXFILL_WINDING) |
| 285 pStream->SetData(strClip.GetBuffer(), strClip.GetSize(), FALSE, FALSE); | 285 strClip << "W n\n"; |
| 286 CPDF_Document* pDoc = pPage->m_pDocument; | 286 else |
| 287 if(!pDoc) | 287 strClip << "W* n\n"; |
| 288 return; | 288 } |
| 289 pDoc->AddIndirectObject(pStream); | 289 } |
| 290 | 290 CPDF_Dictionary* pDic = new CPDF_Dictionary; |
| 291 CPDF_Array* pContentArray = NULL; | 291 CPDF_Stream* pStream = new CPDF_Stream(NULL, 0, pDic); |
| 292 if (pContentObj && pContentObj->GetType() == PDFOBJ_ARRAY) | 292 pStream->SetData(strClip.GetBuffer(), strClip.GetSize(), FALSE, FALSE); |
| 293 { | 293 CPDF_Document* pDoc = pPage->m_pDocument; |
| 294 pContentArray = (CPDF_Array*)pContentObj; | 294 if (!pDoc) |
| 295 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjN
um()); | 295 return; |
| 296 pContentArray->InsertAt(0, pRef); | 296 pDoc->AddIndirectObject(pStream); |
| 297 } | 297 |
| 298 else if(pContentObj && pContentObj->GetType() == PDFOBJ_REFERENCE) | 298 CPDF_Array* pContentArray = NULL; |
| 299 { | 299 if (pContentObj && pContentObj->GetType() == PDFOBJ_ARRAY) { |
| 300 CPDF_Reference* pReference = (CPDF_Reference*)pContentObj; | 300 pContentArray = (CPDF_Array*)pContentObj; |
| 301 CPDF_Object* pDirectObj = pReference->GetDirect(); | 301 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); |
| 302 if(pDirectObj != NULL) | 302 pContentArray->InsertAt(0, pRef); |
| 303 { | 303 } else if (pContentObj && pContentObj->GetType() == PDFOBJ_REFERENCE) { |
| 304 if(pDirectObj->GetType() == PDFOBJ_ARRAY) | 304 CPDF_Reference* pReference = (CPDF_Reference*)pContentObj; |
| 305 { | 305 CPDF_Object* pDirectObj = pReference->GetDirect(); |
| 306 pContentArray = (CPDF_Array*)pDirectObj; | 306 if (pDirectObj != NULL) { |
| 307 CPDF_Reference* pRef = new CPDF_Reference(pDoc,
pStream->GetObjNum()); | 307 if (pDirectObj->GetType() == PDFOBJ_ARRAY) { |
| 308 pContentArray->InsertAt(0, pRef); | 308 pContentArray = (CPDF_Array*)pDirectObj; |
| 309 } | 309 CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum()); |
| 310 else if(pDirectObj->GetType() == PDFOBJ_STREAM) | 310 pContentArray->InsertAt(0, pRef); |
| 311 { | 311 } else if (pDirectObj->GetType() == PDFOBJ_STREAM) { |
| 312 pContentArray = new CPDF_Array(); | 312 pContentArray = new CPDF_Array(); |
| 313 pContentArray->AddReference(pDoc,pStream->GetObj
Num()); | 313 pContentArray->AddReference(pDoc, pStream->GetObjNum()); |
| 314 pContentArray->AddReference(pDoc,pDirectObj->Get
ObjNum()); | 314 pContentArray->AddReference(pDoc, pDirectObj->GetObjNum()); |
| 315 pPageDic->SetAtReference("Contents", pDoc, pDoc-
>AddIndirectObject(pContentArray)); | 315 pPageDic->SetAtReference("Contents", pDoc, |
| 316 } | 316 pDoc->AddIndirectObject(pContentArray)); |
| 317 } | 317 } |
| 318 } | 318 } |
| 319 } | 319 } |
| 320 | 320 } |
| OLD | NEW |