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/fpdfdoc/cpvt_generateap.h" | 7 #include "core/fpdfdoc/cpvt_generateap.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 CPDF_Dictionary* pDRDict = pFormDict->GetDictFor("DR"); | 54 CPDF_Dictionary* pDRDict = pFormDict->GetDictFor("DR"); |
55 if (!pDRDict) | 55 if (!pDRDict) |
56 return false; | 56 return false; |
57 | 57 |
58 CPDF_Dictionary* pDRFontDict = pDRDict->GetDictFor("Font"); | 58 CPDF_Dictionary* pDRFontDict = pDRDict->GetDictFor("Font"); |
59 if (!pDRFontDict) | 59 if (!pDRFontDict) |
60 return false; | 60 return false; |
61 | 61 |
62 CPDF_Dictionary* pFontDict = pDRFontDict->GetDictFor(sFontName.Mid(1)); | 62 CPDF_Dictionary* pFontDict = pDRFontDict->GetDictFor(sFontName.Mid(1)); |
63 if (!pFontDict) { | 63 if (!pFontDict) { |
64 auto pNewFontDict = | 64 pFontDict = pDoc->NewIndirect<CPDF_Dictionary>(pDoc->GetByteStringPool()); |
65 pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool()); | 65 pFontDict->SetNameFor("Type", "Font"); |
66 pNewFontDict->SetNameFor("Type", "Font"); | 66 pFontDict->SetNameFor("Subtype", "Type1"); |
67 pNewFontDict->SetNameFor("Subtype", "Type1"); | 67 pFontDict->SetNameFor("BaseFont", "Helvetica"); |
68 pNewFontDict->SetNameFor("BaseFont", "Helvetica"); | 68 pFontDict->SetNameFor("Encoding", "WinAnsiEncoding"); |
69 pNewFontDict->SetNameFor("Encoding", "WinAnsiEncoding"); | 69 pDRFontDict->SetReferenceFor(sFontName.Mid(1), pDoc, pFontDict); |
70 // Ownership passes to AddIndirectObject(). | |
71 pFontDict = pNewFontDict.release(); | |
72 pDRFontDict->SetReferenceFor(sFontName.Mid(1), pDoc, | |
73 pDoc->AddIndirectObject(pFontDict)); | |
74 } | 70 } |
75 CPDF_Font* pDefFont = pDoc->LoadFont(pFontDict); | 71 CPDF_Font* pDefFont = pDoc->LoadFont(pFontDict); |
76 if (!pDefFont) | 72 if (!pDefFont) |
77 return false; | 73 return false; |
78 | 74 |
79 CFX_FloatRect rcAnnot = pAnnotDict->GetRectFor("Rect"); | 75 CFX_FloatRect rcAnnot = pAnnotDict->GetRectFor("Rect"); |
80 int32_t nRotate = 0; | 76 int32_t nRotate = 0; |
81 if (CPDF_Dictionary* pMKDict = pAnnotDict->GetDictFor("MK")) | 77 if (CPDF_Dictionary* pMKDict = pAnnotDict->GetDictFor("MK")) |
82 nRotate = pMKDict->GetIntegerFor("R"); | 78 nRotate = pMKDict->GetIntegerFor("R"); |
83 | 79 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 CPDF_Dictionary* pAPDict = pAnnotDict->GetDictFor("AP"); | 166 CPDF_Dictionary* pAPDict = pAnnotDict->GetDictFor("AP"); |
171 if (!pAPDict) { | 167 if (!pAPDict) { |
172 auto pNewAPDict = | 168 auto pNewAPDict = |
173 pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool()); | 169 pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool()); |
174 // Ownership passes to |pAnnotDict|. | 170 // Ownership passes to |pAnnotDict|. |
175 pAPDict = pNewAPDict.release(); | 171 pAPDict = pNewAPDict.release(); |
176 pAnnotDict->SetFor("AP", pAPDict); | 172 pAnnotDict->SetFor("AP", pAPDict); |
177 } | 173 } |
178 CPDF_Stream* pNormalStream = pAPDict->GetStreamFor("N"); | 174 CPDF_Stream* pNormalStream = pAPDict->GetStreamFor("N"); |
179 if (!pNormalStream) { | 175 if (!pNormalStream) { |
180 auto pNewNormalStream = pdfium::MakeUnique<CPDF_Stream>(); | 176 pNormalStream = pDoc->NewIndirect<CPDF_Stream>(); |
181 // Ownership passes to AddIndirectObject(). | 177 pAPDict->SetReferenceFor("N", pDoc, pNormalStream); |
182 pNormalStream = pNewNormalStream.release(); | |
183 pAPDict->SetReferenceFor("N", pDoc, pDoc->AddIndirectObject(pNormalStream)); | |
184 } | 178 } |
185 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); | 179 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); |
186 if (pStreamDict) { | 180 if (pStreamDict) { |
187 pStreamDict->SetMatrixFor("Matrix", matrix); | 181 pStreamDict->SetMatrixFor("Matrix", matrix); |
188 pStreamDict->SetRectFor("BBox", rcBBox); | 182 pStreamDict->SetRectFor("BBox", rcBBox); |
189 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources"); | 183 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources"); |
190 if (pStreamResList) { | 184 if (pStreamResList) { |
191 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictFor("Font"); | 185 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictFor("Font"); |
192 if (!pStreamResFontList) { | 186 if (!pStreamResFontList) { |
193 auto pNewStreamResFontList = | 187 auto pNewStreamResFontList = |
194 pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool()); | 188 pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool()); |
195 // Ownership passes to |pStreamResList|. | 189 // Ownership passes to |pStreamResList|. |
196 pStreamResFontList = pNewStreamResFontList.release(); | 190 pStreamResFontList = pNewStreamResFontList.release(); |
197 pStreamResList->SetFor("Font", pStreamResFontList); | 191 pStreamResList->SetFor("Font", pStreamResFontList); |
198 } | 192 } |
199 if (!pStreamResFontList->KeyExist(sFontName)) | 193 if (!pStreamResFontList->KeyExist(sFontName)) |
200 pStreamResFontList->SetReferenceFor(sFontName, pDoc, | 194 pStreamResFontList->SetReferenceFor(sFontName, pDoc, pFontDict); |
201 pFontDict->GetObjNum()); | |
202 } else { | 195 } else { |
203 pStreamDict->SetFor("Resources", | 196 pStreamDict->SetFor("Resources", |
204 pFormDict->GetDictFor("DR")->Clone().release()); | 197 pFormDict->GetDictFor("DR")->Clone().release()); |
205 pStreamResList = pStreamDict->GetDictFor("Resources"); | 198 pStreamResList = pStreamDict->GetDictFor("Resources"); |
206 } | 199 } |
207 } | 200 } |
208 switch (nWidgetType) { | 201 switch (nWidgetType) { |
209 case 0: { | 202 case 0: { |
210 CFX_WideString swValue = | 203 CFX_WideString swValue = |
211 FPDF_GetFieldAttr(pAnnotDict, "V") | 204 FPDF_GetFieldAttr(pAnnotDict, "V") |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 CPDF_Dictionary* pStreamResFontList = | 438 CPDF_Dictionary* pStreamResFontList = |
446 pStreamResList->GetDictFor("Font"); | 439 pStreamResList->GetDictFor("Font"); |
447 if (!pStreamResFontList) { | 440 if (!pStreamResFontList) { |
448 auto pNewStreamResFontList = | 441 auto pNewStreamResFontList = |
449 pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool()); | 442 pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool()); |
450 // Ownership passes to |pStreamResList|. | 443 // Ownership passes to |pStreamResList|. |
451 pStreamResFontList = pNewStreamResFontList.release(); | 444 pStreamResFontList = pNewStreamResFontList.release(); |
452 pStreamResList->SetFor("Font", pStreamResFontList); | 445 pStreamResList->SetFor("Font", pStreamResFontList); |
453 } | 446 } |
454 if (!pStreamResFontList->KeyExist(sFontName)) | 447 if (!pStreamResFontList->KeyExist(sFontName)) |
455 pStreamResFontList->SetReferenceFor(sFontName, pDoc, | 448 pStreamResFontList->SetReferenceFor(sFontName, pDoc, pFontDict); |
456 pFontDict->GetObjNum()); | |
457 } else { | 449 } else { |
458 pStreamDict->SetFor("Resources", | 450 pStreamDict->SetFor("Resources", |
459 pFormDict->GetDictFor("DR")->Clone().release()); | 451 pFormDict->GetDictFor("DR")->Clone().release()); |
460 pStreamResList = pStreamDict->GetDictFor("Resources"); | 452 pStreamResList = pStreamDict->GetDictFor("Resources"); |
461 } | 453 } |
462 } | 454 } |
463 } | 455 } |
464 return true; | 456 return true; |
465 } | 457 } |
466 | 458 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 | 565 |
574 auto pExtGStateDict = | 566 auto pExtGStateDict = |
575 pdfium::MakeUnique<CPDF_Dictionary>(pAnnotDict.GetByteStringPool()); | 567 pdfium::MakeUnique<CPDF_Dictionary>(pAnnotDict.GetByteStringPool()); |
576 pExtGStateDict->SetFor(sExtGSDictName, pGSDict.release()); | 568 pExtGStateDict->SetFor(sExtGSDictName, pGSDict.release()); |
577 return pExtGStateDict; | 569 return pExtGStateDict; |
578 } | 570 } |
579 | 571 |
580 std::unique_ptr<CPDF_Dictionary> GenerateResourceFontDict( | 572 std::unique_ptr<CPDF_Dictionary> GenerateResourceFontDict( |
581 CPDF_Document* pDoc, | 573 CPDF_Document* pDoc, |
582 const CFX_ByteString& sFontDictName) { | 574 const CFX_ByteString& sFontDictName) { |
583 auto pFontDict = | 575 CPDF_Dictionary* pFontDict = |
584 pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool()); | 576 pDoc->NewIndirect<CPDF_Dictionary>(pDoc->GetByteStringPool()); |
585 pFontDict->SetNameFor("Type", "Font"); | 577 pFontDict->SetNameFor("Type", "Font"); |
586 pFontDict->SetNameFor("Subtype", "Type1"); | 578 pFontDict->SetNameFor("Subtype", "Type1"); |
587 pFontDict->SetNameFor("BaseFont", "Helvetica"); | 579 pFontDict->SetNameFor("BaseFont", "Helvetica"); |
588 pFontDict->SetNameFor("Encoding", "WinAnsiEncoding"); | 580 pFontDict->SetNameFor("Encoding", "WinAnsiEncoding"); |
589 | 581 |
590 auto pResourceFontDict = | 582 auto pResourceFontDict = |
591 pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool()); | 583 pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool()); |
592 pResourceFontDict->SetReferenceFor( | 584 pResourceFontDict->SetReferenceFor(sFontDictName, pDoc, pFontDict); |
593 sFontDictName, pDoc, pDoc->AddIndirectObject(pFontDict.release())); | |
594 return pResourceFontDict; | 585 return pResourceFontDict; |
595 } | 586 } |
596 | 587 |
597 std::unique_ptr<CPDF_Dictionary> GenerateResourceDict( | 588 std::unique_ptr<CPDF_Dictionary> GenerateResourceDict( |
598 CPDF_Document* pDoc, | 589 CPDF_Document* pDoc, |
599 std::unique_ptr<CPDF_Dictionary> pExtGStateDict, | 590 std::unique_ptr<CPDF_Dictionary> pExtGStateDict, |
600 std::unique_ptr<CPDF_Dictionary> pResourceFontDict) { | 591 std::unique_ptr<CPDF_Dictionary> pResourceFontDict) { |
601 auto pResourceDict = | 592 auto pResourceDict = |
602 pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool()); | 593 pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool()); |
603 if (pExtGStateDict) | 594 if (pExtGStateDict) |
604 pResourceDict->SetFor("ExtGState", pExtGStateDict.release()); | 595 pResourceDict->SetFor("ExtGState", pExtGStateDict.release()); |
605 if (pResourceFontDict) | 596 if (pResourceFontDict) |
606 pResourceDict->SetFor("Font", pResourceFontDict.release()); | 597 pResourceDict->SetFor("Font", pResourceFontDict.release()); |
607 return pResourceDict; | 598 return pResourceDict; |
608 } | 599 } |
609 | 600 |
610 void GenerateAndSetAPDict(CPDF_Document* pDoc, | 601 void GenerateAndSetAPDict(CPDF_Document* pDoc, |
611 CPDF_Dictionary* pAnnotDict, | 602 CPDF_Dictionary* pAnnotDict, |
612 const CFX_ByteTextBuf& sAppStream, | 603 const CFX_ByteTextBuf& sAppStream, |
613 std::unique_ptr<CPDF_Dictionary> pResourceDict, | 604 std::unique_ptr<CPDF_Dictionary> pResourceDict, |
614 bool bIsTextMarkupAnnotation) { | 605 bool bIsTextMarkupAnnotation) { |
615 auto pNormalStream = pdfium::MakeUnique<CPDF_Stream>(); | 606 CPDF_Stream* pNormalStream = pDoc->NewIndirect<CPDF_Stream>(); |
616 pNormalStream->SetData(sAppStream.GetBuffer(), sAppStream.GetSize()); | 607 pNormalStream->SetData(sAppStream.GetBuffer(), sAppStream.GetSize()); |
617 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); | |
618 | 608 |
619 auto pAPDict = pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool()); | 609 auto pAPDict = pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool()); |
620 pAPDict->SetReferenceFor("N", pDoc, | 610 pAPDict->SetReferenceFor("N", pDoc, pNormalStream); |
621 pDoc->AddIndirectObject(pNormalStream.release())); | |
622 pAnnotDict->SetFor("AP", pAPDict.release()); | 611 pAnnotDict->SetFor("AP", pAPDict.release()); |
623 | 612 |
| 613 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); |
624 pStreamDict->SetIntegerFor("FormType", 1); | 614 pStreamDict->SetIntegerFor("FormType", 1); |
625 pStreamDict->SetStringFor("Subtype", "Form"); | 615 pStreamDict->SetStringFor("Subtype", "Form"); |
626 pStreamDict->SetMatrixFor("Matrix", CFX_Matrix()); | 616 pStreamDict->SetMatrixFor("Matrix", CFX_Matrix()); |
627 | 617 |
628 CFX_FloatRect rect = bIsTextMarkupAnnotation | 618 CFX_FloatRect rect = bIsTextMarkupAnnotation |
629 ? CPDF_Annot::RectFromQuadPoints(pAnnotDict) | 619 ? CPDF_Annot::RectFromQuadPoints(pAnnotDict) |
630 : pAnnotDict->GetRectFor("Rect"); | 620 : pAnnotDict->GetRectFor("Rect"); |
631 pStreamDict->SetRectFor("BBox", rect); | 621 pStreamDict->SetRectFor("BBox", rect); |
632 pStreamDict->SetFor("Resources", pResourceDict.release()); | 622 pStreamDict->SetFor("Resources", pResourceDict.release()); |
633 } | 623 } |
(...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1372 int32_t nFontIndex, | 1362 int32_t nFontIndex, |
1373 FX_FLOAT fFontSize) { | 1363 FX_FLOAT fFontSize) { |
1374 CFX_ByteTextBuf sRet; | 1364 CFX_ByteTextBuf sRet; |
1375 if (pFontMap) { | 1365 if (pFontMap) { |
1376 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); | 1366 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); |
1377 if (sFontAlias.GetLength() > 0 && fFontSize > 0) | 1367 if (sFontAlias.GetLength() > 0 && fFontSize > 0) |
1378 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; | 1368 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; |
1379 } | 1369 } |
1380 return sRet.MakeString(); | 1370 return sRet.MakeString(); |
1381 } | 1371 } |
OLD | NEW |