summaryrefslogtreecommitdiff
path: root/core/fpdfdoc/cpdf_defaultappearance.cpp
diff options
context:
space:
mode:
authordan sinclair <dsinclair@chromium.org>2018-03-09 22:54:11 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-03-09 22:54:11 +0000
commit073b99d51c7a964e5b97278f88ed9ebe917b62d3 (patch)
tree5da4d14072d0db6419bc712201acc23f4f2cfe4d /core/fpdfdoc/cpdf_defaultappearance.cpp
parent0d0d3ad30ca8ec3d0bd04a92f89882409c1a14ff (diff)
downloadpdfium-073b99d51c7a964e5b97278f88ed9ebe917b62d3.tar.xz
Cleanup CPDF_DefaultAppearance
Minor cleanups and refactoring of the CPDF_DefaultAppearance class. Change-Id: I7b3de021e8a6a1e9ca1d70ae413f3c433627f3fd Reviewed-on: https://pdfium-review.googlesource.com/28390 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Diffstat (limited to 'core/fpdfdoc/cpdf_defaultappearance.cpp')
-rw-r--r--core/fpdfdoc/cpdf_defaultappearance.cpp42
1 files changed, 18 insertions, 24 deletions
diff --git a/core/fpdfdoc/cpdf_defaultappearance.cpp b/core/fpdfdoc/cpdf_defaultappearance.cpp
index 4542c59a7d..ba0679a19a 100644
--- a/core/fpdfdoc/cpdf_defaultappearance.cpp
+++ b/core/fpdfdoc/cpdf_defaultappearance.cpp
@@ -79,35 +79,29 @@ void CPDF_DefaultAppearance::GetColor(int& iColorType, float fc[4]) {
void CPDF_DefaultAppearance::GetColor(FX_ARGB& color, int& iColorType) {
color = 0;
- iColorType = CFX_Color::kTransparent;
- if (m_csDA.IsEmpty())
+ float values[4];
+ GetColor(iColorType, values);
+ if (iColorType == CFX_Color::kTransparent)
return;
- CPDF_SimpleParser syntax(m_csDA.AsStringView());
- if (syntax.FindTagParamFromStart("g", 1)) {
- iColorType = CFX_Color::kGray;
- float g = FX_atof(syntax.GetWord()) * 255 + 0.5f;
- color = ArgbEncode(255, (int)g, (int)g, (int)g);
+ if (iColorType == CFX_Color::kGray) {
+ int g = static_cast<int>(values[0] * 255 + 0.5f);
+ color = ArgbEncode(255, g, g, g);
return;
}
- if (syntax.FindTagParamFromStart("rg", 3)) {
- 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;
- color = ArgbEncode(255, (int)r, (int)g, (int)b);
+ if (iColorType == 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);
+ color = ArgbEncode(255, r, g, b);
return;
}
- if (syntax.FindTagParamFromStart("k", 4)) {
- iColorType = CFX_Color::kCMYK;
- float c = FX_atof(syntax.GetWord());
- float m = FX_atof(syntax.GetWord());
- float y = FX_atof(syntax.GetWord());
- float k = FX_atof(syntax.GetWord());
- float r = 1.0f - std::min(1.0f, c + k);
- float g = 1.0f - std::min(1.0f, m + k);
- float b = 1.0f - std::min(1.0f, y + k);
- color = ArgbEncode(255, (int)(r * 255 + 0.5f), (int)(g * 255 + 0.5f),
- (int)(b * 255 + 0.5f));
+ if (iColorType == 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]);
+ color = ArgbEncode(255, static_cast<int>(r * 255 + 0.5f),
+ static_cast<int>(g * 255 + 0.5f),
+ static_cast<int>(b * 255 + 0.5f));
}
}