summaryrefslogtreecommitdiff
path: root/core/fxge
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2018-03-28 20:00:35 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-03-28 20:00:35 +0000
commit53a8093c6ef694ec520fe0b087fbac86af97f5e8 (patch)
tree519a805d66eed415e310eb67a05212c6d217025d /core/fxge
parent971a674ef17526ad37ce55ba90110830b94889d0 (diff)
downloadpdfium-53a8093c6ef694ec520fe0b087fbac86af97f5e8.tar.xz
Use CPDF_DefaultAppearance instead of custom parsing
This CL moves code over to using CPDF_DefaultAppearance instead of calling the CPDF_SimpleParser directly. This means the code for finding a specific tag start can move into CPDF_DefaultAppearance directly. Change-Id: I1dc64e54aedd03d059b963121d466f3eb75c17db Reviewed-on: https://pdfium-review.googlesource.com/28410 Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fxge')
-rw-r--r--core/fxge/cfx_color.cpp36
1 files changed, 19 insertions, 17 deletions
diff --git a/core/fxge/cfx_color.cpp b/core/fxge/cfx_color.cpp
index 42ab39d670..5175adc50a 100644
--- a/core/fxge/cfx_color.cpp
+++ b/core/fxge/cfx_color.cpp
@@ -9,7 +9,7 @@
#include <algorithm>
#include "core/fpdfapi/parser/cpdf_array.h"
-#include "core/fpdfapi/parser/cpdf_simple_parser.h"
+#include "core/fpdfdoc/cpdf_defaultappearance.h"
namespace {
@@ -84,23 +84,25 @@ CFX_Color CFX_Color::ParseColor(const CPDF_Array& array) {
// 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);
+ CPDF_DefaultAppearance appearance(str);
+ ASSERT(appearance.HasColor());
+
+ int color_type;
+ float values[4];
+ appearance.GetColor(color_type, values);
+
+ if (color_type == CFX_Color::kTransparent)
+ return CFX_Color(CFX_Color::kTransparent);
+ if (color_type == CFX_Color::kGray)
+ return CFX_Color(CFX_Color::kGray, values[0]);
+ if (color_type == CFX_Color::kRGB)
+ return CFX_Color(CFX_Color::kRGB, values[0], values[1], values[2]);
+ if (color_type == CFX_Color::kCMYK) {
+ return CFX_Color(CFX_Color::kCMYK, values[0], values[1], values[2],
+ values[3]);
}
+
+ NOTREACHED();
return CFX_Color(CFX_Color::kTransparent);
}