Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cpdf_bafontmap_unittest.cpp
Go to the documentation of this file.
1// Copyright 2022 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/fpdfdoc/cpdf_bafontmap.h"
6
7#include <utility>
8
9#include "build/build_config.h"
10#include "constants/annotation_common.h"
11#include "core/fpdfapi/font/cpdf_font.h"
12#include "core/fpdfapi/page/test_with_page_module.h"
13#include "core/fpdfapi/parser/cpdf_dictionary.h"
14#include "core/fpdfapi/parser/cpdf_name.h"
15#include "core/fpdfapi/parser/cpdf_string.h"
16#include "core/fpdfapi/parser/cpdf_test_document.h"
17
18using BAFontMapTest = TestWithPageModule;
19
20TEST_F(BAFontMapTest, DefaultFont) {
21 // Without any font resources, CPDF_BAFontMap generates a default font.
23
24 auto annot_dict = pdfium::MakeRetain<CPDF_Dictionary>();
25 annot_dict->SetNewFor<CPDF_Name>(pdfium::annotation::kSubtype, "Widget");
26 annot_dict->SetNewFor<CPDF_String>("DA", "0 0 0 rg /F1 12 Tf",
27 /*bHex=*/false);
28
29 CPDF_BAFontMap font_map(&doc, std::move(annot_dict), "N");
30#if !BUILDFLAG(IS_WIN)
31 // TODO(thestig): Figure out why this does not work on Windows.
32 EXPECT_EQ(font_map.GetPDFFontAlias(0), "Helvetica_00");
33#endif
34 RetainPtr<CPDF_Font> font = font_map.GetPDFFont(0);
35 ASSERT_TRUE(font);
36 EXPECT_TRUE(font->IsType1Font());
37 EXPECT_EQ(font->GetBaseFontName(), "Helvetica");
38}
39
40TEST_F(BAFontMapTest, Bug853238) {
42 auto root_dict = pdfium::MakeRetain<CPDF_Dictionary>();
43 auto acroform_dict = root_dict->SetNewFor<CPDF_Dictionary>("AcroForm");
44 auto annot_dr_dict = acroform_dict->SetNewFor<CPDF_Dictionary>("DR");
45 auto annot_font_dict = annot_dr_dict->SetNewFor<CPDF_Dictionary>("Font");
46 auto annot_font_f1_dict = annot_font_dict->SetNewFor<CPDF_Dictionary>("F1");
47 annot_font_f1_dict->SetNewFor<CPDF_Name>("Type", "Font");
48 annot_font_f1_dict->SetNewFor<CPDF_Name>("Subtype", "Type1");
49 annot_font_f1_dict->SetNewFor<CPDF_Name>("BaseFont", "Times-Roman");
50 doc.SetRoot(root_dict);
51
52 auto annot_dict = pdfium::MakeRetain<CPDF_Dictionary>();
53 annot_dict->SetNewFor<CPDF_Name>(pdfium::annotation::kSubtype, "Widget");
54 annot_dict->SetNewFor<CPDF_String>("DA", "0 0 0 rg /F1 12 Tf",
55 /*bHex=*/false);
56
57 CPDF_BAFontMap font_map(&doc, std::move(annot_dict), "N");
58 EXPECT_EQ(font_map.GetPDFFontAlias(0), "F1");
59 RetainPtr<CPDF_Font> font = font_map.GetPDFFont(0);
60 ASSERT_TRUE(font);
61 EXPECT_TRUE(font->IsType1Font());
62 EXPECT_EQ(font->GetBaseFontName(), "Times-Roman");
63}
ByteString GetPDFFontAlias(int32_t nFontIndex) override
void SetRoot(RetainPtr< CPDF_Dictionary > root)
TEST_F(CPDF_CIDFontTest, BUG_920636)