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