Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cpdf_scaledrenderbuffer.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_scaledrenderbuffer.h"
8
9#include "core/fpdfapi/parser/cpdf_dictionary.h"
10#include "core/fpdfapi/render/cpdf_devicebuffer.h"
11#include "core/fpdfapi/render/cpdf_rendercontext.h"
12#include "core/fxge/cfx_defaultrenderdevice.h"
13#include "core/fxge/dib/cfx_dibitmap.h"
14
15namespace {
16
17constexpr size_t kImageSizeLimitBytes = 30 * 1024 * 1024;
18
19} // namespace
20
22
24
26 CFX_RenderDevice* pDevice,
27 const FX_RECT& rect,
28 const CPDF_PageObject* pObj,
29 const CPDF_RenderOptions* pOptions,
30 int max_dpi) {
31 m_pDevice = pDevice;
32 if (m_pDevice->GetDeviceCaps(FXDC_RENDER_CAPS) & FXRC_GET_BITS)
33 return true;
34
35 m_Rect = rect;
36 m_Matrix = CPDF_DeviceBuffer::CalculateMatrix(pDevice, rect, max_dpi,
37 /*scale=*/true);
38 m_pBitmapDevice = std::make_unique<CFX_DefaultRenderDevice>();
39 bool bIsAlpha =
40 !!(m_pDevice->GetDeviceCaps(FXDC_RENDER_CAPS) & FXRC_ALPHA_OUTPUT);
42 while (true) {
43 FX_RECT bitmap_rect =
45 int32_t width = bitmap_rect.Width();
46 int32_t height = bitmap_rect.Height();
47 // Set to 0 to make CalculatePitchAndSize() calculate it.
48 constexpr uint32_t kNoPitch = 0;
49 absl::optional<CFX_DIBitmap::PitchAndSize> pitch_size =
50 CFX_DIBitmap::CalculatePitchAndSize(width, height, dibFormat, kNoPitch);
51 if (!pitch_size.has_value())
52 return false;
53
54 if (pitch_size.value().size <= kImageSizeLimitBytes &&
55 m_pBitmapDevice->Create(width, height, dibFormat, nullptr)) {
56 break;
57 }
58 m_Matrix.Scale(0.5f, 0.5f);
59 }
60 pContext->GetBackgroundToDevice(m_pBitmapDevice.get(), pObj, pOptions,
61 m_Matrix);
62 return true;
63}
64
66 return m_pBitmapDevice ? static_cast<CFX_RenderDevice*>(m_pBitmapDevice.get())
67 : m_pDevice.get();
68}
69
71 if (m_pBitmapDevice) {
72#if defined(PDF_USE_SKIA)
73 if (!m_pBitmapDevice->SyncInternalBitmaps()) {
74 return;
75 }
76#endif
77 m_pDevice->StretchDIBits(m_pBitmapDevice->GetBitmap(), m_Rect.left,
78 m_Rect.top, m_Rect.Width(), m_Rect.Height());
79 }
80}
CFX_FloatRect(const FX_RECT &rect)
FX_RECT GetOuterRect() const
CFX_Matrix & operator=(const CFX_Matrix &other)=default
CFX_FloatRect TransformRect(const CFX_FloatRect &rect) const
void Scale(float sx, float sy)
static CFX_Matrix CalculateMatrix(CFX_RenderDevice *pDevice, const FX_RECT &rect, int max_dpi, bool scale)
bool Initialize(CPDF_RenderContext *pContext, CFX_RenderDevice *pDevice, const FX_RECT &rect, const CPDF_PageObject *pObj, const CPDF_RenderOptions *pOptions, int max_dpi)
CFX_RenderDevice * GetDevice() const
FXDIB_Format
Definition fx_dib.h:19
#define FXDC_RENDER_CAPS
#define FXRC_ALPHA_OUTPUT
#define FXRC_GET_BITS
FX_RECT & operator=(const FX_RECT &that)=default
int Height() const
int Width() const