5#include "core/fxge/cfx_fontmapper.h"
11#include "core/fxcrt/fx_codepage.h"
12#include "core/fxge/cfx_gemodule.h"
13#include "core/fxge/systemfontinfo_iface.h"
14#include "testing/gmock/include/gmock/gmock.h"
15#include "testing/gtest/include/gtest/gtest.h"
19using testing::ElementsAre;
20using testing::InSequence;
23using testing::WithArg;
34 (
int,
bool,
FX_Charset,
int,
const ByteString&),
39 (
void*, uint32_t, pdfium::span<uint8_t>),
54 return CFX_FontMapper::GetCachedTTCFace(font_handle, ttc_size, data_size);
58 ByteString subst_name,
62 return CFX_FontMapper::GetCachedFace(font_handle, subst_name, weight,
63 is_italic, data_size);
73 font_mapper_ = std::make_unique<TestFontMapper>();
75 system_font_info_ = system_font_info.get();
76 font_mapper_->SetSystemFontInfo(std::move(system_font_info));
77 font_mapper_->AddInstalledFont(
"dummy", FX_Charset::kANSI);
85 std::unique_ptr<TestFontMapper> font_mapper_;
118 EXPECT_EQ(0xffffffffu,
120 EXPECT_EQ(0xffffffffu,
124 EXPECT_EQ(FT_MAKE_TAG(
'G',
'S',
'U',
'B'),
129 const char kFontName[] =
"dummy";
134 EXPECT_EQ(1u, font_mapper.GetFaceSize());
135 EXPECT_EQ(kFontName, font_mapper.GetFaceName(0));
139TEST_F(CFXFontMapperSystemFontInfoTest, RawBytesForIndex) {
141 void*
const kFontHandle =
reinterpret_cast<
void*>(12345);
144 EXPECT_CALL(system_font_info(), MapFont).WillOnce(Return(kFontHandle));
145 EXPECT_CALL(system_font_info(), GetFontData(kFontHandle, 0, _))
146 .WillOnce(Return(2));
147 EXPECT_CALL(system_font_info(), GetFontData(kFontHandle, 0, _))
148 .WillOnce(DoAll(WithArg<2>(Invoke([](pdfium::span<uint8_t> buffer) {
153 EXPECT_CALL(system_font_info(), DeleteFont(kFontHandle));
156 FixedSizeDataVector<uint8_t> data = font_mapper().RawBytesForIndex(0);
157 EXPECT_THAT(data.span(), ElementsAre(
'0',
'1'));
160TEST_F(CFXFontMapperSystemFontInfoTest, RawBytesForIndexFailToMap) {
161 EXPECT_CALL(system_font_info(), MapFont).WillOnce(Return(
nullptr));
163 FixedSizeDataVector<uint8_t> data = font_mapper().RawBytesForIndex(0);
164 EXPECT_TRUE(data.empty());
167TEST_F(CFXFontMapperSystemFontInfoTest, RawBytesForIndexFailToGetDataSize) {
169 void*
const kFontHandle =
reinterpret_cast<
void*>(12345);
172 EXPECT_CALL(system_font_info(), MapFont).WillOnce(Return(kFontHandle));
173 EXPECT_CALL(system_font_info(), GetFontData(kFontHandle, 0, _))
174 .WillOnce(Return(0));
175 EXPECT_CALL(system_font_info(), DeleteFont(kFontHandle));
178 FixedSizeDataVector<uint8_t> data = font_mapper().RawBytesForIndex(0);
179 EXPECT_TRUE(data.empty());
182TEST_F(CFXFontMapperSystemFontInfoTest, RawBytesForIndexFailToGetData) {
184 void*
const kFontHandle =
reinterpret_cast<
void*>(12345);
187 EXPECT_CALL(system_font_info(), MapFont).WillOnce(Return(kFontHandle));
188 EXPECT_CALL(system_font_info(), GetFontData(kFontHandle, 0, _))
189 .WillOnce(Return(2));
190 EXPECT_CALL(system_font_info(), GetFontData(kFontHandle, 0, _))
191 .WillOnce(Return(0));
192 EXPECT_CALL(system_font_info(), DeleteFont(kFontHandle));
195 FixedSizeDataVector<uint8_t> data = font_mapper().RawBytesForIndex(0);
196 EXPECT_TRUE(data.empty());
202 void*
const kFontHandle =
reinterpret_cast<
void*>(12345);
203 constexpr size_t kTtcSize = 1024;
204 constexpr size_t kDataSize = 2;
208 EXPECT_CALL(system_font_info(), GetFontData(kFontHandle, kTableTTCF, _))
209 .WillOnce(DoAll(WithArg<2>(Invoke([&](pdfium::span<uint8_t> buffer) {
210 EXPECT_EQ(kTtcSize, buffer.size());
211 std::iota(buffer.begin(), buffer.end(), 0);
214 EXPECT_CALL(system_font_info(), GetFontData(kFontHandle, kTableTTCF, _))
215 .WillOnce(Return(0));
219 font_mapper().GetCachedTTCFace(kFontHandle, kTtcSize, kDataSize));
224 void*
const kFontHandle =
reinterpret_cast<
void*>(12345);
225 constexpr char kSubstName[] =
"dummy_font";
226 constexpr int kWeight = 400;
227 constexpr bool kItalic =
false;
228 constexpr size_t kDataSize = 2;
230 EXPECT_CALL(system_font_info(), GetFontData(kFontHandle, 0, _))
231 .WillOnce(Return(0));
233 EXPECT_FALSE(font_mapper().GetCachedFace(kFontHandle, kSubstName, kWeight,
234 kItalic, kDataSize));
TEST(CFX_FontMapper, IsStandardFontName)
TEST_F(CFXFontMapperSystemFontInfoTest, GetCachedTTCFaceFailToGetData)
MockSystemFontInfo & system_font_info()
CFXFontMapperSystemFontInfoTest()=default
~CFXFontMapperSystemFontInfoTest() override=default
TestFontMapper & font_mapper()
void AddInstalledFont(const ByteString &name, FX_Charset charset)
static constexpr uint32_t MakeTag(char c1, char c2, char c3, char c4)
CFX_FontMapper(CFX_FontMgr *mgr)
static bool IsStandardFontName(const ByteString &name)
static CFX_GEModule * Get()
CFX_FontMgr * GetFontMgr() const
MOCK_METHOD(void *, GetFont,(const ByteString &),(override))
~MockSystemFontInfo() override=default
MOCK_METHOD(bool, GetFaceName,(void *, ByteString *),(override))
MOCK_METHOD(size_t, GetFontData,(void *, uint32_t, pdfium::span< uint8_t >),(override))
MOCK_METHOD(bool, EnumFontList,(CFX_FontMapper *),(override))
MOCK_METHOD(void, DeleteFont,(void *),(override))
MOCK_METHOD(bool, GetFontCharset,(void *, FX_Charset *),(override))
MOCK_METHOD(void *, MapFont,(int, bool, FX_Charset, int, const ByteString &),(override))
MockSystemFontInfo()=default
RetainPtr< CFX_Face > GetCachedFace(void *font_handle, ByteString subst_name, int weight, bool is_italic, size_t data_size)
RetainPtr< CFX_Face > GetCachedTTCFace(void *font_handle, size_t ttc_size, size_t data_size)