John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1 | // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Lei Zhang | b4e7f30 | 2015-11-06 15:52:32 -0800 | [diff] [blame] | 7 | #include "public/fpdf_flatten.h" |
| 8 | |
Lei Zhang | 375a864 | 2016-01-11 11:59:17 -0800 | [diff] [blame] | 9 | #include <algorithm> |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 10 | #include <memory> |
| 11 | #include <utility> |
| 12 | #include <vector> |
Lei Zhang | 375a864 | 2016-01-11 11:59:17 -0800 | [diff] [blame] | 13 | |
dsinclair | 41872fa | 2016-10-04 11:29:35 -0700 | [diff] [blame] | 14 | #include "core/fpdfapi/page/cpdf_page.h" |
| 15 | #include "core/fpdfapi/page/cpdf_pageobject.h" |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame] | 16 | #include "core/fpdfapi/parser/cpdf_array.h" |
| 17 | #include "core/fpdfapi/parser/cpdf_document.h" |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 18 | #include "core/fpdfapi/parser/cpdf_name.h" |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame] | 19 | #include "core/fpdfapi/parser/cpdf_number.h" |
tsepez | 8a3aa45 | 2016-11-16 12:26:06 -0800 | [diff] [blame] | 20 | #include "core/fpdfapi/parser/cpdf_reference.h" |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame] | 21 | #include "core/fpdfapi/parser/cpdf_stream.h" |
| 22 | #include "core/fpdfapi/parser/cpdf_stream_acc.h" |
dsinclair | 1727aee | 2016-09-29 13:12:56 -0700 | [diff] [blame] | 23 | #include "core/fpdfdoc/cpdf_annot.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 24 | #include "fpdfsdk/fsdk_define.h" |
tsepez | 74b8c6e | 2016-10-12 09:38:41 -0700 | [diff] [blame] | 25 | #include "third_party/base/stl_util.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 26 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 27 | enum FPDF_TYPE { MAX, MIN }; |
| 28 | enum FPDF_VALUE { TOP, LEFT, RIGHT, BOTTOM }; |
| 29 | |
tsepez | 381fc83 | 2016-10-10 14:06:44 -0700 | [diff] [blame] | 30 | namespace { |
| 31 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 32 | bool IsValiableRect(CFX_FloatRect rect, CFX_FloatRect rcPage) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 33 | if (rect.left - rect.right > 0.000001f || rect.bottom - rect.top > 0.000001f) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 34 | return false; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 35 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 36 | if (rect.left == 0.0f && rect.top == 0.0f && rect.right == 0.0f && |
| 37 | rect.bottom == 0.0f) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 38 | return false; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 39 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 40 | if (!rcPage.IsEmpty()) { |
| 41 | if (rect.left - rcPage.left < -10.000001f || |
| 42 | rect.right - rcPage.right > 10.000001f || |
| 43 | rect.top - rcPage.top > 10.000001f || |
| 44 | rect.bottom - rcPage.bottom < -10.000001f) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 45 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 46 | } |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 47 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 48 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 51 | void GetContentsRect(CPDF_Document* pDoc, |
| 52 | CPDF_Dictionary* pDict, |
tsepez | 6173c9d | 2016-11-09 16:38:03 -0800 | [diff] [blame] | 53 | std::vector<CFX_FloatRect>* pRectArray) { |
thestig | 5cc2465 | 2016-04-26 11:46:02 -0700 | [diff] [blame] | 54 | std::unique_ptr<CPDF_Page> pPDFPage(new CPDF_Page(pDoc, pDict, false)); |
| 55 | pPDFPage->ParseContent(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 56 | |
thestig | 2fad11a | 2016-06-16 16:39:25 -0700 | [diff] [blame] | 57 | for (const auto& pPageObject : *pPDFPage->GetPageObjectList()) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 58 | CFX_FloatRect rc; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 59 | rc.left = pPageObject->m_Left; |
| 60 | rc.right = pPageObject->m_Right; |
| 61 | rc.bottom = pPageObject->m_Bottom; |
| 62 | rc.top = pPageObject->m_Top; |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 63 | if (IsValiableRect(rc, pDict->GetRectFor("MediaBox"))) |
tsepez | 6173c9d | 2016-11-09 16:38:03 -0800 | [diff] [blame] | 64 | pRectArray->push_back(rc); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 65 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 68 | void ParserStream(CPDF_Dictionary* pPageDic, |
| 69 | CPDF_Dictionary* pStream, |
tsepez | 6173c9d | 2016-11-09 16:38:03 -0800 | [diff] [blame] | 70 | std::vector<CFX_FloatRect>* pRectArray, |
tsepez | 74b8c6e | 2016-10-12 09:38:41 -0700 | [diff] [blame] | 71 | std::vector<CPDF_Dictionary*>* pObjectArray) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 72 | if (!pStream) |
| 73 | return; |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 74 | CFX_FloatRect rect; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 75 | if (pStream->KeyExist("Rect")) |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 76 | rect = pStream->GetRectFor("Rect"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 77 | else if (pStream->KeyExist("BBox")) |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 78 | rect = pStream->GetRectFor("BBox"); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 79 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 80 | if (IsValiableRect(rect, pPageDic->GetRectFor("MediaBox"))) |
tsepez | 6173c9d | 2016-11-09 16:38:03 -0800 | [diff] [blame] | 81 | pRectArray->push_back(rect); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 82 | |
tsepez | 74b8c6e | 2016-10-12 09:38:41 -0700 | [diff] [blame] | 83 | pObjectArray->push_back(pStream); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 86 | int ParserAnnots(CPDF_Document* pSourceDoc, |
| 87 | CPDF_Dictionary* pPageDic, |
tsepez | 6173c9d | 2016-11-09 16:38:03 -0800 | [diff] [blame] | 88 | std::vector<CFX_FloatRect>* pRectArray, |
tsepez | 74b8c6e | 2016-10-12 09:38:41 -0700 | [diff] [blame] | 89 | std::vector<CPDF_Dictionary*>* pObjectArray, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 90 | int nUsage) { |
| 91 | if (!pSourceDoc || !pPageDic) |
| 92 | return FLATTEN_FAIL; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 93 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 94 | GetContentsRect(pSourceDoc, pPageDic, pRectArray); |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 95 | CPDF_Array* pAnnots = pPageDic->GetArrayFor("Annots"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 96 | if (!pAnnots) |
| 97 | return FLATTEN_NOTHINGTODO; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 98 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 99 | uint32_t dwSize = pAnnots->GetCount(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 100 | for (int i = 0; i < (int)dwSize; i++) { |
tsepez | bd56755 | 2016-03-29 14:51:50 -0700 | [diff] [blame] | 101 | CPDF_Dictionary* pAnnotDic = ToDictionary(pAnnots->GetDirectObjectAt(i)); |
Dan Sinclair | f1251c1 | 2015-10-20 16:24:45 -0400 | [diff] [blame] | 102 | if (!pAnnotDic) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 103 | continue; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 104 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 105 | CFX_ByteString sSubtype = pAnnotDic->GetStringFor("Subtype"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 106 | if (sSubtype == "Popup") |
| 107 | continue; |
| 108 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 109 | int nAnnotFlag = pAnnotDic->GetIntegerFor("F"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 110 | if (nAnnotFlag & ANNOTFLAG_HIDDEN) |
| 111 | continue; |
| 112 | |
| 113 | if (nUsage == FLAT_NORMALDISPLAY) { |
| 114 | if (nAnnotFlag & ANNOTFLAG_INVISIBLE) |
| 115 | continue; |
| 116 | |
| 117 | ParserStream(pPageDic, pAnnotDic, pRectArray, pObjectArray); |
| 118 | } else { |
| 119 | if (nAnnotFlag & ANNOTFLAG_PRINT) |
| 120 | ParserStream(pPageDic, pAnnotDic, pRectArray, pObjectArray); |
| 121 | } |
| 122 | } |
| 123 | return FLATTEN_SUCCESS; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame^] | 126 | float GetMinMaxValue(const std::vector<CFX_FloatRect>& array, |
| 127 | FPDF_TYPE type, |
| 128 | FPDF_VALUE value) { |
tsepez | 6173c9d | 2016-11-09 16:38:03 -0800 | [diff] [blame] | 129 | size_t nRects = array.size(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 130 | if (nRects <= 0) |
| 131 | return 0.0f; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 132 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame^] | 133 | std::vector<float> pArray(nRects); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 134 | switch (value) { |
tsepez | 6173c9d | 2016-11-09 16:38:03 -0800 | [diff] [blame] | 135 | case LEFT: |
| 136 | for (size_t i = 0; i < nRects; i++) |
| 137 | pArray[i] = array[i].left; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 138 | break; |
tsepez | 6173c9d | 2016-11-09 16:38:03 -0800 | [diff] [blame] | 139 | case TOP: |
| 140 | for (size_t i = 0; i < nRects; i++) |
| 141 | pArray[i] = array[i].top; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 142 | break; |
tsepez | 6173c9d | 2016-11-09 16:38:03 -0800 | [diff] [blame] | 143 | case RIGHT: |
| 144 | for (size_t i = 0; i < nRects; i++) |
| 145 | pArray[i] = array[i].right; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 146 | break; |
tsepez | 6173c9d | 2016-11-09 16:38:03 -0800 | [diff] [blame] | 147 | case BOTTOM: |
| 148 | for (size_t i = 0; i < nRects; i++) |
| 149 | pArray[i] = array[i].bottom; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 150 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 151 | default: |
weili | 12367cb | 2016-06-03 11:22:16 -0700 | [diff] [blame] | 152 | // Not reachable. |
| 153 | return 0.0f; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 154 | } |
tsepez | 6173c9d | 2016-11-09 16:38:03 -0800 | [diff] [blame] | 155 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame^] | 156 | float fRet = pArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 157 | if (type == MAX) { |
tsepez | 6173c9d | 2016-11-09 16:38:03 -0800 | [diff] [blame] | 158 | for (size_t i = 1; i < nRects; i++) |
| 159 | fRet = std::max(fRet, pArray[i]); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 160 | } else { |
tsepez | 6173c9d | 2016-11-09 16:38:03 -0800 | [diff] [blame] | 161 | for (size_t i = 1; i < nRects; i++) |
| 162 | fRet = std::min(fRet, pArray[i]); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 163 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 164 | return fRet; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 165 | } |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 166 | |
tsepez | 6173c9d | 2016-11-09 16:38:03 -0800 | [diff] [blame] | 167 | CFX_FloatRect CalculateRect(std::vector<CFX_FloatRect>* pRectArray) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 168 | CFX_FloatRect rcRet; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 169 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 170 | rcRet.left = GetMinMaxValue(*pRectArray, MIN, LEFT); |
| 171 | rcRet.top = GetMinMaxValue(*pRectArray, MAX, TOP); |
| 172 | rcRet.right = GetMinMaxValue(*pRectArray, MAX, RIGHT); |
| 173 | rcRet.bottom = GetMinMaxValue(*pRectArray, MIN, BOTTOM); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 174 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 175 | return rcRet; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 176 | } |
| 177 | |
tsepez | 381fc83 | 2016-10-10 14:06:44 -0700 | [diff] [blame] | 178 | uint32_t NewIndirectContentsStream(const CFX_ByteString& key, |
| 179 | CPDF_Document* pDocument) { |
tsepez | 70c4afd | 2016-11-15 11:33:44 -0800 | [diff] [blame] | 180 | CPDF_Stream* pNewContents = pDocument->NewIndirect<CPDF_Stream>( |
tsepez | 9e05ee1 | 2016-11-21 13:19:10 -0800 | [diff] [blame] | 181 | nullptr, 0, |
| 182 | pdfium::MakeUnique<CPDF_Dictionary>(pDocument->GetByteStringPool())); |
tsepez | 381fc83 | 2016-10-10 14:06:44 -0700 | [diff] [blame] | 183 | CFX_ByteString sStream; |
| 184 | sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); |
| 185 | pNewContents->SetData(sStream.raw_str(), sStream.GetLength()); |
tsepez | 70c4afd | 2016-11-15 11:33:44 -0800 | [diff] [blame] | 186 | return pNewContents->GetObjNum(); |
tsepez | 381fc83 | 2016-10-10 14:06:44 -0700 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | void SetPageContents(const CFX_ByteString& key, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 190 | CPDF_Dictionary* pPage, |
| 191 | CPDF_Document* pDocument) { |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 192 | CPDF_Array* pContentsArray = nullptr; |
tsepez | 381fc83 | 2016-10-10 14:06:44 -0700 | [diff] [blame] | 193 | CPDF_Stream* pContentsStream = pPage->GetStreamFor("Contents"); |
| 194 | if (!pContentsStream) { |
| 195 | pContentsArray = pPage->GetArrayFor("Contents"); |
| 196 | if (!pContentsArray) { |
| 197 | if (!key.IsEmpty()) { |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 198 | pPage->SetNewFor<CPDF_Reference>( |
| 199 | "Contents", pDocument, NewIndirectContentsStream(key, pDocument)); |
tsepez | 381fc83 | 2016-10-10 14:06:44 -0700 | [diff] [blame] | 200 | } |
| 201 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 202 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 203 | } |
tsepez | 381fc83 | 2016-10-10 14:06:44 -0700 | [diff] [blame] | 204 | pPage->ConvertToIndirectObjectFor("Contents", pDocument); |
| 205 | if (!pContentsArray) { |
tsepez | 70c4afd | 2016-11-15 11:33:44 -0800 | [diff] [blame] | 206 | pContentsArray = pDocument->NewIndirect<CPDF_Array>(); |
tsepez | 381fc83 | 2016-10-10 14:06:44 -0700 | [diff] [blame] | 207 | CPDF_StreamAcc acc; |
| 208 | acc.LoadAllData(pContentsStream); |
| 209 | CFX_ByteString sStream = "q\n"; |
Tom Sepez | c25a421 | 2016-10-14 17:45:56 -0700 | [diff] [blame] | 210 | CFX_ByteString sBody = |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 211 | CFX_ByteString((const char*)acc.GetData(), acc.GetSize()); |
tsepez | 381fc83 | 2016-10-10 14:06:44 -0700 | [diff] [blame] | 212 | sStream = sStream + sBody + "\nQ"; |
| 213 | pContentsStream->SetData(sStream.raw_str(), sStream.GetLength()); |
tsepez | 8a3aa45 | 2016-11-16 12:26:06 -0800 | [diff] [blame] | 214 | pContentsArray->AddNew<CPDF_Reference>(pDocument, |
| 215 | pContentsStream->GetObjNum()); |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 216 | pPage->SetNewFor<CPDF_Reference>("Contents", pDocument, |
| 217 | pContentsArray->GetObjNum()); |
tsepez | 381fc83 | 2016-10-10 14:06:44 -0700 | [diff] [blame] | 218 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 219 | if (!key.IsEmpty()) { |
tsepez | 8a3aa45 | 2016-11-16 12:26:06 -0800 | [diff] [blame] | 220 | pContentsArray->AddNew<CPDF_Reference>( |
| 221 | pDocument, NewIndirectContentsStream(key, pDocument)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 222 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 223 | } |
| 224 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 225 | CFX_Matrix GetMatrix(CFX_FloatRect rcAnnot, |
| 226 | CFX_FloatRect rcStream, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 227 | const CFX_Matrix& matrix) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 228 | if (rcStream.IsEmpty()) |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 229 | return CFX_Matrix(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 230 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 231 | matrix.TransformRect(rcStream); |
| 232 | rcStream.Normalize(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 233 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame^] | 234 | float a = rcAnnot.Width() / rcStream.Width(); |
| 235 | float d = rcAnnot.Height() / rcStream.Height(); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 236 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame^] | 237 | float e = rcAnnot.left - rcStream.left * a; |
| 238 | float f = rcAnnot.bottom - rcStream.bottom * d; |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 239 | return CFX_Matrix(a, 0, 0, d, e, f); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 240 | } |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 241 | |
tsepez | 381fc83 | 2016-10-10 14:06:44 -0700 | [diff] [blame] | 242 | } // namespace |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 243 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 244 | DLLEXPORT int STDCALL FPDFPage_Flatten(FPDF_PAGE page, int nFlag) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 245 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
tsepez | 6173c9d | 2016-11-09 16:38:03 -0800 | [diff] [blame] | 246 | if (!page) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 247 | return FLATTEN_FAIL; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 248 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 249 | CPDF_Document* pDocument = pPage->m_pDocument; |
| 250 | CPDF_Dictionary* pPageDict = pPage->m_pFormDict; |
tsepez | 6173c9d | 2016-11-09 16:38:03 -0800 | [diff] [blame] | 251 | if (!pDocument || !pPageDict) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 252 | return FLATTEN_FAIL; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 253 | |
tsepez | 74b8c6e | 2016-10-12 09:38:41 -0700 | [diff] [blame] | 254 | std::vector<CPDF_Dictionary*> ObjectArray; |
tsepez | 6173c9d | 2016-11-09 16:38:03 -0800 | [diff] [blame] | 255 | std::vector<CFX_FloatRect> RectArray; |
| 256 | int iRet = |
| 257 | ParserAnnots(pDocument, pPageDict, &RectArray, &ObjectArray, nFlag); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 258 | if (iRet == FLATTEN_NOTHINGTODO || iRet == FLATTEN_FAIL) |
| 259 | return iRet; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 260 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 261 | CFX_FloatRect rcOriginalCB; |
| 262 | CFX_FloatRect rcMerger = CalculateRect(&RectArray); |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 263 | CFX_FloatRect rcOriginalMB = pPageDict->GetRectFor("MediaBox"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 264 | if (pPageDict->KeyExist("CropBox")) |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 265 | rcOriginalMB = pPageDict->GetRectFor("CropBox"); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 266 | |
tsepez | 6173c9d | 2016-11-09 16:38:03 -0800 | [diff] [blame] | 267 | if (rcOriginalMB.IsEmpty()) |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 268 | rcOriginalMB = CFX_FloatRect(0.0f, 0.0f, 612.0f, 792.0f); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 269 | |
tsepez | 6173c9d | 2016-11-09 16:38:03 -0800 | [diff] [blame] | 270 | rcMerger.left = std::max(rcMerger.left, rcOriginalMB.left); |
| 271 | rcMerger.right = std::min(rcMerger.right, rcOriginalMB.right); |
| 272 | rcMerger.bottom = std::max(rcMerger.bottom, rcOriginalMB.bottom); |
| 273 | rcMerger.top = std::min(rcMerger.top, rcOriginalMB.top); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 274 | if (pPageDict->KeyExist("ArtBox")) |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 275 | rcOriginalCB = pPageDict->GetRectFor("ArtBox"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 276 | else |
| 277 | rcOriginalCB = rcOriginalMB; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 278 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 279 | if (!rcOriginalMB.IsEmpty()) { |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 280 | CPDF_Array* pMediaBox = pPageDict->SetNewFor<CPDF_Array>("MediaBox"); |
tsepez | 8a3aa45 | 2016-11-16 12:26:06 -0800 | [diff] [blame] | 281 | pMediaBox->AddNew<CPDF_Number>(rcOriginalMB.left); |
| 282 | pMediaBox->AddNew<CPDF_Number>(rcOriginalMB.bottom); |
| 283 | pMediaBox->AddNew<CPDF_Number>(rcOriginalMB.right); |
| 284 | pMediaBox->AddNew<CPDF_Number>(rcOriginalMB.top); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 285 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 286 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 287 | if (!rcOriginalCB.IsEmpty()) { |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 288 | CPDF_Array* pCropBox = pPageDict->SetNewFor<CPDF_Array>("ArtBox"); |
tsepez | 8a3aa45 | 2016-11-16 12:26:06 -0800 | [diff] [blame] | 289 | pCropBox->AddNew<CPDF_Number>(rcOriginalCB.left); |
| 290 | pCropBox->AddNew<CPDF_Number>(rcOriginalCB.bottom); |
| 291 | pCropBox->AddNew<CPDF_Number>(rcOriginalCB.right); |
| 292 | pCropBox->AddNew<CPDF_Number>(rcOriginalCB.top); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 293 | } |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 294 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 295 | CPDF_Dictionary* pRes = pPageDict->GetDictFor("Resources"); |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 296 | if (!pRes) |
| 297 | pRes = pPageDict->SetNewFor<CPDF_Dictionary>("Resources"); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 298 | |
tsepez | 70c4afd | 2016-11-15 11:33:44 -0800 | [diff] [blame] | 299 | CPDF_Stream* pNewXObject = pDocument->NewIndirect<CPDF_Stream>( |
tsepez | 9e05ee1 | 2016-11-21 13:19:10 -0800 | [diff] [blame] | 300 | nullptr, 0, |
| 301 | pdfium::MakeUnique<CPDF_Dictionary>(pDocument->GetByteStringPool())); |
tsepez | 698c571 | 2016-09-28 16:47:07 -0700 | [diff] [blame] | 302 | |
tsepez | 70c4afd | 2016-11-15 11:33:44 -0800 | [diff] [blame] | 303 | uint32_t dwObjNum = pNewXObject->GetObjNum(); |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 304 | CPDF_Dictionary* pPageXObject = pRes->GetDictFor("XObject"); |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 305 | if (!pPageXObject) |
| 306 | pPageXObject = pRes->SetNewFor<CPDF_Dictionary>("XObject"); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 307 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 308 | CFX_ByteString key = ""; |
tsepez | 74b8c6e | 2016-10-12 09:38:41 -0700 | [diff] [blame] | 309 | int nStreams = pdfium::CollectionSize<int>(ObjectArray); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 310 | if (nStreams > 0) { |
| 311 | for (int iKey = 0; /*iKey < 100*/; iKey++) { |
| 312 | char sExtend[5] = {}; |
| 313 | FXSYS_itoa(iKey, sExtend, 10); |
| 314 | key = CFX_ByteString("FFT") + CFX_ByteString(sExtend); |
tsepez | 7b1ccf9 | 2016-04-14 11:04:57 -0700 | [diff] [blame] | 315 | if (!pPageXObject->KeyExist(key)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 316 | break; |
| 317 | } |
| 318 | } |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 319 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 320 | SetPageContents(key, pPageDict, pDocument); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 321 | |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 322 | CPDF_Dictionary* pNewXORes = nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 323 | if (!key.IsEmpty()) { |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 324 | pPageXObject->SetNewFor<CPDF_Reference>(key, pDocument, dwObjNum); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 325 | CPDF_Dictionary* pNewOXbjectDic = pNewXObject->GetDict(); |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 326 | pNewXORes = pNewOXbjectDic->SetNewFor<CPDF_Dictionary>("Resources"); |
| 327 | pNewOXbjectDic->SetNewFor<CPDF_Name>("Type", "XObject"); |
| 328 | pNewOXbjectDic->SetNewFor<CPDF_Name>("Subtype", "Form"); |
| 329 | pNewOXbjectDic->SetNewFor<CPDF_Number>("FormType", 1); |
| 330 | pNewOXbjectDic->SetNewFor<CPDF_Name>("Name", "FRM"); |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 331 | CFX_FloatRect rcBBox = pPageDict->GetRectFor("ArtBox"); |
| 332 | pNewOXbjectDic->SetRectFor("BBox", rcBBox); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 333 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 334 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 335 | for (int i = 0; i < nStreams; i++) { |
tsepez | 74b8c6e | 2016-10-12 09:38:41 -0700 | [diff] [blame] | 336 | CPDF_Dictionary* pAnnotDic = ObjectArray[i]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 337 | if (!pAnnotDic) |
| 338 | continue; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 339 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 340 | CFX_FloatRect rcAnnot = pAnnotDic->GetRectFor("Rect"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 341 | rcAnnot.Normalize(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 342 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 343 | CFX_ByteString sAnnotState = pAnnotDic->GetStringFor("AS"); |
| 344 | CPDF_Dictionary* pAnnotAP = pAnnotDic->GetDictFor("AP"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 345 | if (!pAnnotAP) |
| 346 | continue; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 347 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 348 | CPDF_Stream* pAPStream = pAnnotAP->GetStreamFor("N"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 349 | if (!pAPStream) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 350 | CPDF_Dictionary* pAPDic = pAnnotAP->GetDictFor("N"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 351 | if (!pAPDic) |
| 352 | continue; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 353 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 354 | if (!sAnnotState.IsEmpty()) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 355 | pAPStream = pAPDic->GetStreamFor(sAnnotState); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 356 | } else { |
Oliver Chang | 3f1c71f | 2016-01-11 08:45:31 -0800 | [diff] [blame] | 357 | auto it = pAPDic->begin(); |
| 358 | if (it != pAPDic->end()) { |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 359 | CPDF_Object* pFirstObj = it->second.get(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 360 | if (pFirstObj) { |
Dan Sinclair | bf81c14 | 2015-10-26 16:54:39 -0400 | [diff] [blame] | 361 | if (pFirstObj->IsReference()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 362 | pFirstObj = pFirstObj->GetDirect(); |
Dan Sinclair | aa435ba | 2015-10-22 16:45:48 -0400 | [diff] [blame] | 363 | if (!pFirstObj->IsStream()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 364 | continue; |
Dan Sinclair | aa435ba | 2015-10-22 16:45:48 -0400 | [diff] [blame] | 365 | pAPStream = pFirstObj->AsStream(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 366 | } |
| 367 | } |
| 368 | } |
| 369 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 370 | if (!pAPStream) |
| 371 | continue; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 372 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 373 | CPDF_Dictionary* pAPDic = pAPStream->GetDict(); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 374 | CFX_FloatRect rcStream; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 375 | if (pAPDic->KeyExist("Rect")) |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 376 | rcStream = pAPDic->GetRectFor("Rect"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 377 | else if (pAPDic->KeyExist("BBox")) |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 378 | rcStream = pAPDic->GetRectFor("BBox"); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 379 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 380 | if (rcStream.IsEmpty()) |
| 381 | continue; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 382 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 383 | CPDF_Object* pObj = pAPStream; |
tsepez | d0ecd89 | 2016-11-08 17:30:04 -0800 | [diff] [blame] | 384 | if (pObj->IsInline()) { |
tsepez | 335cf09 | 2016-11-09 13:28:26 -0800 | [diff] [blame] | 385 | std::unique_ptr<CPDF_Object> pNew = pObj->Clone(); |
| 386 | pObj = pNew.get(); |
tsepez | 70c4afd | 2016-11-15 11:33:44 -0800 | [diff] [blame] | 387 | pDocument->AddIndirectObject(std::move(pNew)); |
tsepez | d0ecd89 | 2016-11-08 17:30:04 -0800 | [diff] [blame] | 388 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 389 | |
tsepez | d0ecd89 | 2016-11-08 17:30:04 -0800 | [diff] [blame] | 390 | CPDF_Dictionary* pObjDic = pObj->GetDict(); |
| 391 | if (pObjDic) { |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 392 | pObjDic->SetNewFor<CPDF_Name>("Type", "XObject"); |
| 393 | pObjDic->SetNewFor<CPDF_Name>("Subtype", "Form"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 394 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 395 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 396 | CPDF_Dictionary* pXObject = pNewXORes->GetDictFor("XObject"); |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 397 | if (!pXObject) |
| 398 | pXObject = pNewXORes->SetNewFor<CPDF_Dictionary>("XObject"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 399 | |
| 400 | CFX_ByteString sFormName; |
| 401 | sFormName.Format("F%d", i); |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 402 | pXObject->SetNewFor<CPDF_Reference>(sFormName, pDocument, |
| 403 | pObj->GetObjNum()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 404 | |
| 405 | CPDF_StreamAcc acc; |
| 406 | acc.LoadAllData(pNewXObject); |
| 407 | |
| 408 | const uint8_t* pData = acc.GetData(); |
| 409 | CFX_ByteString sStream(pData, acc.GetSize()); |
tsepez | d0ecd89 | 2016-11-08 17:30:04 -0800 | [diff] [blame] | 410 | CFX_Matrix matrix = pAPDic->GetMatrixFor("Matrix"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 411 | if (matrix.IsIdentity()) { |
| 412 | matrix.a = 1.0f; |
| 413 | matrix.b = 0.0f; |
| 414 | matrix.c = 0.0f; |
| 415 | matrix.d = 1.0f; |
| 416 | matrix.e = 0.0f; |
| 417 | matrix.f = 0.0f; |
| 418 | } |
| 419 | |
tsepez | bb577af | 2016-09-21 19:10:19 -0700 | [diff] [blame] | 420 | CFX_ByteString sTemp; |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 421 | CFX_Matrix m = GetMatrix(rcAnnot, rcStream, matrix); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 422 | sTemp.Format("q %f 0 0 %f %f %f cm /%s Do Q\n", m.a, m.d, m.e, m.f, |
| 423 | sFormName.c_str()); |
| 424 | sStream += sTemp; |
tsepez | e6db16e | 2016-09-19 10:45:09 -0700 | [diff] [blame] | 425 | pNewXObject->SetData(sStream.raw_str(), sStream.GetLength()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 426 | } |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 427 | pPageDict->RemoveFor("Annots"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 428 | return FLATTEN_SUCCESS; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 429 | } |