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