Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 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 | |
Dan Sinclair | 80c4878 | 2017-03-23 12:11:20 -0400 | [diff] [blame] | 7 | #include "xfa/fxfa/cxfa_ffwidget.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 8 | |
| 9 | #include <algorithm> |
thestig | 39fbb7e | 2016-05-12 15:35:00 -0700 | [diff] [blame] | 10 | #include <memory> |
Dan Sinclair | 85c8e7f | 2016-11-21 13:50:32 -0500 | [diff] [blame] | 11 | #include <vector> |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 12 | |
dsinclair | 41872fa | 2016-10-04 11:29:35 -0700 | [diff] [blame] | 13 | #include "core/fpdfapi/page/cpdf_pageobjectholder.h" |
dsinclair | 8a4e286 | 2016-09-29 13:43:30 -0700 | [diff] [blame] | 14 | #include "core/fxcodec/codec/ccodec_progressivedecoder.h" |
| 15 | #include "core/fxcodec/fx_codec.h" |
tsepez | 1a1d764 | 2016-12-06 06:29:28 -0800 | [diff] [blame] | 16 | #include "core/fxcrt/cfx_maybe_owned.h" |
dsinclair | 74a34fc | 2016-09-29 16:41:42 -0700 | [diff] [blame] | 17 | #include "core/fxge/cfx_gemodule.h" |
| 18 | #include "core/fxge/cfx_pathdata.h" |
| 19 | #include "core/fxge/cfx_renderdevice.h" |
Nicolas Pena | c3202a9 | 2017-04-04 13:38:29 -0400 | [diff] [blame] | 20 | #include "core/fxge/dib/cfx_imagerenderer.h" |
Nicolas Pena | bdbb0bd | 2017-03-31 15:39:44 -0400 | [diff] [blame] | 21 | #include "core/fxge/dib/cfx_imagetransformer.h" |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 22 | #include "xfa/fwl/fwl_widgethit.h" |
Dan Sinclair | 1f5d498 | 2017-01-10 16:37:32 -0500 | [diff] [blame] | 23 | #include "xfa/fxfa/app/cxfa_textlayout.h" |
dsinclair | 5b49309 | 2016-09-29 20:20:24 -0700 | [diff] [blame] | 24 | #include "xfa/fxfa/cxfa_eventparam.h" |
Dan Sinclair | 80c4878 | 2017-03-23 12:11:20 -0400 | [diff] [blame] | 25 | #include "xfa/fxfa/cxfa_ffapp.h" |
| 26 | #include "xfa/fxfa/cxfa_ffdoc.h" |
| 27 | #include "xfa/fxfa/cxfa_ffdocview.h" |
| 28 | #include "xfa/fxfa/cxfa_ffpageview.h" |
| 29 | #include "xfa/fxfa/cxfa_widgetacc.h" |
dsinclair | 44d054c | 2016-04-06 10:23:46 -0700 | [diff] [blame] | 30 | #include "xfa/fxfa/parser/cxfa_corner.h" |
Dan Sinclair | efcae5d | 2017-03-29 14:47:46 -0400 | [diff] [blame] | 31 | #include "xfa/fxfa/parser/cxfa_node.h" |
Dan Sinclair | 811b8a4 | 2016-03-17 08:59:42 -0400 | [diff] [blame] | 32 | #include "xfa/fxgraphics/cfx_color.h" |
dsinclair | 202ad72 | 2016-09-29 17:41:42 -0700 | [diff] [blame] | 33 | #include "xfa/fxgraphics/cfx_graphics.h" |
Dan Sinclair | 811b8a4 | 2016-03-17 08:59:42 -0400 | [diff] [blame] | 34 | #include "xfa/fxgraphics/cfx_path.h" |
| 35 | #include "xfa/fxgraphics/cfx_pattern.h" |
| 36 | #include "xfa/fxgraphics/cfx_shading.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 37 | |
dan sinclair | aaf0bdc | 2017-02-04 10:16:21 -0500 | [diff] [blame] | 38 | CXFA_FFWidget::CXFA_FFWidget(CXFA_WidgetAcc* pDataAcc) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 39 | : CXFA_ContentLayoutItem(pDataAcc->GetNode()), |
dan sinclair | aaf0bdc | 2017-02-04 10:16:21 -0500 | [diff] [blame] | 40 | m_pPageView(nullptr), |
Dan Sinclair | bba2a7c | 2017-02-07 16:36:39 -0500 | [diff] [blame] | 41 | m_pDataAcc(pDataAcc) {} |
dan sinclair | aaf0bdc | 2017-02-04 10:16:21 -0500 | [diff] [blame] | 42 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 43 | CXFA_FFWidget::~CXFA_FFWidget() {} |
dsinclair | 2085538 | 2016-10-31 07:29:34 -0700 | [diff] [blame] | 44 | |
dsinclair | 1a7534a | 2016-11-22 15:56:11 -0800 | [diff] [blame] | 45 | const CFWL_App* CXFA_FFWidget::GetFWLApp() { |
dsinclair | 2085538 | 2016-10-31 07:29:34 -0700 | [diff] [blame] | 46 | return GetPageView()->GetDocView()->GetDoc()->GetApp()->GetFWLApp(); |
| 47 | } |
| 48 | |
Lei Zhang | afc8eb3 | 2017-03-28 14:32:13 -0700 | [diff] [blame] | 49 | const CFX_RectF& CXFA_FFWidget::GetWidgetRect() const { |
Dan Sinclair | c222907 | 2017-02-07 09:04:28 -0500 | [diff] [blame] | 50 | if ((m_dwStatus & XFA_WidgetStatus_RectCached) == 0) |
| 51 | RecacheWidgetRect(); |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 52 | return m_rtWidget; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 53 | } |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 54 | |
Lei Zhang | afc8eb3 | 2017-03-28 14:32:13 -0700 | [diff] [blame] | 55 | const CFX_RectF& CXFA_FFWidget::RecacheWidgetRect() const { |
dsinclair | 935d8d5 | 2016-05-17 10:32:18 -0700 | [diff] [blame] | 56 | m_dwStatus |= XFA_WidgetStatus_RectCached; |
Dan Sinclair | c222907 | 2017-02-07 09:04:28 -0500 | [diff] [blame] | 57 | m_rtWidget = GetRect(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 58 | return m_rtWidget; |
| 59 | } |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 60 | |
| 61 | CFX_RectF CXFA_FFWidget::GetRectWithoutRotate() { |
| 62 | CFX_RectF rtWidget = GetWidgetRect(); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 63 | float fValue = 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 64 | switch (m_pDataAcc->GetRotate()) { |
| 65 | case 90: |
| 66 | rtWidget.top = rtWidget.bottom(); |
| 67 | fValue = rtWidget.width; |
| 68 | rtWidget.width = rtWidget.height; |
| 69 | rtWidget.height = fValue; |
| 70 | break; |
| 71 | case 180: |
| 72 | rtWidget.left = rtWidget.right(); |
| 73 | rtWidget.top = rtWidget.bottom(); |
| 74 | break; |
| 75 | case 270: |
| 76 | rtWidget.left = rtWidget.right(); |
| 77 | fValue = rtWidget.width; |
| 78 | rtWidget.width = rtWidget.height; |
| 79 | rtWidget.height = fValue; |
| 80 | break; |
| 81 | } |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 82 | return rtWidget; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 83 | } |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 84 | |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 85 | uint32_t CXFA_FFWidget::GetStatus() { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 86 | return m_dwStatus; |
| 87 | } |
| 88 | |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 89 | void CXFA_FFWidget::ModifyStatus(uint32_t dwAdded, uint32_t dwRemoved) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 90 | m_dwStatus = (m_dwStatus & ~dwRemoved) | dwAdded; |
| 91 | } |
| 92 | |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 93 | CFX_RectF CXFA_FFWidget::GetBBox(uint32_t dwStatus, bool bDrawFocus) { |
| 94 | if (bDrawFocus || !m_pPageView) |
| 95 | return CFX_RectF(); |
| 96 | return m_pPageView->GetPageViewRect(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | CXFA_WidgetAcc* CXFA_FFWidget::GetDataAcc() { |
| 100 | return m_pDataAcc; |
| 101 | } |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 102 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 103 | bool CXFA_FFWidget::GetToolTip(CFX_WideString& wsToolTip) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 104 | if (CXFA_Assist assist = m_pDataAcc->GetAssist()) { |
| 105 | if (CXFA_ToolTip toolTip = assist.GetToolTip()) { |
| 106 | return toolTip.GetTip(wsToolTip); |
| 107 | } |
| 108 | } |
| 109 | return GetCaptionText(wsToolTip); |
| 110 | } |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 111 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 112 | void CXFA_FFWidget::RenderWidget(CFX_Graphics* pGS, |
| 113 | CFX_Matrix* pMatrix, |
dsinclair | 9d6ca99 | 2016-06-16 10:51:56 -0700 | [diff] [blame] | 114 | uint32_t dwStatus) { |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 115 | if (!IsMatchVisibleStatus(dwStatus)) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 116 | return; |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 117 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 118 | CXFA_Border border = m_pDataAcc->GetBorder(); |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 119 | if (!border) |
| 120 | return; |
| 121 | |
| 122 | CFX_RectF rtBorder = GetRectWithoutRotate(); |
| 123 | CXFA_Margin margin = border.GetMargin(); |
| 124 | if (margin) |
| 125 | XFA_RectWidthoutMargin(rtBorder, margin); |
| 126 | |
| 127 | rtBorder.Normalize(); |
| 128 | DrawBorder(pGS, border, rtBorder, pMatrix); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 129 | } |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 130 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 131 | bool CXFA_FFWidget::IsLoaded() { |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 132 | return !!m_pPageView; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 133 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 134 | bool CXFA_FFWidget::LoadWidget() { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 135 | PerformLayout(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 136 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 137 | } |
| 138 | void CXFA_FFWidget::UnloadWidget() {} |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 139 | bool CXFA_FFWidget::PerformLayout() { |
Dan Sinclair | c222907 | 2017-02-07 09:04:28 -0500 | [diff] [blame] | 140 | RecacheWidgetRect(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 141 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 142 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 143 | bool CXFA_FFWidget::UpdateFWLData() { |
| 144 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 145 | } |
| 146 | void CXFA_FFWidget::UpdateWidgetProperty() {} |
| 147 | void CXFA_FFWidget::DrawBorder(CFX_Graphics* pGS, |
| 148 | CXFA_Box box, |
| 149 | const CFX_RectF& rtBorder, |
| 150 | CFX_Matrix* pMatrix, |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 151 | uint32_t dwFlags) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 152 | XFA_DrawBox(box, pGS, rtBorder, pMatrix, dwFlags); |
| 153 | } |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 154 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 155 | void CXFA_FFWidget::InvalidateWidget(const CFX_RectF* pRect) { |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 156 | if (pRect) { |
Dan Sinclair | e3978d0 | 2017-03-23 09:12:10 -0400 | [diff] [blame] | 157 | GetDoc()->GetDocEnvironment()->InvalidateRect(m_pPageView, *pRect); |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 158 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 159 | } |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 160 | |
| 161 | CFX_RectF rtWidget = GetBBox(XFA_WidgetStatus_Focused); |
| 162 | rtWidget.Inflate(2, 2); |
Dan Sinclair | e3978d0 | 2017-03-23 09:12:10 -0400 | [diff] [blame] | 163 | GetDoc()->GetDocEnvironment()->InvalidateRect(m_pPageView, rtWidget); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 164 | } |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 165 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 166 | void CXFA_FFWidget::AddInvalidateRect(const CFX_RectF* pRect) { |
| 167 | CFX_RectF rtWidget; |
| 168 | if (pRect) { |
| 169 | rtWidget = *pRect; |
| 170 | } else { |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 171 | rtWidget = GetBBox(XFA_WidgetStatus_Focused); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 172 | rtWidget.Inflate(2, 2); |
| 173 | } |
| 174 | m_pDocView->AddInvalidateRect(m_pPageView, rtWidget); |
| 175 | } |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 176 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 177 | bool CXFA_FFWidget::GetCaptionText(CFX_WideString& wsCap) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 178 | CXFA_TextLayout* pCapTextlayout = m_pDataAcc->GetCaptionTextLayout(); |
| 179 | if (!pCapTextlayout) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 180 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 181 | } |
| 182 | pCapTextlayout->GetText(wsCap); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 183 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 184 | } |
tsepez | 7d89e72 | 2016-05-04 13:38:11 -0700 | [diff] [blame] | 185 | |
| 186 | bool CXFA_FFWidget::IsFocused() { |
dsinclair | 935d8d5 | 2016-05-17 10:32:18 -0700 | [diff] [blame] | 187 | return !!(m_dwStatus & XFA_WidgetStatus_Focused); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 188 | } |
tsepez | 7d89e72 | 2016-05-04 13:38:11 -0700 | [diff] [blame] | 189 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 190 | bool CXFA_FFWidget::OnMouseEnter() { |
| 191 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 192 | } |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 193 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 194 | bool CXFA_FFWidget::OnMouseExit() { |
| 195 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 196 | } |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 197 | |
| 198 | bool CXFA_FFWidget::OnLButtonDown(uint32_t dwFlags, const CFX_PointF& point) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 199 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 200 | } |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 201 | |
| 202 | bool CXFA_FFWidget::OnLButtonUp(uint32_t dwFlags, const CFX_PointF& point) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 203 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 204 | } |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 205 | |
| 206 | bool CXFA_FFWidget::OnLButtonDblClk(uint32_t dwFlags, const CFX_PointF& point) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 207 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 208 | } |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 209 | |
| 210 | bool CXFA_FFWidget::OnMouseMove(uint32_t dwFlags, const CFX_PointF& point) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 211 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 212 | } |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 213 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 214 | bool CXFA_FFWidget::OnMouseWheel(uint32_t dwFlags, |
| 215 | int16_t zDelta, |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 216 | const CFX_PointF& point) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 217 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 218 | } |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 219 | |
| 220 | bool CXFA_FFWidget::OnRButtonDown(uint32_t dwFlags, const CFX_PointF& point) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 221 | return false; |
| 222 | } |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 223 | |
| 224 | bool CXFA_FFWidget::OnRButtonUp(uint32_t dwFlags, const CFX_PointF& point) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 225 | return false; |
| 226 | } |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 227 | |
| 228 | bool CXFA_FFWidget::OnRButtonDblClk(uint32_t dwFlags, const CFX_PointF& point) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 229 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 230 | } |
| 231 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 232 | bool CXFA_FFWidget::OnSetFocus(CXFA_FFWidget* pOldWidget) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 233 | CXFA_FFWidget* pParent = GetParent(); |
| 234 | if (pParent && !pParent->IsAncestorOf(pOldWidget)) { |
| 235 | pParent->OnSetFocus(pOldWidget); |
| 236 | } |
dsinclair | 935d8d5 | 2016-05-17 10:32:18 -0700 | [diff] [blame] | 237 | m_dwStatus |= XFA_WidgetStatus_Focused; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 238 | CXFA_EventParam eParam; |
| 239 | eParam.m_eType = XFA_EVENT_Enter; |
| 240 | eParam.m_pTarget = m_pDataAcc; |
| 241 | m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Enter, &eParam); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 242 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 243 | } |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 244 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 245 | bool CXFA_FFWidget::OnKillFocus(CXFA_FFWidget* pNewWidget) { |
dsinclair | 935d8d5 | 2016-05-17 10:32:18 -0700 | [diff] [blame] | 246 | m_dwStatus &= ~XFA_WidgetStatus_Focused; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 247 | EventKillFocus(); |
| 248 | if (pNewWidget) { |
| 249 | CXFA_FFWidget* pParent = GetParent(); |
| 250 | if (pParent && !pParent->IsAncestorOf(pNewWidget)) { |
| 251 | pParent->OnKillFocus(pNewWidget); |
| 252 | } |
| 253 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 254 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 255 | } |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 256 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 257 | bool CXFA_FFWidget::OnKeyDown(uint32_t dwKeyCode, uint32_t dwFlags) { |
| 258 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 259 | } |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 260 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 261 | bool CXFA_FFWidget::OnKeyUp(uint32_t dwKeyCode, uint32_t dwFlags) { |
| 262 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 263 | } |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 264 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 265 | bool CXFA_FFWidget::OnChar(uint32_t dwChar, uint32_t dwFlags) { |
| 266 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 267 | } |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 268 | |
| 269 | FWL_WidgetHit CXFA_FFWidget::OnHitTest(const CFX_PointF& point) { |
dsinclair | 89fcde8 | 2016-05-03 13:00:25 -0700 | [diff] [blame] | 270 | return FWL_WidgetHit::Unknown; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 271 | } |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 272 | |
| 273 | bool CXFA_FFWidget::OnSetCursor(const CFX_PointF& point) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 274 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 275 | } |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 276 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 277 | bool CXFA_FFWidget::CanUndo() { |
| 278 | return false; |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 279 | } |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 280 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 281 | bool CXFA_FFWidget::CanRedo() { |
| 282 | return false; |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 283 | } |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 284 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 285 | bool CXFA_FFWidget::Undo() { |
| 286 | return false; |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 287 | } |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 288 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 289 | bool CXFA_FFWidget::Redo() { |
| 290 | return false; |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 291 | } |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 292 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 293 | bool CXFA_FFWidget::CanCopy() { |
| 294 | return false; |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 295 | } |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 296 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 297 | bool CXFA_FFWidget::CanCut() { |
| 298 | return false; |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 299 | } |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 300 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 301 | bool CXFA_FFWidget::CanPaste() { |
| 302 | return false; |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 303 | } |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 304 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 305 | bool CXFA_FFWidget::CanSelectAll() { |
| 306 | return false; |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 307 | } |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 308 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 309 | bool CXFA_FFWidget::CanDelete() { |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 310 | return CanCut(); |
| 311 | } |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 312 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 313 | bool CXFA_FFWidget::CanDeSelect() { |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 314 | return CanCopy(); |
| 315 | } |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 316 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 317 | bool CXFA_FFWidget::Copy(CFX_WideString& wsCopy) { |
| 318 | return false; |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 319 | } |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 320 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 321 | bool CXFA_FFWidget::Cut(CFX_WideString& wsCut) { |
| 322 | return false; |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 323 | } |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 324 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 325 | bool CXFA_FFWidget::Paste(const CFX_WideString& wsPaste) { |
| 326 | return false; |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 327 | } |
dsinclair | 14a60c5 | 2016-11-16 12:15:27 -0800 | [diff] [blame] | 328 | |
| 329 | void CXFA_FFWidget::SelectAll() {} |
| 330 | |
| 331 | void CXFA_FFWidget::Delete() {} |
| 332 | |
| 333 | void CXFA_FFWidget::DeSelect() {} |
| 334 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 335 | bool CXFA_FFWidget::GetSuggestWords(CFX_PointF pointf, |
| 336 | std::vector<CFX_ByteString>& sSuggest) { |
| 337 | return false; |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 338 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 339 | bool CXFA_FFWidget::ReplaceSpellCheckWord(CFX_PointF pointf, |
| 340 | const CFX_ByteStringC& bsReplace) { |
| 341 | return false; |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 342 | } |
Dan Sinclair | 1f403ce | 2017-02-21 12:56:24 -0500 | [diff] [blame] | 343 | |
| 344 | CFX_PointF CXFA_FFWidget::Rotate2Normal(const CFX_PointF& point) { |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 345 | CFX_Matrix mt = GetRotateMatrix(); |
Dan Sinclair | 1f403ce | 2017-02-21 12:56:24 -0500 | [diff] [blame] | 346 | if (mt.IsIdentity()) |
| 347 | return point; |
| 348 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 349 | CFX_Matrix mtReverse; |
| 350 | mtReverse.SetReverse(mt); |
Dan Sinclair | 1f403ce | 2017-02-21 12:56:24 -0500 | [diff] [blame] | 351 | return mtReverse.Transform(point); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 352 | } |
Dan Sinclair | 1f403ce | 2017-02-21 12:56:24 -0500 | [diff] [blame] | 353 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 354 | static void XFA_GetMatrix(CFX_Matrix& m, |
| 355 | int32_t iRotate, |
weili | 038aa53 | 2016-05-20 15:38:29 -0700 | [diff] [blame] | 356 | XFA_ATTRIBUTEENUM at, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 357 | const CFX_RectF& rt) { |
| 358 | if (!iRotate) { |
| 359 | return; |
| 360 | } |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 361 | float fAnchorX = 0; |
| 362 | float fAnchorY = 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 363 | switch (at) { |
| 364 | case XFA_ATTRIBUTEENUM_TopLeft: |
| 365 | fAnchorX = rt.left, fAnchorY = rt.top; |
| 366 | break; |
| 367 | case XFA_ATTRIBUTEENUM_TopCenter: |
| 368 | fAnchorX = (rt.left + rt.right()) / 2, fAnchorY = rt.top; |
| 369 | break; |
| 370 | case XFA_ATTRIBUTEENUM_TopRight: |
| 371 | fAnchorX = rt.right(), fAnchorY = rt.top; |
| 372 | break; |
| 373 | case XFA_ATTRIBUTEENUM_MiddleLeft: |
| 374 | fAnchorX = rt.left, fAnchorY = (rt.top + rt.bottom()) / 2; |
| 375 | break; |
| 376 | case XFA_ATTRIBUTEENUM_MiddleCenter: |
| 377 | fAnchorX = (rt.left + rt.right()) / 2, |
| 378 | fAnchorY = (rt.top + rt.bottom()) / 2; |
| 379 | break; |
| 380 | case XFA_ATTRIBUTEENUM_MiddleRight: |
| 381 | fAnchorX = rt.right(), fAnchorY = (rt.top + rt.bottom()) / 2; |
| 382 | break; |
| 383 | case XFA_ATTRIBUTEENUM_BottomLeft: |
| 384 | fAnchorX = rt.left, fAnchorY = rt.bottom(); |
| 385 | break; |
| 386 | case XFA_ATTRIBUTEENUM_BottomCenter: |
| 387 | fAnchorX = (rt.left + rt.right()) / 2, fAnchorY = rt.bottom(); |
| 388 | break; |
| 389 | case XFA_ATTRIBUTEENUM_BottomRight: |
| 390 | fAnchorX = rt.right(), fAnchorY = rt.bottom(); |
| 391 | break; |
weili | 038aa53 | 2016-05-20 15:38:29 -0700 | [diff] [blame] | 392 | default: |
| 393 | break; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 394 | } |
| 395 | switch (iRotate) { |
| 396 | case 90: |
| 397 | m.a = 0, m.b = -1, m.c = 1, m.d = 0, m.e = fAnchorX - fAnchorY, |
| 398 | m.f = fAnchorX + fAnchorY; |
| 399 | break; |
| 400 | case 180: |
| 401 | m.a = -1, m.b = 0, m.c = 0, m.d = -1, m.e = fAnchorX * 2, |
| 402 | m.f = fAnchorY * 2; |
| 403 | break; |
| 404 | case 270: |
| 405 | m.a = 0, m.b = 1, m.c = -1, m.d = 0, m.e = fAnchorX + fAnchorY, |
| 406 | m.f = fAnchorY - fAnchorX; |
| 407 | break; |
| 408 | } |
| 409 | } |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 410 | |
| 411 | CFX_Matrix CXFA_FFWidget::GetRotateMatrix() { |
| 412 | CFX_Matrix mt; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 413 | int32_t iRotate = m_pDataAcc->GetRotate(); |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 414 | if (!iRotate) |
| 415 | return mt; |
| 416 | |
| 417 | CFX_RectF rcWidget = GetRectWithoutRotate(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 418 | XFA_ATTRIBUTEENUM at = XFA_ATTRIBUTEENUM_TopLeft; |
| 419 | XFA_GetMatrix(mt, iRotate, at, rcWidget); |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 420 | |
| 421 | return mt; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 422 | } |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 423 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 424 | bool CXFA_FFWidget::IsLayoutRectEmpty() { |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 425 | CFX_RectF rtLayout = GetRectWithoutRotate(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 426 | return rtLayout.width < 0.1f && rtLayout.height < 0.1f; |
| 427 | } |
| 428 | CXFA_FFWidget* CXFA_FFWidget::GetParent() { |
| 429 | CXFA_Node* pParentNode = |
| 430 | m_pDataAcc->GetNode()->GetNodeItem(XFA_NODEITEM_Parent); |
| 431 | if (pParentNode) { |
| 432 | CXFA_WidgetAcc* pParentWidgetAcc = |
tsepez | 20d6b76 | 2016-06-09 11:46:16 -0700 | [diff] [blame] | 433 | static_cast<CXFA_WidgetAcc*>(pParentNode->GetWidgetData()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 434 | if (pParentWidgetAcc) { |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 435 | return pParentWidgetAcc->GetNextWidget(nullptr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 436 | } |
| 437 | } |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 438 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 439 | } |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 440 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 441 | bool CXFA_FFWidget::IsAncestorOf(CXFA_FFWidget* pWidget) { |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 442 | if (!pWidget) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 443 | return false; |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 444 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 445 | CXFA_Node* pNode = m_pDataAcc->GetNode(); |
| 446 | CXFA_Node* pChildNode = pWidget->GetDataAcc()->GetNode(); |
| 447 | while (pChildNode) { |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 448 | if (pChildNode == pNode) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 449 | return true; |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 450 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 451 | pChildNode = pChildNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 452 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 453 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 454 | } |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 455 | |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 456 | bool CXFA_FFWidget::PtInActiveRect(const CFX_PointF& point) { |
| 457 | return GetWidgetRect().Contains(point); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 458 | } |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 459 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 460 | CXFA_FFDocView* CXFA_FFWidget::GetDocView() { |
| 461 | return m_pDocView; |
| 462 | } |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 463 | |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 464 | void CXFA_FFWidget::SetDocView(CXFA_FFDocView* pDocView) { |
| 465 | m_pDocView = pDocView; |
| 466 | } |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 467 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 468 | CXFA_FFDoc* CXFA_FFWidget::GetDoc() { |
tsepez | 20d6b76 | 2016-06-09 11:46:16 -0700 | [diff] [blame] | 469 | return m_pDocView->GetDoc(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 470 | } |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 471 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 472 | CXFA_FFApp* CXFA_FFWidget::GetApp() { |
| 473 | return GetDoc()->GetApp(); |
| 474 | } |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 475 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 476 | IXFA_AppProvider* CXFA_FFWidget::GetAppProvider() { |
| 477 | return GetApp()->GetAppProvider(); |
| 478 | } |
tsepez | 7d89e72 | 2016-05-04 13:38:11 -0700 | [diff] [blame] | 479 | |
| 480 | bool CXFA_FFWidget::IsMatchVisibleStatus(uint32_t dwStatus) { |
dsinclair | 935d8d5 | 2016-05-17 10:32:18 -0700 | [diff] [blame] | 481 | return !!(m_dwStatus & XFA_WidgetStatus_Visible); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 482 | } |
tsepez | 7d89e72 | 2016-05-04 13:38:11 -0700 | [diff] [blame] | 483 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 484 | void CXFA_FFWidget::EventKillFocus() { |
dsinclair | 935d8d5 | 2016-05-17 10:32:18 -0700 | [diff] [blame] | 485 | if (m_dwStatus & XFA_WidgetStatus_Access) { |
| 486 | m_dwStatus &= ~XFA_WidgetStatus_Access; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 487 | return; |
| 488 | } |
| 489 | CXFA_EventParam eParam; |
| 490 | eParam.m_eType = XFA_EVENT_Exit; |
| 491 | eParam.m_pTarget = m_pDataAcc; |
| 492 | m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Exit, &eParam); |
| 493 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 494 | bool CXFA_FFWidget::IsButtonDown() { |
dsinclair | 935d8d5 | 2016-05-17 10:32:18 -0700 | [diff] [blame] | 495 | return (m_dwStatus & XFA_WidgetStatus_ButtonDown) != 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 496 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 497 | void CXFA_FFWidget::SetButtonDown(bool bSet) { |
dsinclair | 935d8d5 | 2016-05-17 10:32:18 -0700 | [diff] [blame] | 498 | bSet ? m_dwStatus |= XFA_WidgetStatus_ButtonDown |
| 499 | : m_dwStatus &= ~XFA_WidgetStatus_ButtonDown; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 500 | } |
| 501 | int32_t XFA_StrokeTypeSetLineDash(CFX_Graphics* pGraphics, |
| 502 | int32_t iStrokeType, |
| 503 | int32_t iCapType) { |
| 504 | switch (iStrokeType) { |
| 505 | case XFA_ATTRIBUTEENUM_DashDot: { |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 506 | float dashArray[] = {4, 1, 2, 1}; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 507 | if (iCapType != XFA_ATTRIBUTEENUM_Butt) { |
| 508 | dashArray[1] = 2; |
| 509 | dashArray[3] = 2; |
| 510 | } |
| 511 | pGraphics->SetLineDash(0, dashArray, 4); |
| 512 | return FX_DASHSTYLE_DashDot; |
| 513 | } |
| 514 | case XFA_ATTRIBUTEENUM_DashDotDot: { |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 515 | float dashArray[] = {4, 1, 2, 1, 2, 1}; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 516 | if (iCapType != XFA_ATTRIBUTEENUM_Butt) { |
| 517 | dashArray[1] = 2; |
| 518 | dashArray[3] = 2; |
| 519 | dashArray[5] = 2; |
| 520 | } |
| 521 | pGraphics->SetLineDash(0, dashArray, 6); |
| 522 | return FX_DASHSTYLE_DashDotDot; |
| 523 | } |
| 524 | case XFA_ATTRIBUTEENUM_Dashed: { |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 525 | float dashArray[] = {5, 1}; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 526 | if (iCapType != XFA_ATTRIBUTEENUM_Butt) { |
| 527 | dashArray[1] = 2; |
| 528 | } |
| 529 | pGraphics->SetLineDash(0, dashArray, 2); |
| 530 | return FX_DASHSTYLE_Dash; |
| 531 | } |
| 532 | case XFA_ATTRIBUTEENUM_Dotted: { |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 533 | float dashArray[] = {2, 1}; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 534 | if (iCapType != XFA_ATTRIBUTEENUM_Butt) { |
| 535 | dashArray[1] = 2; |
| 536 | } |
| 537 | pGraphics->SetLineDash(0, dashArray, 2); |
| 538 | return FX_DASHSTYLE_Dot; |
| 539 | } |
| 540 | default: |
| 541 | break; |
| 542 | } |
| 543 | pGraphics->SetLineDash(FX_DASHSTYLE_Solid); |
| 544 | return FX_DASHSTYLE_Solid; |
| 545 | } |
| 546 | CFX_GraphStateData::LineCap XFA_LineCapToFXGE(int32_t iLineCap) { |
| 547 | switch (iLineCap) { |
| 548 | case XFA_ATTRIBUTEENUM_Round: |
| 549 | return CFX_GraphStateData::LineCapRound; |
| 550 | case XFA_ATTRIBUTEENUM_Butt: |
| 551 | return CFX_GraphStateData::LineCapButt; |
| 552 | default: |
| 553 | break; |
| 554 | } |
| 555 | return CFX_GraphStateData::LineCapSquare; |
| 556 | } |
thestig | 39fbb7e | 2016-05-12 15:35:00 -0700 | [diff] [blame] | 557 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 558 | class CXFA_ImageRenderer { |
| 559 | public: |
| 560 | CXFA_ImageRenderer(); |
| 561 | ~CXFA_ImageRenderer(); |
thestig | 39fbb7e | 2016-05-12 15:35:00 -0700 | [diff] [blame] | 562 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 563 | bool Start(CFX_RenderDevice* pDevice, |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 564 | const CFX_RetainPtr<CFX_DIBSource>& pDIBSource, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 565 | FX_ARGB bitmap_argb, |
| 566 | int bitmap_alpha, |
| 567 | const CFX_Matrix* pImage2Device, |
| 568 | uint32_t flags, |
| 569 | int blendType = FXDIB_BLEND_NORMAL); |
| 570 | bool Continue(IFX_Pause* pPause); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 571 | |
| 572 | protected: |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 573 | bool StartDIBSource(); |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 574 | void CompositeDIBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 575 | int left, |
| 576 | int top, |
| 577 | FX_ARGB mask_argb, |
| 578 | int bitmap_alpha, |
| 579 | int blend_mode, |
| 580 | int Transparency); |
weili | b4d1b57 | 2016-08-10 14:50:48 -0700 | [diff] [blame] | 581 | |
| 582 | CFX_RenderDevice* m_pDevice; |
| 583 | int m_Status; |
| 584 | CFX_Matrix m_ImageMatrix; |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 585 | CFX_RetainPtr<CFX_DIBSource> m_pDIBSource; |
| 586 | CFX_RetainPtr<CFX_DIBitmap> m_pCloneConvert; |
weili | b4d1b57 | 2016-08-10 14:50:48 -0700 | [diff] [blame] | 587 | int m_BitmapAlpha; |
| 588 | FX_ARGB m_FillArgb; |
| 589 | uint32_t m_Flags; |
| 590 | std::unique_ptr<CFX_ImageTransformer> m_pTransformer; |
Nicolas Pena | c3202a9 | 2017-04-04 13:38:29 -0400 | [diff] [blame] | 591 | std::unique_ptr<CFX_ImageRenderer> m_DeviceHandle; |
weili | b4d1b57 | 2016-08-10 14:50:48 -0700 | [diff] [blame] | 592 | int32_t m_BlendType; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 593 | bool m_Result; |
| 594 | bool m_bPrint; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 595 | }; |
weili | b4d1b57 | 2016-08-10 14:50:48 -0700 | [diff] [blame] | 596 | |
| 597 | CXFA_ImageRenderer::CXFA_ImageRenderer() |
| 598 | : m_pDevice(nullptr), |
| 599 | m_Status(0), |
weili | b4d1b57 | 2016-08-10 14:50:48 -0700 | [diff] [blame] | 600 | m_BitmapAlpha(255), |
| 601 | m_FillArgb(0), |
| 602 | m_Flags(0), |
| 603 | m_DeviceHandle(nullptr), |
| 604 | m_BlendType(FXDIB_BLEND_NORMAL), |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 605 | m_Result(true), |
| 606 | m_bPrint(false) {} |
thestig | 495bda1 | 2016-04-28 17:29:19 -0700 | [diff] [blame] | 607 | |
Nicolas Pena | c3202a9 | 2017-04-04 13:38:29 -0400 | [diff] [blame] | 608 | CXFA_ImageRenderer::~CXFA_ImageRenderer() {} |
thestig | 495bda1 | 2016-04-28 17:29:19 -0700 | [diff] [blame] | 609 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 610 | bool CXFA_ImageRenderer::Start(CFX_RenderDevice* pDevice, |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 611 | const CFX_RetainPtr<CFX_DIBSource>& pDIBSource, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 612 | FX_ARGB bitmap_argb, |
| 613 | int bitmap_alpha, |
| 614 | const CFX_Matrix* pImage2Device, |
| 615 | uint32_t flags, |
| 616 | int blendType) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 617 | m_pDevice = pDevice; |
| 618 | m_pDIBSource = pDIBSource; |
| 619 | m_FillArgb = bitmap_argb; |
| 620 | m_BitmapAlpha = bitmap_alpha; |
| 621 | m_ImageMatrix = *pImage2Device; |
| 622 | m_Flags = flags; |
| 623 | m_BlendType = blendType; |
| 624 | return StartDIBSource(); |
| 625 | } |
thestig | d3e354a | 2016-05-26 11:04:40 -0700 | [diff] [blame] | 626 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 627 | bool CXFA_ImageRenderer::StartDIBSource() { |
thestig | d3e354a | 2016-05-26 11:04:40 -0700 | [diff] [blame] | 628 | if (m_pDevice->StartDIBitsWithBlend(m_pDIBSource, m_BitmapAlpha, m_FillArgb, |
Nicolas Pena | c3202a9 | 2017-04-04 13:38:29 -0400 | [diff] [blame] | 629 | &m_ImageMatrix, m_Flags, &m_DeviceHandle, |
thestig | d3e354a | 2016-05-26 11:04:40 -0700 | [diff] [blame] | 630 | m_BlendType)) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 631 | if (m_DeviceHandle) { |
| 632 | m_Status = 3; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 633 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 634 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 635 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 636 | } |
| 637 | CFX_FloatRect image_rect_f = m_ImageMatrix.GetUnitRect(); |
thestig | ad5ac75 | 2016-08-09 12:09:22 -0700 | [diff] [blame] | 638 | FX_RECT image_rect = image_rect_f.GetOuterRect(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 639 | int dest_width = image_rect.Width(); |
| 640 | int dest_height = image_rect.Height(); |
Dan Sinclair | 669a418 | 2017-04-03 14:51:45 -0400 | [diff] [blame] | 641 | if ((fabs(m_ImageMatrix.b) >= 0.5f || m_ImageMatrix.a == 0) || |
| 642 | (fabs(m_ImageMatrix.c) >= 0.5f || m_ImageMatrix.d == 0)) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 643 | if (m_bPrint && !(m_pDevice->GetRenderCaps() & FXRC_BLEND_MODE)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 644 | m_Result = false; |
| 645 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 646 | } |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 647 | CFX_RetainPtr<CFX_DIBSource> pDib = m_pDIBSource; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 648 | if (m_pDIBSource->HasAlpha() && |
| 649 | !(m_pDevice->GetRenderCaps() & FXRC_ALPHA_IMAGE) && |
| 650 | !(m_pDevice->GetRenderCaps() & FXRC_GET_BITS)) { |
tsepez | 1a1d764 | 2016-12-06 06:29:28 -0800 | [diff] [blame] | 651 | m_pCloneConvert = m_pDIBSource->CloneConvert(FXDIB_Rgb); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 652 | if (!m_pCloneConvert) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 653 | m_Result = false; |
| 654 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 655 | } |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 656 | pDib = m_pCloneConvert; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 657 | } |
| 658 | FX_RECT clip_box = m_pDevice->GetClipBox(); |
| 659 | clip_box.Intersect(image_rect); |
| 660 | m_Status = 2; |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 661 | m_pTransformer = pdfium::MakeUnique<CFX_ImageTransformer>( |
| 662 | pDib, &m_ImageMatrix, m_Flags, &clip_box); |
thestig | 39fbb7e | 2016-05-12 15:35:00 -0700 | [diff] [blame] | 663 | m_pTransformer->Start(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 664 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 665 | } |
| 666 | if (m_ImageMatrix.a < 0) { |
| 667 | dest_width = -dest_width; |
| 668 | } |
| 669 | if (m_ImageMatrix.d > 0) { |
| 670 | dest_height = -dest_height; |
| 671 | } |
| 672 | int dest_left, dest_top; |
| 673 | dest_left = dest_width > 0 ? image_rect.left : image_rect.right; |
| 674 | dest_top = dest_height > 0 ? image_rect.top : image_rect.bottom; |
| 675 | if (m_pDIBSource->IsOpaqueImage() && m_BitmapAlpha == 255) { |
thestig | d3e354a | 2016-05-26 11:04:40 -0700 | [diff] [blame] | 676 | if (m_pDevice->StretchDIBitsWithFlagsAndBlend( |
| 677 | m_pDIBSource, dest_left, dest_top, dest_width, dest_height, m_Flags, |
| 678 | m_BlendType)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 679 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 680 | } |
| 681 | } |
| 682 | if (m_pDIBSource->IsAlphaMask()) { |
| 683 | if (m_BitmapAlpha != 255) { |
| 684 | m_FillArgb = FXARGB_MUL_ALPHA(m_FillArgb, m_BitmapAlpha); |
| 685 | } |
thestig | d3e354a | 2016-05-26 11:04:40 -0700 | [diff] [blame] | 686 | if (m_pDevice->StretchBitMaskWithFlags(m_pDIBSource, dest_left, dest_top, |
| 687 | dest_width, dest_height, m_FillArgb, |
| 688 | m_Flags)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 689 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 690 | } |
| 691 | } |
| 692 | if (m_bPrint && !(m_pDevice->GetRenderCaps() & FXRC_BLEND_MODE)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 693 | m_Result = false; |
| 694 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 695 | } |
| 696 | FX_RECT clip_box = m_pDevice->GetClipBox(); |
| 697 | FX_RECT dest_rect = clip_box; |
| 698 | dest_rect.Intersect(image_rect); |
| 699 | FX_RECT dest_clip( |
| 700 | dest_rect.left - image_rect.left, dest_rect.top - image_rect.top, |
| 701 | dest_rect.right - image_rect.left, dest_rect.bottom - image_rect.top); |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 702 | CFX_RetainPtr<CFX_DIBitmap> pStretched = |
| 703 | m_pDIBSource->StretchTo(dest_width, dest_height, m_Flags, &dest_clip); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 704 | if (pStretched) { |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 705 | CompositeDIBitmap(pStretched, dest_rect.left, dest_rect.top, m_FillArgb, |
| 706 | m_BitmapAlpha, m_BlendType, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 707 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 708 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 709 | } |
thestig | 39fbb7e | 2016-05-12 15:35:00 -0700 | [diff] [blame] | 710 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 711 | bool CXFA_ImageRenderer::Continue(IFX_Pause* pPause) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 712 | if (m_Status == 2) { |
thestig | 39fbb7e | 2016-05-12 15:35:00 -0700 | [diff] [blame] | 713 | if (m_pTransformer->Continue(pPause)) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 714 | return true; |
thestig | 39fbb7e | 2016-05-12 15:35:00 -0700 | [diff] [blame] | 715 | |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 716 | CFX_RetainPtr<CFX_DIBitmap> pBitmap = m_pTransformer->DetachBitmap(); |
thestig | 39fbb7e | 2016-05-12 15:35:00 -0700 | [diff] [blame] | 717 | if (!pBitmap) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 718 | return false; |
thestig | 39fbb7e | 2016-05-12 15:35:00 -0700 | [diff] [blame] | 719 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 720 | if (pBitmap->IsAlphaMask()) { |
thestig | 39fbb7e | 2016-05-12 15:35:00 -0700 | [diff] [blame] | 721 | if (m_BitmapAlpha != 255) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 722 | m_FillArgb = FXARGB_MUL_ALPHA(m_FillArgb, m_BitmapAlpha); |
thestig | 39fbb7e | 2016-05-12 15:35:00 -0700 | [diff] [blame] | 723 | m_Result = |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 724 | m_pDevice->SetBitMask(pBitmap, m_pTransformer->result().left, |
thestig | 39fbb7e | 2016-05-12 15:35:00 -0700 | [diff] [blame] | 725 | m_pTransformer->result().top, m_FillArgb); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 726 | } else { |
thestig | 39fbb7e | 2016-05-12 15:35:00 -0700 | [diff] [blame] | 727 | if (m_BitmapAlpha != 255) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 728 | pBitmap->MultiplyAlpha(m_BitmapAlpha); |
thestig | d3e354a | 2016-05-26 11:04:40 -0700 | [diff] [blame] | 729 | m_Result = m_pDevice->SetDIBitsWithBlend( |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 730 | pBitmap, m_pTransformer->result().left, m_pTransformer->result().top, |
| 731 | m_BlendType); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 732 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 733 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 734 | } |
thestig | 39fbb7e | 2016-05-12 15:35:00 -0700 | [diff] [blame] | 735 | if (m_Status == 3) |
Nicolas Pena | c3202a9 | 2017-04-04 13:38:29 -0400 | [diff] [blame] | 736 | return m_pDevice->ContinueDIBits(m_DeviceHandle.get(), pPause); |
thestig | 39fbb7e | 2016-05-12 15:35:00 -0700 | [diff] [blame] | 737 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 738 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 739 | } |
thestig | 39fbb7e | 2016-05-12 15:35:00 -0700 | [diff] [blame] | 740 | |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 741 | void CXFA_ImageRenderer::CompositeDIBitmap( |
| 742 | const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap, |
| 743 | int left, |
| 744 | int top, |
| 745 | FX_ARGB mask_argb, |
| 746 | int bitmap_alpha, |
| 747 | int blend_mode, |
| 748 | int Transparency) { |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 749 | if (!pDIBitmap) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 750 | return; |
| 751 | } |
tsepez | 7d89e72 | 2016-05-04 13:38:11 -0700 | [diff] [blame] | 752 | bool bIsolated = !!(Transparency & PDFTRANS_ISOLATED); |
| 753 | bool bGroup = !!(Transparency & PDFTRANS_GROUP); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 754 | if (blend_mode == FXDIB_BLEND_NORMAL) { |
| 755 | if (!pDIBitmap->IsAlphaMask()) { |
| 756 | if (bitmap_alpha < 255) { |
| 757 | pDIBitmap->MultiplyAlpha(bitmap_alpha); |
| 758 | } |
| 759 | if (m_pDevice->SetDIBits(pDIBitmap, left, top)) { |
| 760 | return; |
| 761 | } |
| 762 | } else { |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 763 | uint32_t fill_argb = (mask_argb); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 764 | if (bitmap_alpha < 255) { |
| 765 | ((uint8_t*)&fill_argb)[3] = |
| 766 | ((uint8_t*)&fill_argb)[3] * bitmap_alpha / 255; |
| 767 | } |
| 768 | if (m_pDevice->SetBitMask(pDIBitmap, left, top, fill_argb)) { |
| 769 | return; |
| 770 | } |
| 771 | } |
| 772 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 773 | bool bBackAlphaRequired = blend_mode && bIsolated; |
| 774 | bool bGetBackGround = |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 775 | ((m_pDevice->GetRenderCaps() & FXRC_ALPHA_OUTPUT)) || |
| 776 | (!(m_pDevice->GetRenderCaps() & FXRC_ALPHA_OUTPUT) && |
| 777 | (m_pDevice->GetRenderCaps() & FXRC_GET_BITS) && !bBackAlphaRequired); |
| 778 | if (bGetBackGround) { |
| 779 | if (bIsolated || !bGroup) { |
| 780 | if (pDIBitmap->IsAlphaMask()) { |
| 781 | return; |
| 782 | } |
thestig | d3e354a | 2016-05-26 11:04:40 -0700 | [diff] [blame] | 783 | m_pDevice->SetDIBitsWithBlend(pDIBitmap, left, top, blend_mode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 784 | } else { |
| 785 | FX_RECT rect(left, top, left + pDIBitmap->GetWidth(), |
| 786 | top + pDIBitmap->GetHeight()); |
| 787 | rect.Intersect(m_pDevice->GetClipBox()); |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 788 | CFX_RetainPtr<CFX_DIBitmap> pClone; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 789 | if (m_pDevice->GetBackDrop() && m_pDevice->GetBitmap()) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 790 | pClone = m_pDevice->GetBackDrop()->Clone(&rect); |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 791 | CFX_RetainPtr<CFX_DIBitmap> pForeBitmap = m_pDevice->GetBitmap(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 792 | pClone->CompositeBitmap(0, 0, pClone->GetWidth(), pClone->GetHeight(), |
| 793 | pForeBitmap, rect.left, rect.top); |
| 794 | left = left >= 0 ? 0 : left; |
| 795 | top = top >= 0 ? 0 : top; |
| 796 | if (!pDIBitmap->IsAlphaMask()) |
| 797 | pClone->CompositeBitmap(0, 0, pClone->GetWidth(), pClone->GetHeight(), |
| 798 | pDIBitmap, left, top, blend_mode); |
| 799 | else |
| 800 | pClone->CompositeMask(0, 0, pClone->GetWidth(), pClone->GetHeight(), |
| 801 | pDIBitmap, mask_argb, left, top, blend_mode); |
| 802 | } else { |
| 803 | pClone = pDIBitmap; |
| 804 | } |
| 805 | if (m_pDevice->GetBackDrop()) { |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 806 | m_pDevice->SetDIBits(pClone, rect.left, rect.top); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 807 | } else { |
thestig | d3e354a | 2016-05-26 11:04:40 -0700 | [diff] [blame] | 808 | if (pDIBitmap->IsAlphaMask()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 809 | return; |
thestig | d3e354a | 2016-05-26 11:04:40 -0700 | [diff] [blame] | 810 | m_pDevice->SetDIBitsWithBlend(pDIBitmap, rect.left, rect.top, |
| 811 | blend_mode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 812 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 813 | } |
| 814 | return; |
| 815 | } |
tsepez | 1a1d764 | 2016-12-06 06:29:28 -0800 | [diff] [blame] | 816 | if (!pDIBitmap->HasAlpha() || |
| 817 | (m_pDevice->GetRenderCaps() & FXRC_ALPHA_IMAGE)) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 818 | return; |
| 819 | } |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 820 | CFX_RetainPtr<CFX_DIBitmap> pCloneConvert = |
tsepez | 1a1d764 | 2016-12-06 06:29:28 -0800 | [diff] [blame] | 821 | pDIBitmap->CloneConvert(FXDIB_Rgb); |
| 822 | if (!pCloneConvert) |
| 823 | return; |
| 824 | |
| 825 | CXFA_ImageRenderer imageRender; |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 826 | if (!imageRender.Start(m_pDevice, pCloneConvert, m_FillArgb, m_BitmapAlpha, |
| 827 | &m_ImageMatrix, m_Flags)) { |
tsepez | 1a1d764 | 2016-12-06 06:29:28 -0800 | [diff] [blame] | 828 | return; |
| 829 | } |
| 830 | while (imageRender.Continue(nullptr)) |
| 831 | continue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 832 | } |
tsepez | 1a1d764 | 2016-12-06 06:29:28 -0800 | [diff] [blame] | 833 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 834 | void XFA_DrawImage(CFX_Graphics* pGS, |
| 835 | const CFX_RectF& rtImage, |
| 836 | CFX_Matrix* pMatrix, |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 837 | const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 838 | int32_t iAspect, |
| 839 | int32_t iImageXDpi, |
| 840 | int32_t iImageYDpi, |
| 841 | int32_t iHorzAlign, |
| 842 | int32_t iVertAlign) { |
Dan Sinclair | bba2a7c | 2017-02-07 16:36:39 -0500 | [diff] [blame] | 843 | if (rtImage.IsEmpty()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 844 | return; |
Dan Sinclair | bba2a7c | 2017-02-07 16:36:39 -0500 | [diff] [blame] | 845 | if (!pDIBitmap || !pDIBitmap->GetBuffer()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 846 | return; |
Dan Sinclair | bba2a7c | 2017-02-07 16:36:39 -0500 | [diff] [blame] | 847 | |
| 848 | CFX_RectF rtFit( |
| 849 | rtImage.TopLeft(), |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 850 | XFA_UnitPx2Pt((float)pDIBitmap->GetWidth(), (float)iImageXDpi), |
| 851 | XFA_UnitPx2Pt((float)pDIBitmap->GetHeight(), (float)iImageYDpi)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 852 | switch (iAspect) { |
| 853 | case XFA_ATTRIBUTEENUM_Fit: { |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 854 | float f1 = rtImage.height / rtFit.height; |
| 855 | float f2 = rtImage.width / rtFit.width; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 856 | f1 = std::min(f1, f2); |
| 857 | rtFit.height = rtFit.height * f1; |
| 858 | rtFit.width = rtFit.width * f1; |
| 859 | } break; |
| 860 | case XFA_ATTRIBUTEENUM_Actual: |
| 861 | break; |
| 862 | case XFA_ATTRIBUTEENUM_Height: { |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 863 | float f1 = rtImage.height / rtFit.height; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 864 | rtFit.height = rtImage.height; |
| 865 | rtFit.width = f1 * rtFit.width; |
| 866 | } break; |
| 867 | case XFA_ATTRIBUTEENUM_None: |
| 868 | rtFit.height = rtImage.height; |
| 869 | rtFit.width = rtImage.width; |
| 870 | break; |
| 871 | case XFA_ATTRIBUTEENUM_Width: { |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 872 | float f1 = rtImage.width / rtFit.width; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 873 | rtFit.width = rtImage.width; |
| 874 | rtFit.height = rtFit.height * f1; |
| 875 | } break; |
| 876 | } |
| 877 | if (iHorzAlign == XFA_ATTRIBUTEENUM_Center) { |
| 878 | rtFit.left += (rtImage.width - rtFit.width) / 2; |
| 879 | } else if (iHorzAlign == XFA_ATTRIBUTEENUM_Right) { |
| 880 | rtFit.left = rtImage.right() - rtFit.width; |
| 881 | } |
| 882 | if (iVertAlign == XFA_ATTRIBUTEENUM_Middle) { |
| 883 | rtFit.top += (rtImage.height - rtFit.height) / 2; |
| 884 | } else if (iVertAlign == XFA_ATTRIBUTEENUM_Bottom) { |
| 885 | rtFit.top = rtImage.bottom() - rtImage.height; |
| 886 | } |
| 887 | CFX_RenderDevice* pRenderDevice = pGS->GetRenderDevice(); |
| 888 | pRenderDevice->SaveState(); |
dan sinclair | 071d786 | 2017-02-07 20:46:32 -0500 | [diff] [blame] | 889 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 890 | CFX_PathData path; |
| 891 | path.AppendRect(rtImage.left, rtImage.bottom(), rtImage.right(), rtImage.top); |
| 892 | pRenderDevice->SetClip_PathFill(&path, pMatrix, FXFILL_WINDING); |
dan sinclair | 071d786 | 2017-02-07 20:46:32 -0500 | [diff] [blame] | 893 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 894 | CFX_Matrix mtImage(1, 0, 0, -1, 0, 1); |
dan sinclair | 071d786 | 2017-02-07 20:46:32 -0500 | [diff] [blame] | 895 | mtImage.Concat( |
| 896 | CFX_Matrix(rtFit.width, 0, 0, rtFit.height, rtFit.left, rtFit.top)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 897 | mtImage.Concat(*pMatrix); |
dan sinclair | 071d786 | 2017-02-07 20:46:32 -0500 | [diff] [blame] | 898 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 899 | CXFA_ImageRenderer imageRender; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 900 | bool bRet = imageRender.Start(pRenderDevice, pDIBitmap, 0, 255, &mtImage, |
| 901 | FXDIB_INTERPOL); |
dan sinclair | 071d786 | 2017-02-07 20:46:32 -0500 | [diff] [blame] | 902 | while (bRet) |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 903 | bRet = imageRender.Continue(nullptr); |
dan sinclair | 071d786 | 2017-02-07 20:46:32 -0500 | [diff] [blame] | 904 | |
thestig | 41846a0 | 2016-05-26 10:45:30 -0700 | [diff] [blame] | 905 | pRenderDevice->RestoreState(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | static const uint8_t g_inv_base64[128] = { |
| 909 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, |
| 910 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, |
| 911 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 62, 255, |
| 912 | 255, 255, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255, 255, |
| 913 | 255, 255, 255, 255, 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, |
| 914 | 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, |
| 915 | 25, 255, 255, 255, 255, 255, 255, 26, 27, 28, 29, 30, 31, 32, 33, |
| 916 | 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, |
| 917 | 49, 50, 51, 255, 255, 255, 255, 255, |
| 918 | }; |
| 919 | |
| 920 | static uint8_t* XFA_RemoveBase64Whitespace(const uint8_t* pStr, int32_t iLen) { |
| 921 | uint8_t* pCP; |
| 922 | int32_t i = 0, j = 0; |
| 923 | if (iLen == 0) { |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 924 | iLen = FXSYS_strlen((char*)pStr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 925 | } |
| 926 | pCP = FX_Alloc(uint8_t, iLen + 1); |
| 927 | for (; i < iLen; i++) { |
| 928 | if ((pStr[i] & 128) == 0) { |
| 929 | if (g_inv_base64[pStr[i]] != 0xFF || pStr[i] == '=') { |
| 930 | pCP[j++] = pStr[i]; |
| 931 | } |
| 932 | } |
| 933 | } |
| 934 | pCP[j] = '\0'; |
| 935 | return pCP; |
| 936 | } |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 937 | static int32_t XFA_Base64Decode(const char* pStr, uint8_t* pOutBuffer) { |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 938 | if (!pStr) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 939 | return 0; |
| 940 | } |
| 941 | uint8_t* pBuffer = |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 942 | XFA_RemoveBase64Whitespace((uint8_t*)pStr, FXSYS_strlen((char*)pStr)); |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 943 | if (!pBuffer) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 944 | return 0; |
| 945 | } |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 946 | int32_t iLen = FXSYS_strlen((char*)pBuffer); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 947 | int32_t i = 0, j = 0; |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 948 | uint32_t dwLimb = 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 949 | for (; i + 3 < iLen; i += 4) { |
| 950 | if (pBuffer[i] == '=' || pBuffer[i + 1] == '=' || pBuffer[i + 2] == '=' || |
| 951 | pBuffer[i + 3] == '=') { |
| 952 | if (pBuffer[i] == '=' || pBuffer[i + 1] == '=') { |
| 953 | break; |
| 954 | } |
| 955 | if (pBuffer[i + 2] == '=') { |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 956 | dwLimb = ((uint32_t)g_inv_base64[pBuffer[i]] << 6) | |
| 957 | ((uint32_t)g_inv_base64[pBuffer[i + 1]]); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 958 | pOutBuffer[j] = (uint8_t)(dwLimb >> 4) & 0xFF; |
| 959 | j++; |
| 960 | } else { |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 961 | dwLimb = ((uint32_t)g_inv_base64[pBuffer[i]] << 12) | |
| 962 | ((uint32_t)g_inv_base64[pBuffer[i + 1]] << 6) | |
| 963 | ((uint32_t)g_inv_base64[pBuffer[i + 2]]); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 964 | pOutBuffer[j] = (uint8_t)(dwLimb >> 10) & 0xFF; |
| 965 | pOutBuffer[j + 1] = (uint8_t)(dwLimb >> 2) & 0xFF; |
| 966 | j += 2; |
| 967 | } |
| 968 | } else { |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 969 | dwLimb = ((uint32_t)g_inv_base64[pBuffer[i]] << 18) | |
| 970 | ((uint32_t)g_inv_base64[pBuffer[i + 1]] << 12) | |
| 971 | ((uint32_t)g_inv_base64[pBuffer[i + 2]] << 6) | |
| 972 | ((uint32_t)g_inv_base64[pBuffer[i + 3]]); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 973 | pOutBuffer[j] = (uint8_t)(dwLimb >> 16) & 0xff; |
| 974 | pOutBuffer[j + 1] = (uint8_t)(dwLimb >> 8) & 0xff; |
| 975 | pOutBuffer[j + 2] = (uint8_t)(dwLimb)&0xff; |
| 976 | j += 3; |
| 977 | } |
| 978 | } |
| 979 | FX_Free(pBuffer); |
| 980 | return j; |
| 981 | } |
Tom Sepez | 4161c5c | 2016-03-21 12:26:54 -0700 | [diff] [blame] | 982 | |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 983 | static const char g_base64_chars[] = |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 984 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; |
Tom Sepez | 4161c5c | 2016-03-21 12:26:54 -0700 | [diff] [blame] | 985 | |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 986 | char* XFA_Base64Encode(const uint8_t* buf, int32_t buf_len) { |
| 987 | char* out = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 988 | int i, j; |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 989 | uint32_t limb; |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 990 | out = FX_Alloc(char, ((buf_len * 8 + 5) / 6) + 5); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 991 | for (i = 0, j = 0, limb = 0; i + 2 < buf_len; i += 3, j += 4) { |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 992 | limb = ((uint32_t)buf[i] << 16) | ((uint32_t)buf[i + 1] << 8) | |
| 993 | ((uint32_t)buf[i + 2]); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 994 | out[j] = g_base64_chars[(limb >> 18) & 63]; |
| 995 | out[j + 1] = g_base64_chars[(limb >> 12) & 63]; |
| 996 | out[j + 2] = g_base64_chars[(limb >> 6) & 63]; |
| 997 | out[j + 3] = g_base64_chars[(limb)&63]; |
| 998 | } |
| 999 | switch (buf_len - i) { |
| 1000 | case 0: |
| 1001 | break; |
| 1002 | case 1: |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 1003 | limb = ((uint32_t)buf[i]); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1004 | out[j++] = g_base64_chars[(limb >> 2) & 63]; |
| 1005 | out[j++] = g_base64_chars[(limb << 4) & 63]; |
| 1006 | out[j++] = '='; |
| 1007 | out[j++] = '='; |
| 1008 | break; |
| 1009 | case 2: |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 1010 | limb = ((uint32_t)buf[i] << 8) | ((uint32_t)buf[i + 1]); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1011 | out[j++] = g_base64_chars[(limb >> 10) & 63]; |
| 1012 | out[j++] = g_base64_chars[(limb >> 4) & 63]; |
| 1013 | out[j++] = g_base64_chars[(limb << 2) & 63]; |
| 1014 | out[j++] = '='; |
| 1015 | break; |
| 1016 | default: |
| 1017 | break; |
| 1018 | } |
| 1019 | out[j] = '\0'; |
| 1020 | return out; |
| 1021 | } |
tsepez | fc58ad1 | 2016-04-05 12:22:15 -0700 | [diff] [blame] | 1022 | FXCODEC_IMAGE_TYPE XFA_GetImageType(const CFX_WideString& wsType) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1023 | CFX_WideString wsContentType(wsType); |
| 1024 | wsContentType.MakeLower(); |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 1025 | if (wsContentType == L"image/jpg") |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1026 | return FXCODEC_IMAGE_JPG; |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 1027 | if (wsContentType == L"image/png") |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1028 | return FXCODEC_IMAGE_PNG; |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 1029 | if (wsContentType == L"image/gif") |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1030 | return FXCODEC_IMAGE_GIF; |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 1031 | if (wsContentType == L"image/bmp") |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1032 | return FXCODEC_IMAGE_BMP; |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 1033 | if (wsContentType == L"image/tif") |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1034 | return FXCODEC_IMAGE_TIF; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1035 | return FXCODEC_IMAGE_UNKNOWN; |
| 1036 | } |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 1037 | |
| 1038 | CFX_RetainPtr<CFX_DIBitmap> XFA_LoadImageData(CXFA_FFDoc* pDoc, |
| 1039 | CXFA_Image* pImage, |
| 1040 | bool& bNameImage, |
| 1041 | int32_t& iImageXDpi, |
| 1042 | int32_t& iImageYDpi) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1043 | CFX_WideString wsHref; |
dsinclair | 31b08d4 | 2017-03-28 15:47:47 +0000 | [diff] [blame] | 1044 | CFX_WideString wsImage; |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 1045 | pImage->GetHref(wsHref); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1046 | pImage->GetContent(wsImage); |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 1047 | if (wsHref.IsEmpty() && wsImage.IsEmpty()) |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 1048 | return nullptr; |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 1049 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1050 | CFX_WideString wsContentType; |
| 1051 | pImage->GetContentType(wsContentType); |
| 1052 | FXCODEC_IMAGE_TYPE type = XFA_GetImageType(wsContentType); |
| 1053 | CFX_ByteString bsContent; |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 1054 | uint8_t* pImageBuffer = nullptr; |
tsepez | 833619b | 2016-12-07 09:21:17 -0800 | [diff] [blame] | 1055 | CFX_RetainPtr<IFX_SeekableReadStream> pImageFileRead; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1056 | if (wsImage.GetLength() > 0) { |
| 1057 | XFA_ATTRIBUTEENUM iEncoding = |
| 1058 | (XFA_ATTRIBUTEENUM)pImage->GetTransferEncoding(); |
| 1059 | if (iEncoding == XFA_ATTRIBUTEENUM_Base64) { |
| 1060 | CFX_ByteString bsData = wsImage.UTF8Encode(); |
| 1061 | int32_t iLength = bsData.GetLength(); |
| 1062 | pImageBuffer = FX_Alloc(uint8_t, iLength); |
tsepez | b4c9f3f | 2016-04-13 15:41:21 -0700 | [diff] [blame] | 1063 | int32_t iRead = XFA_Base64Decode(bsData.c_str(), pImageBuffer); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1064 | if (iRead > 0) { |
tsepez | 345d489 | 2016-11-30 15:10:55 -0800 | [diff] [blame] | 1065 | pImageFileRead = IFX_MemoryStream::Create(pImageBuffer, iRead); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1066 | } |
| 1067 | } else { |
| 1068 | bsContent = CFX_ByteString::FromUnicode(wsImage); |
tsepez | 345d489 | 2016-11-30 15:10:55 -0800 | [diff] [blame] | 1069 | pImageFileRead = IFX_MemoryStream::Create( |
tsepez | cfd4d57 | 2016-04-08 14:38:54 -0700 | [diff] [blame] | 1070 | const_cast<uint8_t*>(bsContent.raw_str()), bsContent.GetLength()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1071 | } |
| 1072 | } else { |
| 1073 | CFX_WideString wsURL = wsHref; |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 1074 | if (wsURL.Left(7) != L"http://" && wsURL.Left(6) != L"ftp://") { |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 1075 | CFX_RetainPtr<CFX_DIBitmap> pBitmap = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1076 | pDoc->GetPDFNamedImage(wsURL.AsStringC(), iImageXDpi, iImageYDpi); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1077 | if (pBitmap) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1078 | bNameImage = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1079 | return pBitmap; |
| 1080 | } |
| 1081 | } |
dsinclair | a440bb3 | 2016-09-14 07:01:54 -0700 | [diff] [blame] | 1082 | pImageFileRead = pDoc->GetDocEnvironment()->OpenLinkedFile(pDoc, wsURL); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1083 | } |
| 1084 | if (!pImageFileRead) { |
| 1085 | FX_Free(pImageBuffer); |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 1086 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1087 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1088 | bNameImage = false; |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 1089 | CFX_RetainPtr<CFX_DIBitmap> pBitmap = |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1090 | XFA_LoadImageFromBuffer(pImageFileRead, type, iImageXDpi, iImageYDpi); |
| 1091 | FX_Free(pImageBuffer); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1092 | return pBitmap; |
| 1093 | } |
| 1094 | static FXDIB_Format XFA_GetDIBFormat(FXCODEC_IMAGE_TYPE type, |
| 1095 | int32_t iComponents, |
| 1096 | int32_t iBitsPerComponent) { |
| 1097 | FXDIB_Format dibFormat = FXDIB_Argb; |
| 1098 | switch (type) { |
| 1099 | case FXCODEC_IMAGE_BMP: |
| 1100 | case FXCODEC_IMAGE_JPG: |
| 1101 | case FXCODEC_IMAGE_TIF: { |
| 1102 | dibFormat = FXDIB_Rgb32; |
| 1103 | int32_t bpp = iComponents * iBitsPerComponent; |
| 1104 | if (bpp <= 24) { |
| 1105 | dibFormat = FXDIB_Rgb; |
| 1106 | } |
| 1107 | } break; |
| 1108 | case FXCODEC_IMAGE_PNG: |
| 1109 | default: |
| 1110 | break; |
| 1111 | } |
| 1112 | return dibFormat; |
| 1113 | } |
tsepez | 833619b | 2016-12-07 09:21:17 -0800 | [diff] [blame] | 1114 | |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 1115 | CFX_RetainPtr<CFX_DIBitmap> XFA_LoadImageFromBuffer( |
tsepez | 833619b | 2016-12-07 09:21:17 -0800 | [diff] [blame] | 1116 | const CFX_RetainPtr<IFX_SeekableReadStream>& pImageFileRead, |
| 1117 | FXCODEC_IMAGE_TYPE type, |
| 1118 | int32_t& iImageXDpi, |
| 1119 | int32_t& iImageYDpi) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1120 | CFX_GEModule* pGeModule = CFX_GEModule::Get(); |
tsepez | 833619b | 2016-12-07 09:21:17 -0800 | [diff] [blame] | 1121 | if (!pGeModule) |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 1122 | return nullptr; |
tsepez | 833619b | 2016-12-07 09:21:17 -0800 | [diff] [blame] | 1123 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1124 | CCodec_ModuleMgr* pCodecMgr = pGeModule->GetCodecModule(); |
tsepez | 833619b | 2016-12-07 09:21:17 -0800 | [diff] [blame] | 1125 | if (!pCodecMgr) |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 1126 | return nullptr; |
tsepez | 833619b | 2016-12-07 09:21:17 -0800 | [diff] [blame] | 1127 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1128 | CFX_DIBAttribute dibAttr; |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 1129 | CFX_RetainPtr<CFX_DIBitmap> pBitmap; |
Tom Sepez | b4a2618 | 2017-03-01 12:15:00 -0800 | [diff] [blame] | 1130 | std::unique_ptr<CCodec_ProgressiveDecoder> pProgressiveDecoder = |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1131 | pCodecMgr->CreateProgressiveDecoder(); |
dsinclair | 82e24b1 | 2016-06-13 13:46:49 -0700 | [diff] [blame] | 1132 | pProgressiveDecoder->LoadImageInfo(pImageFileRead, type, &dibAttr, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1133 | switch (dibAttr.m_wDPIUnit) { |
| 1134 | case FXCODEC_RESUNIT_CENTIMETER: |
| 1135 | dibAttr.m_nXDPI = (int32_t)(dibAttr.m_nXDPI * 2.54f); |
| 1136 | dibAttr.m_nYDPI = (int32_t)(dibAttr.m_nYDPI * 2.54f); |
| 1137 | break; |
| 1138 | case FXCODEC_RESUNIT_METER: |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1139 | dibAttr.m_nXDPI = (int32_t)(dibAttr.m_nXDPI / (float)100 * 2.54f); |
| 1140 | dibAttr.m_nYDPI = (int32_t)(dibAttr.m_nYDPI / (float)100 * 2.54f); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1141 | break; |
| 1142 | default: |
| 1143 | break; |
| 1144 | } |
| 1145 | iImageXDpi = dibAttr.m_nXDPI > 1 ? dibAttr.m_nXDPI : (96); |
| 1146 | iImageYDpi = dibAttr.m_nYDPI > 1 ? dibAttr.m_nYDPI : (96); |
| 1147 | if (pProgressiveDecoder->GetWidth() > 0 && |
| 1148 | pProgressiveDecoder->GetHeight() > 0) { |
| 1149 | type = pProgressiveDecoder->GetType(); |
| 1150 | int32_t iComponents = pProgressiveDecoder->GetNumComponents(); |
| 1151 | int32_t iBpc = pProgressiveDecoder->GetBPC(); |
| 1152 | FXDIB_Format dibFormat = XFA_GetDIBFormat(type, iComponents, iBpc); |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 1153 | pBitmap = pdfium::MakeRetain<CFX_DIBitmap>(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1154 | pBitmap->Create(pProgressiveDecoder->GetWidth(), |
| 1155 | pProgressiveDecoder->GetHeight(), dibFormat); |
| 1156 | pBitmap->Clear(0xffffffff); |
| 1157 | int32_t nFrames; |
| 1158 | if ((pProgressiveDecoder->GetFrames(nFrames) == |
| 1159 | FXCODEC_STATUS_DECODE_READY) && |
| 1160 | (nFrames > 0)) { |
| 1161 | pProgressiveDecoder->StartDecode(pBitmap, 0, 0, pBitmap->GetWidth(), |
| 1162 | pBitmap->GetHeight()); |
| 1163 | pProgressiveDecoder->ContinueDecode(); |
| 1164 | } |
| 1165 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1166 | return pBitmap; |
| 1167 | } |
Tom Sepez | b4a2618 | 2017-03-01 12:15:00 -0800 | [diff] [blame] | 1168 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1169 | void XFA_RectWidthoutMargin(CFX_RectF& rt, const CXFA_Margin& mg, bool bUI) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1170 | if (!mg) { |
| 1171 | return; |
| 1172 | } |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1173 | float fLeftInset, fTopInset, fRightInset, fBottomInset; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1174 | mg.GetLeftInset(fLeftInset); |
| 1175 | mg.GetTopInset(fTopInset); |
| 1176 | mg.GetRightInset(fRightInset); |
| 1177 | mg.GetBottomInset(fBottomInset); |
| 1178 | rt.Deflate(fLeftInset, fTopInset, fRightInset, fBottomInset); |
| 1179 | } |
| 1180 | CXFA_FFWidget* XFA_GetWidgetFromLayoutItem(CXFA_LayoutItem* pLayoutItem) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1181 | if (XFA_IsCreateWidget(pLayoutItem->GetFormNode()->GetElementType())) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1182 | return static_cast<CXFA_FFWidget*>(pLayoutItem); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1183 | return nullptr; |
| 1184 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1185 | bool XFA_IsCreateWidget(XFA_Element eType) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1186 | return eType == XFA_Element::Field || eType == XFA_Element::Draw || |
| 1187 | eType == XFA_Element::Subform || eType == XFA_Element::ExclGroup; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1188 | } |
| 1189 | static void XFA_BOX_GetPath_Arc(CXFA_Box box, |
| 1190 | CFX_RectF rtDraw, |
| 1191 | CFX_Path& fillPath, |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 1192 | uint32_t dwFlags) { |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1193 | float a, b; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1194 | a = rtDraw.width / 2.0f; |
| 1195 | b = rtDraw.height / 2.0f; |
| 1196 | if (box.IsCircular() || (dwFlags & XFA_DRAWBOX_ForceRound) != 0) { |
| 1197 | a = b = std::min(a, b); |
| 1198 | } |
| 1199 | CFX_PointF center = rtDraw.Center(); |
| 1200 | rtDraw.left = center.x - a; |
| 1201 | rtDraw.top = center.y - b; |
| 1202 | rtDraw.width = a + a; |
| 1203 | rtDraw.height = b + b; |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1204 | float startAngle = 0, sweepAngle = 360; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1205 | bool bStart = box.GetStartAngle(startAngle); |
| 1206 | bool bEnd = box.GetSweepAngle(sweepAngle); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1207 | if (!bStart && !bEnd) { |
| 1208 | fillPath.AddEllipse(rtDraw); |
| 1209 | return; |
| 1210 | } |
| 1211 | startAngle = -startAngle * FX_PI / 180.0f; |
| 1212 | sweepAngle = -sweepAngle * FX_PI / 180.0f; |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 1213 | fillPath.AddArc(rtDraw.TopLeft(), rtDraw.Size(), startAngle, sweepAngle); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1214 | } |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 1215 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1216 | static void XFA_BOX_GetPath(CXFA_Box box, |
tsepez | a0b2d23 | 2017-01-23 11:32:36 -0800 | [diff] [blame] | 1217 | const std::vector<CXFA_Stroke>& strokes, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1218 | CFX_RectF rtWidget, |
| 1219 | CFX_Path& path, |
| 1220 | int32_t nIndex, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1221 | bool bStart, |
| 1222 | bool bCorner) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 1223 | ASSERT(nIndex >= 0 && nIndex < 8); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1224 | int32_t n = (nIndex & 1) ? nIndex - 1 : nIndex; |
| 1225 | CXFA_Corner corner1(strokes[n].GetNode()); |
| 1226 | CXFA_Corner corner2(strokes[(n + 2) % 8].GetNode()); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1227 | float fRadius1 = bCorner ? corner1.GetRadius() : 0.0f; |
| 1228 | float fRadius2 = bCorner ? corner2.GetRadius() : 0.0f; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1229 | bool bInverted = corner1.IsInverted(); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1230 | float offsetY = 0.0f; |
| 1231 | float offsetX = 0.0f; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1232 | bool bRound = corner1.GetJoinType() == XFA_ATTRIBUTEENUM_Round; |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1233 | float halfAfter = 0.0f; |
| 1234 | float halfBefore = 0.0f; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1235 | CXFA_Stroke stroke = strokes[nIndex]; |
| 1236 | if (stroke.IsCorner()) { |
| 1237 | CXFA_Stroke edgeBefore = strokes[(nIndex + 1 * 8 - 1) % 8]; |
| 1238 | CXFA_Stroke edgeAfter = strokes[nIndex + 1]; |
| 1239 | if (stroke.IsInverted()) { |
| 1240 | if (!stroke.SameStyles(edgeBefore)) { |
| 1241 | halfBefore = edgeBefore.GetThickness() / 2; |
| 1242 | } |
| 1243 | if (!stroke.SameStyles(edgeAfter)) { |
| 1244 | halfAfter = edgeAfter.GetThickness() / 2; |
| 1245 | } |
| 1246 | } |
| 1247 | } else { |
| 1248 | CXFA_Stroke edgeBefore = strokes[(nIndex + 8 - 2) % 8]; |
| 1249 | CXFA_Stroke edgeAfter = strokes[(nIndex + 2) % 8]; |
| 1250 | if (!bRound && !bInverted) { |
weili | 038aa53 | 2016-05-20 15:38:29 -0700 | [diff] [blame] | 1251 | halfBefore = edgeBefore.GetThickness() / 2; |
| 1252 | halfAfter = edgeAfter.GetThickness() / 2; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1253 | } |
| 1254 | } |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1255 | float offsetEX = 0.0f; |
| 1256 | float offsetEY = 0.0f; |
| 1257 | float sx = 0.0f; |
| 1258 | float sy = 0.0f; |
| 1259 | float vx = 1.0f; |
| 1260 | float vy = 1.0f; |
| 1261 | float nx = 1.0f; |
| 1262 | float ny = 1.0f; |
weili | 038aa53 | 2016-05-20 15:38:29 -0700 | [diff] [blame] | 1263 | CFX_PointF cpStart; |
| 1264 | CFX_PointF cp1; |
| 1265 | CFX_PointF cp2; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1266 | if (bRound) { |
| 1267 | sy = FX_PI / 2; |
| 1268 | } |
| 1269 | switch (nIndex) { |
| 1270 | case 0: |
| 1271 | case 1: |
| 1272 | cp1 = rtWidget.TopLeft(); |
| 1273 | cp2 = rtWidget.TopRight(); |
| 1274 | if (nIndex == 0) { |
| 1275 | cpStart.x = cp1.x - halfBefore; |
| 1276 | cpStart.y = cp1.y + fRadius1, offsetY = -halfAfter; |
| 1277 | } else { |
| 1278 | cpStart.x = cp1.x + fRadius1 - halfBefore, cpStart.y = cp1.y, |
| 1279 | offsetEX = halfAfter; |
| 1280 | } |
| 1281 | vx = 1, vy = 1; |
| 1282 | nx = -1, ny = 0; |
| 1283 | if (bRound) { |
| 1284 | sx = bInverted ? FX_PI / 2 : FX_PI; |
| 1285 | } else { |
| 1286 | sx = 1, sy = 0; |
| 1287 | } |
| 1288 | break; |
| 1289 | case 2: |
| 1290 | case 3: |
| 1291 | cp1 = rtWidget.TopRight(); |
| 1292 | cp2 = rtWidget.BottomRight(); |
| 1293 | if (nIndex == 2) { |
| 1294 | cpStart.x = cp1.x - fRadius1, cpStart.y = cp1.y - halfBefore, |
| 1295 | offsetX = halfAfter; |
| 1296 | } else { |
| 1297 | cpStart.x = cp1.x, cpStart.y = cp1.y + fRadius1 - halfBefore, |
| 1298 | offsetEY = halfAfter; |
| 1299 | } |
| 1300 | vx = -1, vy = 1; |
| 1301 | nx = 0, ny = -1; |
| 1302 | if (bRound) { |
| 1303 | sx = bInverted ? FX_PI : FX_PI * 3 / 2; |
| 1304 | } else { |
| 1305 | sx = 0, sy = 1; |
| 1306 | } |
| 1307 | break; |
| 1308 | case 4: |
| 1309 | case 5: |
| 1310 | cp1 = rtWidget.BottomRight(); |
| 1311 | cp2 = rtWidget.BottomLeft(); |
| 1312 | if (nIndex == 4) { |
| 1313 | cpStart.x = cp1.x + halfBefore, cpStart.y = cp1.y - fRadius1, |
| 1314 | offsetY = halfAfter; |
| 1315 | } else { |
| 1316 | cpStart.x = cp1.x - fRadius1 + halfBefore, cpStart.y = cp1.y, |
| 1317 | offsetEX = -halfAfter; |
| 1318 | } |
| 1319 | vx = -1, vy = -1; |
| 1320 | nx = 1, ny = 0; |
| 1321 | if (bRound) { |
| 1322 | sx = bInverted ? FX_PI * 3 / 2 : 0; |
| 1323 | } else { |
| 1324 | sx = -1, sy = 0; |
| 1325 | } |
| 1326 | break; |
| 1327 | case 6: |
| 1328 | case 7: |
| 1329 | cp1 = rtWidget.BottomLeft(); |
| 1330 | cp2 = rtWidget.TopLeft(); |
| 1331 | if (nIndex == 6) { |
| 1332 | cpStart.x = cp1.x + fRadius1, cpStart.y = cp1.y + halfBefore, |
| 1333 | offsetX = -halfAfter; |
| 1334 | } else { |
| 1335 | cpStart.x = cp1.x, cpStart.y = cp1.y - fRadius1 + halfBefore, |
| 1336 | offsetEY = -halfAfter; |
| 1337 | } |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 1338 | vx = 1; |
| 1339 | vy = -1; |
| 1340 | nx = 0; |
| 1341 | ny = 1; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1342 | if (bRound) { |
| 1343 | sx = bInverted ? 0 : FX_PI / 2; |
| 1344 | } else { |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 1345 | sx = 0; |
| 1346 | sy = -1; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1347 | } |
| 1348 | break; |
| 1349 | } |
| 1350 | if (bStart) { |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 1351 | path.MoveTo(cpStart); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1352 | } |
| 1353 | if (nIndex & 1) { |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 1354 | path.LineTo(CFX_PointF(cp2.x + fRadius2 * nx + offsetEX, |
| 1355 | cp2.y + fRadius2 * ny + offsetEY)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1356 | return; |
| 1357 | } |
| 1358 | if (bRound) { |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 1359 | if (fRadius1 < 0) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1360 | sx -= FX_PI; |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 1361 | if (bInverted) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1362 | sy *= -1; |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 1363 | |
Dan Sinclair | bba2a7c | 2017-02-07 16:36:39 -0500 | [diff] [blame] | 1364 | CFX_RectF rtRadius(cp1.x + offsetX * 2, cp1.y + offsetY * 2, |
| 1365 | fRadius1 * 2 * vx - offsetX * 2, |
| 1366 | fRadius1 * 2 * vy - offsetY * 2); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1367 | rtRadius.Normalize(); |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 1368 | if (bInverted) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1369 | rtRadius.Offset(-fRadius1 * vx, -fRadius1 * vy); |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 1370 | |
| 1371 | path.ArcTo(rtRadius.TopLeft(), rtRadius.Size(), sx, sy); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1372 | } else { |
weili | 038aa53 | 2016-05-20 15:38:29 -0700 | [diff] [blame] | 1373 | CFX_PointF cp; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1374 | if (bInverted) { |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 1375 | cp.x = cp1.x + fRadius1 * vx; |
| 1376 | cp.y = cp1.y + fRadius1 * vy; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1377 | } else { |
| 1378 | cp = cp1; |
| 1379 | } |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 1380 | path.LineTo(cp); |
| 1381 | path.LineTo(CFX_PointF(cp1.x + fRadius1 * sx + offsetX, |
| 1382 | cp1.y + fRadius1 * sy + offsetY)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1383 | } |
| 1384 | } |
| 1385 | static void XFA_BOX_GetFillPath(CXFA_Box box, |
tsepez | a0b2d23 | 2017-01-23 11:32:36 -0800 | [diff] [blame] | 1386 | const std::vector<CXFA_Stroke>& strokes, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1387 | CFX_RectF rtWidget, |
| 1388 | CFX_Path& fillPath, |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 1389 | uint16_t dwFlags) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1390 | if (box.IsArc() || (dwFlags & XFA_DRAWBOX_ForceRound) != 0) { |
| 1391 | CXFA_Edge edge = box.GetEdge(0); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1392 | float fThickness = edge.GetThickness(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1393 | if (fThickness < 0) { |
| 1394 | fThickness = 0; |
| 1395 | } |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1396 | float fHalf = fThickness / 2; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1397 | int32_t iHand = box.GetHand(); |
| 1398 | if (iHand == XFA_ATTRIBUTEENUM_Left) { |
| 1399 | rtWidget.Inflate(fHalf, fHalf); |
| 1400 | } else if (iHand == XFA_ATTRIBUTEENUM_Right) { |
| 1401 | rtWidget.Deflate(fHalf, fHalf); |
| 1402 | } |
| 1403 | XFA_BOX_GetPath_Arc(box, rtWidget, fillPath, dwFlags); |
| 1404 | return; |
| 1405 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1406 | bool bSameStyles = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1407 | CXFA_Stroke stroke1 = strokes[0]; |
weili | db444d2 | 2016-06-02 15:48:15 -0700 | [diff] [blame] | 1408 | for (int32_t i = 1; i < 8; i++) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1409 | CXFA_Stroke stroke2 = strokes[i]; |
| 1410 | if (!stroke1.SameStyles(stroke2)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1411 | bSameStyles = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1412 | break; |
| 1413 | } |
| 1414 | stroke1 = stroke2; |
| 1415 | } |
| 1416 | if (bSameStyles) { |
| 1417 | stroke1 = strokes[0]; |
weili | db444d2 | 2016-06-02 15:48:15 -0700 | [diff] [blame] | 1418 | for (int32_t i = 2; i < 8; i += 2) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1419 | CXFA_Stroke stroke2 = strokes[i]; |
| 1420 | if (!stroke1.SameStyles(stroke2, XFA_STROKE_SAMESTYLE_NoPresence | |
| 1421 | XFA_STROKE_SAMESTYLE_Corner)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1422 | bSameStyles = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1423 | break; |
| 1424 | } |
| 1425 | stroke1 = stroke2; |
| 1426 | } |
| 1427 | if (bSameStyles) { |
| 1428 | stroke1 = strokes[0]; |
| 1429 | if (stroke1.IsInverted()) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1430 | bSameStyles = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1431 | } |
| 1432 | if (stroke1.GetJoinType() != XFA_ATTRIBUTEENUM_Square) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1433 | bSameStyles = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1434 | } |
| 1435 | } |
| 1436 | } |
| 1437 | if (bSameStyles) { |
| 1438 | fillPath.AddRectangle(rtWidget.left, rtWidget.top, rtWidget.width, |
| 1439 | rtWidget.height); |
| 1440 | return; |
| 1441 | } |
weili | 038aa53 | 2016-05-20 15:38:29 -0700 | [diff] [blame] | 1442 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1443 | for (int32_t i = 0; i < 8; i += 2) { |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1444 | float sx = 0.0f; |
| 1445 | float sy = 0.0f; |
| 1446 | float vx = 1.0f; |
| 1447 | float vy = 1.0f; |
| 1448 | float nx = 1.0f; |
| 1449 | float ny = 1.0f; |
weili | 038aa53 | 2016-05-20 15:38:29 -0700 | [diff] [blame] | 1450 | CFX_PointF cp1, cp2; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1451 | CXFA_Corner corner1(strokes[i].GetNode()); |
| 1452 | CXFA_Corner corner2(strokes[(i + 2) % 8].GetNode()); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1453 | float fRadius1 = corner1.GetRadius(); |
| 1454 | float fRadius2 = corner2.GetRadius(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1455 | bool bInverted = corner1.IsInverted(); |
| 1456 | bool bRound = corner1.GetJoinType() == XFA_ATTRIBUTEENUM_Round; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1457 | if (bRound) { |
| 1458 | sy = FX_PI / 2; |
| 1459 | } |
| 1460 | switch (i) { |
| 1461 | case 0: |
| 1462 | cp1 = rtWidget.TopLeft(); |
| 1463 | cp2 = rtWidget.TopRight(); |
| 1464 | vx = 1, vy = 1; |
| 1465 | nx = -1, ny = 0; |
| 1466 | if (bRound) { |
| 1467 | sx = bInverted ? FX_PI / 2 : FX_PI; |
| 1468 | } else { |
| 1469 | sx = 1, sy = 0; |
| 1470 | } |
| 1471 | break; |
| 1472 | case 2: |
| 1473 | cp1 = rtWidget.TopRight(); |
| 1474 | cp2 = rtWidget.BottomRight(); |
| 1475 | vx = -1, vy = 1; |
| 1476 | nx = 0, ny = -1; |
| 1477 | if (bRound) { |
| 1478 | sx = bInverted ? FX_PI : FX_PI * 3 / 2; |
| 1479 | } else { |
| 1480 | sx = 0, sy = 1; |
| 1481 | } |
| 1482 | break; |
| 1483 | case 4: |
| 1484 | cp1 = rtWidget.BottomRight(); |
| 1485 | cp2 = rtWidget.BottomLeft(); |
| 1486 | vx = -1, vy = -1; |
| 1487 | nx = 1, ny = 0; |
| 1488 | if (bRound) { |
| 1489 | sx = bInverted ? FX_PI * 3 / 2 : 0; |
| 1490 | } else { |
| 1491 | sx = -1, sy = 0; |
| 1492 | } |
| 1493 | break; |
| 1494 | case 6: |
| 1495 | cp1 = rtWidget.BottomLeft(); |
| 1496 | cp2 = rtWidget.TopLeft(); |
| 1497 | vx = 1, vy = -1; |
| 1498 | nx = 0, ny = 1; |
| 1499 | if (bRound) { |
| 1500 | sx = bInverted ? 0 : FX_PI / 2; |
| 1501 | } else { |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 1502 | sx = 0; |
| 1503 | sy = -1; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1504 | } |
| 1505 | break; |
| 1506 | } |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 1507 | if (i == 0) |
| 1508 | fillPath.MoveTo(CFX_PointF(cp1.x, cp1.y + fRadius1)); |
| 1509 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1510 | if (bRound) { |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 1511 | if (fRadius1 < 0) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1512 | sx -= FX_PI; |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 1513 | if (bInverted) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1514 | sy *= -1; |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 1515 | |
Dan Sinclair | bba2a7c | 2017-02-07 16:36:39 -0500 | [diff] [blame] | 1516 | CFX_RectF rtRadius(cp1.x, cp1.y, fRadius1 * 2 * vx, fRadius1 * 2 * vy); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1517 | rtRadius.Normalize(); |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 1518 | if (bInverted) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1519 | rtRadius.Offset(-fRadius1 * vx, -fRadius1 * vy); |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 1520 | |
| 1521 | fillPath.ArcTo(rtRadius.TopLeft(), rtRadius.Size(), sx, sy); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1522 | } else { |
weili | 038aa53 | 2016-05-20 15:38:29 -0700 | [diff] [blame] | 1523 | CFX_PointF cp; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1524 | if (bInverted) { |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 1525 | cp.x = cp1.x + fRadius1 * vx; |
| 1526 | cp.y = cp1.y + fRadius1 * vy; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1527 | } else { |
| 1528 | cp = cp1; |
| 1529 | } |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 1530 | fillPath.LineTo(cp); |
| 1531 | fillPath.LineTo(CFX_PointF(cp1.x + fRadius1 * sx, cp1.y + fRadius1 * sy)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1532 | } |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 1533 | fillPath.LineTo(CFX_PointF(cp2.x + fRadius2 * nx, cp2.y + fRadius2 * ny)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1534 | } |
| 1535 | } |
| 1536 | static void XFA_BOX_Fill_Radial(CXFA_Box box, |
| 1537 | CFX_Graphics* pGS, |
| 1538 | CFX_Path& fillPath, |
| 1539 | CFX_RectF rtFill, |
| 1540 | CFX_Matrix* pMatrix) { |
| 1541 | CXFA_Fill fill = box.GetFill(); |
| 1542 | FX_ARGB crStart, crEnd; |
| 1543 | crStart = fill.GetColor(); |
| 1544 | int32_t iType = fill.GetRadial(crEnd); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1545 | if (iType != XFA_ATTRIBUTEENUM_ToEdge) { |
| 1546 | FX_ARGB temp = crEnd; |
| 1547 | crEnd = crStart; |
| 1548 | crStart = temp; |
| 1549 | } |
Dan Sinclair | 811b8a4 | 2016-03-17 08:59:42 -0400 | [diff] [blame] | 1550 | CFX_Shading shading(rtFill.Center(), rtFill.Center(), 0, |
Dan Sinclair | 669a418 | 2017-04-03 14:51:45 -0400 | [diff] [blame] | 1551 | sqrt(rtFill.Width() * rtFill.Width() + |
| 1552 | rtFill.Height() * rtFill.Height()) / |
Dan Sinclair | 811b8a4 | 2016-03-17 08:59:42 -0400 | [diff] [blame] | 1553 | 2, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1554 | true, true, crStart, crEnd); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1555 | CFX_Color cr(&shading); |
| 1556 | pGS->SetFillColor(&cr); |
| 1557 | pGS->FillPath(&fillPath, FXFILL_WINDING, pMatrix); |
| 1558 | } |
| 1559 | static void XFA_BOX_Fill_Pattern(CXFA_Box box, |
| 1560 | CFX_Graphics* pGS, |
| 1561 | CFX_Path& fillPath, |
| 1562 | CFX_RectF rtFill, |
| 1563 | CFX_Matrix* pMatrix) { |
| 1564 | CXFA_Fill fill = box.GetFill(); |
| 1565 | FX_ARGB crStart, crEnd; |
| 1566 | crStart = fill.GetColor(); |
| 1567 | int32_t iType = fill.GetPattern(crEnd); |
Dan Sinclair | b9c69ab | 2017-02-23 13:30:34 -0500 | [diff] [blame] | 1568 | FX_HatchStyle iHatch = FX_HatchStyle::Cross; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1569 | switch (iType) { |
| 1570 | case XFA_ATTRIBUTEENUM_CrossDiagonal: |
Dan Sinclair | b9c69ab | 2017-02-23 13:30:34 -0500 | [diff] [blame] | 1571 | iHatch = FX_HatchStyle::DiagonalCross; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1572 | break; |
| 1573 | case XFA_ATTRIBUTEENUM_DiagonalLeft: |
Dan Sinclair | b9c69ab | 2017-02-23 13:30:34 -0500 | [diff] [blame] | 1574 | iHatch = FX_HatchStyle::ForwardDiagonal; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1575 | break; |
| 1576 | case XFA_ATTRIBUTEENUM_DiagonalRight: |
Dan Sinclair | b9c69ab | 2017-02-23 13:30:34 -0500 | [diff] [blame] | 1577 | iHatch = FX_HatchStyle::BackwardDiagonal; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1578 | break; |
| 1579 | case XFA_ATTRIBUTEENUM_Horizontal: |
Dan Sinclair | b9c69ab | 2017-02-23 13:30:34 -0500 | [diff] [blame] | 1580 | iHatch = FX_HatchStyle::Horizontal; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1581 | break; |
| 1582 | case XFA_ATTRIBUTEENUM_Vertical: |
Dan Sinclair | b9c69ab | 2017-02-23 13:30:34 -0500 | [diff] [blame] | 1583 | iHatch = FX_HatchStyle::Vertical; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1584 | break; |
| 1585 | default: |
| 1586 | break; |
| 1587 | } |
Dan Sinclair | 811b8a4 | 2016-03-17 08:59:42 -0400 | [diff] [blame] | 1588 | |
| 1589 | CFX_Pattern pattern(iHatch, crEnd, crStart); |
weili | 9b99ebf | 2016-08-22 13:37:04 -0700 | [diff] [blame] | 1590 | CFX_Color cr(&pattern, 0x0); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1591 | pGS->SetFillColor(&cr); |
| 1592 | pGS->FillPath(&fillPath, FXFILL_WINDING, pMatrix); |
| 1593 | } |
| 1594 | static void XFA_BOX_Fill_Linear(CXFA_Box box, |
| 1595 | CFX_Graphics* pGS, |
| 1596 | CFX_Path& fillPath, |
| 1597 | CFX_RectF rtFill, |
| 1598 | CFX_Matrix* pMatrix) { |
| 1599 | CXFA_Fill fill = box.GetFill(); |
| 1600 | FX_ARGB crStart = fill.GetColor(); |
| 1601 | FX_ARGB crEnd; |
| 1602 | int32_t iType = fill.GetLinear(crEnd); |
| 1603 | CFX_PointF ptStart; |
| 1604 | CFX_PointF ptEnd; |
| 1605 | switch (iType) { |
| 1606 | case XFA_ATTRIBUTEENUM_ToRight: |
| 1607 | ptStart = CFX_PointF(rtFill.left, rtFill.top); |
| 1608 | ptEnd = CFX_PointF(rtFill.right(), rtFill.top); |
| 1609 | break; |
| 1610 | case XFA_ATTRIBUTEENUM_ToBottom: |
| 1611 | ptStart = CFX_PointF(rtFill.left, rtFill.top); |
| 1612 | ptEnd = CFX_PointF(rtFill.left, rtFill.bottom()); |
| 1613 | break; |
| 1614 | case XFA_ATTRIBUTEENUM_ToLeft: |
| 1615 | ptStart = CFX_PointF(rtFill.right(), rtFill.top); |
| 1616 | ptEnd = CFX_PointF(rtFill.left, rtFill.top); |
| 1617 | break; |
| 1618 | case XFA_ATTRIBUTEENUM_ToTop: |
| 1619 | ptStart = CFX_PointF(rtFill.left, rtFill.bottom()); |
| 1620 | ptEnd = CFX_PointF(rtFill.left, rtFill.top); |
| 1621 | break; |
| 1622 | default: |
| 1623 | break; |
| 1624 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1625 | CFX_Shading shading(ptStart, ptEnd, false, false, crStart, crEnd); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1626 | CFX_Color cr(&shading); |
| 1627 | pGS->SetFillColor(&cr); |
| 1628 | pGS->FillPath(&fillPath, FXFILL_WINDING, pMatrix); |
| 1629 | } |
| 1630 | static void XFA_BOX_Fill(CXFA_Box box, |
tsepez | a0b2d23 | 2017-01-23 11:32:36 -0800 | [diff] [blame] | 1631 | const std::vector<CXFA_Stroke>& strokes, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1632 | CFX_Graphics* pGS, |
| 1633 | const CFX_RectF& rtWidget, |
| 1634 | CFX_Matrix* pMatrix, |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 1635 | uint32_t dwFlags) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1636 | CXFA_Fill fill = box.GetFill(); |
Dan Sinclair | efcf362 | 2017-02-23 13:29:56 -0500 | [diff] [blame] | 1637 | if (!fill || fill.GetPresence() != XFA_ATTRIBUTEENUM_Visible) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1638 | return; |
Dan Sinclair | efcf362 | 2017-02-23 13:29:56 -0500 | [diff] [blame] | 1639 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1640 | pGS->SaveGraphState(); |
| 1641 | CFX_Path fillPath; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1642 | XFA_BOX_GetFillPath(box, strokes, rtWidget, fillPath, |
| 1643 | (dwFlags & XFA_DRAWBOX_ForceRound) != 0); |
| 1644 | fillPath.Close(); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1645 | XFA_Element eType = fill.GetFillType(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1646 | switch (eType) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1647 | case XFA_Element::Radial: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1648 | XFA_BOX_Fill_Radial(box, pGS, fillPath, rtWidget, pMatrix); |
| 1649 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1650 | case XFA_Element::Pattern: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1651 | XFA_BOX_Fill_Pattern(box, pGS, fillPath, rtWidget, pMatrix); |
| 1652 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1653 | case XFA_Element::Linear: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1654 | XFA_BOX_Fill_Linear(box, pGS, fillPath, rtWidget, pMatrix); |
| 1655 | break; |
| 1656 | default: { |
| 1657 | FX_ARGB cr; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1658 | if (eType == XFA_Element::Stipple) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1659 | int32_t iRate = fill.GetStipple(cr); |
| 1660 | if (iRate == 0) { |
| 1661 | iRate = 100; |
| 1662 | } |
| 1663 | int32_t a = 0; |
| 1664 | FX_COLORREF rgb; |
| 1665 | ArgbDecode(cr, a, rgb); |
| 1666 | cr = ArgbEncode(iRate * a / 100, rgb); |
| 1667 | } else { |
| 1668 | cr = fill.GetColor(); |
| 1669 | } |
| 1670 | CFX_Color fillColor(cr); |
| 1671 | pGS->SetFillColor(&fillColor); |
| 1672 | pGS->FillPath(&fillPath, FXFILL_WINDING, pMatrix); |
| 1673 | } break; |
| 1674 | } |
| 1675 | pGS->RestoreGraphState(); |
| 1676 | } |
| 1677 | static void XFA_BOX_StrokePath(CXFA_Stroke stroke, |
| 1678 | CFX_Path* pPath, |
| 1679 | CFX_Graphics* pGS, |
| 1680 | CFX_Matrix* pMatrix) { |
| 1681 | if (!stroke || !stroke.IsVisible()) { |
| 1682 | return; |
| 1683 | } |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1684 | float fThickness = stroke.GetThickness(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1685 | if (fThickness < 0.001f) { |
| 1686 | return; |
| 1687 | } |
| 1688 | pGS->SaveGraphState(); |
| 1689 | if (stroke.IsCorner() && fThickness > 2 * stroke.GetRadius()) { |
| 1690 | fThickness = 2 * stroke.GetRadius(); |
| 1691 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1692 | pGS->SetLineWidth(fThickness, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1693 | pGS->SetLineCap(CFX_GraphStateData::LineCapButt); |
| 1694 | XFA_StrokeTypeSetLineDash(pGS, stroke.GetStrokeType(), |
| 1695 | XFA_ATTRIBUTEENUM_Butt); |
| 1696 | CFX_Color fxColor(stroke.GetColor()); |
| 1697 | pGS->SetStrokeColor(&fxColor); |
| 1698 | pGS->StrokePath(pPath, pMatrix); |
| 1699 | pGS->RestoreGraphState(); |
| 1700 | } |
| 1701 | static void XFA_BOX_StrokeArc(CXFA_Box box, |
| 1702 | CFX_Graphics* pGS, |
| 1703 | CFX_RectF rtWidget, |
| 1704 | CFX_Matrix* pMatrix, |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 1705 | uint32_t dwFlags) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1706 | CXFA_Edge edge = box.GetEdge(0); |
| 1707 | if (!edge || !edge.IsVisible()) { |
| 1708 | return; |
| 1709 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1710 | bool bVisible = false; |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1711 | float fThickness = 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1712 | int32_t i3DType = box.Get3DStyle(bVisible, fThickness); |
| 1713 | if (i3DType) { |
| 1714 | if (bVisible && fThickness >= 0.001f) { |
| 1715 | dwFlags |= XFA_DRAWBOX_Lowered3D; |
| 1716 | } |
| 1717 | } |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1718 | float fHalf = edge.GetThickness() / 2; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1719 | if (fHalf < 0) { |
| 1720 | fHalf = 0; |
| 1721 | } |
| 1722 | int32_t iHand = box.GetHand(); |
| 1723 | if (iHand == XFA_ATTRIBUTEENUM_Left) { |
| 1724 | rtWidget.Inflate(fHalf, fHalf); |
| 1725 | } else if (iHand == XFA_ATTRIBUTEENUM_Right) { |
| 1726 | rtWidget.Deflate(fHalf, fHalf); |
| 1727 | } |
| 1728 | if ((dwFlags & XFA_DRAWBOX_ForceRound) == 0 || |
| 1729 | (dwFlags & XFA_DRAWBOX_Lowered3D) == 0) { |
Dan Sinclair | efcf362 | 2017-02-23 13:29:56 -0500 | [diff] [blame] | 1730 | if (fHalf < 0.001f) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1731 | return; |
Dan Sinclair | efcf362 | 2017-02-23 13:29:56 -0500 | [diff] [blame] | 1732 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1733 | CFX_Path arcPath; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1734 | XFA_BOX_GetPath_Arc(box, rtWidget, arcPath, dwFlags); |
| 1735 | XFA_BOX_StrokePath(edge, &arcPath, pGS, pMatrix); |
| 1736 | return; |
| 1737 | } |
| 1738 | pGS->SaveGraphState(); |
| 1739 | pGS->SetLineWidth(fHalf); |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 1740 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1741 | float a, b; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1742 | a = rtWidget.width / 2.0f; |
| 1743 | b = rtWidget.height / 2.0f; |
| 1744 | if (dwFlags & XFA_DRAWBOX_ForceRound) { |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 1745 | a = std::min(a, b); |
| 1746 | b = a; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1747 | } |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 1748 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1749 | CFX_PointF center = rtWidget.Center(); |
| 1750 | rtWidget.left = center.x - a; |
| 1751 | rtWidget.top = center.y - b; |
| 1752 | rtWidget.width = a + a; |
| 1753 | rtWidget.height = b + b; |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 1754 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1755 | float startAngle = 0, sweepAngle = 360; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1756 | startAngle = startAngle * FX_PI / 180.0f; |
| 1757 | sweepAngle = -sweepAngle * FX_PI / 180.0f; |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 1758 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1759 | CFX_Path arcPath; |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 1760 | arcPath.AddArc(rtWidget.TopLeft(), rtWidget.Size(), 3.0f * FX_PI / 4.0f, |
| 1761 | FX_PI); |
| 1762 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1763 | CFX_Color cr(0xFF808080); |
| 1764 | pGS->SetStrokeColor(&cr); |
| 1765 | pGS->StrokePath(&arcPath, pMatrix); |
| 1766 | arcPath.Clear(); |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 1767 | arcPath.AddArc(rtWidget.TopLeft(), rtWidget.Size(), -1.0f * FX_PI / 4.0f, |
| 1768 | FX_PI); |
| 1769 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1770 | cr.Set(0xFFFFFFFF); |
| 1771 | pGS->SetStrokeColor(&cr); |
| 1772 | pGS->StrokePath(&arcPath, pMatrix); |
| 1773 | rtWidget.Deflate(fHalf, fHalf); |
| 1774 | arcPath.Clear(); |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 1775 | arcPath.AddArc(rtWidget.TopLeft(), rtWidget.Size(), 3.0f * FX_PI / 4.0f, |
| 1776 | FX_PI); |
| 1777 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1778 | cr.Set(0xFF404040); |
| 1779 | pGS->SetStrokeColor(&cr); |
| 1780 | pGS->StrokePath(&arcPath, pMatrix); |
| 1781 | arcPath.Clear(); |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 1782 | arcPath.AddArc(rtWidget.TopLeft(), rtWidget.Size(), -1.0f * FX_PI / 4.0f, |
| 1783 | FX_PI); |
| 1784 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1785 | cr.Set(0xFFC0C0C0); |
| 1786 | pGS->SetStrokeColor(&cr); |
| 1787 | pGS->StrokePath(&arcPath, pMatrix); |
| 1788 | pGS->RestoreGraphState(); |
| 1789 | } |
| 1790 | static void XFA_Draw3DRect(CFX_Graphics* pGraphic, |
| 1791 | const CFX_RectF& rt, |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1792 | float fLineWidth, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1793 | CFX_Matrix* pMatrix, |
| 1794 | FX_ARGB argbTopLeft, |
| 1795 | FX_ARGB argbBottomRight) { |
| 1796 | CFX_Color crLT(argbTopLeft); |
| 1797 | pGraphic->SetFillColor(&crLT); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1798 | float fBottom = rt.bottom(); |
| 1799 | float fRight = rt.right(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1800 | CFX_Path pathLT; |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 1801 | pathLT.MoveTo(CFX_PointF(rt.left, fBottom)); |
| 1802 | pathLT.LineTo(CFX_PointF(rt.left, rt.top)); |
| 1803 | pathLT.LineTo(CFX_PointF(fRight, rt.top)); |
| 1804 | pathLT.LineTo(CFX_PointF(fRight - fLineWidth, rt.top + fLineWidth)); |
| 1805 | pathLT.LineTo(CFX_PointF(rt.left + fLineWidth, rt.top + fLineWidth)); |
| 1806 | pathLT.LineTo(CFX_PointF(rt.left + fLineWidth, fBottom - fLineWidth)); |
| 1807 | pathLT.LineTo(CFX_PointF(rt.left, fBottom)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1808 | pGraphic->FillPath(&pathLT, FXFILL_WINDING, pMatrix); |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 1809 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1810 | CFX_Color crRB(argbBottomRight); |
| 1811 | pGraphic->SetFillColor(&crRB); |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 1812 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1813 | CFX_Path pathRB; |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 1814 | pathRB.MoveTo(CFX_PointF(fRight, rt.top)); |
| 1815 | pathRB.LineTo(CFX_PointF(fRight, fBottom)); |
| 1816 | pathRB.LineTo(CFX_PointF(rt.left, fBottom)); |
| 1817 | pathRB.LineTo(CFX_PointF(rt.left + fLineWidth, fBottom - fLineWidth)); |
| 1818 | pathRB.LineTo(CFX_PointF(fRight - fLineWidth, fBottom - fLineWidth)); |
| 1819 | pathRB.LineTo(CFX_PointF(fRight - fLineWidth, rt.top + fLineWidth)); |
| 1820 | pathRB.LineTo(CFX_PointF(fRight, rt.top)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1821 | pGraphic->FillPath(&pathRB, FXFILL_WINDING, pMatrix); |
| 1822 | } |
| 1823 | static void XFA_BOX_Stroke_3DRect_Lowered(CFX_Graphics* pGS, |
| 1824 | CFX_RectF rt, |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1825 | float fThickness, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1826 | CFX_Matrix* pMatrix) { |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1827 | float fHalfWidth = fThickness / 2.0f; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1828 | CFX_RectF rtInner(rt); |
| 1829 | rtInner.Deflate(fHalfWidth, fHalfWidth); |
| 1830 | CFX_Color cr(0xFF000000); |
| 1831 | pGS->SetFillColor(&cr); |
| 1832 | CFX_Path path; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1833 | path.AddRectangle(rt.left, rt.top, rt.width, rt.height); |
| 1834 | path.AddRectangle(rtInner.left, rtInner.top, rtInner.width, rtInner.height); |
| 1835 | pGS->FillPath(&path, FXFILL_ALTERNATE, pMatrix); |
| 1836 | XFA_Draw3DRect(pGS, rtInner, fHalfWidth, pMatrix, 0xFF808080, 0xFFC0C0C0); |
| 1837 | } |
| 1838 | static void XFA_BOX_Stroke_3DRect_Raised(CFX_Graphics* pGS, |
| 1839 | CFX_RectF rt, |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1840 | float fThickness, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1841 | CFX_Matrix* pMatrix) { |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1842 | float fHalfWidth = fThickness / 2.0f; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1843 | CFX_RectF rtInner(rt); |
| 1844 | rtInner.Deflate(fHalfWidth, fHalfWidth); |
| 1845 | CFX_Color cr(0xFF000000); |
| 1846 | pGS->SetFillColor(&cr); |
| 1847 | CFX_Path path; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1848 | path.AddRectangle(rt.left, rt.top, rt.width, rt.height); |
| 1849 | path.AddRectangle(rtInner.left, rtInner.top, rtInner.width, rtInner.height); |
| 1850 | pGS->FillPath(&path, FXFILL_ALTERNATE, pMatrix); |
| 1851 | XFA_Draw3DRect(pGS, rtInner, fHalfWidth, pMatrix, 0xFFFFFFFF, 0xFF808080); |
| 1852 | } |
| 1853 | static void XFA_BOX_Stroke_3DRect_Etched(CFX_Graphics* pGS, |
| 1854 | CFX_RectF rt, |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1855 | float fThickness, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1856 | CFX_Matrix* pMatrix) { |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1857 | float fHalfWidth = fThickness / 2.0f; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1858 | XFA_Draw3DRect(pGS, rt, fThickness, pMatrix, 0xFF808080, 0xFFFFFFFF); |
| 1859 | CFX_RectF rtInner(rt); |
| 1860 | rtInner.Deflate(fHalfWidth, fHalfWidth); |
| 1861 | XFA_Draw3DRect(pGS, rtInner, fHalfWidth, pMatrix, 0xFFFFFFFF, 0xFF808080); |
| 1862 | } |
| 1863 | static void XFA_BOX_Stroke_3DRect_Embossed(CFX_Graphics* pGS, |
| 1864 | CFX_RectF rt, |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1865 | float fThickness, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1866 | CFX_Matrix* pMatrix) { |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1867 | float fHalfWidth = fThickness / 2.0f; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1868 | XFA_Draw3DRect(pGS, rt, fThickness, pMatrix, 0xFF808080, 0xFF000000); |
| 1869 | CFX_RectF rtInner(rt); |
| 1870 | rtInner.Deflate(fHalfWidth, fHalfWidth); |
| 1871 | XFA_Draw3DRect(pGS, rtInner, fHalfWidth, pMatrix, 0xFF000000, 0xFF808080); |
| 1872 | } |
| 1873 | static void XFA_BOX_Stroke_Rect(CXFA_Box box, |
tsepez | a0b2d23 | 2017-01-23 11:32:36 -0800 | [diff] [blame] | 1874 | const std::vector<CXFA_Stroke>& strokes, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1875 | CFX_Graphics* pGS, |
| 1876 | CFX_RectF rtWidget, |
| 1877 | CFX_Matrix* pMatrix) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1878 | bool bVisible = false; |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1879 | float fThickness = 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1880 | int32_t i3DType = box.Get3DStyle(bVisible, fThickness); |
| 1881 | if (i3DType) { |
| 1882 | if (!bVisible || fThickness < 0.001f) { |
| 1883 | return; |
| 1884 | } |
| 1885 | switch (i3DType) { |
| 1886 | case XFA_ATTRIBUTEENUM_Lowered: |
| 1887 | XFA_BOX_Stroke_3DRect_Lowered(pGS, rtWidget, fThickness, pMatrix); |
| 1888 | break; |
| 1889 | case XFA_ATTRIBUTEENUM_Raised: |
| 1890 | XFA_BOX_Stroke_3DRect_Raised(pGS, rtWidget, fThickness, pMatrix); |
| 1891 | break; |
| 1892 | case XFA_ATTRIBUTEENUM_Etched: |
| 1893 | XFA_BOX_Stroke_3DRect_Etched(pGS, rtWidget, fThickness, pMatrix); |
| 1894 | break; |
| 1895 | case XFA_ATTRIBUTEENUM_Embossed: |
| 1896 | XFA_BOX_Stroke_3DRect_Embossed(pGS, rtWidget, fThickness, pMatrix); |
| 1897 | break; |
| 1898 | } |
| 1899 | return; |
| 1900 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1901 | bool bClose = false; |
| 1902 | bool bSameStyles = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1903 | CXFA_Stroke stroke1 = strokes[0]; |
weili | db444d2 | 2016-06-02 15:48:15 -0700 | [diff] [blame] | 1904 | for (int32_t i = 1; i < 8; i++) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1905 | CXFA_Stroke stroke2 = strokes[i]; |
| 1906 | if (!stroke1.SameStyles(stroke2)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1907 | bSameStyles = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1908 | break; |
| 1909 | } |
| 1910 | stroke1 = stroke2; |
| 1911 | } |
| 1912 | if (bSameStyles) { |
| 1913 | stroke1 = strokes[0]; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1914 | bClose = true; |
weili | db444d2 | 2016-06-02 15:48:15 -0700 | [diff] [blame] | 1915 | for (int32_t i = 2; i < 8; i += 2) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1916 | CXFA_Stroke stroke2 = strokes[i]; |
| 1917 | if (!stroke1.SameStyles(stroke2, XFA_STROKE_SAMESTYLE_NoPresence | |
| 1918 | XFA_STROKE_SAMESTYLE_Corner)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1919 | bSameStyles = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1920 | break; |
| 1921 | } |
| 1922 | stroke1 = stroke2; |
| 1923 | } |
| 1924 | if (bSameStyles) { |
| 1925 | stroke1 = strokes[0]; |
Dan Sinclair | efcf362 | 2017-02-23 13:29:56 -0500 | [diff] [blame] | 1926 | if (stroke1.IsInverted()) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1927 | bSameStyles = false; |
Dan Sinclair | efcf362 | 2017-02-23 13:29:56 -0500 | [diff] [blame] | 1928 | if (stroke1.GetJoinType() != XFA_ATTRIBUTEENUM_Square) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1929 | bSameStyles = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1930 | } |
| 1931 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1932 | bool bStart = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1933 | CFX_Path path; |
weili | db444d2 | 2016-06-02 15:48:15 -0700 | [diff] [blame] | 1934 | for (int32_t i = 0; i < 8; i++) { |
| 1935 | CXFA_Stroke stroke = strokes[i]; |
| 1936 | if ((i % 1) == 0 && stroke.GetRadius() < 0) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1937 | bool bEmpty = path.IsEmpty(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1938 | if (!bEmpty) { |
weili | db444d2 | 2016-06-02 15:48:15 -0700 | [diff] [blame] | 1939 | XFA_BOX_StrokePath(stroke, &path, pGS, pMatrix); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1940 | path.Clear(); |
| 1941 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1942 | bStart = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1943 | continue; |
| 1944 | } |
| 1945 | XFA_BOX_GetPath(box, strokes, rtWidget, path, i, bStart, !bSameStyles); |
| 1946 | CXFA_Stroke stroke2 = strokes[(i + 1) % 8]; |
weili | db444d2 | 2016-06-02 15:48:15 -0700 | [diff] [blame] | 1947 | bStart = !stroke.SameStyles(stroke2); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1948 | if (bStart) { |
weili | db444d2 | 2016-06-02 15:48:15 -0700 | [diff] [blame] | 1949 | XFA_BOX_StrokePath(stroke, &path, pGS, pMatrix); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1950 | path.Clear(); |
| 1951 | } |
| 1952 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1953 | bool bEmpty = path.IsEmpty(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1954 | if (!bEmpty) { |
| 1955 | if (bClose) { |
| 1956 | path.Close(); |
| 1957 | } |
| 1958 | XFA_BOX_StrokePath(strokes[7], &path, pGS, pMatrix); |
| 1959 | } |
| 1960 | } |
| 1961 | static void XFA_BOX_Stroke(CXFA_Box box, |
tsepez | a0b2d23 | 2017-01-23 11:32:36 -0800 | [diff] [blame] | 1962 | const std::vector<CXFA_Stroke>& strokes, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1963 | CFX_Graphics* pGS, |
| 1964 | CFX_RectF rtWidget, |
| 1965 | CFX_Matrix* pMatrix, |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 1966 | uint32_t dwFlags) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1967 | if (box.IsArc() || (dwFlags & XFA_DRAWBOX_ForceRound) != 0) { |
| 1968 | XFA_BOX_StrokeArc(box, pGS, rtWidget, pMatrix, dwFlags); |
| 1969 | return; |
| 1970 | } |
| 1971 | bool bVisible = false; |
| 1972 | for (int32_t j = 0; j < 4; j++) { |
| 1973 | if (strokes[j * 2 + 1].IsVisible()) { |
| 1974 | bVisible = true; |
| 1975 | break; |
| 1976 | } |
| 1977 | } |
| 1978 | if (!bVisible) { |
| 1979 | return; |
| 1980 | } |
| 1981 | for (int32_t i = 1; i < 8; i += 2) { |
| 1982 | CXFA_Edge edge(strokes[i].GetNode()); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1983 | float fThickness = edge.GetThickness(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1984 | if (fThickness < 0) { |
| 1985 | fThickness = 0; |
| 1986 | } |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1987 | float fHalf = fThickness / 2; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1988 | int32_t iHand = box.GetHand(); |
| 1989 | switch (i) { |
| 1990 | case 1: |
| 1991 | if (iHand == XFA_ATTRIBUTEENUM_Left) { |
| 1992 | rtWidget.top -= fHalf; |
| 1993 | rtWidget.height += fHalf; |
| 1994 | } else if (iHand == XFA_ATTRIBUTEENUM_Right) { |
| 1995 | rtWidget.top += fHalf; |
| 1996 | rtWidget.height -= fHalf; |
| 1997 | } |
| 1998 | break; |
| 1999 | case 3: |
| 2000 | if (iHand == XFA_ATTRIBUTEENUM_Left) { |
| 2001 | rtWidget.width += fHalf; |
| 2002 | } else if (iHand == XFA_ATTRIBUTEENUM_Right) { |
| 2003 | rtWidget.width -= fHalf; |
| 2004 | } |
| 2005 | break; |
| 2006 | case 5: |
| 2007 | if (iHand == XFA_ATTRIBUTEENUM_Left) { |
| 2008 | rtWidget.height += fHalf; |
| 2009 | } else if (iHand == XFA_ATTRIBUTEENUM_Right) { |
| 2010 | rtWidget.height -= fHalf; |
| 2011 | } |
| 2012 | break; |
| 2013 | case 7: |
| 2014 | if (iHand == XFA_ATTRIBUTEENUM_Left) { |
| 2015 | rtWidget.left -= fHalf; |
| 2016 | rtWidget.width += fHalf; |
| 2017 | } else if (iHand == XFA_ATTRIBUTEENUM_Right) { |
| 2018 | rtWidget.left += fHalf; |
| 2019 | rtWidget.width -= fHalf; |
| 2020 | } |
| 2021 | break; |
| 2022 | } |
| 2023 | } |
| 2024 | XFA_BOX_Stroke_Rect(box, strokes, pGS, rtWidget, pMatrix); |
| 2025 | } |
| 2026 | void XFA_DrawBox(CXFA_Box box, |
| 2027 | CFX_Graphics* pGS, |
| 2028 | const CFX_RectF& rtWidget, |
| 2029 | CFX_Matrix* pMatrix, |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 2030 | uint32_t dwFlags) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 2031 | if (!box || box.GetPresence() != XFA_ATTRIBUTEENUM_Visible) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2032 | return; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 2033 | |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 2034 | XFA_Element eType = box.GetElementType(); |
| 2035 | if (eType != XFA_Element::Arc && eType != XFA_Element::Border && |
| 2036 | eType != XFA_Element::Rectangle) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2037 | return; |
| 2038 | } |
tsepez | a0b2d23 | 2017-01-23 11:32:36 -0800 | [diff] [blame] | 2039 | std::vector<CXFA_Stroke> strokes; |
| 2040 | if (!(dwFlags & XFA_DRAWBOX_ForceRound) && eType != XFA_Element::Arc) |
| 2041 | box.GetStrokes(&strokes); |
| 2042 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2043 | XFA_BOX_Fill(box, strokes, pGS, rtWidget, pMatrix, dwFlags); |
| 2044 | XFA_BOX_Stroke(box, strokes, pGS, rtWidget, pMatrix, dwFlags); |
| 2045 | } |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 2046 | |
| 2047 | CXFA_CalcData::CXFA_CalcData() : m_iRefCount(0) {} |
| 2048 | |
Tom Sepez | 51d02b3 | 2017-01-30 14:49:24 -0800 | [diff] [blame] | 2049 | CXFA_CalcData::~CXFA_CalcData() {} |