Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
font_renamer.cpp
Go to the documentation of this file.
1// Copyright 2022 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/font_renamer.h"
6
7#include <string>
8
9#include "testing/test_fonts.h"
10
11namespace {
12
13FPDF_SYSFONTINFO* GetImpl(FPDF_SYSFONTINFO* info) {
14 return static_cast<FontRenamer*>(info)->impl();
15}
16
17void ReleaseImpl(FPDF_SYSFONTINFO* info) {
18 FPDF_SYSFONTINFO* impl = GetImpl(info);
19 impl->Release(impl);
20}
21
22void EnumFontsImpl(FPDF_SYSFONTINFO* info, void* mapper) {
23 FPDF_SYSFONTINFO* impl = GetImpl(info);
24 impl->EnumFonts(impl, mapper);
25}
26
27void* MapFontImpl(FPDF_SYSFONTINFO* info,
28 int weight,
29 FPDF_BOOL italic,
30 int charset,
31 int pitch_family,
32 const char* face,
33 FPDF_BOOL* exact) {
34 std::string renamed_face = TestFonts::RenameFont(face);
35 FPDF_SYSFONTINFO* impl = GetImpl(info);
36 return impl->MapFont(impl, weight, italic, charset, pitch_family,
37 renamed_face.c_str(), exact);
38}
39
40void* GetFontImpl(FPDF_SYSFONTINFO* info, const char* face) {
41 // Any non-null return will do.
42 FPDF_SYSFONTINFO* impl = GetImpl(info);
43 std::string renamed_face = TestFonts::RenameFont(face);
44 return impl->GetFont(impl, renamed_face.c_str());
45}
46
47unsigned long GetFontDataImpl(FPDF_SYSFONTINFO* info,
48 void* font,
49 unsigned int table,
50 unsigned char* buffer,
51 unsigned long buf_size) {
52 FPDF_SYSFONTINFO* impl = GetImpl(info);
53 return impl->GetFontData(impl, font, table, buffer, buf_size);
54}
55
56unsigned long GetFaceNameImpl(FPDF_SYSFONTINFO* info,
57 void* font,
58 char* buffer,
59 unsigned long buf_size) {
60 FPDF_SYSFONTINFO* impl = GetImpl(info);
61 return impl->GetFaceName(impl, font, buffer, buf_size);
62}
63
64int GetFontCharsetImpl(FPDF_SYSFONTINFO* info, void* font) {
65 FPDF_SYSFONTINFO* impl = GetImpl(info);
66 return impl->GetFontCharset(impl, font);
67}
68
69void DeleteFontImpl(FPDF_SYSFONTINFO* info, void* font) {
70 FPDF_SYSFONTINFO* impl = GetImpl(info);
71 impl->DeleteFont(impl, font);
72}
73
74} // namespace
75
77 version = 1;
78 Release = ReleaseImpl;
79 EnumFonts = EnumFontsImpl;
80 MapFont = MapFontImpl;
81 GetFont = GetFontImpl;
82 GetFontData = GetFontDataImpl;
83 GetFaceName = GetFaceNameImpl;
84 GetFontCharset = GetFontCharsetImpl;
85 DeleteFont = DeleteFontImpl;
86 FPDF_SetSystemFontInfo(this);
87}
88
89FontRenamer::~FontRenamer() {
90 FPDF_FreeDefaultSystemFontInfo(impl_.ExtractAsDangling());
91}
FPDF_SYSFONTINFO * impl()
static std::string RenameFont(const char *face)
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)