Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
test_fonts.cpp
Go to the documentation of this file.
1
// Copyright 2021 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
"testing/test_fonts.h"
6
7
#
include
<
memory
>
8
#
include
<
set
>
9
#
include
<
utility
>
10
11
#
include
"core/fxge/cfx_fontmapper.h"
12
#
include
"core/fxge/cfx_fontmgr.h"
13
#
include
"core/fxge/cfx_gemodule.h"
14
#
include
"core/fxge/systemfontinfo_iface.h"
15
#
include
"testing/utils/path_service.h"
16
17
namespace
{
18
19
ByteString
RenameFontForTesting(
const
ByteString
& face) {
20
ByteString
result;
21
if
(face.Contains(
"Arial"
) || face.Contains(
"Calibri"
) ||
22
face.Contains(
"Helvetica"
)) {
23
// Sans
24
result
=
"Arimo"
;
25
}
else
if
(face.IsEmpty() || face.Contains(
"Times"
)) {
26
// Serif
27
result
=
"Tinos"
;
28
}
else
if
(face.Contains(
"Courier"
)) {
29
// Mono
30
result
=
"Cousine"
;
31
}
else
{
32
// Some tests expect the fallback font.
33
return
face;
34
}
35
36
if
(face.Contains(
"Bold"
))
37
result
+=
" Bold"
;
38
39
if
(face.Contains(
"Italic"
) || face.Contains(
"Oblique"
))
40
result
+=
" Italic"
;
41
42
return
result;
43
}
44
45
// Intercepts font requests and renames font faces to those in test_fonts.
46
class
SystemFontInfoWrapper :
public
SystemFontInfoIface
{
47
public
:
48
explicit
SystemFontInfoWrapper(std::unique_ptr<SystemFontInfoIface> impl)
49
: impl_(std::move(impl)) {}
50
~SystemFontInfoWrapper()
override
{
CHECK
(active_fonts_.empty()); }
51
52
bool
EnumFontList(
CFX_FontMapper
* pMapper)
override
{
53
return
impl_->EnumFontList(pMapper);
54
}
55
void
* MapFont(
int
weight,
56
bool
bItalic,
57
FX_Charset
charset,
58
int
pitch_family,
59
const
ByteString
& face)
override
{
60
void
* font = impl_->MapFont(weight, bItalic, charset, pitch_family,
61
RenameFontForTesting(face));
62
if
(font) {
63
bool
inserted = active_fonts_.insert(font).second;
64
CHECK
(inserted);
65
}
66
return
font;
67
}
68
void
* GetFont(
const
ByteString
& face)
override
{
69
return
impl_->GetFont(RenameFontForTesting(face));
70
}
71
size_t GetFontData(
void
* hFont,
72
uint32_t table,
73
pdfium::span<uint8_t> buffer)
override
{
74
return
impl_->GetFontData(hFont, table, buffer);
75
}
76
bool
GetFaceName(
void
* hFont,
ByteString
* name)
override
{
77
auto
face = RenameFontForTesting(*name);
78
return
impl_->GetFaceName(hFont, &face);
79
}
80
bool
GetFontCharset(
void
* hFont,
FX_Charset
* charset)
override
{
81
return
impl_->GetFontCharset(hFont, charset);
82
}
83
void
DeleteFont(
void
* hFont)
override
{
84
CHECK
(active_fonts_.erase(hFont));
85
impl_->DeleteFont(hFont);
86
}
87
88
private
:
89
std::unique_ptr<SystemFontInfoIface> impl_;
90
std::set<
void
*> active_fonts_;
91
};
92
93
}
// namespace
94
95
TestFonts
::
TestFonts
() {
96
if
(!
PathService
::GetExecutableDir(&font_path_))
97
return
;
98
font_path_.push_back(
PATH_SEPARATOR
);
99
font_path_.append(
"test_fonts"
);
100
font_paths_ = std::vector<
const
char
*>{font_path_.c_str(),
nullptr
};
101
}
102
103
TestFonts
::~
TestFonts
() =
default
;
104
105
void
TestFonts
::
InstallFontMapper
() {
106
auto
* font_mapper =
CFX_GEModule
::
Get
(
)
->
GetFontMgr
(
)
->
GetBuiltinMapper
(
)
;
107
font_mapper->SetSystemFontInfo(
std
::make_unique<SystemFontInfoWrapper>(
108
font_mapper->TakeSystemFontInfo()));
109
}
110
111
// static
112
std
::string
TestFonts
::
RenameFont
(
const
char
* face) {
113
ByteString
renamed_face = RenameFontForTesting(face);
114
return
std
::string(renamed_face.c_str());
115
}
ByteString
fxcrt::ByteString ByteString
Definition
bytestring.h:180
CFX_FontMapper
Definition
cfx_fontmapper.h:31
CFX_FontMgr::GetBuiltinMapper
CFX_FontMapper * GetBuiltinMapper() const
Definition
cfx_fontmgr.h:72
CFX_GEModule
Definition
cfx_gemodule.h:25
CFX_GEModule::Get
static CFX_GEModule * Get()
Definition
cfx_gemodule.cpp:45
CFX_GEModule::GetFontMgr
CFX_FontMgr * GetFontMgr() const
Definition
cfx_gemodule.h:45
PathService
Definition
path_service.h:17
SystemFontInfoIface
Definition
systemfontinfo_iface.h:21
TestFonts
Definition
test_fonts.h:11
TestFonts::TestFonts
TestFonts()
Definition
test_fonts.cpp:95
TestFonts::~TestFonts
~TestFonts()
TestFonts::RenameFont
static std::string RenameFont(const char *face)
Definition
test_fonts.cpp:112
TestFonts::InstallFontMapper
void InstallFontMapper()
Definition
test_fonts.cpp:105
fxcrt::ByteString::operator+=
ByteString & operator+=(const char *str)
Definition
bytestring.cpp:182
fxcrt::ByteString::operator=
ByteString & operator=(const char *str)
Definition
bytestring.cpp:150
FX_Charset
FX_Charset
Definition
fx_codepage.h:71
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
PATH_SEPARATOR
#define PATH_SEPARATOR
Definition
path_service.h:13
CHECK
#define CHECK(cvref)
Definition
q23utility.cpp:15
qtwebengine
src
3rdparty
chromium
third_party
pdfium
testing
test_fonts.cpp
Generated on
for Qt by
1.18.0