| 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 <algorithm> |
| 10 |
| 9 #include "fpdfsdk/include/fsdk_define.h" | 11 #include "fpdfsdk/include/fsdk_define.h" |
| 10 | 12 |
| 11 typedef CFX_ArrayTemplate<CPDF_Dictionary*> CPDF_ObjectArray; | 13 typedef CFX_ArrayTemplate<CPDF_Dictionary*> CPDF_ObjectArray; |
| 12 typedef CFX_ArrayTemplate<CPDF_Rect> CPDF_RectArray; | 14 typedef CFX_ArrayTemplate<CPDF_Rect> CPDF_RectArray; |
| 13 | 15 |
| 14 enum FPDF_TYPE { MAX, MIN }; | 16 enum FPDF_TYPE { MAX, MIN }; |
| 15 enum FPDF_VALUE { TOP, LEFT, RIGHT, BOTTOM }; | 17 enum FPDF_VALUE { TOP, LEFT, RIGHT, BOTTOM }; |
| 16 | 18 |
| 17 FX_BOOL IsValiableRect(CPDF_Rect rect, CPDF_Rect rcPage) { | 19 FX_BOOL IsValiableRect(CPDF_Rect rect, CPDF_Rect rcPage) { |
| 18 if (rect.left - rect.right > 0.000001f || rect.bottom - rect.top > 0.000001f) | 20 if (rect.left - rect.right > 0.000001f || rect.bottom - rect.top > 0.000001f) |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 matrix.b * rcStream.left + matrix.d * rcStream.bottom + matrix.f; | 295 matrix.b * rcStream.left + matrix.d * rcStream.bottom + matrix.f; |
| 294 FX_FLOAT x2 = matrix.a * rcStream.left + matrix.c * rcStream.top + matrix.e; | 296 FX_FLOAT x2 = matrix.a * rcStream.left + matrix.c * rcStream.top + matrix.e; |
| 295 FX_FLOAT y2 = matrix.b * rcStream.left + matrix.d * rcStream.top + matrix.f; | 297 FX_FLOAT y2 = matrix.b * rcStream.left + matrix.d * rcStream.top + matrix.f; |
| 296 FX_FLOAT x3 = | 298 FX_FLOAT x3 = |
| 297 matrix.a * rcStream.right + matrix.c * rcStream.bottom + matrix.e; | 299 matrix.a * rcStream.right + matrix.c * rcStream.bottom + matrix.e; |
| 298 FX_FLOAT y3 = | 300 FX_FLOAT y3 = |
| 299 matrix.b * rcStream.right + matrix.d * rcStream.bottom + matrix.f; | 301 matrix.b * rcStream.right + matrix.d * rcStream.bottom + matrix.f; |
| 300 FX_FLOAT x4 = matrix.a * rcStream.right + matrix.c * rcStream.top + matrix.e; | 302 FX_FLOAT x4 = matrix.a * rcStream.right + matrix.c * rcStream.top + matrix.e; |
| 301 FX_FLOAT y4 = matrix.b * rcStream.right + matrix.d * rcStream.top + matrix.f; | 303 FX_FLOAT y4 = matrix.b * rcStream.right + matrix.d * rcStream.top + matrix.f; |
| 302 | 304 |
| 303 FX_FLOAT left = FX_MIN(FX_MIN(x1, x2), FX_MIN(x3, x4)); | 305 FX_FLOAT left = std::min(std::min(x1, x2), std::min(x3, x4)); |
| 304 FX_FLOAT bottom = FX_MIN(FX_MIN(y1, y2), FX_MIN(y3, y4)); | 306 FX_FLOAT bottom = std::min(std::min(y1, y2), std::min(y3, y4)); |
| 305 | 307 |
| 306 fa = (rcAnnot.right - rcAnnot.left) / fStreamWidth; | 308 fa = (rcAnnot.right - rcAnnot.left) / fStreamWidth; |
| 307 fd = (rcAnnot.top - rcAnnot.bottom) / fStreamHeight; | 309 fd = (rcAnnot.top - rcAnnot.bottom) / fStreamHeight; |
| 308 fe = rcAnnot.left - left * fa; | 310 fe = rcAnnot.left - left * fa; |
| 309 ff = rcAnnot.bottom - bottom * fd; | 311 ff = rcAnnot.bottom - bottom * fd; |
| 310 } | 312 } |
| 311 | 313 |
| 312 DLLEXPORT int STDCALL FPDFPage_Flatten(FPDF_PAGE page, int nFlag) { | 314 DLLEXPORT int STDCALL FPDFPage_Flatten(FPDF_PAGE page, int nFlag) { |
| 313 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); | 315 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 314 if (!page) { | 316 if (!page) { |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 pNewXObject->SetData((const uint8_t*)sStream, sStream.GetLength(), FALSE, | 516 pNewXObject->SetData((const uint8_t*)sStream, sStream.GetLength(), FALSE, |
| 515 FALSE); | 517 FALSE); |
| 516 } | 518 } |
| 517 pPageDict->RemoveAt("Annots"); | 519 pPageDict->RemoveAt("Annots"); |
| 518 | 520 |
| 519 ObjectArray.RemoveAll(); | 521 ObjectArray.RemoveAll(); |
| 520 RectArray.RemoveAll(); | 522 RectArray.RemoveAll(); |
| 521 | 523 |
| 522 return FLATTEN_SUCCESS; | 524 return FLATTEN_SUCCESS; |
| 523 } | 525 } |
| OLD | NEW |