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