7#include "xfa/fgas/font/cfgas_pdffontmgr.h"
14#include "core/fpdfapi/font/cpdf_font.h"
15#include "core/fpdfapi/page/cpdf_docpagedata.h"
16#include "core/fpdfapi/parser/cpdf_dictionary.h"
17#include "core/fpdfapi/parser/cpdf_document.h"
18#include "core/fpdfapi/parser/fpdf_parser_utility.h"
19#include "core/fxcrt/check.h"
20#include "core/fxcrt/stl_util.h"
21#include "core/fxge/fx_font.h"
22#include "xfa/fgas/font/cfgas_fontmgr.h"
23#include "xfa/fgas/font/cfgas_gefont.h"
28using FontNameEntry =
std::array<
const char*, 5>;
29constexpr auto kXFAPDFFontNameTable =
fxcrt::ToArray<
const FontNameEntry>({
30 {{
"Adobe PI Std",
"AdobePIStd",
"AdobePIStd",
"AdobePIStd",
"AdobePIStd"}},
31 {{
"Myriad Pro Light",
"MyriadPro-Light",
"MyriadPro-Semibold",
32 "MyriadPro-LightIt",
"MyriadPro-SemiboldIt"}},
38 for (
const auto& entry : kXFAPDFFontNameTable) {
39 if (strPsName == entry[0]) {
60 size_t iPsLen = bsPsName.GetLength();
61 auto nIndex = bsDRName.Find(bsPsName);
62 if (nIndex.has_value() && !bStrictMatch)
65 if (!nIndex.has_value() || nIndex.value() != 0)
68 size_t iDifferLength = bsDRName.GetLength() - iPsLen;
69 if (iDifferLength > 1 || (bBold || bItalic)) {
70 auto iBoldIndex = bsDRName.Find(
"Bold");
71 if (bBold != iBoldIndex.has_value())
74 if (iBoldIndex.has_value()) {
75 iDifferLength =
std::min(iDifferLength - 4,
76 bsDRName.GetLength() - iBoldIndex.value() - 4);
78 bool bItalicFont =
true;
79 if (bsDRName.Contains(
"Italic"))
81 else if (bsDRName.Contains(
"It"))
83 else if (bsDRName.Contains(
"Oblique"))
88 if (bItalic != bItalicFont)
91 if (iDifferLength > 1) {
92 ByteString bsDRTailer = bsDRName.Last(iDifferLength);
93 if (bsDRTailer
== "MT" || bsDRTailer
== "PSMT" ||
94 bsDRTailer
== "Regular" || bsDRTailer
== "Reg") {
97 if (iBoldIndex.has_value() || bItalicFont)
101 switch (bsPsName[iPsLen - 1]) {
103 if (bsDRName.Last(5) ==
"Light")
108 if (bsDRName.Last(7) ==
"Regular" || bsDRName.Last(3) ==
"Reg")
113 if (bsDRName.Last(5) ==
"Medium")
138 m_pDoc->GetRoot()->GetDictFor(
"AcroForm")->GetDictFor(
"DR");
143 pFontSetDict = pFontSetDict->GetDictFor(
"Font");
151 auto* pData = CPDF_DocPageData::FromDocument(m_pDoc);
153 for (
const auto& it : locker) {
154 const ByteString& key = it.first;
155 const RetainPtr<CPDF_Object>& pObj = it.second;
156 if (!PsNameMatchDRFontName(name.AsStringView(), bBold, bItalic, key,
160 RetainPtr<CPDF_Dictionary> pFontDict =
161 ToDictionary(pObj->GetMutableDirect());
162 if (!ValidateDictType(pFontDict.Get(),
"Font")) {
166 RetainPtr<CPDF_Font> pPDFFont = pData->GetFont(pFontDict);
167 if (!pPDFFont || !pPDFFont->IsEmbedded()) {
171 return CFGAS_GEFont::LoadFont(std::move(pPDFFont));
178 uint32_t dwFontStyles,
180 auto key =
std::make_pair(wsFontFamily, dwFontStyles);
181 auto it = m_FontMap.find(key);
182 if (it != m_FontMap.end()) {
189 ByteString strFontName = PsNameToFontName(bsPsName, bBold, bItalic);
191 FindFont(strFontName, bBold, bItalic, bStrictMatch);
196 m_FontMap[key] = pFont;
fxcrt::ByteString ByteString
RetainPtr< CFGAS_GEFont > GetFont(const WideString &wsFontFamily, uint32_t dwFontStyles, bool bStrictMatch)
CFGAS_PDFFontMgr(const CPDF_Document *pDoc)
std::map< ByteString, RetainPtr< CPDF_Object >, std::less<> > DictMap
bool operator==(const char *ptr) const
WideString(const WideString &other)=default
ByteString ToDefANSI() const
bool FontStyleIsItalic(uint32_t style)
bool FontStyleIsForceBold(uint32_t style)
fxcrt::ByteStringView ByteStringView
fxcrt::WideString WideString