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_stipple.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_stipple.h"
8
9#include "fxjs/xfa/cjx_node.h"
10#include "xfa/fgas/graphics/cfgas_gegraphics.h"
11#include "xfa/fxfa/parser/cxfa_color.h"
12#include "xfa/fxfa/parser/cxfa_document.h"
13
14namespace {
15
16const CXFA_Node::PropertyData kStipplePropertyData[] = {
17 {XFA_Element::Color, 1, {}},
18 {XFA_Element::Extras, 1, {}},
19};
20
21const CXFA_Node::AttributeData kStippleAttributeData[] = {
24 {XFA_Attribute::Rate, XFA_AttributeType::Integer, (void*)50},
25 {XFA_Attribute::Usehref, XFA_AttributeType::CData, nullptr},
26};
27
28} // namespace
29
30CXFA_Stipple::CXFA_Stipple(CXFA_Document* doc, XFA_PacketType packet)
31 : CXFA_Node(doc,
32 packet,
33 {XFA_XDPPACKET::kTemplate, XFA_XDPPACKET::kForm},
34 XFA_ObjectType::Node,
35 XFA_Element::Stipple,
36 kStipplePropertyData,
37 kStippleAttributeData,
38 cppgc::MakeGarbageCollected<CJX_Node>(
39 doc->GetHeap()->GetAllocationHandle(),
40 this)) {}
41
42CXFA_Stipple::~CXFA_Stipple() = default;
43
44CXFA_Color* CXFA_Stipple::GetColorIfExists() {
45 return GetChild<CXFA_Color>(0, XFA_Element::Color, false);
46}
47
48int32_t CXFA_Stipple::GetRate() {
49 return JSObject()
50 ->TryInteger(XFA_Attribute::Rate, true)
51 .value_or(GetDefaultRate());
52}
53
54void CXFA_Stipple::Draw(CFGAS_GEGraphics* pGS,
55 const CFGAS_GEPath& fillPath,
56 const CFX_RectF& rtFill,
57 const CFX_Matrix& matrix) {
58 int32_t iRate = GetRate();
59 if (iRate == 0)
60 iRate = 100;
61
62 CXFA_Color* pColor = GetColorIfExists();
63 FX_ARGB crColor = pColor ? pColor->GetValue() : CXFA_Color::kBlackColor;
64
65 int32_t alpha;
66 FX_COLORREF colorref;
67 std::tie(alpha, colorref) = ArgbToAlphaAndColorRef(crColor);
68 FX_ARGB cr = AlphaAndColorRefToArgb(iRate * alpha / 100, colorref);
69
73}
CFGAS_GEColor(const FX_ARGB argb)
StateRestorer(CFGAS_GEGraphics *graphics)
void FillPath(const CFGAS_GEPath &path, CFX_FillRenderOptions::FillType fill_type, const CFX_Matrix &matrix)
void SetFillColor(const CFGAS_GEColor &color)
FX_ARGB GetValue() const
static constexpr FX_ARGB kBlackColor
Definition cxfa_color.h:15
~CXFA_Stipple() override
void Draw(CFGAS_GEGraphics *pGS, const CFGAS_GEPath &fillPath, const CFX_RectF &rtFill, const CFX_Matrix &matrix)
static int32_t GetDefaultRate()
FX_ARGB AlphaAndColorRefToArgb(int a, FX_COLORREF colorref)
Definition fx_dib.cpp:57
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