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

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

Issue 1980973002: Convert border style defines to an enum class. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 7 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 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "core/fpdfdoc/cpvt_generateap.h" 7 #include "core/fpdfdoc/cpvt_generateap.h"
8 8
9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" 9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h"
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 rcAnnot.top - rcAnnot.bottom); 100 rcAnnot.top - rcAnnot.bottom);
101 rcBBox = CFX_FloatRect(0, 0, rcAnnot.right - rcAnnot.left, 101 rcBBox = CFX_FloatRect(0, 0, rcAnnot.right - rcAnnot.left,
102 rcAnnot.top - rcAnnot.bottom); 102 rcAnnot.top - rcAnnot.bottom);
103 break; 103 break;
104 case 270: 104 case 270:
105 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);
106 rcBBox = CFX_FloatRect(0, 0, rcAnnot.top - rcAnnot.bottom, 106 rcBBox = CFX_FloatRect(0, 0, rcAnnot.top - rcAnnot.bottom,
107 rcAnnot.right - rcAnnot.left); 107 rcAnnot.right - rcAnnot.left);
108 break; 108 break;
109 } 109 }
110 int32_t nBorderStyle = PBS_SOLID; 110
111 BorderStyle nBorderStyle = BorderStyle::SOLID;
111 FX_FLOAT fBorderWidth = 1; 112 FX_FLOAT fBorderWidth = 1;
112 CPVT_Dash dsBorder(3, 0, 0); 113 CPVT_Dash dsBorder(3, 0, 0);
113 CPVT_Color crLeftTop, crRightBottom; 114 CPVT_Color crLeftTop, crRightBottom;
114 if (CPDF_Dictionary* pBSDict = pAnnotDict->GetDictBy("BS")) { 115 if (CPDF_Dictionary* pBSDict = pAnnotDict->GetDictBy("BS")) {
115 if (pBSDict->KeyExist("W")) 116 if (pBSDict->KeyExist("W"))
116 fBorderWidth = pBSDict->GetNumberBy("W"); 117 fBorderWidth = pBSDict->GetNumberBy("W");
117 118
118 if (CPDF_Array* pArray = pBSDict->GetArrayBy("D")) { 119 if (CPDF_Array* pArray = pBSDict->GetArrayBy("D")) {
119 dsBorder = CPVT_Dash(pArray->GetIntegerAt(0), pArray->GetIntegerAt(1), 120 dsBorder = CPVT_Dash(pArray->GetIntegerAt(0), pArray->GetIntegerAt(1),
120 pArray->GetIntegerAt(2)); 121 pArray->GetIntegerAt(2));
121 } 122 }
122 switch (pBSDict->GetStringBy("S").GetAt(0)) { 123 switch (pBSDict->GetStringBy("S").GetAt(0)) {
123 case 'S': 124 case 'S':
124 nBorderStyle = PBS_SOLID; 125 nBorderStyle = BorderStyle::SOLID;
125 break; 126 break;
126 case 'D': 127 case 'D':
127 nBorderStyle = PBS_DASH; 128 nBorderStyle = BorderStyle::DASH;
128 break; 129 break;
129 case 'B': 130 case 'B':
130 nBorderStyle = PBS_BEVELED; 131 nBorderStyle = BorderStyle::BEVELED;
131 fBorderWidth *= 2; 132 fBorderWidth *= 2;
132 crLeftTop = CPVT_Color(CPVT_Color::kGray, 1); 133 crLeftTop = CPVT_Color(CPVT_Color::kGray, 1);
133 crRightBottom = CPVT_Color(CPVT_Color::kGray, 0.5); 134 crRightBottom = CPVT_Color(CPVT_Color::kGray, 0.5);
134 break; 135 break;
135 case 'I': 136 case 'I':
136 nBorderStyle = PBS_INSET; 137 nBorderStyle = BorderStyle::INSET;
137 fBorderWidth *= 2; 138 fBorderWidth *= 2;
138 crLeftTop = CPVT_Color(CPVT_Color::kGray, 0.5); 139 crLeftTop = CPVT_Color(CPVT_Color::kGray, 0.5);
139 crRightBottom = CPVT_Color(CPVT_Color::kGray, 0.75); 140 crRightBottom = CPVT_Color(CPVT_Color::kGray, 0.75);
140 break; 141 break;
141 case 'U': 142 case 'U':
142 nBorderStyle = PBS_UNDERLINED; 143 nBorderStyle = BorderStyle::UNDERLINE;
143 break; 144 break;
144 } 145 }
145 } 146 }
146 CPVT_Color crBorder, crBG; 147 CPVT_Color crBorder, crBG;
147 if (CPDF_Dictionary* pMKDict = pAnnotDict->GetDictBy("MK")) { 148 if (CPDF_Dictionary* pMKDict = pAnnotDict->GetDictBy("MK")) {
148 if (CPDF_Array* pArray = pMKDict->GetArrayBy("BC")) 149 if (CPDF_Array* pArray = pMKDict->GetArrayBy("BC"))
149 crBorder = CPVT_Color::ParseColor(*pArray); 150 crBorder = CPVT_Color::ParseColor(*pArray);
150 if (CPDF_Array* pArray = pMKDict->GetArrayBy("BG")) 151 if (CPDF_Array* pArray = pMKDict->GetArrayBy("BG"))
151 crBG = CPVT_Color::ParseColor(*pArray); 152 crBG = CPVT_Color::ParseColor(*pArray);
152 } 153 }
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 220.0f / 255.0f), 312 220.0f / 255.0f),
312 TRUE); 313 TRUE);
313 if (sButton.GetLength() > 0 && !rcButton.IsEmpty()) { 314 if (sButton.GetLength() > 0 && !rcButton.IsEmpty()) {
314 sAppStream << "q\n" << sButton; 315 sAppStream << "q\n" << sButton;
315 sAppStream << rcButton.left << " " << rcButton.bottom << " " 316 sAppStream << rcButton.left << " " << rcButton.bottom << " "
316 << rcButton.Width() << " " << rcButton.Height() << " re f\n"; 317 << rcButton.Width() << " " << rcButton.Height() << " re f\n";
317 sAppStream << "Q\n"; 318 sAppStream << "Q\n";
318 CFX_ByteString sButtonBorder = CPVT_GenerateAP::GenerateBorderAP( 319 CFX_ByteString sButtonBorder = CPVT_GenerateAP::GenerateBorderAP(
319 rcButton, 2, CPVT_Color(CPVT_Color::kGray, 0), 320 rcButton, 2, CPVT_Color(CPVT_Color::kGray, 0),
320 CPVT_Color(CPVT_Color::kGray, 1), 321 CPVT_Color(CPVT_Color::kGray, 1),
321 CPVT_Color(CPVT_Color::kGray, 0.5), PBS_BEVELED, 322 CPVT_Color(CPVT_Color::kGray, 0.5), BorderStyle::BEVELED,
322 CPVT_Dash(3, 0, 0)); 323 CPVT_Dash(3, 0, 0));
323 if (sButtonBorder.GetLength() > 0) 324 if (sButtonBorder.GetLength() > 0)
324 sAppStream << "q\n" << sButtonBorder << "Q\n"; 325 sAppStream << "q\n" << sButtonBorder << "Q\n";
325 326
326 CFX_FloatPoint ptCenter = 327 CFX_FloatPoint ptCenter =
327 CFX_FloatPoint((rcButton.left + rcButton.right) / 2, 328 CFX_FloatPoint((rcButton.left + rcButton.right) / 2,
328 (rcButton.top + rcButton.bottom) / 2); 329 (rcButton.top + rcButton.bottom) / 2);
329 if (IsFloatBigger(rcButton.Width(), 6) && 330 if (IsFloatBigger(rcButton.Width(), 6) &&
330 IsFloatBigger(rcButton.Height(), 6)) { 331 IsFloatBigger(rcButton.Height(), 6)) {
331 sAppStream << "q\n" 332 sAppStream << "q\n"
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 return sEditStream.MakeString(); 583 return sEditStream.MakeString();
583 } 584 }
584 585
585 // Static. 586 // Static.
586 CFX_ByteString CPVT_GenerateAP::GenerateBorderAP( 587 CFX_ByteString CPVT_GenerateAP::GenerateBorderAP(
587 const CFX_FloatRect& rect, 588 const CFX_FloatRect& rect,
588 FX_FLOAT fWidth, 589 FX_FLOAT fWidth,
589 const CPVT_Color& color, 590 const CPVT_Color& color,
590 const CPVT_Color& crLeftTop, 591 const CPVT_Color& crLeftTop,
591 const CPVT_Color& crRightBottom, 592 const CPVT_Color& crRightBottom,
592 int32_t nStyle, 593 BorderStyle nStyle,
593 const CPVT_Dash& dash) { 594 const CPVT_Dash& dash) {
594 CFX_ByteTextBuf sAppStream; 595 CFX_ByteTextBuf sAppStream;
595 CFX_ByteString sColor; 596 CFX_ByteString sColor;
596 FX_FLOAT fLeft = rect.left; 597 FX_FLOAT fLeft = rect.left;
597 FX_FLOAT fRight = rect.right; 598 FX_FLOAT fRight = rect.right;
598 FX_FLOAT fTop = rect.top; 599 FX_FLOAT fTop = rect.top;
599 FX_FLOAT fBottom = rect.bottom; 600 FX_FLOAT fBottom = rect.bottom;
600 if (fWidth > 0.0f) { 601 if (fWidth > 0.0f) {
601 FX_FLOAT fHalfWidth = fWidth / 2.0f; 602 FX_FLOAT fHalfWidth = fWidth / 2.0f;
602 switch (nStyle) { 603 switch (nStyle) {
603 default: 604 default:
604 case PBS_SOLID: 605 case BorderStyle::SOLID:
605 sColor = GenerateColorAP(color, TRUE); 606 sColor = GenerateColorAP(color, TRUE);
606 if (sColor.GetLength() > 0) { 607 if (sColor.GetLength() > 0) {
607 sAppStream << sColor; 608 sAppStream << sColor;
608 sAppStream << fLeft << " " << fBottom << " " << fRight - fLeft << " " 609 sAppStream << fLeft << " " << fBottom << " " << fRight - fLeft << " "
609 << fTop - fBottom << " re\n"; 610 << fTop - fBottom << " re\n";
610 sAppStream << fLeft + fWidth << " " << fBottom + fWidth << " " 611 sAppStream << fLeft + fWidth << " " << fBottom + fWidth << " "
611 << fRight - fLeft - fWidth * 2 << " " 612 << fRight - fLeft - fWidth * 2 << " "
612 << fTop - fBottom - fWidth * 2 << " re\n"; 613 << fTop - fBottom - fWidth * 2 << " re\n";
613 sAppStream << "f*\n"; 614 sAppStream << "f*\n";
614 } 615 }
615 break; 616 break;
616 case PBS_DASH: 617 case BorderStyle::DASH:
617 sColor = GenerateColorAP(color, FALSE); 618 sColor = GenerateColorAP(color, FALSE);
618 if (sColor.GetLength() > 0) { 619 if (sColor.GetLength() > 0) {
619 sAppStream << sColor; 620 sAppStream << sColor;
620 sAppStream << fWidth << " w" 621 sAppStream << fWidth << " w"
621 << " [" << dash.nDash << " " << dash.nGap << "] " 622 << " [" << dash.nDash << " " << dash.nGap << "] "
622 << dash.nPhase << " d\n"; 623 << dash.nPhase << " d\n";
623 sAppStream << fLeft + fWidth / 2 << " " << fBottom + fWidth / 2 624 sAppStream << fLeft + fWidth / 2 << " " << fBottom + fWidth / 2
624 << " m\n"; 625 << " m\n";
625 sAppStream << fLeft + fWidth / 2 << " " << fTop - fWidth / 2 626 sAppStream << fLeft + fWidth / 2 << " " << fTop - fWidth / 2
626 << " l\n"; 627 << " l\n";
627 sAppStream << fRight - fWidth / 2 << " " << fTop - fWidth / 2 628 sAppStream << fRight - fWidth / 2 << " " << fTop - fWidth / 2
628 << " l\n"; 629 << " l\n";
629 sAppStream << fRight - fWidth / 2 << " " << fBottom + fWidth / 2 630 sAppStream << fRight - fWidth / 2 << " " << fBottom + fWidth / 2
630 << " l\n"; 631 << " l\n";
631 sAppStream << fLeft + fWidth / 2 << " " << fBottom + fWidth / 2 632 sAppStream << fLeft + fWidth / 2 << " " << fBottom + fWidth / 2
632 << " l S\n"; 633 << " l S\n";
633 } 634 }
634 break; 635 break;
635 case PBS_BEVELED: 636 case BorderStyle::BEVELED:
636 case PBS_INSET: 637 case BorderStyle::INSET:
637 sColor = GenerateColorAP(crLeftTop, TRUE); 638 sColor = GenerateColorAP(crLeftTop, TRUE);
638 if (sColor.GetLength() > 0) { 639 if (sColor.GetLength() > 0) {
639 sAppStream << sColor; 640 sAppStream << sColor;
640 sAppStream << fLeft + fHalfWidth << " " << fBottom + fHalfWidth 641 sAppStream << fLeft + fHalfWidth << " " << fBottom + fHalfWidth
641 << " m\n"; 642 << " m\n";
642 sAppStream << fLeft + fHalfWidth << " " << fTop - fHalfWidth 643 sAppStream << fLeft + fHalfWidth << " " << fTop - fHalfWidth
643 << " l\n"; 644 << " l\n";
644 sAppStream << fRight - fHalfWidth << " " << fTop - fHalfWidth 645 sAppStream << fRight - fHalfWidth << " " << fTop - fHalfWidth
645 << " l\n"; 646 << " l\n";
646 sAppStream << fRight - fHalfWidth * 2 << " " << fTop - fHalfWidth * 2 647 sAppStream << fRight - fHalfWidth * 2 << " " << fTop - fHalfWidth * 2
(...skipping 22 matching lines...) Expand all
669 sColor = GenerateColorAP(color, TRUE); 670 sColor = GenerateColorAP(color, TRUE);
670 if (sColor.GetLength() > 0) { 671 if (sColor.GetLength() > 0) {
671 sAppStream << sColor; 672 sAppStream << sColor;
672 sAppStream << fLeft << " " << fBottom << " " << fRight - fLeft << " " 673 sAppStream << fLeft << " " << fBottom << " " << fRight - fLeft << " "
673 << fTop - fBottom << " re\n"; 674 << fTop - fBottom << " re\n";
674 sAppStream << fLeft + fHalfWidth << " " << fBottom + fHalfWidth << " " 675 sAppStream << fLeft + fHalfWidth << " " << fBottom + fHalfWidth << " "
675 << fRight - fLeft - fHalfWidth * 2 << " " 676 << fRight - fLeft - fHalfWidth * 2 << " "
676 << fTop - fBottom - fHalfWidth * 2 << " re f*\n"; 677 << fTop - fBottom - fHalfWidth * 2 << " re f*\n";
677 } 678 }
678 break; 679 break;
679 case PBS_UNDERLINED: 680 case BorderStyle::UNDERLINE:
680 sColor = GenerateColorAP(color, FALSE); 681 sColor = GenerateColorAP(color, FALSE);
681 if (sColor.GetLength() > 0) { 682 if (sColor.GetLength() > 0) {
682 sAppStream << sColor; 683 sAppStream << sColor;
683 sAppStream << fWidth << " w\n"; 684 sAppStream << fWidth << " w\n";
684 sAppStream << fLeft << " " << fBottom + fWidth / 2 << " m\n"; 685 sAppStream << fLeft << " " << fBottom + fWidth / 2 << " m\n";
685 sAppStream << fRight << " " << fBottom + fWidth / 2 << " l S\n"; 686 sAppStream << fRight << " " << fBottom + fWidth / 2 << " l S\n";
686 } 687 }
687 break; 688 break;
688 } 689 }
689 } 690 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 int32_t nFontIndex, 756 int32_t nFontIndex,
756 FX_FLOAT fFontSize) { 757 FX_FLOAT fFontSize) {
757 CFX_ByteTextBuf sRet; 758 CFX_ByteTextBuf sRet;
758 if (pFontMap) { 759 if (pFontMap) {
759 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); 760 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex);
760 if (sFontAlias.GetLength() > 0 && fFontSize > 0) 761 if (sFontAlias.GetLength() > 0 && fFontSize > 0)
761 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; 762 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n";
762 } 763 }
763 return sRet.MakeString(); 764 return sRet.MakeString();
764 } 765 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698