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
cfx_psrenderer.h
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#ifndef CORE_FXGE_WIN32_CFX_PSRENDERER_H_
8#define CORE_FXGE_WIN32_CFX_PSRENDERER_H_
9
10#include <stddef.h>
11#include <stdint.h>
12
13#include <memory>
14#include <sstream>
15#include <vector>
16
17#include "core/fxcrt/bytestring.h"
18#include "core/fxcrt/data_vector.h"
19#include "core/fxcrt/fx_coordinates.h"
20#include "core/fxcrt/fx_memory_wrappers.h"
21#include "core/fxcrt/fx_stream.h"
22#include "core/fxcrt/fx_string_wrappers.h"
23#include "core/fxcrt/retain_ptr.h"
24#include "core/fxcrt/unowned_ptr.h"
25#include "core/fxge/cfx_graphstatedata.h"
26#include "third_party/abseil-cpp/absl/types/optional.h"
27#include "third_party/base/containers/span.h"
28
29class CFX_DIBBase;
30class CFX_Font;
31class CFX_GlyphCache;
33class CFX_Path;
34class TextCharPos;
37
39 DataVector<uint8_t> (*pA85EncodeFunc)(pdfium::span<const uint8_t> src_span);
40 DataVector<uint8_t> (*pFaxEncodeFunc)(RetainPtr<const CFX_DIBBase> src);
41 DataVector<uint8_t> (*pFlateEncodeFunc)(pdfium::span<const uint8_t> src_span);
42 bool (*pJpegEncodeFunc)(const RetainPtr<const CFX_DIBBase>& pSource,
43 uint8_t** dest_buf,
44 size_t* dest_size);
45 DataVector<uint8_t> (*pRunLengthEncodeFunc)(
46 pdfium::span<const uint8_t> src_span);
47};
48
50 public:
51 enum class RenderingLevel {
52 kLevel2,
53 kLevel3,
55 };
56
58 const EncoderIface* encoder_iface);
60
61 void Init(const RetainPtr<IFX_RetainableWriteStream>& stream,
62 RenderingLevel level,
63 int width,
64 int height);
65 void SaveState();
66 void RestoreState(bool bKeepSaved);
67 void SetClip_PathFill(const CFX_Path& path,
68 const CFX_Matrix* pObject2Device,
69 const CFX_FillRenderOptions& fill_options);
70 void SetClip_PathStroke(const CFX_Path& path,
71 const CFX_Matrix* pObject2Device,
72 const CFX_GraphStateData* pGraphState);
73 FX_RECT GetClipBox() { return m_ClipBox; }
74 bool DrawPath(const CFX_Path& path,
75 const CFX_Matrix* pObject2Device,
76 const CFX_GraphStateData* pGraphState,
77 uint32_t fill_color,
78 uint32_t stroke_color,
79 const CFX_FillRenderOptions& fill_options);
80 bool SetDIBits(const RetainPtr<const CFX_DIBBase>& pBitmap,
81 uint32_t color,
82 int dest_left,
83 int dest_top);
84 bool StretchDIBits(RetainPtr<const CFX_DIBBase> bitmap,
85 uint32_t color,
86 int dest_left,
87 int dest_top,
88 int dest_width,
89 int dest_height,
90 const FXDIB_ResampleOptions& options);
91 bool DrawDIBits(RetainPtr<const CFX_DIBBase> bitmap,
92 uint32_t color,
93 const CFX_Matrix& matrix,
94 const FXDIB_ResampleOptions& options);
95 bool DrawText(int nChars,
96 const TextCharPos* pCharPos,
97 CFX_Font* pFont,
98 const CFX_Matrix& mtObject2Device,
99 float font_size,
100 uint32_t color);
101
103 const ByteString& psname,
104 pdfium::span<const uint8_t> font_data);
105
107 const ByteString& psname,
108 const FX_RECT& bbox,
109 size_t num_glyphs,
110 size_t glyphs_per_descendant_font);
111
112 private:
113 struct Glyph;
114
115 struct FaxCompressResult {
116 FaxCompressResult();
117 FaxCompressResult(const FaxCompressResult&) = delete;
118 FaxCompressResult& operator=(const FaxCompressResult&) = delete;
119 FaxCompressResult(FaxCompressResult&&) noexcept;
120 FaxCompressResult& operator=(FaxCompressResult&&) noexcept;
121 ~FaxCompressResult();
122
123 DataVector<uint8_t> data;
124 bool compressed = false;
125 };
126
127 struct PSCompressResult {
128 PSCompressResult();
129 PSCompressResult(const PSCompressResult&) = delete;
130 PSCompressResult& operator=(const PSCompressResult&) = delete;
131 PSCompressResult(PSCompressResult&&) noexcept;
132 PSCompressResult& operator=(PSCompressResult&&) noexcept;
133 ~PSCompressResult();
134
135 DataVector<uint8_t> data;
136 ByteString filter;
137 };
138
139 void StartRendering();
140 void EndRendering();
141 void OutputPath(const CFX_Path& path, const CFX_Matrix* pObject2Device);
142 void SetGraphState(const CFX_GraphStateData* pGraphState);
143 void SetColor(uint32_t color);
144 void FindPSFontGlyph(CFX_GlyphCache* pGlyphCache,
145 CFX_Font* pFont,
146 const TextCharPos& charpos,
147 int* ps_fontnum,
148 int* ps_glyphindex);
149 void DrawTextAsType3Font(int char_count,
150 const TextCharPos* char_pos,
151 CFX_Font* font,
152 float font_size,
153 fxcrt::ostringstream& buf);
154 bool DrawTextAsType42Font(int char_count,
155 const TextCharPos* char_pos,
156 CFX_Font* font,
157 float font_size,
158 fxcrt::ostringstream& buf);
159 FaxCompressResult FaxCompressData(RetainPtr<const CFX_DIBBase> src) const;
160 absl::optional<PSCompressResult> PSCompressData(
161 pdfium::span<const uint8_t> src_span) const;
162 void WritePreambleString(ByteStringView str);
163 void WritePSBinary(pdfium::span<const uint8_t> data);
164 void WriteStream(fxcrt::ostringstream& stream);
165 void WriteString(ByteStringView str);
166
167 bool m_bInited = false;
168 bool m_bGraphStateSet = false;
169 bool m_bColorSet = false;
170 absl::optional<RenderingLevel> m_Level;
171 uint32_t m_LastColor = 0;
172 FX_RECT m_ClipBox;
173 CFX_GraphStateData m_CurGraphState;
174 UnownedPtr<CFX_PSFontTracker> const m_pFontTracker;
175 UnownedPtr<const EncoderIface> const m_pEncoderIface;
177 std::vector<std::unique_ptr<Glyph>> m_PSFontList;
178 fxcrt::ostringstream m_PreambleOutput;
179 fxcrt::ostringstream m_Output;
180 std::vector<FX_RECT> m_ClipBoxStack;
181};
182
183#endif // CORE_FXGE_WIN32_CFX_PSRENDERER_H_
WindowsPrintMode g_pdfium_print_mode
bool DrawDIBits(RetainPtr< const CFX_DIBBase > bitmap, uint32_t color, const CFX_Matrix &matrix, const FXDIB_ResampleOptions &options)
void SetClip_PathStroke(const CFX_Path &path, const CFX_Matrix *pObject2Device, const CFX_GraphStateData *pGraphState)
FX_RECT GetClipBox()
bool StretchDIBits(RetainPtr< const CFX_DIBBase > bitmap, uint32_t color, int dest_left, int dest_top, int dest_width, int dest_height, const FXDIB_ResampleOptions &options)
static absl::optional< ByteString > GenerateType42SfntDataForTesting(const ByteString &psname, pdfium::span< const uint8_t > font_data)
bool DrawText(int nChars, const TextCharPos *pCharPos, CFX_Font *pFont, const CFX_Matrix &mtObject2Device, float font_size, uint32_t color)
static ByteString GenerateType42FontDictionaryForTesting(const ByteString &psname, const FX_RECT &bbox, size_t num_glyphs, size_t glyphs_per_descendant_font)
CFX_PSRenderer(CFX_PSFontTracker *font_tracker, const EncoderIface *encoder_iface)
void SetClip_PathFill(const CFX_Path &path, const CFX_Matrix *pObject2Device, const CFX_FillRenderOptions &fill_options)
void Init(const RetainPtr< IFX_RetainableWriteStream > &stream, RenderingLevel level, int width, int height)
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)
void RestoreState(bool bKeepSaved)
bool SetDIBits(const RetainPtr< const CFX_DIBBase > &pBitmap, uint32_t color, int dest_left, int dest_top)
CFX_WindowsRenderDevice(HDC hDC, CFX_PSFontTracker *ps_font_tracker, const EncoderIface *encoder_iface)
~CFX_WindowsRenderDevice() override
~CPDF_WindowsRenderDevice() override
CPDF_WindowsRenderDevice(HDC hDC, CFX_PSFontTracker *ps_font_tracker)
bool(* pJpegEncodeFunc)(const RetainPtr< const CFX_DIBBase > &pSource, uint8_t **dest_buf, size_t *dest_size)