• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #include "xfa/fxfa/cxfa_ffimage.h"
8 
9 #include "core/fxge/dib/cfx_dibitmap.h"
10 #include "xfa/fxfa/cxfa_ffapp.h"
11 #include "xfa/fxfa/cxfa_ffdoc.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_FFWidget(pNode) {}
19 
~CXFA_FFImage()20 CXFA_FFImage::~CXFA_FFImage() {
21   GetNode()->SetImageImage(nullptr);
22 }
23 
IsLoaded()24 bool CXFA_FFImage::IsLoaded() {
25   return !!GetNode()->GetImageImage();
26 }
27 
LoadWidget()28 bool CXFA_FFImage::LoadWidget() {
29   if (GetNode()->GetImageImage())
30     return true;
31 
32   return GetNode()->LoadImageImage(GetDoc()) && CXFA_FFWidget::LoadWidget();
33 }
34 
RenderWidget(CXFA_Graphics * pGS,const CFX_Matrix & matrix,HighlightOption highlight)35 void CXFA_FFImage::RenderWidget(CXFA_Graphics* pGS,
36                                 const CFX_Matrix& matrix,
37                                 HighlightOption highlight) {
38   if (!HasVisibleStatus())
39     return;
40 
41   CFX_Matrix mtRotate = GetRotateMatrix();
42   mtRotate.Concat(matrix);
43 
44   CXFA_FFWidget::RenderWidget(pGS, mtRotate, highlight);
45 
46   RetainPtr<CFX_DIBitmap> pDIBitmap = GetNode()->GetImageImage();
47   if (!pDIBitmap)
48     return;
49 
50   CFX_RectF rtImage = GetRectWithoutRotate();
51   CXFA_Margin* margin = m_pNode->GetMarginIfExists();
52   XFA_RectWithoutMargin(&rtImage, margin);
53 
54   XFA_AttributeValue iHorzAlign = XFA_AttributeValue::Left;
55   XFA_AttributeValue iVertAlign = XFA_AttributeValue::Top;
56   CXFA_Para* para = m_pNode->GetParaIfExists();
57   if (para) {
58     iHorzAlign = para->GetHorizontalAlign();
59     iVertAlign = para->GetVerticalAlign();
60   }
61 
62   auto* value = m_pNode->GetFormValueIfExists();
63   CXFA_Image* image = value ? value->GetImageIfExists() : nullptr;
64   if (image) {
65     XFA_DrawImage(pGS, rtImage, mtRotate, pDIBitmap, image->GetAspect(),
66                   m_pNode->GetImageDpi(), iHorzAlign, iVertAlign);
67   }
68 }
69