Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
cpdf_devicebuffer.cpp
Go to the documentation of this file.
1
// Copyright 2016 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
"core/fpdfapi/render/cpdf_devicebuffer.h"
8
9
#
include
<
utility
>
10
11
#
include
"build/build_config.h"
12
#
include
"core/fpdfapi/page/cpdf_pageobject.h"
13
#
include
"core/fpdfapi/parser/cpdf_dictionary.h"
14
#
include
"core/fpdfapi/render/cpdf_renderoptions.h"
15
#
include
"core/fxge/cfx_defaultrenderdevice.h"
16
#
include
"core/fxge/cfx_renderdevice.h"
17
#
include
"core/fxge/dib/cfx_dibitmap.h"
18
#
include
"core/fxge/dib/fx_dib.h"
19
20
#
if
BUILDFLAG
(
IS_WIN
)
21
#
include
"core/fpdfapi/render/cpdf_rendercontext.h"
22
#
else
23
#
include
"core/fxcrt/notreached.h"
24
#
endif
25
26
namespace
{
27
28
#
if
BUILDFLAG
(
IS_WIN
)
29
constexpr
bool
kScaleDeviceBuffer =
true
;
30
#
else
31
constexpr
bool
kScaleDeviceBuffer =
false
;
32
#
endif
33
34
}
// namespace
35
36
// static
37
CFX_Matrix
CPDF_DeviceBuffer
::
CalculateMatrix
(
CFX_RenderDevice
* pDevice,
38
const
FX_RECT
& rect,
39
int
max_dpi,
40
bool
scale) {
41
CFX_Matrix
matrix;
42
matrix
.
Translate
(
-rect
.
left
,
-rect
.
top
)
;
43
if
(scale) {
44
int
horz_size = pDevice
->
GetDeviceCaps
(
FXDC_HORZ_SIZE
)
;
45
int
vert_size = pDevice
->
GetDeviceCaps
(
FXDC_VERT_SIZE
)
;
46
if
(horz_size && vert_size && max_dpi) {
47
int
dpih =
48
pDevice
->
GetDeviceCaps
(
FXDC_PIXEL_WIDTH
)
* 254 / (horz_size * 10);
49
int
dpiv =
50
pDevice
->
GetDeviceCaps
(
FXDC_PIXEL_HEIGHT
)
* 254 / (vert_size * 10);
51
if
(dpih > max_dpi)
52
matrix
.
Scale
(
static_cast
<
float
>(max_dpi) / dpih
,
1.0f
)
;
53
if
(dpiv > max_dpi)
54
matrix
.
Scale
(
1.0f
,
static_cast
<
float
>(max_dpi) / dpiv
)
;
55
}
56
}
57
return
matrix;
58
}
59
60
CPDF_DeviceBuffer
::
CPDF_DeviceBuffer
(
CPDF_RenderContext
* pContext,
61
CFX_RenderDevice
* pDevice,
62
const
FX_RECT
& rect,
63
const
CPDF_PageObject
* pObj,
64
int
max_dpi)
65
:
m_pDevice
(
pDevice
),
66
#
if
BUILDFLAG
(
IS_WIN
)
67
m_pContext
(
pContext
),
68
#
endif
69
m_pObject
(
pObj
),
70
m_pBitmap
(
pdfium
::
MakeRetain
<
CFX_DIBitmap
>()),
71
m_Rect
(
rect
)
,
72
m_Matrix(
CalculateMatrix
(
pDevice
,
rect
,
max_dpi
,
kScaleDeviceBuffer
)
) {
73
}
74
75
CPDF_DeviceBuffer
::~
CPDF_DeviceBuffer
() =
default
;
76
77
RetainPtr
<CFX_DIBitmap>
CPDF_DeviceBuffer
::
Initialize
() {
78
FX_RECT
bitmap_rect =
79
m_Matrix
.
TransformRect
(
CFX_FloatRect
(
m_Rect
)
)
.
GetOuterRect
(
)
;
80
// TODO(crbug.com/355630557): Consider adding support for
81
// `FXDIB_Format::kBgraPremul`
82
if
(!m_pBitmap->Create(bitmap_rect.Width(), bitmap_rect.Height(),
83
FXDIB_Format::kBgra)) {
84
return
nullptr
;
85
}
86
return
m_pBitmap;
87
}
88
89
void
CPDF_DeviceBuffer
::
OutputToDevice
() {
90
if
(m_pDevice->GetDeviceCaps(
FXDC_RENDER_CAPS
) &
FXRC_GET_BITS
) {
91
if
(m_Matrix
.
a
== 1.0f && m_Matrix
.
d
== 1.0f) {
92
m_pDevice->SetDIBits(m_pBitmap, m_Rect.left, m_Rect.top);
93
return
;
94
}
95
96
#
if
BUILDFLAG
(
IS_WIN
)
97
m_pDevice->StretchDIBits(m_pBitmap, m_Rect.left, m_Rect.top, m_Rect.Width(),
98
m_Rect.Height());
99
return
;
100
#
else
101
NOTREACHED_NORETURN
();
102
#
endif
103
}
104
105
#
if
BUILDFLAG
(
IS_WIN
)
106
auto
buffer = pdfium::MakeRetain<CFX_DIBitmap>();
107
if
(!m_pDevice->CreateCompatibleBitmap(buffer, m_pBitmap->GetWidth(),
108
m_pBitmap->GetHeight())) {
109
return
;
110
}
111
m_pContext->GetBackgroundToBitmap(buffer, m_pObject, m_Matrix);
112
buffer->CompositeBitmap(0, 0, buffer->GetWidth(), buffer->GetHeight(),
113
m_pBitmap, 0, 0, BlendMode::kNormal,
nullptr
,
false
);
114
m_pDevice->StretchDIBits(std::move(buffer), m_Rect.left, m_Rect.top,
115
m_Rect.Width(), m_Rect.Height());
116
#
else
117
NOTREACHED_NORETURN
();
118
#
endif
119
}
CFX_FloatRect
Definition
fx_coordinates.h:185
CFX_FloatRect::CFX_FloatRect
CFX_FloatRect(const FX_RECT &rect)
Definition
fx_coordinates.cpp:130
CFX_FloatRect::GetOuterRect
FX_RECT GetOuterRect() const
Definition
fx_coordinates.cpp:183
CFX_Matrix
Definition
fx_coordinates.h:440
CFX_Matrix::TransformRect
CFX_FloatRect TransformRect(const CFX_FloatRect &rect) const
Definition
fx_coordinates.cpp:475
CFX_Matrix::d
float d
Definition
fx_coordinates.h:510
CFX_Matrix::a
float a
Definition
fx_coordinates.h:507
CFX_Matrix::Translate
void Translate(int32_t x, int32_t y)
Definition
fx_coordinates.h:483
CFX_Matrix::Scale
void Scale(float sx, float sy)
Definition
fx_coordinates.cpp:406
CFX_RenderDevice
Definition
cfx_renderdevice.h:39
CFX_RenderDevice::GetDeviceCaps
int GetDeviceCaps(int id) const
Definition
cfx_renderdevice.cpp:533
CPDF_DeviceBuffer
Definition
cpdf_devicebuffer.h:20
CPDF_DeviceBuffer::CPDF_DeviceBuffer
CPDF_DeviceBuffer(CPDF_RenderContext *pContext, CFX_RenderDevice *pDevice, const FX_RECT &rect, const CPDF_PageObject *pObj, int max_dpi)
Definition
cpdf_devicebuffer.cpp:60
CPDF_DeviceBuffer::~CPDF_DeviceBuffer
~CPDF_DeviceBuffer()
CPDF_DeviceBuffer::CalculateMatrix
static CFX_Matrix CalculateMatrix(CFX_RenderDevice *pDevice, const FX_RECT &rect, int max_dpi, bool scale)
Definition
cpdf_devicebuffer.cpp:37
CPDF_DeviceBuffer::OutputToDevice
void OutputToDevice()
Definition
cpdf_devicebuffer.cpp:89
CPDF_DeviceBuffer::Initialize
RetainPtr< CFX_DIBitmap > Initialize()
Definition
cpdf_devicebuffer.cpp:77
CPDF_PageObject
Definition
cpdf_pageobject.h:27
CPDF_RenderContext
Definition
cpdf_rendercontext.h:27
fxcrt::RetainPtr
Definition
retain_ptr.h:28
NOTREACHED_NORETURN
#define NOTREACHED_NORETURN()
Definition
notreached.h:22
FXDC_RENDER_CAPS
#define FXDC_RENDER_CAPS
Definition
render_defines.h:15
FXDC_PIXEL_WIDTH
#define FXDC_PIXEL_WIDTH
Definition
render_defines.h:10
FXDC_VERT_SIZE
#define FXDC_VERT_SIZE
Definition
render_defines.h:14
FXDC_PIXEL_HEIGHT
#define FXDC_PIXEL_HEIGHT
Definition
render_defines.h:11
FXDC_HORZ_SIZE
#define FXDC_HORZ_SIZE
Definition
render_defines.h:13
FXRC_GET_BITS
#define FXRC_GET_BITS
Definition
render_defines.h:17
FX_RECT
Definition
fx_coordinates.h:144
FX_RECT::FX_RECT
FX_RECT(const FX_RECT &that)=default
FX_RECT::top
int32_t top
Definition
fx_coordinates.h:179
FX_RECT::left
int32_t left
Definition
fx_coordinates.h:178
qtwebengine
src
3rdparty
chromium
third_party
pdfium
core
fpdfapi
render
cpdf_devicebuffer.cpp
Generated on
for Qt by
1.18.0