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_linear.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_linear.h"
8
9#include "fxjs/xfa/cjx_node.h"
10#include "xfa/fgas/graphics/cfgas_gegraphics.h"
11#include "xfa/fgas/graphics/cfgas_geshading.h"
12#include "xfa/fxfa/parser/cxfa_color.h"
13#include "xfa/fxfa/parser/cxfa_document.h"
14
15namespace {
16
17const CXFA_Node::PropertyData kLinearPropertyData[] = {
18 {XFA_Element::Color, 1, {}},
19 {XFA_Element::Extras, 1, {}},
20};
21
22const CXFA_Node::AttributeData kLinearAttributeData[] = {
26 (void*)XFA_AttributeValue::ToRight},
27 {XFA_Attribute::Usehref, XFA_AttributeType::CData, nullptr},
28};
29
30} // namespace
31
32CXFA_Linear::CXFA_Linear(CXFA_Document* doc, XFA_PacketType packet)
33 : CXFA_Node(doc,
34 packet,
35 {XFA_XDPPACKET::kTemplate, XFA_XDPPACKET::kForm},
36 XFA_ObjectType::Node,
37 XFA_Element::Linear,
38 kLinearPropertyData,
39 kLinearAttributeData,
40 cppgc::MakeGarbageCollected<CJX_Node>(
41 doc->GetHeap()->GetAllocationHandle(),
42 this)) {}
43
44CXFA_Linear::~CXFA_Linear() = default;
45
46XFA_AttributeValue CXFA_Linear::GetType() {
47 return JSObject()
48 ->TryEnum(XFA_Attribute::Type, true)
49 .value_or(XFA_AttributeValue::ToRight);
50}
51
52CXFA_Color* CXFA_Linear::GetColorIfExists() {
53 return GetChild<CXFA_Color>(0, XFA_Element::Color, false);
54}
55
56void CXFA_Linear::Draw(CFGAS_GEGraphics* pGS,
57 const CFGAS_GEPath& fillPath,
58 FX_ARGB crStart,
59 const CFX_RectF& rtFill,
60 const CFX_Matrix& matrix) {
61 CXFA_Color* pColor = GetColorIfExists();
62 FX_ARGB crEnd = pColor ? pColor->GetValue() : CXFA_Color::kBlackColor;
63
64 CFX_PointF ptStart;
65 CFX_PointF ptEnd;
66 switch (GetType()) {
67 case XFA_AttributeValue::ToRight:
68 ptStart = CFX_PointF(rtFill.left, rtFill.top);
69 ptEnd = CFX_PointF(rtFill.right(), rtFill.top);
70 break;
71 case XFA_AttributeValue::ToBottom:
72 ptStart = CFX_PointF(rtFill.left, rtFill.top);
73 ptEnd = CFX_PointF(rtFill.left, rtFill.bottom());
74 break;
75 case XFA_AttributeValue::ToLeft:
76 ptStart = CFX_PointF(rtFill.right(), rtFill.top);
77 ptEnd = CFX_PointF(rtFill.left, rtFill.top);
78 break;
79 case XFA_AttributeValue::ToTop:
80 ptStart = CFX_PointF(rtFill.left, rtFill.bottom());
81 ptEnd = CFX_PointF(rtFill.left, rtFill.top);
82 break;
83 default:
84 break;
85 }
86
87 CFGAS_GEShading shading(ptStart, ptEnd, false, false, crStart, crEnd);
91}
CFGAS_GEColor(CFGAS_GEShading *shading)
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)
float bottom() const
float right() const
FX_ARGB GetValue() const
static constexpr FX_ARGB kBlackColor
Definition cxfa_color.h:15
void Draw(CFGAS_GEGraphics *pGS, const CFGAS_GEPath &fillPath, FX_ARGB crStart, const CFX_RectF &rtFill, const CFX_Matrix &matrix)
~CXFA_Linear() override
XFA_AttributeType
Definition fxfa_basic.h:83
XFA_Attribute
Definition fxfa_basic.h:67
XFA_Element
Definition fxfa_basic.h:75
XFA_AttributeValue
Definition fxfa_basic.h:60
XFA_PacketType
Definition fxfa_basic.h:44