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
cfgas_defaultfontmanager.cpp
Go to the documentation of this file.
1// Copyright 2017 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 "xfa/fgas/font/cfgas_defaultfontmanager.h"
8
9#include "core/fxcrt/compiler_specific.h"
10#include "core/fxcrt/fx_codepage.h"
11#include "core/fxcrt/numerics/safe_conversions.h"
12#include "core/fxge/fx_font.h"
13#include "xfa/fgas/font/cfgas_fontmgr.h"
14#include "xfa/fgas/font/cfgas_gefont.h"
15#include "xfa/fgas/font/cfgas_gemodule.h"
16#include "xfa/fgas/font/fgas_fontutils.h"
17
18// static
20 WideString wsFontName,
21 uint32_t dwFontStyles) {
23 RetainPtr<CFGAS_GEFont> pFont = pFontMgr->LoadFont(
24 wsFontName.c_str(), dwFontStyles, FX_CodePage::kFailure);
25 if (pFont) {
26 return pFont;
27 }
28 const FGAS_FontInfo* pCurFont =
29 FGAS_FontInfoByFontName(wsFontName.AsStringView());
30 if (!pCurFont || !pCurFont->pReplaceFont) {
31 return nullptr;
32 }
33 uint32_t dwStyle = 0;
34 // TODO(dsinclair): Why doesn't this check the other flags?
35 if (FontStyleIsForceBold(dwFontStyles)) {
36 dwStyle |= FXFONT_FORCE_BOLD;
37 }
38 if (FontStyleIsItalic(dwFontStyles)) {
39 dwStyle |= FXFONT_ITALIC;
40 }
41 ByteStringView replace_view(pCurFont->pReplaceFont);
42 while (!replace_view.IsEmpty()) {
43 ByteStringView segment;
44 auto found = replace_view.Find(',');
45 if (found.has_value()) {
46 segment = replace_view.First(found.value());
47 replace_view = replace_view.Substr(found.value() + 1);
48 } else {
49 segment = replace_view;
50 replace_view = ByteStringView();
51 }
52 pFont = pFontMgr->LoadFont(WideString::FromASCII(segment).c_str(), dwStyle,
54 if (pFont) {
55 return pFont;
56 }
57 }
58 return nullptr;
59}
60
61// static
63 uint32_t dwFontStyles) {
65 RetainPtr<CFGAS_GEFont> pFont =
66 pFontMgr->LoadFont(L"Arial Narrow", dwFontStyles, FX_CodePage::kFailure);
67 if (pFont)
68 return pFont;
69
70 return pFontMgr->LoadFont(nullptr, dwFontStyles, FX_CodePage::kFailure);
71}
static RetainPtr< CFGAS_GEFont > GetDefaultFont(uint32_t dwFontStyles)
static RetainPtr< CFGAS_GEFont > GetFont(WideString wsFontName, uint32_t dwFontStyles)
RetainPtr< CFGAS_GEFont > LoadFont(const wchar_t *pszFontFamily, uint32_t dwFontStyles, FX_CodePage wCodePage)
static CFGAS_GEModule * Get()
CFGAS_FontMgr * GetFontMgr()
static WideString FromASCII(ByteStringView str)
FX_CodePage
Definition fx_codepage.h:19
#define FXFONT_ITALIC
Definition fx_font.h:35
bool FontStyleIsItalic(uint32_t style)
Definition fx_font.h:64
#define FXFONT_FORCE_BOLD
Definition fx_font.h:38
bool FontStyleIsForceBold(uint32_t style)
Definition fx_font.h:61
fxcrt::ByteStringView ByteStringView
const char * pReplaceFont
fxcrt::WideString WideString
Definition widestring.h:207