7#include "xfa/fgas/font/cfgas_pdffontmgr.h"
13#include "core/fpdfapi/font/cpdf_font.h"
14#include "core/fpdfapi/page/cpdf_docpagedata.h"
15#include "core/fpdfapi/parser/cpdf_dictionary.h"
16#include "core/fpdfapi/parser/cpdf_document.h"
17#include "core/fpdfapi/parser/fpdf_parser_utility.h"
18#include "core/fxge/fx_font.h"
19#include "third_party/base/check.h"
20#include "xfa/fgas/font/cfgas_fontmgr.h"
21#include "xfa/fgas/font/cfgas_gefont.h"
26const char*
const kXFAPDFFontName[][5] = {
27 {
"Adobe PI Std",
"AdobePIStd",
"AdobePIStd",
"AdobePIStd",
"AdobePIStd"},
28 {
"Myriad Pro Light",
"MyriadPro-Light",
"MyriadPro-Semibold",
29 "MyriadPro-LightIt",
"MyriadPro-SemiboldIt"},
40RetainPtr<CFGAS_GEFont> CFGAS_PDFFontMgr::FindFont(
const ByteString& strPsName,
44 RetainPtr<
const CPDF_Dictionary> pFontSetDict =
45 m_pDoc->GetRoot()->GetDictFor(
"AcroForm")->GetDictFor(
"DR");
49 pFontSetDict = pFontSetDict->GetDictFor(
"Font");
53 ByteString name = strPsName;
56 auto* pData = CPDF_DocPageData::FromDocument(m_pDoc);
58 for (
const auto& it : locker) {
59 const ByteString& key = it.first;
60 const RetainPtr<CPDF_Object>& pObj = it.second;
61 if (!PsNameMatchDRFontName(name.AsStringView(), bBold, bItalic, key,
65 RetainPtr<CPDF_Dictionary> pFontDict =
66 ToDictionary(pObj->GetMutableDirect());
67 if (!ValidateDictType(pFontDict.Get(),
"Font"))
70 RetainPtr<CPDF_Font> pPDFFont = pData->GetFont(pFontDict);
71 if (!pPDFFont || !pPDFFont->IsEmbedded())
74 return CFGAS_GEFont::LoadFont(std::move(pPDFFont));
80 const WideString& wsFontFamily,
81 uint32_t dwFontStyles,
83 auto key =
std::make_pair(wsFontFamily, dwFontStyles);
84 auto it = m_FontMap.find(key);
85 if (it != m_FontMap.end())
91 ByteString strFontName = PsNameToFontName(bsPsName, bBold, bItalic);
93 FindFont(strFontName, bBold, bItalic, bStrictMatch);
97 m_FontMap[key] = pFont;
101ByteString CFGAS_PDFFontMgr::PsNameToFontName(
const ByteString& strPsName,
104 for (size_t i = 0; i <
std::size(kXFAPDFFontName); ++i) {
105 if (strPsName == kXFAPDFFontName[i][0]) {
111 return kXFAPDFFontName[i][index];
117bool CFGAS_PDFFontMgr::PsNameMatchDRFontName(ByteStringView bsPsName,
120 const ByteString& bsDRFontName,
122 ByteString bsDRName = bsDRFontName;
123 bsDRName.Remove(
'-');
124 size_t iPsLen = bsPsName.GetLength();
125 auto nIndex = bsDRName.Find(bsPsName);
126 if (nIndex.has_value() && !bStrictMatch)
129 if (!nIndex.has_value() || nIndex.value() != 0)
132 size_t iDifferLength = bsDRName.GetLength() - iPsLen;
133 if (iDifferLength > 1 || (bBold || bItalic)) {
134 auto iBoldIndex = bsDRName.Find(
"Bold");
135 if (bBold != iBoldIndex.has_value())
138 if (iBoldIndex.has_value()) {
139 iDifferLength =
std::min(iDifferLength - 4,
140 bsDRName.GetLength() - iBoldIndex.value() - 4);
142 bool bItalicFont =
true;
143 if (bsDRName.Contains(
"Italic"))
145 else if (bsDRName.Contains(
"It"))
147 else if (bsDRName.Contains(
"Oblique"))
152 if (bItalic != bItalicFont)
155 if (iDifferLength > 1) {
156 ByteString bsDRTailer = bsDRName.Last(iDifferLength);
157 if (bsDRTailer
== "MT" || bsDRTailer
== "PSMT" ||
158 bsDRTailer
== "Regular" || bsDRTailer
== "Reg") {
161 if (iBoldIndex.has_value() || bItalicFont)
165 switch (bsPsName[iPsLen - 1]) {
167 if (bsDRName.Last(5) ==
"Light")
172 if (bsDRName.Last(7) ==
"Regular" || bsDRName.Last(3) ==
"Reg")
177 if (bsDRName.Last(5) ==
"Medium")
RetainPtr< CFGAS_GEFont > GetFont(const WideString &wsFontFamily, uint32_t dwFontStyles, bool bStrictMatch)
CFGAS_PDFFontMgr(const CPDF_Document *pDoc)
bool operator==(const char *ptr) const
WideString(const WideString &other)
ByteString ToDefANSI() const
bool FontStyleIsItalic(uint32_t style)
bool FontStyleIsForceBold(uint32_t style)