| 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 | 10 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 CPDF_Dictionary* pDRDict = pFormDict->GetDictFor("DR"); | 51 CPDF_Dictionary* pDRDict = pFormDict->GetDictFor("DR"); |
| 52 if (!pDRDict) | 52 if (!pDRDict) |
| 53 return false; | 53 return false; |
| 54 | 54 |
| 55 CPDF_Dictionary* pDRFontDict = pDRDict->GetDictFor("Font"); | 55 CPDF_Dictionary* pDRFontDict = pDRDict->GetDictFor("Font"); |
| 56 if (!pDRFontDict) | 56 if (!pDRFontDict) |
| 57 return false; | 57 return false; |
| 58 | 58 |
| 59 CPDF_Dictionary* pFontDict = pDRFontDict->GetDictFor(sFontName.Mid(1)); | 59 CPDF_Dictionary* pFontDict = pDRFontDict->GetDictFor(sFontName.Mid(1)); |
| 60 if (!pFontDict) { | 60 if (!pFontDict) { |
| 61 pFontDict = new CPDF_Dictionary(pDoc->GetByteStringPool()); | 61 pFontDict = pDoc->AddIndirectDictionary(pDoc->GetByteStringPool()); |
| 62 pFontDict->SetNameFor("Type", "Font"); | 62 pFontDict->SetNameFor("Type", "Font"); |
| 63 pFontDict->SetNameFor("Subtype", "Type1"); | 63 pFontDict->SetNameFor("Subtype", "Type1"); |
| 64 pFontDict->SetNameFor("BaseFont", "Helvetica"); | 64 pFontDict->SetNameFor("BaseFont", "Helvetica"); |
| 65 pFontDict->SetNameFor("Encoding", "WinAnsiEncoding"); | 65 pFontDict->SetNameFor("Encoding", "WinAnsiEncoding"); |
| 66 pDRFontDict->SetReferenceFor(sFontName.Mid(1), pDoc, | 66 pDRFontDict->SetReferenceFor(sFontName.Mid(1), pDoc, pFontDict); |
| 67 pDoc->AddIndirectObject(pFontDict)); | |
| 68 } | 67 } |
| 69 CPDF_Font* pDefFont = pDoc->LoadFont(pFontDict); | 68 CPDF_Font* pDefFont = pDoc->LoadFont(pFontDict); |
| 70 if (!pDefFont) | 69 if (!pDefFont) |
| 71 return false; | 70 return false; |
| 72 | 71 |
| 73 CFX_FloatRect rcAnnot = pAnnotDict->GetRectFor("Rect"); | 72 CFX_FloatRect rcAnnot = pAnnotDict->GetRectFor("Rect"); |
| 74 int32_t nRotate = 0; | 73 int32_t nRotate = 0; |
| 75 if (CPDF_Dictionary* pMKDict = pAnnotDict->GetDictFor("MK")) | 74 if (CPDF_Dictionary* pMKDict = pAnnotDict->GetDictFor("MK")) |
| 76 nRotate = pMKDict->GetIntegerFor("R"); | 75 nRotate = pMKDict->GetIntegerFor("R"); |
| 77 | 76 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 CFX_FloatRect(rcBBox.left + fBorderWidth, rcBBox.bottom + fBorderWidth, | 160 CFX_FloatRect(rcBBox.left + fBorderWidth, rcBBox.bottom + fBorderWidth, |
| 162 rcBBox.right - fBorderWidth, rcBBox.top - fBorderWidth); | 161 rcBBox.right - fBorderWidth, rcBBox.top - fBorderWidth); |
| 163 rcBody.Normalize(); | 162 rcBody.Normalize(); |
| 164 CPDF_Dictionary* pAPDict = pAnnotDict->GetDictFor("AP"); | 163 CPDF_Dictionary* pAPDict = pAnnotDict->GetDictFor("AP"); |
| 165 if (!pAPDict) { | 164 if (!pAPDict) { |
| 166 pAPDict = new CPDF_Dictionary(pDoc->GetByteStringPool()); | 165 pAPDict = new CPDF_Dictionary(pDoc->GetByteStringPool()); |
| 167 pAnnotDict->SetFor("AP", pAPDict); | 166 pAnnotDict->SetFor("AP", pAPDict); |
| 168 } | 167 } |
| 169 CPDF_Stream* pNormalStream = pAPDict->GetStreamFor("N"); | 168 CPDF_Stream* pNormalStream = pAPDict->GetStreamFor("N"); |
| 170 if (!pNormalStream) { | 169 if (!pNormalStream) { |
| 171 pNormalStream = new CPDF_Stream; | 170 pNormalStream = pDoc->AddIndirectStream(); |
| 172 pAPDict->SetReferenceFor("N", pDoc, pDoc->AddIndirectObject(pNormalStream)); | 171 pAPDict->SetReferenceFor("N", pDoc, pNormalStream); |
| 173 } | 172 } |
| 174 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); | 173 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); |
| 175 if (pStreamDict) { | 174 if (pStreamDict) { |
| 176 pStreamDict->SetMatrixFor("Matrix", matrix); | 175 pStreamDict->SetMatrixFor("Matrix", matrix); |
| 177 pStreamDict->SetRectFor("BBox", rcBBox); | 176 pStreamDict->SetRectFor("BBox", rcBBox); |
| 178 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources"); | 177 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources"); |
| 179 if (pStreamResList) { | 178 if (pStreamResList) { |
| 180 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictFor("Font"); | 179 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictFor("Font"); |
| 181 if (!pStreamResFontList) { | 180 if (!pStreamResFontList) { |
| 182 pStreamResFontList = new CPDF_Dictionary(pDoc->GetByteStringPool()); | 181 pStreamResFontList = new CPDF_Dictionary(pDoc->GetByteStringPool()); |
| 183 pStreamResList->SetFor("Font", pStreamResFontList); | 182 pStreamResList->SetFor("Font", pStreamResFontList); |
| 184 } | 183 } |
| 185 if (!pStreamResFontList->KeyExist(sFontName)) | 184 if (!pStreamResFontList->KeyExist(sFontName)) |
| 186 pStreamResFontList->SetReferenceFor(sFontName, pDoc, | 185 pStreamResFontList->SetReferenceFor(sFontName, pDoc, pFontDict); |
| 187 pFontDict->GetObjNum()); | |
| 188 } else { | 186 } else { |
| 189 pStreamDict->SetFor("Resources", pFormDict->GetDictFor("DR")->Clone()); | 187 pStreamDict->SetFor("Resources", pFormDict->GetDictFor("DR")->Clone()); |
| 190 pStreamResList = pStreamDict->GetDictFor("Resources"); | 188 pStreamResList = pStreamDict->GetDictFor("Resources"); |
| 191 } | 189 } |
| 192 } | 190 } |
| 193 switch (nWidgetType) { | 191 switch (nWidgetType) { |
| 194 case 0: { | 192 case 0: { |
| 195 CFX_WideString swValue = | 193 CFX_WideString swValue = |
| 196 FPDF_GetFieldAttr(pAnnotDict, "V") | 194 FPDF_GetFieldAttr(pAnnotDict, "V") |
| 197 ? FPDF_GetFieldAttr(pAnnotDict, "V")->GetUnicodeText() | 195 ? FPDF_GetFieldAttr(pAnnotDict, "V")->GetUnicodeText() |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 pStreamDict->SetRectFor("BBox", rcBBox); | 425 pStreamDict->SetRectFor("BBox", rcBBox); |
| 428 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources"); | 426 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources"); |
| 429 if (pStreamResList) { | 427 if (pStreamResList) { |
| 430 CPDF_Dictionary* pStreamResFontList = | 428 CPDF_Dictionary* pStreamResFontList = |
| 431 pStreamResList->GetDictFor("Font"); | 429 pStreamResList->GetDictFor("Font"); |
| 432 if (!pStreamResFontList) { | 430 if (!pStreamResFontList) { |
| 433 pStreamResFontList = new CPDF_Dictionary(pDoc->GetByteStringPool()); | 431 pStreamResFontList = new CPDF_Dictionary(pDoc->GetByteStringPool()); |
| 434 pStreamResList->SetFor("Font", pStreamResFontList); | 432 pStreamResList->SetFor("Font", pStreamResFontList); |
| 435 } | 433 } |
| 436 if (!pStreamResFontList->KeyExist(sFontName)) | 434 if (!pStreamResFontList->KeyExist(sFontName)) |
| 437 pStreamResFontList->SetReferenceFor(sFontName, pDoc, | 435 pStreamResFontList->SetReferenceFor(sFontName, pDoc, pFontDict); |
| 438 pFontDict->GetObjNum()); | |
| 439 } else { | 436 } else { |
| 440 pStreamDict->SetFor("Resources", pFormDict->GetDictFor("DR")->Clone()); | 437 pStreamDict->SetFor("Resources", pFormDict->GetDictFor("DR")->Clone()); |
| 441 pStreamResList = pStreamDict->GetDictFor("Resources"); | 438 pStreamResList = pStreamDict->GetDictFor("Resources"); |
| 442 } | 439 } |
| 443 } | 440 } |
| 444 } | 441 } |
| 445 return true; | 442 return true; |
| 446 } | 443 } |
| 447 | 444 |
| 448 CFX_ByteString GetColorStringWithDefault(CPDF_Array* pColor, | 445 CFX_ByteString GetColorStringWithDefault(CPDF_Array* pColor, |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 pGSDict->SetStringFor("BM", sBlendMode); | 549 pGSDict->SetStringFor("BM", sBlendMode); |
| 553 | 550 |
| 554 CPDF_Dictionary* pExtGStateDict = | 551 CPDF_Dictionary* pExtGStateDict = |
| 555 new CPDF_Dictionary(pAnnotDict.GetByteStringPool()); | 552 new CPDF_Dictionary(pAnnotDict.GetByteStringPool()); |
| 556 pExtGStateDict->SetFor(sExtGSDictName, pGSDict); | 553 pExtGStateDict->SetFor(sExtGSDictName, pGSDict); |
| 557 return pExtGStateDict; | 554 return pExtGStateDict; |
| 558 } | 555 } |
| 559 | 556 |
| 560 CPDF_Dictionary* GenerateResourceFontDict(CPDF_Document* pDoc, | 557 CPDF_Dictionary* GenerateResourceFontDict(CPDF_Document* pDoc, |
| 561 const CFX_ByteString& sFontDictName) { | 558 const CFX_ByteString& sFontDictName) { |
| 562 CPDF_Dictionary* pFontDict = new CPDF_Dictionary(pDoc->GetByteStringPool()); | 559 CPDF_Dictionary* pFontDict = |
| 560 pDoc->AddIndirectDictionary(pDoc->GetByteStringPool()); |
| 563 pFontDict->SetNameFor("Type", "Font"); | 561 pFontDict->SetNameFor("Type", "Font"); |
| 564 pFontDict->SetNameFor("Subtype", "Type1"); | 562 pFontDict->SetNameFor("Subtype", "Type1"); |
| 565 pFontDict->SetNameFor("BaseFont", "Helvetica"); | 563 pFontDict->SetNameFor("BaseFont", "Helvetica"); |
| 566 pFontDict->SetNameFor("Encoding", "WinAnsiEncoding"); | 564 pFontDict->SetNameFor("Encoding", "WinAnsiEncoding"); |
| 567 | 565 |
| 568 CPDF_Dictionary* pResourceFontDict = | 566 CPDF_Dictionary* pResourceFontDict = |
| 569 new CPDF_Dictionary(pDoc->GetByteStringPool()); | 567 new CPDF_Dictionary(pDoc->GetByteStringPool()); |
| 570 pResourceFontDict->SetReferenceFor(sFontDictName, pDoc, | 568 pResourceFontDict->SetReferenceFor(sFontDictName, pDoc, pFontDict); |
| 571 pDoc->AddIndirectObject(pFontDict)); | |
| 572 return pResourceFontDict; | 569 return pResourceFontDict; |
| 573 } | 570 } |
| 574 | 571 |
| 575 // Takes ownership of |pExtGStateDict| and |pResourceFontDict|. | 572 // Takes ownership of |pExtGStateDict| and |pResourceFontDict|. |
| 576 CPDF_Dictionary* GenerateResourceDict(CPDF_Document* pDoc, | 573 CPDF_Dictionary* GenerateResourceDict(CPDF_Document* pDoc, |
| 577 CPDF_Dictionary* pExtGStateDict, | 574 CPDF_Dictionary* pExtGStateDict, |
| 578 CPDF_Dictionary* pResourceFontDict) { | 575 CPDF_Dictionary* pResourceFontDict) { |
| 579 CPDF_Dictionary* pResourceDict = | 576 CPDF_Dictionary* pResourceDict = |
| 580 new CPDF_Dictionary(pDoc->GetByteStringPool()); | 577 new CPDF_Dictionary(pDoc->GetByteStringPool()); |
| 581 if (pExtGStateDict) | 578 if (pExtGStateDict) |
| 582 pResourceDict->SetFor("ExtGState", pExtGStateDict); | 579 pResourceDict->SetFor("ExtGState", pExtGStateDict); |
| 583 | 580 |
| 584 if (pResourceFontDict) | 581 if (pResourceFontDict) |
| 585 pResourceDict->SetFor("Font", pResourceFontDict); | 582 pResourceDict->SetFor("Font", pResourceFontDict); |
| 586 | 583 |
| 587 return pResourceDict; | 584 return pResourceDict; |
| 588 } | 585 } |
| 589 | 586 |
| 590 // Takes ownership of |pResourceDict|. | 587 // Takes ownership of |pResourceDict|. |
| 591 void GenerateAndSetAPDict(CPDF_Document* pDoc, | 588 void GenerateAndSetAPDict(CPDF_Document* pDoc, |
| 592 CPDF_Dictionary* pAnnotDict, | 589 CPDF_Dictionary* pAnnotDict, |
| 593 const CFX_ByteTextBuf& sAppStream, | 590 const CFX_ByteTextBuf& sAppStream, |
| 594 CPDF_Dictionary* pResourceDict, | 591 CPDF_Dictionary* pResourceDict, |
| 595 bool bIsTextMarkupAnnotation) { | 592 bool bIsTextMarkupAnnotation) { |
| 596 CPDF_Dictionary* pAPDict = new CPDF_Dictionary(pDoc->GetByteStringPool()); | 593 CPDF_Dictionary* pAPDict = new CPDF_Dictionary(pDoc->GetByteStringPool()); |
| 597 pAnnotDict->SetFor("AP", pAPDict); | 594 pAnnotDict->SetFor("AP", pAPDict); |
| 598 | 595 |
| 599 CPDF_Stream* pNormalStream = new CPDF_Stream; | 596 CPDF_Stream* pNormalStream = pDoc->AddIndirectStream(); |
| 600 pNormalStream->SetData(sAppStream.GetBuffer(), sAppStream.GetSize()); | 597 pNormalStream->SetData(sAppStream.GetBuffer(), sAppStream.GetSize()); |
| 601 pAPDict->SetReferenceFor("N", pDoc, pDoc->AddIndirectObject(pNormalStream)); | 598 pAPDict->SetReferenceFor("N", pDoc, pNormalStream); |
| 602 | 599 |
| 603 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); | 600 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); |
| 604 pStreamDict->SetIntegerFor("FormType", 1); | 601 pStreamDict->SetIntegerFor("FormType", 1); |
| 605 pStreamDict->SetStringFor("Subtype", "Form"); | 602 pStreamDict->SetStringFor("Subtype", "Form"); |
| 606 pStreamDict->SetMatrixFor("Matrix", CFX_Matrix()); | 603 pStreamDict->SetMatrixFor("Matrix", CFX_Matrix()); |
| 607 | 604 |
| 608 CFX_FloatRect rect = bIsTextMarkupAnnotation | 605 CFX_FloatRect rect = bIsTextMarkupAnnotation |
| 609 ? CPDF_Annot::RectFromQuadPoints(pAnnotDict) | 606 ? CPDF_Annot::RectFromQuadPoints(pAnnotDict) |
| 610 : pAnnotDict->GetRectFor("Rect"); | 607 : pAnnotDict->GetRectFor("Rect"); |
| 611 pStreamDict->SetRectFor("BBox", rect); | 608 pStreamDict->SetRectFor("BBox", rect); |
| (...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1353 int32_t nFontIndex, | 1350 int32_t nFontIndex, |
| 1354 FX_FLOAT fFontSize) { | 1351 FX_FLOAT fFontSize) { |
| 1355 CFX_ByteTextBuf sRet; | 1352 CFX_ByteTextBuf sRet; |
| 1356 if (pFontMap) { | 1353 if (pFontMap) { |
| 1357 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); | 1354 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); |
| 1358 if (sFontAlias.GetLength() > 0 && fFontSize > 0) | 1355 if (sFontAlias.GetLength() > 0 && fFontSize > 0) |
| 1359 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; | 1356 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; |
| 1360 } | 1357 } |
| 1361 return sRet.MakeString(); | 1358 return sRet.MakeString(); |
| 1362 } | 1359 } |
| OLD | NEW |