From 28bb2f2ffe751cf4142329e27238da52ae9f848b Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Tue, 3 Apr 2018 19:52:27 +0000 Subject: Remove DefaultAppearance HasColor and return an optional instead This CL converts CPDF_DefaultAppearance to return Optional items instead of having a HasColor. This saves the double parse of the appearance stream. Change-Id: Ib3c136da6e2adfb559e495de1d299cce0b4ad25f Reviewed-on: https://pdfium-review.googlesource.com/29630 Reviewed-by: Henrique Nakashima Commit-Queue: dsinclair --- core/fxge/cfx_color.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'core/fxge') 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 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]); } -- cgit v1.2.3