xref: /aosp_15_r20/external/pdfium/core/fxge/fx_font_unittest.cpp (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1 // Copyright 2018 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 <string>
6 
7 #include "core/fxge/cfx_folderfontinfo.h"
8 #include "core/fxge/cfx_fontmapper.h"
9 #include "core/fxge/cfx_gemodule.h"
10 #include "core/fxge/fx_font.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "testing/utils/path_service.h"
13 #include "third_party/base/check.h"
14 
TEST(FXFontTest,UnicodeFromAdobeName)15 TEST(FXFontTest, UnicodeFromAdobeName) {
16   EXPECT_EQ(static_cast<wchar_t>(0x0000), UnicodeFromAdobeName("nonesuch"));
17   EXPECT_EQ(static_cast<wchar_t>(0x0000), UnicodeFromAdobeName(""));
18   EXPECT_EQ(static_cast<wchar_t>(0x00b6), UnicodeFromAdobeName("paragraph"));
19   EXPECT_EQ(static_cast<wchar_t>(0x00d3), UnicodeFromAdobeName("Oacute"));
20   EXPECT_EQ(static_cast<wchar_t>(0x00fe), UnicodeFromAdobeName("thorn"));
21   EXPECT_EQ(static_cast<wchar_t>(0x0384), UnicodeFromAdobeName("tonos"));
22   EXPECT_EQ(static_cast<wchar_t>(0x2022), UnicodeFromAdobeName("bullet"));
23 }
24 
TEST(FXFontTest,AdobeNameFromUnicode)25 TEST(FXFontTest, AdobeNameFromUnicode) {
26   EXPECT_STREQ("", AdobeNameFromUnicode(0x0000).c_str());
27   EXPECT_STREQ("divide", AdobeNameFromUnicode(0x00f7).c_str());
28   EXPECT_STREQ("Lslash", AdobeNameFromUnicode(0x0141).c_str());
29   EXPECT_STREQ("tonos", AdobeNameFromUnicode(0x0384).c_str());
30   EXPECT_STREQ("afii57513", AdobeNameFromUnicode(0x0691).c_str());
31   EXPECT_STREQ("angkhankhuthai", AdobeNameFromUnicode(0x0e5a).c_str());
32   EXPECT_STREQ("Euro", AdobeNameFromUnicode(0x20ac).c_str());
33 }
34 
TEST(FXFontTest,ReadFontNameFromMicrosoftEntries)35 TEST(FXFontTest, ReadFontNameFromMicrosoftEntries) {
36   std::string test_data_dir;
37   PathService::GetTestDataDir(&test_data_dir);
38   DCHECK(!test_data_dir.empty());
39 
40   CFX_FontMapper font_mapper(nullptr);
41 
42   {
43     // |folder_font_info| has to be deallocated before the |font_mapper| or we
44     // run into UnownedPtr class issues with ASAN.
45     CFX_FolderFontInfo folder_font_info;
46     folder_font_info.AddPath(
47         (test_data_dir + PATH_SEPARATOR + "font_tests").c_str());
48 
49     font_mapper.SetSystemFontInfo(
50         CFX_GEModule::Get()->GetPlatform()->CreateDefaultSystemFontInfo());
51     ASSERT_TRUE(folder_font_info.EnumFontList(&font_mapper));
52   }
53 
54   ASSERT_EQ(1u, font_mapper.GetFaceSize());
55   ASSERT_EQ("Test", font_mapper.GetFaceName(0));
56 }
57