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

Side by Side Diff: core/src/fpdfdoc/doc_ap.cpp

Issue 1648233002: Merge to XFA: Member function name refactoring (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: more xfa changes Created 4 years, 10 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/src/fpdfdoc/doc_annot.cpp ('k') | core/src/fpdfdoc/doc_basic.cpp » ('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 2014 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/include/fpdfdoc/fpdf_ap.h" 7 #include "core/include/fpdfdoc/fpdf_ap.h"
8 #include "core/include/fpdfdoc/fpdf_doc.h" 8 #include "core/include/fpdfdoc/fpdf_doc.h"
9 #include "core/include/fpdfdoc/fpdf_vt.h" 9 #include "core/include/fpdfdoc/fpdf_vt.h"
10 #include "doc_utils.h" 10 #include "doc_utils.h"
11 #include "pdf_vt.h" 11 #include "pdf_vt.h"
12 12
13 #define PBS_SOLID 0 13 #define PBS_SOLID 0
14 #define PBS_DASH 1 14 #define PBS_DASH 1
15 #define PBS_BEVELED 2 15 #define PBS_BEVELED 2
16 #define PBS_INSET 3 16 #define PBS_INSET 3
17 #define PBS_UNDERLINED 4 17 #define PBS_UNDERLINED 4
18 18
19 FX_BOOL FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) { 19 FX_BOOL FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) {
20 if (!pAnnotDict || pAnnotDict->GetConstString("Subtype") != "Widget") { 20 if (!pAnnotDict || pAnnotDict->GetConstStringBy("Subtype") != "Widget") {
21 return FALSE; 21 return FALSE;
22 } 22 }
23 CFX_ByteString field_type = FPDF_GetFieldAttr(pAnnotDict, "FT")->GetString(); 23 CFX_ByteString field_type = FPDF_GetFieldAttr(pAnnotDict, "FT")->GetString();
24 FX_DWORD flags = FPDF_GetFieldAttr(pAnnotDict, "Ff") 24 FX_DWORD flags = FPDF_GetFieldAttr(pAnnotDict, "Ff")
25 ? FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteger() 25 ? FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteger()
26 : 0; 26 : 0;
27 if (field_type == "Tx") { 27 if (field_type == "Tx") {
28 return CPVT_GenerateAP::GenerateTextFieldAP(pDoc, pAnnotDict); 28 return CPVT_GenerateAP::GenerateTextFieldAP(pDoc, pAnnotDict);
29 } 29 }
30 if (field_type == "Ch") { 30 if (field_type == "Ch") {
31 return (flags & (1 << 17)) 31 return (flags & (1 << 17))
32 ? CPVT_GenerateAP::GenerateComboBoxAP(pDoc, pAnnotDict) 32 ? CPVT_GenerateAP::GenerateComboBoxAP(pDoc, pAnnotDict)
33 : CPVT_GenerateAP::GenerateListBoxAP(pDoc, pAnnotDict); 33 : CPVT_GenerateAP::GenerateListBoxAP(pDoc, pAnnotDict);
34 } 34 }
35 if (field_type == "Btn") { 35 if (field_type == "Btn") {
36 if (!(flags & (1 << 16))) { 36 if (!(flags & (1 << 16))) {
37 if (!pAnnotDict->KeyExist("AS")) { 37 if (!pAnnotDict->KeyExist("AS")) {
38 if (CPDF_Dictionary* pParentDict = pAnnotDict->GetDict("Parent")) { 38 if (CPDF_Dictionary* pParentDict = pAnnotDict->GetDictBy("Parent")) {
39 if (pParentDict->KeyExist("AS")) { 39 if (pParentDict->KeyExist("AS")) {
40 pAnnotDict->SetAtString("AS", pParentDict->GetString("AS")); 40 pAnnotDict->SetAtString("AS", pParentDict->GetStringBy("AS"));
41 } 41 }
42 } 42 }
43 } 43 }
44 } 44 }
45 } 45 }
46 return FALSE; 46 return FALSE;
47 } 47 }
48 48
49 class CPVT_FontMap : public IPVT_FontMap { 49 class CPVT_FontMap : public IPVT_FontMap {
50 public: 50 public:
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 m_sDefFontAlias(sDefFontAlias), 82 m_sDefFontAlias(sDefFontAlias),
83 m_pSysFont(NULL), 83 m_pSysFont(NULL),
84 m_sSysFontAlias() {} 84 m_sSysFontAlias() {}
85 CPVT_FontMap::~CPVT_FontMap() {} 85 CPVT_FontMap::~CPVT_FontMap() {}
86 void CPVT_FontMap::GetAnnotSysPDFFont(CPDF_Document* pDoc, 86 void CPVT_FontMap::GetAnnotSysPDFFont(CPDF_Document* pDoc,
87 CPDF_Dictionary* pResDict, 87 CPDF_Dictionary* pResDict,
88 CPDF_Font*& pSysFont, 88 CPDF_Font*& pSysFont,
89 CFX_ByteString& sSysFontAlias) { 89 CFX_ByteString& sSysFontAlias) {
90 if (pDoc && pResDict) { 90 if (pDoc && pResDict) {
91 CFX_ByteString sFontAlias; 91 CFX_ByteString sFontAlias;
92 CPDF_Dictionary* pFormDict = pDoc->GetRoot()->GetDict("AcroForm"); 92 CPDF_Dictionary* pFormDict = pDoc->GetRoot()->GetDictBy("AcroForm");
93 if (CPDF_Font* pPDFFont = 93 if (CPDF_Font* pPDFFont =
94 AddNativeInterFormFont(pFormDict, pDoc, sSysFontAlias)) { 94 AddNativeInterFormFont(pFormDict, pDoc, sSysFontAlias)) {
95 if (CPDF_Dictionary* pFontList = pResDict->GetDict("Font")) { 95 if (CPDF_Dictionary* pFontList = pResDict->GetDictBy("Font")) {
96 if (!pFontList->KeyExist(sSysFontAlias)) { 96 if (!pFontList->KeyExist(sSysFontAlias)) {
97 pFontList->SetAtReference(sSysFontAlias, pDoc, 97 pFontList->SetAtReference(sSysFontAlias, pDoc,
98 pPDFFont->GetFontDict()); 98 pPDFFont->GetFontDict());
99 } 99 }
100 } 100 }
101 pSysFont = pPDFFont; 101 pSysFont = pPDFFont;
102 } 102 }
103 } 103 }
104 } 104 }
105 CPDF_Font* CPVT_FontMap::GetPDFFont(int32_t nFontIndex) { 105 CPDF_Font* CPVT_FontMap::GetPDFFont(int32_t nFontIndex) {
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 FX_FLOAT f3 = FX_atof(syntax.GetWord()); 246 FX_FLOAT f3 = FX_atof(syntax.GetWord());
247 FX_FLOAT f4 = FX_atof(syntax.GetWord()); 247 FX_FLOAT f4 = FX_atof(syntax.GetWord());
248 return CPVT_Color(CPVT_Color::kCMYK, f1, f2, f3, f4); 248 return CPVT_Color(CPVT_Color::kCMYK, f1, f2, f3, f4);
249 } 249 }
250 return CPVT_Color(CPVT_Color::kTransparent); 250 return CPVT_Color(CPVT_Color::kTransparent);
251 } 251 }
252 static CPVT_Color ParseColor(const CPDF_Array& array) { 252 static CPVT_Color ParseColor(const CPDF_Array& array) {
253 CPVT_Color rt; 253 CPVT_Color rt;
254 switch (array.GetCount()) { 254 switch (array.GetCount()) {
255 case 1: 255 case 1:
256 rt = CPVT_Color(CPVT_Color::kGray, array.GetFloat(0)); 256 rt = CPVT_Color(CPVT_Color::kGray, array.GetFloatAt(0));
257 break; 257 break;
258 case 3: 258 case 3:
259 rt = CPVT_Color(CPVT_Color::kRGB, array.GetFloat(0), array.GetFloat(1), 259 rt = CPVT_Color(CPVT_Color::kRGB, array.GetFloatAt(0),
260 array.GetFloat(2)); 260 array.GetFloatAt(1), array.GetFloatAt(2));
261 break; 261 break;
262 case 4: 262 case 4:
263 rt = CPVT_Color(CPVT_Color::kCMYK, array.GetFloat(0), array.GetFloat(1), 263 rt = CPVT_Color(CPVT_Color::kCMYK, array.GetFloatAt(0),
264 array.GetFloat(2), array.GetFloat(3)); 264 array.GetFloatAt(1), array.GetFloatAt(2),
265 array.GetFloatAt(3));
265 break; 266 break;
266 } 267 }
267 return rt; 268 return rt;
268 } 269 }
269 static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, 270 static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc,
270 CPDF_Dictionary* pAnnotDict, 271 CPDF_Dictionary* pAnnotDict,
271 const int32_t& nWidgetType) { 272 const int32_t& nWidgetType) {
272 CPDF_Dictionary* pFormDict = NULL; 273 CPDF_Dictionary* pFormDict = NULL;
273 if (CPDF_Dictionary* pRootDict = pDoc->GetRoot()) { 274 if (CPDF_Dictionary* pRootDict = pDoc->GetRoot()) {
274 pFormDict = pRootDict->GetDict("AcroForm"); 275 pFormDict = pRootDict->GetDictBy("AcroForm");
275 } 276 }
276 if (!pFormDict) { 277 if (!pFormDict) {
277 return FALSE; 278 return FALSE;
278 } 279 }
279 CFX_ByteString DA; 280 CFX_ByteString DA;
280 if (CPDF_Object* pDAObj = FPDF_GetFieldAttr(pAnnotDict, "DA")) { 281 if (CPDF_Object* pDAObj = FPDF_GetFieldAttr(pAnnotDict, "DA")) {
281 DA = pDAObj->GetString(); 282 DA = pDAObj->GetString();
282 } 283 }
283 if (DA.IsEmpty()) { 284 if (DA.IsEmpty()) {
284 DA = pFormDict->GetString("DA"); 285 DA = pFormDict->GetStringBy("DA");
285 } 286 }
286 if (DA.IsEmpty()) { 287 if (DA.IsEmpty()) {
287 return FALSE; 288 return FALSE;
288 } 289 }
289 CPDF_SimpleParser syntax(DA); 290 CPDF_SimpleParser syntax(DA);
290 syntax.FindTagParam("Tf", 2); 291 syntax.FindTagParam("Tf", 2);
291 CFX_ByteString sFontName = syntax.GetWord(); 292 CFX_ByteString sFontName = syntax.GetWord();
292 sFontName = PDF_NameDecode(sFontName); 293 sFontName = PDF_NameDecode(sFontName);
293 if (sFontName.IsEmpty()) { 294 if (sFontName.IsEmpty()) {
294 return FALSE; 295 return FALSE;
295 } 296 }
296 FX_FLOAT fFontSize = FX_atof(syntax.GetWord()); 297 FX_FLOAT fFontSize = FX_atof(syntax.GetWord());
297 CPVT_Color crText = ParseColor(DA); 298 CPVT_Color crText = ParseColor(DA);
298 FX_BOOL bUseFormRes = FALSE; 299 FX_BOOL bUseFormRes = FALSE;
299 CPDF_Dictionary* pFontDict = NULL; 300 CPDF_Dictionary* pFontDict = NULL;
300 CPDF_Dictionary* pDRDict = pAnnotDict->GetDict("DR"); 301 CPDF_Dictionary* pDRDict = pAnnotDict->GetDictBy("DR");
301 if (!pDRDict) { 302 if (!pDRDict) {
302 pDRDict = pFormDict->GetDict("DR"); 303 pDRDict = pFormDict->GetDictBy("DR");
303 bUseFormRes = TRUE; 304 bUseFormRes = TRUE;
304 } 305 }
305 CPDF_Dictionary* pDRFontDict = NULL; 306 CPDF_Dictionary* pDRFontDict = NULL;
306 if (pDRDict && (pDRFontDict = pDRDict->GetDict("Font"))) { 307 if (pDRDict && (pDRFontDict = pDRDict->GetDictBy("Font"))) {
307 pFontDict = pDRFontDict->GetDict(sFontName.Mid(1)); 308 pFontDict = pDRFontDict->GetDictBy(sFontName.Mid(1));
308 if (!pFontDict && !bUseFormRes) { 309 if (!pFontDict && !bUseFormRes) {
309 pDRDict = pFormDict->GetDict("DR"); 310 pDRDict = pFormDict->GetDictBy("DR");
310 pDRFontDict = pDRDict->GetDict("Font"); 311 pDRFontDict = pDRDict->GetDictBy("Font");
311 if (pDRFontDict) { 312 if (pDRFontDict) {
312 pFontDict = pDRFontDict->GetDict(sFontName.Mid(1)); 313 pFontDict = pDRFontDict->GetDictBy(sFontName.Mid(1));
313 } 314 }
314 } 315 }
315 } 316 }
316 if (!pDRFontDict) { 317 if (!pDRFontDict) {
317 return FALSE; 318 return FALSE;
318 } 319 }
319 if (!pFontDict) { 320 if (!pFontDict) {
320 pFontDict = new CPDF_Dictionary; 321 pFontDict = new CPDF_Dictionary;
321 pFontDict->SetAtName("Type", "Font"); 322 pFontDict->SetAtName("Type", "Font");
322 pFontDict->SetAtName("Subtype", "Type1"); 323 pFontDict->SetAtName("Subtype", "Type1");
323 pFontDict->SetAtName("BaseFont", "Helvetica"); 324 pFontDict->SetAtName("BaseFont", "Helvetica");
324 pFontDict->SetAtName("Encoding", "WinAnsiEncoding"); 325 pFontDict->SetAtName("Encoding", "WinAnsiEncoding");
325 pDoc->AddIndirectObject(pFontDict); 326 pDoc->AddIndirectObject(pFontDict);
326 pDRFontDict->SetAtReference(sFontName.Mid(1), pDoc, pFontDict); 327 pDRFontDict->SetAtReference(sFontName.Mid(1), pDoc, pFontDict);
327 } 328 }
328 CPDF_Font* pDefFont = pDoc->LoadFont(pFontDict); 329 CPDF_Font* pDefFont = pDoc->LoadFont(pFontDict);
329 if (!pDefFont) { 330 if (!pDefFont) {
330 return FALSE; 331 return FALSE;
331 } 332 }
332 CPDF_Rect rcAnnot = pAnnotDict->GetRect("Rect"); 333 CPDF_Rect rcAnnot = pAnnotDict->GetRectBy("Rect");
333 int32_t nRotate = 0; 334 int32_t nRotate = 0;
334 if (CPDF_Dictionary* pMKDict = pAnnotDict->GetDict("MK")) { 335 if (CPDF_Dictionary* pMKDict = pAnnotDict->GetDictBy("MK")) {
335 nRotate = pMKDict->GetInteger("R"); 336 nRotate = pMKDict->GetIntegerBy("R");
336 } 337 }
337 CPDF_Rect rcBBox; 338 CPDF_Rect rcBBox;
338 CFX_Matrix matrix; 339 CFX_Matrix matrix;
339 switch (nRotate % 360) { 340 switch (nRotate % 360) {
340 case 0: 341 case 0:
341 rcBBox = CPDF_Rect(0, 0, rcAnnot.right - rcAnnot.left, 342 rcBBox = CPDF_Rect(0, 0, rcAnnot.right - rcAnnot.left,
342 rcAnnot.top - rcAnnot.bottom); 343 rcAnnot.top - rcAnnot.bottom);
343 break; 344 break;
344 case 90: 345 case 90:
345 matrix = CFX_Matrix(0, 1, -1, 0, rcAnnot.right - rcAnnot.left, 0); 346 matrix = CFX_Matrix(0, 1, -1, 0, rcAnnot.right - rcAnnot.left, 0);
346 rcBBox = CPDF_Rect(0, 0, rcAnnot.top - rcAnnot.bottom, 347 rcBBox = CPDF_Rect(0, 0, rcAnnot.top - rcAnnot.bottom,
347 rcAnnot.right - rcAnnot.left); 348 rcAnnot.right - rcAnnot.left);
348 break; 349 break;
349 case 180: 350 case 180:
350 matrix = CFX_Matrix(-1, 0, 0, -1, rcAnnot.right - rcAnnot.left, 351 matrix = CFX_Matrix(-1, 0, 0, -1, rcAnnot.right - rcAnnot.left,
351 rcAnnot.top - rcAnnot.bottom); 352 rcAnnot.top - rcAnnot.bottom);
352 rcBBox = CPDF_Rect(0, 0, rcAnnot.right - rcAnnot.left, 353 rcBBox = CPDF_Rect(0, 0, rcAnnot.right - rcAnnot.left,
353 rcAnnot.top - rcAnnot.bottom); 354 rcAnnot.top - rcAnnot.bottom);
354 break; 355 break;
355 case 270: 356 case 270:
356 matrix = CFX_Matrix(0, -1, 1, 0, 0, rcAnnot.top - rcAnnot.bottom); 357 matrix = CFX_Matrix(0, -1, 1, 0, 0, rcAnnot.top - rcAnnot.bottom);
357 rcBBox = CPDF_Rect(0, 0, rcAnnot.top - rcAnnot.bottom, 358 rcBBox = CPDF_Rect(0, 0, rcAnnot.top - rcAnnot.bottom,
358 rcAnnot.right - rcAnnot.left); 359 rcAnnot.right - rcAnnot.left);
359 break; 360 break;
360 } 361 }
361 int32_t nBorderStyle = PBS_SOLID; 362 int32_t nBorderStyle = PBS_SOLID;
362 FX_FLOAT fBorderWidth = 1; 363 FX_FLOAT fBorderWidth = 1;
363 CPVT_Dash dsBorder(3, 0, 0); 364 CPVT_Dash dsBorder(3, 0, 0);
364 CPVT_Color crLeftTop, crRightBottom; 365 CPVT_Color crLeftTop, crRightBottom;
365 if (CPDF_Dictionary* pBSDict = pAnnotDict->GetDict("BS")) { 366 if (CPDF_Dictionary* pBSDict = pAnnotDict->GetDictBy("BS")) {
366 if (pBSDict->KeyExist("W")) { 367 if (pBSDict->KeyExist("W")) {
367 fBorderWidth = pBSDict->GetNumber("W"); 368 fBorderWidth = pBSDict->GetNumberBy("W");
368 } 369 }
369 if (CPDF_Array* pArray = pBSDict->GetArray("D")) { 370 if (CPDF_Array* pArray = pBSDict->GetArrayBy("D")) {
370 dsBorder = CPVT_Dash(pArray->GetInteger(0), pArray->GetInteger(1), 371 dsBorder = CPVT_Dash(pArray->GetIntegerAt(0), pArray->GetIntegerAt(1),
371 pArray->GetInteger(2)); 372 pArray->GetIntegerAt(2));
372 } 373 }
373 switch (pBSDict->GetString("S").GetAt(0)) { 374 switch (pBSDict->GetStringBy("S").GetAt(0)) {
374 case 'S': 375 case 'S':
375 nBorderStyle = PBS_SOLID; 376 nBorderStyle = PBS_SOLID;
376 break; 377 break;
377 case 'D': 378 case 'D':
378 nBorderStyle = PBS_DASH; 379 nBorderStyle = PBS_DASH;
379 break; 380 break;
380 case 'B': 381 case 'B':
381 nBorderStyle = PBS_BEVELED; 382 nBorderStyle = PBS_BEVELED;
382 fBorderWidth *= 2; 383 fBorderWidth *= 2;
383 crLeftTop = CPVT_Color(CPVT_Color::kGray, 1); 384 crLeftTop = CPVT_Color(CPVT_Color::kGray, 1);
384 crRightBottom = CPVT_Color(CPVT_Color::kGray, 0.5); 385 crRightBottom = CPVT_Color(CPVT_Color::kGray, 0.5);
385 break; 386 break;
386 case 'I': 387 case 'I':
387 nBorderStyle = PBS_INSET; 388 nBorderStyle = PBS_INSET;
388 fBorderWidth *= 2; 389 fBorderWidth *= 2;
389 crLeftTop = CPVT_Color(CPVT_Color::kGray, 0.5); 390 crLeftTop = CPVT_Color(CPVT_Color::kGray, 0.5);
390 crRightBottom = CPVT_Color(CPVT_Color::kGray, 0.75); 391 crRightBottom = CPVT_Color(CPVT_Color::kGray, 0.75);
391 break; 392 break;
392 case 'U': 393 case 'U':
393 nBorderStyle = PBS_UNDERLINED; 394 nBorderStyle = PBS_UNDERLINED;
394 break; 395 break;
395 } 396 }
396 } 397 }
397 CPVT_Color crBorder, crBG; 398 CPVT_Color crBorder, crBG;
398 if (CPDF_Dictionary* pMKDict = pAnnotDict->GetDict("MK")) { 399 if (CPDF_Dictionary* pMKDict = pAnnotDict->GetDictBy("MK")) {
399 if (CPDF_Array* pArray = pMKDict->GetArray("BC")) { 400 if (CPDF_Array* pArray = pMKDict->GetArrayBy("BC")) {
400 crBorder = ParseColor(*pArray); 401 crBorder = ParseColor(*pArray);
401 } 402 }
402 if (CPDF_Array* pArray = pMKDict->GetArray("BG")) { 403 if (CPDF_Array* pArray = pMKDict->GetArrayBy("BG")) {
403 crBG = ParseColor(*pArray); 404 crBG = ParseColor(*pArray);
404 } 405 }
405 } 406 }
406 CFX_ByteTextBuf sAppStream; 407 CFX_ByteTextBuf sAppStream;
407 CFX_ByteString sBG = CPVT_GenerateAP::GenerateColorAP(crBG, TRUE); 408 CFX_ByteString sBG = CPVT_GenerateAP::GenerateColorAP(crBG, TRUE);
408 if (sBG.GetLength() > 0) { 409 if (sBG.GetLength() > 0) {
409 sAppStream << "q\n" << sBG << rcBBox.left << " " << rcBBox.bottom << " " 410 sAppStream << "q\n" << sBG << rcBBox.left << " " << rcBBox.bottom << " "
410 << rcBBox.Width() << " " << rcBBox.Height() << " re f\n" 411 << rcBBox.Width() << " " << rcBBox.Height() << " re f\n"
411 << "Q\n"; 412 << "Q\n";
412 } 413 }
413 CFX_ByteString sBorderStream = CPVT_GenerateAP::GenerateBorderAP( 414 CFX_ByteString sBorderStream = CPVT_GenerateAP::GenerateBorderAP(
414 rcBBox, fBorderWidth, crBorder, crLeftTop, crRightBottom, nBorderStyle, 415 rcBBox, fBorderWidth, crBorder, crLeftTop, crRightBottom, nBorderStyle,
415 dsBorder); 416 dsBorder);
416 if (sBorderStream.GetLength() > 0) { 417 if (sBorderStream.GetLength() > 0) {
417 sAppStream << "q\n" << sBorderStream << "Q\n"; 418 sAppStream << "q\n" << sBorderStream << "Q\n";
418 } 419 }
419 CPDF_Rect rcBody = 420 CPDF_Rect rcBody =
420 CPDF_Rect(rcBBox.left + fBorderWidth, rcBBox.bottom + fBorderWidth, 421 CPDF_Rect(rcBBox.left + fBorderWidth, rcBBox.bottom + fBorderWidth,
421 rcBBox.right - fBorderWidth, rcBBox.top - fBorderWidth); 422 rcBBox.right - fBorderWidth, rcBBox.top - fBorderWidth);
422 rcBody.Normalize(); 423 rcBody.Normalize();
423 CPDF_Dictionary* pAPDict = pAnnotDict->GetDict("AP"); 424 CPDF_Dictionary* pAPDict = pAnnotDict->GetDictBy("AP");
424 if (!pAPDict) { 425 if (!pAPDict) {
425 pAPDict = new CPDF_Dictionary; 426 pAPDict = new CPDF_Dictionary;
426 pAnnotDict->SetAt("AP", pAPDict); 427 pAnnotDict->SetAt("AP", pAPDict);
427 } 428 }
428 CPDF_Stream* pNormalStream = pAPDict->GetStream("N"); 429 CPDF_Stream* pNormalStream = pAPDict->GetStreamBy("N");
429 if (!pNormalStream) { 430 if (!pNormalStream) {
430 pNormalStream = new CPDF_Stream(nullptr, 0, nullptr); 431 pNormalStream = new CPDF_Stream(nullptr, 0, nullptr);
431 int32_t objnum = pDoc->AddIndirectObject(pNormalStream); 432 int32_t objnum = pDoc->AddIndirectObject(pNormalStream);
432 pAnnotDict->GetDict("AP")->SetAtReference("N", pDoc, objnum); 433 pAnnotDict->GetDictBy("AP")->SetAtReference("N", pDoc, objnum);
433 } 434 }
434 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); 435 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict();
435 if (pStreamDict) { 436 if (pStreamDict) {
436 pStreamDict->SetAtMatrix("Matrix", matrix); 437 pStreamDict->SetAtMatrix("Matrix", matrix);
437 pStreamDict->SetAtRect("BBox", rcBBox); 438 pStreamDict->SetAtRect("BBox", rcBBox);
438 CPDF_Dictionary* pStreamResList = pStreamDict->GetDict("Resources"); 439 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictBy("Resources");
439 if (pStreamResList) { 440 if (pStreamResList) {
440 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDict("Font"); 441 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictBy("Font");
441 if (!pStreamResFontList) { 442 if (!pStreamResFontList) {
442 pStreamResFontList = new CPDF_Dictionary; 443 pStreamResFontList = new CPDF_Dictionary;
443 pStreamResList->SetAt("Font", pStreamResFontList); 444 pStreamResList->SetAt("Font", pStreamResFontList);
444 } 445 }
445 if (!pStreamResFontList->KeyExist(sFontName)) { 446 if (!pStreamResFontList->KeyExist(sFontName)) {
446 pStreamResFontList->SetAtReference(sFontName, pDoc, pFontDict); 447 pStreamResFontList->SetAtReference(sFontName, pDoc, pFontDict);
447 } 448 }
448 } else { 449 } else {
449 pStreamDict->SetAt("Resources", pFormDict->GetDict("DR")->Clone()); 450 pStreamDict->SetAt("Resources", pFormDict->GetDictBy("DR")->Clone());
450 pStreamResList = pStreamDict->GetDict("Resources"); 451 pStreamResList = pStreamDict->GetDictBy("Resources");
451 } 452 }
452 } 453 }
453 switch (nWidgetType) { 454 switch (nWidgetType) {
454 case 0: { 455 case 0: {
455 CFX_WideString swValue = 456 CFX_WideString swValue =
456 FPDF_GetFieldAttr(pAnnotDict, "V") 457 FPDF_GetFieldAttr(pAnnotDict, "V")
457 ? FPDF_GetFieldAttr(pAnnotDict, "V")->GetUnicodeText() 458 ? FPDF_GetFieldAttr(pAnnotDict, "V")->GetUnicodeText()
458 : CFX_WideString(); 459 : CFX_WideString();
459 int32_t nAlign = FPDF_GetFieldAttr(pAnnotDict, "Q") 460 int32_t nAlign = FPDF_GetFieldAttr(pAnnotDict, "Q")
460 ? FPDF_GetFieldAttr(pAnnotDict, "Q")->GetInteger() 461 ? FPDF_GetFieldAttr(pAnnotDict, "Q")->GetInteger()
461 : 0; 462 : 0;
462 FX_DWORD dwFlags = FPDF_GetFieldAttr(pAnnotDict, "Ff") 463 FX_DWORD dwFlags = FPDF_GetFieldAttr(pAnnotDict, "Ff")
463 ? FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteger() 464 ? FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteger()
464 : 0; 465 : 0;
465 FX_DWORD dwMaxLen = 466 FX_DWORD dwMaxLen =
466 FPDF_GetFieldAttr(pAnnotDict, "MaxLen") 467 FPDF_GetFieldAttr(pAnnotDict, "MaxLen")
467 ? FPDF_GetFieldAttr(pAnnotDict, "MaxLen")->GetInteger() 468 ? FPDF_GetFieldAttr(pAnnotDict, "MaxLen")->GetInteger()
468 : 0; 469 : 0;
469 CPVT_FontMap map(pDoc, 470 CPVT_FontMap map(pDoc,
470 pStreamDict ? pStreamDict->GetDict("Resources") : NULL, 471 pStreamDict ? pStreamDict->GetDictBy("Resources") : NULL,
471 pDefFont, sFontName.Right(sFontName.GetLength() - 1)); 472 pDefFont, sFontName.Right(sFontName.GetLength() - 1));
472 CPVT_Provider prd(&map); 473 CPVT_Provider prd(&map);
473 CPDF_VariableText vt; 474 CPDF_VariableText vt;
474 vt.SetProvider(&prd); 475 vt.SetProvider(&prd);
475 vt.SetPlateRect(rcBody); 476 vt.SetPlateRect(rcBody);
476 vt.SetAlignment(nAlign); 477 vt.SetAlignment(nAlign);
477 if (IsFloatZero(fFontSize)) { 478 if (IsFloatZero(fFontSize)) {
478 vt.SetAutoFontSize(TRUE); 479 vt.SetAutoFontSize(TRUE);
479 } else { 480 } else {
480 vt.SetFontSize(fFontSize); 481 vt.SetFontSize(fFontSize);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 << sBody << "ET\n" 520 << sBody << "ET\n"
520 << "Q\nEMC\n"; 521 << "Q\nEMC\n";
521 } 522 }
522 } break; 523 } break;
523 case 1: { 524 case 1: {
524 CFX_WideString swValue = 525 CFX_WideString swValue =
525 FPDF_GetFieldAttr(pAnnotDict, "V") 526 FPDF_GetFieldAttr(pAnnotDict, "V")
526 ? FPDF_GetFieldAttr(pAnnotDict, "V")->GetUnicodeText() 527 ? FPDF_GetFieldAttr(pAnnotDict, "V")->GetUnicodeText()
527 : CFX_WideString(); 528 : CFX_WideString();
528 CPVT_FontMap map(pDoc, 529 CPVT_FontMap map(pDoc,
529 pStreamDict ? pStreamDict->GetDict("Resources") : NULL, 530 pStreamDict ? pStreamDict->GetDictBy("Resources") : NULL,
530 pDefFont, sFontName.Right(sFontName.GetLength() - 1)); 531 pDefFont, sFontName.Right(sFontName.GetLength() - 1));
531 CPVT_Provider prd(&map); 532 CPVT_Provider prd(&map);
532 CPDF_VariableText vt; 533 CPDF_VariableText vt;
533 vt.SetProvider(&prd); 534 vt.SetProvider(&prd);
534 CPDF_Rect rcButton = rcBody; 535 CPDF_Rect rcButton = rcBody;
535 rcButton.left = rcButton.right - 13; 536 rcButton.left = rcButton.right - 13;
536 rcButton.Normalize(); 537 rcButton.Normalize();
537 CPDF_Rect rcEdit = rcBody; 538 CPDF_Rect rcEdit = rcBody;
538 rcEdit.right = rcButton.left; 539 rcEdit.right = rcButton.left;
539 rcEdit.Normalize(); 540 rcEdit.Normalize();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " m\n"; 587 sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " m\n";
587 sAppStream << ptCenter.x + 3 << " " << ptCenter.y + 1.5f << " l\n"; 588 sAppStream << ptCenter.x + 3 << " " << ptCenter.y + 1.5f << " l\n";
588 sAppStream << ptCenter.x << " " << ptCenter.y - 1.5f << " l\n"; 589 sAppStream << ptCenter.x << " " << ptCenter.y - 1.5f << " l\n";
589 sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " l f\n"; 590 sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " l f\n";
590 sAppStream << sButton << "Q\n"; 591 sAppStream << sButton << "Q\n";
591 } 592 }
592 } 593 }
593 } break; 594 } break;
594 case 2: { 595 case 2: {
595 CPVT_FontMap map(pDoc, 596 CPVT_FontMap map(pDoc,
596 pStreamDict ? pStreamDict->GetDict("Resources") : NULL, 597 pStreamDict ? pStreamDict->GetDictBy("Resources") : NULL,
597 pDefFont, sFontName.Right(sFontName.GetLength() - 1)); 598 pDefFont, sFontName.Right(sFontName.GetLength() - 1));
598 CPVT_Provider prd(&map); 599 CPVT_Provider prd(&map);
599 CPDF_Array* pOpts = FPDF_GetFieldAttr(pAnnotDict, "Opt") 600 CPDF_Array* pOpts = FPDF_GetFieldAttr(pAnnotDict, "Opt")
600 ? FPDF_GetFieldAttr(pAnnotDict, "Opt")->GetArray() 601 ? FPDF_GetFieldAttr(pAnnotDict, "Opt")->GetArray()
601 : NULL; 602 : NULL;
602 CPDF_Array* pSels = FPDF_GetFieldAttr(pAnnotDict, "I") 603 CPDF_Array* pSels = FPDF_GetFieldAttr(pAnnotDict, "I")
603 ? FPDF_GetFieldAttr(pAnnotDict, "I")->GetArray() 604 ? FPDF_GetFieldAttr(pAnnotDict, "I")->GetArray()
604 : NULL; 605 : NULL;
605 int32_t nTop = FPDF_GetFieldAttr(pAnnotDict, "TI") 606 int32_t nTop = FPDF_GetFieldAttr(pAnnotDict, "TI")
606 ? FPDF_GetFieldAttr(pAnnotDict, "TI")->GetInteger() 607 ? FPDF_GetFieldAttr(pAnnotDict, "TI")->GetInteger()
607 : 0; 608 : 0;
608 CFX_ByteTextBuf sBody; 609 CFX_ByteTextBuf sBody;
609 if (pOpts) { 610 if (pOpts) {
610 FX_FLOAT fy = rcBody.top; 611 FX_FLOAT fy = rcBody.top;
611 for (int32_t i = nTop, sz = pOpts->GetCount(); i < sz; i++) { 612 for (int32_t i = nTop, sz = pOpts->GetCount(); i < sz; i++) {
612 if (IsFloatSmaller(fy, rcBody.bottom)) { 613 if (IsFloatSmaller(fy, rcBody.bottom)) {
613 break; 614 break;
614 } 615 }
615 if (CPDF_Object* pOpt = pOpts->GetElementValue(i)) { 616 if (CPDF_Object* pOpt = pOpts->GetElementValue(i)) {
616 CFX_WideString swItem; 617 CFX_WideString swItem;
617 if (pOpt->IsString()) 618 if (pOpt->IsString())
618 swItem = pOpt->GetUnicodeText(); 619 swItem = pOpt->GetUnicodeText();
619 else if (CPDF_Array* pArray = pOpt->AsArray()) 620 else if (CPDF_Array* pArray = pOpt->AsArray())
620 swItem = pArray->GetElementValue(1)->GetUnicodeText(); 621 swItem = pArray->GetElementValue(1)->GetUnicodeText();
621 622
622 FX_BOOL bSelected = FALSE; 623 FX_BOOL bSelected = FALSE;
623 if (pSels) { 624 if (pSels) {
624 for (FX_DWORD s = 0, ssz = pSels->GetCount(); s < ssz; s++) { 625 for (FX_DWORD s = 0, ssz = pSels->GetCount(); s < ssz; s++) {
625 if (i == pSels->GetInteger(s)) { 626 if (i == pSels->GetIntegerAt(s)) {
626 bSelected = TRUE; 627 bSelected = TRUE;
627 break; 628 break;
628 } 629 }
629 } 630 }
630 } 631 }
631 CPDF_VariableText vt; 632 CPDF_VariableText vt;
632 vt.SetProvider(&prd); 633 vt.SetProvider(&prd);
633 vt.SetPlateRect(CPDF_Rect(rcBody.left, 0.0f, rcBody.right, 0.0f)); 634 vt.SetPlateRect(CPDF_Rect(rcBody.left, 0.0f, rcBody.right, 0.0f));
634 if (IsFloatZero(fFontSize)) { 635 if (IsFloatZero(fFontSize)) {
635 vt.SetFontSize(12.0f); 636 vt.SetFontSize(12.0f);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 } 677 }
677 } break; 678 } break;
678 } 679 }
679 if (pNormalStream) { 680 if (pNormalStream) {
680 pNormalStream->SetData((uint8_t*)sAppStream.GetBuffer(), 681 pNormalStream->SetData((uint8_t*)sAppStream.GetBuffer(),
681 sAppStream.GetSize(), FALSE, FALSE); 682 sAppStream.GetSize(), FALSE, FALSE);
682 pStreamDict = pNormalStream->GetDict(); 683 pStreamDict = pNormalStream->GetDict();
683 if (pStreamDict) { 684 if (pStreamDict) {
684 pStreamDict->SetAtMatrix("Matrix", matrix); 685 pStreamDict->SetAtMatrix("Matrix", matrix);
685 pStreamDict->SetAtRect("BBox", rcBBox); 686 pStreamDict->SetAtRect("BBox", rcBBox);
686 CPDF_Dictionary* pStreamResList = pStreamDict->GetDict("Resources"); 687 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictBy("Resources");
687 if (pStreamResList) { 688 if (pStreamResList) {
688 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDict("Font"); 689 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictBy("Font");
689 if (!pStreamResFontList) { 690 if (!pStreamResFontList) {
690 pStreamResFontList = new CPDF_Dictionary; 691 pStreamResFontList = new CPDF_Dictionary;
691 pStreamResList->SetAt("Font", pStreamResFontList); 692 pStreamResList->SetAt("Font", pStreamResFontList);
692 } 693 }
693 if (!pStreamResFontList->KeyExist(sFontName)) { 694 if (!pStreamResFontList->KeyExist(sFontName)) {
694 pStreamResFontList->SetAtReference(sFontName, pDoc, pFontDict); 695 pStreamResFontList->SetAtReference(sFontName, pDoc, pFontDict);
695 } 696 }
696 } else { 697 } else {
697 pStreamDict->SetAt("Resources", pFormDict->GetDict("DR")->Clone()); 698 pStreamDict->SetAt("Resources", pFormDict->GetDictBy("DR")->Clone());
698 pStreamResList = pStreamDict->GetDict("Resources"); 699 pStreamResList = pStreamDict->GetDictBy("Resources");
699 } 700 }
700 } 701 }
701 } 702 }
702 return TRUE; 703 return TRUE;
703 } 704 }
704 FX_BOOL CPVT_GenerateAP::GenerateTextFieldAP(CPDF_Document* pDoc, 705 FX_BOOL CPVT_GenerateAP::GenerateTextFieldAP(CPDF_Document* pDoc,
705 CPDF_Dictionary* pAnnotDict) { 706 CPDF_Dictionary* pAnnotDict) {
706 return GenerateWidgetAP(pDoc, pAnnotDict, 0); 707 return GenerateWidgetAP(pDoc, pAnnotDict, 0);
707 } 708 }
708 FX_BOOL CPVT_GenerateAP::GenerateComboBoxAP(CPDF_Document* pDoc, 709 FX_BOOL CPVT_GenerateAP::GenerateComboBoxAP(CPDF_Document* pDoc,
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 case CPVT_Color::kCMYK: 925 case CPVT_Color::kCMYK:
925 sColorStream << color.fColor1 << " " << color.fColor2 << " " 926 sColorStream << color.fColor1 << " " << color.fColor2 << " "
926 << color.fColor3 << " " << color.fColor4 << " " 927 << color.fColor3 << " " << color.fColor4 << " "
927 << (bFillOrStroke ? "k" : "K") << "\n"; 928 << (bFillOrStroke ? "k" : "K") << "\n";
928 break; 929 break;
929 case CPVT_Color::kTransparent: 930 case CPVT_Color::kTransparent:
930 break; 931 break;
931 } 932 }
932 return sColorStream.GetByteString(); 933 return sColorStream.GetByteString();
933 } 934 }
OLDNEW
« no previous file with comments | « core/src/fpdfdoc/doc_annot.cpp ('k') | core/src/fpdfdoc/doc_basic.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698