56 auto pPathObj =
std::make_unique<CPDF_PathObject>();
57 pPathObj->set_stroke(
true);
59 pPathObj->path().AppendRect(10, 5, 13, 30);
61 auto dummy_page_dict = pdfium::MakeRetain<CPDF_Dictionary>();
62 auto pTestPage = pdfium::MakeRetain<CPDF_Page>(
nullptr, dummy_page_dict);
64 fxcrt::ostringstream buf;
65 TestProcessPath(&generator, &buf, pPathObj.get());
66 EXPECT_EQ(
"q 1 0 0 1 0 0 cm 10 5 3 25 re B* Q\n", ByteString(buf));
68 pPathObj =
std::make_unique<CPDF_PathObject>();
70 pPathObj->path().AppendPoint(CFX_PointF(5.2f, 0),
72 pPathObj->path().AppendPoint(CFX_PointF(5.2f, 3.78f),
74 pPathObj->path().AppendPointAndClose(CFX_PointF(0, 3.78f),
77 TestProcessPath(&generator, &buf, pPathObj.get());
78 EXPECT_EQ(
"q 1 0 0 1 0 0 cm 0 0 5.1999998 3.78 re n Q\n", ByteString(buf));
82 static const std::vector<
float> rgb = {0.000000000000000000001f, 0.7f, 0.35f};
84 CPDF_ColorSpace::GetStockCS(CPDF_ColorSpace::Family::kDeviceRGB);
86 auto pPathObj =
std::make_unique<CPDF_PathObject>();
90 pPathObj->path().AppendRect(0.000000000000000000001,
91 0.000000000000000000001, 100, 100);
93 pPathObj->mutable_color_state().SetFillColor(pCS, rgb);
94 pPathObj->mutable_color_state().SetStrokeColor(pCS, rgb);
95 pPathObj->mutable_graph_state().SetLineWidth(200000000000000000001.0);
97 200000000000000.000002
));
99 auto dummy_page_dict = pdfium::MakeRetain<CPDF_Dictionary>();
100 auto pTestPage = pdfium::MakeRetain<CPDF_Page>(
nullptr, dummy_page_dict);
102 fxcrt::ostringstream buf;
103 TestProcessPath(&generator, &buf, pPathObj.get());
105 "q 0 0.701961 0.34902 rg 0 0.701961 0.34902 RG 200000000000000000000 w"
106 " 1 0 0 1 .00000000000000000000099999997 200000000000000 cm .000000000"
107 "00000000000099999997 .00000000000000000000099999997 100 100 re f Q\n",
113 auto pPathObj =
std::make_unique<CPDF_PathObject>();
114 pPathObj->mutable_color_state().SetFillColor(pCS, rgb);
115 pPathObj->mutable_color_state().SetStrokeColor(pCS, rgb);
116 pPathObj->mutable_graph_state().SetLineWidth(2.000000000000000000001);
120 pPathObj->path().AppendPoint(CFX_PointF(0.000000000000000000001f, 4.67f),
122 pPathObj->path().AppendPoint(
123 CFX_PointF(0.000000000000000000001, 100000000000000.000002),
125 pPathObj->path().AppendPoint(CFX_PointF(0.0000000000001f, 3.15f),
127 pPathObj->path().AppendPoint(CFX_PointF(3.57f, 2.98f),
129 pPathObj->path().AppendPointAndClose(
130 CFX_PointF(53.4f, 5000000000000000000.00000000000000004),
132 auto dummy_page_dict = pdfium::MakeRetain<CPDF_Dictionary>();
133 auto pTestPage = pdfium::MakeRetain<CPDF_Page>(
nullptr, dummy_page_dict);
135 fxcrt::ostringstream buf;
137 TestProcessPath(&generator, &buf, pPathObj.get());
139 "q 0 0.701961 0.34902 rg 0 0.701961 0.34902 RG 2 w 1 0 0 1 432 4999999"
140 "90000000 cm .00000000000000000000099999997 4.6700001 m .0000000000000"
141 "0000000099999997 100000000000000 l .000000000000099999998 3.1500001 3"
142 ".5699999 2.98 53.400002 5000000000000000000 c h f Q\n",
148 auto pPathObj =
std::make_unique<CPDF_PathObject>();
150 pPathObj->path().AppendPoint(CFX_PointF(3.102f, 4.67f),
152 pPathObj->path().AppendPoint(CFX_PointF(5.45f, 0.29f),
154 pPathObj->path().AppendPoint(CFX_PointF(4.24f, 3.15f),
156 pPathObj->path().AppendPoint(CFX_PointF(4.65f, 2.98f),
158 pPathObj->path().AppendPoint(CFX_PointF(3.456f, 0.24f),
160 pPathObj->path().AppendPoint(CFX_PointF(10.6f, 11.15f),
162 pPathObj->path().AppendPoint(CFX_PointF(11, 12.5f),
164 pPathObj->path().AppendPoint(CFX_PointF(11.46f, 12.67f),
166 pPathObj->path().AppendPoint(CFX_PointF(11.84f, 12.96f),
168 pPathObj->path().AppendPointAndClose(CFX_PointF(12, 13.64f),
171 auto dummy_page_dict = pdfium::MakeRetain<CPDF_Dictionary>();
172 auto pTestPage = pdfium::MakeRetain<CPDF_Page>(
nullptr, dummy_page_dict);
174 fxcrt::ostringstream buf;
175 TestProcessPath(&generator, &buf, pPathObj.get());
177 "q 1 0 0 1 0 0 cm 3.102 4.6700001 m 5.4499998 .28999999 l 4.2399998 "
178 "3.1500001 4.6500001 2.98 3.4560001 .23999999 c 10.6000004 11.149999"
179 "6 l 11 12.5 l 11.46 12.6700001 11.8400002 12.96 12 13.6400003 c h f"
185 auto pPathObj =
std::make_unique<CPDF_PathObject>();
186 pPathObj->set_stroke(
true);
190 pPathObj->path().AppendPointAndClose(CFX_PointF(5, 6),
193 static const std::vector<
float> rgb = {0.5f, 0.7f, 0.35f};
195 CPDF_ColorSpace::GetStockCS(CPDF_ColorSpace::Family::kDeviceRGB);
196 pPathObj->mutable_color_state().SetFillColor(pCS, rgb);
198 static const std::vector<
float> rgb2 = {1, 0.9f, 0};
199 pPathObj->mutable_color_state().SetStrokeColor(pCS, rgb2);
200 pPathObj->mutable_general_state().SetFillAlpha(0.5f);
201 pPathObj->mutable_general_state().SetStrokeAlpha(0.8f);
204 pDoc->CreateNewDoc();
206 RetainPtr<CPDF_Dictionary> pPageDict(pDoc->CreateNewPage(0));
207 auto pTestPage = pdfium::MakeRetain<CPDF_Page>(pDoc.get(), pPageDict);
209 fxcrt::ostringstream buf;
210 TestProcessPath(&generator, &buf, pPathObj.get());
211 ByteString pathString(buf);
214 EXPECT_EQ(
"q 0.501961 0.701961 0.34902 rg 1 0.901961 0 RG /",
215 pathString.First(48));
216 EXPECT_EQ(
" gs 1 0 0 1 0 0 cm 1 2 m 3 4 l 5 6 l h B Q\n",
217 pathString.Last(43));
218 ASSERT_GT(pathString.GetLength(), 91U);
219 RetainPtr<
const CPDF_Dictionary> externalGS =
220 TestGetResource(&generator,
"ExtGState",
221 pathString.Substr(48, pathString.GetLength() - 91));
222 ASSERT_TRUE(externalGS);
223 EXPECT_EQ(0.5f, externalGS->GetFloatFor(
"ca"));
224 EXPECT_EQ(0.8f, externalGS->GetFloatFor(
"CA"));
227 pPathObj->mutable_graph_state().SetLineWidth(10.5f);
229 TestProcessPath(&generator, &buf, pPathObj.get());
230 ByteString pathString2(buf);
231 EXPECT_EQ(
"q 0.501961 0.701961 0.34902 rg 1 0.901961 0 RG 10.5 w /",
232 pathString2.First(55));
233 EXPECT_EQ(
" gs 1 0 0 1 0 0 cm 1 2 m 3 4 l 5 6 l h B Q\n",
234 pathString2.Last(43));
237 EXPECT_EQ(pathString.GetLength() + 7, pathString2.GetLength());
238 EXPECT_EQ(pathString.Substr(48, pathString.GetLength() - 76),
239 pathString2.Substr(55, pathString2.GetLength() - 83));
245 pDoc->CreateNewDoc();
247 RetainPtr<CPDF_Dictionary> pPageDict(pDoc->CreateNewPage(0));
248 auto pTestPage = pdfium::MakeRetain<CPDF_Page>(pDoc.get(), pPageDict);
250 auto pTextObj =
std::make_unique<CPDF_TextObject>();
251 pTextObj->mutable_text_state().SetFont(
253 pTextObj->mutable_text_state().SetFontSize(10.0f);
255 static const std::vector<
float> rgb = {0.5f, 0.7f, 0.35f};
257 CPDF_ColorSpace::GetStockCS(CPDF_ColorSpace::Family::kDeviceRGB);
258 pTextObj->mutable_color_state().SetFillColor(pCS, rgb);
260 static const std::vector<
float> rgb2 = {1, 0.9f, 0};
261 pTextObj->mutable_color_state().SetStrokeColor(pCS, rgb2);
262 pTextObj->mutable_general_state().SetFillAlpha(0.5f);
263 pTextObj->mutable_general_state().SetStrokeAlpha(0.8f);
265 pTextObj->SetText(
"Hello World");
266 fxcrt::ostringstream buf;
267 TestProcessText(&generator, &buf, pTextObj.get());
268 ByteString textString(buf);
269 auto firstResourceAt = textString.Find(
'/');
270 ASSERT_TRUE(firstResourceAt.has_value());
271 firstResourceAt = firstResourceAt.value() + 1;
272 auto secondResourceAt = textString.ReverseFind(
'/');
273 ASSERT_TRUE(secondResourceAt.has_value());
274 secondResourceAt = secondResourceAt.value() + 1;
275 ByteString firstString = textString.First(firstResourceAt.value());
276 ByteString midString =
277 textString.Substr(firstResourceAt.value(),
278 secondResourceAt.value() - firstResourceAt.value());
279 ByteString lastString =
280 textString.Last(textString.GetLength() - secondResourceAt.value());
282 ByteString compareString1 =
283 "q 0.501961 0.701961 0.34902 rg 1 0.901961 0 RG /";
285 ByteString compareString2 =
" gs BT 1 0 0 1 100 100 Tm /";
286 ByteString compareString3 =
" 10 Tf 0 Tr <48656C6C6F20576F726C64> Tj ET Q\n";
287 EXPECT_LT(compareString1.GetLength() + compareString2.GetLength() +
288 compareString3.GetLength(),
289 textString.GetLength());
290 EXPECT_EQ(compareString1, firstString.First(compareString1.GetLength()));
291 EXPECT_EQ(compareString2, midString.Last(compareString2.GetLength()));
292 EXPECT_EQ(compareString3, lastString.Last(compareString3.GetLength()));
293 RetainPtr<
const CPDF_Dictionary> externalGS = TestGetResource(
294 &generator,
"ExtGState",
295 midString.First(midString.GetLength() - compareString2.GetLength()));
296 ASSERT_TRUE(externalGS);
297 EXPECT_EQ(0.5f, externalGS->GetFloatFor(
"ca"));
298 EXPECT_EQ(0.8f, externalGS->GetFloatFor(
"CA"));
299 RetainPtr<
const CPDF_Dictionary> fontDict = TestGetResource(
301 lastString.First(lastString.GetLength() - compareString3.GetLength()));
302 ASSERT_TRUE(fontDict);
303 EXPECT_EQ(
"Font", fontDict->GetNameFor(
"Type"));
304 EXPECT_EQ(
"Type1", fontDict->GetNameFor(
"Subtype"));
305 EXPECT_EQ(
"Times-Roman", fontDict->GetNameFor(
"BaseFont"));
311 pDoc->CreateNewDoc();
313 RetainPtr<CPDF_Dictionary> pPageDict(pDoc->CreateNewPage(0));
314 auto pTestPage = pdfium::MakeRetain<CPDF_Page>(pDoc.get(), pPageDict);
317 fxcrt::ostringstream buf;
320 auto pTextObj =
std::make_unique<CPDF_TextObject>();
321 auto pDict = pDoc->NewIndirect<CPDF_Dictionary>();
322 pDict->SetNewFor<CPDF_Name>(
"Type",
"Font");
323 pDict->SetNewFor<CPDF_Name>(
"Subtype",
"TrueType");
326 pDict->SetNewFor<CPDF_Name>(
"BaseFont", pFont->GetBaseFontName());
328 auto pDesc = pDoc->NewIndirect<CPDF_Dictionary>();
329 pDesc->SetNewFor<CPDF_Name>(
"Type",
"FontDescriptor");
330 pDesc->SetNewFor<CPDF_Name>(
"FontName", pFont->GetBaseFontName());
331 pDict->SetNewFor<CPDF_Reference>(
"FontDescriptor", pDoc.get(),
334 pTextObj->mutable_text_state().SetFont(
336 pTextObj->mutable_text_state().SetFontSize(15.5f);
337 pTextObj->SetText(
"I am indirect");
350 TestProcessText(&generator, &buf, pTextObj.get());
353 ByteString textString(buf);
354 auto firstResourceAt = textString.Find(
'/');
355 ASSERT_TRUE(firstResourceAt.has_value());
356 firstResourceAt = firstResourceAt.value() + 1;
357 ByteString firstString = textString.First(firstResourceAt.value());
358 ByteString lastString =
359 textString.Last(textString.GetLength() - firstResourceAt.value());
361 ByteString compareString1 =
"q 0 0 5 4 re W* n BT 1 0 0 1 0 0 Tm /";
362 ByteString compareString2 =
363 " 15.5 Tf 4 Tr <4920616D20696E646972656374> Tj ET Q\n";
364 EXPECT_LT(compareString1.GetLength() + compareString2.GetLength(),
365 textString.GetLength());
366 EXPECT_EQ(compareString1, textString.First(compareString1.GetLength()));
367 EXPECT_EQ(compareString2, textString.Last(compareString2.GetLength()));
368 RetainPtr<
const CPDF_Dictionary> fontDict = TestGetResource(
370 textString.Substr(compareString1.GetLength(),
371 textString.GetLength() - compareString1.GetLength() -
372 compareString2.GetLength()));
373 ASSERT_TRUE(fontDict);
374 EXPECT_TRUE(fontDict->GetObjNum());
375 EXPECT_EQ(
"Font", fontDict->GetNameFor(
"Type"));
376 EXPECT_EQ(
"TrueType", fontDict->GetNameFor(
"Subtype"));
377 EXPECT_EQ(
"Helvetica", fontDict->GetNameFor(
"BaseFont"));
378 RetainPtr<
const CPDF_Dictionary> fontDesc =
379 fontDict->GetDictFor(
"FontDescriptor");
380 ASSERT_TRUE(fontDesc);
381 EXPECT_TRUE(fontDesc->GetObjNum());
382 EXPECT_EQ(
"FontDescriptor", fontDesc->GetNameFor(
"Type"));
383 EXPECT_EQ(
"Helvetica", fontDesc->GetNameFor(
"FontName"));
407 pDoc->CreateNewDoc();
408 static constexpr uint8_t kContents[] =
409 "q 1 0 0 1 0 0 cm 3.102 4.6700001 m 5.4500012 .28999999 "
410 "l 4.2399998 3.1499999 4.65 2.98 3.456 0.24 c 3.102 4.6700001 l h f Q\n";
411 auto pStream = pdfium::MakeRetain<CPDF_Stream>(
412 DataVector<uint8_t>(
std::begin(kContents),
std::end(kContents)),
413 pdfium::MakeRetain<CPDF_Dictionary>());
416 auto pTestForm =
std::make_unique<CPDF_Form>(pDoc.get(),
nullptr, pStream);
417 pTestForm->ParseContent();
419 pTestForm->GetParseState());
422 fxcrt::ostringstream process_buf;
423 generator.ProcessPageObjects(&process_buf);
425 "q 1 0 0 1 0 0 cm 3.102 4.6700001 m 5.4500012 .28999999 l 4.2399998 3.14"
426 "99999 4.6500001 2.98 3.4560001 .24000001 c 3.102 4.6700001 l h f Q\n",
static CPDF_DocPageData * FromDocument(const CPDF_Document *pDoc)
RetainPtr< const CPDF_Dictionary > TestGetResource(CPDF_PageContentGenerator *pGen, const ByteString &type, const ByteString &name)
void TestProcessText(CPDF_PageContentGenerator *pGen, fxcrt::ostringstream *buf, CPDF_TextObject *pTextObj)
void TestProcessPath(CPDF_PageContentGenerator *pGen, fxcrt::ostringstream *buf, CPDF_PathObject *pPathObj)
TEST_F(CPDF_PageContentGeneratorTest, ProcessRect)