5#include "public/fpdf_sysfontinfo.h"
10#include "build/build_config.h"
11#include "core/fxcrt/compiler_specific.h"
12#include "testing/embedder_test.h"
13#include "testing/embedder_test_environment.h"
14#include "testing/gmock/include/gmock/gmock.h"
15#include "testing/gtest/include/gtest/gtest.h"
21void FakeRelease(FPDF_SYSFONTINFO* pThis) {}
22void FakeEnumFonts(FPDF_SYSFONTINFO* pThis,
void* pMapper) {}
24void* FakeMapFont(FPDF_SYSFONTINFO* pThis,
35void* FakeGetFont(FPDF_SYSFONTINFO* pThis,
const char* face) {
40unsigned long FakeGetFontData(FPDF_SYSFONTINFO* pThis,
43 unsigned char* buffer,
44 unsigned long buf_size) {
48unsigned long FakeGetFaceName(FPDF_SYSFONTINFO* pThis,
51 unsigned long buf_size) {
55int FakeGetFontCharset(FPDF_SYSFONTINFO* pThis,
void* hFont) {
59void FakeDeleteFont(FPDF_SYSFONTINFO* pThis,
void* hFont) {}
63class FPDFUnavailableSysFontInfoEmbedderTest :
public EmbedderTest {
65 FPDFUnavailableSysFontInfoEmbedderTest() =
default;
66 ~FPDFUnavailableSysFontInfoEmbedderTest() override =
default;
68 void SetUp() override {
82 void TearDown() override {
92 FPDF_SYSFONTINFO font_info_;
97 FPDFSysFontInfoEmbedderTest() =
default;
98 ~FPDFSysFontInfoEmbedderTest() override =
default;
100 void SetUp() override {
103 ASSERT_TRUE(font_info_);
107 void TearDown() override {
121 FPDF_SYSFONTINFO* font_info_;
127 ASSERT_TRUE(OpenDocument(
"bug_972518.pdf"));
128 ASSERT_EQ(1, FPDF_GetPageCount(document()));
130 FPDF_PAGE page = LoadPage(0);
136 ASSERT_TRUE(OpenDocument(
"hello_world.pdf"));
137 ASSERT_EQ(1, FPDF_GetPageCount(document()));
139 FPDF_PAGE page = LoadPage(0);
144 ScopedFPDFBitmap bitmap = RenderPage(page);
145 ASSERT_EQ(200, FPDFBitmap_GetWidth(bitmap.get()));
146 ASSERT_EQ(200, FPDFBitmap_GetHeight(bitmap.get()));
153 static constexpr int kExpectedCharsets[] = {
159 std::vector<
int> charsets;
175 EXPECT_THAT(charsets, testing::UnorderedElementsAreArray(kExpectedCharsets));
179 static constexpr int kExpectedCharsets[] = {
189 static const std::string kExpectedFontNames[] = {
190 "Helvetica",
"SimSun",
"MingLiU",
"MS Gothic",
"Batang",
"Arial",
198 std::vector<
int> charsets;
199 std::vector<
const char*> font_names;
201 const size_t count = FPDF_GetDefaultTTFMapCount();
202 for (size_t i = 0; i < count; ++i) {
203 const FPDF_CharsetFontMap* entry = FPDF_GetDefaultTTFMapEntry(i);
209 EXPECT_THAT(charsets, testing::ElementsAreArray(kExpectedCharsets));
210 EXPECT_THAT(font_names, testing::ElementsAreArray(kExpectedFontNames));
213 EXPECT_FALSE(FPDF_GetDefaultTTFMapEntry(count));
214 EXPECT_FALSE(FPDF_GetDefaultTTFMapEntry(9999));
static EmbedderTestEnvironment * GetInstance()
#define UNSAFE_BUFFERS(...)
FPDF_EXPORT void FPDF_CALLCONV FPDF_SetSystemFontInfo(FPDF_SYSFONTINFO *pFontInfoExt)
FPDF_EXPORT const FPDF_CharsetFontMap *FPDF_CALLCONV FPDF_GetDefaultTTFMap()
FPDF_EXPORT FPDF_SYSFONTINFO *FPDF_CALLCONV FPDF_GetDefaultSystemFontInfo()
FPDF_EXPORT void FPDF_CALLCONV FPDF_FreeDefaultSystemFontInfo(FPDF_SYSFONTINFO *pFontInfo)
#define FXFONT_HANGEUL_CHARSET
#define FXFONT_EASTERNEUROPEAN_CHARSET
#define FXFONT_SHIFTJIS_CHARSET
#define FXFONT_CYRILLIC_CHARSET
#define FXFONT_ANSI_CHARSET
#define FXFONT_ARABIC_CHARSET
#define FXFONT_GB2312_CHARSET
#define FXFONT_CHINESEBIG5_CHARSET
TEST_F(FPDFUnavailableSysFontInfoEmbedderTest, Bug972518)
TEST_F(FPDFSysFontInfoEmbedderTest, DefaultSystemFontInfo)
void(* Release)(struct _FPDF_SYSFONTINFO *pThis)
void(* DeleteFont)(struct _FPDF_SYSFONTINFO *pThis, void *hFont)
unsigned long(* GetFontData)(struct _FPDF_SYSFONTINFO *pThis, void *hFont, unsigned int table, unsigned char *buffer, unsigned long buf_size)
void *(* GetFont)(struct _FPDF_SYSFONTINFO *pThis, const char *face)
unsigned long(* GetFaceName)(struct _FPDF_SYSFONTINFO *pThis, void *hFont, char *buffer, unsigned long buf_size)
int(* GetFontCharset)(struct _FPDF_SYSFONTINFO *pThis, void *hFont)
void(* EnumFonts)(struct _FPDF_SYSFONTINFO *pThis, void *pMapper)
void *(* MapFont)(struct _FPDF_SYSFONTINFO *pThis, int weight, FPDF_BOOL bItalic, int charset, int pitch_family, const char *face, FPDF_BOOL *bExact)