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
cxfa_color.cpp
Go to the documentation of this file.
1// Copyright 2017 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 "xfa/fxfa/parser/cxfa_color.h"
8
9#include "core/fxcrt/fx_extension.h"
10#include "fxjs/xfa/cjx_node.h"
11#include "xfa/fgas/graphics/cfgas_gecolor.h"
12#include "xfa/fxfa/parser/cxfa_document.h"
13
14namespace {
15
16const CXFA_Node::PropertyData kColorPropertyData[] = {
17 {XFA_Element::Extras, 1, {}},
18};
19
20const CXFA_Node::AttributeData kColorAttributeData[] = {
23 {XFA_Attribute::CSpace, XFA_AttributeType::CData, (void*)L"SRGB"},
24 {XFA_Attribute::Usehref, XFA_AttributeType::CData, nullptr},
25 {XFA_Attribute::Value, XFA_AttributeType::CData, nullptr},
26};
27
28} // namespace
29
30// static
32 static constexpr FX_ARGB kDefaultValue = 0xff000000;
33 if (view.IsEmpty())
34 return kDefaultValue;
35
36 pdfium::span<const wchar_t> str = view.span();
37 size_t cc = 0;
38 while (cc < str.size() && FXSYS_iswspace(str[cc])) {
39 cc++;
40 }
41
42 if (cc >= str.size()) {
43 return kDefaultValue;
44 }
45
46 uint8_t r = 0;
47 uint8_t g = 0;
48 uint8_t b = 0;
49 while (cc < str.size()) {
50 if (str[cc] == ',' || !FXSYS_IsDecimalDigit(str[cc]))
51 break;
52
53 r = r * 10 + str[cc] - '0';
54 cc++;
55 }
56 if (cc < str.size() && str[cc] == ',') {
57 cc++;
58 while (cc < str.size() && FXSYS_iswspace(str[cc])) {
59 cc++;
60 }
61
62 while (cc < str.size()) {
63 if (str[cc] == ',' || !FXSYS_IsDecimalDigit(str[cc]))
64 break;
65
66 g = g * 10 + str[cc] - '0';
67 cc++;
68 }
69 if (cc < str.size() && str[cc] == ',') {
70 cc++;
71 while (cc < str.size() && FXSYS_iswspace(str[cc])) {
72 cc++;
73 }
74
75 while (cc < str.size()) {
76 if (str[cc] == ',' || !FXSYS_IsDecimalDigit(str[cc]))
77 break;
78
79 b = b * 10 + str[cc] - '0';
80 cc++;
81 }
82 }
83 }
84 return ArgbEncode(0xFF, r, g, b);
85}
86
87CXFA_Color::CXFA_Color(CXFA_Document* doc, XFA_PacketType packet)
88 : CXFA_Node(doc,
89 packet,
90 {XFA_XDPPACKET::kTemplate, XFA_XDPPACKET::kForm},
91 XFA_ObjectType::Node,
92 XFA_Element::Color,
93 kColorPropertyData,
94 kColorAttributeData,
95 cppgc::MakeGarbageCollected<CJX_Node>(
96 doc->GetHeap()->GetAllocationHandle(),
97 this)) {}
98
99CXFA_Color::~CXFA_Color() = default;
100
101FX_ARGB CXFA_Color::GetValue() const {
102 std::optional<WideString> val =
103 JSObject()->TryCData(XFA_Attribute::Value, false);
104 return val.has_value() ? StringToFXARGB(val->AsStringView()) : 0xFF000000;
105}
106
107FX_ARGB CXFA_Color::GetValueOrDefault(FX_ARGB defaultValue) const {
108 std::optional<WideString> val =
109 JSObject()->TryCData(XFA_Attribute::Value, false);
110 return val.has_value() ? StringToFXARGB(val->AsStringView()) : defaultValue;
111}
112
113void CXFA_Color::SetValue(FX_ARGB color) {
114 JSObject()->SetCData(XFA_Attribute::Value,
116 CFGAS_GEColor::ColorToString(color).AsStringView()));
117}
static ByteString ColorToString(FX_ARGB argb)
FX_ARGB GetValueOrDefault(FX_ARGB defaultValue) const
~CXFA_Color() override
FX_ARGB GetValue() const
static FX_ARGB StringToFXARGB(WideStringView view)
void SetValue(FX_ARGB color)
static WideString FromASCII(ByteStringView str)
uint32_t FX_ARGB
Definition fx_dib.h:36
constexpr FX_ARGB ArgbEncode(uint32_t a, uint32_t r, uint32_t g, uint32_t b)
Definition fx_dib.h:188
XFA_AttributeType
Definition fxfa_basic.h:83
XFA_Attribute
Definition fxfa_basic.h:67
XFA_Element
Definition fxfa_basic.h:75
XFA_PacketType
Definition fxfa_basic.h:44
fxcrt::WideStringView WideStringView
fxcrt::WideString WideString
Definition widestring.h:207