1 // Copyright 2016 PDFium Authors. All rights reserved.
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 "xfa/fxfa/parser/cxfa_measurement.h"
10 #include "xfa/fxfa/parser/xfa_object.h"
11
GetPresence() const12 int32_t CXFA_Stroke::GetPresence() const {
13 return m_pNode ? m_pNode->GetEnum(XFA_ATTRIBUTE_Presence)
14 : XFA_ATTRIBUTEENUM_Invisible;
15 }
16
GetCapType() const17 int32_t CXFA_Stroke::GetCapType() const {
18 if (!m_pNode)
19 return XFA_ATTRIBUTEENUM_Square;
20 return m_pNode->GetEnum(XFA_ATTRIBUTE_Cap);
21 }
22
GetStrokeType() const23 int32_t CXFA_Stroke::GetStrokeType() const {
24 return m_pNode ? m_pNode->GetEnum(XFA_ATTRIBUTE_Stroke)
25 : XFA_ATTRIBUTEENUM_Solid;
26 }
27
GetThickness() const28 FX_FLOAT CXFA_Stroke::GetThickness() const {
29 return GetMSThickness().ToUnit(XFA_UNIT_Pt);
30 }
31
GetMSThickness() const32 CXFA_Measurement CXFA_Stroke::GetMSThickness() const {
33 return m_pNode ? m_pNode->GetMeasure(XFA_ATTRIBUTE_Thickness)
34 : XFA_GetAttributeDefaultValue_Measure(XFA_Element::Edge,
35 XFA_ATTRIBUTE_Thickness,
36 XFA_XDPPACKET_Form);
37 }
38
SetMSThickness(CXFA_Measurement msThinkness)39 void CXFA_Stroke::SetMSThickness(CXFA_Measurement msThinkness) {
40 if (!m_pNode)
41 return;
42
43 m_pNode->SetMeasure(XFA_ATTRIBUTE_Thickness, msThinkness);
44 }
45
GetColor() const46 FX_ARGB CXFA_Stroke::GetColor() const {
47 if (!m_pNode)
48 return 0xFF000000;
49
50 CXFA_Node* pNode = m_pNode->GetChild(0, XFA_Element::Color);
51 if (!pNode)
52 return 0xFF000000;
53
54 CFX_WideStringC wsColor;
55 pNode->TryCData(XFA_ATTRIBUTE_Value, wsColor);
56 return CXFA_Data::ToColor(wsColor);
57 }
58
SetColor(FX_ARGB argb)59 void CXFA_Stroke::SetColor(FX_ARGB argb) {
60 if (!m_pNode)
61 return;
62
63 CXFA_Node* pNode = m_pNode->GetProperty(0, XFA_Element::Color);
64 CFX_WideString wsColor;
65 int a;
66 int r;
67 int g;
68 int b;
69 ArgbDecode(argb, a, r, g, b);
70 wsColor.Format(L"%d,%d,%d", r, g, b);
71 pNode->SetCData(XFA_ATTRIBUTE_Value, wsColor);
72 }
73
GetJoinType() const74 int32_t CXFA_Stroke::GetJoinType() const {
75 return m_pNode ? m_pNode->GetEnum(XFA_ATTRIBUTE_Join)
76 : XFA_ATTRIBUTEENUM_Square;
77 }
78
IsInverted() const79 bool CXFA_Stroke::IsInverted() const {
80 return m_pNode ? m_pNode->GetBoolean(XFA_ATTRIBUTE_Inverted) : false;
81 }
82
GetRadius() const83 FX_FLOAT CXFA_Stroke::GetRadius() const {
84 return m_pNode ? m_pNode->GetMeasure(XFA_ATTRIBUTE_Radius).ToUnit(XFA_UNIT_Pt)
85 : 0;
86 }
87
SameStyles(CXFA_Stroke stroke,uint32_t dwFlags) const88 bool CXFA_Stroke::SameStyles(CXFA_Stroke stroke, uint32_t dwFlags) const {
89 if (m_pNode == stroke.GetNode())
90 return true;
91 if (FXSYS_fabs(GetThickness() - stroke.GetThickness()) >= 0.01f)
92 return false;
93 if ((dwFlags & XFA_STROKE_SAMESTYLE_NoPresence) == 0 &&
94 IsVisible() != stroke.IsVisible()) {
95 return false;
96 }
97 if (GetStrokeType() != stroke.GetStrokeType())
98 return false;
99 if (GetColor() != stroke.GetColor())
100 return false;
101 if ((dwFlags & XFA_STROKE_SAMESTYLE_Corner) != 0 &&
102 FXSYS_fabs(GetRadius() - stroke.GetRadius()) >= 0.01f) {
103 return false;
104 }
105 return true;
106 }
107