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
cgdi_printer_driver.cpp
Go to the documentation of this file.
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 "core/fxge/win32/cgdi_printer_driver.h"
8
9#include <math.h>
10#include <windows.h>
11
12#include <algorithm>
13#include <memory>
14#include <utility>
15
16#include "core/fxcrt/fx_memory.h"
17#include "core/fxcrt/fx_system.h"
18#include "core/fxcrt/retain_ptr.h"
19#include "core/fxge/cfx_font.h"
20#include "core/fxge/cfx_windowsrenderdevice.h"
21#include "core/fxge/dib/cfx_dibbase.h"
22#include "core/fxge/dib/cfx_dibitmap.h"
23#include "core/fxge/render_defines.h"
24#include "core/fxge/text_char_pos.h"
25#include "third_party/base/check.h"
26#include "third_party/base/check_op.h"
27
32
33CGdiPrinterDriver::~CGdiPrinterDriver() = default;
34
35int CGdiPrinterDriver::GetDeviceCaps(int caps_id) const {
36 if (caps_id == FXDC_HORZ_SIZE)
37 return m_HorzSize;
38 if (caps_id == FXDC_VERT_SIZE)
39 return m_VertSize;
40 return CGdiDeviceDriver::GetDeviceCaps(caps_id);
41}
42
43bool CGdiPrinterDriver::SetDIBits(const RetainPtr<const CFX_DIBBase>& pSource,
44 uint32_t color,
45 const FX_RECT& src_rect,
46 int left,
47 int top,
48 BlendMode blend_type) {
49 if (pSource->IsMaskFormat()) {
50 FX_RECT clip_rect(left, top, left + src_rect.Width(),
51 top + src_rect.Height());
52 int dest_width = pSource->GetWidth();
53 int dest_height = pSource->GetHeight();
54 return StretchDIBits(std::move(pSource), color, left - src_rect.left,
55 top - src_rect.top, dest_width, dest_height,
58 }
59
60 DCHECK_EQ(blend_type, BlendMode::kNormal);
61 if (pSource->IsAlphaFormat())
62 return false;
63
64 return GDI_SetDIBits(pSource, src_rect, left, top);
65}
66
67bool CGdiPrinterDriver::StretchDIBits(RetainPtr<const CFX_DIBBase> bitmap,
68 uint32_t color,
69 int dest_left,
70 int dest_top,
71 int dest_width,
72 int dest_height,
73 const FX_RECT* pClipRect,
74 const FXDIB_ResampleOptions& options,
75 BlendMode blend_type) {
76 if (bitmap->IsMaskFormat()) {
77 int alpha = FXARGB_A(color);
78 if (bitmap->GetBPP() != 1 || alpha != 255) {
79 return false;
80 }
81
82 if (dest_width < 0 || dest_height < 0) {
83 bitmap = bitmap->FlipImage(dest_width < 0, dest_height < 0);
84 if (!bitmap) {
85 return false;
86 }
87
88 if (dest_width < 0)
89 dest_left += dest_width;
90 if (dest_height < 0)
91 dest_top += dest_height;
92
93 dest_width = abs(dest_width);
94 dest_height = abs(dest_height);
95 }
96
97 return GDI_StretchBitMask(std::move(bitmap), dest_left, dest_top,
98 dest_width, dest_height, color);
99 }
100
101 if (bitmap->IsAlphaFormat()) {
102 return false;
103 }
104
105 if (dest_width < 0 || dest_height < 0) {
106 bitmap = bitmap->FlipImage(dest_width < 0, dest_height < 0);
107 if (!bitmap) {
108 return false;
109 }
110
111 if (dest_width < 0)
112 dest_left += dest_width;
113 if (dest_height < 0)
114 dest_top += dest_height;
115
116 dest_width = abs(dest_width);
117 dest_height = abs(dest_height);
118 }
119
120 return GDI_StretchDIBits(std::move(bitmap), dest_left, dest_top, dest_width,
121 dest_height, options);
122}
123
124bool CGdiPrinterDriver::StartDIBits(RetainPtr<const CFX_DIBBase> bitmap,
125 float alpha,
126 uint32_t color,
127 const CFX_Matrix& matrix,
128 const FXDIB_ResampleOptions& options,
129 std::unique_ptr<CFX_ImageRenderer>* handle,
130 BlendMode blend_type) {
131 if (alpha != 1.0f || bitmap->IsAlphaFormat() ||
132 (bitmap->IsMaskFormat() && (bitmap->GetBPP() != 1))) {
133 return false;
134 }
135 CFX_FloatRect unit_rect = matrix.GetUnitRect();
136 FX_RECT full_rect = unit_rect.GetOuterRect();
137 if (fabs(matrix.b) < 0.5f && matrix.a != 0 && fabs(matrix.c) < 0.5f &&
138 matrix.d != 0) {
139 bool bFlipX = matrix.a < 0;
140 bool bFlipY = matrix.d > 0;
141 return StretchDIBits(std::move(bitmap), color,
142 bFlipX ? full_rect.right : full_rect.left,
143 bFlipY ? full_rect.bottom : full_rect.top,
144 bFlipX ? -full_rect.Width() : full_rect.Width(),
145 bFlipY ? -full_rect.Height() : full_rect.Height(),
146 nullptr, FXDIB_ResampleOptions(), blend_type);
147 }
148 if (fabs(matrix.a) >= 0.5f || fabs(matrix.d) >= 0.5f)
149 return false;
150
151 const bool flip_x = matrix.c > 0;
152 const bool flip_y = matrix.b < 0;
153 bitmap = bitmap->SwapXY(flip_x, flip_y);
154 if (!bitmap) {
155 return false;
156 }
157
158 return StretchDIBits(std::move(bitmap), color, full_rect.left, full_rect.top,
159 full_rect.Width(), full_rect.Height(), nullptr,
160 FXDIB_ResampleOptions(), blend_type);
161}
162
163bool CGdiPrinterDriver::DrawDeviceText(
164 pdfium::span<const TextCharPos> pCharPos,
165 CFX_Font* pFont,
166 const CFX_Matrix& mtObject2Device,
167 float font_size,
168 uint32_t color,
169 const CFX_TextRenderOptions& /*options*/) {
170 return false;
171}
FX_RECT GetOuterRect() const
CFX_FloatRect GetUnitRect() const
bool GDI_SetDIBits(const RetainPtr< const CFX_DIBBase > &source, const FX_RECT &src_rect, int left, int top)
bool GDI_StretchDIBits(RetainPtr< const CFX_DIBBase > source, int dest_left, int dest_top, int dest_width, int dest_height, const FXDIB_ResampleOptions &options)
int GetDeviceCaps(int caps_id) const override
bool GDI_StretchBitMask(RetainPtr< const CFX_DIBBase > source, int dest_left, int dest_top, int dest_width, int dest_height, uint32_t bitmap_color)
bool StretchDIBits(RetainPtr< const CFX_DIBBase > bitmap, uint32_t color, int dest_left, int dest_top, int dest_width, int dest_height, const FX_RECT *pClipRect, const FXDIB_ResampleOptions &options, BlendMode blend_type) override
bool SetDIBits(const RetainPtr< const CFX_DIBBase > &pBitmap, uint32_t color, const FX_RECT &src_rect, int left, int top, BlendMode blend_type) override
~CGdiPrinterDriver() override
int GetDeviceCaps(int caps_id) const override
bool DrawDeviceText(pdfium::span< const TextCharPos > pCharPos, CFX_Font *pFont, const CFX_Matrix &mtObject2Device, float font_size, uint32_t color, const CFX_TextRenderOptions &options) override
bool StartDIBits(RetainPtr< const CFX_DIBBase > bitmap, float alpha, uint32_t color, const CFX_Matrix &matrix, const FXDIB_ResampleOptions &options, std::unique_ptr< CFX_ImageRenderer > *handle, BlendMode blend_type) override
BlendMode
Definition fx_dib.h:49
#define FXARGB_A(argb)
Definition fx_dib.h:124
#define FXDC_VERT_SIZE
#define FXDC_HORZ_SIZE
int Height() const
int32_t bottom
int32_t right
int Width() const
int32_t top
int32_t left
constexpr FX_RECT(int l, int t, int r, int b)