summaryrefslogtreecommitdiff
path: root/core/fxge
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-10-23 21:38:28 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-10-23 21:38:28 +0000
commit5ff1ddeb54a425e1af25607646697e93a39bd51d (patch)
tree31266c1e22ab146883cc165bc7925a341ce28a9d /core/fxge
parent401077e47c49c3b1cb865ee6f1f29a931a6ca45b (diff)
downloadpdfium-5ff1ddeb54a425e1af25607646697e93a39bd51d.tar.xz
Test color.convert() and equal() from JS (and fix comparison logic).
Currently, color.equal(a, b) may not give the same result as color.equal(b, a) since arg1 is converted to be the type of arg2, and some of these conversions lose information. Instead promote to the type with the most components in the hope of preserving the most information. Better error message when there are the right number of parameters but the types are wrong. Change-Id: I1d93fa29db4fb65e0f7c07c3ba7d9ca87ebf7bc9 Reviewed-on: https://pdfium-review.googlesource.com/c/44413 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fxge')
-rw-r--r--core/fxge/cfx_color.cpp9
-rw-r--r--core/fxge/cfx_color.h1
2 files changed, 10 insertions, 0 deletions
diff --git a/core/fxge/cfx_color.cpp b/core/fxge/cfx_color.cpp
index e4d89dc2ff..a19f040e51 100644
--- a/core/fxge/cfx_color.cpp
+++ b/core/fxge/cfx_color.cpp
@@ -11,6 +11,15 @@
#include "core/fpdfapi/parser/cpdf_array.h"
#include "core/fpdfdoc/cpdf_defaultappearance.h"
+// Color types are orded by increasing number of components so we can
+// choose a best color type during some conversions.
+static_assert(CFX_Color::kTransparent < CFX_Color::kGray,
+ "color type values must be ordered");
+static_assert(CFX_Color::kGray < CFX_Color::kRGB,
+ "color type values must be ordered");
+static_assert(CFX_Color::kRGB < CFX_Color::kCMYK,
+ "color type values must be ordered");
+
namespace {
bool InRange(float comp) {
diff --git a/core/fxge/cfx_color.h b/core/fxge/cfx_color.h
index d6fabad989..1dd512a42d 100644
--- a/core/fxge/cfx_color.h
+++ b/core/fxge/cfx_color.h
@@ -14,6 +14,7 @@ struct CFX_Color {
static CFX_Color ParseColor(const CPDF_Array& array);
static CFX_Color ParseColor(const ByteString& str);
+ // Ordered by increasing number of components.
enum Type { kTransparent = 0, kGray, kRGB, kCMYK };
explicit CFX_Color(FX_COLORREF ref)