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" |
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
12 #include "core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h" | 12 #include "core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h" |
13 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" | 13 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" |
14 #include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" | 14 #include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" |
15 #include "core/fpdfdoc/cpvt_color.h" | 15 #include "core/fpdfdoc/cpvt_color.h" |
16 #include "core/fpdfdoc/cpvt_fontmap.h" | 16 #include "core/fpdfdoc/cpvt_fontmap.h" |
17 #include "core/fpdfdoc/include/cpdf_annot.h" | 17 #include "core/fpdfdoc/include/cpdf_annot.h" |
18 #include "core/fpdfdoc/include/cpdf_formfield.h" | 18 #include "core/fpdfdoc/include/cpdf_formfield.h" |
19 #include "core/fpdfdoc/include/cpvt_word.h" | 19 #include "core/fpdfdoc/include/cpvt_word.h" |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 bool GenerateWidgetAP(CPDF_Document* pDoc, | 23 bool GenerateWidgetAP(CPDF_Document* pDoc, |
24 CPDF_Dictionary* pAnnotDict, | 24 CPDF_Dictionary* pAnnotDict, |
25 const int32_t& nWidgetType) { | 25 const int32_t& nWidgetType) { |
26 CPDF_Dictionary* pFormDict = nullptr; | 26 CPDF_Dictionary* pFormDict = nullptr; |
27 if (CPDF_Dictionary* pRootDict = pDoc->GetRoot()) | 27 if (CPDF_Dictionary* pRootDict = pDoc->GetRoot()) |
28 pFormDict = pRootDict->GetDictBy("AcroForm"); | 28 pFormDict = pRootDict->GetDictFor("AcroForm"); |
29 if (!pFormDict) | 29 if (!pFormDict) |
30 return false; | 30 return false; |
31 | 31 |
32 CFX_ByteString DA; | 32 CFX_ByteString DA; |
33 if (CPDF_Object* pDAObj = FPDF_GetFieldAttr(pAnnotDict, "DA")) | 33 if (CPDF_Object* pDAObj = FPDF_GetFieldAttr(pAnnotDict, "DA")) |
34 DA = pDAObj->GetString(); | 34 DA = pDAObj->GetString(); |
35 if (DA.IsEmpty()) | 35 if (DA.IsEmpty()) |
36 DA = pFormDict->GetStringBy("DA"); | 36 DA = pFormDict->GetStringFor("DA"); |
37 if (DA.IsEmpty()) | 37 if (DA.IsEmpty()) |
38 return false; | 38 return false; |
39 | 39 |
40 CPDF_SimpleParser syntax(DA.AsStringC()); | 40 CPDF_SimpleParser syntax(DA.AsStringC()); |
41 syntax.FindTagParamFromStart("Tf", 2); | 41 syntax.FindTagParamFromStart("Tf", 2); |
42 CFX_ByteString sFontName(syntax.GetWord()); | 42 CFX_ByteString sFontName(syntax.GetWord()); |
43 sFontName = PDF_NameDecode(sFontName); | 43 sFontName = PDF_NameDecode(sFontName); |
44 if (sFontName.IsEmpty()) | 44 if (sFontName.IsEmpty()) |
45 return false; | 45 return false; |
46 | 46 |
47 FX_FLOAT fFontSize = FX_atof(syntax.GetWord()); | 47 FX_FLOAT fFontSize = FX_atof(syntax.GetWord()); |
48 CPVT_Color crText = CPVT_Color::ParseColor(DA); | 48 CPVT_Color crText = CPVT_Color::ParseColor(DA); |
49 CPDF_Dictionary* pDRDict = pFormDict->GetDictBy("DR"); | 49 CPDF_Dictionary* pDRDict = pFormDict->GetDictFor("DR"); |
50 if (!pDRDict) | 50 if (!pDRDict) |
51 return false; | 51 return false; |
52 | 52 |
53 CPDF_Dictionary* pDRFontDict = pDRDict->GetDictBy("Font"); | 53 CPDF_Dictionary* pDRFontDict = pDRDict->GetDictFor("Font"); |
54 if (!pDRFontDict) | 54 if (!pDRFontDict) |
55 return false; | 55 return false; |
56 | 56 |
57 CPDF_Dictionary* pFontDict = pDRFontDict->GetDictBy(sFontName.Mid(1)); | 57 CPDF_Dictionary* pFontDict = pDRFontDict->GetDictFor(sFontName.Mid(1)); |
58 if (!pFontDict) { | 58 if (!pFontDict) { |
59 pFontDict = new CPDF_Dictionary; | 59 pFontDict = new CPDF_Dictionary; |
60 pFontDict->SetAtName("Type", "Font"); | 60 pFontDict->SetNameFor("Type", "Font"); |
61 pFontDict->SetAtName("Subtype", "Type1"); | 61 pFontDict->SetNameFor("Subtype", "Type1"); |
62 pFontDict->SetAtName("BaseFont", "Helvetica"); | 62 pFontDict->SetNameFor("BaseFont", "Helvetica"); |
63 pFontDict->SetAtName("Encoding", "WinAnsiEncoding"); | 63 pFontDict->SetNameFor("Encoding", "WinAnsiEncoding"); |
64 pDoc->AddIndirectObject(pFontDict); | 64 pDoc->AddIndirectObject(pFontDict); |
65 pDRFontDict->SetAtReference(sFontName.Mid(1), pDoc, pFontDict); | 65 pDRFontDict->SetReferenceFor(sFontName.Mid(1), pDoc, pFontDict); |
66 } | 66 } |
67 CPDF_Font* pDefFont = pDoc->LoadFont(pFontDict); | 67 CPDF_Font* pDefFont = pDoc->LoadFont(pFontDict); |
68 if (!pDefFont) | 68 if (!pDefFont) |
69 return false; | 69 return false; |
70 | 70 |
71 CFX_FloatRect rcAnnot = pAnnotDict->GetRectBy("Rect"); | 71 CFX_FloatRect rcAnnot = pAnnotDict->GetRectFor("Rect"); |
72 int32_t nRotate = 0; | 72 int32_t nRotate = 0; |
73 if (CPDF_Dictionary* pMKDict = pAnnotDict->GetDictBy("MK")) | 73 if (CPDF_Dictionary* pMKDict = pAnnotDict->GetDictFor("MK")) |
74 nRotate = pMKDict->GetIntegerBy("R"); | 74 nRotate = pMKDict->GetIntegerFor("R"); |
75 | 75 |
76 CFX_FloatRect rcBBox; | 76 CFX_FloatRect rcBBox; |
77 CFX_Matrix matrix; | 77 CFX_Matrix matrix; |
78 switch (nRotate % 360) { | 78 switch (nRotate % 360) { |
79 case 0: | 79 case 0: |
80 rcBBox = CFX_FloatRect(0, 0, rcAnnot.right - rcAnnot.left, | 80 rcBBox = CFX_FloatRect(0, 0, rcAnnot.right - rcAnnot.left, |
81 rcAnnot.top - rcAnnot.bottom); | 81 rcAnnot.top - rcAnnot.bottom); |
82 break; | 82 break; |
83 case 90: | 83 case 90: |
84 matrix = CFX_Matrix(0, 1, -1, 0, rcAnnot.right - rcAnnot.left, 0); | 84 matrix = CFX_Matrix(0, 1, -1, 0, rcAnnot.right - rcAnnot.left, 0); |
(...skipping 10 matching lines...) Expand all Loading... |
95 matrix = CFX_Matrix(0, -1, 1, 0, 0, rcAnnot.top - rcAnnot.bottom); | 95 matrix = CFX_Matrix(0, -1, 1, 0, 0, rcAnnot.top - rcAnnot.bottom); |
96 rcBBox = CFX_FloatRect(0, 0, rcAnnot.top - rcAnnot.bottom, | 96 rcBBox = CFX_FloatRect(0, 0, rcAnnot.top - rcAnnot.bottom, |
97 rcAnnot.right - rcAnnot.left); | 97 rcAnnot.right - rcAnnot.left); |
98 break; | 98 break; |
99 } | 99 } |
100 | 100 |
101 BorderStyle nBorderStyle = BorderStyle::SOLID; | 101 BorderStyle nBorderStyle = BorderStyle::SOLID; |
102 FX_FLOAT fBorderWidth = 1; | 102 FX_FLOAT fBorderWidth = 1; |
103 CPVT_Dash dsBorder(3, 0, 0); | 103 CPVT_Dash dsBorder(3, 0, 0); |
104 CPVT_Color crLeftTop, crRightBottom; | 104 CPVT_Color crLeftTop, crRightBottom; |
105 if (CPDF_Dictionary* pBSDict = pAnnotDict->GetDictBy("BS")) { | 105 if (CPDF_Dictionary* pBSDict = pAnnotDict->GetDictFor("BS")) { |
106 if (pBSDict->KeyExist("W")) | 106 if (pBSDict->KeyExist("W")) |
107 fBorderWidth = pBSDict->GetNumberBy("W"); | 107 fBorderWidth = pBSDict->GetNumberFor("W"); |
108 | 108 |
109 if (CPDF_Array* pArray = pBSDict->GetArrayBy("D")) { | 109 if (CPDF_Array* pArray = pBSDict->GetArrayFor("D")) { |
110 dsBorder = CPVT_Dash(pArray->GetIntegerAt(0), pArray->GetIntegerAt(1), | 110 dsBorder = CPVT_Dash(pArray->GetIntegerAt(0), pArray->GetIntegerAt(1), |
111 pArray->GetIntegerAt(2)); | 111 pArray->GetIntegerAt(2)); |
112 } | 112 } |
113 switch (pBSDict->GetStringBy("S").GetAt(0)) { | 113 switch (pBSDict->GetStringFor("S").GetAt(0)) { |
114 case 'S': | 114 case 'S': |
115 nBorderStyle = BorderStyle::SOLID; | 115 nBorderStyle = BorderStyle::SOLID; |
116 break; | 116 break; |
117 case 'D': | 117 case 'D': |
118 nBorderStyle = BorderStyle::DASH; | 118 nBorderStyle = BorderStyle::DASH; |
119 break; | 119 break; |
120 case 'B': | 120 case 'B': |
121 nBorderStyle = BorderStyle::BEVELED; | 121 nBorderStyle = BorderStyle::BEVELED; |
122 fBorderWidth *= 2; | 122 fBorderWidth *= 2; |
123 crLeftTop = CPVT_Color(CPVT_Color::kGray, 1); | 123 crLeftTop = CPVT_Color(CPVT_Color::kGray, 1); |
124 crRightBottom = CPVT_Color(CPVT_Color::kGray, 0.5); | 124 crRightBottom = CPVT_Color(CPVT_Color::kGray, 0.5); |
125 break; | 125 break; |
126 case 'I': | 126 case 'I': |
127 nBorderStyle = BorderStyle::INSET; | 127 nBorderStyle = BorderStyle::INSET; |
128 fBorderWidth *= 2; | 128 fBorderWidth *= 2; |
129 crLeftTop = CPVT_Color(CPVT_Color::kGray, 0.5); | 129 crLeftTop = CPVT_Color(CPVT_Color::kGray, 0.5); |
130 crRightBottom = CPVT_Color(CPVT_Color::kGray, 0.75); | 130 crRightBottom = CPVT_Color(CPVT_Color::kGray, 0.75); |
131 break; | 131 break; |
132 case 'U': | 132 case 'U': |
133 nBorderStyle = BorderStyle::UNDERLINE; | 133 nBorderStyle = BorderStyle::UNDERLINE; |
134 break; | 134 break; |
135 } | 135 } |
136 } | 136 } |
137 CPVT_Color crBorder, crBG; | 137 CPVT_Color crBorder, crBG; |
138 if (CPDF_Dictionary* pMKDict = pAnnotDict->GetDictBy("MK")) { | 138 if (CPDF_Dictionary* pMKDict = pAnnotDict->GetDictFor("MK")) { |
139 if (CPDF_Array* pArray = pMKDict->GetArrayBy("BC")) | 139 if (CPDF_Array* pArray = pMKDict->GetArrayFor("BC")) |
140 crBorder = CPVT_Color::ParseColor(*pArray); | 140 crBorder = CPVT_Color::ParseColor(*pArray); |
141 if (CPDF_Array* pArray = pMKDict->GetArrayBy("BG")) | 141 if (CPDF_Array* pArray = pMKDict->GetArrayFor("BG")) |
142 crBG = CPVT_Color::ParseColor(*pArray); | 142 crBG = CPVT_Color::ParseColor(*pArray); |
143 } | 143 } |
144 CFX_ByteTextBuf sAppStream; | 144 CFX_ByteTextBuf sAppStream; |
145 CFX_ByteString sBG = | 145 CFX_ByteString sBG = |
146 CPVT_GenerateAP::GenerateColorAP(crBG, PaintOperation::FILL); | 146 CPVT_GenerateAP::GenerateColorAP(crBG, PaintOperation::FILL); |
147 if (sBG.GetLength() > 0) { | 147 if (sBG.GetLength() > 0) { |
148 sAppStream << "q\n" << sBG << rcBBox.left << " " << rcBBox.bottom << " " | 148 sAppStream << "q\n" << sBG << rcBBox.left << " " << rcBBox.bottom << " " |
149 << rcBBox.Width() << " " << rcBBox.Height() << " re f\n" | 149 << rcBBox.Width() << " " << rcBBox.Height() << " re f\n" |
150 << "Q\n"; | 150 << "Q\n"; |
151 } | 151 } |
152 CFX_ByteString sBorderStream = CPVT_GenerateAP::GenerateBorderAP( | 152 CFX_ByteString sBorderStream = CPVT_GenerateAP::GenerateBorderAP( |
153 rcBBox, fBorderWidth, crBorder, crLeftTop, crRightBottom, nBorderStyle, | 153 rcBBox, fBorderWidth, crBorder, crLeftTop, crRightBottom, nBorderStyle, |
154 dsBorder); | 154 dsBorder); |
155 if (sBorderStream.GetLength() > 0) | 155 if (sBorderStream.GetLength() > 0) |
156 sAppStream << "q\n" << sBorderStream << "Q\n"; | 156 sAppStream << "q\n" << sBorderStream << "Q\n"; |
157 | 157 |
158 CFX_FloatRect rcBody = | 158 CFX_FloatRect rcBody = |
159 CFX_FloatRect(rcBBox.left + fBorderWidth, rcBBox.bottom + fBorderWidth, | 159 CFX_FloatRect(rcBBox.left + fBorderWidth, rcBBox.bottom + fBorderWidth, |
160 rcBBox.right - fBorderWidth, rcBBox.top - fBorderWidth); | 160 rcBBox.right - fBorderWidth, rcBBox.top - fBorderWidth); |
161 rcBody.Normalize(); | 161 rcBody.Normalize(); |
162 CPDF_Dictionary* pAPDict = pAnnotDict->GetDictBy("AP"); | 162 CPDF_Dictionary* pAPDict = pAnnotDict->GetDictFor("AP"); |
163 if (!pAPDict) { | 163 if (!pAPDict) { |
164 pAPDict = new CPDF_Dictionary; | 164 pAPDict = new CPDF_Dictionary; |
165 pAnnotDict->SetAt("AP", pAPDict); | 165 pAnnotDict->SetFor("AP", pAPDict); |
166 } | 166 } |
167 CPDF_Stream* pNormalStream = pAPDict->GetStreamBy("N"); | 167 CPDF_Stream* pNormalStream = pAPDict->GetStreamFor("N"); |
168 if (!pNormalStream) { | 168 if (!pNormalStream) { |
169 pNormalStream = new CPDF_Stream(nullptr, 0, nullptr); | 169 pNormalStream = new CPDF_Stream(nullptr, 0, nullptr); |
170 int32_t objnum = pDoc->AddIndirectObject(pNormalStream); | 170 int32_t objnum = pDoc->AddIndirectObject(pNormalStream); |
171 pAnnotDict->GetDictBy("AP")->SetAtReference("N", pDoc, objnum); | 171 pAnnotDict->GetDictFor("AP")->SetReferenceFor("N", pDoc, objnum); |
172 } | 172 } |
173 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); | 173 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); |
174 if (pStreamDict) { | 174 if (pStreamDict) { |
175 pStreamDict->SetAtMatrix("Matrix", matrix); | 175 pStreamDict->SetMatrixFor("Matrix", matrix); |
176 pStreamDict->SetAtRect("BBox", rcBBox); | 176 pStreamDict->SetRectFor("BBox", rcBBox); |
177 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictBy("Resources"); | 177 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources"); |
178 if (pStreamResList) { | 178 if (pStreamResList) { |
179 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictBy("Font"); | 179 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictFor("Font"); |
180 if (!pStreamResFontList) { | 180 if (!pStreamResFontList) { |
181 pStreamResFontList = new CPDF_Dictionary; | 181 pStreamResFontList = new CPDF_Dictionary; |
182 pStreamResList->SetAt("Font", pStreamResFontList); | 182 pStreamResList->SetFor("Font", pStreamResFontList); |
183 } | 183 } |
184 if (!pStreamResFontList->KeyExist(sFontName)) | 184 if (!pStreamResFontList->KeyExist(sFontName)) |
185 pStreamResFontList->SetAtReference(sFontName, pDoc, pFontDict); | 185 pStreamResFontList->SetReferenceFor(sFontName, pDoc, pFontDict); |
186 } else { | 186 } else { |
187 pStreamDict->SetAt("Resources", pFormDict->GetDictBy("DR")->Clone()); | 187 pStreamDict->SetFor("Resources", pFormDict->GetDictFor("DR")->Clone()); |
188 pStreamResList = pStreamDict->GetDictBy("Resources"); | 188 pStreamResList = pStreamDict->GetDictFor("Resources"); |
189 } | 189 } |
190 } | 190 } |
191 switch (nWidgetType) { | 191 switch (nWidgetType) { |
192 case 0: { | 192 case 0: { |
193 CFX_WideString swValue = | 193 CFX_WideString swValue = |
194 FPDF_GetFieldAttr(pAnnotDict, "V") | 194 FPDF_GetFieldAttr(pAnnotDict, "V") |
195 ? FPDF_GetFieldAttr(pAnnotDict, "V")->GetUnicodeText() | 195 ? FPDF_GetFieldAttr(pAnnotDict, "V")->GetUnicodeText() |
196 : CFX_WideString(); | 196 : CFX_WideString(); |
197 int32_t nAlign = FPDF_GetFieldAttr(pAnnotDict, "Q") | 197 int32_t nAlign = FPDF_GetFieldAttr(pAnnotDict, "Q") |
198 ? FPDF_GetFieldAttr(pAnnotDict, "Q")->GetInteger() | 198 ? FPDF_GetFieldAttr(pAnnotDict, "Q")->GetInteger() |
199 : 0; | 199 : 0; |
200 uint32_t dwFlags = FPDF_GetFieldAttr(pAnnotDict, "Ff") | 200 uint32_t dwFlags = FPDF_GetFieldAttr(pAnnotDict, "Ff") |
201 ? FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteger() | 201 ? FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteger() |
202 : 0; | 202 : 0; |
203 uint32_t dwMaxLen = | 203 uint32_t dwMaxLen = |
204 FPDF_GetFieldAttr(pAnnotDict, "MaxLen") | 204 FPDF_GetFieldAttr(pAnnotDict, "MaxLen") |
205 ? FPDF_GetFieldAttr(pAnnotDict, "MaxLen")->GetInteger() | 205 ? FPDF_GetFieldAttr(pAnnotDict, "MaxLen")->GetInteger() |
206 : 0; | 206 : 0; |
207 CPVT_FontMap map( | 207 CPVT_FontMap map( |
208 pDoc, pStreamDict ? pStreamDict->GetDictBy("Resources") : nullptr, | 208 pDoc, pStreamDict ? pStreamDict->GetDictFor("Resources") : nullptr, |
209 pDefFont, sFontName.Right(sFontName.GetLength() - 1)); | 209 pDefFont, sFontName.Right(sFontName.GetLength() - 1)); |
210 CPDF_VariableText::Provider prd(&map); | 210 CPDF_VariableText::Provider prd(&map); |
211 CPDF_VariableText vt; | 211 CPDF_VariableText vt; |
212 vt.SetProvider(&prd); | 212 vt.SetProvider(&prd); |
213 vt.SetPlateRect(rcBody); | 213 vt.SetPlateRect(rcBody); |
214 vt.SetAlignment(nAlign); | 214 vt.SetAlignment(nAlign); |
215 if (IsFloatZero(fFontSize)) | 215 if (IsFloatZero(fFontSize)) |
216 vt.SetAutoFontSize(TRUE); | 216 vt.SetAutoFontSize(TRUE); |
217 else | 217 else |
218 vt.SetFontSize(fFontSize); | 218 vt.SetFontSize(fFontSize); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 << sBody << "ET\n" | 259 << sBody << "ET\n" |
260 << "Q\nEMC\n"; | 260 << "Q\nEMC\n"; |
261 } | 261 } |
262 } break; | 262 } break; |
263 case 1: { | 263 case 1: { |
264 CFX_WideString swValue = | 264 CFX_WideString swValue = |
265 FPDF_GetFieldAttr(pAnnotDict, "V") | 265 FPDF_GetFieldAttr(pAnnotDict, "V") |
266 ? FPDF_GetFieldAttr(pAnnotDict, "V")->GetUnicodeText() | 266 ? FPDF_GetFieldAttr(pAnnotDict, "V")->GetUnicodeText() |
267 : CFX_WideString(); | 267 : CFX_WideString(); |
268 CPVT_FontMap map( | 268 CPVT_FontMap map( |
269 pDoc, pStreamDict ? pStreamDict->GetDictBy("Resources") : nullptr, | 269 pDoc, pStreamDict ? pStreamDict->GetDictFor("Resources") : nullptr, |
270 pDefFont, sFontName.Right(sFontName.GetLength() - 1)); | 270 pDefFont, sFontName.Right(sFontName.GetLength() - 1)); |
271 CPDF_VariableText::Provider prd(&map); | 271 CPDF_VariableText::Provider prd(&map); |
272 CPDF_VariableText vt; | 272 CPDF_VariableText vt; |
273 vt.SetProvider(&prd); | 273 vt.SetProvider(&prd); |
274 CFX_FloatRect rcButton = rcBody; | 274 CFX_FloatRect rcButton = rcBody; |
275 rcButton.left = rcButton.right - 13; | 275 rcButton.left = rcButton.right - 13; |
276 rcButton.Normalize(); | 276 rcButton.Normalize(); |
277 CFX_FloatRect rcEdit = rcBody; | 277 CFX_FloatRect rcEdit = rcBody; |
278 rcEdit.right = rcButton.left; | 278 rcEdit.right = rcButton.left; |
279 rcEdit.Normalize(); | 279 rcEdit.Normalize(); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " m\n"; | 329 sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " m\n"; |
330 sAppStream << ptCenter.x + 3 << " " << ptCenter.y + 1.5f << " l\n"; | 330 sAppStream << ptCenter.x + 3 << " " << ptCenter.y + 1.5f << " l\n"; |
331 sAppStream << ptCenter.x << " " << ptCenter.y - 1.5f << " l\n"; | 331 sAppStream << ptCenter.x << " " << ptCenter.y - 1.5f << " l\n"; |
332 sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " l f\n"; | 332 sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " l f\n"; |
333 sAppStream << sButton << "Q\n"; | 333 sAppStream << sButton << "Q\n"; |
334 } | 334 } |
335 } | 335 } |
336 } break; | 336 } break; |
337 case 2: { | 337 case 2: { |
338 CPVT_FontMap map( | 338 CPVT_FontMap map( |
339 pDoc, pStreamDict ? pStreamDict->GetDictBy("Resources") : nullptr, | 339 pDoc, pStreamDict ? pStreamDict->GetDictFor("Resources") : nullptr, |
340 pDefFont, sFontName.Right(sFontName.GetLength() - 1)); | 340 pDefFont, sFontName.Right(sFontName.GetLength() - 1)); |
341 CPDF_VariableText::Provider prd(&map); | 341 CPDF_VariableText::Provider prd(&map); |
342 CPDF_Array* pOpts = ToArray(FPDF_GetFieldAttr(pAnnotDict, "Opt")); | 342 CPDF_Array* pOpts = ToArray(FPDF_GetFieldAttr(pAnnotDict, "Opt")); |
343 CPDF_Array* pSels = ToArray(FPDF_GetFieldAttr(pAnnotDict, "I")); | 343 CPDF_Array* pSels = ToArray(FPDF_GetFieldAttr(pAnnotDict, "I")); |
344 CPDF_Object* pTi = FPDF_GetFieldAttr(pAnnotDict, "TI"); | 344 CPDF_Object* pTi = FPDF_GetFieldAttr(pAnnotDict, "TI"); |
345 int32_t nTop = pTi ? pTi->GetInteger() : 0; | 345 int32_t nTop = pTi ? pTi->GetInteger() : 0; |
346 CFX_ByteTextBuf sBody; | 346 CFX_ByteTextBuf sBody; |
347 if (pOpts) { | 347 if (pOpts) { |
348 FX_FLOAT fy = rcBody.top; | 348 FX_FLOAT fy = rcBody.top; |
349 for (size_t i = nTop, sz = pOpts->GetCount(); i < sz; i++) { | 349 for (size_t i = nTop, sz = pOpts->GetCount(); i < sz; i++) { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 << rcBody.Width() << " " << rcBody.Height() << " re\nW\nn\n" | 415 << rcBody.Width() << " " << rcBody.Height() << " re\nW\nn\n" |
416 << sBody.AsStringC() << "Q\nEMC\n"; | 416 << sBody.AsStringC() << "Q\nEMC\n"; |
417 } | 417 } |
418 } break; | 418 } break; |
419 } | 419 } |
420 if (pNormalStream) { | 420 if (pNormalStream) { |
421 pNormalStream->SetData(sAppStream.GetBuffer(), sAppStream.GetSize(), FALSE, | 421 pNormalStream->SetData(sAppStream.GetBuffer(), sAppStream.GetSize(), FALSE, |
422 FALSE); | 422 FALSE); |
423 pStreamDict = pNormalStream->GetDict(); | 423 pStreamDict = pNormalStream->GetDict(); |
424 if (pStreamDict) { | 424 if (pStreamDict) { |
425 pStreamDict->SetAtMatrix("Matrix", matrix); | 425 pStreamDict->SetMatrixFor("Matrix", matrix); |
426 pStreamDict->SetAtRect("BBox", rcBBox); | 426 pStreamDict->SetRectFor("BBox", rcBBox); |
427 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictBy("Resources"); | 427 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources"); |
428 if (pStreamResList) { | 428 if (pStreamResList) { |
429 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictBy("Font"); | 429 CPDF_Dictionary* pStreamResFontList = |
| 430 pStreamResList->GetDictFor("Font"); |
430 if (!pStreamResFontList) { | 431 if (!pStreamResFontList) { |
431 pStreamResFontList = new CPDF_Dictionary; | 432 pStreamResFontList = new CPDF_Dictionary; |
432 pStreamResList->SetAt("Font", pStreamResFontList); | 433 pStreamResList->SetFor("Font", pStreamResFontList); |
433 } | 434 } |
434 if (!pStreamResFontList->KeyExist(sFontName)) | 435 if (!pStreamResFontList->KeyExist(sFontName)) |
435 pStreamResFontList->SetAtReference(sFontName, pDoc, pFontDict); | 436 pStreamResFontList->SetReferenceFor(sFontName, pDoc, pFontDict); |
436 } else { | 437 } else { |
437 pStreamDict->SetAt("Resources", pFormDict->GetDictBy("DR")->Clone()); | 438 pStreamDict->SetFor("Resources", pFormDict->GetDictFor("DR")->Clone()); |
438 pStreamResList = pStreamDict->GetDictBy("Resources"); | 439 pStreamResList = pStreamDict->GetDictFor("Resources"); |
439 } | 440 } |
440 } | 441 } |
441 } | 442 } |
442 return true; | 443 return true; |
443 } | 444 } |
444 | 445 |
445 CFX_ByteString GetColorStringWithDefault(CPDF_Array* pColor, | 446 CFX_ByteString GetColorStringWithDefault(CPDF_Array* pColor, |
446 const CPVT_Color& crDefaultColor, | 447 const CPVT_Color& crDefaultColor, |
447 PaintOperation nOperation) { | 448 PaintOperation nOperation) { |
448 if (pColor) { | 449 if (pColor) { |
449 CPVT_Color color = CPVT_Color::ParseColor(*pColor); | 450 CPVT_Color color = CPVT_Color::ParseColor(*pColor); |
450 return CPVT_GenerateAP::GenerateColorAP(color, nOperation); | 451 return CPVT_GenerateAP::GenerateColorAP(color, nOperation); |
451 } | 452 } |
452 | 453 |
453 return CPVT_GenerateAP::GenerateColorAP(crDefaultColor, nOperation); | 454 return CPVT_GenerateAP::GenerateColorAP(crDefaultColor, nOperation); |
454 } | 455 } |
455 | 456 |
456 FX_FLOAT GetBorderWidth(const CPDF_Dictionary& pAnnotDict) { | 457 FX_FLOAT GetBorderWidth(const CPDF_Dictionary& pAnnotDict) { |
457 if (CPDF_Dictionary* pBorderStyleDict = pAnnotDict.GetDictBy("BS")) { | 458 if (CPDF_Dictionary* pBorderStyleDict = pAnnotDict.GetDictFor("BS")) { |
458 if (pBorderStyleDict->KeyExist("W")) | 459 if (pBorderStyleDict->KeyExist("W")) |
459 return pBorderStyleDict->GetNumberBy("W"); | 460 return pBorderStyleDict->GetNumberFor("W"); |
460 } | 461 } |
461 | 462 |
462 if (CPDF_Array* pBorderArray = pAnnotDict.GetArrayBy("Border")) { | 463 if (CPDF_Array* pBorderArray = pAnnotDict.GetArrayFor("Border")) { |
463 if (pBorderArray->GetCount() > 2) | 464 if (pBorderArray->GetCount() > 2) |
464 return pBorderArray->GetNumberAt(2); | 465 return pBorderArray->GetNumberAt(2); |
465 } | 466 } |
466 | 467 |
467 return 1; | 468 return 1; |
468 } | 469 } |
469 | 470 |
470 CPDF_Array* GetDashArray(const CPDF_Dictionary& pAnnotDict) { | 471 CPDF_Array* GetDashArray(const CPDF_Dictionary& pAnnotDict) { |
471 if (CPDF_Dictionary* pBorderStyleDict = pAnnotDict.GetDictBy("BS")) { | 472 if (CPDF_Dictionary* pBorderStyleDict = pAnnotDict.GetDictFor("BS")) { |
472 if (pBorderStyleDict->GetStringBy("S") == "D") | 473 if (pBorderStyleDict->GetStringFor("S") == "D") |
473 return pBorderStyleDict->GetArrayBy("D"); | 474 return pBorderStyleDict->GetArrayFor("D"); |
474 } | 475 } |
475 | 476 |
476 if (CPDF_Array* pBorderArray = pAnnotDict.GetArrayBy("Border")) { | 477 if (CPDF_Array* pBorderArray = pAnnotDict.GetArrayFor("Border")) { |
477 if (pBorderArray->GetCount() == 4) | 478 if (pBorderArray->GetCount() == 4) |
478 return pBorderArray->GetArrayAt(3); | 479 return pBorderArray->GetArrayAt(3); |
479 } | 480 } |
480 | 481 |
481 return nullptr; | 482 return nullptr; |
482 } | 483 } |
483 | 484 |
484 CFX_ByteString GetDashPatternString(const CPDF_Dictionary& pAnnotDict) { | 485 CFX_ByteString GetDashPatternString(const CPDF_Dictionary& pAnnotDict) { |
485 CPDF_Array* pDashArray = GetDashArray(pAnnotDict); | 486 CPDF_Array* pDashArray = GetDashArray(pAnnotDict); |
486 if (!pDashArray || pDashArray->IsEmpty()) | 487 if (!pDashArray || pDashArray->IsEmpty()) |
487 return CFX_ByteString(); | 488 return CFX_ByteString(); |
488 | 489 |
489 // Support maximum of ten elements in the dash array. | 490 // Support maximum of ten elements in the dash array. |
490 size_t pDashArrayCount = std::min<size_t>(pDashArray->GetCount(), 10); | 491 size_t pDashArrayCount = std::min<size_t>(pDashArray->GetCount(), 10); |
491 CFX_ByteTextBuf sDashStream; | 492 CFX_ByteTextBuf sDashStream; |
492 | 493 |
493 sDashStream << "["; | 494 sDashStream << "["; |
494 for (size_t i = 0; i < pDashArrayCount; ++i) | 495 for (size_t i = 0; i < pDashArrayCount; ++i) |
495 sDashStream << pDashArray->GetNumberAt(i) << " "; | 496 sDashStream << pDashArray->GetNumberAt(i) << " "; |
496 sDashStream << "] 0 d\n"; | 497 sDashStream << "] 0 d\n"; |
497 | 498 |
498 return sDashStream.MakeString(); | 499 return sDashStream.MakeString(); |
499 } | 500 } |
500 | 501 |
501 CFX_ByteString GetPopupContentsString(CPDF_Document* pDoc, | 502 CFX_ByteString GetPopupContentsString(CPDF_Document* pDoc, |
502 const CPDF_Dictionary& pAnnotDict, | 503 const CPDF_Dictionary& pAnnotDict, |
503 CPDF_Font* pDefFont, | 504 CPDF_Font* pDefFont, |
504 const CFX_ByteString& sFontName) { | 505 const CFX_ByteString& sFontName) { |
505 CFX_WideString swValue(pAnnotDict.GetUnicodeTextBy("T")); | 506 CFX_WideString swValue(pAnnotDict.GetUnicodeTextFor("T")); |
506 swValue += L'\n'; | 507 swValue += L'\n'; |
507 swValue += pAnnotDict.GetUnicodeTextBy("Contents"); | 508 swValue += pAnnotDict.GetUnicodeTextFor("Contents"); |
508 CPVT_FontMap map(pDoc, nullptr, pDefFont, sFontName); | 509 CPVT_FontMap map(pDoc, nullptr, pDefFont, sFontName); |
509 | 510 |
510 CPDF_VariableText::Provider prd(&map); | 511 CPDF_VariableText::Provider prd(&map); |
511 CPDF_VariableText vt; | 512 CPDF_VariableText vt; |
512 vt.SetProvider(&prd); | 513 vt.SetProvider(&prd); |
513 vt.SetPlateRect(pAnnotDict.GetRectBy("Rect")); | 514 vt.SetPlateRect(pAnnotDict.GetRectFor("Rect")); |
514 vt.SetFontSize(12); | 515 vt.SetFontSize(12); |
515 vt.SetAutoReturn(TRUE); | 516 vt.SetAutoReturn(TRUE); |
516 vt.SetMultiLine(TRUE); | 517 vt.SetMultiLine(TRUE); |
517 | 518 |
518 vt.Initialize(); | 519 vt.Initialize(); |
519 vt.SetText(swValue); | 520 vt.SetText(swValue); |
520 vt.RearrangeAll(); | 521 vt.RearrangeAll(); |
521 CFX_FloatPoint ptOffset(3.0f, -3.0f); | 522 CFX_FloatPoint ptOffset(3.0f, -3.0f); |
522 CFX_ByteString sContent = CPVT_GenerateAP::GenerateEditAP( | 523 CFX_ByteString sContent = CPVT_GenerateAP::GenerateEditAP( |
523 &map, vt.GetIterator(), ptOffset, FALSE, 0); | 524 &map, vt.GetIterator(), ptOffset, FALSE, 0); |
524 | 525 |
525 if (sContent.IsEmpty()) | 526 if (sContent.IsEmpty()) |
526 return CFX_ByteString(); | 527 return CFX_ByteString(); |
527 | 528 |
528 CFX_ByteTextBuf sAppStream; | 529 CFX_ByteTextBuf sAppStream; |
529 sAppStream << "BT\n" | 530 sAppStream << "BT\n" |
530 << CPVT_GenerateAP::GenerateColorAP( | 531 << CPVT_GenerateAP::GenerateColorAP( |
531 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), PaintOperation::FILL) | 532 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), PaintOperation::FILL) |
532 << sContent << "ET\n" | 533 << sContent << "ET\n" |
533 << "Q\n"; | 534 << "Q\n"; |
534 return sAppStream.MakeString(); | 535 return sAppStream.MakeString(); |
535 } | 536 } |
536 | 537 |
537 CPDF_Dictionary* GenerateExtGStateDict(const CPDF_Dictionary& pAnnotDict, | 538 CPDF_Dictionary* GenerateExtGStateDict(const CPDF_Dictionary& pAnnotDict, |
538 const CFX_ByteString& sExtGSDictName, | 539 const CFX_ByteString& sExtGSDictName, |
539 const CFX_ByteString& sBlendMode) { | 540 const CFX_ByteString& sBlendMode) { |
540 CPDF_Dictionary* pGSDict = new CPDF_Dictionary; | 541 CPDF_Dictionary* pGSDict = new CPDF_Dictionary; |
541 pGSDict->SetAtString("Type", "ExtGState"); | 542 pGSDict->SetStringFor("Type", "ExtGState"); |
542 | 543 |
543 FX_FLOAT fOpacity = | 544 FX_FLOAT fOpacity = |
544 pAnnotDict.KeyExist("CA") ? pAnnotDict.GetNumberBy("CA") : 1; | 545 pAnnotDict.KeyExist("CA") ? pAnnotDict.GetNumberFor("CA") : 1; |
545 pGSDict->SetAtNumber("CA", fOpacity); | 546 pGSDict->SetNumberFor("CA", fOpacity); |
546 pGSDict->SetAtNumber("ca", fOpacity); | 547 pGSDict->SetNumberFor("ca", fOpacity); |
547 pGSDict->SetAtBoolean("AIS", false); | 548 pGSDict->SetBooleanFor("AIS", false); |
548 pGSDict->SetAtString("BM", sBlendMode); | 549 pGSDict->SetStringFor("BM", sBlendMode); |
549 | 550 |
550 CPDF_Dictionary* pExtGStateDict = new CPDF_Dictionary; | 551 CPDF_Dictionary* pExtGStateDict = new CPDF_Dictionary; |
551 pExtGStateDict->SetAt(sExtGSDictName, pGSDict); | 552 pExtGStateDict->SetFor(sExtGSDictName, pGSDict); |
552 | 553 |
553 return pExtGStateDict; | 554 return pExtGStateDict; |
554 } | 555 } |
555 | 556 |
556 CPDF_Dictionary* GenerateResourceFontDict(CPDF_Document* pDoc, | 557 CPDF_Dictionary* GenerateResourceFontDict(CPDF_Document* pDoc, |
557 const CFX_ByteString& sFontDictName) { | 558 const CFX_ByteString& sFontDictName) { |
558 CPDF_Dictionary* pFontDict = new CPDF_Dictionary; | 559 CPDF_Dictionary* pFontDict = new CPDF_Dictionary; |
559 pFontDict->SetAtName("Type", "Font"); | 560 pFontDict->SetNameFor("Type", "Font"); |
560 pFontDict->SetAtName("Subtype", "Type1"); | 561 pFontDict->SetNameFor("Subtype", "Type1"); |
561 pFontDict->SetAtName("BaseFont", "Helvetica"); | 562 pFontDict->SetNameFor("BaseFont", "Helvetica"); |
562 pFontDict->SetAtName("Encoding", "WinAnsiEncoding"); | 563 pFontDict->SetNameFor("Encoding", "WinAnsiEncoding"); |
563 pDoc->AddIndirectObject(pFontDict); | 564 pDoc->AddIndirectObject(pFontDict); |
564 | 565 |
565 CPDF_Dictionary* pResourceFontDict = new CPDF_Dictionary; | 566 CPDF_Dictionary* pResourceFontDict = new CPDF_Dictionary; |
566 pResourceFontDict->SetAtReference(sFontDictName, pDoc, pFontDict); | 567 pResourceFontDict->SetReferenceFor(sFontDictName, pDoc, pFontDict); |
567 | 568 |
568 return pResourceFontDict; | 569 return pResourceFontDict; |
569 } | 570 } |
570 | 571 |
571 // Takes ownership of |pExtGStateDict| and |pResourceFontDict|. | 572 // Takes ownership of |pExtGStateDict| and |pResourceFontDict|. |
572 CPDF_Dictionary* GenerateResourceDict(CPDF_Dictionary* pExtGStateDict, | 573 CPDF_Dictionary* GenerateResourceDict(CPDF_Dictionary* pExtGStateDict, |
573 CPDF_Dictionary* pResourceFontDict) { | 574 CPDF_Dictionary* pResourceFontDict) { |
574 CPDF_Dictionary* pResourceDict = new CPDF_Dictionary; | 575 CPDF_Dictionary* pResourceDict = new CPDF_Dictionary; |
575 if (pExtGStateDict) | 576 if (pExtGStateDict) |
576 pResourceDict->SetAt("ExtGState", pExtGStateDict); | 577 pResourceDict->SetFor("ExtGState", pExtGStateDict); |
577 | 578 |
578 if (pResourceFontDict) | 579 if (pResourceFontDict) |
579 pResourceDict->SetAt("Font", pResourceFontDict); | 580 pResourceDict->SetFor("Font", pResourceFontDict); |
580 | 581 |
581 return pResourceDict; | 582 return pResourceDict; |
582 } | 583 } |
583 | 584 |
584 // Takes ownership of |pResourceDict|. | 585 // Takes ownership of |pResourceDict|. |
585 void GenerateAndSetAPDict(CPDF_Document* pDoc, | 586 void GenerateAndSetAPDict(CPDF_Document* pDoc, |
586 CPDF_Dictionary* pAnnotDict, | 587 CPDF_Dictionary* pAnnotDict, |
587 const CFX_ByteTextBuf& sAppStream, | 588 const CFX_ByteTextBuf& sAppStream, |
588 CPDF_Dictionary* pResourceDict) { | 589 CPDF_Dictionary* pResourceDict) { |
589 CPDF_Dictionary* pAPDict = new CPDF_Dictionary; | 590 CPDF_Dictionary* pAPDict = new CPDF_Dictionary; |
590 pAnnotDict->SetAt("AP", pAPDict); | 591 pAnnotDict->SetFor("AP", pAPDict); |
591 | 592 |
592 CPDF_Stream* pNormalStream = new CPDF_Stream(nullptr, 0, nullptr); | 593 CPDF_Stream* pNormalStream = new CPDF_Stream(nullptr, 0, nullptr); |
593 int32_t objnum = pDoc->AddIndirectObject(pNormalStream); | 594 int32_t objnum = pDoc->AddIndirectObject(pNormalStream); |
594 pAnnotDict->GetDictBy("AP")->SetAtReference("N", pDoc, objnum); | 595 pAnnotDict->GetDictFor("AP")->SetReferenceFor("N", pDoc, objnum); |
595 | 596 |
596 pNormalStream->SetData(sAppStream.GetBuffer(), sAppStream.GetSize(), FALSE, | 597 pNormalStream->SetData(sAppStream.GetBuffer(), sAppStream.GetSize(), FALSE, |
597 FALSE); | 598 FALSE); |
598 | 599 |
599 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); | 600 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); |
600 pStreamDict->SetAtInteger("FormType", 1); | 601 pStreamDict->SetIntegerFor("FormType", 1); |
601 pStreamDict->SetAtString("Subtype", "Form"); | 602 pStreamDict->SetStringFor("Subtype", "Form"); |
602 pStreamDict->SetAtMatrix("Matrix", CFX_Matrix()); | 603 pStreamDict->SetMatrixFor("Matrix", CFX_Matrix()); |
603 | 604 |
604 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); | 605 CFX_FloatRect rect = pAnnotDict->GetRectFor("Rect"); |
605 pStreamDict->SetAtRect("BBox", rect); | 606 pStreamDict->SetRectFor("BBox", rect); |
606 | 607 |
607 pStreamDict->SetAt("Resources", pResourceDict); | 608 pStreamDict->SetFor("Resources", pResourceDict); |
608 } | 609 } |
609 | 610 |
610 CFX_ByteString GetPaintOperatorString(bool bIsStrokeRect, bool bIsFillRect) { | 611 CFX_ByteString GetPaintOperatorString(bool bIsStrokeRect, bool bIsFillRect) { |
611 if (bIsStrokeRect) | 612 if (bIsStrokeRect) |
612 return bIsFillRect ? "b" : "s"; | 613 return bIsFillRect ? "b" : "s"; |
613 return bIsFillRect ? "f" : "n"; | 614 return bIsFillRect ? "f" : "n"; |
614 } | 615 } |
615 | 616 |
616 CFX_ByteString GenerateTextSymbolAP(const CFX_FloatRect& rect) { | 617 CFX_ByteString GenerateTextSymbolAP(const CFX_FloatRect& rect) { |
617 CFX_ByteTextBuf sAppStream; | 618 CFX_ByteTextBuf sAppStream; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 << lineRect.right << " " << lineRect.top << " l\n"; | 660 << lineRect.right << " " << lineRect.top << " l\n"; |
660 } | 661 } |
661 sAppStream << "B*\n"; | 662 sAppStream << "B*\n"; |
662 | 663 |
663 return sAppStream.MakeString(); | 664 return sAppStream.MakeString(); |
664 } | 665 } |
665 | 666 |
666 } // namespace | 667 } // namespace |
667 | 668 |
668 bool FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) { | 669 bool FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) { |
669 if (!pAnnotDict || pAnnotDict->GetStringBy("Subtype") != "Widget") | 670 if (!pAnnotDict || pAnnotDict->GetStringFor("Subtype") != "Widget") |
670 return false; | 671 return false; |
671 | 672 |
672 CFX_ByteString field_type = FPDF_GetFieldAttr(pAnnotDict, "FT")->GetString(); | 673 CFX_ByteString field_type = FPDF_GetFieldAttr(pAnnotDict, "FT")->GetString(); |
673 uint32_t flags = FPDF_GetFieldAttr(pAnnotDict, "Ff") | 674 uint32_t flags = FPDF_GetFieldAttr(pAnnotDict, "Ff") |
674 ? FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteger() | 675 ? FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteger() |
675 : 0; | 676 : 0; |
676 if (field_type == "Tx") { | 677 if (field_type == "Tx") { |
677 return CPVT_GenerateAP::GenerateTextFieldAP(pDoc, pAnnotDict); | 678 return CPVT_GenerateAP::GenerateTextFieldAP(pDoc, pAnnotDict); |
678 } | 679 } |
679 if (field_type == "Ch") { | 680 if (field_type == "Ch") { |
680 return (flags & (1 << 17)) | 681 return (flags & (1 << 17)) |
681 ? CPVT_GenerateAP::GenerateComboBoxAP(pDoc, pAnnotDict) | 682 ? CPVT_GenerateAP::GenerateComboBoxAP(pDoc, pAnnotDict) |
682 : CPVT_GenerateAP::GenerateListBoxAP(pDoc, pAnnotDict); | 683 : CPVT_GenerateAP::GenerateListBoxAP(pDoc, pAnnotDict); |
683 } | 684 } |
684 if (field_type == "Btn") { | 685 if (field_type == "Btn") { |
685 if (!(flags & (1 << 16))) { | 686 if (!(flags & (1 << 16))) { |
686 if (!pAnnotDict->KeyExist("AS")) { | 687 if (!pAnnotDict->KeyExist("AS")) { |
687 if (CPDF_Dictionary* pParentDict = pAnnotDict->GetDictBy("Parent")) { | 688 if (CPDF_Dictionary* pParentDict = pAnnotDict->GetDictFor("Parent")) { |
688 if (pParentDict->KeyExist("AS")) { | 689 if (pParentDict->KeyExist("AS")) { |
689 pAnnotDict->SetAtString("AS", pParentDict->GetStringBy("AS")); | 690 pAnnotDict->SetStringFor("AS", pParentDict->GetStringFor("AS")); |
690 } | 691 } |
691 } | 692 } |
692 } | 693 } |
693 } | 694 } |
694 } | 695 } |
695 return false; | 696 return false; |
696 } | 697 } |
697 | 698 |
698 // Static. | 699 // Static. |
699 bool CPVT_GenerateAP::GenerateComboBoxAP(CPDF_Document* pDoc, | 700 bool CPVT_GenerateAP::GenerateComboBoxAP(CPDF_Document* pDoc, |
(...skipping 12 matching lines...) Expand all Loading... |
712 CPDF_Dictionary* pAnnotDict) { | 713 CPDF_Dictionary* pAnnotDict) { |
713 return GenerateWidgetAP(pDoc, pAnnotDict, 0); | 714 return GenerateWidgetAP(pDoc, pAnnotDict, 0); |
714 } | 715 } |
715 | 716 |
716 bool CPVT_GenerateAP::GenerateCircleAP(CPDF_Document* pDoc, | 717 bool CPVT_GenerateAP::GenerateCircleAP(CPDF_Document* pDoc, |
717 CPDF_Dictionary* pAnnotDict) { | 718 CPDF_Dictionary* pAnnotDict) { |
718 CFX_ByteTextBuf sAppStream; | 719 CFX_ByteTextBuf sAppStream; |
719 CFX_ByteString sExtGSDictName = "GS"; | 720 CFX_ByteString sExtGSDictName = "GS"; |
720 sAppStream << "/" << sExtGSDictName << " gs "; | 721 sAppStream << "/" << sExtGSDictName << " gs "; |
721 | 722 |
722 CPDF_Array* pInteriorColor = pAnnotDict->GetArrayBy("IC"); | 723 CPDF_Array* pInteriorColor = pAnnotDict->GetArrayFor("IC"); |
723 sAppStream << GetColorStringWithDefault(pInteriorColor, | 724 sAppStream << GetColorStringWithDefault(pInteriorColor, |
724 CPVT_Color(CPVT_Color::kTransparent), | 725 CPVT_Color(CPVT_Color::kTransparent), |
725 PaintOperation::FILL); | 726 PaintOperation::FILL); |
726 | 727 |
727 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), | 728 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayFor("C"), |
728 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), | 729 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), |
729 PaintOperation::STROKE); | 730 PaintOperation::STROKE); |
730 | 731 |
731 FX_FLOAT fBorderWidth = GetBorderWidth(*pAnnotDict); | 732 FX_FLOAT fBorderWidth = GetBorderWidth(*pAnnotDict); |
732 bool bIsStrokeRect = fBorderWidth > 0; | 733 bool bIsStrokeRect = fBorderWidth > 0; |
733 | 734 |
734 if (bIsStrokeRect) { | 735 if (bIsStrokeRect) { |
735 sAppStream << fBorderWidth << " w "; | 736 sAppStream << fBorderWidth << " w "; |
736 sAppStream << GetDashPatternString(*pAnnotDict); | 737 sAppStream << GetDashPatternString(*pAnnotDict); |
737 } | 738 } |
738 | 739 |
739 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); | 740 CFX_FloatRect rect = pAnnotDict->GetRectFor("Rect"); |
740 rect.Normalize(); | 741 rect.Normalize(); |
741 | 742 |
742 if (bIsStrokeRect) { | 743 if (bIsStrokeRect) { |
743 // Deflating rect because stroking a path entails painting all points whose | 744 // Deflating rect because stroking a path entails painting all points whose |
744 // perpendicular distance from the path in user space is less than or equal | 745 // perpendicular distance from the path in user space is less than or equal |
745 // to half the line width. | 746 // to half the line width. |
746 rect.Deflate(fBorderWidth / 2, fBorderWidth / 2); | 747 rect.Deflate(fBorderWidth / 2, fBorderWidth / 2); |
747 } | 748 } |
748 | 749 |
749 const FX_FLOAT fMiddleX = (rect.left + rect.right) / 2; | 750 const FX_FLOAT fMiddleX = (rect.left + rect.right) / 2; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict); | 786 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict); |
786 return true; | 787 return true; |
787 } | 788 } |
788 | 789 |
789 bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc, | 790 bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc, |
790 CPDF_Dictionary* pAnnotDict) { | 791 CPDF_Dictionary* pAnnotDict) { |
791 CFX_ByteTextBuf sAppStream; | 792 CFX_ByteTextBuf sAppStream; |
792 CFX_ByteString sExtGSDictName = "GS"; | 793 CFX_ByteString sExtGSDictName = "GS"; |
793 sAppStream << "/" << sExtGSDictName << " gs "; | 794 sAppStream << "/" << sExtGSDictName << " gs "; |
794 | 795 |
795 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), | 796 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayFor("C"), |
796 CPVT_Color(CPVT_Color::kRGB, 1, 1, 0), | 797 CPVT_Color(CPVT_Color::kRGB, 1, 1, 0), |
797 PaintOperation::FILL); | 798 PaintOperation::FILL); |
798 | 799 |
799 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); | 800 CFX_FloatRect rect = pAnnotDict->GetRectFor("Rect"); |
800 rect.Normalize(); | 801 rect.Normalize(); |
801 | 802 |
802 sAppStream << rect.left << " " << rect.top << " m " << rect.right << " " | 803 sAppStream << rect.left << " " << rect.top << " m " << rect.right << " " |
803 << rect.top << " l " << rect.right << " " << rect.bottom << " l " | 804 << rect.top << " l " << rect.right << " " << rect.bottom << " l " |
804 << rect.left << " " << rect.bottom << " l " | 805 << rect.left << " " << rect.bottom << " l " |
805 << "h f\n"; | 806 << "h f\n"; |
806 | 807 |
807 CPDF_Dictionary* pExtGStateDict = | 808 CPDF_Dictionary* pExtGStateDict = |
808 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Multiply"); | 809 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Multiply"); |
809 CPDF_Dictionary* pResourceDict = | 810 CPDF_Dictionary* pResourceDict = |
810 GenerateResourceDict(pExtGStateDict, nullptr); | 811 GenerateResourceDict(pExtGStateDict, nullptr); |
811 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict); | 812 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict); |
812 | 813 |
813 return true; | 814 return true; |
814 } | 815 } |
815 | 816 |
816 bool CPVT_GenerateAP::GenerateInkAP(CPDF_Document* pDoc, | 817 bool CPVT_GenerateAP::GenerateInkAP(CPDF_Document* pDoc, |
817 CPDF_Dictionary* pAnnotDict) { | 818 CPDF_Dictionary* pAnnotDict) { |
818 FX_FLOAT fBorderWidth = GetBorderWidth(*pAnnotDict); | 819 FX_FLOAT fBorderWidth = GetBorderWidth(*pAnnotDict); |
819 bool bIsStroke = fBorderWidth > 0; | 820 bool bIsStroke = fBorderWidth > 0; |
820 | 821 |
821 if (!bIsStroke) | 822 if (!bIsStroke) |
822 return false; | 823 return false; |
823 | 824 |
824 CPDF_Array* pInkList = pAnnotDict->GetArrayBy("InkList"); | 825 CPDF_Array* pInkList = pAnnotDict->GetArrayFor("InkList"); |
825 if (!pInkList || pInkList->IsEmpty()) | 826 if (!pInkList || pInkList->IsEmpty()) |
826 return false; | 827 return false; |
827 | 828 |
828 CFX_ByteTextBuf sAppStream; | 829 CFX_ByteTextBuf sAppStream; |
829 CFX_ByteString sExtGSDictName = "GS"; | 830 CFX_ByteString sExtGSDictName = "GS"; |
830 sAppStream << "/" << sExtGSDictName << " gs "; | 831 sAppStream << "/" << sExtGSDictName << " gs "; |
831 | 832 |
832 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), | 833 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayFor("C"), |
833 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), | 834 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), |
834 PaintOperation::STROKE); | 835 PaintOperation::STROKE); |
835 | 836 |
836 sAppStream << fBorderWidth << " w "; | 837 sAppStream << fBorderWidth << " w "; |
837 sAppStream << GetDashPatternString(*pAnnotDict); | 838 sAppStream << GetDashPatternString(*pAnnotDict); |
838 | 839 |
839 // Set inflated rect as a new rect because paths near the border with large | 840 // Set inflated rect as a new rect because paths near the border with large |
840 // width should not be clipped to the original rect. | 841 // width should not be clipped to the original rect. |
841 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); | 842 CFX_FloatRect rect = pAnnotDict->GetRectFor("Rect"); |
842 rect.Inflate(fBorderWidth / 2, fBorderWidth / 2); | 843 rect.Inflate(fBorderWidth / 2, fBorderWidth / 2); |
843 pAnnotDict->SetAtRect("Rect", rect); | 844 pAnnotDict->SetRectFor("Rect", rect); |
844 | 845 |
845 for (size_t i = 0; i < pInkList->GetCount(); i++) { | 846 for (size_t i = 0; i < pInkList->GetCount(); i++) { |
846 CPDF_Array* pInkCoordList = pInkList->GetArrayAt(i); | 847 CPDF_Array* pInkCoordList = pInkList->GetArrayAt(i); |
847 if (!pInkCoordList || pInkCoordList->GetCount() < 2) | 848 if (!pInkCoordList || pInkCoordList->GetCount() < 2) |
848 continue; | 849 continue; |
849 | 850 |
850 sAppStream << pInkCoordList->GetNumberAt(0) << " " | 851 sAppStream << pInkCoordList->GetNumberAt(0) << " " |
851 << pInkCoordList->GetNumberAt(1) << " m "; | 852 << pInkCoordList->GetNumberAt(1) << " m "; |
852 | 853 |
853 for (size_t j = 0; j < pInkCoordList->GetCount() - 1; j += 2) { | 854 for (size_t j = 0; j < pInkCoordList->GetCount() - 1; j += 2) { |
(...skipping 11 matching lines...) Expand all Loading... |
865 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict); | 866 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict); |
866 return true; | 867 return true; |
867 } | 868 } |
868 | 869 |
869 bool CPVT_GenerateAP::GenerateTextAP(CPDF_Document* pDoc, | 870 bool CPVT_GenerateAP::GenerateTextAP(CPDF_Document* pDoc, |
870 CPDF_Dictionary* pAnnotDict) { | 871 CPDF_Dictionary* pAnnotDict) { |
871 CFX_ByteTextBuf sAppStream; | 872 CFX_ByteTextBuf sAppStream; |
872 CFX_ByteString sExtGSDictName = "GS"; | 873 CFX_ByteString sExtGSDictName = "GS"; |
873 sAppStream << "/" << sExtGSDictName << " gs "; | 874 sAppStream << "/" << sExtGSDictName << " gs "; |
874 | 875 |
875 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); | 876 CFX_FloatRect rect = pAnnotDict->GetRectFor("Rect"); |
876 const FX_FLOAT fNoteLength = 20; | 877 const FX_FLOAT fNoteLength = 20; |
877 CFX_FloatRect noteRect(rect.left, rect.bottom, rect.left + fNoteLength, | 878 CFX_FloatRect noteRect(rect.left, rect.bottom, rect.left + fNoteLength, |
878 rect.bottom + fNoteLength); | 879 rect.bottom + fNoteLength); |
879 pAnnotDict->SetAtRect("Rect", noteRect); | 880 pAnnotDict->SetRectFor("Rect", noteRect); |
880 | 881 |
881 sAppStream << GenerateTextSymbolAP(noteRect); | 882 sAppStream << GenerateTextSymbolAP(noteRect); |
882 | 883 |
883 CPDF_Dictionary* pExtGStateDict = | 884 CPDF_Dictionary* pExtGStateDict = |
884 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); | 885 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); |
885 CPDF_Dictionary* pResourceDict = | 886 CPDF_Dictionary* pResourceDict = |
886 GenerateResourceDict(pExtGStateDict, nullptr); | 887 GenerateResourceDict(pExtGStateDict, nullptr); |
887 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict); | 888 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict); |
888 return true; | 889 return true; |
889 } | 890 } |
890 | 891 |
891 bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc, | 892 bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc, |
892 CPDF_Dictionary* pAnnotDict) { | 893 CPDF_Dictionary* pAnnotDict) { |
893 CFX_ByteTextBuf sAppStream; | 894 CFX_ByteTextBuf sAppStream; |
894 CFX_ByteString sExtGSDictName = "GS"; | 895 CFX_ByteString sExtGSDictName = "GS"; |
895 sAppStream << "/" << sExtGSDictName << " gs "; | 896 sAppStream << "/" << sExtGSDictName << " gs "; |
896 | 897 |
897 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), | 898 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayFor("C"), |
898 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), | 899 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), |
899 PaintOperation::STROKE); | 900 PaintOperation::STROKE); |
900 | 901 |
901 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); | 902 CFX_FloatRect rect = pAnnotDict->GetRectFor("Rect"); |
902 rect.Normalize(); | 903 rect.Normalize(); |
903 | 904 |
904 FX_FLOAT fLineWidth = 1.0; | 905 FX_FLOAT fLineWidth = 1.0; |
905 sAppStream << fLineWidth << " w " << rect.left << " " | 906 sAppStream << fLineWidth << " w " << rect.left << " " |
906 << rect.bottom + fLineWidth << " m " << rect.right << " " | 907 << rect.bottom + fLineWidth << " m " << rect.right << " " |
907 << rect.bottom + fLineWidth << " l S\n"; | 908 << rect.bottom + fLineWidth << " l S\n"; |
908 | 909 |
909 CPDF_Dictionary* pExtGStateDict = | 910 CPDF_Dictionary* pExtGStateDict = |
910 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); | 911 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); |
911 CPDF_Dictionary* pResourceDict = | 912 CPDF_Dictionary* pResourceDict = |
912 GenerateResourceDict(pExtGStateDict, nullptr); | 913 GenerateResourceDict(pExtGStateDict, nullptr); |
913 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict); | 914 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict); |
914 return true; | 915 return true; |
915 } | 916 } |
916 | 917 |
917 bool CPVT_GenerateAP::GeneratePopupAP(CPDF_Document* pDoc, | 918 bool CPVT_GenerateAP::GeneratePopupAP(CPDF_Document* pDoc, |
918 CPDF_Dictionary* pAnnotDict) { | 919 CPDF_Dictionary* pAnnotDict) { |
919 CFX_ByteTextBuf sAppStream; | 920 CFX_ByteTextBuf sAppStream; |
920 CFX_ByteString sExtGSDictName = "GS"; | 921 CFX_ByteString sExtGSDictName = "GS"; |
921 sAppStream << "/" << sExtGSDictName << " gs\n"; | 922 sAppStream << "/" << sExtGSDictName << " gs\n"; |
922 | 923 |
923 sAppStream << GenerateColorAP(CPVT_Color(CPVT_Color::kRGB, 1, 1, 0), | 924 sAppStream << GenerateColorAP(CPVT_Color(CPVT_Color::kRGB, 1, 1, 0), |
924 PaintOperation::FILL); | 925 PaintOperation::FILL); |
925 sAppStream << GenerateColorAP(CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), | 926 sAppStream << GenerateColorAP(CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), |
926 PaintOperation::STROKE); | 927 PaintOperation::STROKE); |
927 | 928 |
928 const FX_FLOAT fBorderWidth = 1; | 929 const FX_FLOAT fBorderWidth = 1; |
929 sAppStream << fBorderWidth << " w\n"; | 930 sAppStream << fBorderWidth << " w\n"; |
930 | 931 |
931 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); | 932 CFX_FloatRect rect = pAnnotDict->GetRectFor("Rect"); |
932 rect.Normalize(); | 933 rect.Normalize(); |
933 rect.Deflate(fBorderWidth / 2, fBorderWidth / 2); | 934 rect.Deflate(fBorderWidth / 2, fBorderWidth / 2); |
934 | 935 |
935 sAppStream << rect.left << " " << rect.bottom << " " << rect.Width() << " " | 936 sAppStream << rect.left << " " << rect.bottom << " " << rect.Width() << " " |
936 << rect.Height() << " re b\n"; | 937 << rect.Height() << " re b\n"; |
937 | 938 |
938 CFX_ByteString sFontName = "FONT"; | 939 CFX_ByteString sFontName = "FONT"; |
939 CPDF_Dictionary* pExtGStateDict = | 940 CPDF_Dictionary* pExtGStateDict = |
940 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); | 941 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); |
941 CPDF_Dictionary* pResourceFontDict = | 942 CPDF_Dictionary* pResourceFontDict = |
942 GenerateResourceFontDict(pDoc, sFontName); | 943 GenerateResourceFontDict(pDoc, sFontName); |
943 CPDF_Dictionary* pResourceDict = | 944 CPDF_Dictionary* pResourceDict = |
944 GenerateResourceDict(pResourceFontDict, pExtGStateDict); | 945 GenerateResourceDict(pResourceFontDict, pExtGStateDict); |
945 | 946 |
946 CPDF_Font* pDefFont = pDoc->LoadFont(pResourceFontDict); | 947 CPDF_Font* pDefFont = pDoc->LoadFont(pResourceFontDict); |
947 if (!pDefFont) | 948 if (!pDefFont) |
948 return false; | 949 return false; |
949 | 950 |
950 sAppStream << GetPopupContentsString(pDoc, *pAnnotDict, pDefFont, sFontName); | 951 sAppStream << GetPopupContentsString(pDoc, *pAnnotDict, pDefFont, sFontName); |
951 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict); | 952 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict); |
952 return true; | 953 return true; |
953 } | 954 } |
954 | 955 |
955 bool CPVT_GenerateAP::GenerateSquareAP(CPDF_Document* pDoc, | 956 bool CPVT_GenerateAP::GenerateSquareAP(CPDF_Document* pDoc, |
956 CPDF_Dictionary* pAnnotDict) { | 957 CPDF_Dictionary* pAnnotDict) { |
957 CFX_ByteTextBuf sAppStream; | 958 CFX_ByteTextBuf sAppStream; |
958 CFX_ByteString sExtGSDictName = "GS"; | 959 CFX_ByteString sExtGSDictName = "GS"; |
959 sAppStream << "/" << sExtGSDictName << " gs "; | 960 sAppStream << "/" << sExtGSDictName << " gs "; |
960 | 961 |
961 CPDF_Array* pInteriorColor = pAnnotDict->GetArrayBy("IC"); | 962 CPDF_Array* pInteriorColor = pAnnotDict->GetArrayFor("IC"); |
962 sAppStream << GetColorStringWithDefault(pInteriorColor, | 963 sAppStream << GetColorStringWithDefault(pInteriorColor, |
963 CPVT_Color(CPVT_Color::kTransparent), | 964 CPVT_Color(CPVT_Color::kTransparent), |
964 PaintOperation::FILL); | 965 PaintOperation::FILL); |
965 | 966 |
966 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), | 967 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayFor("C"), |
967 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), | 968 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), |
968 PaintOperation::STROKE); | 969 PaintOperation::STROKE); |
969 | 970 |
970 FX_FLOAT fBorderWidth = GetBorderWidth(*pAnnotDict); | 971 FX_FLOAT fBorderWidth = GetBorderWidth(*pAnnotDict); |
971 bool bIsStrokeRect = fBorderWidth > 0; | 972 bool bIsStrokeRect = fBorderWidth > 0; |
972 | 973 |
973 if (bIsStrokeRect) { | 974 if (bIsStrokeRect) { |
974 sAppStream << fBorderWidth << " w "; | 975 sAppStream << fBorderWidth << " w "; |
975 sAppStream << GetDashPatternString(*pAnnotDict); | 976 sAppStream << GetDashPatternString(*pAnnotDict); |
976 } | 977 } |
977 | 978 |
978 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); | 979 CFX_FloatRect rect = pAnnotDict->GetRectFor("Rect"); |
979 rect.Normalize(); | 980 rect.Normalize(); |
980 | 981 |
981 if (bIsStrokeRect) { | 982 if (bIsStrokeRect) { |
982 // Deflating rect because stroking a path entails painting all points whose | 983 // Deflating rect because stroking a path entails painting all points whose |
983 // perpendicular distance from the path in user space is less than or equal | 984 // perpendicular distance from the path in user space is less than or equal |
984 // to half the line width. | 985 // to half the line width. |
985 rect.Deflate(fBorderWidth / 2, fBorderWidth / 2); | 986 rect.Deflate(fBorderWidth / 2, fBorderWidth / 2); |
986 } | 987 } |
987 | 988 |
988 bool bIsFillRect = pInteriorColor && (pInteriorColor->GetCount() > 0); | 989 bool bIsFillRect = pInteriorColor && (pInteriorColor->GetCount() > 0); |
989 | 990 |
990 sAppStream << rect.left << " " << rect.bottom << " " << rect.Width() << " " | 991 sAppStream << rect.left << " " << rect.bottom << " " << rect.Width() << " " |
991 << rect.Height() << " re " | 992 << rect.Height() << " re " |
992 << GetPaintOperatorString(bIsStrokeRect, bIsFillRect) << "\n"; | 993 << GetPaintOperatorString(bIsStrokeRect, bIsFillRect) << "\n"; |
993 | 994 |
994 CPDF_Dictionary* pExtGStateDict = | 995 CPDF_Dictionary* pExtGStateDict = |
995 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); | 996 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); |
996 CPDF_Dictionary* pResourceDict = | 997 CPDF_Dictionary* pResourceDict = |
997 GenerateResourceDict(pExtGStateDict, nullptr); | 998 GenerateResourceDict(pExtGStateDict, nullptr); |
998 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict); | 999 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict); |
999 return true; | 1000 return true; |
1000 } | 1001 } |
1001 | 1002 |
1002 bool CPVT_GenerateAP::GenerateSquigglyAP(CPDF_Document* pDoc, | 1003 bool CPVT_GenerateAP::GenerateSquigglyAP(CPDF_Document* pDoc, |
1003 CPDF_Dictionary* pAnnotDict) { | 1004 CPDF_Dictionary* pAnnotDict) { |
1004 CFX_ByteTextBuf sAppStream; | 1005 CFX_ByteTextBuf sAppStream; |
1005 CFX_ByteString sExtGSDictName = "GS"; | 1006 CFX_ByteString sExtGSDictName = "GS"; |
1006 sAppStream << "/" << sExtGSDictName << " gs "; | 1007 sAppStream << "/" << sExtGSDictName << " gs "; |
1007 | 1008 |
1008 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), | 1009 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayFor("C"), |
1009 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), | 1010 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), |
1010 PaintOperation::STROKE); | 1011 PaintOperation::STROKE); |
1011 | 1012 |
1012 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); | 1013 CFX_FloatRect rect = pAnnotDict->GetRectFor("Rect"); |
1013 rect.Normalize(); | 1014 rect.Normalize(); |
1014 | 1015 |
1015 FX_FLOAT fLineWidth = 1.0; | 1016 FX_FLOAT fLineWidth = 1.0; |
1016 sAppStream << fLineWidth << " w "; | 1017 sAppStream << fLineWidth << " w "; |
1017 | 1018 |
1018 const FX_FLOAT fDelta = 2.0; | 1019 const FX_FLOAT fDelta = 2.0; |
1019 const FX_FLOAT fTop = rect.bottom + fDelta; | 1020 const FX_FLOAT fTop = rect.bottom + fDelta; |
1020 const FX_FLOAT fBottom = rect.bottom; | 1021 const FX_FLOAT fBottom = rect.bottom; |
1021 | 1022 |
1022 sAppStream << rect.left << " " << fTop << " m "; | 1023 sAppStream << rect.left << " " << fTop << " m "; |
(...skipping 23 matching lines...) Expand all Loading... |
1046 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict); | 1047 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict); |
1047 return true; | 1048 return true; |
1048 } | 1049 } |
1049 | 1050 |
1050 bool CPVT_GenerateAP::GenerateStrikeOutAP(CPDF_Document* pDoc, | 1051 bool CPVT_GenerateAP::GenerateStrikeOutAP(CPDF_Document* pDoc, |
1051 CPDF_Dictionary* pAnnotDict) { | 1052 CPDF_Dictionary* pAnnotDict) { |
1052 CFX_ByteTextBuf sAppStream; | 1053 CFX_ByteTextBuf sAppStream; |
1053 CFX_ByteString sExtGSDictName = "GS"; | 1054 CFX_ByteString sExtGSDictName = "GS"; |
1054 sAppStream << "/" << sExtGSDictName << " gs "; | 1055 sAppStream << "/" << sExtGSDictName << " gs "; |
1055 | 1056 |
1056 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayBy("C"), | 1057 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayFor("C"), |
1057 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), | 1058 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), |
1058 PaintOperation::STROKE); | 1059 PaintOperation::STROKE); |
1059 | 1060 |
1060 CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); | 1061 CFX_FloatRect rect = pAnnotDict->GetRectFor("Rect"); |
1061 rect.Normalize(); | 1062 rect.Normalize(); |
1062 | 1063 |
1063 FX_FLOAT fLineWidth = 1.0; | 1064 FX_FLOAT fLineWidth = 1.0; |
1064 FX_FLOAT fY = (rect.top + rect.bottom) / 2; | 1065 FX_FLOAT fY = (rect.top + rect.bottom) / 2; |
1065 sAppStream << fLineWidth << " w " << rect.left << " " << fY << " m " | 1066 sAppStream << fLineWidth << " w " << rect.left << " " << fY << " m " |
1066 << rect.right << " " << fY << " l S\n"; | 1067 << rect.right << " " << fY << " l S\n"; |
1067 | 1068 |
1068 CPDF_Dictionary* pExtGStateDict = | 1069 CPDF_Dictionary* pExtGStateDict = |
1069 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); | 1070 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); |
1070 CPDF_Dictionary* pResourceDict = | 1071 CPDF_Dictionary* pResourceDict = |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1333 int32_t nFontIndex, | 1334 int32_t nFontIndex, |
1334 FX_FLOAT fFontSize) { | 1335 FX_FLOAT fFontSize) { |
1335 CFX_ByteTextBuf sRet; | 1336 CFX_ByteTextBuf sRet; |
1336 if (pFontMap) { | 1337 if (pFontMap) { |
1337 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); | 1338 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); |
1338 if (sFontAlias.GetLength() > 0 && fFontSize > 0) | 1339 if (sFontAlias.GetLength() > 0 && fFontSize > 0) |
1339 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; | 1340 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; |
1340 } | 1341 } |
1341 return sRet.MakeString(); | 1342 return sRet.MakeString(); |
1342 } | 1343 } |
OLD | NEW |