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
cps_printer_driver.cpp
Go to the documentation of this file.
1// Copyright 2020 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/cps_printer_driver.h"
8
9#include <stdint.h>
10
11#include <sstream>
12#include <utility>
13
14#include "core/fxcrt/data_vector.h"
15#include "core/fxcrt/fx_system.h"
16#include "core/fxcrt/retain_ptr.h"
17#include "core/fxge/cfx_fillrenderoptions.h"
18#include "core/fxge/cfx_path.h"
19#include "core/fxge/dib/cfx_dibbase.h"
20#include "core/fxge/dib/cfx_imagerenderer.h"
21#include "core/fxge/win32/cpsoutput.h"
22#include "third_party/base/check.h"
23#include "third_party/base/notreached.h"
24
25namespace {
26
27CFX_PSRenderer::RenderingLevel RenderingLevelFromWindowsPrintMode(
28 WindowsPrintMode mode) {
29 switch (mode) {
39 default:
40 // |mode| should be PostScript.
41 NOTREACHED_NORETURN();
42 }
43}
44
45} // namespace
46
47CPSPrinterDriver::CPSPrinterDriver(HDC hDC,
49 CFX_PSFontTracker* ps_font_tracker,
50 const EncoderIface* encoder_iface)
53 RenderingLevelFromWindowsPrintMode(mode);
54 CPSOutput::OutputMode output_mode =
59 : CPSOutput::OutputMode::kExtEscape;
60
61 m_HorzSize = ::GetDeviceCaps(m_hDC, HORZSIZE);
62 m_VertSize = ::GetDeviceCaps(m_hDC, VERTSIZE);
63 m_Width = ::GetDeviceCaps(m_hDC, HORZRES);
64 m_Height = ::GetDeviceCaps(m_hDC, VERTRES);
65 m_nBitsPerPixel = ::GetDeviceCaps(m_hDC, BITSPIXEL);
66
67 m_PSRenderer.Init(pdfium::MakeRetain<CPSOutput>(m_hDC, output_mode), level,
68 m_Width, m_Height);
69 HRGN hRgn = ::CreateRectRgn(0, 0, 1, 1);
70 if (::GetClipRgn(m_hDC, hRgn) == 1) {
71 DWORD dwCount = ::GetRegionData(hRgn, 0, nullptr);
72 if (dwCount) {
73 DataVector<uint8_t> buffer(dwCount);
74 RGNDATA* pData = reinterpret_cast<RGNDATA*>(buffer.data());
75 if (::GetRegionData(hRgn, dwCount, pData)) {
76 CFX_Path path;
77 for (uint32_t i = 0; i < pData->rdh.nCount; i++) {
78 RECT* pRect =
79 reinterpret_cast<RECT*>(pData->Buffer + pData->rdh.nRgnSize * i);
80 path.AppendRect(static_cast<float>(pRect->left),
81 static_cast<float>(pRect->bottom),
82 static_cast<float>(pRect->right),
83 static_cast<float>(pRect->top));
84 }
85 m_PSRenderer.SetClip_PathFill(path, nullptr,
86 CFX_FillRenderOptions::WindingOptions());
87 }
88 }
89 }
90 ::DeleteObject(hRgn);
91}
92
93CPSPrinterDriver::~CPSPrinterDriver() = default;
94
95DeviceType CPSPrinterDriver::GetDeviceType() const {
97}
98
99int CPSPrinterDriver::GetDeviceCaps(int caps_id) const {
100 switch (caps_id) {
101 case FXDC_PIXEL_WIDTH:
102 return m_Width;
104 return m_Height;
105 case FXDC_BITS_PIXEL:
106 return m_nBitsPerPixel;
107 case FXDC_RENDER_CAPS:
108 return FXRC_BIT_MASK;
109 case FXDC_HORZ_SIZE:
110 return m_HorzSize;
111 case FXDC_VERT_SIZE:
112 return m_VertSize;
113 default:
114 NOTREACHED_NORETURN();
115 }
116}
117
118void CPSPrinterDriver::SaveState() {
119 m_PSRenderer.SaveState();
120}
121
122void CPSPrinterDriver::RestoreState(bool bKeepSaved) {
123 m_PSRenderer.RestoreState(bKeepSaved);
124}
125
126bool CPSPrinterDriver::SetClip_PathFill(
127 const CFX_Path& path,
128 const CFX_Matrix* pObject2Device,
129 const CFX_FillRenderOptions& fill_options) {
130 m_PSRenderer.SetClip_PathFill(path, pObject2Device, fill_options);
131 return true;
132}
133
134bool CPSPrinterDriver::SetClip_PathStroke(
135 const CFX_Path& path,
136 const CFX_Matrix* pObject2Device,
137 const CFX_GraphStateData* pGraphState) {
138 m_PSRenderer.SetClip_PathStroke(path, pObject2Device, pGraphState);
139 return true;
140}
141
142bool CPSPrinterDriver::DrawPath(const CFX_Path& path,
143 const CFX_Matrix* pObject2Device,
144 const CFX_GraphStateData* pGraphState,
145 FX_ARGB fill_color,
146 FX_ARGB stroke_color,
147 const CFX_FillRenderOptions& fill_options,
148 BlendMode blend_type) {
149 if (blend_type != BlendMode::kNormal)
150 return false;
151 return m_PSRenderer.DrawPath(path, pObject2Device, pGraphState, fill_color,
152 stroke_color, fill_options);
153}
154
155bool CPSPrinterDriver::GetClipBox(FX_RECT* pRect) {
156 *pRect = m_PSRenderer.GetClipBox();
157 return true;
158}
159
160bool CPSPrinterDriver::SetDIBits(const RetainPtr<const CFX_DIBBase>& pBitmap,
161 uint32_t color,
162 const FX_RECT& src_rect,
163 int left,
164 int top,
165 BlendMode blend_type) {
166 if (blend_type != BlendMode::kNormal)
167 return false;
168 return m_PSRenderer.SetDIBits(pBitmap, color, left, top);
169}
170
171bool CPSPrinterDriver::StretchDIBits(RetainPtr<const CFX_DIBBase> bitmap,
172 uint32_t color,
173 int dest_left,
174 int dest_top,
175 int dest_width,
176 int dest_height,
177 const FX_RECT* pClipRect,
178 const FXDIB_ResampleOptions& options,
179 BlendMode blend_type) {
180 return blend_type == BlendMode::kNormal &&
181 m_PSRenderer.StretchDIBits(std::move(bitmap), color, dest_left,
182 dest_top, dest_width, dest_height, options);
183}
184
185bool CPSPrinterDriver::StartDIBits(RetainPtr<const CFX_DIBBase> bitmap,
186 float alpha,
187 uint32_t color,
188 const CFX_Matrix& matrix,
189 const FXDIB_ResampleOptions& options,
190 std::unique_ptr<CFX_ImageRenderer>* handle,
191 BlendMode blend_type) {
192 if (blend_type != BlendMode::kNormal || alpha != 1.0f) {
193 return false;
194 }
195
196 *handle = nullptr;
197 return m_PSRenderer.DrawDIBits(std::move(bitmap), color, matrix, options);
198}
199
200bool CPSPrinterDriver::DrawDeviceText(
201 pdfium::span<const TextCharPos> pCharPos,
202 CFX_Font* pFont,
203 const CFX_Matrix& mtObject2Device,
204 float font_size,
205 uint32_t color,
206 const CFX_TextRenderOptions& /*options*/) {
207 return m_PSRenderer.DrawText(pCharPos.size(), pCharPos.data(), pFont,
208 mtObject2Device, font_size, color);
209}
210
211bool CPSPrinterDriver::MultiplyAlpha(float alpha) {
212 // PostScript doesn't support transparency. All callers are using
213 // `CFX_DIBitmap`-backed raster devices anyway.
214 NOTREACHED_NORETURN();
215}
216
217bool CPSPrinterDriver::MultiplyAlphaMask(
218 const RetainPtr<const CFX_DIBBase>& mask) {
219 // PostScript doesn't support transparency. All callers are using
220 // `CFX_DIBitmap`-backed raster devices anyway.
221 NOTREACHED_NORETURN();
222}
void AppendRect(float left, float bottom, float right, float top)
Definition cfx_path.cpp:309
bool SetClip_PathFill(const CFX_Path &paath, const CFX_Matrix *pObject2Device, const CFX_FillRenderOptions &fill_options) override
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
CPSPrinterDriver(HDC hDC, WindowsPrintMode mode, CFX_PSFontTracker *ps_font_tracker, const EncoderIface *encoder_iface)
bool MultiplyAlphaMask(const RetainPtr< const CFX_DIBBase > &mask) override
bool GetClipBox(FX_RECT *pRect) 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
~CPSPrinterDriver() 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 MultiplyAlpha(float alpha) override
void SaveState() override
bool SetClip_PathStroke(const CFX_Path &path, const CFX_Matrix *pObject2Device, const CFX_GraphStateData *pGraphState) 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
DeviceType GetDeviceType() const override
void RestoreState(bool bKeepSaved) override
bool DrawPath(const CFX_Path &path, const CFX_Matrix *pObject2Device, const CFX_GraphStateData *pGraphState, uint32_t fill_color, uint32_t stroke_color, const CFX_FillRenderOptions &fill_options, BlendMode blend_type) override
BlendMode
Definition fx_dib.h:49
#define FXDC_BITS_PIXEL
#define FXDC_RENDER_CAPS
#define FXDC_PIXEL_WIDTH
#define FXRC_BIT_MASK
#define FXDC_VERT_SIZE
#define FXDC_PIXEL_HEIGHT
#define FXDC_HORZ_SIZE