56 auto pPathObj =
std::make_unique<CPDF_PathObject>();
57 pPathObj->set_stroke(
true);
59 pPathObj->path().AppendRect(10, 5, 13, 30);
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 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 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
));
100 auto pTestPage =
pdfium::MakeRetain<CPDF_Page>(
nullptr, dummy_page_dict);
102 fxcrt::ostringstream buf;
103 TestProcessPath(&generator, &buf, pPathObj.get());
105 "q .00000000000000000000099999997 .69999999 .34999999 rg "
106 ".00000000000000000000099999997 .69999999 .34999999 RG "
107 "200000000000000000000 w 1 0 0 1 .00000000000000000000099999997 "
108 "200000000000000 cm .00000000000000000000099999997 "
109 ".00000000000000000000099999997 100 100 re f Q\n",
115 auto pPathObj =
std::make_unique<CPDF_PathObject>();
116 pPathObj->mutable_color_state().SetFillColor(pCS, rgb);
117 pPathObj->mutable_color_state().SetStrokeColor(pCS, rgb);
118 pPathObj->mutable_graph_state().SetLineWidth(2.000000000000000000001);
122 pPathObj->path().AppendPoint(CFX_PointF(0.000000000000000000001f, 4.67f),
124 pPathObj->path().AppendPoint(
125 CFX_PointF(0.000000000000000000001, 100000000000000.000002),
127 pPathObj->path().AppendPoint(CFX_PointF(0.0000000000001f, 3.15f),
129 pPathObj->path().AppendPoint(CFX_PointF(3.57f, 2.98f),
131 pPathObj->path().AppendPointAndClose(
132 CFX_PointF(53.4f, 5000000000000000000.00000000000000004),
135 auto pTestPage =
pdfium::MakeRetain<CPDF_Page>(
nullptr, dummy_page_dict);
137 fxcrt::ostringstream buf;
139 TestProcessPath(&generator, &buf, pPathObj.get());
141 "q .00000000000000000000099999997 .69999999 .34999999 rg "
142 ".00000000000000000000099999997 .69999999 .34999999 RG 2 w 1 0 0 1 432 "
143 "499999990000000 cm .00000000000000000000099999997 4.6700001 m "
144 ".00000000000000000000099999997 100000000000000 l "
145 ".000000000000099999998 3.1500001 3.5699999 2.98 53.400002 "
146 "5000000000000000000 c h f Q\n",
152 auto pPathObj =
std::make_unique<CPDF_PathObject>();
154 pPathObj->path().AppendPoint(CFX_PointF(3.102f, 4.67f),
156 pPathObj->path().AppendPoint(CFX_PointF(5.45f, 0.29f),
158 pPathObj->path().AppendPoint(CFX_PointF(4.24f, 3.15f),
160 pPathObj->path().AppendPoint(CFX_PointF(4.65f, 2.98f),
162 pPathObj->path().AppendPoint(CFX_PointF(3.456f, 0.24f),
164 pPathObj->path().AppendPoint(CFX_PointF(10.6f, 11.15f),
166 pPathObj->path().AppendPoint(CFX_PointF(11, 12.5f),
168 pPathObj->path().AppendPoint(CFX_PointF(11.46f, 12.67f),
170 pPathObj->path().AppendPoint(CFX_PointF(11.84f, 12.96f),
172 pPathObj->path().AppendPointAndClose(CFX_PointF(12, 13.64f),
176 auto pTestPage =
pdfium::MakeRetain<CPDF_Page>(
nullptr, dummy_page_dict);
178 fxcrt::ostringstream buf;
179 TestProcessPath(&generator, &buf, pPathObj.get());
181 "q 3.102 4.6700001 m 5.4499998 .28999999 l 4.2399998 "
182 "3.1500001 4.6500001 2.98 3.4560001 .23999999 c 10.6000004 11.149999"
183 "6 l 11 12.5 l 11.46 12.6700001 11.8400002 12.96 12 13.6400003 c h f"
189 auto pPathObj =
std::make_unique<CPDF_PathObject>();
190 pPathObj->set_stroke(
true);
194 pPathObj->path().AppendPointAndClose(CFX_PointF(5, 6),
197 static const std::vector<
float> rgb = {0.5f, 0.7f, 0.35f};
199 CPDF_ColorSpace::GetStockCS(CPDF_ColorSpace::Family::kDeviceRGB);
200 pPathObj->mutable_color_state().SetFillColor(pCS, rgb);
202 static const std::vector<
float> rgb2 = {1, 0.9f, 0};
203 pPathObj->mutable_color_state().SetStrokeColor(pCS, rgb2);
204 pPathObj->mutable_general_state().SetFillAlpha(0.5f);
205 pPathObj->mutable_general_state().SetStrokeAlpha(0.8f);
208 pDoc->CreateNewDoc();
211 auto pTestPage =
pdfium::MakeRetain<CPDF_Page>(pDoc.get(), pPageDict);
213 fxcrt::ostringstream buf;
214 TestProcessPath(&generator, &buf, pPathObj.get());
219 "q .5 .69999999 .34999999 rg 1 .89999998 0 RG /";
220 const ByteStringView kExpectedStringEnd =
" gs 1 2 m 3 4 l 5 6 l h B Q\n";
221 const size_t kExpectedStringMinLength =
222 kExpectedStringStart.GetLength() + kExpectedStringEnd.GetLength();
223 EXPECT_EQ(kExpectedStringStart,
224 path_string.First(kExpectedStringStart.GetLength()));
225 EXPECT_EQ(kExpectedStringEnd,
226 path_string.Last(kExpectedStringEnd.GetLength()));
227 ASSERT_GT(path_string.GetLength(), kExpectedStringMinLength);
229 &generator,
"ExtGState",
230 path_string.Substr(kExpectedStringStart.GetLength(),
231 path_string.GetLength() - kExpectedStringMinLength));
232 ASSERT_TRUE(external_gs);
233 EXPECT_EQ(0.5f, external_gs->GetFloatFor(
"ca"));
234 EXPECT_EQ(0.8f, external_gs->GetFloatFor(
"CA"));
237 pPathObj->mutable_graph_state().SetLineWidth(10.5f);
239 TestProcessPath(&generator, &buf, pPathObj.get());
241 "q .5 .69999999 .34999999 rg 1 .89999998 0 RG 10.5 w /";
243 EXPECT_EQ(kExpectedStringStart2,
244 path_string2.First(kExpectedStringStart2.GetLength()));
245 EXPECT_EQ(kExpectedStringEnd,
246 path_string2.Last(kExpectedStringEnd.GetLength()));
249 const size_t kExpectedStringsLengthDifference =
250 kExpectedStringStart2.GetLength() - kExpectedStringStart.GetLength();
251 EXPECT_EQ(path_string.GetLength() + kExpectedStringsLengthDifference,
252 path_string2.GetLength());
254 path_string.Substr(kExpectedStringStart.GetLength(),
255 path_string.GetLength() - kExpectedStringMinLength),
256 path_string2.Substr(kExpectedStringStart2.GetLength(),
257 path_string2.GetLength() - kExpectedStringMinLength -
258 kExpectedStringsLengthDifference));
264 pDoc->CreateNewDoc();
267 auto pTestPage =
pdfium::MakeRetain<CPDF_Page>(pDoc.get(), pPageDict);
269 auto pTextObj =
std::make_unique<CPDF_TextObject>();
270 pTextObj->mutable_text_state().SetFont(
272 pTextObj->mutable_text_state().SetFontSize(10.0f);
274 static const std::vector<
float> rgb = {0.5f, 0.7f, 0.35f};
276 CPDF_ColorSpace::GetStockCS(CPDF_ColorSpace::Family::kDeviceRGB);
277 pTextObj->mutable_color_state().SetFillColor(pCS, rgb);
279 static const std::vector<
float> rgb2 = {1, 0.9f, 0};
280 pTextObj->mutable_color_state().SetStrokeColor(pCS, rgb2);
281 pTextObj->mutable_general_state().SetFillAlpha(0.5f);
282 pTextObj->mutable_general_state().SetStrokeAlpha(0.8f);
284 pTextObj->SetText(
"Hello World");
285 fxcrt::ostringstream buf;
286 TestProcessText(&generator, &buf, pTextObj.get());
288 auto first_resource_at = text_string.Find(
'/');
289 ASSERT_TRUE(first_resource_at.has_value());
290 first_resource_at = first_resource_at.value() + 1;
291 auto second_resource_at = text_string.ReverseFind(
'/');
292 ASSERT_TRUE(second_resource_at.has_value());
293 second_resource_at = second_resource_at.value() + 1;
294 ByteString first_string = text_string.First(first_resource_at.value());
296 first_resource_at.value(),
297 second_resource_at.value() - first_resource_at.value());
299 text_string.Last(text_string.GetLength() - second_resource_at.value());
302 "q .5 .69999999 .34999999 rg 1 .89999998 0 RG /";
304 const ByteString kCompareString2 =
" gs BT 1 0 0 1 100 100 Tm /";
306 " 10 Tf 0 Tr <48656C6C6F20576F726C64> Tj ET Q\n";
307 EXPECT_LT(kCompareString1.GetLength() + kCompareString2.GetLength() +
308 kCompareString3.GetLength(),
309 text_string.GetLength());
310 EXPECT_EQ(kCompareString1, first_string.First(kCompareString1.GetLength()));
311 EXPECT_EQ(kCompareString2, mid_string.Last(kCompareString2.GetLength()));
312 EXPECT_EQ(kCompareString3, last_string.Last(kCompareString3.GetLength()));
314 &generator,
"ExtGState",
315 mid_string.First(mid_string.GetLength() - kCompareString2.GetLength()));
316 ASSERT_TRUE(external_gs);
317 EXPECT_EQ(0.5f, external_gs->GetFloatFor(
"ca"));
318 EXPECT_EQ(0.8f, external_gs->GetFloatFor(
"CA"));
321 last_string.First(last_string.GetLength() - kCompareString3.GetLength()));
322 ASSERT_TRUE(font_dict);
323 EXPECT_EQ(
"Font", font_dict->GetNameFor(
"Type"));
324 EXPECT_EQ(
"Type1", font_dict->GetNameFor(
"Subtype"));
325 EXPECT_EQ(
"Times-Roman", font_dict->GetNameFor(
"BaseFont"));
331 pDoc->CreateNewDoc();
334 auto pTestPage =
pdfium::MakeRetain<CPDF_Page>(pDoc.get(), pPageDict);
337 fxcrt::ostringstream buf;
340 auto pTextObj =
std::make_unique<CPDF_TextObject>();
342 pDict->SetNewFor<CPDF_Name>(
"Type",
"Font");
343 pDict->SetNewFor<CPDF_Name>(
"Subtype",
"TrueType");
346 pDict->SetNewFor<CPDF_Name>(
"BaseFont", pFont->GetBaseFontName());
349 pDesc->SetNewFor<CPDF_Name>(
"Type",
"FontDescriptor");
350 pDesc->SetNewFor<CPDF_Name>(
"FontName", pFont->GetBaseFontName());
351 pDict->SetNewFor<CPDF_Reference>(
"FontDescriptor", pDoc.get(),
354 pTextObj->mutable_text_state().SetFont(
356 pTextObj->mutable_text_state().SetFontSize(15.5f);
357 pTextObj->SetText(
"I am indirect");
370 TestProcessText(&generator, &buf, pTextObj.get());
374 auto first_resource_at = text_string.Find(
'/');
375 ASSERT_TRUE(first_resource_at.has_value());
376 first_resource_at = first_resource_at.value() + 1;
377 ByteString first_string = text_string.First(first_resource_at.value());
379 text_string.Last(text_string.GetLength() - first_resource_at.value());
381 ByteString compare_string1 =
"q 0 0 5 4 re W* n BT /";
383 " 15.5 Tf 4 Tr <4920616D20696E646972656374> Tj ET Q\n";
384 EXPECT_LT(compare_string1.GetLength() + compare_string2.GetLength(),
385 text_string.GetLength());
386 EXPECT_EQ(compare_string1, text_string.First(compare_string1.GetLength()));
387 EXPECT_EQ(compare_string2, text_string.Last(compare_string2.GetLength()));
390 text_string.Substr(compare_string1.GetLength(),
391 text_string.GetLength() - compare_string1.GetLength() -
392 compare_string2.GetLength()));
393 ASSERT_TRUE(font_dict);
394 EXPECT_TRUE(font_dict->GetObjNum());
395 EXPECT_EQ(
"Font", font_dict->GetNameFor(
"Type"));
396 EXPECT_EQ(
"TrueType", font_dict->GetNameFor(
"Subtype"));
397 EXPECT_EQ(
"Helvetica", font_dict->GetNameFor(
"BaseFont"));
399 font_dict->GetDictFor(
"FontDescriptor");
400 ASSERT_TRUE(font_desc);
401 EXPECT_TRUE(font_desc->GetObjNum());
402 EXPECT_EQ(
"FontDescriptor", font_desc->GetNameFor(
"Type"));
403 EXPECT_EQ(
"Helvetica", font_desc->GetNameFor(
"FontName"));
void TestProcessText(CPDF_PageContentGenerator *pGen, fxcrt::ostringstream *buf, CPDF_TextObject *pTextObj)
void TestProcessPath(CPDF_PageContentGenerator *pGen, fxcrt::ostringstream *buf, CPDF_PathObject *pPathObj)
RetainPtr< const CPDF_Dictionary > TestGetResource(CPDF_PageContentGenerator *pGen, const ByteString &type, const ByteString &name)
static CPDF_DocPageData * FromDocument(const CPDF_Document *pDoc)
TEST_F(CPDFPageContentGeneratorTest, ProcessRect)