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
cxfa_fontmgr.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 "xfa/fxfa/cxfa_fontmgr.h"
8
9#include "core/fpdfapi/parser/cpdf_dictionary.h"
10#include "core/fxge/cfx_fontmgr.h"
11#include "core/fxge/cfx_gemodule.h"
12#include "xfa/fgas/font/cfgas_defaultfontmanager.h"
13#include "xfa/fgas/font/cfgas_gefont.h"
14#include "xfa/fgas/font/fgas_fontutils.h"
15#include "xfa/fxfa/cxfa_ffapp.h"
16#include "xfa/fxfa/cxfa_ffdoc.h"
17
18CXFA_FontMgr::CXFA_FontMgr() = default;
19
20CXFA_FontMgr::~CXFA_FontMgr() = default;
21
22void CXFA_FontMgr::Trace(cppgc::Visitor* visitor) const {}
23
24RetainPtr<CFGAS_GEFont> CXFA_FontMgr::GetFont(CXFA_FFDoc* pDoc,
25 const WideString& wsFontFamily,
26 uint32_t dwFontStyles) {
27 auto key = std::make_pair(wsFontFamily, dwFontStyles);
28 auto iter = m_FontMap.find(key);
29 if (iter != m_FontMap.end())
30 return iter->second;
31
32 WideString wsEnglishName = FGAS_FontNameToEnglishName(wsFontFamily);
33 RetainPtr<CFGAS_GEFont> pFont =
34 pDoc->GetPDFFont(wsEnglishName, dwFontStyles, true);
35 if (pFont)
36 return pFont;
37
38 pFont = CFGAS_DefaultFontManager::GetFont(wsFontFamily, dwFontStyles);
39 if (!pFont) {
40 pFont = pDoc->GetPDFFont(wsEnglishName, dwFontStyles, false);
41 if (pFont)
42 return pFont;
43 }
44 if (!pFont) {
45 pFont = CFGAS_DefaultFontManager::GetDefaultFont(dwFontStyles);
46 }
47 if (!pFont) {
48 pFont = CFGAS_GEFont::LoadStockFont(
49 pDoc->GetPDFDoc(), ByteString::Format("%ls", wsFontFamily.c_str()));
50 }
51 if (!pFont)
52 return nullptr;
53
54 m_FontMap[key] = pFont;
55 return pFont;
56}
static RetainPtr< CFGAS_GEFont > GetDefaultFont(uint32_t dwFontStyles)
static RetainPtr< CFGAS_GEFont > GetFont(WideString wsFontName, uint32_t dwFontStyles)
static RetainPtr< CFGAS_GEFont > LoadStockFont(CPDF_Document *pDoc, const ByteString &font_family)
CPDF_Document * GetPDFDoc() const
Definition cxfa_ffdoc.h:169
RetainPtr< CFGAS_GEFont > GetPDFFont(const WideString &family, uint32_t styles, bool strict)
void Trace(cppgc::Visitor *visitor) const
RetainPtr< CFGAS_GEFont > GetFont(CXFA_FFDoc *hDoc, const WideString &wsFontFamily, uint32_t dwFontStyles)
static ByteString Format(const char *pFormat,...)
const wchar_t * c_str() const
Definition widestring.h:81
WideString FGAS_FontNameToEnglishName(const WideString &wsLocalName)