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_flatten.h" | 7 #include "public/fpdf_flatten.h" |
8 | 8 |
9 #include "fpdfsdk/include/fsdk_define.h" | 9 #include "fpdfsdk/include/fsdk_define.h" |
10 | 10 |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 dwObjNum = pDocument->AddIndirectObject(pNewContents); | 245 dwObjNum = pDocument->AddIndirectObject(pNewContents); |
246 pContentsArray->AddReference(pDocument, dwObjNum); | 246 pContentsArray->AddReference(pDocument, dwObjNum); |
247 | 247 |
248 CFX_ByteString sStream; | 248 CFX_ByteString sStream; |
249 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); | 249 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); |
250 pNewContents->SetData((const uint8_t*)sStream, sStream.GetLength(), FALSE, | 250 pNewContents->SetData((const uint8_t*)sStream, sStream.GetLength(), FALSE, |
251 FALSE); | 251 FALSE); |
252 } | 252 } |
253 } | 253 } |
254 | 254 |
255 CFX_AffineMatrix GetMatrix(CPDF_Rect rcAnnot, | 255 CFX_Matrix GetMatrix(CPDF_Rect rcAnnot, CPDF_Rect rcStream, CFX_Matrix matrix) { |
Lei Zhang
2015/12/10 22:34:02
const ref?
Tom Sepez
2015/12/10 22:48:41
Ok. There's a big CL one can cobble up to pass CF
| |
256 CPDF_Rect rcStream, | |
257 CFX_AffineMatrix matrix) { | |
258 if (rcStream.IsEmpty()) | 256 if (rcStream.IsEmpty()) |
259 return CFX_AffineMatrix(); | 257 return CFX_Matrix(); |
260 | 258 |
261 matrix.TransformRect(rcStream); | 259 matrix.TransformRect(rcStream); |
262 rcStream.Normalize(); | 260 rcStream.Normalize(); |
263 | 261 |
264 FX_FLOAT a = rcAnnot.Width() / rcStream.Width(); | 262 FX_FLOAT a = rcAnnot.Width() / rcStream.Width(); |
265 FX_FLOAT d = rcAnnot.Height() / rcStream.Height(); | 263 FX_FLOAT d = rcAnnot.Height() / rcStream.Height(); |
266 | 264 |
267 FX_FLOAT e = rcAnnot.left - rcStream.left * a; | 265 FX_FLOAT e = rcAnnot.left - rcStream.left * a; |
268 FX_FLOAT f = rcAnnot.bottom - rcStream.bottom * d; | 266 FX_FLOAT f = rcAnnot.bottom - rcStream.bottom * d; |
269 return CFX_AffineMatrix(a, 0, 0, d, e, f); | 267 return CFX_Matrix(a, 0, 0, d, e, f); |
270 } | 268 } |
271 | 269 |
272 void GetOffset(FX_FLOAT& fa, | 270 void GetOffset(FX_FLOAT& fa, |
273 FX_FLOAT& fd, | 271 FX_FLOAT& fd, |
274 FX_FLOAT& fe, | 272 FX_FLOAT& fe, |
275 FX_FLOAT& ff, | 273 FX_FLOAT& ff, |
276 CPDF_Rect rcAnnot, | 274 CPDF_Rect rcAnnot, |
277 CPDF_Rect rcStream, | 275 CPDF_Rect rcStream, |
278 CFX_AffineMatrix matrix) { | 276 CFX_Matrix matrix) { |
Tom Sepez
2015/12/10 22:48:40
here too.
| |
279 FX_FLOAT fStreamWidth = 0.0f; | 277 FX_FLOAT fStreamWidth = 0.0f; |
280 FX_FLOAT fStreamHeight = 0.0f; | 278 FX_FLOAT fStreamHeight = 0.0f; |
281 | 279 |
282 if (matrix.a != 0 && matrix.d != 0) { | 280 if (matrix.a != 0 && matrix.d != 0) { |
283 fStreamWidth = rcStream.right - rcStream.left; | 281 fStreamWidth = rcStream.right - rcStream.left; |
284 fStreamHeight = rcStream.top - rcStream.bottom; | 282 fStreamHeight = rcStream.top - rcStream.bottom; |
285 } else { | 283 } else { |
286 fStreamWidth = rcStream.top - rcStream.bottom; | 284 fStreamWidth = rcStream.top - rcStream.bottom; |
287 fStreamHeight = rcStream.right - rcStream.left; | 285 fStreamHeight = rcStream.right - rcStream.left; |
288 } | 286 } |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
451 continue; | 449 continue; |
452 pAPStream = pFirstObj->AsStream(); | 450 pAPStream = pFirstObj->AsStream(); |
453 } | 451 } |
454 } | 452 } |
455 } | 453 } |
456 } | 454 } |
457 if (!pAPStream) | 455 if (!pAPStream) |
458 continue; | 456 continue; |
459 | 457 |
460 CPDF_Dictionary* pAPDic = pAPStream->GetDict(); | 458 CPDF_Dictionary* pAPDic = pAPStream->GetDict(); |
461 CFX_AffineMatrix matrix = pAPDic->GetMatrix("Matrix"); | 459 CFX_Matrix matrix = pAPDic->GetMatrix("Matrix"); |
462 | 460 |
463 CPDF_Rect rcStream; | 461 CPDF_Rect rcStream; |
464 if (pAPDic->KeyExist("Rect")) | 462 if (pAPDic->KeyExist("Rect")) |
465 rcStream = pAPDic->GetRect("Rect"); | 463 rcStream = pAPDic->GetRect("Rect"); |
466 else if (pAPDic->KeyExist("BBox")) | 464 else if (pAPDic->KeyExist("BBox")) |
467 rcStream = pAPDic->GetRect("BBox"); | 465 rcStream = pAPDic->GetRect("BBox"); |
468 | 466 |
469 if (rcStream.IsEmpty()) | 467 if (rcStream.IsEmpty()) |
470 continue; | 468 continue; |
471 | 469 |
(...skipping 27 matching lines...) Expand all Loading... | |
499 | 497 |
500 if (matrix.IsIdentity()) { | 498 if (matrix.IsIdentity()) { |
501 matrix.a = 1.0f; | 499 matrix.a = 1.0f; |
502 matrix.b = 0.0f; | 500 matrix.b = 0.0f; |
503 matrix.c = 0.0f; | 501 matrix.c = 0.0f; |
504 matrix.d = 1.0f; | 502 matrix.d = 1.0f; |
505 matrix.e = 0.0f; | 503 matrix.e = 0.0f; |
506 matrix.f = 0.0f; | 504 matrix.f = 0.0f; |
507 } | 505 } |
508 | 506 |
509 CFX_AffineMatrix m = GetMatrix(rcAnnot, rcStream, matrix); | 507 CFX_Matrix m = GetMatrix(rcAnnot, rcStream, matrix); |
510 sTemp.Format("q %f 0 0 %f %f %f cm /%s Do Q\n", m.a, m.d, m.e, m.f, | 508 sTemp.Format("q %f 0 0 %f %f %f cm /%s Do Q\n", m.a, m.d, m.e, m.f, |
511 sFormName.c_str()); | 509 sFormName.c_str()); |
512 sStream += sTemp; | 510 sStream += sTemp; |
513 | 511 |
514 pNewXObject->SetData((const uint8_t*)sStream, sStream.GetLength(), FALSE, | 512 pNewXObject->SetData((const uint8_t*)sStream, sStream.GetLength(), FALSE, |
515 FALSE); | 513 FALSE); |
516 } | 514 } |
517 pPageDict->RemoveAt("Annots"); | 515 pPageDict->RemoveAt("Annots"); |
518 | 516 |
519 ObjectArray.RemoveAll(); | 517 ObjectArray.RemoveAll(); |
520 RectArray.RemoveAll(); | 518 RectArray.RemoveAll(); |
521 | 519 |
522 return FLATTEN_SUCCESS; | 520 return FLATTEN_SUCCESS; |
523 } | 521 } |
OLD | NEW |