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_simplefont_unittest.cpp
Go to the documentation of this file.
1// Copyright 2023 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_simplefont.h"
6
7#include <stdint.h>
8
9#include <utility>
10
11#include "core/fpdfapi/page/test_with_page_module.h"
12#include "core/fpdfapi/parser/cpdf_dictionary.h"
13#include "core/fpdfapi/parser/cpdf_name.h"
14#include "core/fpdfapi/parser/cpdf_reference.h"
15#include "core/fpdfapi/parser/cpdf_stream.h"
16#include "core/fpdfapi/parser/cpdf_test_document.h"
17#include "core/fxcrt/retain_ptr.h"
18#include "core/fxge/fontdata/chromefontdata/chromefontdata.h"
19#include "testing/gtest/include/gtest/gtest.h"
20
21namespace {
22
23using CPDFSimpleFontTest = TestWithPageModule;
24
25class TestSimpleFont : public CPDF_SimpleFont {
26 public:
27 TestSimpleFont(CPDF_Document* doc, RetainPtr<CPDF_Dictionary> font_dict)
28 : CPDF_SimpleFont(doc, std::move(font_dict)) {}
29 ~TestSimpleFont() override = default;
30
31 // CPDF_SimpleFont:
32 bool Load() override { return LoadCommon(); }
33 void LoadGlyphMap() override {}
34};
35
36} // namespace
37
38TEST_F(CPDFSimpleFontTest, BaseFontNameWithSubsetting) {
40
41 // The code being exercised requires valid font data.
42 auto font_file_stream = doc.NewIndirect<CPDF_Stream>(
43 DataVector<uint8_t>(std::begin(kFoxitFixedFontData),
45 pdfium::MakeRetain<CPDF_Dictionary>());
46 ASSERT_TRUE(font_file_stream);
47 const uint32_t stream_object_number = font_file_stream->GetObjNum();
48 ASSERT_GT(stream_object_number, 0u);
49
50 auto font_descriptor_dict = pdfium::MakeRetain<CPDF_Dictionary>();
51 font_descriptor_dict->SetFor("FontFile", pdfium::MakeRetain<CPDF_Reference>(
52 &doc, stream_object_number));
53
54 auto font_dict = pdfium::MakeRetain<CPDF_Dictionary>();
55 font_dict->SetNewFor<CPDF_Name>("BaseFont", "CHEESE+Swiss");
56 font_dict->SetFor("FontDescriptor", std::move(font_descriptor_dict));
57
58 auto font = pdfium::MakeRetain<TestSimpleFont>(&doc, std::move(font_dict));
59 ASSERT_TRUE(font->Load());
60 EXPECT_EQ("Swiss", font->GetBaseFontName());
61}
const unsigned char kFoxitFixedFontData[17597]
Definition FoxitFixed.cpp:9
TEST_F(CPDF_CIDFontTest, BUG_920636)