1 // Copyright 2014 PDFium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #include "xfa/fxfa/app/xfa_ffimage.h" 8 9 #include "xfa/fxfa/app/xfa_ffdraw.h" 10 #include "xfa/fxfa/xfa_ffapp.h" 11 #include "xfa/fxfa/xfa_ffdoc.h" 12 #include "xfa/fxfa/xfa_ffpageview.h" 13 #include "xfa/fxfa/xfa_ffwidget.h" 14 15 CXFA_FFImage::CXFA_FFImage(CXFA_WidgetAcc* pDataAcc) : CXFA_FFDraw(pDataAcc) {} 16 17 CXFA_FFImage::~CXFA_FFImage() { 18 CXFA_FFImage::UnloadWidget(); 19 } 20 21 bool CXFA_FFImage::IsLoaded() { 22 return !!GetDataAcc()->GetImageImage(); 23 } 24 bool CXFA_FFImage::LoadWidget() { 25 if (GetDataAcc()->GetImageImage()) { 26 return true; 27 } 28 GetDataAcc()->LoadImageImage(); 29 return CXFA_FFDraw::LoadWidget(); 30 } 31 void CXFA_FFImage::UnloadWidget() { 32 GetDataAcc()->SetImageImage(nullptr); 33 } 34 void CXFA_FFImage::RenderWidget(CFX_Graphics* pGS, 35 CFX_Matrix* pMatrix, 36 uint32_t dwStatus) { 37 if (!IsMatchVisibleStatus(dwStatus)) 38 return; 39 40 CFX_Matrix mtRotate = GetRotateMatrix(); 41 if (pMatrix) 42 mtRotate.Concat(*pMatrix); 43 44 CXFA_FFWidget::RenderWidget(pGS, &mtRotate, dwStatus); 45 46 CFX_DIBitmap* pDIBitmap = GetDataAcc()->GetImageImage(); 47 if (!pDIBitmap) 48 return; 49 50 CFX_RectF rtImage = GetRectWithoutRotate(); 51 if (CXFA_Margin mgWidget = m_pDataAcc->GetMargin()) 52 XFA_RectWidthoutMargin(rtImage, mgWidget); 53 54 int32_t iHorzAlign = XFA_ATTRIBUTEENUM_Left; 55 int32_t iVertAlign = XFA_ATTRIBUTEENUM_Top; 56 if (CXFA_Para para = m_pDataAcc->GetPara()) { 57 iHorzAlign = para.GetHorizontalAlign(); 58 iVertAlign = para.GetVerticalAlign(); 59 } 60 61 CXFA_Value value = m_pDataAcc->GetFormValue(); 62 CXFA_Image imageObj = value.GetImage(); 63 int32_t iAspect = imageObj.GetAspect(); 64 int32_t iImageXDpi = 0; 65 int32_t iImageYDpi = 0; 66 m_pDataAcc->GetImageDpi(iImageXDpi, iImageYDpi); 67 XFA_DrawImage(pGS, rtImage, &mtRotate, pDIBitmap, iAspect, iImageXDpi, 68 iImageYDpi, iHorzAlign, iVertAlign); 69 } 70