1 // Copyright 2019 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 #include "core/fpdfapi/font/cpdf_cidfont.h"
6
7 #include <utility>
8
9 #include "core/fpdfapi/page/test_with_page_module.h"
10 #include "core/fpdfapi/parser/cpdf_array.h"
11 #include "core/fpdfapi/parser/cpdf_dictionary.h"
12 #include "core/fpdfapi/parser/cpdf_document.h"
13 #include "core/fpdfapi/parser/cpdf_name.h"
14 #include "core/fpdfapi/parser/cpdf_test_document.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 using CPDF_CIDFontTest = TestWithPageModule;
18
TEST_F(CPDF_CIDFontTest,BUG_920636)19 TEST_F(CPDF_CIDFontTest, BUG_920636) {
20 CPDF_TestDocument doc;
21 auto font_dict = pdfium::MakeRetain<CPDF_Dictionary>();
22 font_dict->SetNewFor<CPDF_Name>("Encoding", "Identity−H");
23
24 {
25 auto descendant_fonts = pdfium::MakeRetain<CPDF_Array>();
26 {
27 auto descendant_font = pdfium::MakeRetain<CPDF_Dictionary>();
28 descendant_font->SetNewFor<CPDF_Name>("BaseFont", "CourierStd");
29 descendant_fonts->Append(std::move(descendant_font));
30 }
31 font_dict->SetFor("DescendantFonts", std::move(descendant_fonts));
32 }
33
34 auto font = pdfium::MakeRetain<CPDF_CIDFont>(&doc, std::move(font_dict));
35 ASSERT_TRUE(font->Load());
36
37 // It would be nice if we can test more values here. However, the glyph
38 // indices are sometimes machine dependent.
39 struct {
40 uint32_t charcode;
41 int glyph;
42 } static constexpr kTestCases[] = {
43 {0, 31},
44 {256, 287},
45 {34661, 34692},
46 };
47
48 for (const auto& test_case : kTestCases) {
49 EXPECT_EQ(test_case.glyph,
50 font->GlyphFromCharCode(test_case.charcode, nullptr));
51 }
52 }
53