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

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

Issue 1634123004: War on #defines - part 2 (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Missing break 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
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
14 #define PBS_DASH 1
15 #define PBS_BEVELED 2
16 #define PBS_INSET 3
17 #define PBS_UNDERLINED 4
18
13 FX_BOOL FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) { 19 FX_BOOL FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) {
14 if (!pAnnotDict || pAnnotDict->GetConstString("Subtype") != "Widget") { 20 if (!pAnnotDict || pAnnotDict->GetConstString("Subtype") != "Widget") {
15 return FALSE; 21 return FALSE;
16 } 22 }
17 CFX_ByteString field_type = FPDF_GetFieldAttr(pAnnotDict, "FT")->GetString(); 23 CFX_ByteString field_type = FPDF_GetFieldAttr(pAnnotDict, "FT")->GetString();
18 FX_DWORD flags = FPDF_GetFieldAttr(pAnnotDict, "Ff") 24 FX_DWORD flags = FPDF_GetFieldAttr(pAnnotDict, "Ff")
19 ? FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteger() 25 ? FPDF_GetFieldAttr(pAnnotDict, "Ff")->GetInteger()
20 : 0; 26 : 0;
21 if (field_type == "Tx") { 27 if (field_type == "Tx") {
22 return CPVT_GenerateAP::GenerateTextFieldAP(pDoc, pAnnotDict); 28 return CPVT_GenerateAP::GenerateTextFieldAP(pDoc, pAnnotDict);
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 if (sFontAlias.GetLength() > 0 && fFontSize > 0) { 223 if (sFontAlias.GetLength() > 0 && fFontSize > 0) {
218 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; 224 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n";
219 } 225 }
220 } 226 }
221 return sRet.GetByteString(); 227 return sRet.GetByteString();
222 } 228 }
223 static CPVT_Color ParseColor(const CFX_ByteString& str) { 229 static CPVT_Color ParseColor(const CFX_ByteString& str) {
224 CPDF_SimpleParser syntax(str); 230 CPDF_SimpleParser syntax(str);
225 syntax.SetPos(0); 231 syntax.SetPos(0);
226 if (syntax.FindTagParam("g", 1)) { 232 if (syntax.FindTagParam("g", 1)) {
227 return CPVT_Color(CT_GRAY, FX_atof(syntax.GetWord())); 233 return CPVT_Color(CPVT_Color::GRAY, FX_atof(syntax.GetWord()));
228 } 234 }
229 syntax.SetPos(0); 235 syntax.SetPos(0);
230 if (syntax.FindTagParam("rg", 3)) { 236 if (syntax.FindTagParam("rg", 3)) {
231 FX_FLOAT f1 = FX_atof(syntax.GetWord()); 237 FX_FLOAT f1 = FX_atof(syntax.GetWord());
232 FX_FLOAT f2 = FX_atof(syntax.GetWord()); 238 FX_FLOAT f2 = FX_atof(syntax.GetWord());
233 FX_FLOAT f3 = FX_atof(syntax.GetWord()); 239 FX_FLOAT f3 = FX_atof(syntax.GetWord());
234 return CPVT_Color(CT_RGB, f1, f2, f3); 240 return CPVT_Color(CPVT_Color::RGB, f1, f2, f3);
235 } 241 }
236 syntax.SetPos(0); 242 syntax.SetPos(0);
237 if (syntax.FindTagParam("k", 4)) { 243 if (syntax.FindTagParam("k", 4)) {
238 FX_FLOAT f1 = FX_atof(syntax.GetWord()); 244 FX_FLOAT f1 = FX_atof(syntax.GetWord());
239 FX_FLOAT f2 = FX_atof(syntax.GetWord()); 245 FX_FLOAT f2 = FX_atof(syntax.GetWord());
240 FX_FLOAT f3 = FX_atof(syntax.GetWord()); 246 FX_FLOAT f3 = FX_atof(syntax.GetWord());
241 FX_FLOAT f4 = FX_atof(syntax.GetWord()); 247 FX_FLOAT f4 = FX_atof(syntax.GetWord());
242 return CPVT_Color(CT_CMYK, f1, f2, f3, f4); 248 return CPVT_Color(CPVT_Color::CMYK, f1, f2, f3, f4);
243 } 249 }
244 return CPVT_Color(CT_TRANSPARENT); 250 return CPVT_Color(CPVT_Color::TRANSPARENT);
245 } 251 }
246 static CPVT_Color ParseColor(const CPDF_Array& array) { 252 static CPVT_Color ParseColor(const CPDF_Array& array) {
247 CPVT_Color rt; 253 CPVT_Color rt;
248 switch (array.GetCount()) { 254 switch (array.GetCount()) {
249 case 1: 255 case 1:
250 rt = CPVT_Color(CT_GRAY, array.GetFloat(0)); 256 rt = CPVT_Color(CPVT_Color::GRAY, array.GetFloat(0));
251 break; 257 break;
252 case 3: 258 case 3:
253 rt = CPVT_Color(CT_RGB, array.GetFloat(0), array.GetFloat(1), 259 rt = CPVT_Color(CPVT_Color::RGB, array.GetFloat(0), array.GetFloat(1),
254 array.GetFloat(2)); 260 array.GetFloat(2));
255 break; 261 break;
256 case 4: 262 case 4:
257 rt = CPVT_Color(CT_CMYK, array.GetFloat(0), array.GetFloat(1), 263 rt = CPVT_Color(CPVT_Color::CMYK, array.GetFloat(0), array.GetFloat(1),
258 array.GetFloat(2), array.GetFloat(3)); 264 array.GetFloat(2), array.GetFloat(3));
259 break; 265 break;
260 } 266 }
261 return rt; 267 return rt;
262 } 268 }
263 static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, 269 static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc,
264 CPDF_Dictionary* pAnnotDict, 270 CPDF_Dictionary* pAnnotDict,
265 const int32_t& nWidgetType) { 271 const int32_t& nWidgetType) {
266 CPDF_Dictionary* pFormDict = NULL; 272 CPDF_Dictionary* pFormDict = NULL;
267 if (CPDF_Dictionary* pRootDict = pDoc->GetRoot()) { 273 if (CPDF_Dictionary* pRootDict = pDoc->GetRoot()) {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 switch (pBSDict->GetString("S").GetAt(0)) { 373 switch (pBSDict->GetString("S").GetAt(0)) {
368 case 'S': 374 case 'S':
369 nBorderStyle = PBS_SOLID; 375 nBorderStyle = PBS_SOLID;
370 break; 376 break;
371 case 'D': 377 case 'D':
372 nBorderStyle = PBS_DASH; 378 nBorderStyle = PBS_DASH;
373 break; 379 break;
374 case 'B': 380 case 'B':
375 nBorderStyle = PBS_BEVELED; 381 nBorderStyle = PBS_BEVELED;
376 fBorderWidth *= 2; 382 fBorderWidth *= 2;
377 crLeftTop = CPVT_Color(CT_GRAY, 1); 383 crLeftTop = CPVT_Color(CPVT_Color::GRAY, 1);
378 crRightBottom = CPVT_Color(CT_GRAY, 0.5); 384 crRightBottom = CPVT_Color(CPVT_Color::GRAY, 0.5);
379 break; 385 break;
380 case 'I': 386 case 'I':
381 nBorderStyle = PBS_INSET; 387 nBorderStyle = PBS_INSET;
382 fBorderWidth *= 2; 388 fBorderWidth *= 2;
383 crLeftTop = CPVT_Color(CT_GRAY, 0.5); 389 crLeftTop = CPVT_Color(CPVT_Color::GRAY, 0.5);
384 crRightBottom = CPVT_Color(CT_GRAY, 0.75); 390 crRightBottom = CPVT_Color(CPVT_Color::GRAY, 0.75);
385 break; 391 break;
386 case 'U': 392 case 'U':
387 nBorderStyle = PBS_UNDERLINED; 393 nBorderStyle = PBS_UNDERLINED;
388 break; 394 break;
389 } 395 }
390 } 396 }
391 CPVT_Color crBorder, crBG; 397 CPVT_Color crBorder, crBG;
392 if (CPDF_Dictionary* pMKDict = pAnnotDict->GetDict("MK")) { 398 if (CPDF_Dictionary* pMKDict = pAnnotDict->GetDict("MK")) {
393 if (CPDF_Array* pArray = pMKDict->GetArray("BC")) { 399 if (CPDF_Array* pArray = pMKDict->GetArray("BC")) {
394 crBorder = ParseColor(*pArray); 400 crBorder = ParseColor(*pArray);
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 if (sEdit.GetLength() > 0) { 554 if (sEdit.GetLength() > 0) {
549 sAppStream << "/Tx BMC\n" 555 sAppStream << "/Tx BMC\n"
550 << "q\n"; 556 << "q\n";
551 sAppStream << rcEdit.left << " " << rcEdit.bottom << " " 557 sAppStream << rcEdit.left << " " << rcEdit.bottom << " "
552 << rcEdit.Width() << " " << rcEdit.Height() << " re\nW\nn\n"; 558 << rcEdit.Width() << " " << rcEdit.Height() << " re\nW\nn\n";
553 sAppStream << "BT\n" << CPVT_GenerateAP::GenerateColorAP(crText, TRUE) 559 sAppStream << "BT\n" << CPVT_GenerateAP::GenerateColorAP(crText, TRUE)
554 << sEdit << "ET\n" 560 << sEdit << "ET\n"
555 << "Q\nEMC\n"; 561 << "Q\nEMC\n";
556 } 562 }
557 CFX_ByteString sButton = CPVT_GenerateAP::GenerateColorAP( 563 CFX_ByteString sButton = CPVT_GenerateAP::GenerateColorAP(
558 CPVT_Color(CT_RGB, 220.0f / 255.0f, 220.0f / 255.0f, 220.0f / 255.0f), 564 CPVT_Color(CPVT_Color::RGB, 220.0f / 255.0f, 220.0f / 255.0f,
565 220.0f / 255.0f),
559 TRUE); 566 TRUE);
560 if (sButton.GetLength() > 0 && !rcButton.IsEmpty()) { 567 if (sButton.GetLength() > 0 && !rcButton.IsEmpty()) {
561 sAppStream << "q\n" << sButton; 568 sAppStream << "q\n" << sButton;
562 sAppStream << rcButton.left << " " << rcButton.bottom << " " 569 sAppStream << rcButton.left << " " << rcButton.bottom << " "
563 << rcButton.Width() << " " << rcButton.Height() << " re f\n"; 570 << rcButton.Width() << " " << rcButton.Height() << " re f\n";
564 sAppStream << "Q\n"; 571 sAppStream << "Q\n";
565 CFX_ByteString sButtonBorder = CPVT_GenerateAP::GenerateBorderAP( 572 CFX_ByteString sButtonBorder = CPVT_GenerateAP::GenerateBorderAP(
566 rcButton, 2, CPVT_Color(CT_GRAY, 0), CPVT_Color(CT_GRAY, 1), 573 rcButton, 2, CPVT_Color(CPVT_Color::GRAY, 0),
567 CPVT_Color(CT_GRAY, 0.5), PBS_BEVELED, CPVT_Dash(3, 0, 0)); 574 CPVT_Color(CPVT_Color::GRAY, 1), CPVT_Color(CPVT_Color::GRAY, 0.5),
575 PBS_BEVELED, CPVT_Dash(3, 0, 0));
568 if (sButtonBorder.GetLength() > 0) { 576 if (sButtonBorder.GetLength() > 0) {
569 sAppStream << "q\n" << sButtonBorder << "Q\n"; 577 sAppStream << "q\n" << sButtonBorder << "Q\n";
570 } 578 }
571 CPDF_Point ptCenter = CPDF_Point((rcButton.left + rcButton.right) / 2, 579 CPDF_Point ptCenter = CPDF_Point((rcButton.left + rcButton.right) / 2,
572 (rcButton.top + rcButton.bottom) / 2); 580 (rcButton.top + rcButton.bottom) / 2);
573 if (IsFloatBigger(rcButton.Width(), 6) && 581 if (IsFloatBigger(rcButton.Width(), 6) &&
574 IsFloatBigger(rcButton.Height(), 6)) { 582 IsFloatBigger(rcButton.Height(), 6)) {
575 sAppStream << "q\n" 583 sAppStream << "q\n"
576 << " 0 g\n"; 584 << " 0 g\n";
577 sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " m\n"; 585 sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " m\n";
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 vt.SetFontSize(fFontSize); 636 vt.SetFontSize(fFontSize);
629 } 637 }
630 vt.Initialize(); 638 vt.Initialize();
631 vt.SetText(swItem.c_str()); 639 vt.SetText(swItem.c_str());
632 vt.RearrangeAll(); 640 vt.RearrangeAll();
633 FX_FLOAT fItemHeight = vt.GetContentRect().Height(); 641 FX_FLOAT fItemHeight = vt.GetContentRect().Height();
634 if (bSelected) { 642 if (bSelected) {
635 CPDF_Rect rcItem = 643 CPDF_Rect rcItem =
636 CPDF_Rect(rcBody.left, fy - fItemHeight, rcBody.right, fy); 644 CPDF_Rect(rcBody.left, fy - fItemHeight, rcBody.right, fy);
637 sBody << "q\n" << CPVT_GenerateAP::GenerateColorAP( 645 sBody << "q\n" << CPVT_GenerateAP::GenerateColorAP(
638 CPVT_Color(CT_RGB, 0, 51.0f / 255.0f, 646 CPVT_Color(CPVT_Color::RGB, 0,
639 113.0f / 255.0f), 647 51.0f / 255.0f, 113.0f / 255.0f),
640 TRUE) 648 TRUE)
641 << rcItem.left << " " << rcItem.bottom << " " 649 << rcItem.left << " " << rcItem.bottom << " "
642 << rcItem.Width() << " " << rcItem.Height() << " re f\n" 650 << rcItem.Width() << " " << rcItem.Height() << " re f\n"
643 << "Q\n"; 651 << "Q\n";
644 sBody << "BT\n" << CPVT_GenerateAP::GenerateColorAP( 652 sBody << "BT\n" << CPVT_GenerateAP::GenerateColorAP(
645 CPVT_Color(CT_GRAY, 1), TRUE) 653 CPVT_Color(CPVT_Color::GRAY, 1), TRUE)
646 << CPVT_GenerateAP::GenerateEditAP(&map, vt.GetIterator(), 654 << CPVT_GenerateAP::GenerateEditAP(&map, vt.GetIterator(),
647 CPDF_Point(0.0f, fy), 655 CPDF_Point(0.0f, fy),
648 TRUE, 0) 656 TRUE, 0)
649 << "ET\n"; 657 << "ET\n";
650 } else { 658 } else {
651 sBody << "BT\n" << CPVT_GenerateAP::GenerateColorAP(crText, TRUE) 659 sBody << "BT\n" << CPVT_GenerateAP::GenerateColorAP(crText, TRUE)
652 << CPVT_GenerateAP::GenerateEditAP(&map, vt.GetIterator(), 660 << CPVT_GenerateAP::GenerateEditAP(&map, vt.GetIterator(),
653 CPDF_Point(0.0f, fy), 661 CPDF_Point(0.0f, fy),
654 TRUE, 0) 662 TRUE, 0)
655 << "ET\n"; 663 << "ET\n";
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 } 904 }
897 break; 905 break;
898 } 906 }
899 } 907 }
900 return sAppStream.GetByteString(); 908 return sAppStream.GetByteString();
901 } 909 }
902 CFX_ByteString CPVT_GenerateAP::GenerateColorAP(const CPVT_Color& color, 910 CFX_ByteString CPVT_GenerateAP::GenerateColorAP(const CPVT_Color& color,
903 const FX_BOOL& bFillOrStroke) { 911 const FX_BOOL& bFillOrStroke) {
904 CFX_ByteTextBuf sColorStream; 912 CFX_ByteTextBuf sColorStream;
905 switch (color.nColorType) { 913 switch (color.nColorType) {
906 case CT_RGB: 914 case CPVT_Color::RGB:
907 sColorStream << color.fColor1 << " " << color.fColor2 << " " 915 sColorStream << color.fColor1 << " " << color.fColor2 << " "
908 << color.fColor3 << " " << (bFillOrStroke ? "rg" : "RG") 916 << color.fColor3 << " " << (bFillOrStroke ? "rg" : "RG")
909 << "\n"; 917 << "\n";
910 break; 918 break;
911 case CT_GRAY: 919 case CPVT_Color::GRAY:
912 sColorStream << color.fColor1 << " " << (bFillOrStroke ? "g" : "G") 920 sColorStream << color.fColor1 << " " << (bFillOrStroke ? "g" : "G")
913 << "\n"; 921 << "\n";
914 break; 922 break;
915 case CT_CMYK: 923 case CPVT_Color::CMYK:
916 sColorStream << color.fColor1 << " " << color.fColor2 << " " 924 sColorStream << color.fColor1 << " " << color.fColor2 << " "
917 << color.fColor3 << " " << color.fColor4 << " " 925 << color.fColor3 << " " << color.fColor4 << " "
918 << (bFillOrStroke ? "k" : "K") << "\n"; 926 << (bFillOrStroke ? "k" : "K") << "\n";
919 break; 927 break;
928 case CPVT_Color::TRANSPARENT:
929 break;
920 } 930 }
921 return sColorStream.GetByteString(); 931 return sColorStream.GetByteString();
922 } 932 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698