Add another test for FPDFText_GetFontWeight(). Illustrate the existing behavior and add a TODO to fix it. Rearrange font_weight.in to make adding new fonts for testing more of an append operation inside the .in file, to avoid renumbering the /Contents object every time a font gets added. Bug: pdfium:1420 Change-Id: I3ceb64eeb342803a2d1f47989d6209d70ed157e3 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/62354 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/fpdfsdk/fpdf_text_embeddertest.cpp b/fpdfsdk/fpdf_text_embeddertest.cpp index 7cbd27a..ff3c2cb 100644 --- a/fpdfsdk/fpdf_text_embeddertest.cpp +++ b/fpdfsdk/fpdf_text_embeddertest.cpp
@@ -1353,7 +1353,7 @@ FPDF_TEXTPAGE text_page = FPDFText_LoadPage(page); ASSERT_TRUE(text_page); - EXPECT_EQ(1, FPDFText_CountChars(text_page)); + EXPECT_EQ(2, FPDFText_CountChars(text_page)); EXPECT_EQ(-1, FPDFText_GetFontWeight(nullptr, 0)); EXPECT_EQ(-1, FPDFText_GetFontWeight(text_page, -1)); @@ -1361,8 +1361,12 @@ // The font used for this text only specifies /StemV (80); the weight value // that is returned should be calculated from that (80*5 == 400). - int weight = FPDFText_GetFontWeight(text_page, 0); - EXPECT_EQ(400, weight); + EXPECT_EQ(400, FPDFText_GetFontWeight(text_page, 0)); + + // Using a /StemV value of 82, the estimate comes out to 410, even though + // /FontWeight is 400. + // TODO(crbug.com/pdfium/1420): Fix this the return value here. + EXPECT_EQ(410, FPDFText_GetFontWeight(text_page, 1)); FPDFText_ClosePage(text_page); UnloadPage(page);
diff --git a/testing/resources/font_weight.in b/testing/resources/font_weight.in index fa7336b..7e79cde 100644 --- a/testing/resources/font_weight.in +++ b/testing/resources/font_weight.in
@@ -16,20 +16,34 @@ /Parent 2 0 R /Resources << /Font << - /F1 4 0 R + /F1 5 0 R + /F2 7 0 R >> >> - /Contents 6 0 R + /Contents 4 0 R >> endobj {{object 4 0}} << + {{streamlen}} +>> +stream +BT +0 30 Td +/F1 12 Tf +(1) Tj +/F2 12 Tf +(X) Tj +ET +endstream +endobj +{{object 5 0}} << /Type /Font /Subtype /Type1 /BaseFont /Helvetica - /FontDescriptor 5 0 R + /FontDescriptor 6 0 R >> endobj -{{object 5 0}} << +{{object 6 0}} << /Type /FontDescriptor /FontName /Helvetica /StemV 80 @@ -41,16 +55,32 @@ /Descent -223 >> endobj -{{object 6 0}} << - {{streamlen}} +{{object 7 0}} << + /Type /Font + /Subtype /TrueType + /BaseFont /TimesNewRomanPSMT + /Encoding /WinAnsiEncoding + /FirstChar 31 + /FontDescriptor 8 0 R + /LastChar 252 >> -stream -BT -0 30 Td -/F1 12 Tf -(1) Tj -ET -endstream +endobj +{{object 8 0}} << + /Type /FontDescriptor + /Ascent 891 + /CapHeight 656 + /Descent -216 + /Flags 34 + /FontBBox [-568 -307 2000 1007] + /FontFamily (Times New Roman) + /FontName /TimesNewRomanPSMT + /FontStretch /Normal + /FontWeight 400 + /ItalicAngle 0 + /MissingWidth 778 + /StemV 82 + /XHeight -546 +>> endobj {{xref}} {{trailer}}
diff --git a/testing/resources/font_weight.pdf b/testing/resources/font_weight.pdf index 851aa49..78049d0 100644 --- a/testing/resources/font_weight.pdf +++ b/testing/resources/font_weight.pdf
@@ -17,20 +17,34 @@ /Parent 2 0 R /Resources << /Font << - /F1 4 0 R + /F1 5 0 R + /F2 7 0 R >> >> - /Contents 6 0 R + /Contents 4 0 R >> endobj 4 0 obj << + /Length 48 +>> +stream +BT +0 30 Td +/F1 12 Tf +(1) Tj +/F2 12 Tf +(X) Tj +ET +endstream +endobj +5 0 obj << /Type /Font /Subtype /Type1 /BaseFont /Helvetica - /FontDescriptor 5 0 R + /FontDescriptor 6 0 R >> endobj -5 0 obj << +6 0 obj << /Type /FontDescriptor /FontName /Helvetica /StemV 80 @@ -42,30 +56,48 @@ /Descent -223 >> endobj -6 0 obj << - /Length 31 +7 0 obj << + /Type /Font + /Subtype /TrueType + /BaseFont /TimesNewRomanPSMT + /Encoding /WinAnsiEncoding + /FirstChar 31 + /FontDescriptor 8 0 R + /LastChar 252 >> -stream -BT -0 30 Td -/F1 12 Tf -(1) Tj -ET -endstream +endobj +8 0 obj << + /Type /FontDescriptor + /Ascent 891 + /CapHeight 656 + /Descent -216 + /Flags 34 + /FontBBox [-568 -307 2000 1007] + /FontFamily (Times New Roman) + /FontName /TimesNewRomanPSMT + /FontStretch /Normal + /FontWeight 400 + /ItalicAngle 0 + /MissingWidth 778 + /StemV 82 + /XHeight -546 +>> endobj xref -0 7 +0 9 0000000000 65535 f 0000000015 00000 n 0000000068 00000 n 0000000161 00000 n -0000000287 00000 n -0000000387 00000 n -0000000576 00000 n +0000000303 00000 n +0000000402 00000 n +0000000502 00000 n +0000000691 00000 n +0000000863 00000 n trailer << /Root 1 0 R - /Size 7 + /Size 9 >> startxref -658 +1170 %%EOF