1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "xfa/fxfa/cxfa_ffimage.h"
8
9 #include "xfa/fxfa/cxfa_ffapp.h"
10 #include "xfa/fxfa/cxfa_ffdoc.h"
11 #include "xfa/fxfa/cxfa_ffdraw.h"
12 #include "xfa/fxfa/cxfa_ffpageview.h"
13 #include "xfa/fxfa/cxfa_ffwidget.h"
14 #include "xfa/fxfa/parser/cxfa_image.h"
15 #include "xfa/fxfa/parser/cxfa_para.h"
16 #include "xfa/fxfa/parser/cxfa_value.h"
17
CXFA_FFImage(CXFA_Node * pNode)18 CXFA_FFImage::CXFA_FFImage(CXFA_Node* pNode) : CXFA_FFDraw(pNode) {}
19
~CXFA_FFImage()20 CXFA_FFImage::~CXFA_FFImage() {
21 CXFA_FFImage::UnloadWidget();
22 }
23
IsLoaded()24 bool CXFA_FFImage::IsLoaded() {
25 return !!GetNode()->GetWidgetAcc()->GetImageImage();
26 }
27
LoadWidget()28 bool CXFA_FFImage::LoadWidget() {
29 if (GetNode()->GetWidgetAcc()->GetImageImage())
30 return true;
31
32 return GetNode()->GetWidgetAcc()->LoadImageImage(GetDoc())
33 ? CXFA_FFDraw::LoadWidget()
34 : false;
35 }
36
UnloadWidget()37 void CXFA_FFImage::UnloadWidget() {
38 GetNode()->GetWidgetAcc()->SetImageImage(nullptr);
39 }
40
RenderWidget(CXFA_Graphics * pGS,const CFX_Matrix & matrix,uint32_t dwStatus)41 void CXFA_FFImage::RenderWidget(CXFA_Graphics* pGS,
42 const CFX_Matrix& matrix,
43 uint32_t dwStatus) {
44 if (!IsMatchVisibleStatus(dwStatus))
45 return;
46
47 CFX_Matrix mtRotate = GetRotateMatrix();
48 mtRotate.Concat(matrix);
49
50 CXFA_FFWidget::RenderWidget(pGS, mtRotate, dwStatus);
51
52 RetainPtr<CFX_DIBitmap> pDIBitmap =
53 GetNode()->GetWidgetAcc()->GetImageImage();
54 if (!pDIBitmap)
55 return;
56
57 CFX_RectF rtImage = GetRectWithoutRotate();
58 CXFA_Margin* margin = m_pNode->GetMarginIfExists();
59 if (margin)
60 XFA_RectWithoutMargin(rtImage, margin);
61
62 XFA_AttributeEnum iHorzAlign = XFA_AttributeEnum::Left;
63 XFA_AttributeEnum iVertAlign = XFA_AttributeEnum::Top;
64 CXFA_Para* para = m_pNode->GetParaIfExists();
65 if (para) {
66 iHorzAlign = para->GetHorizontalAlign();
67 iVertAlign = para->GetVerticalAlign();
68 }
69
70 int32_t iImageXDpi = 0;
71 int32_t iImageYDpi = 0;
72 m_pNode->GetWidgetAcc()->GetImageDpi(iImageXDpi, iImageYDpi);
73
74 auto* value = m_pNode->GetFormValueIfExists();
75 CXFA_Image* image = value ? value->GetImageIfExists() : nullptr;
76 if (image) {
77 XFA_DrawImage(pGS, rtImage, mtRotate, pDIBitmap, image->GetAspect(),
78 iImageXDpi, iImageYDpi, iHorzAlign, iVertAlign);
79 }
80 }
81