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/fx_codepage.h"
10#include "core/fxge/fx_font.h"
11#include "third_party/base/numerics/safe_conversions.h"
12#include "xfa/fgas/font/cfgas_fontmgr.h"
13#include "xfa/fgas/font/cfgas_gefont.h"
14#include "xfa/fgas/font/cfgas_gemodule.h"
15#include "xfa/fgas/font/fgas_fontutils.h"
16
17// static
19 WideString wsFontName,
20 uint32_t dwFontStyles) {
22 RetainPtr<CFGAS_GEFont> pFont = pFontMgr->LoadFont(
23 wsFontName.c_str(), dwFontStyles, FX_CodePage::kFailure);
24 if (pFont)
25 return pFont;
26
27 const FGAS_FontInfo* pCurFont =
28 FGAS_FontInfoByFontName(wsFontName.AsStringView());
29 if (!pCurFont || !pCurFont->pReplaceFont)
30 return pFont;
31
32 uint32_t dwStyle = 0;
33 // TODO(dsinclair): Why doesn't this check the other flags?
34 if (FontStyleIsForceBold(dwFontStyles))
35 dwStyle |= FXFONT_FORCE_BOLD;
36 if (FontStyleIsItalic(dwFontStyles))
37 dwStyle |= FXFONT_ITALIC;
38
39 const char* pReplace = pCurFont->pReplaceFont;
40 int32_t iLength = pdfium::base::checked_cast<int32_t>(strlen(pReplace));
41 while (iLength > 0) {
42 const char* pNameText = pReplace;
43 while (*pNameText != ',' && iLength > 0) {
44 pNameText++;
45 iLength--;
46 }
47 WideString wsReplace =
48 WideString::FromASCII(ByteStringView(pReplace, pNameText - pReplace));
49 pFont =
50 pFontMgr->LoadFont(wsReplace.c_str(), dwStyle, FX_CodePage::kFailure);
51 if (pFont)
52 break;
53
54 iLength--;
55 pNameText++;
56 pReplace = pNameText;
57 }
58 return pFont;
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()
const wchar_t * c_str() const
Definition widestring.h:81
static WideString FromASCII(ByteStringView str)
FX_CodePage
Definition fx_codepage.h:18
#define FXFONT_ITALIC
Definition fx_font.h:33
bool FontStyleIsItalic(uint32_t style)
Definition fx_font.h:62
#define FXFONT_FORCE_BOLD
Definition fx_font.h:36
bool FontStyleIsForceBold(uint32_t style)
Definition fx_font.h:59
const char * pReplaceFont