Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
14
namespace
{
15
16
const
CXFA_Node
::
PropertyData
kColorPropertyData[] = {
17
{
XFA_Element
::Extras, 1, {}},
18
};
19
20
const
CXFA_Node
::
AttributeData
kColorAttributeData[] = {
21
{
XFA_Attribute
::Id,
XFA_AttributeType
::
CData
,
nullptr
},
22
{
XFA_Attribute
::Use,
XFA_AttributeType
::
CData
,
nullptr
},
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
31
FX_ARGB
CXFA_Color::
StringToFXARGB
(
WideStringView
view) {
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
87
CXFA_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
99
CXFA_Color::~
CXFA_Color
() =
default
;
100
101
FX_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
107
FX_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
113
void
CXFA_Color::
SetValue
(
FX_ARGB
color) {
114
JSObject()->SetCData(
XFA_Attribute
::Value,
115
WideString
::
FromASCII
(
116
CFGAS_GEColor
::
ColorToString
(
color
)
.AsStringView()
)
);
117
}
CFGAS_GEColor
Definition
cfgas_gecolor.h:19
CFGAS_GEColor::ColorToString
static ByteString ColorToString(FX_ARGB argb)
Definition
cfgas_gecolor.cpp:24
CXFA_Color::GetValueOrDefault
FX_ARGB GetValueOrDefault(FX_ARGB defaultValue) const
Definition
cxfa_color.cpp:107
CXFA_Color::~CXFA_Color
~CXFA_Color() override
CXFA_Color::GetValue
FX_ARGB GetValue() const
Definition
cxfa_color.cpp:101
CXFA_Color::StringToFXARGB
static FX_ARGB StringToFXARGB(WideStringView view)
Definition
cxfa_color.cpp:31
CXFA_Color::SetValue
void SetValue(FX_ARGB color)
Definition
cxfa_color.cpp:113
CXFA_Node
Definition
cxfa_node.h:94
fxcrt::WideString::FromASCII
static WideString FromASCII(ByteStringView str)
Definition
widestring.cpp:704
FX_ARGB
uint32_t FX_ARGB
Definition
fx_dib.h:36
ArgbEncode
constexpr FX_ARGB ArgbEncode(uint32_t a, uint32_t r, uint32_t g, uint32_t b)
Definition
fx_dib.h:188
XFA_AttributeType
XFA_AttributeType
Definition
fxfa_basic.h:83
XFA_AttributeType::CData
@ CData
Definition
fxfa_basic.h:85
XFA_Attribute
XFA_Attribute
Definition
fxfa_basic.h:67
XFA_Element
XFA_Element
Definition
fxfa_basic.h:75
XFA_PacketType
XFA_PacketType
Definition
fxfa_basic.h:44
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
WideStringView
fxcrt::WideStringView WideStringView
Definition
string_view_template.h:326
CXFA_Node::AttributeData
Definition
cxfa_node.h:110
CXFA_Node::PropertyData
Definition
cxfa_node.h:96
WideString
fxcrt::WideString WideString
Definition
widestring.h:207
qtwebengine
src
3rdparty
chromium
third_party
pdfium
xfa
fxfa
parser
cxfa_color.cpp
Generated on
for Qt by
1.18.0