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_rendercontext.h"
15#include "core/fpdfapi/render/cpdf_renderoptions.h"
16#include "core/fxge/cfx_defaultrenderdevice.h"
17#include "core/fxge/cfx_renderdevice.h"
18#include "core/fxge/dib/cfx_dibitmap.h"
19#include "core/fxge/dib/fx_dib.h"
20
21namespace {
22
23#if BUILDFLAG(IS_APPLE)
24constexpr bool kScaleDeviceBuffer = false;
25#else
26constexpr bool kScaleDeviceBuffer = true;
27#endif
28
29} // namespace
30
31// static
33 const FX_RECT& rect,
34 int max_dpi,
35 bool scale) {
36 CFX_Matrix matrix;
37 matrix.Translate(-rect.left, -rect.top);
38 if (scale) {
39 int horz_size = pDevice->GetDeviceCaps(FXDC_HORZ_SIZE);
40 int vert_size = pDevice->GetDeviceCaps(FXDC_VERT_SIZE);
41 if (horz_size && vert_size && max_dpi) {
42 int dpih =
43 pDevice->GetDeviceCaps(FXDC_PIXEL_WIDTH) * 254 / (horz_size * 10);
44 int dpiv =
45 pDevice->GetDeviceCaps(FXDC_PIXEL_HEIGHT) * 254 / (vert_size * 10);
46 if (dpih > max_dpi)
47 matrix.Scale(static_cast<float>(max_dpi) / dpih, 1.0f);
48 if (dpiv > max_dpi)
49 matrix.Scale(1.0f, static_cast<float>(max_dpi) / dpiv);
50 }
51 }
52 return matrix;
53}
54
56 CFX_RenderDevice* pDevice,
57 const FX_RECT& rect,
58 const CPDF_PageObject* pObj,
59 int max_dpi)
64 m_Rect(rect),
65 m_Matrix(CalculateMatrix(pDevice, rect, max_dpi, kScaleDeviceBuffer)) {}
66
68
70 FX_RECT bitmap_rect =
72 if (!m_pBitmap->Create(bitmap_rect.Width(), bitmap_rect.Height(),
73 FXDIB_Format::kArgb)) {
74 return nullptr;
75 }
76 return m_pBitmap;
77}
78
80 if (m_pDevice->GetDeviceCaps(FXDC_RENDER_CAPS) & FXRC_GET_BITS) {
81 if (m_Matrix.a == 1.0f && m_Matrix.d == 1.0f) {
82 m_pDevice->SetDIBits(m_pBitmap, m_Rect.left, m_Rect.top);
83 } else {
84 m_pDevice->StretchDIBits(m_pBitmap, m_Rect.left, m_Rect.top,
85 m_Rect.Width(), m_Rect.Height());
86 }
87 return;
88 }
89 auto buffer = pdfium::MakeRetain<CFX_DIBitmap>();
90 if (!m_pDevice->CreateCompatibleBitmap(buffer, m_pBitmap->GetWidth(),
91 m_pBitmap->GetHeight())) {
92 return;
93 }
94 m_pContext->GetBackgroundToBitmap(buffer, m_pObject, m_Matrix);
95 buffer->CompositeBitmap(0, 0, buffer->GetWidth(), buffer->GetHeight(),
96 m_pBitmap, 0, 0, BlendMode::kNormal, nullptr, false);
97 m_pDevice->StretchDIBits(std::move(buffer), m_Rect.left, m_Rect.top,
98 m_Rect.Width(), m_Rect.Height());
99}
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 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