Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cpdf_color_utils.cpp
Go to the documentation of this file.
1// Copyright 2019 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#include "core/fpdfdoc/cpdf_color_utils.h"
8
9#include "core/fpdfapi/parser/cpdf_array.h"
10#include "core/fpdfdoc/cpdf_defaultappearance.h"
11#include "core/fxcrt/bytestring.h"
12#include "third_party/base/notreached.h"
13
14namespace fpdfdoc {
15
16CFX_Color CFXColorFromArray(const CPDF_Array& array) {
17 CFX_Color rt;
18 switch (array.size()) {
19 case 1:
20 rt = CFX_Color(CFX_Color::Type::kGray, array.GetFloatAt(0));
21 break;
22 case 3:
23 rt = CFX_Color(CFX_Color::Type::kRGB, array.GetFloatAt(0),
24 array.GetFloatAt(1), array.GetFloatAt(2));
25 break;
26 case 4:
27 rt = CFX_Color(CFX_Color::Type::kCMYK, array.GetFloatAt(0),
28 array.GetFloatAt(1), array.GetFloatAt(2),
29 array.GetFloatAt(3));
30 break;
31 }
32 return rt;
33}
34
35CFX_Color CFXColorFromString(const ByteString& str) {
36 CPDF_DefaultAppearance appearance(str);
37 return appearance.GetColor().value_or(CFX_Color());
38}
39
40} // namespace fpdfdoc
CPDF_DefaultAppearance(const ByteString &csDA)
CFX_Color CFXColorFromArray(const CPDF_Array &array)
CFX_Color CFXColorFromString(const ByteString &str)
CFX_Color & operator=(const CFX_Color &that)=default
constexpr CFX_Color(Type type=CFX_Color::Type::kTransparent, float color1=0.0f, float color2=0.0f, float color3=0.0f, float color4=0.0f)
Definition cfx_color.h:27