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
fx_apple_platform.cpp
Go to the documentation of this file.
1
// Copyright 2014 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
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7
#
include
"core/fxge/apple/fx_apple_platform.h"
8
9
#
include
<
memory
>
10
#
include
<
utility
>
11
12
#
include
"core/fxcrt/compiler_specific.h"
13
#
include
"core/fxcrt/fx_codepage.h"
14
#
include
"core/fxge/cfx_folderfontinfo.h"
15
#
include
"core/fxge/cfx_fontmgr.h"
16
#
include
"core/fxge/fx_font.h"
17
#
include
"core/fxge/systemfontinfo_iface.h"
18
19
namespace
{
20
21
struct
Substs {
22
const
char
* m_pName;
23
const
char
* m_pSubstName;
24
};
25
26
constexpr
Substs kBase14Substs[] = {
27
{
"Courier"
,
"Courier New"
},
28
{
"Courier-Bold"
,
"Courier New Bold"
},
29
{
"Courier-BoldOblique"
,
"Courier New Bold Italic"
},
30
{
"Courier-Oblique"
,
"Courier New Italic"
},
31
{
"Helvetica"
,
"Arial"
},
32
{
"Helvetica-Bold"
,
"Arial Bold"
},
33
{
"Helvetica-BoldOblique"
,
"Arial Bold Italic"
},
34
{
"Helvetica-Oblique"
,
"Arial Italic"
},
35
{
"Times-Roman"
,
"Times New Roman"
},
36
{
"Times-Bold"
,
"Times New Roman Bold"
},
37
{
"Times-BoldItalic"
,
"Times New Roman Bold Italic"
},
38
{
"Times-Italic"
,
"Times New Roman Italic"
},
39
};
40
41
class
CFX_MacFontInfo
final
:
public
CFX_FolderFontInfo
{
42
public
:
43
CFX_MacFontInfo() =
default
;
44
~CFX_MacFontInfo()
override
=
default
;
45
46
// CFX_FolderFontInfo
47
void
* MapFont(
int
weight,
48
bool
bItalic,
49
FX_Charset
charset,
50
int
pitch_family,
51
const
ByteString
& face)
override
;
52
53
bool
ParseFontCfg(
const
char
** pUserPaths);
54
};
55
56
constexpr
char
kJapanGothic[] =
"Hiragino Kaku Gothic Pro W6"
;
57
constexpr
char
kJapanMincho[] =
"Hiragino Mincho Pro W6"
;
58
59
ByteString
GetJapanesePreference(
const
ByteString
& face,
60
int
weight,
61
int
pitch_family) {
62
if
(face.Contains(
"Gothic"
))
63
return
kJapanGothic;
64
if
(
FontFamilyIsRoman
(
pitch_family
)
|| weight <= 400)
65
return
kJapanMincho;
66
return
kJapanGothic;
67
}
68
69
void
* CFX_MacFontInfo::MapFont(
int
weight,
70
bool
bItalic,
71
FX_Charset
charset,
72
int
pitch_family,
73
const
ByteString
& face) {
74
for
(
const
auto
& sub : kBase14Substs) {
75
if
(face == ByteStringView(sub.m_pName))
76
return
GetFont
(sub.m_pSubstName);
77
}
78
79
// The request may not ask for the bold and/or italic version of a font by
80
// name. So try to construct the appropriate name. This is not 100% foolproof
81
// as there are fonts that have "Oblique" or "BoldOblique" or "Heavy" in their
82
// names instead. But this at least works for common fonts like Arial and
83
// Times New Roman. A more sophisticated approach would be to find all the
84
// fonts in |m_FontList| with |face| in the name, and examine the fonts to
85
// see which best matches the requested characteristics.
86
if
(!face.Contains(
"Bold"
) && !face.Contains(
"Italic"
)) {
87
ByteString
new_face = face;
88
if
(weight > 400)
89
new_face
+=
" Bold"
;
90
if
(bItalic)
91
new_face
+=
" Italic"
;
92
auto
it = m_FontList.find(new_face);
93
if
(it != m_FontList.end())
94
return
it->second.get();
95
}
96
97
auto
it = m_FontList.find(face);
98
if
(it != m_FontList.end())
99
return
it->second.get();
100
101
if
(charset ==
FX_Charset
::
kANSI
&&
FontFamilyIsFixedPitch
(
pitch_family
)
)
102
return
GetFont
(
"Courier New"
);
103
104
if
(charset ==
FX_Charset
::
kANSI
|| charset ==
FX_Charset
::
kSymbol
)
105
return
nullptr
;
106
107
ByteString
other_face;
108
switch
(charset) {
109
case
FX_Charset
::
kShiftJIS
:
110
other_face
=
GetJapanesePreference(face, weight, pitch_family);
111
break
;
112
case
FX_Charset
::
kChineseSimplified
:
113
other_face
=
"STSong"
;
114
break
;
115
case
FX_Charset
::
kHangul
:
116
other_face
=
"AppleMyungjo"
;
117
break
;
118
case
FX_Charset
::
kChineseTraditional
:
119
other_face
=
"LiSong Pro Light"
;
120
break
;
121
default
:
122
other_face
=
face;
123
break
;
124
}
125
it = m_FontList.find(other_face);
126
return
it != m_FontList.end() ? it->second.get() :
nullptr
;
127
}
128
129
bool
CFX_MacFontInfo::ParseFontCfg(
const
char
** pUserPaths) {
130
if
(!pUserPaths) {
131
return
false
;
132
}
133
UNSAFE_TODO
({
134
for
(
const
char
** pPath = pUserPaths; *pPath; ++pPath) {
135
AddPath
(*pPath);
136
}
137
});
138
return
true
;
139
}
140
141
}
// namespace
142
143
CApplePlatform::
CApplePlatform
() =
default
;
144
145
CApplePlatform::~
CApplePlatform
() =
default
;
146
147
void
CApplePlatform::
Init
() {}
148
149
std
::
unique_ptr
<
SystemFontInfoIface
>
150
CApplePlatform::
CreateDefaultSystemFontInfo
() {
151
auto
pInfo =
std
::make_unique<CFX_MacFontInfo>();
152
if
(!pInfo->ParseFontCfg(
CFX_GEModule
::
Get
(
)
->
GetUserFontPaths
(
)
)) {
153
pInfo->AddPath(
"~/Library/Fonts"
);
154
pInfo->AddPath(
"/Library/Fonts"
);
155
pInfo->AddPath(
"/System/Library/Fonts"
);
156
}
157
return
pInfo;
158
}
159
160
void
* CApplePlatform::
CreatePlatformFont
(
161
pdfium::span<
const
uint8_t> font_span) {
162
return
m_quartz2d
.CreateFont(font_span);
163
}
164
165
// static
166
std::unique_ptr<CFX_GEModule::PlatformIface>
167
CFX_GEModule
::
PlatformIface
::Create() {
168
return
std
::make_unique<CApplePlatform>();
169
}
ByteString
fxcrt::ByteString ByteString
Definition
bytestring.h:180
CApplePlatform::CApplePlatform
CApplePlatform()
CApplePlatform::Init
void Init() override
Definition
fx_apple_platform.cpp:147
CApplePlatform::CreateDefaultSystemFontInfo
std::unique_ptr< SystemFontInfoIface > CreateDefaultSystemFontInfo() override
Definition
fx_apple_platform.cpp:150
CApplePlatform::CreatePlatformFont
void * CreatePlatformFont(pdfium::span< const uint8_t > font_span) override
Definition
fx_apple_platform.cpp:160
CApplePlatform::m_quartz2d
CQuartz2D m_quartz2d
Definition
fx_apple_platform.h:25
CApplePlatform::~CApplePlatform
~CApplePlatform() override
CFX_FolderFontInfo
Definition
cfx_folderfontinfo.h:26
CFX_FolderFontInfo::AddPath
void AddPath(const ByteString &path)
Definition
cfx_folderfontinfo.cpp:140
CFX_FolderFontInfo::GetFont
void * GetFont(const ByteString &face) override
Definition
cfx_folderfontinfo.cpp:378
CFX_GEModule::PlatformIface
Definition
cfx_gemodule.h:27
CFX_GEModule
Definition
cfx_gemodule.h:25
CFX_GEModule::Get
static CFX_GEModule * Get()
Definition
cfx_gemodule.cpp:45
CFX_GEModule::GetUserFontPaths
const char ** GetUserFontPaths() const
Definition
cfx_gemodule.h:47
fxcrt::ByteString::operator+=
ByteString & operator+=(const char *str)
Definition
bytestring.cpp:182
fxcrt::ByteString::operator=
ByteString & operator=(const char *str)
Definition
bytestring.cpp:150
fxcrt::ByteString::operator=
ByteString & operator=(const ByteString &that)
Definition
bytestring.cpp:168
fxcrt::ByteString::operator=
ByteString & operator=(ByteString &&that) noexcept
Definition
bytestring.cpp:175
UNSAFE_TODO
#define UNSAFE_TODO(...)
Definition
compiler_specific.h:102
FX_Charset
FX_Charset
Definition
fx_codepage.h:71
FX_Charset::kChineseTraditional
@ kChineseTraditional
Definition
fx_codepage.h:91
FX_Charset::kANSI
@ kANSI
Definition
fx_codepage.h:72
FX_Charset::kSymbol
@ kSymbol
Definition
fx_codepage.h:74
FX_Charset::kChineseSimplified
@ kChineseSimplified
Definition
fx_codepage.h:90
FX_Charset::kHangul
@ kHangul
Definition
fx_codepage.h:88
FX_Charset::kShiftJIS
@ kShiftJIS
Definition
fx_codepage.h:87
FontFamilyIsFixedPitch
bool FontFamilyIsFixedPitch(uint32_t family)
Definition
fx_font.h:86
FontFamilyIsRoman
bool FontFamilyIsRoman(uint32_t family)
Definition
fx_font.h:89
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
qtwebengine
src
3rdparty
chromium
third_party
pdfium
core
fxge
apple
fx_apple_platform.cpp
Generated on
for Qt by
1.18.0