• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/src/foxitlib.h"
8 #include "xfa/src/fxfa/src/common/xfa_common.h"
9 #include "xfa_ffwidget.h"
10 #include "xfa_ffdraw.h"
11 #include "xfa_ffpath.h"
12 #include "xfa_ffpageview.h"
13 #include "xfa_ffdoc.h"
14 #include "xfa_ffapp.h"
CXFA_FFLine(CXFA_FFPageView * pPageView,CXFA_WidgetAcc * pDataAcc)15 CXFA_FFLine::CXFA_FFLine(CXFA_FFPageView* pPageView, CXFA_WidgetAcc* pDataAcc)
16     : CXFA_FFDraw(pPageView, pDataAcc) {}
~CXFA_FFLine()17 CXFA_FFLine::~CXFA_FFLine() {}
GetRectFromHand(CFX_RectF & rect,int32_t iHand,FX_FLOAT fLineWidth)18 void CXFA_FFLine::GetRectFromHand(CFX_RectF& rect,
19                                   int32_t iHand,
20                                   FX_FLOAT fLineWidth) {
21   FX_FLOAT fHalfWidth = fLineWidth / 2.0f;
22   if (rect.height < 1.0f) {
23     switch (iHand) {
24       case XFA_ATTRIBUTEENUM_Left:
25         rect.top -= fHalfWidth;
26         break;
27       case XFA_ATTRIBUTEENUM_Right:
28         rect.top += fHalfWidth;
29     }
30   } else if (rect.width < 1.0f) {
31     switch (iHand) {
32       case XFA_ATTRIBUTEENUM_Left:
33         rect.left += fHalfWidth;
34         break;
35       case XFA_ATTRIBUTEENUM_Right:
36         rect.left += fHalfWidth;
37         break;
38     }
39   } else {
40     switch (iHand) {
41       case XFA_ATTRIBUTEENUM_Left:
42         rect.Inflate(fHalfWidth, fHalfWidth);
43         break;
44       case XFA_ATTRIBUTEENUM_Right:
45         rect.Deflate(fHalfWidth, fHalfWidth);
46         break;
47     }
48   }
49 }
RenderWidget(CFX_Graphics * pGS,CFX_Matrix * pMatrix,FX_DWORD dwStatus,int32_t iRotate)50 void CXFA_FFLine::RenderWidget(CFX_Graphics* pGS,
51                                CFX_Matrix* pMatrix,
52                                FX_DWORD dwStatus,
53                                int32_t iRotate) {
54   if (!IsMatchVisibleStatus(dwStatus)) {
55     return;
56   }
57   CXFA_Value value = m_pDataAcc->GetFormValue();
58   if (!value) {
59     return;
60   }
61   CXFA_Line lineObj = value.GetLine();
62   FX_ARGB lineColor = 0xFF000000;
63   int32_t iStrokeType = 0;
64   FX_FLOAT fLineWidth = 1.0f;
65   FX_BOOL bSlope = lineObj.GetSlop();
66   int32_t iCap = 0;
67   CXFA_Edge edge = lineObj.GetEdge();
68   if (edge.IsExistInXML()) {
69     if (edge.GetPresence() != XFA_ATTRIBUTEENUM_Visible) {
70       return;
71     }
72     lineColor = edge.GetColor();
73     iStrokeType = edge.GetStrokeType();
74     fLineWidth = edge.GetThickness();
75     iCap = edge.GetCapType();
76   }
77   CFX_Matrix mtRotate;
78   GetRotateMatrix(mtRotate);
79   if (pMatrix) {
80     mtRotate.Concat(*pMatrix);
81   }
82   CFX_RectF rtLine;
83   GetRectWithoutRotate(rtLine);
84   if (CXFA_Margin mgWidget = m_pDataAcc->GetMargin()) {
85     XFA_RectWidthoutMargin(rtLine, mgWidget);
86   }
87   GetRectFromHand(rtLine, lineObj.GetHand(), fLineWidth);
88   CFX_Path linePath;
89   linePath.Create();
90   if (bSlope && rtLine.right() > 0.0f && rtLine.bottom() > 0.0f) {
91     linePath.AddLine(rtLine.right(), rtLine.top, rtLine.left, rtLine.bottom());
92   } else {
93     linePath.AddLine(rtLine.left, rtLine.top, rtLine.right(), rtLine.bottom());
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 }
CXFA_FFArc(CXFA_FFPageView * pPageView,CXFA_WidgetAcc * pDataAcc)104 CXFA_FFArc::CXFA_FFArc(CXFA_FFPageView* pPageView, CXFA_WidgetAcc* pDataAcc)
105     : CXFA_FFDraw(pPageView, pDataAcc) {}
~CXFA_FFArc()106 CXFA_FFArc::~CXFA_FFArc() {}
RenderWidget(CFX_Graphics * pGS,CFX_Matrix * pMatrix,FX_DWORD dwStatus,int32_t iRotate)107 void CXFA_FFArc::RenderWidget(CFX_Graphics* pGS,
108                               CFX_Matrix* pMatrix,
109                               FX_DWORD dwStatus,
110                               int32_t iRotate) {
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,FX_DWORD dwStatus,int32_t iRotate)135 void CXFA_FFRectangle::RenderWidget(CFX_Graphics* pGS,
136                                     CFX_Matrix* pMatrix,
137                                     FX_DWORD dwStatus,
138                                     int32_t iRotate) {
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;
148   GetRectWithoutRotate(rect);
149   if (CXFA_Margin mgWidget = m_pDataAcc->GetMargin()) {
150     XFA_RectWidthoutMargin(rect, mgWidget);
151   }
152   CFX_Matrix mtRotate;
153   GetRotateMatrix(mtRotate);
154   if (pMatrix) {
155     mtRotate.Concat(*pMatrix);
156   }
157   DrawBorder(pGS, rtObj, rect, &mtRotate);
158 }
159