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