OLD | NEW |
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" |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 if (sFontAlias.GetLength() > 0 && fFontSize > 0) { | 223 if (sFontAlias.GetLength() > 0 && fFontSize > 0) { |
224 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; | 224 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; |
225 } | 225 } |
226 } | 226 } |
227 return sRet.GetByteString(); | 227 return sRet.GetByteString(); |
228 } | 228 } |
229 static CPVT_Color ParseColor(const CFX_ByteString& str) { | 229 static CPVT_Color ParseColor(const CFX_ByteString& str) { |
230 CPDF_SimpleParser syntax(str); | 230 CPDF_SimpleParser syntax(str); |
231 syntax.SetPos(0); | 231 syntax.SetPos(0); |
232 if (syntax.FindTagParam("g", 1)) { | 232 if (syntax.FindTagParam("g", 1)) { |
233 return CPVT_Color(CPVT_Color::GRAY, FX_atof(syntax.GetWord())); | 233 return CPVT_Color(CPVT_Color::kGray, FX_atof(syntax.GetWord())); |
234 } | 234 } |
235 syntax.SetPos(0); | 235 syntax.SetPos(0); |
236 if (syntax.FindTagParam("rg", 3)) { | 236 if (syntax.FindTagParam("rg", 3)) { |
237 FX_FLOAT f1 = FX_atof(syntax.GetWord()); | 237 FX_FLOAT f1 = FX_atof(syntax.GetWord()); |
238 FX_FLOAT f2 = FX_atof(syntax.GetWord()); | 238 FX_FLOAT f2 = FX_atof(syntax.GetWord()); |
239 FX_FLOAT f3 = FX_atof(syntax.GetWord()); | 239 FX_FLOAT f3 = FX_atof(syntax.GetWord()); |
240 return CPVT_Color(CPVT_Color::RGB, f1, f2, f3); | 240 return CPVT_Color(CPVT_Color::kRGB, f1, f2, f3); |
241 } | 241 } |
242 syntax.SetPos(0); | 242 syntax.SetPos(0); |
243 if (syntax.FindTagParam("k", 4)) { | 243 if (syntax.FindTagParam("k", 4)) { |
244 FX_FLOAT f1 = FX_atof(syntax.GetWord()); | 244 FX_FLOAT f1 = FX_atof(syntax.GetWord()); |
245 FX_FLOAT f2 = FX_atof(syntax.GetWord()); | 245 FX_FLOAT f2 = FX_atof(syntax.GetWord()); |
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::CMYK, f1, f2, f3, f4); | 248 return CPVT_Color(CPVT_Color::kCMYK, f1, f2, f3, f4); |
249 } | 249 } |
250 return CPVT_Color(CPVT_Color::TRANSPARENT); | 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::GRAY, array.GetFloat(0)); | 256 rt = CPVT_Color(CPVT_Color::kGray, array.GetFloat(0)); |
257 break; | 257 break; |
258 case 3: | 258 case 3: |
259 rt = CPVT_Color(CPVT_Color::RGB, array.GetFloat(0), array.GetFloat(1), | 259 rt = CPVT_Color(CPVT_Color::kRGB, array.GetFloat(0), array.GetFloat(1), |
260 array.GetFloat(2)); | 260 array.GetFloat(2)); |
261 break; | 261 break; |
262 case 4: | 262 case 4: |
263 rt = CPVT_Color(CPVT_Color::CMYK, array.GetFloat(0), array.GetFloat(1), | 263 rt = CPVT_Color(CPVT_Color::kCMYK, array.GetFloat(0), array.GetFloat(1), |
264 array.GetFloat(2), array.GetFloat(3)); | 264 array.GetFloat(2), array.GetFloat(3)); |
265 break; | 265 break; |
266 } | 266 } |
267 return rt; | 267 return rt; |
268 } | 268 } |
269 static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, | 269 static FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc, |
270 CPDF_Dictionary* pAnnotDict, | 270 CPDF_Dictionary* pAnnotDict, |
271 const int32_t& nWidgetType) { | 271 const int32_t& nWidgetType) { |
272 CPDF_Dictionary* pFormDict = NULL; | 272 CPDF_Dictionary* pFormDict = NULL; |
273 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 Loading... |
373 switch (pBSDict->GetString("S").GetAt(0)) { | 373 switch (pBSDict->GetString("S").GetAt(0)) { |
374 case 'S': | 374 case 'S': |
375 nBorderStyle = PBS_SOLID; | 375 nBorderStyle = PBS_SOLID; |
376 break; | 376 break; |
377 case 'D': | 377 case 'D': |
378 nBorderStyle = PBS_DASH; | 378 nBorderStyle = PBS_DASH; |
379 break; | 379 break; |
380 case 'B': | 380 case 'B': |
381 nBorderStyle = PBS_BEVELED; | 381 nBorderStyle = PBS_BEVELED; |
382 fBorderWidth *= 2; | 382 fBorderWidth *= 2; |
383 crLeftTop = CPVT_Color(CPVT_Color::GRAY, 1); | 383 crLeftTop = CPVT_Color(CPVT_Color::kGray, 1); |
384 crRightBottom = CPVT_Color(CPVT_Color::GRAY, 0.5); | 384 crRightBottom = CPVT_Color(CPVT_Color::kGray, 0.5); |
385 break; | 385 break; |
386 case 'I': | 386 case 'I': |
387 nBorderStyle = PBS_INSET; | 387 nBorderStyle = PBS_INSET; |
388 fBorderWidth *= 2; | 388 fBorderWidth *= 2; |
389 crLeftTop = CPVT_Color(CPVT_Color::GRAY, 0.5); | 389 crLeftTop = CPVT_Color(CPVT_Color::kGray, 0.5); |
390 crRightBottom = CPVT_Color(CPVT_Color::GRAY, 0.75); | 390 crRightBottom = CPVT_Color(CPVT_Color::kGray, 0.75); |
391 break; | 391 break; |
392 case 'U': | 392 case 'U': |
393 nBorderStyle = PBS_UNDERLINED; | 393 nBorderStyle = PBS_UNDERLINED; |
394 break; | 394 break; |
395 } | 395 } |
396 } | 396 } |
397 CPVT_Color crBorder, crBG; | 397 CPVT_Color crBorder, crBG; |
398 if (CPDF_Dictionary* pMKDict = pAnnotDict->GetDict("MK")) { | 398 if (CPDF_Dictionary* pMKDict = pAnnotDict->GetDict("MK")) { |
399 if (CPDF_Array* pArray = pMKDict->GetArray("BC")) { | 399 if (CPDF_Array* pArray = pMKDict->GetArray("BC")) { |
400 crBorder = ParseColor(*pArray); | 400 crBorder = ParseColor(*pArray); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 if (sEdit.GetLength() > 0) { | 554 if (sEdit.GetLength() > 0) { |
555 sAppStream << "/Tx BMC\n" | 555 sAppStream << "/Tx BMC\n" |
556 << "q\n"; | 556 << "q\n"; |
557 sAppStream << rcEdit.left << " " << rcEdit.bottom << " " | 557 sAppStream << rcEdit.left << " " << rcEdit.bottom << " " |
558 << rcEdit.Width() << " " << rcEdit.Height() << " re\nW\nn\n"; | 558 << rcEdit.Width() << " " << rcEdit.Height() << " re\nW\nn\n"; |
559 sAppStream << "BT\n" << CPVT_GenerateAP::GenerateColorAP(crText, TRUE) | 559 sAppStream << "BT\n" << CPVT_GenerateAP::GenerateColorAP(crText, TRUE) |
560 << sEdit << "ET\n" | 560 << sEdit << "ET\n" |
561 << "Q\nEMC\n"; | 561 << "Q\nEMC\n"; |
562 } | 562 } |
563 CFX_ByteString sButton = CPVT_GenerateAP::GenerateColorAP( | 563 CFX_ByteString sButton = CPVT_GenerateAP::GenerateColorAP( |
564 CPVT_Color(CPVT_Color::RGB, 220.0f / 255.0f, 220.0f / 255.0f, | 564 CPVT_Color(CPVT_Color::kRGB, 220.0f / 255.0f, 220.0f / 255.0f, |
565 220.0f / 255.0f), | 565 220.0f / 255.0f), |
566 TRUE); | 566 TRUE); |
567 if (sButton.GetLength() > 0 && !rcButton.IsEmpty()) { | 567 if (sButton.GetLength() > 0 && !rcButton.IsEmpty()) { |
568 sAppStream << "q\n" << sButton; | 568 sAppStream << "q\n" << sButton; |
569 sAppStream << rcButton.left << " " << rcButton.bottom << " " | 569 sAppStream << rcButton.left << " " << rcButton.bottom << " " |
570 << rcButton.Width() << " " << rcButton.Height() << " re f\n"; | 570 << rcButton.Width() << " " << rcButton.Height() << " re f\n"; |
571 sAppStream << "Q\n"; | 571 sAppStream << "Q\n"; |
572 CFX_ByteString sButtonBorder = CPVT_GenerateAP::GenerateBorderAP( | 572 CFX_ByteString sButtonBorder = CPVT_GenerateAP::GenerateBorderAP( |
573 rcButton, 2, CPVT_Color(CPVT_Color::GRAY, 0), | 573 rcButton, 2, CPVT_Color(CPVT_Color::kGray, 0), |
574 CPVT_Color(CPVT_Color::GRAY, 1), CPVT_Color(CPVT_Color::GRAY, 0.5), | 574 CPVT_Color(CPVT_Color::kGray, 1), |
575 PBS_BEVELED, CPVT_Dash(3, 0, 0)); | 575 CPVT_Color(CPVT_Color::kGray, 0.5), PBS_BEVELED, |
| 576 CPVT_Dash(3, 0, 0)); |
576 if (sButtonBorder.GetLength() > 0) { | 577 if (sButtonBorder.GetLength() > 0) { |
577 sAppStream << "q\n" << sButtonBorder << "Q\n"; | 578 sAppStream << "q\n" << sButtonBorder << "Q\n"; |
578 } | 579 } |
579 CPDF_Point ptCenter = CPDF_Point((rcButton.left + rcButton.right) / 2, | 580 CPDF_Point ptCenter = CPDF_Point((rcButton.left + rcButton.right) / 2, |
580 (rcButton.top + rcButton.bottom) / 2); | 581 (rcButton.top + rcButton.bottom) / 2); |
581 if (IsFloatBigger(rcButton.Width(), 6) && | 582 if (IsFloatBigger(rcButton.Width(), 6) && |
582 IsFloatBigger(rcButton.Height(), 6)) { | 583 IsFloatBigger(rcButton.Height(), 6)) { |
583 sAppStream << "q\n" | 584 sAppStream << "q\n" |
584 << " 0 g\n"; | 585 << " 0 g\n"; |
585 sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " m\n"; | 586 sAppStream << ptCenter.x - 3 << " " << ptCenter.y + 1.5f << " m\n"; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 vt.SetFontSize(fFontSize); | 637 vt.SetFontSize(fFontSize); |
637 } | 638 } |
638 vt.Initialize(); | 639 vt.Initialize(); |
639 vt.SetText(swItem.c_str()); | 640 vt.SetText(swItem.c_str()); |
640 vt.RearrangeAll(); | 641 vt.RearrangeAll(); |
641 FX_FLOAT fItemHeight = vt.GetContentRect().Height(); | 642 FX_FLOAT fItemHeight = vt.GetContentRect().Height(); |
642 if (bSelected) { | 643 if (bSelected) { |
643 CPDF_Rect rcItem = | 644 CPDF_Rect rcItem = |
644 CPDF_Rect(rcBody.left, fy - fItemHeight, rcBody.right, fy); | 645 CPDF_Rect(rcBody.left, fy - fItemHeight, rcBody.right, fy); |
645 sBody << "q\n" << CPVT_GenerateAP::GenerateColorAP( | 646 sBody << "q\n" << CPVT_GenerateAP::GenerateColorAP( |
646 CPVT_Color(CPVT_Color::RGB, 0, | 647 CPVT_Color(CPVT_Color::kRGB, 0, |
647 51.0f / 255.0f, 113.0f / 255.0f), | 648 51.0f / 255.0f, 113.0f / 255.0f), |
648 TRUE) | 649 TRUE) |
649 << rcItem.left << " " << rcItem.bottom << " " | 650 << rcItem.left << " " << rcItem.bottom << " " |
650 << rcItem.Width() << " " << rcItem.Height() << " re f\n" | 651 << rcItem.Width() << " " << rcItem.Height() << " re f\n" |
651 << "Q\n"; | 652 << "Q\n"; |
652 sBody << "BT\n" << CPVT_GenerateAP::GenerateColorAP( | 653 sBody << "BT\n" << CPVT_GenerateAP::GenerateColorAP( |
653 CPVT_Color(CPVT_Color::GRAY, 1), TRUE) | 654 CPVT_Color(CPVT_Color::kGray, 1), TRUE) |
654 << CPVT_GenerateAP::GenerateEditAP(&map, vt.GetIterator(), | 655 << CPVT_GenerateAP::GenerateEditAP(&map, vt.GetIterator(), |
655 CPDF_Point(0.0f, fy), | 656 CPDF_Point(0.0f, fy), |
656 TRUE, 0) | 657 TRUE, 0) |
657 << "ET\n"; | 658 << "ET\n"; |
658 } else { | 659 } else { |
659 sBody << "BT\n" << CPVT_GenerateAP::GenerateColorAP(crText, TRUE) | 660 sBody << "BT\n" << CPVT_GenerateAP::GenerateColorAP(crText, TRUE) |
660 << CPVT_GenerateAP::GenerateEditAP(&map, vt.GetIterator(), | 661 << CPVT_GenerateAP::GenerateEditAP(&map, vt.GetIterator(), |
661 CPDF_Point(0.0f, fy), | 662 CPDF_Point(0.0f, fy), |
662 TRUE, 0) | 663 TRUE, 0) |
663 << "ET\n"; | 664 << "ET\n"; |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
904 } | 905 } |
905 break; | 906 break; |
906 } | 907 } |
907 } | 908 } |
908 return sAppStream.GetByteString(); | 909 return sAppStream.GetByteString(); |
909 } | 910 } |
910 CFX_ByteString CPVT_GenerateAP::GenerateColorAP(const CPVT_Color& color, | 911 CFX_ByteString CPVT_GenerateAP::GenerateColorAP(const CPVT_Color& color, |
911 const FX_BOOL& bFillOrStroke) { | 912 const FX_BOOL& bFillOrStroke) { |
912 CFX_ByteTextBuf sColorStream; | 913 CFX_ByteTextBuf sColorStream; |
913 switch (color.nColorType) { | 914 switch (color.nColorType) { |
914 case CPVT_Color::RGB: | 915 case CPVT_Color::kRGB: |
915 sColorStream << color.fColor1 << " " << color.fColor2 << " " | 916 sColorStream << color.fColor1 << " " << color.fColor2 << " " |
916 << color.fColor3 << " " << (bFillOrStroke ? "rg" : "RG") | 917 << color.fColor3 << " " << (bFillOrStroke ? "rg" : "RG") |
917 << "\n"; | 918 << "\n"; |
918 break; | 919 break; |
919 case CPVT_Color::GRAY: | 920 case CPVT_Color::kGray: |
920 sColorStream << color.fColor1 << " " << (bFillOrStroke ? "g" : "G") | 921 sColorStream << color.fColor1 << " " << (bFillOrStroke ? "g" : "G") |
921 << "\n"; | 922 << "\n"; |
922 break; | 923 break; |
923 case CPVT_Color::CMYK: | 924 case CPVT_Color::kCMYK: |
924 sColorStream << color.fColor1 << " " << color.fColor2 << " " | 925 sColorStream << color.fColor1 << " " << color.fColor2 << " " |
925 << color.fColor3 << " " << color.fColor4 << " " | 926 << color.fColor3 << " " << color.fColor4 << " " |
926 << (bFillOrStroke ? "k" : "K") << "\n"; | 927 << (bFillOrStroke ? "k" : "K") << "\n"; |
927 break; | 928 break; |
928 case CPVT_Color::TRANSPARENT: | 929 case CPVT_Color::kTransparent: |
929 break; | 930 break; |
930 } | 931 } |
931 return sColorStream.GetByteString(); | 932 return sColorStream.GetByteString(); |
932 } | 933 } |
OLD | NEW |