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