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 "core/fpdfapi/fpdf_font/include/cpdf_font.h" | 9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" |
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" | 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 return FALSE; | 29 return FALSE; |
30 | 30 |
31 CFX_ByteString DA; | 31 CFX_ByteString DA; |
32 if (CPDF_Object* pDAObj = FPDF_GetFieldAttr(pAnnotDict, "DA")) | 32 if (CPDF_Object* pDAObj = FPDF_GetFieldAttr(pAnnotDict, "DA")) |
33 DA = pDAObj->GetString(); | 33 DA = pDAObj->GetString(); |
34 if (DA.IsEmpty()) | 34 if (DA.IsEmpty()) |
35 DA = pFormDict->GetStringBy("DA"); | 35 DA = pFormDict->GetStringBy("DA"); |
36 if (DA.IsEmpty()) | 36 if (DA.IsEmpty()) |
37 return FALSE; | 37 return FALSE; |
38 | 38 |
39 CPDF_SimpleParser syntax(DA); | 39 CPDF_SimpleParser syntax(DA.AsByteStringC()); |
40 syntax.FindTagParamFromStart("Tf", 2); | 40 syntax.FindTagParamFromStart("Tf", 2); |
41 CFX_ByteString sFontName = syntax.GetWord(); | 41 CFX_ByteString sFontName = syntax.GetWord(); |
42 sFontName = PDF_NameDecode(sFontName); | 42 sFontName = PDF_NameDecode(sFontName); |
43 if (sFontName.IsEmpty()) | 43 if (sFontName.IsEmpty()) |
44 return FALSE; | 44 return FALSE; |
45 | 45 |
46 FX_FLOAT fFontSize = FX_atof(syntax.GetWord()); | 46 FX_FLOAT fFontSize = FX_atof(syntax.GetWord()); |
47 CPVT_Color crText = CPVT_Color::ParseColor(DA); | 47 CPVT_Color crText = CPVT_Color::ParseColor(DA); |
48 FX_BOOL bUseFormRes = FALSE; | 48 FX_BOOL bUseFormRes = FALSE; |
49 CPDF_Dictionary* pFontDict = nullptr; | 49 CPDF_Dictionary* pFontDict = nullptr; |
50 CPDF_Dictionary* pDRDict = pAnnotDict->GetDictBy("DR"); | 50 CPDF_Dictionary* pDRDict = pAnnotDict->GetDictBy("DR"); |
51 if (!pDRDict) { | 51 if (!pDRDict) { |
52 pDRDict = pFormDict->GetDictBy("DR"); | 52 pDRDict = pFormDict->GetDictBy("DR"); |
53 bUseFormRes = TRUE; | 53 bUseFormRes = TRUE; |
54 } | 54 } |
55 CPDF_Dictionary* pDRFontDict = pDRDict ? pDRDict->GetDictBy("Font") : nullptr; | 55 CPDF_Dictionary* pDRFontDict = pDRDict ? pDRDict->GetDictBy("Font") : nullptr; |
56 if (pDRFontDict) { | 56 if (pDRFontDict) { |
57 pFontDict = pDRFontDict->GetDictBy(sFontName.Mid(1)); | 57 pFontDict = pDRFontDict->GetDictBy(sFontName.Mid(1).AsByteStringC()); |
58 if (!pFontDict && !bUseFormRes) { | 58 if (!pFontDict && !bUseFormRes) { |
59 pDRDict = pFormDict->GetDictBy("DR"); | 59 pDRDict = pFormDict->GetDictBy("DR"); |
60 pDRFontDict = pDRDict->GetDictBy("Font"); | 60 pDRFontDict = pDRDict->GetDictBy("Font"); |
61 if (pDRFontDict) | 61 if (pDRFontDict) |
62 pFontDict = pDRFontDict->GetDictBy(sFontName.Mid(1)); | 62 pFontDict = pDRFontDict->GetDictBy(sFontName.Mid(1).AsByteStringC()); |
63 } | 63 } |
64 } | 64 } |
65 if (!pDRFontDict) | 65 if (!pDRFontDict) |
66 return FALSE; | 66 return FALSE; |
67 | 67 |
68 if (!pFontDict) { | 68 if (!pFontDict) { |
69 pFontDict = new CPDF_Dictionary; | 69 pFontDict = new CPDF_Dictionary; |
70 pFontDict->SetAtName("Type", "Font"); | 70 pFontDict->SetAtName("Type", "Font"); |
71 pFontDict->SetAtName("Subtype", "Type1"); | 71 pFontDict->SetAtName("Subtype", "Type1"); |
72 pFontDict->SetAtName("BaseFont", "Helvetica"); | 72 pFontDict->SetAtName("BaseFont", "Helvetica"); |
73 pFontDict->SetAtName("Encoding", "WinAnsiEncoding"); | 73 pFontDict->SetAtName("Encoding", "WinAnsiEncoding"); |
74 pDoc->AddIndirectObject(pFontDict); | 74 pDoc->AddIndirectObject(pFontDict); |
75 pDRFontDict->SetAtReference(sFontName.Mid(1), pDoc, pFontDict); | 75 pDRFontDict->SetAtReference(sFontName.Mid(1).AsByteStringC(), pDoc, |
| 76 pFontDict); |
76 } | 77 } |
77 CPDF_Font* pDefFont = pDoc->LoadFont(pFontDict); | 78 CPDF_Font* pDefFont = pDoc->LoadFont(pFontDict); |
78 if (!pDefFont) | 79 if (!pDefFont) |
79 return FALSE; | 80 return FALSE; |
80 | 81 |
81 CFX_FloatRect rcAnnot = pAnnotDict->GetRectBy("Rect"); | 82 CFX_FloatRect rcAnnot = pAnnotDict->GetRectBy("Rect"); |
82 int32_t nRotate = 0; | 83 int32_t nRotate = 0; |
83 if (CPDF_Dictionary* pMKDict = pAnnotDict->GetDictBy("MK")) | 84 if (CPDF_Dictionary* pMKDict = pAnnotDict->GetDictBy("MK")) |
84 nRotate = pMKDict->GetIntegerBy("R"); | 85 nRotate = pMKDict->GetIntegerBy("R"); |
85 | 86 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 if (pStreamDict) { | 183 if (pStreamDict) { |
183 pStreamDict->SetAtMatrix("Matrix", matrix); | 184 pStreamDict->SetAtMatrix("Matrix", matrix); |
184 pStreamDict->SetAtRect("BBox", rcBBox); | 185 pStreamDict->SetAtRect("BBox", rcBBox); |
185 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictBy("Resources"); | 186 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictBy("Resources"); |
186 if (pStreamResList) { | 187 if (pStreamResList) { |
187 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictBy("Font"); | 188 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictBy("Font"); |
188 if (!pStreamResFontList) { | 189 if (!pStreamResFontList) { |
189 pStreamResFontList = new CPDF_Dictionary; | 190 pStreamResFontList = new CPDF_Dictionary; |
190 pStreamResList->SetAt("Font", pStreamResFontList); | 191 pStreamResList->SetAt("Font", pStreamResFontList); |
191 } | 192 } |
192 if (!pStreamResFontList->KeyExist(sFontName)) | 193 if (!pStreamResFontList->KeyExist(sFontName.AsByteStringC())) |
193 pStreamResFontList->SetAtReference(sFontName, pDoc, pFontDict); | 194 pStreamResFontList->SetAtReference(sFontName.AsByteStringC(), pDoc, |
| 195 pFontDict); |
194 } else { | 196 } else { |
195 pStreamDict->SetAt("Resources", pFormDict->GetDictBy("DR")->Clone()); | 197 pStreamDict->SetAt("Resources", pFormDict->GetDictBy("DR")->Clone()); |
196 pStreamResList = pStreamDict->GetDictBy("Resources"); | 198 pStreamResList = pStreamDict->GetDictBy("Resources"); |
197 } | 199 } |
198 } | 200 } |
199 switch (nWidgetType) { | 201 switch (nWidgetType) { |
200 case 0: { | 202 case 0: { |
201 CFX_WideString swValue = | 203 CFX_WideString swValue = |
202 FPDF_GetFieldAttr(pAnnotDict, "V") | 204 FPDF_GetFieldAttr(pAnnotDict, "V") |
203 ? FPDF_GetFieldAttr(pAnnotDict, "V")->GetUnicodeText() | 205 ? FPDF_GetFieldAttr(pAnnotDict, "V")->GetUnicodeText() |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 if (pStreamDict) { | 430 if (pStreamDict) { |
429 pStreamDict->SetAtMatrix("Matrix", matrix); | 431 pStreamDict->SetAtMatrix("Matrix", matrix); |
430 pStreamDict->SetAtRect("BBox", rcBBox); | 432 pStreamDict->SetAtRect("BBox", rcBBox); |
431 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictBy("Resources"); | 433 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictBy("Resources"); |
432 if (pStreamResList) { | 434 if (pStreamResList) { |
433 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictBy("Font"); | 435 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictBy("Font"); |
434 if (!pStreamResFontList) { | 436 if (!pStreamResFontList) { |
435 pStreamResFontList = new CPDF_Dictionary; | 437 pStreamResFontList = new CPDF_Dictionary; |
436 pStreamResList->SetAt("Font", pStreamResFontList); | 438 pStreamResList->SetAt("Font", pStreamResFontList); |
437 } | 439 } |
438 if (!pStreamResFontList->KeyExist(sFontName)) | 440 if (!pStreamResFontList->KeyExist(sFontName.AsByteStringC())) |
439 pStreamResFontList->SetAtReference(sFontName, pDoc, pFontDict); | 441 pStreamResFontList->SetAtReference(sFontName.AsByteStringC(), pDoc, |
| 442 pFontDict); |
440 } else { | 443 } else { |
441 pStreamDict->SetAt("Resources", pFormDict->GetDictBy("DR")->Clone()); | 444 pStreamDict->SetAt("Resources", pFormDict->GetDictBy("DR")->Clone()); |
442 pStreamResList = pStreamDict->GetDictBy("Resources"); | 445 pStreamResList = pStreamDict->GetDictBy("Resources"); |
443 } | 446 } |
444 } | 447 } |
445 } | 448 } |
446 return TRUE; | 449 return TRUE; |
447 } | 450 } |
448 | 451 |
449 } // namespace | 452 } // namespace |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
760 int32_t nFontIndex, | 763 int32_t nFontIndex, |
761 FX_FLOAT fFontSize) { | 764 FX_FLOAT fFontSize) { |
762 CFX_ByteTextBuf sRet; | 765 CFX_ByteTextBuf sRet; |
763 if (pFontMap) { | 766 if (pFontMap) { |
764 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); | 767 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); |
765 if (sFontAlias.GetLength() > 0 && fFontSize > 0) | 768 if (sFontAlias.GetLength() > 0 && fFontSize > 0) |
766 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; | 769 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; |
767 } | 770 } |
768 return sRet.GetByteString(); | 771 return sRet.GetByteString(); |
769 } | 772 } |
OLD | NEW |