5#include "testing/test_fonts.h"
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"
19ByteString RenameFontForTesting(
const ByteString& face) {
21 if (face.Contains(
"Arial") || face.Contains(
"Calibri") ||
22 face.Contains(
"Helvetica")) {
25 }
else if (face
.IsEmpty() || face.Contains(
"Times")) {
28 }
else if (face.Contains(
"Courier")) {
36 if (face.Contains(
"Bold"))
39 if (face.Contains(
"Italic") || face.Contains(
"Oblique"))
48 explicit SystemFontInfoWrapper(std::unique_ptr<SystemFontInfoIface> impl)
49 : impl_(std::move(impl)) {}
50 ~SystemFontInfoWrapper()
override {
CHECK(active_fonts_.empty()); }
53 return impl_->EnumFontList(pMapper);
55 void* MapFont(
int weight,
59 const ByteString& face)
override {
60 void* font = impl_->MapFont(weight, bItalic, charset, pitch_family,
61 RenameFontForTesting(face));
63 bool inserted = active_fonts_.insert(font).second;
68 void* GetFont(
const ByteString& face)
override {
69 return impl_->GetFont(RenameFontForTesting(face));
71 size_t GetFontData(
void* hFont,
73 pdfium::span<uint8_t> buffer)
override {
74 return impl_->GetFontData(hFont, table, buffer);
76 bool GetFaceName(
void* hFont, ByteString* name)
override {
77 auto face = RenameFontForTesting(*name);
78 return impl_->GetFaceName(hFont, &face);
80 bool GetFontCharset(
void* hFont,
FX_Charset* charset)
override {
81 return impl_->GetFontCharset(hFont, charset);
83 void DeleteFont(
void* hFont)
override {
84 CHECK(active_fonts_.erase(hFont));
85 impl_->DeleteFont(hFont);
89 std::unique_ptr<SystemFontInfoIface> impl_;
90 std::set<
void*> active_fonts_;
96 if (!PathService::GetExecutableDir(&font_path_))
99 font_path_.append(
"test_fonts");
100 font_paths_ = std::vector<
const char*>{font_path_.c_str(),
nullptr};
107 font_mapper->SetSystemFontInfo(
std::make_unique<SystemFontInfoWrapper>(
108 font_mapper->TakeSystemFontInfo()));
113 ByteString renamed_face = RenameFontForTesting(face);
114 return std::string(renamed_face
.c_str());
CFX_FontMapper * GetBuiltinMapper() const
static CFX_GEModule * Get()
CFX_FontMgr * GetFontMgr() const
static std::string RenameFont(const char *face)
ByteString & operator+=(const char *str)
ByteString & operator=(const char *str)
const char * c_str() const