diff options
author | jaepark <jaepark@google.com> | 2016-08-02 12:25:15 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-08-02 12:25:15 -0700 |
commit | b2e63373054f0f1c3dbcdfa5e75acf2831b113f6 (patch) | |
tree | 5ff5f07b7ca26e3bfd5e814edc2ee4453db248d7 /core | |
parent | 448c4337f2be2523727451b265311d48e9550ee5 (diff) | |
download | pdfium-b2e63373054f0f1c3dbcdfa5e75acf2831b113f6.tar.xz |
Use PaintOperation instead of bFillOrStroke in CPVT_GenerateAP.
Also, use PaintOperation instead of bStrokingOperation in
CPDF_DefaultAppearance.
Review-Url: https://codereview.chromium.org/2197353002
Diffstat (limited to 'core')
-rw-r--r-- | core/fpdfdoc/cpvt_generateap.cpp | 57 | ||||
-rw-r--r-- | core/fpdfdoc/cpvt_generateap.h | 2 | ||||
-rw-r--r-- | core/fpdfdoc/doc_utils.cpp | 44 | ||||
-rw-r--r-- | core/fpdfdoc/include/cpdf_defaultappearance.h | 10 |
4 files changed, 70 insertions, 43 deletions
diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp index 78bd780eb5..aaf4b79858 100644 --- a/core/fpdfdoc/cpvt_generateap.cpp +++ b/core/fpdfdoc/cpvt_generateap.cpp @@ -152,7 +152,8 @@ bool GenerateWidgetAP(CPDF_Document* pDoc, crBG = CPVT_Color::ParseColor(*pArray); } CFX_ByteTextBuf sAppStream; - CFX_ByteString sBG = CPVT_GenerateAP::GenerateColorAP(crBG, TRUE); + CFX_ByteString sBG = + CPVT_GenerateAP::GenerateColorAP(crBG, PaintOperation::FILL); if (sBG.GetLength() > 0) { sAppStream << "q\n" << sBG << rcBBox.left << " " << rcBBox.bottom << " " << rcBBox.Width() << " " << rcBBox.Height() << " re f\n" @@ -262,7 +263,9 @@ bool GenerateWidgetAP(CPDF_Document* pDoc, << rcBody.Width() << " " << rcBody.Height() << " re\nW\nn\n"; } - sAppStream << "BT\n" << CPVT_GenerateAP::GenerateColorAP(crText, TRUE) + sAppStream << "BT\n" + << CPVT_GenerateAP::GenerateColorAP(crText, + PaintOperation::FILL) << sBody << "ET\n" << "Q\nEMC\n"; } @@ -303,14 +306,16 @@ bool GenerateWidgetAP(CPDF_Document* pDoc, << "q\n"; sAppStream << rcEdit.left << " " << rcEdit.bottom << " " << rcEdit.Width() << " " << rcEdit.Height() << " re\nW\nn\n"; - sAppStream << "BT\n" << CPVT_GenerateAP::GenerateColorAP(crText, TRUE) + sAppStream << "BT\n" + << CPVT_GenerateAP::GenerateColorAP(crText, + PaintOperation::FILL) << sEdit << "ET\n" << "Q\nEMC\n"; } CFX_ByteString sButton = CPVT_GenerateAP::GenerateColorAP( CPVT_Color(CPVT_Color::kRGB, 220.0f / 255.0f, 220.0f / 255.0f, 220.0f / 255.0f), - TRUE); + PaintOperation::FILL); if (sButton.GetLength() > 0 && !rcButton.IsEmpty()) { sAppStream << "q\n" << sButton; sAppStream << rcButton.left << " " << rcButton.bottom << " " @@ -385,21 +390,26 @@ bool GenerateWidgetAP(CPDF_Document* pDoc, if (bSelected) { CFX_FloatRect rcItem = CFX_FloatRect( rcBody.left, fy - fItemHeight, rcBody.right, fy); - sBody << "q\n" << CPVT_GenerateAP::GenerateColorAP( - CPVT_Color(CPVT_Color::kRGB, 0, - 51.0f / 255.0f, 113.0f / 255.0f), - TRUE) + sBody << "q\n" + << CPVT_GenerateAP::GenerateColorAP( + CPVT_Color(CPVT_Color::kRGB, 0, 51.0f / 255.0f, + 113.0f / 255.0f), + PaintOperation::FILL) << rcItem.left << " " << rcItem.bottom << " " << rcItem.Width() << " " << rcItem.Height() << " re f\n" << "Q\n"; - sBody << "BT\n" << CPVT_GenerateAP::GenerateColorAP( - CPVT_Color(CPVT_Color::kGray, 1), TRUE) + sBody << "BT\n" + << CPVT_GenerateAP::GenerateColorAP( + CPVT_Color(CPVT_Color::kGray, 1), + PaintOperation::FILL) << CPVT_GenerateAP::GenerateEditAP(&map, vt.GetIterator(), CFX_FloatPoint(0.0f, fy), TRUE, 0) << "ET\n"; } else { - sBody << "BT\n" << CPVT_GenerateAP::GenerateColorAP(crText, TRUE) + sBody << "BT\n" + << CPVT_GenerateAP::GenerateColorAP(crText, + PaintOperation::FILL) << CPVT_GenerateAP::GenerateEditAP(&map, vt.GetIterator(), CFX_FloatPoint(0.0f, fy), TRUE, 0) @@ -505,7 +515,7 @@ bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc, if (pAnnotDict->KeyExist("C")) { CPDF_Array* pColor = pAnnotDict->GetArrayBy("C"); CPVT_Color color = CPVT_Color::ParseColor(*pColor); - sAppStream << CPVT_GenerateAP::GenerateColorAP(color, TRUE); + sAppStream << CPVT_GenerateAP::GenerateColorAP(color, PaintOperation::FILL); } else { // Defaults to 0xFFFF00 color for highlight. sAppStream << "1 1 0 rg \n"; @@ -660,7 +670,7 @@ CFX_ByteString CPVT_GenerateAP::GenerateBorderAP( switch (nStyle) { default: case BorderStyle::SOLID: - sColor = GenerateColorAP(color, TRUE); + sColor = GenerateColorAP(color, PaintOperation::FILL); if (sColor.GetLength() > 0) { sAppStream << sColor; sAppStream << fLeft << " " << fBottom << " " << fRight - fLeft << " " @@ -672,7 +682,7 @@ CFX_ByteString CPVT_GenerateAP::GenerateBorderAP( } break; case BorderStyle::DASH: - sColor = GenerateColorAP(color, FALSE); + sColor = GenerateColorAP(color, PaintOperation::STROKE); if (sColor.GetLength() > 0) { sAppStream << sColor; sAppStream << fWidth << " w" @@ -692,7 +702,7 @@ CFX_ByteString CPVT_GenerateAP::GenerateBorderAP( break; case BorderStyle::BEVELED: case BorderStyle::INSET: - sColor = GenerateColorAP(crLeftTop, TRUE); + sColor = GenerateColorAP(crLeftTop, PaintOperation::FILL); if (sColor.GetLength() > 0) { sAppStream << sColor; sAppStream << fLeft + fHalfWidth << " " << fBottom + fHalfWidth @@ -708,7 +718,7 @@ CFX_ByteString CPVT_GenerateAP::GenerateBorderAP( sAppStream << fLeft + fHalfWidth * 2 << " " << fBottom + fHalfWidth * 2 << " l f\n"; } - sColor = GenerateColorAP(crRightBottom, TRUE); + sColor = GenerateColorAP(crRightBottom, PaintOperation::FILL); if (sColor.GetLength() > 0) { sAppStream << sColor; sAppStream << fRight - fHalfWidth << " " << fTop - fHalfWidth @@ -724,7 +734,7 @@ CFX_ByteString CPVT_GenerateAP::GenerateBorderAP( sAppStream << fRight - fHalfWidth * 2 << " " << fTop - fHalfWidth * 2 << " l f\n"; } - sColor = GenerateColorAP(color, TRUE); + sColor = GenerateColorAP(color, PaintOperation::FILL); if (sColor.GetLength() > 0) { sAppStream << sColor; sAppStream << fLeft << " " << fBottom << " " << fRight - fLeft << " " @@ -735,7 +745,7 @@ CFX_ByteString CPVT_GenerateAP::GenerateBorderAP( } break; case BorderStyle::UNDERLINE: - sColor = GenerateColorAP(color, FALSE); + sColor = GenerateColorAP(color, PaintOperation::STROKE); if (sColor.GetLength() > 0) { sAppStream << sColor; sAppStream << fWidth << " w\n"; @@ -750,22 +760,25 @@ CFX_ByteString CPVT_GenerateAP::GenerateBorderAP( // Static. CFX_ByteString CPVT_GenerateAP::GenerateColorAP(const CPVT_Color& color, - const FX_BOOL& bFillOrStroke) { + PaintOperation nOperation) { CFX_ByteTextBuf sColorStream; switch (color.nColorType) { case CPVT_Color::kRGB: sColorStream << color.fColor1 << " " << color.fColor2 << " " - << color.fColor3 << " " << (bFillOrStroke ? "rg" : "RG") + << color.fColor3 << " " + << (nOperation == PaintOperation::STROKE ? "RG" : "rg") << "\n"; break; case CPVT_Color::kGray: - sColorStream << color.fColor1 << " " << (bFillOrStroke ? "g" : "G") + sColorStream << color.fColor1 << " " + << (nOperation == PaintOperation::STROKE ? "G" : "g") << "\n"; break; case CPVT_Color::kCMYK: sColorStream << color.fColor1 << " " << color.fColor2 << " " << color.fColor3 << " " << color.fColor4 << " " - << (bFillOrStroke ? "k" : "K") << "\n"; + << (nOperation == PaintOperation::STROKE ? "K" : "k") + << "\n"; break; case CPVT_Color::kTransparent: break; diff --git a/core/fpdfdoc/cpvt_generateap.h b/core/fpdfdoc/cpvt_generateap.h index 4b4d7d093b..6cd9dcea67 100644 --- a/core/fpdfdoc/cpvt_generateap.h +++ b/core/fpdfdoc/cpvt_generateap.h @@ -46,7 +46,7 @@ class CPVT_GenerateAP { BorderStyle nStyle, const CPVT_Dash& dash); static CFX_ByteString GenerateColorAP(const CPVT_Color& color, - const FX_BOOL& bFillOrStroke); + PaintOperation nOperation); static CFX_ByteString GetPDFWordString(IPVT_FontMap* pFontMap, int32_t nFontIndex, diff --git a/core/fpdfdoc/doc_utils.cpp b/core/fpdfdoc/doc_utils.cpp index 284520d150..aaaaddf0c6 100644 --- a/core/fpdfdoc/doc_utils.cpp +++ b/core/fpdfdoc/doc_utils.cpp @@ -117,33 +117,38 @@ void CPDF_DefaultAppearance::GetFont(CFX_ByteString& csFontNameTag, } csFontNameTag = PDF_NameDecode(csFontNameTag); } -FX_BOOL CPDF_DefaultAppearance::HasColor(FX_BOOL bStrokingOperation) { +FX_BOOL CPDF_DefaultAppearance::HasColor(PaintOperation nOperation) { if (m_csDA.IsEmpty()) { return FALSE; } CPDF_SimpleParser syntax(m_csDA.AsStringC()); - if (syntax.FindTagParamFromStart(bStrokingOperation ? "G" : "g", 1)) { + if (syntax.FindTagParamFromStart( + (nOperation == PaintOperation::STROKE ? "G" : "g"), 1)) { return TRUE; } - if (syntax.FindTagParamFromStart(bStrokingOperation ? "RG" : "rg", 3)) { + if (syntax.FindTagParamFromStart( + (nOperation == PaintOperation::STROKE ? "RG" : "rg"), 3)) { return TRUE; } - return syntax.FindTagParamFromStart(bStrokingOperation ? "K" : "k", 4); + return syntax.FindTagParamFromStart( + (nOperation == PaintOperation::STROKE ? "K" : "k"), 4); } CFX_ByteString CPDF_DefaultAppearance::GetColorString( - FX_BOOL bStrokingOperation) { + PaintOperation nOperation) { CFX_ByteString csColor; if (m_csDA.IsEmpty()) { return csColor; } CPDF_SimpleParser syntax(m_csDA.AsStringC()); - if (syntax.FindTagParamFromStart(bStrokingOperation ? "G" : "g", 1)) { + if (syntax.FindTagParamFromStart( + (nOperation == PaintOperation::STROKE ? "G" : "g"), 1)) { csColor += syntax.GetWord(); csColor += " "; csColor += syntax.GetWord(); return csColor; } - if (syntax.FindTagParamFromStart(bStrokingOperation ? "RG" : "rg", 3)) { + if (syntax.FindTagParamFromStart( + (nOperation == PaintOperation::STROKE ? "RG" : "rg"), 3)) { csColor += syntax.GetWord(); csColor += " "; csColor += syntax.GetWord(); @@ -153,7 +158,8 @@ CFX_ByteString CPDF_DefaultAppearance::GetColorString( csColor += syntax.GetWord(); return csColor; } - if (syntax.FindTagParamFromStart(bStrokingOperation ? "K" : "k", 4)) { + if (syntax.FindTagParamFromStart( + (nOperation == PaintOperation::STROKE ? "K" : "k"), 4)) { csColor += syntax.GetWord(); csColor += " "; csColor += syntax.GetWord(); @@ -168,7 +174,7 @@ CFX_ByteString CPDF_DefaultAppearance::GetColorString( } void CPDF_DefaultAppearance::GetColor(int& iColorType, FX_FLOAT fc[4], - FX_BOOL bStrokingOperation) { + PaintOperation nOperation) { iColorType = COLORTYPE_TRANSPARENT; for (int c = 0; c < 4; c++) { fc[c] = 0; @@ -177,19 +183,22 @@ void CPDF_DefaultAppearance::GetColor(int& iColorType, return; } CPDF_SimpleParser syntax(m_csDA.AsStringC()); - if (syntax.FindTagParamFromStart(bStrokingOperation ? "G" : "g", 1)) { + if (syntax.FindTagParamFromStart( + (nOperation == PaintOperation::STROKE ? "G" : "g"), 1)) { iColorType = COLORTYPE_GRAY; fc[0] = FX_atof(syntax.GetWord()); return; } - if (syntax.FindTagParamFromStart(bStrokingOperation ? "RG" : "rg", 3)) { + if (syntax.FindTagParamFromStart( + (nOperation == PaintOperation::STROKE ? "RG" : "rg"), 3)) { iColorType = COLORTYPE_RGB; fc[0] = FX_atof(syntax.GetWord()); fc[1] = FX_atof(syntax.GetWord()); fc[2] = FX_atof(syntax.GetWord()); return; } - if (syntax.FindTagParamFromStart(bStrokingOperation ? "K" : "k", 4)) { + if (syntax.FindTagParamFromStart( + (nOperation == PaintOperation::STROKE ? "K" : "k"), 4)) { iColorType = COLORTYPE_CMYK; fc[0] = FX_atof(syntax.GetWord()); fc[1] = FX_atof(syntax.GetWord()); @@ -199,20 +208,22 @@ void CPDF_DefaultAppearance::GetColor(int& iColorType, } void CPDF_DefaultAppearance::GetColor(FX_ARGB& color, int& iColorType, - FX_BOOL bStrokingOperation) { + PaintOperation nOperation) { color = 0; iColorType = COLORTYPE_TRANSPARENT; if (m_csDA.IsEmpty()) { return; } CPDF_SimpleParser syntax(m_csDA.AsStringC()); - if (syntax.FindTagParamFromStart(bStrokingOperation ? "G" : "g", 1)) { + if (syntax.FindTagParamFromStart( + (nOperation == PaintOperation::STROKE ? "G" : "g"), 1)) { iColorType = COLORTYPE_GRAY; FX_FLOAT g = FX_atof(syntax.GetWord()) * 255 + 0.5f; color = ArgbEncode(255, (int)g, (int)g, (int)g); return; } - if (syntax.FindTagParamFromStart(bStrokingOperation ? "RG" : "rg", 3)) { + if (syntax.FindTagParamFromStart( + (nOperation == PaintOperation::STROKE ? "RG" : "rg"), 3)) { iColorType = COLORTYPE_RGB; FX_FLOAT r = FX_atof(syntax.GetWord()) * 255 + 0.5f; FX_FLOAT g = FX_atof(syntax.GetWord()) * 255 + 0.5f; @@ -220,7 +231,8 @@ void CPDF_DefaultAppearance::GetColor(FX_ARGB& color, color = ArgbEncode(255, (int)r, (int)g, (int)b); return; } - if (syntax.FindTagParamFromStart(bStrokingOperation ? "K" : "k", 4)) { + if (syntax.FindTagParamFromStart( + (nOperation == PaintOperation::STROKE ? "K" : "k"), 4)) { iColorType = COLORTYPE_CMYK; FX_FLOAT c = FX_atof(syntax.GetWord()); FX_FLOAT m = FX_atof(syntax.GetWord()); diff --git a/core/fpdfdoc/include/cpdf_defaultappearance.h b/core/fpdfdoc/include/cpdf_defaultappearance.h index c45d4eeffc..c0fd3de709 100644 --- a/core/fpdfdoc/include/cpdf_defaultappearance.h +++ b/core/fpdfdoc/include/cpdf_defaultappearance.h @@ -14,6 +14,7 @@ #include "core/fxge/include/fx_dib.h" enum class BorderStyle { SOLID, DASH, BEVELED, INSET, UNDERLINE }; +enum class PaintOperation { STROKE, FILL }; class CPDF_DefaultAppearance { public: @@ -30,14 +31,15 @@ class CPDF_DefaultAppearance { CFX_ByteString GetFontString(); void GetFont(CFX_ByteString& csFontNameTag, FX_FLOAT& fFontSize); - FX_BOOL HasColor(FX_BOOL bStrokingOperation = FALSE); - CFX_ByteString GetColorString(FX_BOOL bStrokingOperation = FALSE); + FX_BOOL HasColor(PaintOperation nOperation = PaintOperation::FILL); + CFX_ByteString GetColorString( + PaintOperation nOperation = PaintOperation::FILL); void GetColor(int& iColorType, FX_FLOAT fc[4], - FX_BOOL bStrokingOperation = FALSE); + PaintOperation nOperation = PaintOperation::FILL); void GetColor(FX_ARGB& color, int& iColorType, - FX_BOOL bStrokingOperation = FALSE); + PaintOperation nOperation = PaintOperation::FILL); FX_BOOL HasTextMatrix(); CFX_ByteString GetTextMatrixString(); |