xref: /aosp_15_r20/external/pdfium/xfa/fxfa/cxfa_ffimage.cpp (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1 // Copyright 2014 The PDFium Authors
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 <utility>
10 
11 #include "core/fxge/dib/cfx_dibitmap.h"
12 #include "xfa/fxfa/cxfa_ffapp.h"
13 #include "xfa/fxfa/cxfa_ffdoc.h"
14 #include "xfa/fxfa/cxfa_ffpageview.h"
15 #include "xfa/fxfa/cxfa_ffwidget.h"
16 #include "xfa/fxfa/parser/cxfa_image.h"
17 #include "xfa/fxfa/parser/cxfa_para.h"
18 #include "xfa/fxfa/parser/cxfa_value.h"
19 
CXFA_FFImage(CXFA_Node * pNode)20 CXFA_FFImage::CXFA_FFImage(CXFA_Node* pNode) : CXFA_FFWidget(pNode) {}
21 
22 CXFA_FFImage::~CXFA_FFImage() = default;
23 
PreFinalize()24 void CXFA_FFImage::PreFinalize() {
25   GetNode()->SetLayoutImage(nullptr);
26 }
27 
IsLoaded()28 bool CXFA_FFImage::IsLoaded() {
29   return !!GetNode()->GetLayoutImage();
30 }
31 
LoadWidget()32 bool CXFA_FFImage::LoadWidget() {
33   if (GetNode()->GetLayoutImage())
34     return true;
35 
36   return GetNode()->LoadLayoutImage(GetDoc()) && CXFA_FFWidget::LoadWidget();
37 }
38 
RenderWidget(CFGAS_GEGraphics * pGS,const CFX_Matrix & matrix,HighlightOption highlight)39 void CXFA_FFImage::RenderWidget(CFGAS_GEGraphics* pGS,
40                                 const CFX_Matrix& matrix,
41                                 HighlightOption highlight) {
42   if (!HasVisibleStatus())
43     return;
44 
45   CFX_Matrix mtRotate = GetRotateMatrix();
46   mtRotate.Concat(matrix);
47 
48   CXFA_FFWidget::RenderWidget(pGS, mtRotate, highlight);
49 
50   RetainPtr<CFX_DIBitmap> pDIBitmap = GetNode()->GetLayoutImage();
51   if (!pDIBitmap)
52     return;
53 
54   CFX_RectF rtImage = GetRectWithoutRotate();
55   CXFA_Margin* margin = m_pNode->GetMarginIfExists();
56   XFA_RectWithoutMargin(&rtImage, margin);
57 
58   XFA_AttributeValue iHorzAlign = XFA_AttributeValue::Left;
59   XFA_AttributeValue iVertAlign = XFA_AttributeValue::Top;
60   CXFA_Para* para = m_pNode->GetParaIfExists();
61   if (para) {
62     iHorzAlign = para->GetHorizontalAlign();
63     iVertAlign = para->GetVerticalAlign();
64   }
65 
66   auto* value = m_pNode->GetFormValueIfExists();
67   if (!value)
68     return;
69 
70   CXFA_Image* image = value->GetImageIfExists();
71   if (!image)
72     return;
73 
74   XFA_DrawImage(pGS, rtImage, mtRotate, std::move(pDIBitmap),
75                 image->GetAspect(), m_pNode->GetLayoutImageDpi(), iHorzAlign,
76                 iVertAlign);
77 }
78