Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Side by Side Diff: core/fpdfdoc/cpvt_generateap.cpp

Issue 1840413002: Split core/include/fpdfdoc/fpdf_ap.h (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/fpdfdoc/cpvt_generateap.h ('k') | core/fpdfdoc/cpvt_provider.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 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"
8
7 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" 9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h"
8 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
9 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h" 12 #include "core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h"
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" 13 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h"
12 #include "core/fpdfdoc/doc_utils.h" 14 #include "core/fpdfdoc/cpvt_color.h"
15 #include "core/fpdfdoc/cpvt_fontmap.h"
16 #include "core/fpdfdoc/cpvt_provider.h"
13 #include "core/fpdfdoc/pdf_vt.h" 17 #include "core/fpdfdoc/pdf_vt.h"
14 #include "core/include/fpdfdoc/fpdf_ap.h"
15 #include "core/include/fpdfdoc/fpdf_doc.h" 18 #include "core/include/fpdfdoc/fpdf_doc.h"
16 #include "core/include/fpdfdoc/fpdf_vt.h"
17 19
18 #define PBS_SOLID 0 20 namespace {
19 #define PBS_DASH 1
20 #define PBS_BEVELED 2
21 #define PBS_INSET 3
22 #define PBS_UNDERLINED 4
23 21
24 FX_BOOL FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) { 22 FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc,
25 if (!pAnnotDict || pAnnotDict->GetConstStringBy("Subtype") != "Widget") { 23 CPDF_Dictionary* pAnnotDict,
24 const int32_t& nWidgetType) {
25 CPDF_Dictionary* pFormDict = nullptr;
26 if (CPDF_Dictionary* pRootDict = pDoc->GetRoot())
27 pFormDict = pRootDict->GetDictBy("AcroForm");
28 if (!pFormDict)
26 return FALSE; 29 return FALSE;
27 }
28 CFX_ByteString field_type = FPDF_GetFieldAttr(pAnnotDict, "FT")->GetString();
29 uint32_t flags = FPDF_GetFieldAttr(pAnnotDict, "Ff")
30 ? FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteger()
31 : 0;
32 if (field_type == "Tx") {
33 return CPVT_GenerateAP::GenerateTextFieldAP(pDoc, pAnnotDict);
34 }
35 if (field_type == "Ch") {
36 return (flags & (1 << 17))
37 ? CPVT_GenerateAP::GenerateComboBoxAP(pDoc, pAnnotDict)
38 : CPVT_GenerateAP::GenerateListBoxAP(pDoc, pAnnotDict);
39 }
40 if (field_type == "Btn") {
41 if (!(flags & (1 << 16))) {
42 if (!pAnnotDict->KeyExist("AS")) {
43 if (CPDF_Dictionary* pParentDict = pAnnotDict->GetDictBy("Parent")) {
44 if (pParentDict->KeyExist("AS")) {
45 pAnnotDict->SetAtString("AS", pParentDict->GetStringBy("AS"));
46 }
47 }
48 }
49 }
50 }
51 return FALSE;
52 }
53 30
54 class CPVT_FontMap : public IPVT_FontMap { 31 CFX_ByteString DA;
55 public: 32 if (CPDF_Object* pDAObj = FPDF_GetFieldAttr(pAnnotDict, "DA"))
56 CPVT_FontMap(CPDF_Document* pDoc, 33 DA = pDAObj->GetString();
57 CPDF_Dictionary* pResDict, 34 if (DA.IsEmpty())
58 CPDF_Font* pDefFont, 35 DA = pFormDict->GetStringBy("DA");
59 const CFX_ByteString& sDefFontAlias); 36 if (DA.IsEmpty())
60 ~CPVT_FontMap() override; 37 return FALSE;
61 38
62 // IPVT_FontMap
63 CPDF_Font* GetPDFFont(int32_t nFontIndex) override;
64 CFX_ByteString GetPDFFontAlias(int32_t nFontIndex) override;
65
66 static void GetAnnotSysPDFFont(CPDF_Document* pDoc,
67 CPDF_Dictionary* pResDict,
68 CPDF_Font*& pSysFont,
69 CFX_ByteString& sSysFontAlias);
70
71 private:
72 CPDF_Document* m_pDocument;
73 CPDF_Dictionary* m_pResDict;
74 CPDF_Font* m_pDefFont;
75 CFX_ByteString m_sDefFontAlias;
76 CPDF_Font* m_pSysFont;
77 CFX_ByteString m_sSysFontAlias;
78 };
79
80 CPVT_FontMap::CPVT_FontMap(CPDF_Document* pDoc,
81 CPDF_Dictionary* pResDict,
82 CPDF_Font* pDefFont,
83 const CFX_ByteString& sDefFontAlias)
84 : m_pDocument(pDoc),
85 m_pResDict(pResDict),
86 m_pDefFont(pDefFont),
87 m_sDefFontAlias(sDefFontAlias),
88 m_pSysFont(NULL),
89 m_sSysFontAlias() {}
90 CPVT_FontMap::~CPVT_FontMap() {}
91 void CPVT_FontMap::GetAnnotSysPDFFont(CPDF_Document* pDoc,
92 CPDF_Dictionary* pResDict,
93 CPDF_Font*& pSysFont,
94 CFX_ByteString& sSysFontAlias) {
95 if (pDoc && pResDict) {
96 CFX_ByteString sFontAlias;
97 CPDF_Dictionary* pFormDict = pDoc->GetRoot()->GetDictBy("AcroForm");
98 if (CPDF_Font* pPDFFont =
99 AddNativeInterFormFont(pFormDict, pDoc, sSysFontAlias)) {
100 if (CPDF_Dictionary* pFontList = pResDict->GetDictBy("Font")) {
101 if (!pFontList->KeyExist(sSysFontAlias)) {
102 pFontList->SetAtReference(sSysFontAlias, pDoc,
103 pPDFFont->GetFontDict());
104 }
105 }
106 pSysFont = pPDFFont;
107 }
108 }
109 }
110 CPDF_Font* CPVT_FontMap::GetPDFFont(int32_t nFontIndex) {
111 switch (nFontIndex) {
112 case 0:
113 return m_pDefFont;
114 case 1:
115 if (!m_pSysFont) {
116 GetAnnotSysPDFFont(m_pDocument, m_pResDict, m_pSysFont,
117 m_sSysFontAlias);
118 }
119 return m_pSysFont;
120 }
121 return NULL;
122 }
123 CFX_ByteString CPVT_FontMap::GetPDFFontAlias(int32_t nFontIndex) {
124 switch (nFontIndex) {
125 case 0:
126 return m_sDefFontAlias;
127 case 1:
128 if (!m_pSysFont) {
129 GetAnnotSysPDFFont(m_pDocument, m_pResDict, m_pSysFont,
130 m_sSysFontAlias);
131 }
132 return m_sSysFontAlias;
133 }
134 return "";
135 }
136 CPVT_Provider::CPVT_Provider(IPVT_FontMap* pFontMap) : m_pFontMap(pFontMap) {
137 ASSERT(m_pFontMap);
138 }
139 CPVT_Provider::~CPVT_Provider() {}
140 int32_t CPVT_Provider::GetCharWidth(int32_t nFontIndex,
141 uint16_t word,
142 int32_t nWordStyle) {
143 if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) {
144 uint32_t charcode = pPDFFont->CharCodeFromUnicode(word);
145 if (charcode != CPDF_Font::kInvalidCharCode) {
146 return pPDFFont->GetCharWidthF(charcode);
147 }
148 }
149 return 0;
150 }
151 int32_t CPVT_Provider::GetTypeAscent(int32_t nFontIndex) {
152 if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) {
153 return pPDFFont->GetTypeAscent();
154 }
155 return 0;
156 }
157 int32_t CPVT_Provider::GetTypeDescent(int32_t nFontIndex) {
158 if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) {
159 return pPDFFont->GetTypeDescent();
160 }
161 return 0;
162 }
163 int32_t CPVT_Provider::GetWordFontIndex(uint16_t word,
164 int32_t charset,
165 int32_t nFontIndex) {
166 if (CPDF_Font* pDefFont = m_pFontMap->GetPDFFont(0)) {
167 if (pDefFont->CharCodeFromUnicode(word) != CPDF_Font::kInvalidCharCode) {
168 return 0;
169 }
170 }
171 if (CPDF_Font* pSysFont = m_pFontMap->GetPDFFont(1)) {
172 if (pSysFont->CharCodeFromUnicode(word) != CPDF_Font::kInvalidCharCode) {
173 return 1;
174 }
175 }
176 return -1;
177 }
178 FX_BOOL CPVT_Provider::IsLatinWord(uint16_t word) {
179 if ((word >= 0x61 && word <= 0x7A) || (word >= 0x41 && word <= 0x5A) ||
180 word == 0x2D || word == 0x27) {
181 return TRUE;
182 }
183 return FALSE;
184 }
185 int32_t CPVT_Provider::GetDefaultFontIndex() {
186 return 0;
187 }
188
189 static CFX_ByteString GetPDFWordString(IPVT_FontMap* pFontMap,
190 int32_t nFontIndex,
191 uint16_t Word,
192 uint16_t SubWord) {
193 CFX_ByteString sWord;
194 if (SubWord > 0) {
195 sWord.Format("%c", SubWord);
196 return sWord;
197 }
198
199 if (!pFontMap)
200 return sWord;
201
202 if (CPDF_Font* pPDFFont = pFontMap->GetPDFFont(nFontIndex)) {
203 if (pPDFFont->GetBaseFont().Compare("Symbol") == 0 ||
204 pPDFFont->GetBaseFont().Compare("ZapfDingbats") == 0) {
205 sWord.Format("%c", Word);
206 } else {
207 uint32_t dwCharCode = pPDFFont->CharCodeFromUnicode(Word);
208 if (dwCharCode != CPDF_Font::kInvalidCharCode) {
209 pPDFFont->AppendChar(sWord, dwCharCode);
210 }
211 }
212 }
213 return sWord;
214 }
215
216 static CFX_ByteString GetWordRenderString(const CFX_ByteString& strWords) {
217 if (strWords.GetLength() > 0) {
218 return PDF_EncodeString(strWords) + " Tj\n";
219 }
220 return "";
221 }
222 static CFX_ByteString GetFontSetString(IPVT_FontMap* pFontMap,
223 int32_t nFontIndex,
224 FX_FLOAT fFontSize) {
225 CFX_ByteTextBuf sRet;
226 if (pFontMap) {
227 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex);
228 if (sFontAlias.GetLength() > 0 && fFontSize > 0) {
229 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n";
230 }
231 }
232 return sRet.GetByteString();
233 }
234 static CPVT_Color ParseColor(const CFX_ByteString& str) {
235 CPDF_SimpleParser syntax(str);
236 if (syntax.FindTagParamFromStart("g", 1)) {
237 return CPVT_Color(CPVT_Color::kGray, FX_atof(syntax.GetWord()));
238 }
239 if (syntax.FindTagParamFromStart("rg", 3)) {
240 FX_FLOAT f1 = FX_atof(syntax.GetWord());
241 FX_FLOAT f2 = FX_atof(syntax.GetWord());
242 FX_FLOAT f3 = FX_atof(syntax.GetWord());
243 return CPVT_Color(CPVT_Color::kRGB, f1, f2, f3);
244 }
245 if (syntax.FindTagParamFromStart("k", 4)) {
246 FX_FLOAT f1 = FX_atof(syntax.GetWord());
247 FX_FLOAT f2 = FX_atof(syntax.GetWord());
248 FX_FLOAT f3 = FX_atof(syntax.GetWord());
249 FX_FLOAT f4 = FX_atof(syntax.GetWord());
250 return CPVT_Color(CPVT_Color::kCMYK, f1, f2, f3, f4);
251 }
252 return CPVT_Color(CPVT_Color::kTransparent);
253 }
254 static CPVT_Color ParseColor(const CPDF_Array& array) {
255 CPVT_Color rt;
256 switch (array.GetCount()) {
257 case 1:
258 rt = CPVT_Color(CPVT_Color::kGray, array.GetFloatAt(0));
259 break;
260 case 3:
261 rt = CPVT_Color(CPVT_Color::kRGB, array.GetFloatAt(0),
262 array.GetFloatAt(1), array.GetFloatAt(2));
263 break;
264 case 4:
265 rt = CPVT_Color(CPVT_Color::kCMYK, array.GetFloatAt(0),
266 array.GetFloatAt(1), array.GetFloatAt(2),
267 array.GetFloatAt(3));
268 break;
269 }
270 return rt;
271 }
272 static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc,
273 CPDF_Dictionary* pAnnotDict,
274 const int32_t& nWidgetType) {
275 CPDF_Dictionary* pFormDict = NULL;
276 if (CPDF_Dictionary* pRootDict = pDoc->GetRoot()) {
277 pFormDict = pRootDict->GetDictBy("AcroForm");
278 }
279 if (!pFormDict) {
280 return FALSE;
281 }
282 CFX_ByteString DA;
283 if (CPDF_Object* pDAObj = FPDF_GetFieldAttr(pAnnotDict, "DA")) {
284 DA = pDAObj->GetString();
285 }
286 if (DA.IsEmpty()) {
287 DA = pFormDict->GetStringBy("DA");
288 }
289 if (DA.IsEmpty()) {
290 return FALSE;
291 }
292 CPDF_SimpleParser syntax(DA); 39 CPDF_SimpleParser syntax(DA);
293 syntax.FindTagParamFromStart("Tf", 2); 40 syntax.FindTagParamFromStart("Tf", 2);
294 CFX_ByteString sFontName = syntax.GetWord(); 41 CFX_ByteString sFontName = syntax.GetWord();
295 sFontName = PDF_NameDecode(sFontName); 42 sFontName = PDF_NameDecode(sFontName);
296 if (sFontName.IsEmpty()) { 43 if (sFontName.IsEmpty())
297 return FALSE; 44 return FALSE;
298 } 45
299 FX_FLOAT fFontSize = FX_atof(syntax.GetWord()); 46 FX_FLOAT fFontSize = FX_atof(syntax.GetWord());
300 CPVT_Color crText = ParseColor(DA); 47 CPVT_Color crText = CPVT_Color::ParseColor(DA);
301 FX_BOOL bUseFormRes = FALSE; 48 FX_BOOL bUseFormRes = FALSE;
302 CPDF_Dictionary* pFontDict = NULL; 49 CPDF_Dictionary* pFontDict = nullptr;
303 CPDF_Dictionary* pDRDict = pAnnotDict->GetDictBy("DR"); 50 CPDF_Dictionary* pDRDict = pAnnotDict->GetDictBy("DR");
304 if (!pDRDict) { 51 if (!pDRDict) {
305 pDRDict = pFormDict->GetDictBy("DR"); 52 pDRDict = pFormDict->GetDictBy("DR");
306 bUseFormRes = TRUE; 53 bUseFormRes = TRUE;
307 } 54 }
308 CPDF_Dictionary* pDRFontDict = pDRDict ? pDRDict->GetDictBy("Font") : nullptr; 55 CPDF_Dictionary* pDRFontDict = pDRDict ? pDRDict->GetDictBy("Font") : nullptr;
309 if (pDRFontDict) { 56 if (pDRFontDict) {
310 pFontDict = pDRFontDict->GetDictBy(sFontName.Mid(1)); 57 pFontDict = pDRFontDict->GetDictBy(sFontName.Mid(1));
311 if (!pFontDict && !bUseFormRes) { 58 if (!pFontDict && !bUseFormRes) {
312 pDRDict = pFormDict->GetDictBy("DR"); 59 pDRDict = pFormDict->GetDictBy("DR");
313 pDRFontDict = pDRDict->GetDictBy("Font"); 60 pDRFontDict = pDRDict->GetDictBy("Font");
314 if (pDRFontDict) { 61 if (pDRFontDict)
315 pFontDict = pDRFontDict->GetDictBy(sFontName.Mid(1)); 62 pFontDict = pDRFontDict->GetDictBy(sFontName.Mid(1));
316 }
317 } 63 }
318 } 64 }
319 if (!pDRFontDict) { 65 if (!pDRFontDict)
320 return FALSE; 66 return FALSE;
321 } 67
322 if (!pFontDict) { 68 if (!pFontDict) {
323 pFontDict = new CPDF_Dictionary; 69 pFontDict = new CPDF_Dictionary;
324 pFontDict->SetAtName("Type", "Font"); 70 pFontDict->SetAtName("Type", "Font");
325 pFontDict->SetAtName("Subtype", "Type1"); 71 pFontDict->SetAtName("Subtype", "Type1");
326 pFontDict->SetAtName("BaseFont", "Helvetica"); 72 pFontDict->SetAtName("BaseFont", "Helvetica");
327 pFontDict->SetAtName("Encoding", "WinAnsiEncoding"); 73 pFontDict->SetAtName("Encoding", "WinAnsiEncoding");
328 pDoc->AddIndirectObject(pFontDict); 74 pDoc->AddIndirectObject(pFontDict);
329 pDRFontDict->SetAtReference(sFontName.Mid(1), pDoc, pFontDict); 75 pDRFontDict->SetAtReference(sFontName.Mid(1), pDoc, pFontDict);
330 } 76 }
331 CPDF_Font* pDefFont = pDoc->LoadFont(pFontDict); 77 CPDF_Font* pDefFont = pDoc->LoadFont(pFontDict);
332 if (!pDefFont) { 78 if (!pDefFont)
333 return FALSE; 79 return FALSE;
334 } 80
335 CFX_FloatRect rcAnnot = pAnnotDict->GetRectBy("Rect"); 81 CFX_FloatRect rcAnnot = pAnnotDict->GetRectBy("Rect");
336 int32_t nRotate = 0; 82 int32_t nRotate = 0;
337 if (CPDF_Dictionary* pMKDict = pAnnotDict->GetDictBy("MK")) { 83 if (CPDF_Dictionary* pMKDict = pAnnotDict->GetDictBy("MK"))
338 nRotate = pMKDict->GetIntegerBy("R"); 84 nRotate = pMKDict->GetIntegerBy("R");
339 } 85
340 CFX_FloatRect rcBBox; 86 CFX_FloatRect rcBBox;
341 CFX_Matrix matrix; 87 CFX_Matrix matrix;
342 switch (nRotate % 360) { 88 switch (nRotate % 360) {
343 case 0: 89 case 0:
344 rcBBox = CFX_FloatRect(0, 0, rcAnnot.right - rcAnnot.left, 90 rcBBox = CFX_FloatRect(0, 0, rcAnnot.right - rcAnnot.left,
345 rcAnnot.top - rcAnnot.bottom); 91 rcAnnot.top - rcAnnot.bottom);
346 break; 92 break;
347 case 90: 93 case 90:
348 matrix = CFX_Matrix(0, 1, -1, 0, rcAnnot.right - rcAnnot.left, 0); 94 matrix = CFX_Matrix(0, 1, -1, 0, rcAnnot.right - rcAnnot.left, 0);
349 rcBBox = CFX_FloatRect(0, 0, rcAnnot.top - rcAnnot.bottom, 95 rcBBox = CFX_FloatRect(0, 0, rcAnnot.top - rcAnnot.bottom,
350 rcAnnot.right - rcAnnot.left); 96 rcAnnot.right - rcAnnot.left);
351 break; 97 break;
352 case 180: 98 case 180:
353 matrix = CFX_Matrix(-1, 0, 0, -1, rcAnnot.right - rcAnnot.left, 99 matrix = CFX_Matrix(-1, 0, 0, -1, rcAnnot.right - rcAnnot.left,
354 rcAnnot.top - rcAnnot.bottom); 100 rcAnnot.top - rcAnnot.bottom);
355 rcBBox = CFX_FloatRect(0, 0, rcAnnot.right - rcAnnot.left, 101 rcBBox = CFX_FloatRect(0, 0, rcAnnot.right - rcAnnot.left,
356 rcAnnot.top - rcAnnot.bottom); 102 rcAnnot.top - rcAnnot.bottom);
357 break; 103 break;
358 case 270: 104 case 270:
359 matrix = CFX_Matrix(0, -1, 1, 0, 0, rcAnnot.top - rcAnnot.bottom); 105 matrix = CFX_Matrix(0, -1, 1, 0, 0, rcAnnot.top - rcAnnot.bottom);
360 rcBBox = CFX_FloatRect(0, 0, rcAnnot.top - rcAnnot.bottom, 106 rcBBox = CFX_FloatRect(0, 0, rcAnnot.top - rcAnnot.bottom,
361 rcAnnot.right - rcAnnot.left); 107 rcAnnot.right - rcAnnot.left);
362 break; 108 break;
363 } 109 }
364 int32_t nBorderStyle = PBS_SOLID; 110 int32_t nBorderStyle = PBS_SOLID;
365 FX_FLOAT fBorderWidth = 1; 111 FX_FLOAT fBorderWidth = 1;
366 CPVT_Dash dsBorder(3, 0, 0); 112 CPVT_Dash dsBorder(3, 0, 0);
367 CPVT_Color crLeftTop, crRightBottom; 113 CPVT_Color crLeftTop, crRightBottom;
368 if (CPDF_Dictionary* pBSDict = pAnnotDict->GetDictBy("BS")) { 114 if (CPDF_Dictionary* pBSDict = pAnnotDict->GetDictBy("BS")) {
369 if (pBSDict->KeyExist("W")) { 115 if (pBSDict->KeyExist("W"))
370 fBorderWidth = pBSDict->GetNumberBy("W"); 116 fBorderWidth = pBSDict->GetNumberBy("W");
371 } 117
372 if (CPDF_Array* pArray = pBSDict->GetArrayBy("D")) { 118 if (CPDF_Array* pArray = pBSDict->GetArrayBy("D")) {
373 dsBorder = CPVT_Dash(pArray->GetIntegerAt(0), pArray->GetIntegerAt(1), 119 dsBorder = CPVT_Dash(pArray->GetIntegerAt(0), pArray->GetIntegerAt(1),
374 pArray->GetIntegerAt(2)); 120 pArray->GetIntegerAt(2));
375 } 121 }
376 switch (pBSDict->GetStringBy("S").GetAt(0)) { 122 switch (pBSDict->GetStringBy("S").GetAt(0)) {
377 case 'S': 123 case 'S':
378 nBorderStyle = PBS_SOLID; 124 nBorderStyle = PBS_SOLID;
379 break; 125 break;
380 case 'D': 126 case 'D':
381 nBorderStyle = PBS_DASH; 127 nBorderStyle = PBS_DASH;
(...skipping 10 matching lines...) Expand all
392 crLeftTop = CPVT_Color(CPVT_Color::kGray, 0.5); 138 crLeftTop = CPVT_Color(CPVT_Color::kGray, 0.5);
393 crRightBottom = CPVT_Color(CPVT_Color::kGray, 0.75); 139 crRightBottom = CPVT_Color(CPVT_Color::kGray, 0.75);
394 break; 140 break;
395 case 'U': 141 case 'U':
396 nBorderStyle = PBS_UNDERLINED; 142 nBorderStyle = PBS_UNDERLINED;
397 break; 143 break;
398 } 144 }
399 } 145 }
400 CPVT_Color crBorder, crBG; 146 CPVT_Color crBorder, crBG;
401 if (CPDF_Dictionary* pMKDict = pAnnotDict->GetDictBy("MK")) { 147 if (CPDF_Dictionary* pMKDict = pAnnotDict->GetDictBy("MK")) {
402 if (CPDF_Array* pArray = pMKDict->GetArrayBy("BC")) { 148 if (CPDF_Array* pArray = pMKDict->GetArrayBy("BC"))
403 crBorder = ParseColor(*pArray); 149 crBorder = CPVT_Color::ParseColor(*pArray);
404 } 150 if (CPDF_Array* pArray = pMKDict->GetArrayBy("BG"))
405 if (CPDF_Array* pArray = pMKDict->GetArrayBy("BG")) { 151 crBG = CPVT_Color::ParseColor(*pArray);
406 crBG = ParseColor(*pArray);
407 }
408 } 152 }
409 CFX_ByteTextBuf sAppStream; 153 CFX_ByteTextBuf sAppStream;
410 CFX_ByteString sBG = CPVT_GenerateAP::GenerateColorAP(crBG, TRUE); 154 CFX_ByteString sBG = CPVT_GenerateAP::GenerateColorAP(crBG, TRUE);
411 if (sBG.GetLength() > 0) { 155 if (sBG.GetLength() > 0) {
412 sAppStream << "q\n" << sBG << rcBBox.left << " " << rcBBox.bottom << " " 156 sAppStream << "q\n" << sBG << rcBBox.left << " " << rcBBox.bottom << " "
413 << rcBBox.Width() << " " << rcBBox.Height() << " re f\n" 157 << rcBBox.Width() << " " << rcBBox.Height() << " re f\n"
414 << "Q\n"; 158 << "Q\n";
415 } 159 }
416 CFX_ByteString sBorderStream = CPVT_GenerateAP::GenerateBorderAP( 160 CFX_ByteString sBorderStream = CPVT_GenerateAP::GenerateBorderAP(
417 rcBBox, fBorderWidth, crBorder, crLeftTop, crRightBottom, nBorderStyle, 161 rcBBox, fBorderWidth, crBorder, crLeftTop, crRightBottom, nBorderStyle,
418 dsBorder); 162 dsBorder);
419 if (sBorderStream.GetLength() > 0) { 163 if (sBorderStream.GetLength() > 0)
420 sAppStream << "q\n" << sBorderStream << "Q\n"; 164 sAppStream << "q\n" << sBorderStream << "Q\n";
421 } 165
422 CFX_FloatRect rcBody = 166 CFX_FloatRect rcBody =
423 CFX_FloatRect(rcBBox.left + fBorderWidth, rcBBox.bottom + fBorderWidth, 167 CFX_FloatRect(rcBBox.left + fBorderWidth, rcBBox.bottom + fBorderWidth,
424 rcBBox.right - fBorderWidth, rcBBox.top - fBorderWidth); 168 rcBBox.right - fBorderWidth, rcBBox.top - fBorderWidth);
425 rcBody.Normalize(); 169 rcBody.Normalize();
426 CPDF_Dictionary* pAPDict = pAnnotDict->GetDictBy("AP"); 170 CPDF_Dictionary* pAPDict = pAnnotDict->GetDictBy("AP");
427 if (!pAPDict) { 171 if (!pAPDict) {
428 pAPDict = new CPDF_Dictionary; 172 pAPDict = new CPDF_Dictionary;
429 pAnnotDict->SetAt("AP", pAPDict); 173 pAnnotDict->SetAt("AP", pAPDict);
430 } 174 }
431 CPDF_Stream* pNormalStream = pAPDict->GetStreamBy("N"); 175 CPDF_Stream* pNormalStream = pAPDict->GetStreamBy("N");
432 if (!pNormalStream) { 176 if (!pNormalStream) {
433 pNormalStream = new CPDF_Stream(nullptr, 0, nullptr); 177 pNormalStream = new CPDF_Stream(nullptr, 0, nullptr);
434 int32_t objnum = pDoc->AddIndirectObject(pNormalStream); 178 int32_t objnum = pDoc->AddIndirectObject(pNormalStream);
435 pAnnotDict->GetDictBy("AP")->SetAtReference("N", pDoc, objnum); 179 pAnnotDict->GetDictBy("AP")->SetAtReference("N", pDoc, objnum);
436 } 180 }
437 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); 181 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict();
438 if (pStreamDict) { 182 if (pStreamDict) {
439 pStreamDict->SetAtMatrix("Matrix", matrix); 183 pStreamDict->SetAtMatrix("Matrix", matrix);
440 pStreamDict->SetAtRect("BBox", rcBBox); 184 pStreamDict->SetAtRect("BBox", rcBBox);
441 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictBy("Resources"); 185 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictBy("Resources");
442 if (pStreamResList) { 186 if (pStreamResList) {
443 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictBy("Font"); 187 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictBy("Font");
444 if (!pStreamResFontList) { 188 if (!pStreamResFontList) {
445 pStreamResFontList = new CPDF_Dictionary; 189 pStreamResFontList = new CPDF_Dictionary;
446 pStreamResList->SetAt("Font", pStreamResFontList); 190 pStreamResList->SetAt("Font", pStreamResFontList);
447 } 191 }
448 if (!pStreamResFontList->KeyExist(sFontName)) { 192 if (!pStreamResFontList->KeyExist(sFontName))
449 pStreamResFontList->SetAtReference(sFontName, pDoc, pFontDict); 193 pStreamResFontList->SetAtReference(sFontName, pDoc, pFontDict);
450 }
451 } else { 194 } else {
452 pStreamDict->SetAt("Resources", pFormDict->GetDictBy("DR")->Clone()); 195 pStreamDict->SetAt("Resources", pFormDict->GetDictBy("DR")->Clone());
453 pStreamResList = pStreamDict->GetDictBy("Resources"); 196 pStreamResList = pStreamDict->GetDictBy("Resources");
454 } 197 }
455 } 198 }
456 switch (nWidgetType) { 199 switch (nWidgetType) {
457 case 0: { 200 case 0: {
458 CFX_WideString swValue = 201 CFX_WideString swValue =
459 FPDF_GetFieldAttr(pAnnotDict, "V") 202 FPDF_GetFieldAttr(pAnnotDict, "V")
460 ? FPDF_GetFieldAttr(pAnnotDict, "V")->GetUnicodeText() 203 ? FPDF_GetFieldAttr(pAnnotDict, "V")->GetUnicodeText()
461 : CFX_WideString(); 204 : CFX_WideString();
462 int32_t nAlign = FPDF_GetFieldAttr(pAnnotDict, "Q") 205 int32_t nAlign = FPDF_GetFieldAttr(pAnnotDict, "Q")
463 ? FPDF_GetFieldAttr(pAnnotDict, "Q")->GetInteger() 206 ? FPDF_GetFieldAttr(pAnnotDict, "Q")->GetInteger()
464 : 0; 207 : 0;
465 uint32_t dwFlags = FPDF_GetFieldAttr(pAnnotDict, "Ff") 208 uint32_t dwFlags = FPDF_GetFieldAttr(pAnnotDict, "Ff")
466 ? FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteger() 209 ? FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteger()
467 : 0; 210 : 0;
468 uint32_t dwMaxLen = 211 uint32_t dwMaxLen =
469 FPDF_GetFieldAttr(pAnnotDict, "MaxLen") 212 FPDF_GetFieldAttr(pAnnotDict, "MaxLen")
470 ? FPDF_GetFieldAttr(pAnnotDict, "MaxLen")->GetInteger() 213 ? FPDF_GetFieldAttr(pAnnotDict, "MaxLen")->GetInteger()
471 : 0; 214 : 0;
472 CPVT_FontMap map(pDoc, 215 CPVT_FontMap map(
473 pStreamDict ? pStreamDict->GetDictBy("Resources") : NULL, 216 pDoc, pStreamDict ? pStreamDict->GetDictBy("Resources") : nullptr,
474 pDefFont, sFontName.Right(sFontName.GetLength() - 1)); 217 pDefFont, sFontName.Right(sFontName.GetLength() - 1));
475 CPVT_Provider prd(&map); 218 CPVT_Provider prd(&map);
476 CPDF_VariableText vt; 219 CPDF_VariableText vt;
477 vt.SetProvider(&prd); 220 vt.SetProvider(&prd);
478 vt.SetPlateRect(rcBody); 221 vt.SetPlateRect(rcBody);
479 vt.SetAlignment(nAlign); 222 vt.SetAlignment(nAlign);
480 if (IsFloatZero(fFontSize)) { 223 if (IsFloatZero(fFontSize))
481 vt.SetAutoFontSize(TRUE); 224 vt.SetAutoFontSize(TRUE);
482 } else { 225 else
483 vt.SetFontSize(fFontSize); 226 vt.SetFontSize(fFontSize);
484 } 227
485 FX_BOOL bMultiLine = (dwFlags >> 12) & 1; 228 FX_BOOL bMultiLine = (dwFlags >> 12) & 1;
486 if (bMultiLine) { 229 if (bMultiLine) {
487 vt.SetMultiLine(TRUE); 230 vt.SetMultiLine(TRUE);
488 vt.SetAutoReturn(TRUE); 231 vt.SetAutoReturn(TRUE);
489 } 232 }
490 uint16_t subWord = 0; 233 uint16_t subWord = 0;
491 if ((dwFlags >> 13) & 1) { 234 if ((dwFlags >> 13) & 1) {
492 subWord = '*'; 235 subWord = '*';
493 vt.SetPasswordChar(subWord); 236 vt.SetPasswordChar(subWord);
494 } 237 }
495 FX_BOOL bCharArray = (dwFlags >> 24) & 1; 238 FX_BOOL bCharArray = (dwFlags >> 24) & 1;
496 if (bCharArray) { 239 if (bCharArray)
497 vt.SetCharArray(dwMaxLen); 240 vt.SetCharArray(dwMaxLen);
498 } else { 241 else
499 vt.SetLimitChar(dwMaxLen); 242 vt.SetLimitChar(dwMaxLen);
500 } 243
501 vt.Initialize(); 244 vt.Initialize();
502 vt.SetText(swValue.c_str()); 245 vt.SetText(swValue.c_str());
503 vt.RearrangeAll(); 246 vt.RearrangeAll();
504 CFX_FloatRect rcContent = vt.GetContentRect(); 247 CFX_FloatRect rcContent = vt.GetContentRect();
505 CFX_FloatPoint ptOffset(0.0f, 0.0f); 248 CFX_FloatPoint ptOffset(0.0f, 0.0f);
506 if (!bMultiLine) { 249 if (!bMultiLine) {
507 ptOffset = 250 ptOffset =
508 CFX_FloatPoint(0.0f, (rcContent.Height() - rcBody.Height()) / 2.0f); 251 CFX_FloatPoint(0.0f, (rcContent.Height() - rcBody.Height()) / 2.0f);
509 } 252 }
510 CFX_ByteString sBody = CPVT_GenerateAP::GenerateEditAP( 253 CFX_ByteString sBody = CPVT_GenerateAP::GenerateEditAP(
(...skipping 10 matching lines...) Expand all
521 sAppStream << "BT\n" << CPVT_GenerateAP::GenerateColorAP(crText, TRUE) 264 sAppStream << "BT\n" << CPVT_GenerateAP::GenerateColorAP(crText, TRUE)
522 << sBody << "ET\n" 265 << sBody << "ET\n"
523 << "Q\nEMC\n"; 266 << "Q\nEMC\n";
524 } 267 }
525 } break; 268 } break;
526 case 1: { 269 case 1: {
527 CFX_WideString swValue = 270 CFX_WideString swValue =
528 FPDF_GetFieldAttr(pAnnotDict, "V") 271 FPDF_GetFieldAttr(pAnnotDict, "V")
529 ? FPDF_GetFieldAttr(pAnnotDict, "V")->GetUnicodeText() 272 ? FPDF_GetFieldAttr(pAnnotDict, "V")->GetUnicodeText()
530 : CFX_WideString(); 273 : CFX_WideString();
531 CPVT_FontMap map(pDoc, 274 CPVT_FontMap map(
532 pStreamDict ? pStreamDict->GetDictBy("Resources") : NULL, 275 pDoc, pStreamDict ? pStreamDict->GetDictBy("Resources") : nullptr,
533 pDefFont, sFontName.Right(sFontName.GetLength() - 1)); 276 pDefFont, sFontName.Right(sFontName.GetLength() - 1));
534 CPVT_Provider prd(&map); 277 CPVT_Provider prd(&map);
535 CPDF_VariableText vt; 278 CPDF_VariableText vt;
536 vt.SetProvider(&prd); 279 vt.SetProvider(&prd);
537 CFX_FloatRect rcButton = rcBody; 280 CFX_FloatRect rcButton = rcBody;
538 rcButton.left = rcButton.right - 13; 281 rcButton.left = rcButton.right - 13;
539 rcButton.Normalize(); 282 rcButton.Normalize();
540 CFX_FloatRect rcEdit = rcBody; 283 CFX_FloatRect rcEdit = rcBody;
541 rcEdit.right = rcButton.left; 284 rcEdit.right = rcButton.left;
542 rcEdit.Normalize(); 285 rcEdit.Normalize();
543 vt.SetPlateRect(rcEdit); 286 vt.SetPlateRect(rcEdit);
544 if (IsFloatZero(fFontSize)) { 287 if (IsFloatZero(fFontSize))
545 vt.SetAutoFontSize(TRUE); 288 vt.SetAutoFontSize(TRUE);
546 } else { 289 else
547 vt.SetFontSize(fFontSize); 290 vt.SetFontSize(fFontSize);
548 } 291
549 vt.Initialize(); 292 vt.Initialize();
550 vt.SetText(swValue.c_str()); 293 vt.SetText(swValue.c_str());
551 vt.RearrangeAll(); 294 vt.RearrangeAll();
552 CFX_FloatRect rcContent = vt.GetContentRect(); 295 CFX_FloatRect rcContent = vt.GetContentRect();
553 CFX_FloatPoint ptOffset = 296 CFX_FloatPoint ptOffset =
554 CFX_FloatPoint(0.0f, (rcContent.Height() - rcEdit.Height()) / 2.0f); 297 CFX_FloatPoint(0.0f, (rcContent.Height() - rcEdit.Height()) / 2.0f);
555 CFX_ByteString sEdit = CPVT_GenerateAP::GenerateEditAP( 298 CFX_ByteString sEdit = CPVT_GenerateAP::GenerateEditAP(
556 &map, vt.GetIterator(), ptOffset, TRUE, 0); 299 &map, vt.GetIterator(), ptOffset, TRUE, 0);
557 if (sEdit.GetLength() > 0) { 300 if (sEdit.GetLength() > 0) {
558 sAppStream << "/Tx BMC\n" 301 sAppStream << "/Tx BMC\n"
(...skipping 11 matching lines...) Expand all
570 if (sButton.GetLength() > 0 && !rcButton.IsEmpty()) { 313 if (sButton.GetLength() > 0 && !rcButton.IsEmpty()) {
571 sAppStream << "q\n" << sButton; 314 sAppStream << "q\n" << sButton;
572 sAppStream << rcButton.left << " " << rcButton.bottom << " " 315 sAppStream << rcButton.left << " " << rcButton.bottom << " "
573 << rcButton.Width() << " " << rcButton.Height() << " re f\n"; 316 << rcButton.Width() << " " << rcButton.Height() << " re f\n";
574 sAppStream << "Q\n"; 317 sAppStream << "Q\n";
575 CFX_ByteString sButtonBorder = CPVT_GenerateAP::GenerateBorderAP( 318 CFX_ByteString sButtonBorder = CPVT_GenerateAP::GenerateBorderAP(
576 rcButton, 2, CPVT_Color(CPVT_Color::kGray, 0), 319 rcButton, 2, CPVT_Color(CPVT_Color::kGray, 0),
577 CPVT_Color(CPVT_Color::kGray, 1), 320 CPVT_Color(CPVT_Color::kGray, 1),
578 CPVT_Color(CPVT_Color::kGray, 0.5), PBS_BEVELED, 321 CPVT_Color(CPVT_Color::kGray, 0.5), PBS_BEVELED,
579 CPVT_Dash(3, 0, 0)); 322 CPVT_Dash(3, 0, 0));
580 if (sButtonBorder.GetLength() > 0) { 323 if (sButtonBorder.GetLength() > 0)
581 sAppStream << "q\n" << sButtonBorder << "Q\n"; 324 sAppStream << "q\n" << sButtonBorder << "Q\n";
582 } 325
583 CFX_FloatPoint ptCenter = 326 CFX_FloatPoint ptCenter =
584 CFX_FloatPoint((rcButton.left + rcButton.right) / 2, 327 CFX_FloatPoint((rcButton.left + rcButton.right) / 2,
585 (rcButton.top + rcButton.bottom) / 2); 328 (rcButton.top + rcButton.bottom) / 2);
586 if (IsFloatBigger(rcButton.Width(), 6) && 329 if (IsFloatBigger(rcButton.Width(), 6) &&
587 IsFloatBigger(rcButton.Height(), 6)) { 330 IsFloatBigger(rcButton.Height(), 6)) {
588 sAppStream << "q\n" 331 sAppStream << "q\n"
589 << " 0 g\n"; 332 << " 0 g\n";
590 sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " m\n"; 333 sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " m\n";
591 sAppStream << ptCenter.x + 3 << " " << ptCenter.y + 1.5f << " l\n"; 334 sAppStream << ptCenter.x + 3 << " " << ptCenter.y + 1.5f << " l\n";
592 sAppStream << ptCenter.x << " " << ptCenter.y - 1.5f << " l\n"; 335 sAppStream << ptCenter.x << " " << ptCenter.y - 1.5f << " l\n";
593 sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " l f\n"; 336 sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " l f\n";
594 sAppStream << sButton << "Q\n"; 337 sAppStream << sButton << "Q\n";
595 } 338 }
596 } 339 }
597 } break; 340 } break;
598 case 2: { 341 case 2: {
599 CPVT_FontMap map(pDoc, 342 CPVT_FontMap map(
600 pStreamDict ? pStreamDict->GetDictBy("Resources") : NULL, 343 pDoc, pStreamDict ? pStreamDict->GetDictBy("Resources") : nullptr,
601 pDefFont, sFontName.Right(sFontName.GetLength() - 1)); 344 pDefFont, sFontName.Right(sFontName.GetLength() - 1));
602 CPVT_Provider prd(&map); 345 CPVT_Provider prd(&map);
603 CPDF_Array* pOpts = FPDF_GetFieldAttr(pAnnotDict, "Opt") 346 CPDF_Array* pOpts = FPDF_GetFieldAttr(pAnnotDict, "Opt")
604 ? FPDF_GetFieldAttr(pAnnotDict, "Opt")->GetArray() 347 ? FPDF_GetFieldAttr(pAnnotDict, "Opt")->GetArray()
605 : NULL; 348 : nullptr;
606 CPDF_Array* pSels = FPDF_GetFieldAttr(pAnnotDict, "I") 349 CPDF_Array* pSels = FPDF_GetFieldAttr(pAnnotDict, "I")
607 ? FPDF_GetFieldAttr(pAnnotDict, "I")->GetArray() 350 ? FPDF_GetFieldAttr(pAnnotDict, "I")->GetArray()
608 : NULL; 351 : nullptr;
609 int32_t nTop = FPDF_GetFieldAttr(pAnnotDict, "TI") 352 int32_t nTop = FPDF_GetFieldAttr(pAnnotDict, "TI")
610 ? FPDF_GetFieldAttr(pAnnotDict, "TI")->GetInteger() 353 ? FPDF_GetFieldAttr(pAnnotDict, "TI")->GetInteger()
611 : 0; 354 : 0;
612 CFX_ByteTextBuf sBody; 355 CFX_ByteTextBuf sBody;
613 if (pOpts) { 356 if (pOpts) {
614 FX_FLOAT fy = rcBody.top; 357 FX_FLOAT fy = rcBody.top;
615 for (int32_t i = nTop, sz = pOpts->GetCount(); i < sz; i++) { 358 for (int32_t i = nTop, sz = pOpts->GetCount(); i < sz; i++) {
616 if (IsFloatSmaller(fy, rcBody.bottom)) { 359 if (IsFloatSmaller(fy, rcBody.bottom))
617 break; 360 break;
618 } 361
619 if (CPDF_Object* pOpt = pOpts->GetDirectObjectAt(i)) { 362 if (CPDF_Object* pOpt = pOpts->GetDirectObjectAt(i)) {
620 CFX_WideString swItem; 363 CFX_WideString swItem;
621 if (pOpt->IsString()) 364 if (pOpt->IsString())
622 swItem = pOpt->GetUnicodeText(); 365 swItem = pOpt->GetUnicodeText();
623 else if (CPDF_Array* pArray = pOpt->AsArray()) 366 else if (CPDF_Array* pArray = pOpt->AsArray())
624 swItem = pArray->GetDirectObjectAt(1)->GetUnicodeText(); 367 swItem = pArray->GetDirectObjectAt(1)->GetUnicodeText();
625 368
626 FX_BOOL bSelected = FALSE; 369 FX_BOOL bSelected = FALSE;
627 if (pSels) { 370 if (pSels) {
628 for (uint32_t s = 0, ssz = pSels->GetCount(); s < ssz; s++) { 371 for (uint32_t s = 0, ssz = pSels->GetCount(); s < ssz; s++) {
629 if (i == pSels->GetIntegerAt(s)) { 372 if (i == pSels->GetIntegerAt(s)) {
630 bSelected = TRUE; 373 bSelected = TRUE;
631 break; 374 break;
632 } 375 }
633 } 376 }
634 } 377 }
635 CPDF_VariableText vt; 378 CPDF_VariableText vt;
636 vt.SetProvider(&prd); 379 vt.SetProvider(&prd);
637 vt.SetPlateRect( 380 vt.SetPlateRect(
638 CFX_FloatRect(rcBody.left, 0.0f, rcBody.right, 0.0f)); 381 CFX_FloatRect(rcBody.left, 0.0f, rcBody.right, 0.0f));
639 if (IsFloatZero(fFontSize)) { 382 vt.SetFontSize(IsFloatZero(fFontSize) ? 12.0f : fFontSize);
640 vt.SetFontSize(12.0f); 383
641 } else {
642 vt.SetFontSize(fFontSize);
643 }
644 vt.Initialize(); 384 vt.Initialize();
645 vt.SetText(swItem.c_str()); 385 vt.SetText(swItem.c_str());
646 vt.RearrangeAll(); 386 vt.RearrangeAll();
647 FX_FLOAT fItemHeight = vt.GetContentRect().Height(); 387 FX_FLOAT fItemHeight = vt.GetContentRect().Height();
648 if (bSelected) { 388 if (bSelected) {
649 CFX_FloatRect rcItem = CFX_FloatRect( 389 CFX_FloatRect rcItem = CFX_FloatRect(
650 rcBody.left, fy - fItemHeight, rcBody.right, fy); 390 rcBody.left, fy - fItemHeight, rcBody.right, fy);
651 sBody << "q\n" << CPVT_GenerateAP::GenerateColorAP( 391 sBody << "q\n" << CPVT_GenerateAP::GenerateColorAP(
652 CPVT_Color(CPVT_Color::kRGB, 0, 392 CPVT_Color(CPVT_Color::kRGB, 0,
653 51.0f / 255.0f, 113.0f / 255.0f), 393 51.0f / 255.0f, 113.0f / 255.0f),
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 if (pStreamDict) { 428 if (pStreamDict) {
689 pStreamDict->SetAtMatrix("Matrix", matrix); 429 pStreamDict->SetAtMatrix("Matrix", matrix);
690 pStreamDict->SetAtRect("BBox", rcBBox); 430 pStreamDict->SetAtRect("BBox", rcBBox);
691 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictBy("Resources"); 431 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictBy("Resources");
692 if (pStreamResList) { 432 if (pStreamResList) {
693 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictBy("Font"); 433 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictBy("Font");
694 if (!pStreamResFontList) { 434 if (!pStreamResFontList) {
695 pStreamResFontList = new CPDF_Dictionary; 435 pStreamResFontList = new CPDF_Dictionary;
696 pStreamResList->SetAt("Font", pStreamResFontList); 436 pStreamResList->SetAt("Font", pStreamResFontList);
697 } 437 }
698 if (!pStreamResFontList->KeyExist(sFontName)) { 438 if (!pStreamResFontList->KeyExist(sFontName))
699 pStreamResFontList->SetAtReference(sFontName, pDoc, pFontDict); 439 pStreamResFontList->SetAtReference(sFontName, pDoc, pFontDict);
700 }
701 } else { 440 } else {
702 pStreamDict->SetAt("Resources", pFormDict->GetDictBy("DR")->Clone()); 441 pStreamDict->SetAt("Resources", pFormDict->GetDictBy("DR")->Clone());
703 pStreamResList = pStreamDict->GetDictBy("Resources"); 442 pStreamResList = pStreamDict->GetDictBy("Resources");
704 } 443 }
705 } 444 }
706 } 445 }
707 return TRUE; 446 return TRUE;
708 } 447 }
448
449 } // namespace
450
451 FX_BOOL FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) {
452 if (!pAnnotDict || pAnnotDict->GetConstStringBy("Subtype") != "Widget") {
453 return FALSE;
454 }
455 CFX_ByteString field_type = FPDF_GetFieldAttr(pAnnotDict, "FT")->GetString();
456 uint32_t flags = FPDF_GetFieldAttr(pAnnotDict, "Ff")
457 ? FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteger()
458 : 0;
459 if (field_type == "Tx") {
460 return CPVT_GenerateAP::GenerateTextFieldAP(pDoc, pAnnotDict);
461 }
462 if (field_type == "Ch") {
463 return (flags & (1 << 17))
464 ? CPVT_GenerateAP::GenerateComboBoxAP(pDoc, pAnnotDict)
465 : CPVT_GenerateAP::GenerateListBoxAP(pDoc, pAnnotDict);
466 }
467 if (field_type == "Btn") {
468 if (!(flags & (1 << 16))) {
469 if (!pAnnotDict->KeyExist("AS")) {
470 if (CPDF_Dictionary* pParentDict = pAnnotDict->GetDictBy("Parent")) {
471 if (pParentDict->KeyExist("AS")) {
472 pAnnotDict->SetAtString("AS", pParentDict->GetStringBy("AS"));
473 }
474 }
475 }
476 }
477 }
478 return FALSE;
479 }
480
481 // Static.
709 FX_BOOL CPVT_GenerateAP::GenerateTextFieldAP(CPDF_Document* pDoc, 482 FX_BOOL CPVT_GenerateAP::GenerateTextFieldAP(CPDF_Document* pDoc,
710 CPDF_Dictionary* pAnnotDict) { 483 CPDF_Dictionary* pAnnotDict) {
711 return GenerateWidgetAP(pDoc, pAnnotDict, 0); 484 return GenerateWidgetAP(pDoc, pAnnotDict, 0);
712 } 485 }
486
487 // Static.
713 FX_BOOL CPVT_GenerateAP::GenerateComboBoxAP(CPDF_Document* pDoc, 488 FX_BOOL CPVT_GenerateAP::GenerateComboBoxAP(CPDF_Document* pDoc,
714 CPDF_Dictionary* pAnnotDict) { 489 CPDF_Dictionary* pAnnotDict) {
715 return GenerateWidgetAP(pDoc, pAnnotDict, 1); 490 return GenerateWidgetAP(pDoc, pAnnotDict, 1);
716 } 491 }
492
493 // Static.
717 FX_BOOL CPVT_GenerateAP::GenerateListBoxAP(CPDF_Document* pDoc, 494 FX_BOOL CPVT_GenerateAP::GenerateListBoxAP(CPDF_Document* pDoc,
718 CPDF_Dictionary* pAnnotDict) { 495 CPDF_Dictionary* pAnnotDict) {
719 return GenerateWidgetAP(pDoc, pAnnotDict, 2); 496 return GenerateWidgetAP(pDoc, pAnnotDict, 2);
720 } 497 }
498
499 // Static.
721 CFX_ByteString CPVT_GenerateAP::GenerateEditAP( 500 CFX_ByteString CPVT_GenerateAP::GenerateEditAP(
722 IPVT_FontMap* pFontMap, 501 IPVT_FontMap* pFontMap,
723 IPDF_VariableText_Iterator* pIterator, 502 IPDF_VariableText_Iterator* pIterator,
724 const CFX_FloatPoint& ptOffset, 503 const CFX_FloatPoint& ptOffset,
725 FX_BOOL bContinuous, 504 FX_BOOL bContinuous,
726 uint16_t SubWord, 505 uint16_t SubWord,
727 const CPVT_WordRange* pVisible) { 506 const CPVT_WordRange* pVisible) {
728 CFX_ByteTextBuf sEditStream, sLineStream, sWords; 507 CFX_ByteTextBuf sEditStream, sLineStream, sWords;
729 CFX_FloatPoint ptOld(0.0f, 0.0f), ptNew(0.0f, 0.0f); 508 CFX_FloatPoint ptOld(0.0f, 0.0f), ptNew(0.0f, 0.0f);
730 int32_t nCurFontIndex = -1; 509 int32_t nCurFontIndex = -1;
731 if (pIterator) { 510 if (pIterator) {
732 if (pVisible) { 511 if (pVisible)
733 pIterator->SetAt(pVisible->BeginPos); 512 pIterator->SetAt(pVisible->BeginPos);
734 } else { 513 else
735 pIterator->SetAt(0); 514 pIterator->SetAt(0);
736 } 515
737 CPVT_WordPlace oldplace; 516 CPVT_WordPlace oldplace;
738 while (pIterator->NextWord()) { 517 while (pIterator->NextWord()) {
739 CPVT_WordPlace place = pIterator->GetAt(); 518 CPVT_WordPlace place = pIterator->GetAt();
740 if (pVisible && place.WordCmp(pVisible->EndPos) > 0) { 519 if (pVisible && place.WordCmp(pVisible->EndPos) > 0)
741 break; 520 break;
742 } 521
743 if (bContinuous) { 522 if (bContinuous) {
744 if (place.LineCmp(oldplace) != 0) { 523 if (place.LineCmp(oldplace) != 0) {
745 if (sWords.GetSize() > 0) { 524 if (sWords.GetSize() > 0) {
746 sLineStream << GetWordRenderString(sWords.GetByteString()); 525 sLineStream << GetWordRenderString(sWords.GetByteString());
747 sEditStream << sLineStream; 526 sEditStream << sLineStream;
748 sLineStream.Clear(); 527 sLineStream.Clear();
749 sWords.Clear(); 528 sWords.Clear();
750 } 529 }
751 CPVT_Word word; 530 CPVT_Word word;
752 if (pIterator->GetWord(word)) { 531 if (pIterator->GetWord(word)) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 } 579 }
801 } 580 }
802 if (sWords.GetSize() > 0) { 581 if (sWords.GetSize() > 0) {
803 sLineStream << GetWordRenderString(sWords.GetByteString()); 582 sLineStream << GetWordRenderString(sWords.GetByteString());
804 sEditStream << sLineStream; 583 sEditStream << sLineStream;
805 sWords.Clear(); 584 sWords.Clear();
806 } 585 }
807 } 586 }
808 return sEditStream.GetByteString(); 587 return sEditStream.GetByteString();
809 } 588 }
589
590 // Static.
810 CFX_ByteString CPVT_GenerateAP::GenerateBorderAP( 591 CFX_ByteString CPVT_GenerateAP::GenerateBorderAP(
811 const CFX_FloatRect& rect, 592 const CFX_FloatRect& rect,
812 FX_FLOAT fWidth, 593 FX_FLOAT fWidth,
813 const CPVT_Color& color, 594 const CPVT_Color& color,
814 const CPVT_Color& crLeftTop, 595 const CPVT_Color& crLeftTop,
815 const CPVT_Color& crRightBottom, 596 const CPVT_Color& crRightBottom,
816 int32_t nStyle, 597 int32_t nStyle,
817 const CPVT_Dash& dash) { 598 const CPVT_Dash& dash) {
818 CFX_ByteTextBuf sAppStream; 599 CFX_ByteTextBuf sAppStream;
819 CFX_ByteString sColor; 600 CFX_ByteString sColor;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 sAppStream << sColor; 687 sAppStream << sColor;
907 sAppStream << fWidth << " w\n"; 688 sAppStream << fWidth << " w\n";
908 sAppStream << fLeft << " " << fBottom + fWidth / 2 << " m\n"; 689 sAppStream << fLeft << " " << fBottom + fWidth / 2 << " m\n";
909 sAppStream << fRight << " " << fBottom + fWidth / 2 << " l S\n"; 690 sAppStream << fRight << " " << fBottom + fWidth / 2 << " l S\n";
910 } 691 }
911 break; 692 break;
912 } 693 }
913 } 694 }
914 return sAppStream.GetByteString(); 695 return sAppStream.GetByteString();
915 } 696 }
697
698 // Static.
916 CFX_ByteString CPVT_GenerateAP::GenerateColorAP(const CPVT_Color& color, 699 CFX_ByteString CPVT_GenerateAP::GenerateColorAP(const CPVT_Color& color,
917 const FX_BOOL& bFillOrStroke) { 700 const FX_BOOL& bFillOrStroke) {
918 CFX_ByteTextBuf sColorStream; 701 CFX_ByteTextBuf sColorStream;
919 switch (color.nColorType) { 702 switch (color.nColorType) {
920 case CPVT_Color::kRGB: 703 case CPVT_Color::kRGB:
921 sColorStream << color.fColor1 << " " << color.fColor2 << " " 704 sColorStream << color.fColor1 << " " << color.fColor2 << " "
922 << color.fColor3 << " " << (bFillOrStroke ? "rg" : "RG") 705 << color.fColor3 << " " << (bFillOrStroke ? "rg" : "RG")
923 << "\n"; 706 << "\n";
924 break; 707 break;
925 case CPVT_Color::kGray: 708 case CPVT_Color::kGray:
926 sColorStream << color.fColor1 << " " << (bFillOrStroke ? "g" : "G") 709 sColorStream << color.fColor1 << " " << (bFillOrStroke ? "g" : "G")
927 << "\n"; 710 << "\n";
928 break; 711 break;
929 case CPVT_Color::kCMYK: 712 case CPVT_Color::kCMYK:
930 sColorStream << color.fColor1 << " " << color.fColor2 << " " 713 sColorStream << color.fColor1 << " " << color.fColor2 << " "
931 << color.fColor3 << " " << color.fColor4 << " " 714 << color.fColor3 << " " << color.fColor4 << " "
932 << (bFillOrStroke ? "k" : "K") << "\n"; 715 << (bFillOrStroke ? "k" : "K") << "\n";
933 break; 716 break;
934 case CPVT_Color::kTransparent: 717 case CPVT_Color::kTransparent:
935 break; 718 break;
936 } 719 }
937 return sColorStream.GetByteString(); 720 return sColorStream.GetByteString();
938 } 721 }
722
723 // Static.
724 CFX_ByteString CPVT_GenerateAP::GetPDFWordString(IPVT_FontMap* pFontMap,
725 int32_t nFontIndex,
726 uint16_t Word,
727 uint16_t SubWord) {
728 CFX_ByteString sWord;
729 if (SubWord > 0) {
730 sWord.Format("%c", SubWord);
731 return sWord;
732 }
733
734 if (!pFontMap)
735 return sWord;
736
737 if (CPDF_Font* pPDFFont = pFontMap->GetPDFFont(nFontIndex)) {
738 if (pPDFFont->GetBaseFont().Compare("Symbol") == 0 ||
739 pPDFFont->GetBaseFont().Compare("ZapfDingbats") == 0) {
740 sWord.Format("%c", Word);
741 } else {
742 uint32_t dwCharCode = pPDFFont->CharCodeFromUnicode(Word);
743 if (dwCharCode != CPDF_Font::kInvalidCharCode)
744 pPDFFont->AppendChar(sWord, dwCharCode);
745 }
746 }
747 return sWord;
748 }
749
750 // Static.
751 CFX_ByteString CPVT_GenerateAP::GetWordRenderString(
752 const CFX_ByteString& strWords) {
753 if (strWords.GetLength() > 0)
754 return PDF_EncodeString(strWords) + " Tj\n";
755 return "";
756 }
757
758 // Static.
759 CFX_ByteString CPVT_GenerateAP::GetFontSetString(IPVT_FontMap* pFontMap,
760 int32_t nFontIndex,
761 FX_FLOAT fFontSize) {
762 CFX_ByteTextBuf sRet;
763 if (pFontMap) {
764 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex);
765 if (sFontAlias.GetLength() > 0 && fFontSize > 0)
766 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n";
767 }
768 return sRet.GetByteString();
769 }
OLDNEW
« no previous file with comments | « core/fpdfdoc/cpvt_generateap.h ('k') | core/fpdfdoc/cpvt_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698