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_stroke.cpp
Go to the documentation of this file.
1// Copyright 2016 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_stroke.h"
8
9#include <math.h>
10
11#include <utility>
12
13#include "fxjs/xfa/cjx_object.h"
14#include "xfa/fgas/graphics/cfgas_gecolor.h"
15#include "xfa/fgas/graphics/cfgas_gegraphics.h"
16#include "xfa/fxfa/cxfa_ffwidget.h"
17#include "xfa/fxfa/parser/cxfa_color.h"
18#include "xfa/fxfa/parser/cxfa_document.h"
19#include "xfa/fxfa/parser/cxfa_measurement.h"
20#include "xfa/fxfa/parser/cxfa_node.h"
21#include "xfa/fxfa/parser/xfa_utils.h"
22
24 XFA_AttributeValue iStrokeType,
25 XFA_AttributeValue iCapType) {
26 switch (iStrokeType) {
27 case XFA_AttributeValue::DashDot: {
28 float dashArray[] = {4, 1, 2, 1};
29 if (iCapType != XFA_AttributeValue::Butt) {
30 dashArray[1] = 2;
31 dashArray[3] = 2;
32 }
33 pGraphics->SetLineDash(0, dashArray);
34 break;
35 }
36 case XFA_AttributeValue::DashDotDot: {
37 float dashArray[] = {4, 1, 2, 1, 2, 1};
38 if (iCapType != XFA_AttributeValue::Butt) {
39 dashArray[1] = 2;
40 dashArray[3] = 2;
41 dashArray[5] = 2;
42 }
43 pGraphics->SetLineDash(0, dashArray);
44 break;
45 }
46 case XFA_AttributeValue::Dashed: {
47 float dashArray[] = {5, 1};
48 if (iCapType != XFA_AttributeValue::Butt)
49 dashArray[1] = 2;
50
51 pGraphics->SetLineDash(0, dashArray);
52 break;
53 }
54 case XFA_AttributeValue::Dotted: {
55 float dashArray[] = {2, 1};
56 if (iCapType != XFA_AttributeValue::Butt)
57 dashArray[1] = 2;
58
59 pGraphics->SetLineDash(0, dashArray);
60 break;
61 }
62 default:
63 pGraphics->SetSolidLineDash();
64 break;
65 }
66}
67
68CXFA_Stroke::CXFA_Stroke(CXFA_Document* pDoc,
69 XFA_PacketType ePacket,
70 Mask<XFA_XDPPACKET> validPackets,
71 XFA_ObjectType oType,
72 XFA_Element eType,
73 pdfium::span<const PropertyData> properties,
74 pdfium::span<const AttributeData> attributes,
75 CJX_Object* js_node)
76 : CXFA_Node(pDoc,
77 ePacket,
78 validPackets,
79 oType,
80 eType,
81 properties,
82 attributes,
83 js_node) {}
84
85CXFA_Stroke::~CXFA_Stroke() = default;
86
88 XFA_AttributeValue presence = JSObject()
89 ->TryEnum(XFA_Attribute::Presence, true)
90 .value_or(XFA_AttributeValue::Visible);
91 return presence == XFA_AttributeValue::Visible;
92}
93
95 return JSObject()->GetEnum(XFA_Attribute::Cap);
96}
97
99 return JSObject()->GetEnum(XFA_Attribute::Stroke);
100}
101
105
107 return JSObject()->GetMeasure(XFA_Attribute::Thickness);
108}
109
111 JSObject()->SetMeasure(XFA_Attribute::Thickness, msThinkness, false);
112}
113
115 const auto* pNode = GetChild<CXFA_Color>(0, XFA_Element::Color, false);
116 if (!pNode)
117 return 0xFF000000;
118
119 return CXFA_Color::StringToFXARGB(
120 pNode->JSObject()->GetCData(XFA_Attribute::Value).AsStringView());
121}
122
124 CXFA_Color* pNode =
125 JSObject()->GetOrCreateProperty<CXFA_Color>(0, XFA_Element::Color);
126 if (!pNode)
127 return;
128
129 pNode->JSObject()->SetCData(
130 XFA_Attribute::Value,
132}
133
135 return JSObject()->GetEnum(XFA_Attribute::Join);
136}
137
139 return JSObject()->GetBoolean(XFA_Attribute::Inverted);
140}
141
142float CXFA_Stroke::GetRadius() const {
143 return JSObject()
144 ->TryMeasure(XFA_Attribute::Radius, true)
146 .ToUnit(XFA_Unit::Pt);
147}
148
150 Mask<SameStyleOption> dwFlags) {
151 if (this == stroke)
152 return true;
153 if (fabs(GetThickness() - stroke->GetThickness()) >= 0.01f)
154 return false;
155 if (!(dwFlags & SameStyleOption::kNoPresence) &&
156 IsVisible() != stroke->IsVisible()) {
157 return false;
158 }
160 return false;
161 if (GetColor() != stroke->GetColor())
162 return false;
164 fabs(GetRadius() - stroke->GetRadius()) >= 0.01f) {
165 return false;
166 }
167 return true;
168}
169
171 const CFGAS_GEPath& pPath,
172 const CFX_Matrix& matrix) {
173 if (!IsVisible())
174 return;
175
176 float fThickness = GetThickness();
177 if (fThickness < 0.001f)
178 return;
179
181 if (IsCorner() && fThickness > 2 * GetRadius())
182 fThickness = 2 * GetRadius();
183
184 pGS->SetLineWidth(fThickness);
189 pGS->StrokePath(pPath, matrix);
190}
static ByteString ColorToString(FX_ARGB argb)
CFGAS_GEColor(FX_ARGB argb)
StateRestorer(CFGAS_GEGraphics *graphics)
void SetLineWidth(float lineWidth)
void SetStrokeColor(const CFGAS_GEColor &color)
void SetLineCap(CFX_GraphStateData::LineCap lineCap)
void StrokePath(const CFGAS_GEPath &path, const CFX_Matrix &matrix)
static FX_ARGB StringToFXARGB(WideStringView view)
CXFA_Measurement(float fValue, XFA_Unit eUnit)
float ToUnit(XFA_Unit eUnit) const
FX_ARGB GetColor() const
XFA_AttributeValue GetJoinType()
CXFA_Stroke(CXFA_Document *pDoc, XFA_PacketType ePacket, Mask< XFA_XDPPACKET > validPackets, XFA_ObjectType oType, XFA_Element eType, pdfium::span< const PropertyData > properties, pdfium::span< const AttributeData > attributes, CJX_Object *js_node)
bool IsCorner() const
Definition cxfa_stroke.h:32
XFA_AttributeValue GetCapType()
float GetRadius() const
void Stroke(CFGAS_GEGraphics *pGS, const CFGAS_GEPath &pPath, const CFX_Matrix &matrix)
bool SameStyles(CXFA_Stroke *stroke, Mask< SameStyleOption > dwFlags)
bool IsInverted()
~CXFA_Stroke() override
bool IsVisible()
void SetMSThickness(CXFA_Measurement msThinkness)
CXFA_Measurement GetMSThickness() const
void SetColor(FX_ARGB argb)
float GetThickness() const
XFA_AttributeValue GetStrokeType()
static WideString FromASCII(ByteStringView str)
XFA_ObjectType
Definition cxfa_object.h:21
void XFA_StrokeTypeSetLineDash(CFGAS_GEGraphics *pGraphics, XFA_AttributeValue iStrokeType, XFA_AttributeValue iCapType)
uint32_t FX_ARGB
Definition fx_dib.h:36
XFA_Unit
Definition fxfa_basic.h:91
XFA_Attribute
Definition fxfa_basic.h:67
XFA_XDPPACKET
Definition fxfa_basic.h:51
XFA_Element
Definition fxfa_basic.h:75
XFA_AttributeValue
Definition fxfa_basic.h:60
XFA_PacketType
Definition fxfa_basic.h:44
fxcrt::WideString WideString
Definition widestring.h:207