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_radial.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_radial.h"
8
9#include <math.h>
10
11#include <utility>
12
13#include "fxjs/xfa/cjx_node.h"
14#include "xfa/fgas/graphics/cfgas_gegraphics.h"
15#include "xfa/fgas/graphics/cfgas_geshading.h"
16#include "xfa/fxfa/parser/cxfa_color.h"
17#include "xfa/fxfa/parser/cxfa_document.h"
18
19namespace {
20
21const CXFA_Node::PropertyData kRadialPropertyData[] = {
22 {XFA_Element::Color, 1, {}},
23 {XFA_Element::Extras, 1, {}},
24};
25
26const CXFA_Node::AttributeData kRadialAttributeData[] = {
30 (void*)XFA_AttributeValue::ToEdge},
31 {XFA_Attribute::Usehref, XFA_AttributeType::CData, nullptr},
32};
33
34} // namespace
35
36CXFA_Radial::CXFA_Radial(CXFA_Document* doc, XFA_PacketType packet)
37 : CXFA_Node(doc,
38 packet,
39 {XFA_XDPPACKET::kTemplate, XFA_XDPPACKET::kForm},
40 XFA_ObjectType::Node,
41 XFA_Element::Radial,
42 kRadialPropertyData,
43 kRadialAttributeData,
44 cppgc::MakeGarbageCollected<CJX_Node>(
45 doc->GetHeap()->GetAllocationHandle(),
46 this)) {}
47
48CXFA_Radial::~CXFA_Radial() = default;
49
50bool CXFA_Radial::IsToEdge() {
51 auto value = JSObject()->TryEnum(XFA_Attribute::Type, true);
52 return !value.has_value() || value.value() == XFA_AttributeValue::ToEdge;
53}
54
55CXFA_Color* CXFA_Radial::GetColorIfExists() {
56 return GetChild<CXFA_Color>(0, XFA_Element::Color, false);
57}
58
59void CXFA_Radial::Draw(CFGAS_GEGraphics* pGS,
60 const CFGAS_GEPath& fillPath,
61 FX_ARGB crStart,
62 const CFX_RectF& rtFill,
63 const CFX_Matrix& matrix) {
64 CXFA_Color* pColor = GetColorIfExists();
65 FX_ARGB crEnd = pColor ? pColor->GetValue() : CXFA_Color::kBlackColor;
66 if (!IsToEdge())
67 std::swap(crStart, crEnd);
68
69 float end_radius = FXSYS_sqrt2(rtFill.Width(), rtFill.Height()) / 2;
70 CFGAS_GEShading shading(rtFill.Center(), rtFill.Center(), 0, end_radius, true,
71 true, crStart, crEnd);
72
76}
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 Width() const
float Height() 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_Radial() override
float FXSYS_sqrt2(float a, float b)
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