| OLD | NEW |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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 "core/fpdfapi/edit/cpdf_pagecontentgenerator.h" | 7 #include "core/fpdfapi/edit/cpdf_pagecontentgenerator.h" |
| 8 | 8 |
| 9 #include "core/fpdfapi/edit/cpdf_creator.h" | 9 #include "core/fpdfapi/edit/cpdf_creator.h" |
| 10 #include "core/fpdfapi/page/cpdf_docpagedata.h" | 10 #include "core/fpdfapi/page/cpdf_docpagedata.h" |
| 11 #include "core/fpdfapi/page/cpdf_image.h" | 11 #include "core/fpdfapi/page/cpdf_image.h" |
| 12 #include "core/fpdfapi/page/cpdf_imageobject.h" | 12 #include "core/fpdfapi/page/cpdf_imageobject.h" |
| 13 #include "core/fpdfapi/page/cpdf_page.h" | 13 #include "core/fpdfapi/page/cpdf_page.h" |
| 14 #include "core/fpdfapi/page/cpdf_pageobject.h" | 14 #include "core/fpdfapi/page/cpdf_pageobject.h" |
| 15 #include "core/fpdfapi/page/pageint.h" | 15 #include "core/fpdfapi/page/pageint.h" |
| 16 #include "core/fpdfapi/parser/cpdf_array.h" | 16 #include "core/fpdfapi/parser/cpdf_array.h" |
| 17 #include "core/fpdfapi/parser/cpdf_dictionary.h" | 17 #include "core/fpdfapi/parser/cpdf_dictionary.h" |
| 18 #include "core/fpdfapi/parser/cpdf_document.h" | 18 #include "core/fpdfapi/parser/cpdf_document.h" |
| 19 #include "core/fpdfapi/parser/cpdf_name.h" |
| 20 #include "core/fpdfapi/parser/cpdf_reference.h" |
| 19 #include "core/fpdfapi/parser/cpdf_stream.h" | 21 #include "core/fpdfapi/parser/cpdf_stream.h" |
| 20 #include "core/fpdfapi/parser/cpdf_stream_acc.h" | 22 #include "core/fpdfapi/parser/cpdf_stream_acc.h" |
| 21 #include "core/fpdfapi/parser/fpdf_parser_decode.h" | 23 #include "core/fpdfapi/parser/fpdf_parser_decode.h" |
| 22 | 24 |
| 23 CFX_ByteTextBuf& operator<<(CFX_ByteTextBuf& ar, CFX_Matrix& matrix) { | 25 CFX_ByteTextBuf& operator<<(CFX_ByteTextBuf& ar, CFX_Matrix& matrix) { |
| 24 ar << matrix.a << " " << matrix.b << " " << matrix.c << " " << matrix.d << " " | 26 ar << matrix.a << " " << matrix.b << " " << matrix.c << " " << matrix.d << " " |
| 25 << matrix.e << " " << matrix.f; | 27 << matrix.e << " " << matrix.f; |
| 26 return ar; | 28 return ar; |
| 27 } | 29 } |
| 28 | 30 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 47 ProcessImage(buf, pImageObject); | 49 ProcessImage(buf, pImageObject); |
| 48 } | 50 } |
| 49 CPDF_Dictionary* pPageDict = m_pPage->m_pFormDict; | 51 CPDF_Dictionary* pPageDict = m_pPage->m_pFormDict; |
| 50 CPDF_Object* pContent = | 52 CPDF_Object* pContent = |
| 51 pPageDict ? pPageDict->GetDirectObjectFor("Contents") : nullptr; | 53 pPageDict ? pPageDict->GetDirectObjectFor("Contents") : nullptr; |
| 52 if (pContent) | 54 if (pContent) |
| 53 pPageDict->RemoveFor("Contents"); | 55 pPageDict->RemoveFor("Contents"); |
| 54 | 56 |
| 55 CPDF_Stream* pStream = m_pDocument->NewIndirect<CPDF_Stream>(); | 57 CPDF_Stream* pStream = m_pDocument->NewIndirect<CPDF_Stream>(); |
| 56 pStream->SetData(buf.GetBuffer(), buf.GetLength()); | 58 pStream->SetData(buf.GetBuffer(), buf.GetLength()); |
| 57 pPageDict->SetReferenceFor("Contents", m_pDocument, pStream); | 59 pPageDict->SetNewFor<CPDF_Reference>("Contents", m_pDocument, |
| 60 pStream->GetObjNum()); |
| 58 } | 61 } |
| 59 | 62 |
| 60 CFX_ByteString CPDF_PageContentGenerator::RealizeResource( | 63 CFX_ByteString CPDF_PageContentGenerator::RealizeResource( |
| 61 uint32_t dwResourceObjNum, | 64 uint32_t dwResourceObjNum, |
| 62 const CFX_ByteString& bsType) { | 65 const CFX_ByteString& bsType) { |
| 63 ASSERT(dwResourceObjNum); | 66 ASSERT(dwResourceObjNum); |
| 64 if (!m_pPage->m_pResources) { | 67 if (!m_pPage->m_pResources) { |
| 65 m_pPage->m_pResources = m_pDocument->NewIndirect<CPDF_Dictionary>(); | 68 m_pPage->m_pResources = m_pDocument->NewIndirect<CPDF_Dictionary>(); |
| 66 m_pPage->m_pFormDict->SetReferenceFor("Resources", m_pDocument, | 69 m_pPage->m_pFormDict->SetNewFor<CPDF_Reference>( |
| 67 m_pPage->m_pResources); | 70 "Resources", m_pDocument, m_pPage->m_pResources->GetObjNum()); |
| 68 } | 71 } |
| 69 CPDF_Dictionary* pResList = m_pPage->m_pResources->GetDictFor(bsType); | 72 CPDF_Dictionary* pResList = m_pPage->m_pResources->GetDictFor(bsType); |
| 70 if (!pResList) { | 73 if (!pResList) |
| 71 pResList = new CPDF_Dictionary(m_pDocument->GetByteStringPool()); | 74 pResList = m_pPage->m_pResources->SetNewFor<CPDF_Dictionary>(bsType); |
| 72 m_pPage->m_pResources->SetFor(bsType, pResList); | 75 |
| 73 } | |
| 74 CFX_ByteString name; | 76 CFX_ByteString name; |
| 75 int idnum = 1; | 77 int idnum = 1; |
| 76 while (1) { | 78 while (1) { |
| 77 name.Format("FX%c%d", bsType[0], idnum); | 79 name.Format("FX%c%d", bsType[0], idnum); |
| 78 if (!pResList->KeyExist(name)) { | 80 if (!pResList->KeyExist(name)) { |
| 79 break; | 81 break; |
| 80 } | 82 } |
| 81 idnum++; | 83 idnum++; |
| 82 } | 84 } |
| 83 pResList->SetReferenceFor(name, m_pDocument, dwResourceObjNum); | 85 pResList->SetNewFor<CPDF_Reference>(name, m_pDocument, dwResourceObjNum); |
| 84 return name; | 86 return name; |
| 85 } | 87 } |
| 86 | 88 |
| 87 void CPDF_PageContentGenerator::ProcessImage(CFX_ByteTextBuf& buf, | 89 void CPDF_PageContentGenerator::ProcessImage(CFX_ByteTextBuf& buf, |
| 88 CPDF_ImageObject* pImageObj) { | 90 CPDF_ImageObject* pImageObj) { |
| 89 if ((pImageObj->m_Matrix.a == 0 && pImageObj->m_Matrix.b == 0) || | 91 if ((pImageObj->m_Matrix.a == 0 && pImageObj->m_Matrix.b == 0) || |
| 90 (pImageObj->m_Matrix.c == 0 && pImageObj->m_Matrix.d == 0)) { | 92 (pImageObj->m_Matrix.c == 0 && pImageObj->m_Matrix.d == 0)) { |
| 91 return; | 93 return; |
| 92 } | 94 } |
| 93 buf << "q " << pImageObj->m_Matrix << " cm "; | 95 buf << "q " << pImageObj->m_Matrix << " cm "; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 119 if (!data || !size) | 121 if (!data || !size) |
| 120 return; | 122 return; |
| 121 | 123 |
| 122 buf << "q " << matrix << " cm "; | 124 buf << "q " << matrix << " cm "; |
| 123 | 125 |
| 124 CFX_FloatRect bbox = m_pPage->GetPageBBox(); | 126 CFX_FloatRect bbox = m_pPage->GetPageBBox(); |
| 125 matrix.TransformRect(bbox); | 127 matrix.TransformRect(bbox); |
| 126 | 128 |
| 127 CPDF_Dictionary* pFormDict = | 129 CPDF_Dictionary* pFormDict = |
| 128 new CPDF_Dictionary(m_pDocument->GetByteStringPool()); | 130 new CPDF_Dictionary(m_pDocument->GetByteStringPool()); |
| 129 pFormDict->SetNameFor("Type", "XObject"); | 131 pFormDict->SetNewFor<CPDF_Name>("Type", "XObject"); |
| 130 pFormDict->SetNameFor("Subtype", "Form"); | 132 pFormDict->SetNewFor<CPDF_Name>("Subtype", "Form"); |
| 131 pFormDict->SetRectFor("BBox", bbox); | 133 pFormDict->SetRectFor("BBox", bbox); |
| 132 | 134 |
| 133 CPDF_Stream* pStream = m_pDocument->NewIndirect<CPDF_Stream>(); | 135 CPDF_Stream* pStream = m_pDocument->NewIndirect<CPDF_Stream>(); |
| 134 pStream->InitStream(data, size, pFormDict); | 136 pStream->InitStream(data, size, pFormDict); |
| 135 | 137 |
| 136 CFX_ByteString name = RealizeResource(pStream->GetObjNum(), "XObject"); | 138 CFX_ByteString name = RealizeResource(pStream->GetObjNum(), "XObject"); |
| 137 buf << "/" << PDF_NameEncode(name) << " Do Q\n"; | 139 buf << "/" << PDF_NameEncode(name) << " Do Q\n"; |
| 138 } | 140 } |
| 139 | 141 |
| 140 void CPDF_PageContentGenerator::TransformContent(CFX_Matrix& matrix) { | 142 void CPDF_PageContentGenerator::TransformContent(CFX_Matrix& matrix) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 ProcessForm(buf, pBuf, size, matrix); | 174 ProcessForm(buf, pBuf, size, matrix); |
| 173 FX_Free(pBuf); | 175 FX_Free(pBuf); |
| 174 FX_Free(pContentArray); | 176 FX_Free(pContentArray); |
| 175 } else if (CPDF_Stream* pStream = pContent->AsStream()) { | 177 } else if (CPDF_Stream* pStream = pContent->AsStream()) { |
| 176 CPDF_StreamAcc contentStream; | 178 CPDF_StreamAcc contentStream; |
| 177 contentStream.LoadAllData(pStream); | 179 contentStream.LoadAllData(pStream); |
| 178 ProcessForm(buf, contentStream.GetData(), contentStream.GetSize(), matrix); | 180 ProcessForm(buf, contentStream.GetData(), contentStream.GetSize(), matrix); |
| 179 } | 181 } |
| 180 CPDF_Stream* pStream = m_pDocument->NewIndirect<CPDF_Stream>(); | 182 CPDF_Stream* pStream = m_pDocument->NewIndirect<CPDF_Stream>(); |
| 181 pStream->SetData(buf.GetBuffer(), buf.GetLength()); | 183 pStream->SetData(buf.GetBuffer(), buf.GetLength()); |
| 182 m_pPage->m_pFormDict->SetReferenceFor("Contents", m_pDocument, pStream); | 184 m_pPage->m_pFormDict->SetNewFor<CPDF_Reference>("Contents", m_pDocument, |
| 185 pStream->GetObjNum()); |
| 183 } | 186 } |
| OLD | NEW |