1 // Copyright 2014 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/app/xfa_ffpath.h"
8
9 #include "xfa/fxfa/app/xfa_ffdraw.h"
10 #include "xfa/fxfa/xfa_ffapp.h"
11 #include "xfa/fxfa/xfa_ffdoc.h"
12 #include "xfa/fxfa/xfa_ffpageview.h"
13 #include "xfa/fxfa/xfa_ffwidget.h"
14 #include "xfa/fxgraphics/cfx_color.h"
15 #include "xfa/fxgraphics/cfx_path.h"
16
CXFA_FFLine(CXFA_WidgetAcc * pDataAcc)17 CXFA_FFLine::CXFA_FFLine(CXFA_WidgetAcc* pDataAcc) : CXFA_FFDraw(pDataAcc) {}
18
~CXFA_FFLine()19 CXFA_FFLine::~CXFA_FFLine() {}
20
GetRectFromHand(CFX_RectF & rect,int32_t iHand,FX_FLOAT fLineWidth)21 void CXFA_FFLine::GetRectFromHand(CFX_RectF& rect,
22 int32_t iHand,
23 FX_FLOAT fLineWidth) {
24 FX_FLOAT fHalfWidth = fLineWidth / 2.0f;
25 if (rect.height < 1.0f) {
26 switch (iHand) {
27 case XFA_ATTRIBUTEENUM_Left:
28 rect.top -= fHalfWidth;
29 break;
30 case XFA_ATTRIBUTEENUM_Right:
31 rect.top += fHalfWidth;
32 }
33 } else if (rect.width < 1.0f) {
34 switch (iHand) {
35 case XFA_ATTRIBUTEENUM_Left:
36 rect.left += fHalfWidth;
37 break;
38 case XFA_ATTRIBUTEENUM_Right:
39 rect.left += fHalfWidth;
40 break;
41 }
42 } else {
43 switch (iHand) {
44 case XFA_ATTRIBUTEENUM_Left:
45 rect.Inflate(fHalfWidth, fHalfWidth);
46 break;
47 case XFA_ATTRIBUTEENUM_Right:
48 rect.Deflate(fHalfWidth, fHalfWidth);
49 break;
50 }
51 }
52 }
53
RenderWidget(CFX_Graphics * pGS,CFX_Matrix * pMatrix,uint32_t dwStatus)54 void CXFA_FFLine::RenderWidget(CFX_Graphics* pGS,
55 CFX_Matrix* pMatrix,
56 uint32_t dwStatus) {
57 if (!IsMatchVisibleStatus(dwStatus))
58 return;
59
60 CXFA_Value value = m_pDataAcc->GetFormValue();
61 if (!value)
62 return;
63
64 CXFA_Line lineObj = value.GetLine();
65 FX_ARGB lineColor = 0xFF000000;
66 int32_t iStrokeType = 0;
67 FX_FLOAT fLineWidth = 1.0f;
68 int32_t iCap = 0;
69 CXFA_Edge edge = lineObj.GetEdge();
70 if (edge) {
71 if (edge.GetPresence() != XFA_ATTRIBUTEENUM_Visible)
72 return;
73
74 lineColor = edge.GetColor();
75 iStrokeType = edge.GetStrokeType();
76 fLineWidth = edge.GetThickness();
77 iCap = edge.GetCapType();
78 }
79
80 CFX_Matrix mtRotate = GetRotateMatrix();
81 if (pMatrix)
82 mtRotate.Concat(*pMatrix);
83
84 CFX_RectF rtLine = GetRectWithoutRotate();
85 if (CXFA_Margin mgWidget = m_pDataAcc->GetMargin())
86 XFA_RectWidthoutMargin(rtLine, mgWidget);
87
88 GetRectFromHand(rtLine, lineObj.GetHand(), fLineWidth);
89 CFX_Path linePath;
90 if (lineObj.GetSlope() && rtLine.right() > 0.0f && rtLine.bottom() > 0.0f)
91 linePath.AddLine(rtLine.TopRight(), rtLine.BottomLeft());
92 else
93 linePath.AddLine(rtLine.TopLeft(), rtLine.BottomRight());
94
95 CFX_Color color(lineColor);
96 pGS->SaveGraphState();
97 pGS->SetLineWidth(fLineWidth, true);
98 XFA_StrokeTypeSetLineDash(pGS, iStrokeType, iCap);
99 pGS->SetStrokeColor(&color);
100 pGS->SetLineCap(XFA_LineCapToFXGE(iCap));
101 pGS->StrokePath(&linePath, &mtRotate);
102 pGS->RestoreGraphState();
103 }
104
CXFA_FFArc(CXFA_WidgetAcc * pDataAcc)105 CXFA_FFArc::CXFA_FFArc(CXFA_WidgetAcc* pDataAcc) : CXFA_FFDraw(pDataAcc) {}
106
~CXFA_FFArc()107 CXFA_FFArc::~CXFA_FFArc() {}
108
RenderWidget(CFX_Graphics * pGS,CFX_Matrix * pMatrix,uint32_t dwStatus)109 void CXFA_FFArc::RenderWidget(CFX_Graphics* pGS,
110 CFX_Matrix* pMatrix,
111 uint32_t dwStatus) {
112 if (!IsMatchVisibleStatus(dwStatus))
113 return;
114
115 CXFA_Value value = m_pDataAcc->GetFormValue();
116 if (!value)
117 return;
118
119 CXFA_Arc arcObj = value.GetArc();
120 CFX_Matrix mtRotate = GetRotateMatrix();
121 if (pMatrix)
122 mtRotate.Concat(*pMatrix);
123
124 CFX_RectF rtArc = GetRectWithoutRotate();
125 if (CXFA_Margin mgWidget = m_pDataAcc->GetMargin())
126 XFA_RectWidthoutMargin(rtArc, mgWidget);
127
128 DrawBorder(pGS, arcObj, rtArc, &mtRotate);
129 }
130
CXFA_FFRectangle(CXFA_WidgetAcc * pDataAcc)131 CXFA_FFRectangle::CXFA_FFRectangle(CXFA_WidgetAcc* pDataAcc)
132 : CXFA_FFDraw(pDataAcc) {}
133
~CXFA_FFRectangle()134 CXFA_FFRectangle::~CXFA_FFRectangle() {}
135
RenderWidget(CFX_Graphics * pGS,CFX_Matrix * pMatrix,uint32_t dwStatus)136 void CXFA_FFRectangle::RenderWidget(CFX_Graphics* pGS,
137 CFX_Matrix* pMatrix,
138 uint32_t dwStatus) {
139 if (!IsMatchVisibleStatus(dwStatus))
140 return;
141
142 CXFA_Value value = m_pDataAcc->GetFormValue();
143 if (!value)
144 return;
145
146 CXFA_Rectangle rtObj = value.GetRectangle();
147 CFX_RectF rect = GetRectWithoutRotate();
148 if (CXFA_Margin mgWidget = m_pDataAcc->GetMargin())
149 XFA_RectWidthoutMargin(rect, mgWidget);
150
151 CFX_Matrix mtRotate = GetRotateMatrix();
152 if (pMatrix)
153 mtRotate.Concat(*pMatrix);
154
155 DrawBorder(pGS, rtObj, rect, &mtRotate);
156 }
157