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_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
26namespace {
27
28#if BUILDFLAG(IS_WIN)
29constexpr bool kScaleDeviceBuffer = true;
30#else
31constexpr bool kScaleDeviceBuffer = false;
32#endif
33
34} // namespace
35
36// static
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
61 CFX_RenderDevice* pDevice,
62 const FX_RECT& rect,
63 const CPDF_PageObject* pObj,
64 int max_dpi)
66#if BUILDFLAG(IS_WIN)
68#endif
71 m_Rect(rect),
72 m_Matrix(CalculateMatrix(pDevice, rect, max_dpi, kScaleDeviceBuffer)) {
73}
74
76
78 FX_RECT bitmap_rect =
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
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
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
118#endif
119}
CFX_FloatRect(const FX_RECT &rect)
FX_RECT GetOuterRect() const
CFX_FloatRect TransformRect(const CFX_FloatRect &rect) const
void Translate(int32_t x, int32_t y)
void Scale(float sx, float sy)
int GetDeviceCaps(int id) const
CPDF_DeviceBuffer(CPDF_RenderContext *pContext, CFX_RenderDevice *pDevice, const FX_RECT &rect, const CPDF_PageObject *pObj, int max_dpi)
static CFX_Matrix CalculateMatrix(CFX_RenderDevice *pDevice, const FX_RECT &rect, int max_dpi, bool scale)
RetainPtr< CFX_DIBitmap > Initialize()
#define NOTREACHED_NORETURN()
Definition notreached.h:22
#define FXDC_RENDER_CAPS
#define FXDC_PIXEL_WIDTH
#define FXDC_VERT_SIZE
#define FXDC_PIXEL_HEIGHT
#define FXDC_HORZ_SIZE
#define FXRC_GET_BITS
FX_RECT(const FX_RECT &that)=default
int32_t top
int32_t left