From 5ff1ddeb54a425e1af25607646697e93a39bd51d Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Tue, 23 Oct 2018 21:38:28 +0000 Subject: 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 Commit-Queue: Tom Sepez --- core/fxge/cfx_color.cpp | 9 +++++++++ core/fxge/cfx_color.h | 1 + 2 files changed, 10 insertions(+) (limited to 'core') 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) -- cgit v1.2.3