From 8e7f932410732a4f05d2e69e9ff66277f54d1bd7 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Mon, 16 Oct 2017 11:35:42 -0400 Subject: Convert CPVT_Color to CFX_Color This CL converts the use of CPVT_Color to CFX_Color and removes the CPVT_Color class. Change-Id: I86a2d06524cd8f0fbce2335f0185426cc41dbe84 Reviewed-on: https://pdfium-review.googlesource.com/16030 Reviewed-by: Ryan Harrison Commit-Queue: dsinclair --- BUILD.gn | 2 - core/fpdfdoc/cpdf_annotlist.cpp | 1 + core/fpdfdoc/cpdf_apsettings.cpp | 18 ++--- core/fpdfdoc/cpdf_defaultappearance.cpp | 18 ++--- core/fpdfdoc/cpdf_formcontrol.h | 5 -- core/fpdfdoc/cpvt_color.cpp | 51 ------------- core/fpdfdoc/cpvt_color.h | 38 ---------- core/fpdfdoc/cpvt_generateap.cpp | 96 ++++++++++++------------- core/fpdfdoc/cpvt_generateap.h | 10 +-- core/fxge/cfx_color.cpp | 122 ++++++++++++++++++++++---------- core/fxge/cfx_color.h | 11 ++- fpdfsdk/cpdfsdk_widget.cpp | 10 +-- fpdfsdk/formfiller/cffl_formfiller.cpp | 2 +- fpdfsdk/fpdfannot.cpp | 13 ++-- fpdfsdk/javascript/Field.cpp | 41 +++++------ fpdfsdk/javascript/color.cpp | 50 ++++++------- fpdfsdk/pwl/cpwl_appstream.cpp | 70 +++++++++--------- fpdfsdk/pwl/cpwl_combo_box.cpp | 6 +- fpdfsdk/pwl/cpwl_scroll_bar.cpp | 2 +- fpdfsdk/pwl/cpwl_wnd.cpp | 6 +- fpdfsdk/pwl/cpwl_wnd.h | 4 +- 21 files changed, 264 insertions(+), 312 deletions(-) delete mode 100644 core/fpdfdoc/cpvt_color.cpp delete mode 100644 core/fpdfdoc/cpvt_color.h diff --git a/BUILD.gn b/BUILD.gn index 3e3f22fdde..57d07fce04 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -353,8 +353,6 @@ static_library("fpdfdoc") { "core/fpdfdoc/cpdf_variabletext.h", "core/fpdfdoc/cpdf_viewerpreferences.cpp", "core/fpdfdoc/cpdf_viewerpreferences.h", - "core/fpdfdoc/cpvt_color.cpp", - "core/fpdfdoc/cpvt_color.h", "core/fpdfdoc/cpvt_dash.h", "core/fpdfdoc/cpvt_floatrect.h", "core/fpdfdoc/cpvt_fontmap.cpp", diff --git a/core/fpdfdoc/cpdf_annotlist.cpp b/core/fpdfdoc/cpdf_annotlist.cpp index 9224943d1e..c0f7ae2f23 100644 --- a/core/fpdfdoc/cpdf_annotlist.cpp +++ b/core/fpdfdoc/cpdf_annotlist.cpp @@ -11,6 +11,7 @@ #include #include "core/fpdfapi/page/cpdf_page.h" +#include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfapi/parser/cpdf_document.h" #include "core/fpdfapi/parser/cpdf_name.h" #include "core/fpdfapi/parser/cpdf_number.h" diff --git a/core/fpdfdoc/cpdf_apsettings.cpp b/core/fpdfdoc/cpdf_apsettings.cpp index 0fc9c202cb..076cdd9b9e 100644 --- a/core/fpdfdoc/cpdf_apsettings.cpp +++ b/core/fpdfdoc/cpdf_apsettings.cpp @@ -10,7 +10,7 @@ #include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" -#include "core/fpdfdoc/cpdf_formcontrol.h" +#include "core/fxge/cfx_color.h" CPDF_ApSettings::CPDF_ApSettings(CPDF_Dictionary* pDict) : m_pDict(pDict) {} @@ -28,7 +28,7 @@ int CPDF_ApSettings::GetRotation() const { FX_ARGB CPDF_ApSettings::GetColor(int& iColorType, const ByteString& csEntry) const { - iColorType = COLORTYPE_TRANSPARENT; + iColorType = CFX_Color::kTransparent; if (!m_pDict) return 0; @@ -39,19 +39,19 @@ FX_ARGB CPDF_ApSettings::GetColor(int& iColorType, FX_ARGB color = 0; size_t dwCount = pEntry->GetCount(); if (dwCount == 1) { - iColorType = COLORTYPE_GRAY; + iColorType = CFX_Color::kGray; float g = pEntry->GetNumberAt(0) * 255; return ArgbEncode(255, (int)g, (int)g, (int)g); } if (dwCount == 3) { - iColorType = COLORTYPE_RGB; + iColorType = CFX_Color::kRGB; float r = pEntry->GetNumberAt(0) * 255; float g = pEntry->GetNumberAt(1) * 255; float b = pEntry->GetNumberAt(2) * 255; return ArgbEncode(255, (int)r, (int)g, (int)b); } if (dwCount == 4) { - iColorType = COLORTYPE_CMYK; + iColorType = CFX_Color::kCMYK; float c = pEntry->GetNumberAt(0); float m = pEntry->GetNumberAt(1); float y = pEntry->GetNumberAt(2); @@ -76,7 +76,7 @@ float CPDF_ApSettings::GetOriginalColor(int index, void CPDF_ApSettings::GetOriginalColor(int& iColorType, float fc[4], const ByteString& csEntry) const { - iColorType = COLORTYPE_TRANSPARENT; + iColorType = CFX_Color::kTransparent; for (int i = 0; i < 4; i++) fc[i] = 0; @@ -89,15 +89,15 @@ void CPDF_ApSettings::GetOriginalColor(int& iColorType, size_t dwCount = pEntry->GetCount(); if (dwCount == 1) { - iColorType = COLORTYPE_GRAY; + iColorType = CFX_Color::kGray; fc[0] = pEntry->GetNumberAt(0); } else if (dwCount == 3) { - iColorType = COLORTYPE_RGB; + iColorType = CFX_Color::kRGB; fc[0] = pEntry->GetNumberAt(0); fc[1] = pEntry->GetNumberAt(1); fc[2] = pEntry->GetNumberAt(2); } else if (dwCount == 4) { - iColorType = COLORTYPE_CMYK; + iColorType = CFX_Color::kCMYK; fc[0] = pEntry->GetNumberAt(0); fc[1] = pEntry->GetNumberAt(1); fc[2] = pEntry->GetNumberAt(2); diff --git a/core/fpdfdoc/cpdf_defaultappearance.cpp b/core/fpdfdoc/cpdf_defaultappearance.cpp index bd7ea1bc07..02d6eea41f 100644 --- a/core/fpdfdoc/cpdf_defaultappearance.cpp +++ b/core/fpdfdoc/cpdf_defaultappearance.cpp @@ -10,7 +10,7 @@ #include "core/fpdfapi/parser/cpdf_simple_parser.h" #include "core/fpdfapi/parser/fpdf_parser_decode.h" -#include "core/fpdfdoc/cpdf_formcontrol.h" +#include "core/fxge/cfx_color.h" bool CPDF_DefaultAppearance::HasFont() { if (m_csDA.IsEmpty()) @@ -110,7 +110,7 @@ ByteString CPDF_DefaultAppearance::GetColorString(PaintOperation nOperation) { void CPDF_DefaultAppearance::GetColor(int& iColorType, float fc[4], PaintOperation nOperation) { - iColorType = COLORTYPE_TRANSPARENT; + iColorType = CFX_Color::kTransparent; for (int c = 0; c < 4; c++) fc[c] = 0; @@ -120,13 +120,13 @@ void CPDF_DefaultAppearance::GetColor(int& iColorType, CPDF_SimpleParser syntax(m_csDA.AsStringView()); if (syntax.FindTagParamFromStart( (nOperation == PaintOperation::STROKE ? "G" : "g"), 1)) { - iColorType = COLORTYPE_GRAY; + iColorType = CFX_Color::kGray; fc[0] = FX_atof(syntax.GetWord()); return; } if (syntax.FindTagParamFromStart( (nOperation == PaintOperation::STROKE ? "RG" : "rg"), 3)) { - iColorType = COLORTYPE_RGB; + iColorType = CFX_Color::kRGB; fc[0] = FX_atof(syntax.GetWord()); fc[1] = FX_atof(syntax.GetWord()); fc[2] = FX_atof(syntax.GetWord()); @@ -134,7 +134,7 @@ void CPDF_DefaultAppearance::GetColor(int& iColorType, } if (syntax.FindTagParamFromStart( (nOperation == PaintOperation::STROKE ? "K" : "k"), 4)) { - iColorType = COLORTYPE_CMYK; + iColorType = CFX_Color::kCMYK; fc[0] = FX_atof(syntax.GetWord()); fc[1] = FX_atof(syntax.GetWord()); fc[2] = FX_atof(syntax.GetWord()); @@ -146,21 +146,21 @@ void CPDF_DefaultAppearance::GetColor(FX_ARGB& color, int& iColorType, PaintOperation nOperation) { color = 0; - iColorType = COLORTYPE_TRANSPARENT; + iColorType = CFX_Color::kTransparent; if (m_csDA.IsEmpty()) return; CPDF_SimpleParser syntax(m_csDA.AsStringView()); if (syntax.FindTagParamFromStart( (nOperation == PaintOperation::STROKE ? "G" : "g"), 1)) { - iColorType = COLORTYPE_GRAY; + iColorType = CFX_Color::kGray; float g = FX_atof(syntax.GetWord()) * 255 + 0.5f; color = ArgbEncode(255, (int)g, (int)g, (int)g); return; } if (syntax.FindTagParamFromStart( (nOperation == PaintOperation::STROKE ? "RG" : "rg"), 3)) { - iColorType = COLORTYPE_RGB; + iColorType = CFX_Color::kRGB; float r = FX_atof(syntax.GetWord()) * 255 + 0.5f; float g = FX_atof(syntax.GetWord()) * 255 + 0.5f; float b = FX_atof(syntax.GetWord()) * 255 + 0.5f; @@ -169,7 +169,7 @@ void CPDF_DefaultAppearance::GetColor(FX_ARGB& color, } if (syntax.FindTagParamFromStart( (nOperation == PaintOperation::STROKE ? "K" : "k"), 4)) { - iColorType = COLORTYPE_CMYK; + iColorType = CFX_Color::kCMYK; float c = FX_atof(syntax.GetWord()); float m = FX_atof(syntax.GetWord()); float y = FX_atof(syntax.GetWord()); diff --git a/core/fpdfdoc/cpdf_formcontrol.h b/core/fpdfdoc/cpdf_formcontrol.h index b22b074600..6485af0b44 100644 --- a/core/fpdfdoc/cpdf_formcontrol.h +++ b/core/fpdfdoc/cpdf_formcontrol.h @@ -28,11 +28,6 @@ #define TEXTPOS_LEFT 5 #define TEXTPOS_OVERLAID 6 -#define COLORTYPE_TRANSPARENT 0 -#define COLORTYPE_GRAY 1 -#define COLORTYPE_RGB 2 -#define COLORTYPE_CMYK 3 - class CFX_RenderDevice; class CPDF_Dictionary; class CPDF_Font; diff --git a/core/fpdfdoc/cpvt_color.cpp b/core/fpdfdoc/cpvt_color.cpp deleted file mode 100644 index 914e416dbd..0000000000 --- a/core/fpdfdoc/cpvt_color.cpp +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "core/fpdfdoc/cpvt_color.h" - -#include "core/fpdfapi/parser/cpdf_simple_parser.h" - -// Static. -CPVT_Color CPVT_Color::ParseColor(const ByteString& str) { - CPDF_SimpleParser syntax(str.AsStringView()); - if (syntax.FindTagParamFromStart("g", 1)) - return CPVT_Color(CPVT_Color::kGray, FX_atof(syntax.GetWord())); - - if (syntax.FindTagParamFromStart("rg", 3)) { - float f1 = FX_atof(syntax.GetWord()); - float f2 = FX_atof(syntax.GetWord()); - float f3 = FX_atof(syntax.GetWord()); - return CPVT_Color(CPVT_Color::kRGB, f1, f2, f3); - } - if (syntax.FindTagParamFromStart("k", 4)) { - float f1 = FX_atof(syntax.GetWord()); - float f2 = FX_atof(syntax.GetWord()); - float f3 = FX_atof(syntax.GetWord()); - float f4 = FX_atof(syntax.GetWord()); - return CPVT_Color(CPVT_Color::kCMYK, f1, f2, f3, f4); - } - return CPVT_Color(CPVT_Color::kTransparent); -} - -// Static. -CPVT_Color CPVT_Color::ParseColor(const CPDF_Array& array) { - CPVT_Color rt; - switch (array.GetCount()) { - case 1: - rt = CPVT_Color(CPVT_Color::kGray, array.GetFloatAt(0)); - break; - case 3: - rt = CPVT_Color(CPVT_Color::kRGB, array.GetFloatAt(0), - array.GetFloatAt(1), array.GetFloatAt(2)); - break; - case 4: - rt = CPVT_Color(CPVT_Color::kCMYK, array.GetFloatAt(0), - array.GetFloatAt(1), array.GetFloatAt(2), - array.GetFloatAt(3)); - break; - } - return rt; -} diff --git a/core/fpdfdoc/cpvt_color.h b/core/fpdfdoc/cpvt_color.h deleted file mode 100644 index a7e925bf79..0000000000 --- a/core/fpdfdoc/cpvt_color.h +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef CORE_FPDFDOC_CPVT_COLOR_H_ -#define CORE_FPDFDOC_CPVT_COLOR_H_ - -#include "core/fpdfapi/parser/cpdf_array.h" -#include "core/fxcrt/fx_string.h" -#include "core/fxcrt/fx_system.h" - -struct CPVT_Color { - enum Type { kTransparent = 0, kGray, kRGB, kCMYK }; - - CPVT_Color(Type type = kTransparent, - float color1 = 0.0f, - float color2 = 0.0f, - float color3 = 0.0f, - float color4 = 0.0f) - : nColorType(type), - fColor1(color1), - fColor2(color2), - fColor3(color3), - fColor4(color4) {} - - Type nColorType; - float fColor1; - float fColor2; - float fColor3; - float fColor4; - - static CPVT_Color ParseColor(const ByteString& str); - static CPVT_Color ParseColor(const CPDF_Array& array); -}; - -#endif // CORE_FPDFDOC_CPVT_COLOR_H_ diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp index 634864c957..ac3e7a51a0 100644 --- a/core/fpdfdoc/cpvt_generateap.cpp +++ b/core/fpdfdoc/cpvt_generateap.cpp @@ -12,6 +12,7 @@ #include #include "core/fpdfapi/font/cpdf_font.h" +#include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfapi/parser/cpdf_boolean.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" #include "core/fpdfapi/parser/cpdf_document.h" @@ -24,7 +25,6 @@ #include "core/fpdfapi/parser/fpdf_parser_decode.h" #include "core/fpdfdoc/cpdf_annot.h" #include "core/fpdfdoc/cpdf_formfield.h" -#include "core/fpdfdoc/cpvt_color.h" #include "core/fpdfdoc/cpvt_fontmap.h" #include "core/fpdfdoc/cpvt_word.h" #include "third_party/base/ptr_util.h" @@ -58,7 +58,7 @@ bool GenerateWidgetAP(CPDF_Document* pDoc, return false; float fFontSize = FX_atof(syntax.GetWord()); - CPVT_Color crText = CPVT_Color::ParseColor(DA); + CFX_Color crText = CFX_Color::ParseColor(DA); CPDF_Dictionary* pDRDict = pFormDict->GetDictFor("DR"); if (!pDRDict) return false; @@ -116,8 +116,8 @@ bool GenerateWidgetAP(CPDF_Document* pDoc, BorderStyle nBorderStyle = BorderStyle::SOLID; float fBorderWidth = 1; CPVT_Dash dsBorder(3, 0, 0); - CPVT_Color crLeftTop; - CPVT_Color crRightBottom; + CFX_Color crLeftTop; + CFX_Color crRightBottom; if (CPDF_Dictionary* pBSDict = pAnnotDict->GetDictFor("BS")) { if (pBSDict->KeyExist("W")) fBorderWidth = pBSDict->GetNumberFor("W"); @@ -137,14 +137,14 @@ bool GenerateWidgetAP(CPDF_Document* pDoc, case 'B': nBorderStyle = BorderStyle::BEVELED; fBorderWidth *= 2; - crLeftTop = CPVT_Color(CPVT_Color::kGray, 1); - crRightBottom = CPVT_Color(CPVT_Color::kGray, 0.5); + crLeftTop = CFX_Color(CFX_Color::kGray, 1); + crRightBottom = CFX_Color(CFX_Color::kGray, 0.5); break; case 'I': nBorderStyle = BorderStyle::INSET; fBorderWidth *= 2; - crLeftTop = CPVT_Color(CPVT_Color::kGray, 0.5); - crRightBottom = CPVT_Color(CPVT_Color::kGray, 0.75); + crLeftTop = CFX_Color(CFX_Color::kGray, 0.5); + crRightBottom = CFX_Color(CFX_Color::kGray, 0.75); break; case 'U': nBorderStyle = BorderStyle::UNDERLINE; @@ -152,13 +152,13 @@ bool GenerateWidgetAP(CPDF_Document* pDoc, } } } - CPVT_Color crBorder; - CPVT_Color crBG; + CFX_Color crBorder; + CFX_Color crBG; if (CPDF_Dictionary* pMKDict = pAnnotDict->GetDictFor("MK")) { if (CPDF_Array* pArray = pMKDict->GetArrayFor("BC")) - crBorder = CPVT_Color::ParseColor(*pArray); + crBorder = CFX_Color::ParseColor(*pArray); if (CPDF_Array* pArray = pMKDict->GetArrayFor("BG")) - crBG = CPVT_Color::ParseColor(*pArray); + crBG = CFX_Color::ParseColor(*pArray); } std::ostringstream sAppStream; ByteString sBG = CPVT_GenerateAP::GenerateColorAP(crBG, PaintOperation::FILL); @@ -320,8 +320,8 @@ bool GenerateWidgetAP(CPDF_Document* pDoc, << "Q\nEMC\n"; } ByteString sButton = CPVT_GenerateAP::GenerateColorAP( - CPVT_Color(CPVT_Color::kRGB, 220.0f / 255.0f, 220.0f / 255.0f, - 220.0f / 255.0f), + CFX_Color(CFX_Color::kRGB, 220.0f / 255.0f, 220.0f / 255.0f, + 220.0f / 255.0f), PaintOperation::FILL); if (sButton.GetLength() > 0 && !rcButton.IsEmpty()) { sAppStream << "q\n" << sButton; @@ -329,10 +329,9 @@ bool GenerateWidgetAP(CPDF_Document* pDoc, << rcButton.Width() << " " << rcButton.Height() << " re f\n"; sAppStream << "Q\n"; ByteString sButtonBorder = CPVT_GenerateAP::GenerateBorderAP( - rcButton, 2, CPVT_Color(CPVT_Color::kGray, 0), - CPVT_Color(CPVT_Color::kGray, 1), - CPVT_Color(CPVT_Color::kGray, 0.5), BorderStyle::BEVELED, - CPVT_Dash(3, 0, 0)); + rcButton, 2, CFX_Color(CFX_Color::kGray, 0), + CFX_Color(CFX_Color::kGray, 1), CFX_Color(CFX_Color::kGray, 0.5), + BorderStyle::BEVELED, CPVT_Dash(3, 0, 0)); if (sButtonBorder.GetLength() > 0) sAppStream << "q\n" << sButtonBorder << "Q\n"; @@ -398,16 +397,15 @@ bool GenerateWidgetAP(CPDF_Document* pDoc, 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), + CFX_Color(CFX_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), - PaintOperation::FILL) + CFX_Color(CFX_Color::kGray, 1), PaintOperation::FILL) << CPVT_GenerateAP::GenerateEditAP(&map, vt.GetIterator(), CFX_PointF(0.0f, fy), true, 0) @@ -461,10 +459,10 @@ bool GenerateWidgetAP(CPDF_Document* pDoc, } ByteString GetColorStringWithDefault(CPDF_Array* pColor, - const CPVT_Color& crDefaultColor, + const CFX_Color& crDefaultColor, PaintOperation nOperation) { if (pColor) { - CPVT_Color color = CPVT_Color::ParseColor(*pColor); + CFX_Color color = CFX_Color::ParseColor(*pColor); return CPVT_GenerateAP::GenerateColorAP(color, nOperation); } @@ -546,7 +544,7 @@ ByteString GetPopupContentsString(CPDF_Document* pDoc, std::ostringstream sAppStream; sAppStream << "BT\n" << CPVT_GenerateAP::GenerateColorAP( - CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), PaintOperation::FILL) + CFX_Color(CFX_Color::kRGB, 0, 0, 0), PaintOperation::FILL) << sContent << "ET\n" << "Q\n"; return ByteString(sAppStream); @@ -577,9 +575,9 @@ ByteString GetPaintOperatorString(bool bIsStrokeRect, bool bIsFillRect) { ByteString GenerateTextSymbolAP(const CFX_FloatRect& rect) { std::ostringstream sAppStream; sAppStream << CPVT_GenerateAP::GenerateColorAP( - CPVT_Color(CPVT_Color::kRGB, 1, 1, 0), PaintOperation::FILL); + CFX_Color(CFX_Color::kRGB, 1, 1, 0), PaintOperation::FILL); sAppStream << CPVT_GenerateAP::GenerateColorAP( - CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), PaintOperation::STROKE); + CFX_Color(CFX_Color::kRGB, 0, 0, 0), PaintOperation::STROKE); const float fBorderWidth = 1; sAppStream << fBorderWidth << " w\n"; @@ -687,12 +685,11 @@ bool CPVT_GenerateAP::GenerateCircleAP(CPDF_Document* pDoc, sAppStream << "/" << sExtGSDictName << " gs "; CPDF_Array* pInteriorColor = pAnnotDict->GetArrayFor("IC"); - sAppStream << GetColorStringWithDefault(pInteriorColor, - CPVT_Color(CPVT_Color::kTransparent), - PaintOperation::FILL); + sAppStream << GetColorStringWithDefault( + pInteriorColor, CFX_Color(CFX_Color::kTransparent), PaintOperation::FILL); sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayFor("C"), - CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), + CFX_Color(CFX_Color::kRGB, 0, 0, 0), PaintOperation::STROKE); float fBorderWidth = GetBorderWidth(*pAnnotDict); @@ -761,7 +758,7 @@ bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc, sAppStream << "/" << sExtGSDictName << " gs "; sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayFor("C"), - CPVT_Color(CPVT_Color::kRGB, 1, 1, 0), + CFX_Color(CFX_Color::kRGB, 1, 1, 0), PaintOperation::FILL); CFX_FloatRect rect = CPDF_Annot::RectFromQuadPoints(pAnnotDict); @@ -799,7 +796,7 @@ bool CPVT_GenerateAP::GenerateInkAP(CPDF_Document* pDoc, sAppStream << "/" << sExtGSDictName << " gs "; sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayFor("C"), - CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), + CFX_Color(CFX_Color::kRGB, 0, 0, 0), PaintOperation::STROKE); sAppStream << fBorderWidth << " w "; @@ -866,7 +863,7 @@ bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc, sAppStream << "/" << sExtGSDictName << " gs "; sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayFor("C"), - CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), + CFX_Color(CFX_Color::kRGB, 0, 0, 0), PaintOperation::STROKE); CFX_FloatRect rect = CPDF_Annot::RectFromQuadPoints(pAnnotDict); @@ -892,9 +889,9 @@ bool CPVT_GenerateAP::GeneratePopupAP(CPDF_Document* pDoc, ByteString sExtGSDictName = "GS"; sAppStream << "/" << sExtGSDictName << " gs\n"; - sAppStream << GenerateColorAP(CPVT_Color(CPVT_Color::kRGB, 1, 1, 0), + sAppStream << GenerateColorAP(CFX_Color(CFX_Color::kRGB, 1, 1, 0), PaintOperation::FILL); - sAppStream << GenerateColorAP(CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), + sAppStream << GenerateColorAP(CFX_Color(CFX_Color::kRGB, 0, 0, 0), PaintOperation::STROKE); const float fBorderWidth = 1; @@ -931,12 +928,11 @@ bool CPVT_GenerateAP::GenerateSquareAP(CPDF_Document* pDoc, sAppStream << "/" << sExtGSDictName << " gs "; CPDF_Array* pInteriorColor = pAnnotDict->GetArrayFor("IC"); - sAppStream << GetColorStringWithDefault(pInteriorColor, - CPVT_Color(CPVT_Color::kTransparent), - PaintOperation::FILL); + sAppStream << GetColorStringWithDefault( + pInteriorColor, CFX_Color(CFX_Color::kTransparent), PaintOperation::FILL); sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayFor("C"), - CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), + CFX_Color(CFX_Color::kRGB, 0, 0, 0), PaintOperation::STROKE); float fBorderWidth = GetBorderWidth(*pAnnotDict); @@ -979,7 +975,7 @@ bool CPVT_GenerateAP::GenerateSquigglyAP(CPDF_Document* pDoc, sAppStream << "/" << sExtGSDictName << " gs "; sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayFor("C"), - CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), + CFX_Color(CFX_Color::kRGB, 0, 0, 0), PaintOperation::STROKE); CFX_FloatRect rect = CPDF_Annot::RectFromQuadPoints(pAnnotDict); @@ -1028,7 +1024,7 @@ bool CPVT_GenerateAP::GenerateStrikeOutAP(CPDF_Document* pDoc, sAppStream << "/" << sExtGSDictName << " gs "; sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayFor("C"), - CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), + CFX_Color(CFX_Color::kRGB, 0, 0, 0), PaintOperation::STROKE); CFX_FloatRect rect = CPDF_Annot::RectFromQuadPoints(pAnnotDict); @@ -1135,9 +1131,9 @@ ByteString CPVT_GenerateAP::GenerateEditAP( // Static. ByteString CPVT_GenerateAP::GenerateBorderAP(const CFX_FloatRect& rect, float fWidth, - const CPVT_Color& color, - const CPVT_Color& crLeftTop, - const CPVT_Color& crRightBottom, + const CFX_Color& color, + const CFX_Color& crLeftTop, + const CFX_Color& crRightBottom, BorderStyle nStyle, const CPVT_Dash& dash) { std::ostringstream sAppStream; @@ -1240,28 +1236,28 @@ ByteString CPVT_GenerateAP::GenerateBorderAP(const CFX_FloatRect& rect, } // Static. -ByteString CPVT_GenerateAP::GenerateColorAP(const CPVT_Color& color, +ByteString CPVT_GenerateAP::GenerateColorAP(const CFX_Color& color, PaintOperation nOperation) { std::ostringstream sColorStream; switch (color.nColorType) { - case CPVT_Color::kRGB: + case CFX_Color::kRGB: sColorStream << color.fColor1 << " " << color.fColor2 << " " << color.fColor3 << " " << (nOperation == PaintOperation::STROKE ? "RG" : "rg") << "\n"; break; - case CPVT_Color::kGray: + case CFX_Color::kGray: sColorStream << color.fColor1 << " " << (nOperation == PaintOperation::STROKE ? "G" : "g") << "\n"; break; - case CPVT_Color::kCMYK: + case CFX_Color::kCMYK: sColorStream << color.fColor1 << " " << color.fColor2 << " " << color.fColor3 << " " << color.fColor4 << " " << (nOperation == PaintOperation::STROKE ? "K" : "k") << "\n"; break; - case CPVT_Color::kTransparent: + case CFX_Color::kTransparent: break; } return ByteString(sColorStream); diff --git a/core/fpdfdoc/cpvt_generateap.h b/core/fpdfdoc/cpvt_generateap.h index 2812b29a47..31962e237b 100644 --- a/core/fpdfdoc/cpvt_generateap.h +++ b/core/fpdfdoc/cpvt_generateap.h @@ -11,11 +11,11 @@ #include "core/fpdfdoc/cpdf_defaultappearance.h" #include "core/fpdfdoc/cpdf_variabletext.h" -#include "core/fpdfdoc/cpvt_color.h" #include "core/fpdfdoc/cpvt_dash.h" #include "core/fxcrt/fx_coordinates.h" #include "core/fxcrt/fx_string.h" #include "core/fxcrt/fx_system.h" +#include "core/fxge/cfx_color.h" class CPDF_Dictionary; class CPDF_Document; @@ -55,12 +55,12 @@ class CPVT_GenerateAP { uint16_t SubWord); static ByteString GenerateBorderAP(const CFX_FloatRect& rect, float fWidth, - const CPVT_Color& color, - const CPVT_Color& crLeftTop, - const CPVT_Color& crRightBottom, + const CFX_Color& color, + const CFX_Color& crLeftTop, + const CFX_Color& crRightBottom, BorderStyle nStyle, const CPVT_Dash& dash); - static ByteString GenerateColorAP(const CPVT_Color& color, + static ByteString GenerateColorAP(const CFX_Color& color, PaintOperation nOperation); static std::unique_ptr GenerateExtGStateDict( const CPDF_Dictionary& pAnnotDict, diff --git a/core/fxge/cfx_color.cpp b/core/fxge/cfx_color.cpp index eebdd2cf1c..42ab39d670 100644 --- a/core/fxge/cfx_color.cpp +++ b/core/fxge/cfx_color.cpp @@ -8,6 +8,9 @@ #include +#include "core/fpdfapi/parser/cpdf_array.h" +#include "core/fpdfapi/parser/cpdf_simple_parser.h" + namespace { bool InRange(float comp) { @@ -16,86 +19,127 @@ bool InRange(float comp) { CFX_Color ConvertCMYK2GRAY(float dC, float dM, float dY, float dK) { if (!InRange(dC) || !InRange(dM) || !InRange(dY) || !InRange(dK)) - return CFX_Color(COLORTYPE_GRAY); + return CFX_Color(CFX_Color::kGray); return CFX_Color( - COLORTYPE_GRAY, + CFX_Color::kGray, 1.0f - std::min(1.0f, 0.3f * dC + 0.59f * dM + 0.11f * dY + dK)); } CFX_Color ConvertGRAY2CMYK(float dGray) { if (!InRange(dGray)) - return CFX_Color(COLORTYPE_CMYK); - return CFX_Color(COLORTYPE_CMYK, 0.0f, 0.0f, 0.0f, 1.0f - dGray); + return CFX_Color(CFX_Color::kCMYK); + return CFX_Color(CFX_Color::kCMYK, 0.0f, 0.0f, 0.0f, 1.0f - dGray); } CFX_Color ConvertGRAY2RGB(float dGray) { if (!InRange(dGray)) - return CFX_Color(COLORTYPE_RGB); - return CFX_Color(COLORTYPE_RGB, dGray, dGray, dGray); + return CFX_Color(CFX_Color::kRGB); + return CFX_Color(CFX_Color::kRGB, dGray, dGray, dGray); } CFX_Color ConvertRGB2GRAY(float dR, float dG, float dB) { if (!InRange(dR) || !InRange(dG) || !InRange(dB)) - return CFX_Color(COLORTYPE_GRAY); - return CFX_Color(COLORTYPE_GRAY, 0.3f * dR + 0.59f * dG + 0.11f * dB); + return CFX_Color(CFX_Color::kGray); + return CFX_Color(CFX_Color::kGray, 0.3f * dR + 0.59f * dG + 0.11f * dB); } CFX_Color ConvertCMYK2RGB(float dC, float dM, float dY, float dK) { if (!InRange(dC) || !InRange(dM) || !InRange(dY) || !InRange(dK)) - return CFX_Color(COLORTYPE_RGB); - return CFX_Color(COLORTYPE_RGB, 1.0f - std::min(1.0f, dC + dK), + return CFX_Color(CFX_Color::kRGB); + return CFX_Color(CFX_Color::kRGB, 1.0f - std::min(1.0f, dC + dK), 1.0f - std::min(1.0f, dM + dK), 1.0f - std::min(1.0f, dY + dK)); } CFX_Color ConvertRGB2CMYK(float dR, float dG, float dB) { if (!InRange(dR) || !InRange(dG) || !InRange(dB)) - return CFX_Color(COLORTYPE_CMYK); + return CFX_Color(CFX_Color::kCMYK); float c = 1.0f - dR; float m = 1.0f - dG; float y = 1.0f - dB; - return CFX_Color(COLORTYPE_CMYK, c, m, y, std::min(c, std::min(m, y))); + return CFX_Color(CFX_Color::kCMYK, c, m, y, std::min(c, std::min(m, y))); } } // namespace +// Static. +CFX_Color CFX_Color::ParseColor(const CPDF_Array& array) { + CFX_Color rt; + switch (array.GetCount()) { + case 1: + rt = CFX_Color(CFX_Color::kGray, array.GetFloatAt(0)); + break; + case 3: + rt = CFX_Color(CFX_Color::kRGB, array.GetFloatAt(0), array.GetFloatAt(1), + array.GetFloatAt(2)); + break; + case 4: + rt = CFX_Color(CFX_Color::kCMYK, array.GetFloatAt(0), array.GetFloatAt(1), + array.GetFloatAt(2), array.GetFloatAt(3)); + break; + } + return rt; +} + +// Static. +CFX_Color CFX_Color::ParseColor(const ByteString& str) { + CPDF_SimpleParser syntax(str.AsStringView()); + if (syntax.FindTagParamFromStart("g", 1)) + return CFX_Color(CFX_Color::kGray, FX_atof(syntax.GetWord())); + + if (syntax.FindTagParamFromStart("rg", 3)) { + float f1 = FX_atof(syntax.GetWord()); + float f2 = FX_atof(syntax.GetWord()); + float f3 = FX_atof(syntax.GetWord()); + return CFX_Color(CFX_Color::kRGB, f1, f2, f3); + } + if (syntax.FindTagParamFromStart("k", 4)) { + float f1 = FX_atof(syntax.GetWord()); + float f2 = FX_atof(syntax.GetWord()); + float f3 = FX_atof(syntax.GetWord()); + float f4 = FX_atof(syntax.GetWord()); + return CFX_Color(CFX_Color::kCMYK, f1, f2, f3, f4); + } + return CFX_Color(CFX_Color::kTransparent); +} + CFX_Color CFX_Color::ConvertColorType(int32_t nConvertColorType) const { if (nColorType == nConvertColorType) return *this; CFX_Color ret; switch (nColorType) { - case COLORTYPE_TRANSPARENT: + case CFX_Color::kTransparent: ret = *this; - ret.nColorType = COLORTYPE_TRANSPARENT; + ret.nColorType = CFX_Color::kTransparent; break; - case COLORTYPE_GRAY: + case CFX_Color::kGray: switch (nConvertColorType) { - case COLORTYPE_RGB: + case CFX_Color::kRGB: ret = ConvertGRAY2RGB(fColor1); break; - case COLORTYPE_CMYK: + case CFX_Color::kCMYK: ret = ConvertGRAY2CMYK(fColor1); break; } break; - case COLORTYPE_RGB: + case CFX_Color::kRGB: switch (nConvertColorType) { - case COLORTYPE_GRAY: + case CFX_Color::kGray: ret = ConvertRGB2GRAY(fColor1, fColor2, fColor3); break; - case COLORTYPE_CMYK: + case CFX_Color::kCMYK: ret = ConvertRGB2CMYK(fColor1, fColor2, fColor3); break; } break; - case COLORTYPE_CMYK: + case CFX_Color::kCMYK: switch (nConvertColorType) { - case COLORTYPE_GRAY: + case CFX_Color::kGray: ret = ConvertCMYK2GRAY(fColor1, fColor2, fColor3, fColor4); break; - case COLORTYPE_RGB: + case CFX_Color::kRGB: ret = ConvertCMYK2RGB(fColor1, fColor2, fColor3, fColor4); break; } @@ -107,21 +151,21 @@ CFX_Color CFX_Color::ConvertColorType(int32_t nConvertColorType) const { FX_COLORREF CFX_Color::ToFXColor(int32_t nTransparency) const { CFX_Color ret; switch (nColorType) { - case COLORTYPE_TRANSPARENT: { - ret = CFX_Color(COLORTYPE_TRANSPARENT, 0, 0, 0, 0); + case CFX_Color::kTransparent: { + ret = CFX_Color(CFX_Color::kTransparent, 0, 0, 0, 0); break; } - case COLORTYPE_GRAY: { + case CFX_Color::kGray: { ret = ConvertGRAY2RGB(fColor1); ret.fColor4 = nTransparency; break; } - case COLORTYPE_RGB: { - ret = CFX_Color(COLORTYPE_RGB, fColor1, fColor2, fColor3); + case CFX_Color::kRGB: { + ret = CFX_Color(CFX_Color::kRGB, fColor1, fColor2, fColor3); ret.fColor4 = nTransparency; break; } - case COLORTYPE_CMYK: { + case CFX_Color::kCMYK: { ret = ConvertCMYK2RGB(fColor1, fColor2, fColor3, fColor4); ret.fColor4 = nTransparency; break; @@ -135,15 +179,15 @@ FX_COLORREF CFX_Color::ToFXColor(int32_t nTransparency) const { CFX_Color CFX_Color::operator-(float fColorSub) const { CFX_Color sRet(nColorType); switch (nColorType) { - case COLORTYPE_TRANSPARENT: - sRet.nColorType = COLORTYPE_RGB; + case CFX_Color::kTransparent: + sRet.nColorType = CFX_Color::kRGB; sRet.fColor1 = std::max(1.0f - fColorSub, 0.0f); sRet.fColor2 = std::max(1.0f - fColorSub, 0.0f); sRet.fColor3 = std::max(1.0f - fColorSub, 0.0f); break; - case COLORTYPE_RGB: - case COLORTYPE_GRAY: - case COLORTYPE_CMYK: + case CFX_Color::kRGB: + case CFX_Color::kGray: + case CFX_Color::kCMYK: sRet.fColor1 = std::max(fColor1 - fColorSub, 0.0f); sRet.fColor2 = std::max(fColor2 - fColorSub, 0.0f); sRet.fColor3 = std::max(fColor3 - fColorSub, 0.0f); @@ -156,15 +200,15 @@ CFX_Color CFX_Color::operator-(float fColorSub) const { CFX_Color CFX_Color::operator/(float fColorDivide) const { CFX_Color sRet(nColorType); switch (nColorType) { - case COLORTYPE_TRANSPARENT: - sRet.nColorType = COLORTYPE_RGB; + case CFX_Color::kTransparent: + sRet.nColorType = CFX_Color::kRGB; sRet.fColor1 = 1.0f / fColorDivide; sRet.fColor2 = 1.0f / fColorDivide; sRet.fColor3 = 1.0f / fColorDivide; break; - case COLORTYPE_RGB: - case COLORTYPE_GRAY: - case COLORTYPE_CMYK: + case CFX_Color::kRGB: + case CFX_Color::kGray: + case CFX_Color::kCMYK: sRet = *this; sRet.fColor1 /= fColorDivide; sRet.fColor2 /= fColorDivide; diff --git a/core/fxge/cfx_color.h b/core/fxge/cfx_color.h index b92c0bcc28..413c0a49c1 100644 --- a/core/fxge/cfx_color.h +++ b/core/fxge/cfx_color.h @@ -11,10 +11,15 @@ #include "core/fxge/fx_dib.h" struct CFX_Color { + static CFX_Color ParseColor(const CPDF_Array& array); + static CFX_Color ParseColor(const ByteString& str); + + enum Type { kTransparent = 0, kGray, kRGB, kCMYK }; + explicit CFX_Color(FX_COLORREF ref) : CFX_Color(FXARGB_R(ref), FXARGB_G(ref), FXARGB_B(ref)) {} - CFX_Color(int32_t type = COLORTYPE_TRANSPARENT, + CFX_Color(int32_t type = CFX_Color::kTransparent, float color1 = 0.0f, float color2 = 0.0f, float color3 = 0.0f, @@ -26,7 +31,7 @@ struct CFX_Color { fColor4(color4) {} CFX_Color(int32_t r, int32_t g, int32_t b) - : nColorType(COLORTYPE_RGB), + : nColorType(CFX_Color::kRGB), fColor1(r / 255.0f), fColor2(g / 255.0f), fColor3(b / 255.0f), @@ -40,7 +45,7 @@ struct CFX_Color { FX_COLORREF ToFXColor(int32_t nTransparency) const; void Reset() { - nColorType = COLORTYPE_TRANSPARENT; + nColorType = CFX_Color::kTransparent; fColor1 = 0.0f; fColor2 = 0.0f; fColor3 = 0.0f; diff --git a/fpdfsdk/cpdfsdk_widget.cpp b/fpdfsdk/cpdfsdk_widget.cpp index a859dcd374..c8bd4eaf08 100644 --- a/fpdfsdk/cpdfsdk_widget.cpp +++ b/fpdfsdk/cpdfsdk_widget.cpp @@ -562,14 +562,14 @@ bool CPDFSDK_Widget::GetFillColor(FX_COLORREF& color) const { CPDF_FormControl* pFormCtrl = GetFormControl(); int iColorType = 0; color = ARGBToColorRef(pFormCtrl->GetBackgroundColor(iColorType)); - return iColorType != COLORTYPE_TRANSPARENT; + return iColorType != CFX_Color::kTransparent; } bool CPDFSDK_Widget::GetBorderColor(FX_COLORREF& color) const { CPDF_FormControl* pFormCtrl = GetFormControl(); int iColorType = 0; color = ARGBToColorRef(pFormCtrl->GetBorderColor(iColorType)); - return iColorType != COLORTYPE_TRANSPARENT; + return iColorType != CFX_Color::kTransparent; } bool CPDFSDK_Widget::GetTextColor(FX_COLORREF& color) const { @@ -579,10 +579,10 @@ bool CPDFSDK_Widget::GetTextColor(FX_COLORREF& color) const { return false; FX_ARGB argb; - int iColorType = COLORTYPE_TRANSPARENT; + int iColorType = CFX_Color::kTransparent; da.GetColor(argb, iColorType); color = ARGBToColorRef(argb); - return iColorType != COLORTYPE_TRANSPARENT; + return iColorType != CFX_Color::kTransparent; } float CPDFSDK_Widget::GetFontSize() const { @@ -919,7 +919,7 @@ CFX_Matrix CPDFSDK_Widget::GetMatrix() const { } CFX_Color CPDFSDK_Widget::GetTextPWLColor() const { - CFX_Color crText = CFX_Color(COLORTYPE_GRAY, 0); + CFX_Color crText = CFX_Color(CFX_Color::kGray, 0); CPDF_FormControl* pFormCtrl = GetFormControl(); CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance(); diff --git a/fpdfsdk/formfiller/cffl_formfiller.cpp b/fpdfsdk/formfiller/cffl_formfiller.cpp index 8f48c029da..f86cb68c59 100644 --- a/fpdfsdk/formfiller/cffl_formfiller.cpp +++ b/fpdfsdk/formfiller/cffl_formfiller.cpp @@ -301,7 +301,7 @@ CPWL_Wnd::CreateParams CFFL_FormFiller::GetCreateParam() { if (m_pWidget->GetBorderColor(color)) cp.sBorderColor = CFX_Color(color); - cp.sTextColor = CFX_Color(COLORTYPE_GRAY, 0); + cp.sTextColor = CFX_Color(CFX_Color::kGray, 0); if (m_pWidget->GetTextColor(color)) cp.sTextColor = CFX_Color(color); diff --git a/fpdfsdk/fpdfannot.cpp b/fpdfsdk/fpdfannot.cpp index 3125ad1a82..a671032b1e 100644 --- a/fpdfsdk/fpdfannot.cpp +++ b/fpdfsdk/fpdfannot.cpp @@ -20,8 +20,8 @@ #include "core/fpdfdoc/cpdf_annot.h" #include "core/fpdfdoc/cpdf_formfield.h" #include "core/fpdfdoc/cpdf_interform.h" -#include "core/fpdfdoc/cpvt_color.h" #include "core/fpdfdoc/cpvt_generateap.h" +#include "core/fxge/cfx_color.h" #include "fpdfsdk/fsdk_define.h" namespace { @@ -536,24 +536,25 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_GetColor(FPDF_ANNOTATION annot, } return true; } - CPVT_Color color = CPVT_Color::ParseColor(*pColor); + + CFX_Color color = CFX_Color::ParseColor(*pColor); switch (color.nColorType) { - case CPVT_Color::kRGB: + case CFX_Color::kRGB: *R = color.fColor1 * 255.f; *G = color.fColor2 * 255.f; *B = color.fColor3 * 255.f; break; - case CPVT_Color::kGray: + case CFX_Color::kGray: *R = 255.f * color.fColor1; *G = 255.f * color.fColor1; *B = 255.f * color.fColor1; break; - case CPVT_Color::kCMYK: + case CFX_Color::kCMYK: *R = 255.f * (1 - color.fColor1) * (1 - color.fColor4); *G = 255.f * (1 - color.fColor2) * (1 - color.fColor4); *B = 255.f * (1 - color.fColor3) * (1 - color.fColor4); break; - case CPVT_Color::kTransparent: + case CFX_Color::kTransparent: *R = 0; *G = 0; *B = 0; diff --git a/fpdfsdk/javascript/Field.cpp b/fpdfsdk/javascript/Field.cpp index da0e60cc18..4e40e6fce5 100644 --- a/fpdfsdk/javascript/Field.cpp +++ b/fpdfsdk/javascript/Field.cpp @@ -1453,19 +1453,19 @@ bool Field::fillColor(CJS_Runtime* pRuntime, pFormControl->GetBackgroundColor(iColorType); CFX_Color color; - if (iColorType == COLORTYPE_TRANSPARENT) { - color = CFX_Color(COLORTYPE_TRANSPARENT); - } else if (iColorType == COLORTYPE_GRAY) { + if (iColorType == CFX_Color::kTransparent) { + color = CFX_Color(CFX_Color::kTransparent); + } else if (iColorType == CFX_Color::kGray) { + color = CFX_Color(CFX_Color::kGray, + pFormControl->GetOriginalBackgroundColor(0)); + } else if (iColorType == CFX_Color::kRGB) { color = - CFX_Color(COLORTYPE_GRAY, pFormControl->GetOriginalBackgroundColor(0)); - } else if (iColorType == COLORTYPE_RGB) { - color = - CFX_Color(COLORTYPE_RGB, pFormControl->GetOriginalBackgroundColor(0), + CFX_Color(CFX_Color::kRGB, pFormControl->GetOriginalBackgroundColor(0), pFormControl->GetOriginalBackgroundColor(1), pFormControl->GetOriginalBackgroundColor(2)); - } else if (iColorType == COLORTYPE_CMYK) { + } else if (iColorType == CFX_Color::kCMYK) { color = - CFX_Color(COLORTYPE_CMYK, pFormControl->GetOriginalBackgroundColor(0), + CFX_Color(CFX_Color::kCMYK, pFormControl->GetOriginalBackgroundColor(0), pFormControl->GetOriginalBackgroundColor(1), pFormControl->GetOriginalBackgroundColor(2), pFormControl->GetOriginalBackgroundColor(3)); @@ -2227,16 +2227,17 @@ bool Field::strokeColor(CJS_Runtime* pRuntime, pFormControl->GetBorderColor(iColorType); CFX_Color color; - if (iColorType == COLORTYPE_TRANSPARENT) { - color = CFX_Color(COLORTYPE_TRANSPARENT); - } else if (iColorType == COLORTYPE_GRAY) { - color = CFX_Color(COLORTYPE_GRAY, pFormControl->GetOriginalBorderColor(0)); - } else if (iColorType == COLORTYPE_RGB) { - color = CFX_Color(COLORTYPE_RGB, pFormControl->GetOriginalBorderColor(0), + if (iColorType == CFX_Color::kTransparent) { + color = CFX_Color(CFX_Color::kTransparent); + } else if (iColorType == CFX_Color::kGray) { + color = + CFX_Color(CFX_Color::kGray, pFormControl->GetOriginalBorderColor(0)); + } else if (iColorType == CFX_Color::kRGB) { + color = CFX_Color(CFX_Color::kRGB, pFormControl->GetOriginalBorderColor(0), pFormControl->GetOriginalBorderColor(1), pFormControl->GetOriginalBorderColor(2)); - } else if (iColorType == COLORTYPE_CMYK) { - color = CFX_Color(COLORTYPE_CMYK, pFormControl->GetOriginalBorderColor(0), + } else if (iColorType == CFX_Color::kCMYK) { + color = CFX_Color(CFX_Color::kCMYK, pFormControl->GetOriginalBorderColor(0), pFormControl->GetOriginalBorderColor(1), pFormControl->GetOriginalBorderColor(2), pFormControl->GetOriginalBorderColor(3)); @@ -2375,10 +2376,10 @@ bool Field::textColor(CJS_Runtime* pRuntime, std::tie(a, r, g, b) = ArgbDecode(color); CFX_Color crRet = - CFX_Color(COLORTYPE_RGB, r / 255.0f, g / 255.0f, b / 255.0f); + CFX_Color(CFX_Color::kRGB, r / 255.0f, g / 255.0f, b / 255.0f); - if (iColorType == COLORTYPE_TRANSPARENT) - crRet = CFX_Color(COLORTYPE_TRANSPARENT); + if (iColorType == CFX_Color::kTransparent) + crRet = CFX_Color(CFX_Color::kTransparent); color::ConvertPWLColorToArray(pRuntime, crRet, &crArray); vp << crArray; diff --git a/fpdfsdk/javascript/color.cpp b/fpdfsdk/javascript/color.cpp index 574c81a3c0..db860d37df 100644 --- a/fpdfsdk/javascript/color.cpp +++ b/fpdfsdk/javascript/color.cpp @@ -39,18 +39,18 @@ JSMethodSpec CJS_Color::MethodSpecs[] = {{"convert", convert_static}, IMPLEMENT_JS_CLASS(CJS_Color, color) color::color(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject) { - m_crTransparent = CFX_Color(COLORTYPE_TRANSPARENT); - m_crBlack = CFX_Color(COLORTYPE_GRAY, 0); - m_crWhite = CFX_Color(COLORTYPE_GRAY, 1); - m_crRed = CFX_Color(COLORTYPE_RGB, 1, 0, 0); - m_crGreen = CFX_Color(COLORTYPE_RGB, 0, 1, 0); - m_crBlue = CFX_Color(COLORTYPE_RGB, 0, 0, 1); - m_crCyan = CFX_Color(COLORTYPE_CMYK, 1, 0, 0, 0); - m_crMagenta = CFX_Color(COLORTYPE_CMYK, 0, 1, 0, 0); - m_crYellow = CFX_Color(COLORTYPE_CMYK, 0, 0, 1, 0); - m_crDKGray = CFX_Color(COLORTYPE_GRAY, 0.25); - m_crGray = CFX_Color(COLORTYPE_GRAY, 0.5); - m_crLTGray = CFX_Color(COLORTYPE_GRAY, 0.75); + m_crTransparent = CFX_Color(CFX_Color::kTransparent); + m_crBlack = CFX_Color(CFX_Color::kGray, 0); + m_crWhite = CFX_Color(CFX_Color::kGray, 1); + m_crRed = CFX_Color(CFX_Color::kRGB, 1, 0, 0); + m_crGreen = CFX_Color(CFX_Color::kRGB, 0, 1, 0); + m_crBlue = CFX_Color(CFX_Color::kRGB, 0, 0, 1); + m_crCyan = CFX_Color(CFX_Color::kCMYK, 1, 0, 0, 0); + m_crMagenta = CFX_Color(CFX_Color::kCMYK, 0, 1, 0, 0); + m_crYellow = CFX_Color(CFX_Color::kCMYK, 0, 0, 1, 0); + m_crDKGray = CFX_Color(CFX_Color::kGray, 0.25); + m_crGray = CFX_Color(CFX_Color::kGray, 0.5); + m_crLTGray = CFX_Color(CFX_Color::kGray, 0.75); } color::~color() {} @@ -59,20 +59,20 @@ void color::ConvertPWLColorToArray(CJS_Runtime* pRuntime, const CFX_Color& color, CJS_Array* array) { switch (color.nColorType) { - case COLORTYPE_TRANSPARENT: + case CFX_Color::kTransparent: array->SetElement(pRuntime, 0, CJS_Value(pRuntime, "T")); break; - case COLORTYPE_GRAY: + case CFX_Color::kGray: array->SetElement(pRuntime, 0, CJS_Value(pRuntime, "G")); array->SetElement(pRuntime, 1, CJS_Value(pRuntime, color.fColor1)); break; - case COLORTYPE_RGB: + case CFX_Color::kRGB: array->SetElement(pRuntime, 0, CJS_Value(pRuntime, "RGB")); array->SetElement(pRuntime, 1, CJS_Value(pRuntime, color.fColor1)); array->SetElement(pRuntime, 2, CJS_Value(pRuntime, color.fColor2)); array->SetElement(pRuntime, 3, CJS_Value(pRuntime, color.fColor3)); break; - case COLORTYPE_CMYK: + case CFX_Color::kCMYK: array->SetElement(pRuntime, 0, CJS_Value(pRuntime, "CMYK")); array->SetElement(pRuntime, 1, CJS_Value(pRuntime, color.fColor1)); array->SetElement(pRuntime, 2, CJS_Value(pRuntime, color.fColor2)); @@ -119,14 +119,14 @@ void color::ConvertArrayToPWLColor(CJS_Runtime* pRuntime, } if (sSpace == "T") { - *color = CFX_Color(COLORTYPE_TRANSPARENT); + *color = CFX_Color(CFX_Color::kTransparent); } else if (sSpace == "G") { - *color = CFX_Color(COLORTYPE_GRAY, (float)d1); + *color = CFX_Color(CFX_Color::kGray, (float)d1); } else if (sSpace == "RGB") { - *color = CFX_Color(COLORTYPE_RGB, (float)d1, (float)d2, (float)d3); + *color = CFX_Color(CFX_Color::kRGB, (float)d1, (float)d2, (float)d3); } else if (sSpace == "CMYK") { *color = - CFX_Color(COLORTYPE_CMYK, (float)d1, (float)d2, (float)d3, (float)d4); + CFX_Color(CFX_Color::kCMYK, (float)d1, (float)d2, (float)d3, (float)d4); } } @@ -226,16 +226,16 @@ bool color::convert(CJS_Runtime* pRuntime, ConvertArrayToPWLColor(pRuntime, aSource, &crSource); ByteString sDestSpace = params[1].ToCFXByteString(pRuntime); - int nColorType = COLORTYPE_TRANSPARENT; + int nColorType = CFX_Color::kTransparent; if (sDestSpace == "T") { - nColorType = COLORTYPE_TRANSPARENT; + nColorType = CFX_Color::kTransparent; } else if (sDestSpace == "G") { - nColorType = COLORTYPE_GRAY; + nColorType = CFX_Color::kGray; } else if (sDestSpace == "RGB") { - nColorType = COLORTYPE_RGB; + nColorType = CFX_Color::kRGB; } else if (sDestSpace == "CMYK") { - nColorType = COLORTYPE_CMYK; + nColorType = CFX_Color::kCMYK; } CJS_Array aDest; diff --git a/fpdfsdk/pwl/cpwl_appstream.cpp b/fpdfsdk/pwl/cpwl_appstream.cpp index 7d7f172f2f..27fa09bc31 100644 --- a/fpdfsdk/pwl/cpwl_appstream.cpp +++ b/fpdfsdk/pwl/cpwl_appstream.cpp @@ -104,19 +104,19 @@ ByteString GetColorAppStream(const CFX_Color& color, std::ostringstream sColorStream; switch (color.nColorType) { - case COLORTYPE_RGB: + case CFX_Color::kRGB: sColorStream << color.fColor1 << " " << color.fColor2 << " " << color.fColor3 << " " << (bFillOrStroke ? kSetRGBOperator : kSetRGBStrokedOperator) << "\n"; break; - case COLORTYPE_GRAY: + case CFX_Color::kGray: sColorStream << color.fColor1 << " " << (bFillOrStroke ? kSetGrayOperator : kSetGrayStrokedOperator) << "\n"; break; - case COLORTYPE_CMYK: + case CFX_Color::kCMYK: sColorStream << color.fColor1 << " " << color.fColor2 << " " << color.fColor3 << " " << color.fColor4 << " " << (bFillOrStroke ? kSetCMYKOperator @@ -1055,7 +1055,7 @@ ByteString GetDropButtonAppStream(const CFX_FloatRect& rcBBox) { std::ostringstream sAppStream; { AutoClosedQCommand q(&sAppStream); - sAppStream << GetColorAppStream(CFX_Color(COLORTYPE_RGB, 220.0f / 255.0f, + sAppStream << GetColorAppStream(CFX_Color(CFX_Color::kRGB, 220.0f / 255.0f, 220.0f / 255.0f, 220.0f / 255.0f), true) << rcBBox.left << " " << rcBBox.bottom << " " @@ -1067,9 +1067,9 @@ ByteString GetDropButtonAppStream(const CFX_FloatRect& rcBBox) { { AutoClosedQCommand q(&sAppStream); sAppStream << GetBorderAppStreamInternal( - rcBBox, 2, CFX_Color(COLORTYPE_GRAY, 0), CFX_Color(COLORTYPE_GRAY, 1), - CFX_Color(COLORTYPE_GRAY, 0.5), BorderStyle::BEVELED, - CPWL_Dash(3, 0, 0)); + rcBBox, 2, CFX_Color(CFX_Color::kGray, 0), + CFX_Color(CFX_Color::kGray, 1), CFX_Color(CFX_Color::kGray, 0.5), + BorderStyle::BEVELED, CPWL_Dash(3, 0, 0)); } CFX_PointF ptCenter = CFX_PointF((rcBBox.left + rcBBox.right) / 2, @@ -1164,20 +1164,20 @@ void CPWL_AppStream::SetAsPushButton() { break; case BorderStyle::BEVELED: fBorderWidth *= 2; - crLeftTop = CFX_Color(COLORTYPE_GRAY, 1); + crLeftTop = CFX_Color(CFX_Color::kGray, 1); crRightBottom = crBackground / 2.0f; break; case BorderStyle::INSET: fBorderWidth *= 2; - crLeftTop = CFX_Color(COLORTYPE_GRAY, 0.5); - crRightBottom = CFX_Color(COLORTYPE_GRAY, 0.75); + crLeftTop = CFX_Color(CFX_Color::kGray, 0.5); + crRightBottom = CFX_Color(CFX_Color::kGray, 0.75); break; default: break; } CFX_FloatRect rcClient = rcWindow.GetDeflated(fBorderWidth, fBorderWidth); - CFX_Color crText(COLORTYPE_GRAY, 0); + CFX_Color crText(CFX_Color::kGray, 0); ByteString csNameTag; CPDF_DefaultAppearance da = pControl->GetDefaultAppearance(); if (da.HasColor()) { @@ -1287,8 +1287,8 @@ void CPWL_AppStream::SetAsPushButton() { break; } case BorderStyle::INSET: { - crLeftTop = CFX_Color(COLORTYPE_GRAY, 0); - crRightBottom = CFX_Color(COLORTYPE_GRAY, 1); + crLeftTop = CFX_Color(CFX_Color::kGray, 0); + crRightBottom = CFX_Color(CFX_Color::kGray, 1); break; } default: @@ -1339,13 +1339,13 @@ void CPWL_AppStream::SetAsCheckBox() { break; case BorderStyle::BEVELED: fBorderWidth *= 2; - crLeftTop = CFX_Color(COLORTYPE_GRAY, 1); + crLeftTop = CFX_Color(CFX_Color::kGray, 1); crRightBottom = crBackground / 2.0f; break; case BorderStyle::INSET: fBorderWidth *= 2; - crLeftTop = CFX_Color(COLORTYPE_GRAY, 0.5); - crRightBottom = CFX_Color(COLORTYPE_GRAY, 0.75); + crLeftTop = CFX_Color(CFX_Color::kGray, 0.5); + crRightBottom = CFX_Color(CFX_Color::kGray, 0.75); break; default: break; @@ -1399,8 +1399,8 @@ void CPWL_AppStream::SetAsCheckBox() { break; } case BorderStyle::INSET: { - crLeftTop = CFX_Color(COLORTYPE_GRAY, 0); - crRightBottom = CFX_Color(COLORTYPE_GRAY, 1); + crLeftTop = CFX_Color(CFX_Color::kGray, 0); + crRightBottom = CFX_Color(CFX_Color::kGray, 1); break; } default: @@ -1455,13 +1455,13 @@ void CPWL_AppStream::SetAsRadioButton() { break; case BorderStyle::BEVELED: fBorderWidth *= 2; - crLeftTop = CFX_Color(COLORTYPE_GRAY, 1); + crLeftTop = CFX_Color(CFX_Color::kGray, 1); crRightBottom = crBackground / 2.0f; break; case BorderStyle::INSET: fBorderWidth *= 2; - crLeftTop = CFX_Color(COLORTYPE_GRAY, 0.5); - crRightBottom = CFX_Color(COLORTYPE_GRAY, 0.75); + crLeftTop = CFX_Color(CFX_Color::kGray, 0.5); + crRightBottom = CFX_Color(CFX_Color::kGray, 0.75); break; default: break; @@ -1504,11 +1504,11 @@ void CPWL_AppStream::SetAsRadioButton() { CFX_FloatRect rcCenter = rcWindow.GetCenterSquare().GetDeflated(1.0f, 1.0f); if (nStyle == CheckStyle::kCircle) { if (nBorderStyle == BorderStyle::BEVELED) { - crLeftTop = CFX_Color(COLORTYPE_GRAY, 1); + crLeftTop = CFX_Color(CFX_Color::kGray, 1); crRightBottom = crBackground - 0.25f; } else if (nBorderStyle == BorderStyle::INSET) { - crLeftTop = CFX_Color(COLORTYPE_GRAY, 0.5f); - crRightBottom = CFX_Color(COLORTYPE_GRAY, 0.75f); + crLeftTop = CFX_Color(CFX_Color::kGray, 0.5f); + crRightBottom = CFX_Color(CFX_Color::kGray, 0.75f); } csAP_N_ON = @@ -1532,8 +1532,8 @@ void CPWL_AppStream::SetAsRadioButton() { break; } case BorderStyle::INSET: { - crLeftTop = CFX_Color(COLORTYPE_GRAY, 0); - crRightBottom = CFX_Color(COLORTYPE_GRAY, 1); + crLeftTop = CFX_Color(CFX_Color::kGray, 0); + crRightBottom = CFX_Color(CFX_Color::kGray, 1); break; } default: @@ -1546,11 +1546,11 @@ void CPWL_AppStream::SetAsRadioButton() { CFX_Color crBK = crBackground - 0.25f; if (nBorderStyle == BorderStyle::BEVELED) { crLeftTop = crBackground - 0.25f; - crRightBottom = CFX_Color(COLORTYPE_GRAY, 1); + crRightBottom = CFX_Color(CFX_Color::kGray, 1); crBK = crBackground; } else if (nBorderStyle == BorderStyle::INSET) { - crLeftTop = CFX_Color(COLORTYPE_GRAY, 0); - crRightBottom = CFX_Color(COLORTYPE_GRAY, 1); + crLeftTop = CFX_Color(CFX_Color::kGray, 0); + crRightBottom = CFX_Color(CFX_Color::kGray, 1); } csAP_D_ON = @@ -1695,7 +1695,7 @@ void CPWL_AppStream::SetAsListBox() { CFX_FloatRect(rcClient.left, fy - fItemHeight, rcClient.right, fy); { AutoClosedQCommand q(&sList); - sList << GetColorAppStream(CFX_Color(COLORTYPE_RGB, 0, 51.0f / 255.0f, + sList << GetColorAppStream(CFX_Color(CFX_Color::kRGB, 0, 51.0f / 255.0f, 113.0f / 255.0f), true) << rcItem.left << " " << rcItem.bottom << " " << rcItem.Width() @@ -1704,7 +1704,7 @@ void CPWL_AppStream::SetAsListBox() { } AutoClosedCommand bt(&sList, kTextBeginOperator, kTextEndOperator); - sList << GetColorAppStream(CFX_Color(COLORTYPE_GRAY, 1), true) + sList << GetColorAppStream(CFX_Color(CFX_Color::kGray, 1), true) << GetEditAppStream(pEdit.get(), CFX_PointF(0.0f, fy), true, 0); } else { CFX_Color crText = widget_->GetTextPWLColor(); @@ -1953,7 +1953,7 @@ void CPWL_AppStream::Remove(const ByteString& sAPType) { ByteString CPWL_AppStream::GetBackgroundAppStream() const { CFX_Color crBackground = widget_->GetFillPWLColor(); - if (crBackground.nColorType != COLORTYPE_TRANSPARENT) + if (crBackground.nColorType != CFX_Color::kTransparent) return GetRectFillAppStream(widget_->GetRotatedRect(), crBackground); return ByteString(); @@ -1976,13 +1976,13 @@ ByteString CPWL_AppStream::GetBorderAppStream() const { break; case BorderStyle::BEVELED: fBorderWidth *= 2; - crLeftTop = CFX_Color(COLORTYPE_GRAY, 1); + crLeftTop = CFX_Color(CFX_Color::kGray, 1); crRightBottom = crBackground / 2.0f; break; case BorderStyle::INSET: fBorderWidth *= 2; - crLeftTop = CFX_Color(COLORTYPE_GRAY, 0.5); - crRightBottom = CFX_Color(COLORTYPE_GRAY, 0.75); + crLeftTop = CFX_Color(CFX_Color::kGray, 0.5); + crRightBottom = CFX_Color(CFX_Color::kGray, 0.75); break; default: break; diff --git a/fpdfsdk/pwl/cpwl_combo_box.cpp b/fpdfsdk/pwl/cpwl_combo_box.cpp index 92b01658f2..67d2d88f50 100644 --- a/fpdfsdk/pwl/cpwl_combo_box.cpp +++ b/fpdfsdk/pwl/cpwl_combo_box.cpp @@ -279,7 +279,7 @@ void CPWL_ComboBox::CreateButton(const CreateParams& cp) { CreateParams bcp = cp; bcp.pParentWnd = this; bcp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PWS_BACKGROUND; - bcp.sBackgroundColor = CFX_Color(COLORTYPE_RGB, 220.0f / 255.0f, + bcp.sBackgroundColor = CFX_Color(CFX_Color::kRGB, 220.0f / 255.0f, 220.0f / 255.0f, 220.0f / 255.0f); bcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR; bcp.dwBorderWidth = 2; @@ -309,10 +309,10 @@ void CPWL_ComboBox::CreateListBox(const CreateParams& cp) { else lcp.fFontSize = cp.fFontSize; - if (cp.sBorderColor.nColorType == COLORTYPE_TRANSPARENT) + if (cp.sBorderColor.nColorType == CFX_Color::kTransparent) lcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR; - if (cp.sBackgroundColor.nColorType == COLORTYPE_TRANSPARENT) + if (cp.sBackgroundColor.nColorType == CFX_Color::kTransparent) lcp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR; m_pList->Create(lcp); diff --git a/fpdfsdk/pwl/cpwl_scroll_bar.cpp b/fpdfsdk/pwl/cpwl_scroll_bar.cpp index 58a874531f..3ec936730e 100644 --- a/fpdfsdk/pwl/cpwl_scroll_bar.cpp +++ b/fpdfsdk/pwl/cpwl_scroll_bar.cpp @@ -22,7 +22,7 @@ constexpr float kTriangleHalfLength = 2.0f; } // namespace -#define PWL_DEFAULT_HEAVYGRAYCOLOR CFX_Color(COLORTYPE_GRAY, 0.50) +#define PWL_DEFAULT_HEAVYGRAYCOLOR CFX_Color(CFX_Color::kGray, 0.50) PWL_FLOATRANGE::PWL_FLOATRANGE() { Default(); diff --git a/fpdfsdk/pwl/cpwl_wnd.cpp b/fpdfsdk/pwl/cpwl_wnd.cpp index 124065cdf9..ec605a3844 100644 --- a/fpdfsdk/pwl/cpwl_wnd.cpp +++ b/fpdfsdk/pwl/cpwl_wnd.cpp @@ -716,9 +716,9 @@ IPVT_FontMap* CPWL_Wnd::GetFontMap() const { CFX_Color CPWL_Wnd::GetBorderLeftTopColor(BorderStyle nBorderStyle) const { switch (nBorderStyle) { case BorderStyle::BEVELED: - return CFX_Color(COLORTYPE_GRAY, 1); + return CFX_Color(CFX_Color::kGray, 1); case BorderStyle::INSET: - return CFX_Color(COLORTYPE_GRAY, 0.5f); + return CFX_Color(CFX_Color::kGray, 0.5f); default: return CFX_Color(); } @@ -729,7 +729,7 @@ CFX_Color CPWL_Wnd::GetBorderRightBottomColor(BorderStyle nBorderStyle) const { case BorderStyle::BEVELED: return GetBackgroundColor() / 2.0f; case BorderStyle::INSET: - return CFX_Color(COLORTYPE_GRAY, 0.75f); + return CFX_Color(CFX_Color::kGray, 0.75f); default: return CFX_Color(); } diff --git a/fpdfsdk/pwl/cpwl_wnd.h b/fpdfsdk/pwl/cpwl_wnd.h index 38d4ce0918..a9a434dbd1 100644 --- a/fpdfsdk/pwl/cpwl_wnd.h +++ b/fpdfsdk/pwl/cpwl_wnd.h @@ -95,8 +95,8 @@ inline bool operator!=(const CFX_Color& c1, const CFX_Color& c2) { #define PWL_SCROLLBAR_WIDTH 12.0f #define PWL_SCROLLBAR_TRANSPARENCY 150 -#define PWL_DEFAULT_BLACKCOLOR CFX_Color(COLORTYPE_GRAY, 0) -#define PWL_DEFAULT_WHITECOLOR CFX_Color(COLORTYPE_GRAY, 1) +#define PWL_DEFAULT_BLACKCOLOR CFX_Color(CFX_Color::kGray, 0) +#define PWL_DEFAULT_WHITECOLOR CFX_Color(CFX_Color::kGray, 1) class CPWL_Wnd : public CPWL_TimerHandler, public Observable { public: -- cgit v1.2.3