diff options
Diffstat (limited to 'xfa/fgas')
-rw-r--r-- | xfa/fgas/font/cfgas_gefont.cpp | 92 | ||||
-rw-r--r-- | xfa/fgas/font/cfgas_gefont.h | 33 | ||||
-rw-r--r-- | xfa/fgas/font/cfgas_pdffontmgr.cpp | 3 | ||||
-rw-r--r-- | xfa/fgas/font/cfgas_pdffontmgr.h | 3 | ||||
-rw-r--r-- | xfa/fgas/layout/cfx_break.cpp | 4 | ||||
-rw-r--r-- | xfa/fgas/layout/cfx_rtfbreak.cpp | 16 | ||||
-rw-r--r-- | xfa/fgas/layout/cfx_txtbreak.cpp | 22 |
7 files changed, 75 insertions, 98 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, diff --git a/xfa/fgas/layout/cfx_break.cpp b/xfa/fgas/layout/cfx_break.cpp index 5c5569ad44..6e1103cf65 100644 --- a/xfa/fgas/layout/cfx_break.cpp +++ b/xfa/fgas/layout/cfx_break.cpp @@ -112,7 +112,7 @@ void CFX_Break::FontChanged() { if (!m_pFont || m_wDefChar == 0xFEFF) return; - m_pFont->GetCharWidth(m_wDefChar, m_iDefChar, false); + m_pFont->GetCharWidth(m_wDefChar, m_iDefChar); m_iDefChar *= m_iFontSize; } @@ -129,7 +129,7 @@ void CFX_Break::SetDefaultChar(wchar_t wch) { if (m_wDefChar == 0xFEFF || !m_pFont) return; - m_pFont->GetCharWidth(m_wDefChar, m_iDefChar, false); + m_pFont->GetCharWidth(m_wDefChar, m_iDefChar); if (m_iDefChar < 0) m_iDefChar = 0; else diff --git a/xfa/fgas/layout/cfx_rtfbreak.cpp b/xfa/fgas/layout/cfx_rtfbreak.cpp index cf37030db0..0b556d89eb 100644 --- a/xfa/fgas/layout/cfx_rtfbreak.cpp +++ b/xfa/fgas/layout/cfx_rtfbreak.cpp @@ -121,7 +121,7 @@ CFX_BreakType CFX_RTFBreak::AppendChar(wchar_t wch) { void CFX_RTFBreak::AppendChar_Combination(CFX_Char* pCurChar) { int32_t iCharWidth = 0; - if (!m_pFont->GetCharWidth(pCurChar->char_code(), iCharWidth, false)) + if (!m_pFont->GetCharWidth(pCurChar->char_code(), iCharWidth)) iCharWidth = 0; iCharWidth *= m_iFontSize; @@ -190,8 +190,8 @@ CFX_BreakType CFX_RTFBreak::AppendChar_Arabic(CFX_Char* pCurChar) { wForm = pdfium::arabic::GetFormChar(pLastChar, pPrevChar, pCurChar); bAlef = (wForm == 0xFEFF && pLastChar->GetCharType() == FX_CHARTYPE_ArabicAlef); - if (!m_pFont->GetCharWidth(wForm, iCharWidth, false) && - !m_pFont->GetCharWidth(pLastChar->char_code(), iCharWidth, false)) { + if (!m_pFont->GetCharWidth(wForm, iCharWidth) && + !m_pFont->GetCharWidth(pLastChar->char_code(), iCharWidth)) { iCharWidth = m_iDefChar; } @@ -205,8 +205,8 @@ CFX_BreakType CFX_RTFBreak::AppendChar_Arabic(CFX_Char* pCurChar) { wForm = pdfium::arabic::GetFormChar(pCurChar, bAlef ? nullptr : pLastChar, nullptr); - if (!m_pFont->GetCharWidth(wForm, iCharWidth, false) && - !m_pFont->GetCharWidth(pCurChar->char_code(), iCharWidth, false)) { + if (!m_pFont->GetCharWidth(wForm, iCharWidth) && + !m_pFont->GetCharWidth(pCurChar->char_code(), iCharWidth)) { iCharWidth = m_iDefChar; } @@ -225,7 +225,7 @@ CFX_BreakType CFX_RTFBreak::AppendChar_Others(CFX_Char* pCurChar) { FX_CHARTYPE chartype = pCurChar->GetCharType(); wchar_t wForm = pCurChar->char_code(); int32_t iCharWidth = 0; - if (!m_pFont->GetCharWidth(wForm, iCharWidth, false)) + if (!m_pFont->GetCharWidth(wForm, iCharWidth)) iCharWidth = m_iDefChar; iCharWidth *= m_iFontSize; @@ -726,9 +726,9 @@ int32_t CFX_RTFBreak::GetDisplayPos(const FX_RTFTEXTOBJ* pText, if (bCharCode) { pCharPos->m_GlyphIndex = wch; } else { - pCharPos->m_GlyphIndex = pFont->GetGlyphIndex(wForm, false); + pCharPos->m_GlyphIndex = pFont->GetGlyphIndex(wForm); if (pCharPos->m_GlyphIndex == 0xFFFF) - pCharPos->m_GlyphIndex = pFont->GetGlyphIndex(wch, false); + pCharPos->m_GlyphIndex = pFont->GetGlyphIndex(wch); } #if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_ pCharPos->m_ExtGID = pCharPos->m_GlyphIndex; diff --git a/xfa/fgas/layout/cfx_txtbreak.cpp b/xfa/fgas/layout/cfx_txtbreak.cpp index a7683bc978..2d6e606e82 100644 --- a/xfa/fgas/layout/cfx_txtbreak.cpp +++ b/xfa/fgas/layout/cfx_txtbreak.cpp @@ -78,7 +78,7 @@ void CFX_TxtBreak::AppendChar_Combination(CFX_Char* pCurChar) { pCurChar->m_dwCharStyles |= FX_TXTCHARSTYLE_ArabicShadda; } } - if (!m_pFont->GetCharWidth(wForm, iCharWidth, false)) + if (!m_pFont->GetCharWidth(wForm, iCharWidth)) iCharWidth = 0; iCharWidth *= m_iFontSize; @@ -137,7 +137,7 @@ CFX_BreakType CFX_TxtBreak::AppendChar_Arabic(CFX_Char* pCurChar) { wForm = pdfium::arabic::GetFormChar(pLastChar, pPrevChar, pCurChar); bAlef = (wForm == 0xFEFF && pLastChar->GetCharType() == FX_CHARTYPE_ArabicAlef); - m_pFont->GetCharWidth(wForm, iCharWidth, false); + m_pFont->GetCharWidth(wForm, iCharWidth); if (wForm == 0xFEFF) iCharWidth = m_iDefChar; @@ -156,7 +156,7 @@ CFX_BreakType CFX_TxtBreak::AppendChar_Arabic(CFX_Char* pCurChar) { if (m_bCombText) { iCharWidth = m_iCombWidth; } else { - m_pFont->GetCharWidth(wForm, iCharWidth, false); + m_pFont->GetCharWidth(wForm, iCharWidth); if (wForm == 0xFEFF) iCharWidth = m_iDefChar; @@ -183,7 +183,7 @@ CFX_BreakType CFX_TxtBreak::AppendChar_Others(CFX_Char* pCurChar) { if (m_bCombText) { iCharWidth = m_iCombWidth; } else { - if (!m_pFont->GetCharWidth(wForm, iCharWidth, false)) + if (!m_pFont->GetCharWidth(wForm, iCharWidth)) iCharWidth = m_iDefChar; iCharWidth *= m_iFontSize; @@ -810,11 +810,11 @@ int32_t CFX_TxtBreak::GetDisplayPos(const FX_TXTRUN* pTxtRun, if (bLam) { formChars[1].wForm = 0x0651; iCharWidth = 0; - pFont->GetCharWidth(0x0651, iCharWidth, false); + pFont->GetCharWidth(0x0651, iCharWidth); formChars[1].iWidth = iCharWidth; formChars[2].wForm = 0x0670; iCharWidth = 0; - pFont->GetCharWidth(0x0670, iCharWidth, false); + pFont->GetCharWidth(0x0670, iCharWidth); formChars[2].iWidth = iCharWidth; } @@ -827,7 +827,7 @@ int32_t CFX_TxtBreak::GetDisplayPos(const FX_TXTRUN* pTxtRun, wLast = (wchar_t)formChars[j - 1].wForm; } if (!bEmptyChar || (bEmptyChar && !bSkipSpace)) { - pCharPos->m_GlyphIndex = pFont->GetGlyphIndex(wForm, false); + pCharPos->m_GlyphIndex = pFont->GetGlyphIndex(wForm); #if _FX_PLATFORM_ == _FX_PLATFORM_APPLE_ pCharPos->m_ExtGID = pCharPos->m_GlyphIndex; #endif @@ -843,14 +843,14 @@ int32_t CFX_TxtBreak::GetDisplayPos(const FX_TXTRUN* pTxtRun, if ((dwStyles & FX_LAYOUTSTYLE_CombText) != 0) { int32_t iFormWidth = iCharWidth; - pFont->GetCharWidth(wForm, iFormWidth, false); + pFont->GetCharWidth(wForm, iFormWidth); float fOffset = fFontSize * (iCharWidth - iFormWidth) / 2000.0f; pCharPos->m_Origin.x += fOffset; } if (chartype == FX_CHARTYPE_Combination) { CFX_Rect rtBBox; - if (pFont->GetCharBBox(wForm, &rtBBox, false)) { + if (pFont->GetCharBBox(wForm, &rtBBox)) { pCharPos->m_Origin.y = fYBase + fFontSize - fFontSize * (float)rtBBox.height / (float)iMaxHeight; @@ -860,7 +860,7 @@ int32_t CFX_TxtBreak::GetDisplayPos(const FX_TXTRUN* pTxtRun, if ((dwLastProps & FX_CHARTYPEBITSMASK) == FX_CHARTYPE_Combination) { CFX_Rect rtBox; - if (pFont->GetCharBBox(wLast, &rtBox, false)) + if (pFont->GetCharBBox(wLast, &rtBox)) pCharPos->m_Origin.y -= fFontSize * rtBox.height / iMaxHeight; } } @@ -957,7 +957,7 @@ std::vector<CFX_RectF> CFX_TxtBreak::GetCharRects(const FX_TXTRUN* pTxtRun, if (bCharBBox && !bRet) { int32_t iCharWidth = 1000; - pFont->GetCharWidth(wch, iCharWidth, false); + pFont->GetCharWidth(wch, iCharWidth); float fRTLeft = 0, fCharWidth = 0; if (iCharWidth > 0) { fCharWidth = iCharWidth * fScale; |