summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/fpdfdoc/cpdf_defaultappearance.cpp39
-rw-r--r--core/fpdfdoc/cpdf_defaultappearance.h5
-rw-r--r--core/fxge/cfx_color.cpp12
3 files changed, 21 insertions, 35 deletions
diff --git a/core/fpdfdoc/cpdf_defaultappearance.cpp b/core/fpdfdoc/cpdf_defaultappearance.cpp
index 161f90e014..4efb0655b4 100644
--- a/core/fpdfdoc/cpdf_defaultappearance.cpp
+++ b/core/fpdfdoc/cpdf_defaultappearance.cpp
@@ -68,64 +68,53 @@ Optional<ByteString> CPDF_DefaultAppearance::GetFont(float* fFontSize) {
return {PDF_NameDecode(csFontNameTag.AsStringView())};
}
-bool CPDF_DefaultAppearance::HasColor() {
- if (m_csDA.IsEmpty())
- return false;
-
- CPDF_SimpleParser syntax(m_csDA.AsStringView());
- if (FindTagParamFromStart(&syntax, "g", 1))
- return true;
- if (FindTagParamFromStart(&syntax, "rg", 3))
- return true;
- return FindTagParamFromStart(&syntax, "k", 4);
-}
-
-CFX_Color::Type CPDF_DefaultAppearance::GetColor(float fc[4]) {
+Optional<CFX_Color::Type> CPDF_DefaultAppearance::GetColor(float fc[4]) {
for (int c = 0; c < 4; c++)
fc[c] = 0;
if (m_csDA.IsEmpty())
- return CFX_Color::kTransparent;
+ return {};
CPDF_SimpleParser syntax(m_csDA.AsStringView());
if (FindTagParamFromStart(&syntax, "g", 1)) {
fc[0] = FX_atof(syntax.GetWord());
- return CFX_Color::kGray;
+ return {CFX_Color::kGray};
}
if (FindTagParamFromStart(&syntax, "rg", 3)) {
fc[0] = FX_atof(syntax.GetWord());
fc[1] = FX_atof(syntax.GetWord());
fc[2] = FX_atof(syntax.GetWord());
- return CFX_Color::kRGB;
+ return {CFX_Color::kRGB};
}
if (FindTagParamFromStart(&syntax, "k", 4)) {
fc[0] = FX_atof(syntax.GetWord());
fc[1] = FX_atof(syntax.GetWord());
fc[2] = FX_atof(syntax.GetWord());
fc[3] = FX_atof(syntax.GetWord());
- return CFX_Color::kCMYK;
+ return {CFX_Color::kCMYK};
}
- return CFX_Color::kTransparent;
+ return {};
}
-std::pair<CFX_Color::Type, FX_ARGB> CPDF_DefaultAppearance::GetColor() {
+std::pair<Optional<CFX_Color::Type>, FX_ARGB>
+CPDF_DefaultAppearance::GetColor() {
float values[4];
- CFX_Color::Type type = GetColor(values);
- if (type == CFX_Color::kTransparent)
+ Optional<CFX_Color::Type> type = GetColor(values);
+ if (!type)
return {type, 0};
- if (type == CFX_Color::kGray) {
+ if (*type == CFX_Color::kGray) {
int g = static_cast<int>(values[0] * 255 + 0.5f);
return {type, ArgbEncode(255, g, g, g)};
}
- if (type == CFX_Color::kRGB) {
+ if (*type == CFX_Color::kRGB) {
int r = static_cast<int>(values[0] * 255 + 0.5f);
int g = static_cast<int>(values[1] * 255 + 0.5f);
int b = static_cast<int>(values[2] * 255 + 0.5f);
return {type, ArgbEncode(255, r, g, b)};
}
- if (type == CFX_Color::kCMYK) {
+ if (*type == CFX_Color::kCMYK) {
float r = 1.0f - std::min(1.0f, values[0] + values[3]);
float g = 1.0f - std::min(1.0f, values[1] + values[3]);
float b = 1.0f - std::min(1.0f, values[2] + values[3]);
@@ -134,7 +123,7 @@ std::pair<CFX_Color::Type, FX_ARGB> CPDF_DefaultAppearance::GetColor() {
static_cast<int>(b * 255 + 0.5f))};
}
NOTREACHED();
- return {CFX_Color::kTransparent, 0};
+ return {{}, 0};
}
bool CPDF_DefaultAppearance::FindTagParamFromStartForTesting(
diff --git a/core/fpdfdoc/cpdf_defaultappearance.h b/core/fpdfdoc/cpdf_defaultappearance.h
index ae3c4f5517..73e35c7cd4 100644
--- a/core/fpdfdoc/cpdf_defaultappearance.h
+++ b/core/fpdfdoc/cpdf_defaultappearance.h
@@ -27,9 +27,8 @@ class CPDF_DefaultAppearance {
Optional<ByteString> GetFont(float* fFontSize);
- bool HasColor();
- CFX_Color::Type GetColor(float fc[4]);
- std::pair<CFX_Color::Type, FX_ARGB> GetColor();
+ Optional<CFX_Color::Type> GetColor(float fc[4]);
+ std::pair<Optional<CFX_Color::Type>, FX_ARGB> GetColor();
bool FindTagParamFromStartForTesting(CPDF_SimpleParser* parser,
const ByteStringView& token,
diff --git a/core/fxge/cfx_color.cpp b/core/fxge/cfx_color.cpp
index 8a2f42d920..19d1d4fd24 100644
--- a/core/fxge/cfx_color.cpp
+++ b/core/fxge/cfx_color.cpp
@@ -85,17 +85,15 @@ CFX_Color CFX_Color::ParseColor(const CPDF_Array& array) {
// Static.
CFX_Color CFX_Color::ParseColor(const ByteString& str) {
CPDF_DefaultAppearance appearance(str);
- ASSERT(appearance.HasColor());
-
float values[4];
- int color_type = appearance.GetColor(values);
- if (color_type == CFX_Color::kTransparent)
+ Optional<CFX_Color::Type> color_type = appearance.GetColor(values);
+ if (!color_type || *color_type == CFX_Color::kTransparent)
return CFX_Color(CFX_Color::kTransparent);
- if (color_type == CFX_Color::kGray)
+ if (*color_type == CFX_Color::kGray)
return CFX_Color(CFX_Color::kGray, values[0]);
- if (color_type == CFX_Color::kRGB)
+ if (*color_type == CFX_Color::kRGB)
return CFX_Color(CFX_Color::kRGB, values[0], values[1], values[2]);
- if (color_type == CFX_Color::kCMYK) {
+ if (*color_type == CFX_Color::kCMYK) {
return CFX_Color(CFX_Color::kCMYK, values[0], values[1], values[2],
values[3]);
}