5#include "core/fxge/win32/cfx_psrenderer.h"
10#include "core/fxcrt/bytestring.h"
11#include "core/fxcrt/data_vector.h"
12#include "core/fxcrt/fx_coordinates.h"
13#include "core/fxcrt/fx_stream.h"
14#include "core/fxcrt/retain_ptr.h"
15#include "core/fxcrt/span.h"
16#include "core/fxge/dib/cfx_dibitmap.h"
17#include "core/fxge/dib/fx_dib.h"
18#include "core/fxge/win32/cfx_psfonttracker.h"
19#include "testing/gtest/include/gtest/gtest.h"
23DataVector<uint8_t> FakeA85Encode(pdfium::span<
const uint8_t> src_span) {
24 return DataVector<uint8_t>({
'd',
'u',
'm',
'm',
'y',
'a',
'8',
'5'});
32 bool WriteBlock(pdfium::span<
const uint8_t> buffer)
override {
33 data_.insert(data_.end(), buffer.begin(), buffer.end());
37 pdfium::span<
const uint8_t> GetSpan()
const {
return data_; }
40 DataVector<uint8_t> data_;
48 result = CFX_PSRenderer::GenerateType42SfntDataForTesting(
"empty", {});
49 EXPECT_FALSE(result.has_value());
51 constexpr uint8_t kOddByteCountTestData[] = {0, 32, 55};
52 static constexpr char kExpectedOddByteCountResult[] = R"(/odd_sfnts [
53<
54002037
55>
56] def
57)";
58 result = CFX_PSRenderer::GenerateType42SfntDataForTesting(
59 "odd", kOddByteCountTestData);
60 ASSERT_TRUE(result.has_value());
61 EXPECT_EQ(kExpectedOddByteCountResult, result.value());
64 constexpr uint8_t kEvenByteCountTestData[] = {0, 32, 66, 77};
65 static constexpr char kExpectedEvenByteCountResult[] = R"(/even_sfnts [
66<
68>
69] def
70)";
71 result = CFX_PSRenderer::GenerateType42SfntDataForTesting(
72 "even", kEvenByteCountTestData);
73 ASSERT_TRUE(result.has_value());
74 EXPECT_EQ(kExpectedEvenByteCountResult, result.value());
80 static constexpr char kExpected1DescendantFontResult[] = R"(8 dict begin
81/FontType 42 def
82/FontMatrix [1 0 0 1 0 0] def
83/FontName /1descendant_0 def
84/Encoding 3 array
85dup 0 /c00 put
86dup 1 /c01 put
87dup 2 /c02 put
88readonly def
89/FontBBox [1 2 3 4] def
90/PaintType 0 def
91/CharStrings 4 dict dup begin
92/.notdef 0 def
93/c00 0 def
94/c01 1 def
95/c02 2 def
96end readonly def
97/sfnts 1descendant_sfnts def
98FontName currentdict end definefont pop
996 dict begin
100/FontName /1descendant def
101/FontType 0 def
102/FontMatrix [1 0 0 1 0 0] def
103/FMapType 2 def
104/Encoding [
1050
106] def
107/FDepVector [
108/1descendant_0 findfont
109] def
110FontName currentdict end definefont pop
111%%EndResource
112)";
113 result = CFX_PSRenderer::GenerateType42FontDictionaryForTesting(
116 EXPECT_EQ(kExpected1DescendantFontResult, result);
118 static constexpr char kExpected2DescendantFontResult[] = R"(8 dict begin
119/FontType 42 def
120/FontMatrix [1 0 0 1 0 0] def
121/FontName /2descendant_0 def
122/Encoding 3 array
123dup 0 /c00 put
124dup 1 /c01 put
125dup 2 /c02 put
126readonly def
127/FontBBox [12 -5 34 199] def
128/PaintType 0 def
129/CharStrings 4 dict dup begin
130/.notdef 0 def
131/c00 0 def
132/c01 1 def
133/c02 2 def
134end readonly def
135/sfnts 2descendant_sfnts def
136FontName currentdict end definefont pop
1378 dict begin
138/FontType 42 def
139/FontMatrix [1 0 0 1 0 0] def
140/FontName /2descendant_1 def
141/Encoding 3 array
142dup 0 /c00 put
143dup 1 /c01 put
144readonly def
145/FontBBox [12 -5 34 199] def
146/PaintType 0 def
147/CharStrings 4 dict dup begin
148/.notdef 0 def
149/c00 3 def
150/c01 4 def
151end readonly def
152/sfnts 2descendant_sfnts def
153FontName currentdict end definefont pop
1546 dict begin
155/FontName /2descendant def
156/FontType 0 def
157/FontMatrix [1 0 0 1 0 0] def
158/FMapType 2 def
159/Encoding [
1600
1611
162] def
163/FDepVector [
164/2descendant_0 findfont
165/2descendant_1 findfont
166] def
167FontName currentdict end definefont pop
168%%EndResource
169)";
170 result = CFX_PSRenderer::GenerateType42FontDictionaryForTesting(
173 EXPECT_EQ(kExpected2DescendantFontResult, result);
177 static constexpr char kExpectedOutput[] = R"(
178save
179/im/initmatrix load def
180/n/newpath load def/m/moveto load def/l/lineto load def/c/curveto load def/h/closepath load def
181/f/fill load def/F/eofill load def/s/stroke load def/W/clip load def/W*/eoclip load def
182/rg/setrgbcolor load def/k/setcmykcolor load def
183/J/setlinecap load def/j/setlinejoin load def/w/setlinewidth load def/M/setmiterlimit load def/d/setdash load def
184/q/gsave load def/Q/grestore load def/iM/imagemask load def
185/Tj/show load def/Ff/findfont load def/Fs/scalefont load def/Sf/setfont load def
186/cm/concat load def/Cm/currentmatrix load def/mx/matrix load def/sm/setmatrix load def
187q
188[1 0 0 1 0 0]cm 10 2 1[10 0 0 -2 0 2]currentfile/ASCII85Decode filter false 1 colorimage
189dummya85
190Q
191
192restore
193)";
194 auto output_stream =
pdfium::MakeRetain<TestWriteStream>();
197 constexpr int kWidth = 10;
198 constexpr int kHeight = 2;
200 const EncoderIface encoder_interface{&FakeA85Encode,
nullptr,
nullptr,
206 auto bitmap =
pdfium::MakeRetain<CFX_DIBitmap>();
214 EXPECT_EQ(output, kExpectedOutput);
fxcrt::ByteString ByteString
constexpr CFX_Matrix()=default
bool DrawDIBits(RetainPtr< const CFX_DIBBase > bitmap, uint32_t color, const CFX_Matrix &matrix, const FXDIB_ResampleOptions &options)
CFX_PSRenderer(CFX_PSFontTracker *font_tracker, const EncoderIface *encoder_iface)
void Init(const RetainPtr< IFX_RetainableWriteStream > &stream, RenderingLevel level, int width, int height)
TEST(FXCRYPT, MD5GenerateEmtpyData)
#define CONSTRUCT_VIA_MAKE_RETAIN
fxcrt::ByteStringView ByteStringView
constexpr FX_RECT(int l, int t, int r, int b)