summaryrefslogtreecommitdiff
path: root/xfa/fgas/font
diff options
context:
space:
mode:
Diffstat (limited to 'xfa/fgas/font')
-rw-r--r--xfa/fgas/font/cfgas_gefont.cpp92
-rw-r--r--xfa/fgas/font/cfgas_gefont.h33
-rw-r--r--xfa/fgas/font/cfgas_pdffontmgr.cpp3
-rw-r--r--xfa/fgas/font/cfgas_pdffontmgr.h3
4 files changed, 54 insertions, 77 deletions
diff --git a/xfa/fgas/font/cfgas_gefont.cpp b/xfa/fgas/font/cfgas_gefont.cpp
index a107607655..58b1381a38 100644
--- a/xfa/fgas/font/cfgas_gefont.cpp
+++ b/xfa/fgas/font/cfgas_gefont.cpp
@@ -165,6 +165,7 @@ bool CFGAS_GEFont::InitFont() {
return !!m_pFontEncoding;
}
+#if _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
RetainPtr<CFGAS_GEFont> CFGAS_GEFont::Derive(uint32_t dwFontStyles,
uint16_t wCodePage) {
RetainPtr<CFGAS_GEFont> pFont(this);
@@ -172,6 +173,7 @@ RetainPtr<CFGAS_GEFont> CFGAS_GEFont::Derive(uint32_t dwFontStyles,
return pFont;
return pdfium::MakeRetain<CFGAS_GEFont>(pFont, dwFontStyles);
}
+#endif // _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
WideString CFGAS_GEFont::GetFamilyName() const {
if (!m_pFont->GetSubstFont() ||
@@ -205,16 +207,7 @@ uint32_t CFGAS_GEFont::GetFontStyles() const {
return dwStyles;
}
-bool CFGAS_GEFont::GetCharWidth(wchar_t wUnicode,
- int32_t& iWidth,
- bool bCharCode) {
- return GetCharWidthInternal(wUnicode, iWidth, true, bCharCode);
-}
-
-bool CFGAS_GEFont::GetCharWidthInternal(wchar_t wUnicode,
- int32_t& iWidth,
- bool bRecursive,
- bool bCharCode) {
+bool CFGAS_GEFont::GetCharWidth(wchar_t wUnicode, int32_t& iWidth) {
auto it = m_CharWidthMap.find(wUnicode);
iWidth = it != m_CharWidthMap.end() ? it->second : 0;
if (iWidth == 65535)
@@ -223,18 +216,17 @@ bool CFGAS_GEFont::GetCharWidthInternal(wchar_t wUnicode,
if (iWidth > 0)
return true;
- if (!m_pProvider ||
- !m_pProvider->GetCharWidth(RetainPtr<CFGAS_GEFont>(this), wUnicode,
- bCharCode, &iWidth)) {
+ if (!m_pProvider || !m_pProvider->GetCharWidth(RetainPtr<CFGAS_GEFont>(this),
+ wUnicode, &iWidth)) {
RetainPtr<CFGAS_GEFont> pFont;
- int32_t iGlyph = GetGlyphIndex(wUnicode, true, &pFont, bCharCode);
+ int32_t iGlyph;
+ std::tie(iGlyph, pFont) = GetGlyphIndexAndFont(wUnicode, true);
if (iGlyph != 0xFFFF && pFont) {
if (pFont.Get() == this) {
iWidth = m_pFont->GetGlyphWidth(iGlyph);
if (iWidth < 0)
iWidth = -1;
- } else if (pFont->GetCharWidthInternal(wUnicode, iWidth, false,
- bCharCode)) {
+ } else if (pFont->GetCharWidth(wUnicode, iWidth)) {
return true;
}
} else {
@@ -245,16 +237,7 @@ bool CFGAS_GEFont::GetCharWidthInternal(wchar_t wUnicode,
return iWidth > 0;
}
-bool CFGAS_GEFont::GetCharBBox(wchar_t wUnicode,
- CFX_Rect* bbox,
- bool bCharCode) {
- return GetCharBBoxInternal(wUnicode, bbox, true, bCharCode);
-}
-
-bool CFGAS_GEFont::GetCharBBoxInternal(wchar_t wUnicode,
- CFX_Rect* bbox,
- bool bRecursive,
- bool bCharCode) {
+bool CFGAS_GEFont::GetCharBBox(wchar_t wUnicode, CFX_Rect* bbox) {
auto it = m_BBoxMap.find(wUnicode);
if (it != m_BBoxMap.end()) {
*bbox = it->second;
@@ -262,12 +245,13 @@ bool CFGAS_GEFont::GetCharBBoxInternal(wchar_t wUnicode,
}
RetainPtr<CFGAS_GEFont> pFont;
- int32_t iGlyph = GetGlyphIndex(wUnicode, true, &pFont, bCharCode);
+ int32_t iGlyph;
+ std::tie(iGlyph, pFont) = GetGlyphIndexAndFont(wUnicode, true);
if (!pFont || iGlyph == 0xFFFF)
return false;
if (pFont.Get() != this)
- return pFont->GetCharBBoxInternal(wUnicode, bbox, false, bCharCode);
+ return pFont->GetCharBBox(wUnicode, bbox);
FX_RECT rtBBox;
if (!m_pFont->GetGlyphBBox(iGlyph, rtBBox))
@@ -291,44 +275,42 @@ bool CFGAS_GEFont::GetBBox(CFX_Rect* bbox) {
return true;
}
-int32_t CFGAS_GEFont::GetGlyphIndex(wchar_t wUnicode, bool bCharCode) {
- return GetGlyphIndex(wUnicode, true, nullptr, bCharCode);
+int32_t CFGAS_GEFont::GetGlyphIndex(wchar_t wUnicode) {
+ int32_t glyph;
+ RetainPtr<CFGAS_GEFont> font;
+ std::tie(glyph, font) = GetGlyphIndexAndFont(wUnicode, true);
+ return glyph;
}
-int32_t CFGAS_GEFont::GetGlyphIndex(wchar_t wUnicode,
- bool bRecursive,
- RetainPtr<CFGAS_GEFont>* ppFont,
- bool bCharCode) {
+std::pair<int32_t, RetainPtr<CFGAS_GEFont>> CFGAS_GEFont::GetGlyphIndexAndFont(
+ wchar_t wUnicode,
+ bool bRecursive) {
int32_t iGlyphIndex = m_pFontEncoding->GlyphFromCharCode(wUnicode);
- if (iGlyphIndex > 0) {
- if (ppFont)
- ppFont->Reset(this);
- return iGlyphIndex;
- }
+ if (iGlyphIndex > 0)
+ return {iGlyphIndex, RetainPtr<CFGAS_GEFont>(this)};
+
const FGAS_FONTUSB* pFontUSB = FGAS_GetUnicodeBitField(wUnicode);
if (!pFontUSB)
- return 0xFFFF;
+ return {0xFFFF, nullptr};
uint16_t wBitField = pFontUSB->wBitField;
if (wBitField >= 128)
- return 0xFFFF;
+ return {0xFFFF, nullptr};
auto it = m_FontMapper.find(wUnicode);
if (it != m_FontMapper.end() && it->second && it->second.Get() != this) {
- iGlyphIndex =
- it->second->GetGlyphIndex(wUnicode, false, nullptr, bCharCode);
+ RetainPtr<CFGAS_GEFont> font;
+ std::tie(iGlyphIndex, font) =
+ it->second->GetGlyphIndexAndFont(wUnicode, false);
if (iGlyphIndex != 0xFFFF) {
for (size_t i = 0; i < m_SubstFonts.size(); ++i) {
- if (m_SubstFonts[i] == it->second) {
- if (ppFont)
- *ppFont = it->second;
- return (iGlyphIndex | ((i + 1) << 24));
- }
+ if (m_SubstFonts[i] == it->second)
+ return {(iGlyphIndex | ((i + 1) << 24)), it->second};
}
}
}
if (!m_pFontMgr || !bRecursive)
- return 0xFFFF;
+ return {0xFFFF, nullptr};
WideString wsFamily = GetFamilyName();
RetainPtr<CFGAS_GEFont> pFont =
@@ -338,17 +320,17 @@ int32_t CFGAS_GEFont::GetGlyphIndex(wchar_t wUnicode,
pFont = m_pFontMgr->GetFontByUnicode(wUnicode, GetFontStyles(), nullptr);
#endif
if (!pFont || pFont.Get() == this) // Avoids direct cycles below.
- return 0xFFFF;
+ return {0xFFFF, nullptr};
m_FontMapper[wUnicode] = pFont;
m_SubstFonts.push_back(pFont);
- iGlyphIndex = pFont->GetGlyphIndex(wUnicode, false, nullptr, bCharCode);
+
+ RetainPtr<CFGAS_GEFont> font;
+ std::tie(iGlyphIndex, font) = pFont->GetGlyphIndexAndFont(wUnicode, false);
if (iGlyphIndex == 0xFFFF)
- return 0xFFFF;
+ return {0xFFFF, nullptr};
- if (ppFont)
- *ppFont = pFont;
- return (iGlyphIndex | (m_SubstFonts.size() << 24));
+ return {(iGlyphIndex | (m_SubstFonts.size() << 24)), pFont};
}
int32_t CFGAS_GEFont::GetAscent() const {
diff --git a/xfa/fgas/font/cfgas_gefont.h b/xfa/fgas/font/cfgas_gefont.h
index 9d990094fa..a1d6b82cb6 100644
--- a/xfa/fgas/font/cfgas_gefont.h
+++ b/xfa/fgas/font/cfgas_gefont.h
@@ -9,6 +9,7 @@
#include <map>
#include <memory>
+#include <utility>
#include <vector>
#include "core/fxcrt/fx_memory.h"
@@ -39,25 +40,30 @@ class CFGAS_GEFont : public Retainable {
std::unique_ptr<CFX_Font> pInternalFont,
CFGAS_FontMgr* pFontMgr);
- RetainPtr<CFGAS_GEFont> Derive(uint32_t dwFontStyles, uint16_t wCodePage = 0);
uint32_t GetFontStyles() const;
- bool GetCharWidth(wchar_t wUnicode, int32_t& iWidth, bool bCharCode);
- int32_t GetGlyphIndex(wchar_t wUnicode, bool bCharCode = false);
+ bool GetCharWidth(wchar_t wUnicode, int32_t& iWidth);
+ int32_t GetGlyphIndex(wchar_t wUnicode);
int32_t GetAscent() const;
int32_t GetDescent() const;
- bool GetCharBBox(wchar_t wUnicode, CFX_Rect* bbox, bool bCharCode = false);
+
+ bool GetCharBBox(wchar_t wUnicode, CFX_Rect* bbox);
bool GetBBox(CFX_Rect* bbox);
+
RetainPtr<CFGAS_GEFont> GetSubstFont(int32_t iGlyphIndex);
CFX_Font* GetDevFont() const { return m_pFont; }
+
void SetFontProvider(CFGAS_PDFFontMgr* pProvider) {
m_pProvider.Reset(pProvider);
}
-#if _FX_PLATFORM_ != _FX_PLATFORM_WINDOWS_
+
+#if _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
+ RetainPtr<CFGAS_GEFont> Derive(uint32_t dwFontStyles, uint16_t wCodePage);
+#else // _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
void SetLogicalFontStyle(uint32_t dwLogFontStyle) {
m_bUseLogFontStyle = true;
m_dwLogFontStyle = dwLogFontStyle;
}
-#endif
+#endif // _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
private:
explicit CFGAS_GEFont(CFGAS_FontMgr* pFontMgr);
@@ -75,18 +81,9 @@ class CFGAS_GEFont : public Retainable {
bool LoadFontInternal(CFX_Font* pExternalFont);
bool LoadFontInternal(std::unique_ptr<CFX_Font> pInternalFont);
bool InitFont();
- bool GetCharBBoxInternal(wchar_t wUnicode,
- CFX_Rect* bbox,
- bool bRecursive,
- bool bCharCode = false);
- bool GetCharWidthInternal(wchar_t wUnicode,
- int32_t& iWidth,
- bool bRecursive,
- bool bCharCode);
- int32_t GetGlyphIndex(wchar_t wUnicode,
- bool bRecursive,
- RetainPtr<CFGAS_GEFont>* ppFont,
- bool bCharCode = false);
+ std::pair<int32_t, RetainPtr<CFGAS_GEFont>> GetGlyphIndexAndFont(
+ wchar_t wUnicode,
+ bool bRecursive);
WideString GetFamilyName() const;
#if _FX_PLATFORM_ != _FX_PLATFORM_WINDOWS_
diff --git a/xfa/fgas/font/cfgas_pdffontmgr.cpp b/xfa/fgas/font/cfgas_pdffontmgr.cpp
index af183c2f99..a860d05a5a 100644
--- a/xfa/fgas/font/cfgas_pdffontmgr.cpp
+++ b/xfa/fgas/font/cfgas_pdffontmgr.cpp
@@ -186,9 +186,8 @@ bool CFGAS_PDFFontMgr::PsNameMatchDRFontName(const ByteStringView& bsPsName,
bool CFGAS_PDFFontMgr::GetCharWidth(const RetainPtr<CFGAS_GEFont>& pFont,
wchar_t wUnicode,
- bool bCharCode,
int32_t* pWidth) {
- if (wUnicode != 0x20 || bCharCode)
+ if (wUnicode != 0x20)
return false;
auto it = m_FDE2PDFFont.find(pFont);
diff --git a/xfa/fgas/font/cfgas_pdffontmgr.h b/xfa/fgas/font/cfgas_pdffontmgr.h
index 410aa009b0..a019990dad 100644
--- a/xfa/fgas/font/cfgas_pdffontmgr.h
+++ b/xfa/fgas/font/cfgas_pdffontmgr.h
@@ -25,15 +25,14 @@ class CFGAS_PDFFontMgr : public Observable<CFGAS_PDFFontMgr> {
explicit CFGAS_PDFFontMgr(CPDF_Document* pDoc, CFGAS_FontMgr* pFontMgr);
~CFGAS_PDFFontMgr();
+ void SetFont(const RetainPtr<CFGAS_GEFont>& pFont, CPDF_Font* pPDFFont);
RetainPtr<CFGAS_GEFont> GetFont(const WideStringView& wsFontFamily,
uint32_t dwFontStyles,
CPDF_Font** pPDFFont,
bool bStrictMatch);
bool GetCharWidth(const RetainPtr<CFGAS_GEFont>& pFont,
wchar_t wUnicode,
- bool bCharCode,
int32_t* pWidth);
- void SetFont(const RetainPtr<CFGAS_GEFont>& pFont, CPDF_Font* pPDFFont);
private:
RetainPtr<CFGAS_GEFont> FindFont(const ByteString& strFamilyName,