summaryrefslogtreecommitdiff
path: root/xfa
diff options
context:
space:
mode:
Diffstat (limited to 'xfa')
-rw-r--r--xfa/fgas/font/fgas_gefont.cpp77
-rw-r--r--xfa/fgas/font/fgas_gefont.h8
-rw-r--r--xfa/fgas/layout/fgas_rtfbreak.cpp159
-rw-r--r--xfa/fgas/layout/fgas_rtfbreak.h8
-rw-r--r--xfa/fgas/layout/fgas_textbreak.cpp10
-rw-r--r--xfa/fxfa/app/xfa_fontmgr.cpp225
-rw-r--r--xfa/fxfa/include/xfa_fontmgr.h39
7 files changed, 269 insertions, 257 deletions
diff --git a/xfa/fgas/font/fgas_gefont.cpp b/xfa/fgas/font/fgas_gefont.cpp
index 8233705342..c272f9160d 100644
--- a/xfa/fgas/font/fgas_gefont.cpp
+++ b/xfa/fgas/font/fgas_gefont.cpp
@@ -6,6 +6,9 @@
#include "xfa/fgas/font/fgas_gefont.h"
+#include <memory>
+#include <utility>
+
#include "core/fxge/include/cfx_substfont.h"
#include "core/fxge/include/cfx_unicodeencoding.h"
#include "core/fxge/include/cfx_unicodeencodingex.h"
@@ -19,9 +22,8 @@ CFGAS_GEFont* CFGAS_GEFont::LoadFont(const FX_WCHAR* pszFontFamily,
uint16_t wCodePage,
IFGAS_FontMgr* pFontMgr) {
#if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
- if (pFontMgr) {
+ if (pFontMgr)
return pFontMgr->GetFontByCodePage(wCodePage, dwFontStyles, pszFontFamily);
- }
return nullptr;
#else
CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr);
@@ -284,69 +286,72 @@ void CFGAS_GEFont::GetFamilyName(CFX_WideString& wsFamily) const {
uint32_t CFGAS_GEFont::GetFontStyles() const {
ASSERT(m_pFont);
#if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
- if (m_bUseLogFontStyle) {
+ if (m_bUseLogFontStyle)
return m_dwLogFontStyle;
- }
#endif
+
uint32_t dwStyles = 0;
- if (!m_pFont->GetSubstFont()) {
- if (m_pFont->IsBold()) {
+ auto* pSubstFont = m_pFont->GetSubstFont();
+ if (pSubstFont) {
+ if (pSubstFont->m_Weight == FXFONT_FW_BOLD)
dwStyles |= FX_FONTSTYLE_Bold;
- }
- if (m_pFont->IsItalic()) {
+ if (pSubstFont->m_SubstFlags & FXFONT_SUBST_ITALIC)
dwStyles |= FX_FONTSTYLE_Italic;
- }
} else {
- if (m_pFont->GetSubstFont()->m_Weight == FXFONT_FW_BOLD) {
+ if (m_pFont->IsBold())
dwStyles |= FX_FONTSTYLE_Bold;
- }
- if (m_pFont->GetSubstFont()->m_SubstFlags & FXFONT_SUBST_ITALIC) {
+ if (m_pFont->IsItalic())
dwStyles |= FX_FONTSTYLE_Italic;
- }
}
return dwStyles;
}
+
FX_BOOL CFGAS_GEFont::GetCharWidth(FX_WCHAR wUnicode,
int32_t& iWidth,
- FX_BOOL bCharCode) {
- return GetCharWidthInternal(wUnicode, iWidth, TRUE, bCharCode);
+ bool bCharCode) {
+ return GetCharWidthInternal(wUnicode, iWidth, true, bCharCode);
}
+
FX_BOOL CFGAS_GEFont::GetCharWidthInternal(FX_WCHAR wUnicode,
int32_t& iWidth,
- FX_BOOL bRecursive,
- FX_BOOL bCharCode) {
+ bool bRecursive,
+ bool bCharCode) {
ASSERT(m_pCharWidthMap);
iWidth = m_pCharWidthMap->GetAt(wUnicode, 0);
- if (iWidth < 1) {
- if (!m_pProvider ||
- !m_pProvider->GetCharWidth(this, wUnicode, iWidth, bCharCode)) {
- CFGAS_GEFont* pFont = nullptr;
- int32_t iGlyph = GetGlyphIndex(wUnicode, TRUE, &pFont, bCharCode);
- if (iGlyph != 0xFFFF && pFont) {
- if (pFont == this) {
- iWidth = m_pFont->GetGlyphWidth(iGlyph);
- if (iWidth < 0) {
- iWidth = -1;
- }
- } else if (pFont->GetCharWidthInternal(wUnicode, iWidth, FALSE,
- bCharCode)) {
- return TRUE;
+ if (iWidth == 65535)
+ return FALSE;
+
+ if (iWidth > 0)
+ return TRUE;
+
+ if (!m_pProvider ||
+ !m_pProvider->GetCharWidth(this, wUnicode, bCharCode, &iWidth)) {
+ CFGAS_GEFont* pFont = nullptr;
+ int32_t iGlyph = GetGlyphIndex(wUnicode, TRUE, &pFont, bCharCode);
+ if (iGlyph != 0xFFFF && pFont) {
+ if (pFont == this) {
+ iWidth = m_pFont->GetGlyphWidth(iGlyph);
+ if (iWidth < 0) {
+ iWidth = -1;
}
- } else {
- iWidth = -1;
+ } else if (pFont->GetCharWidthInternal(wUnicode, iWidth, false,
+ bCharCode)) {
+ return TRUE;
}
+ } else {
+ iWidth = -1;
}
- m_pCharWidthMap->SetAtGrow(wUnicode, (int16_t)iWidth);
- } else if (iWidth == 65535) {
- iWidth = -1;
}
+ m_pCharWidthMap->SetAtGrow(wUnicode, iWidth);
return iWidth > 0;
}
+
FX_BOOL CFGAS_GEFont::GetCharBBox(FX_WCHAR wUnicode,
CFX_Rect& bbox,
FX_BOOL bCharCode) {
return GetCharBBoxInternal(wUnicode, bbox, TRUE, bCharCode);
}
+
FX_BOOL CFGAS_GEFont::GetCharBBoxInternal(FX_WCHAR wUnicode,
CFX_Rect& bbox,
FX_BOOL bRecursive,
diff --git a/xfa/fgas/font/fgas_gefont.h b/xfa/fgas/font/fgas_gefont.h
index 824f931d76..7f3cc60478 100644
--- a/xfa/fgas/font/fgas_gefont.h
+++ b/xfa/fgas/font/fgas_gefont.h
@@ -44,9 +44,7 @@ class CFGAS_GEFont {
CFGAS_GEFont* Derive(uint32_t dwFontStyles, uint16_t wCodePage = 0);
void GetFamilyName(CFX_WideString& wsFamily) const;
uint32_t GetFontStyles() const;
- FX_BOOL GetCharWidth(FX_WCHAR wUnicode,
- int32_t& iWidth,
- FX_BOOL bCharCode = FALSE);
+ FX_BOOL GetCharWidth(FX_WCHAR wUnicode, int32_t& iWidth, bool bCharCode);
int32_t GetGlyphIndex(FX_WCHAR wUnicode, FX_BOOL bCharCode = FALSE);
int32_t GetAscent() const;
int32_t GetDescent() const;
@@ -86,8 +84,8 @@ class CFGAS_GEFont {
FX_BOOL bCharCode = FALSE);
FX_BOOL GetCharWidthInternal(FX_WCHAR wUnicode,
int32_t& iWidth,
- FX_BOOL bRecursive,
- FX_BOOL bCharCode = FALSE);
+ bool bRecursive,
+ bool bCharCode);
int32_t GetGlyphIndex(FX_WCHAR wUnicode,
FX_BOOL bRecursive,
CFGAS_GEFont** ppFont,
diff --git a/xfa/fgas/layout/fgas_rtfbreak.cpp b/xfa/fgas/layout/fgas_rtfbreak.cpp
index bfe3ca674f..21ed0665b9 100644
--- a/xfa/fgas/layout/fgas_rtfbreak.cpp
+++ b/xfa/fgas/layout/fgas_rtfbreak.cpp
@@ -19,10 +19,10 @@ CFX_RTFBreak::CFX_RTFBreak(uint32_t dwPolicies)
m_iBoundaryStart(0),
m_iBoundaryEnd(2000000),
m_dwLayoutStyles(0),
- m_bPagination(FALSE),
- m_bVertical(FALSE),
- m_bSingleLine(FALSE),
- m_bCharCode(FALSE),
+ m_bPagination(false),
+ m_bVertical(false),
+ m_bSingleLine(false),
+ m_bCharCode(false),
m_pFont(nullptr),
m_iFontHeight(240),
m_iFontSize(240),
@@ -52,31 +52,35 @@ CFX_RTFBreak::CFX_RTFBreak(uint32_t dwPolicies)
m_iTolerance(0) {
m_pCurLine = &m_RTFLine1;
}
+
CFX_RTFBreak::~CFX_RTFBreak() {
Reset();
m_PositionedTabs.RemoveAll();
- if (m_pUserData) {
+ if (m_pUserData)
m_pUserData->Release();
- }
}
+
void CFX_RTFBreak::SetLineBoundary(FX_FLOAT fLineStart, FX_FLOAT fLineEnd) {
if (fLineStart > fLineEnd)
return;
+
m_iBoundaryStart = FXSYS_round(fLineStart * 20000.0f);
m_iBoundaryEnd = FXSYS_round(fLineEnd * 20000.0f);
m_pCurLine->m_iStart = std::min(m_pCurLine->m_iStart, m_iBoundaryEnd);
m_pCurLine->m_iStart = std::max(m_pCurLine->m_iStart, m_iBoundaryStart);
}
+
void CFX_RTFBreak::SetLineStartPos(FX_FLOAT fLinePos) {
int32_t iLinePos = FXSYS_round(fLinePos * 20000.0f);
iLinePos = std::min(iLinePos, m_iBoundaryEnd);
iLinePos = std::max(iLinePos, m_iBoundaryStart);
m_pCurLine->m_iStart = iLinePos;
}
+
void CFX_RTFBreak::SetLayoutStyles(uint32_t dwLayoutStyles) {
- if (m_dwLayoutStyles == dwLayoutStyles) {
+ if (m_dwLayoutStyles == dwLayoutStyles)
return;
- }
+
SetBreakStatus();
m_dwLayoutStyles = dwLayoutStyles;
m_bPagination = (m_dwLayoutStyles & FX_RTFLAYOUTSTYLE_Pagination) != 0;
@@ -87,6 +91,7 @@ void CFX_RTFBreak::SetLayoutStyles(uint32_t dwLayoutStyles) {
m_iRotation = m_iLineRotation + m_iCharRotation;
m_iRotation %= 4;
}
+
void CFX_RTFBreak::SetFont(CFGAS_GEFont* pFont) {
if (!pFont) {
return;
@@ -340,9 +345,9 @@ static const FX_RTFBreak_LPFAppendChar g_FX_RTFBreak_lpfAppendChar[16] = {
};
uint32_t CFX_RTFBreak::AppendChar(FX_WCHAR wch) {
ASSERT(m_pFont && m_pCurLine);
- if (m_bCharCode) {
+ if (m_bCharCode)
return AppendChar_CharCode(wch);
- }
+
uint32_t dwProps = kTextLayoutCodeProperties[(uint16_t)wch];
FX_CHARTYPE chartype = GetCharTypeFromProp(dwProps);
CFX_RTFCharArray& tca = m_pCurLine->m_LineChars;
@@ -388,6 +393,7 @@ uint32_t CFX_RTFBreak::AppendChar(FX_WCHAR wch) {
m_eCharType = chartype;
return std::max(dwRet1, dwRet2);
}
+
uint32_t CFX_RTFBreak::AppendChar_CharCode(FX_WCHAR wch) {
ASSERT(m_pFont && m_pCurLine);
ASSERT(m_bCharCode);
@@ -406,9 +412,9 @@ uint32_t CFX_RTFBreak::AppendChar_CharCode(FX_WCHAR wch) {
pCurChar->m_nRotation = m_iCharRotation;
pCurChar->m_iCharWidth = 0;
pCurChar->m_dwIdentity = m_dwIdentity;
- if (m_pUserData) {
+ if (m_pUserData)
m_pUserData->Retain();
- }
+
pCurChar->m_pUserData = m_pUserData;
int32_t iCharWidth = 0;
if (m_bVertical != FX_IsOdd(m_iRotation)) {
@@ -430,6 +436,7 @@ uint32_t CFX_RTFBreak::AppendChar_CharCode(FX_WCHAR wch) {
}
return FX_RTFBREAK_None;
}
+
uint32_t CFX_RTFBreak::AppendChar_Combination(CFX_RTFChar* pCurChar,
int32_t iRotation) {
int32_t iCharWidth = 0;
@@ -504,6 +511,7 @@ uint32_t CFX_RTFBreak::AppendChar_Control(CFX_RTFChar* pCurChar,
}
return dwRet2;
}
+
uint32_t CFX_RTFBreak::AppendChar_Arabic(CFX_RTFChar* pCurChar,
int32_t iRotation) {
CFX_RTFChar* pLastChar = nullptr;
@@ -562,16 +570,16 @@ uint32_t CFX_RTFBreak::AppendChar_Arabic(CFX_RTFChar* pCurChar,
}
return FX_RTFBREAK_None;
}
+
uint32_t CFX_RTFBreak::AppendChar_Others(CFX_RTFChar* pCurChar,
int32_t iRotation) {
FX_CHARTYPE chartype = pCurChar->GetCharType();
FX_WCHAR wForm;
if (chartype == FX_CHARTYPE_Numeric) {
- if (m_dwLayoutStyles & FX_RTFLAYOUTSTYLE_ArabicNumber) {
+ if (m_dwLayoutStyles & FX_RTFLAYOUTSTYLE_ArabicNumber)
wForm = pCurChar->m_wCharCode + 0x0630;
- } else {
+ else
wForm = pCurChar->m_wCharCode;
- }
} else if (m_bRTL || m_bVertical) {
wForm = FX_GetMirrorChar(pCurChar->m_wCharCode, pCurChar->m_dwCharProps,
m_bRTL, m_bVertical);
@@ -579,29 +587,29 @@ uint32_t CFX_RTFBreak::AppendChar_Others(CFX_RTFChar* pCurChar,
wForm = pCurChar->m_wCharCode;
}
int32_t iCharWidth = 0;
- if (m_bVertical != FX_IsOdd(iRotation)) {
- iCharWidth = 1000;
- } else {
- if (!m_pFont->GetCharWidth(wForm, iCharWidth, m_bCharCode)) {
+ if (m_bVertical == FX_IsOdd(iRotation)) {
+ if (!m_pFont->GetCharWidth(wForm, iCharWidth, m_bCharCode))
iCharWidth = m_iDefChar;
- }
+ } else {
+ iCharWidth = 1000;
}
iCharWidth *= m_iFontSize;
- iCharWidth = iCharWidth * m_iHorizontalScale / 100;
+ iCharWidth *= m_iHorizontalScale / 100;
iCharWidth += m_iCharSpace;
- if (chartype == FX_CHARTYPE_Space && m_bWordSpace) {
+ if (chartype == FX_CHARTYPE_Space && m_bWordSpace)
iCharWidth += m_iWordSpace;
- }
+
pCurChar->m_iCharWidth = iCharWidth;
m_pCurLine->m_iWidth += iCharWidth;
- FX_BOOL bBreak = (chartype != FX_CHARTYPE_Space ||
- (m_dwPolicies & FX_RTFBREAKPOLICY_SpaceBreak) != 0);
+ bool bBreak = (chartype != FX_CHARTYPE_Space ||
+ (m_dwPolicies & FX_RTFBREAKPOLICY_SpaceBreak) != 0);
if (!m_bSingleLine && !m_bOrphanLine && bBreak &&
m_pCurLine->GetLineEnd() > m_iBoundaryEnd + m_iTolerance) {
return EndBreak(FX_RTFBREAK_LineBreak);
}
return FX_RTFBREAK_None;
}
+
uint32_t CFX_RTFBreak::EndBreak(uint32_t dwStatus) {
ASSERT(dwStatus >= FX_RTFBREAK_PieceBreak &&
dwStatus <= FX_RTFBREAK_PageBreak);
@@ -610,59 +618,56 @@ uint32_t CFX_RTFBreak::EndBreak(uint32_t dwStatus) {
int32_t iCount = pCurPieces->GetSize();
if (iCount > 0) {
CFX_RTFPiece* pLastPiece = pCurPieces->GetPtrAt(--iCount);
- if (dwStatus > FX_RTFBREAK_PieceBreak) {
+ if (dwStatus > FX_RTFBREAK_PieceBreak)
pLastPiece->m_dwStatus = dwStatus;
- } else {
+ else
dwStatus = pLastPiece->m_dwStatus;
- }
return dwStatus;
- } else {
- CFX_RTFLine* pLastLine = GetRTFLine(TRUE);
- if (pLastLine) {
- pCurPieces = &pLastLine->m_LinePieces;
- iCount = pCurPieces->GetSize();
- if (iCount-- > 0) {
- CFX_RTFPiece* pLastPiece = pCurPieces->GetPtrAt(iCount);
- if (dwStatus > FX_RTFBREAK_PieceBreak) {
- pLastPiece->m_dwStatus = dwStatus;
- } else {
- dwStatus = pLastPiece->m_dwStatus;
- }
- return dwStatus;
- }
- return FX_RTFBREAK_None;
- }
- iCount = m_pCurLine->CountChars();
- if (iCount < 1) {
- return FX_RTFBREAK_None;
- }
- CFX_RTFChar& tc = m_pCurLine->GetChar(iCount - 1);
- tc.m_dwStatus = dwStatus;
- if (dwStatus <= FX_RTFBREAK_PieceBreak) {
+ }
+
+ CFX_RTFLine* pLastLine = GetRTFLine(TRUE);
+ if (pLastLine) {
+ pCurPieces = &pLastLine->m_LinePieces;
+ iCount = pCurPieces->GetSize();
+ if (iCount-- > 0) {
+ CFX_RTFPiece* pLastPiece = pCurPieces->GetPtrAt(iCount);
+ if (dwStatus > FX_RTFBREAK_PieceBreak)
+ pLastPiece->m_dwStatus = dwStatus;
+ else
+ dwStatus = pLastPiece->m_dwStatus;
return dwStatus;
}
+ return FX_RTFBREAK_None;
}
+ iCount = m_pCurLine->CountChars();
+ if (iCount < 1)
+ return FX_RTFBREAK_None;
+
+ CFX_RTFChar& tc = m_pCurLine->GetChar(iCount - 1);
+ tc.m_dwStatus = dwStatus;
+ if (dwStatus <= FX_RTFBREAK_PieceBreak)
+ return dwStatus;
+
m_iReady = (m_pCurLine == &m_RTFLine1) ? 1 : 2;
CFX_RTFLine* pNextLine =
(m_pCurLine == &m_RTFLine1) ? &m_RTFLine2 : &m_RTFLine1;
FX_BOOL bAllChars = (m_iAlignment > FX_RTFLINEALIGNMENT_Right);
CFX_TPOArray tpos(100);
- if (EndBreak_SplitLine(pNextLine, bAllChars, dwStatus)) {
- goto EndBreak_Ret;
- }
- if (!m_bCharCode) {
- EndBreak_BidiLine(tpos, dwStatus);
- }
- if (!m_bPagination && m_iAlignment > FX_RTFLINEALIGNMENT_Left) {
- EndBreak_Alignment(tpos, bAllChars, dwStatus);
+ if (!EndBreak_SplitLine(pNextLine, bAllChars, dwStatus)) {
+ if (!m_bCharCode)
+ EndBreak_BidiLine(tpos, dwStatus);
+
+ if (!m_bPagination && m_iAlignment > FX_RTFLINEALIGNMENT_Left)
+ EndBreak_Alignment(tpos, bAllChars, dwStatus);
}
-EndBreak_Ret:
+
m_pCurLine = pNextLine;
m_pCurLine->m_iStart = m_iBoundaryStart;
CFX_RTFChar* pTC = GetLastChar(0);
m_eCharType = pTC ? pTC->GetCharType() : FX_CHARTYPE_Unknown;
return dwStatus;
}
+
FX_BOOL CFX_RTFBreak::EndBreak_SplitLine(CFX_RTFLine* pNextLine,
FX_BOOL bAllChars,
uint32_t dwStatus) {
@@ -928,20 +933,21 @@ void CFX_RTFBreak::EndBreak_Alignment(CFX_TPOArray& tpos,
}
}
}
+
int32_t CFX_RTFBreak::GetBreakPos(CFX_RTFCharArray& tca,
int32_t& iEndPos,
FX_BOOL bAllChars,
FX_BOOL bOnlyBrk) {
int32_t iLength = tca.GetSize() - 1;
- if (iLength < 1) {
+ if (iLength < 1)
return iLength;
- }
+
int32_t iBreak = -1, iBreakPos = -1, iIndirect = -1, iIndirectPos = -1,
iLast = -1, iLastPos = -1;
if (m_bSingleLine || m_bOrphanLine || iEndPos <= m_iBoundaryEnd) {
- if (!bAllChars || m_bCharCode) {
+ if (!bAllChars || m_bCharCode)
return iLength;
- }
+
iBreak = iLength;
iBreakPos = iEndPos;
}
@@ -950,14 +956,13 @@ int32_t CFX_RTFBreak::GetBreakPos(CFX_RTFCharArray& tca,
const CFX_RTFChar* pChar;
int32_t iCharWidth;
while (iLength > 0) {
- if (iEndPos <= m_iBoundaryEnd) {
+ if (iEndPos <= m_iBoundaryEnd)
break;
- }
+
pChar = pCharArray + iLength--;
iCharWidth = pChar->m_iCharWidth;
- if (iCharWidth > 0) {
+ if (iCharWidth > 0)
iEndPos -= iCharWidth;
- }
}
return iLength;
}
@@ -1040,9 +1045,9 @@ int32_t CFX_RTFBreak::GetBreakPos(CFX_RTFCharArray& tca,
nNext = nCodeProp & 0x003F;
iLength--;
}
- if (bOnlyBrk) {
+ if (bOnlyBrk)
return 0;
- }
+
if (iBreak > -1) {
iEndPos = iBreakPos;
return iBreak;
@@ -1057,6 +1062,7 @@ int32_t CFX_RTFBreak::GetBreakPos(CFX_RTFCharArray& tca,
}
return 0;
}
+
void CFX_RTFBreak::SplitTextLine(CFX_RTFLine* pCurLine,
CFX_RTFLine* pNextLine,
FX_BOOL bAllChars) {
@@ -1105,20 +1111,23 @@ void CFX_RTFBreak::SplitTextLine(CFX_RTFLine* pCurLine,
tc->m_dwStatus = 0;
}
}
+
int32_t CFX_RTFBreak::CountBreakPieces() const {
CFX_RTFPieceArray* pRTFPieces = GetRTFPieces(TRUE);
return pRTFPieces ? pRTFPieces->GetSize() : 0;
}
+
const CFX_RTFPiece* CFX_RTFBreak::GetBreakPiece(int32_t index) const {
CFX_RTFPieceArray* pRTFPieces = GetRTFPieces(TRUE);
- if (!pRTFPieces) {
+ if (!pRTFPieces)
return nullptr;
- }
- if (index < 0 || index >= pRTFPieces->GetSize()) {
+
+ if (index < 0 || index >= pRTFPieces->GetSize())
return nullptr;
- }
+
return pRTFPieces->GetPtrAt(index);
}
+
void CFX_RTFBreak::GetLineRect(CFX_RectF& rect) const {
rect.top = 0;
CFX_RTFLine* pRTFLine = GetRTFLine(TRUE);
@@ -1480,7 +1489,7 @@ int32_t CFX_RTFBreak::GetCharRects(const FX_RTFTEXTOBJ* pText,
}
if (bCharBBox && !bRet) {
int32_t iCharWidth = 1000;
- pFont->GetCharWidth(wch, iCharWidth);
+ pFont->GetCharWidth(wch, iCharWidth, false);
FX_FLOAT fRTLeft = 0, fCharWidth = 0;
if (iCharWidth > 0) {
fCharWidth = iCharWidth * fScale;
diff --git a/xfa/fgas/layout/fgas_rtfbreak.h b/xfa/fgas/layout/fgas_rtfbreak.h
index 9d01809045..35b790f39b 100644
--- a/xfa/fgas/layout/fgas_rtfbreak.h
+++ b/xfa/fgas/layout/fgas_rtfbreak.h
@@ -288,10 +288,10 @@ class CFX_RTFBreak {
int32_t m_iBoundaryStart;
int32_t m_iBoundaryEnd;
uint32_t m_dwLayoutStyles;
- FX_BOOL m_bPagination;
- FX_BOOL m_bVertical;
- FX_BOOL m_bSingleLine;
- FX_BOOL m_bCharCode;
+ bool m_bPagination;
+ bool m_bVertical;
+ bool m_bSingleLine;
+ bool m_bCharCode;
CFGAS_GEFont* m_pFont;
int32_t m_iFontHeight;
int32_t m_iFontSize;
diff --git a/xfa/fgas/layout/fgas_textbreak.cpp b/xfa/fgas/layout/fgas_textbreak.cpp
index 5ee399fead..e10ef01336 100644
--- a/xfa/fgas/layout/fgas_textbreak.cpp
+++ b/xfa/fgas/layout/fgas_textbreak.cpp
@@ -643,13 +643,15 @@ void CFX_TxtBreak::EndBreak_UpdateArabicShapes() {
return;
}
int32_t& iLineWidth = m_pCurLine->m_iWidth;
- CFX_Char *pCur, *pNext;
- pCur = m_pCurLine->GetCharPtr(0);
+ CFX_Char* pCur = m_pCurLine->GetCharPtr(0);
FX_BOOL bPrevNum = (pCur->m_dwCharStyles & FX_TXTCHARSTYLE_ArabicIndic) != 0;
pCur = m_pCurLine->GetCharPtr(1);
FX_WCHAR wch, wForm;
FX_BOOL bNextNum;
- int32_t i = 1, iCharWidth, iRotation;
+ int32_t i = 1;
+ int32_t iCharWidth;
+ int32_t iRotation;
+ CFX_Char* pNext;
do {
i++;
if (i < iCount) {
@@ -1669,7 +1671,7 @@ int32_t CFX_TxtBreak::GetCharRects(const FX_TXTRUN* pTxtRun,
}
if (bCharBBox && !bRet) {
int32_t iCharWidth = 1000;
- pFont->GetCharWidth(wch, iCharWidth);
+ pFont->GetCharWidth(wch, iCharWidth, false);
FX_FLOAT fRTLeft = 0, fCharWidth = 0;
if (iCharWidth > 0) {
fCharWidth = iCharWidth * fScale;
diff --git a/xfa/fxfa/app/xfa_fontmgr.cpp b/xfa/fxfa/app/xfa_fontmgr.cpp
index 3a478038f6..be5081d857 100644
--- a/xfa/fxfa/app/xfa_fontmgr.cpp
+++ b/xfa/fxfa/app/xfa_fontmgr.cpp
@@ -7,6 +7,7 @@
#include "xfa/fxfa/include/xfa_fontmgr.h"
#include <algorithm>
+#include <memory>
#include <utility>
#include "core/fpdfapi/fpdf_font/include/cpdf_font.h"
@@ -16,8 +17,17 @@
#include "xfa/fxfa/include/xfa_ffapp.h"
#include "xfa/fxfa/include/xfa_ffdoc.h"
+namespace {
+
+// The 5 names per entry are: PsName, Normal, Bold, Italic, BoldItalic.
+const char* const g_XFAPDFFontName[][5] = {
+ {"Adobe PI Std", "AdobePIStd", "AdobePIStd", "AdobePIStd", "AdobePIStd"},
+ {"Myriad Pro Light", "MyriadPro-Light", "MyriadPro-Semibold",
+ "MyriadPro-LightIt", "MyriadPro-SemiboldIt"},
+};
+
#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
-static const XFA_FONTINFO g_XFAFontsMap[] = {
+const XFA_FONTINFO g_XFAFontsMap[] = {
{0x01d5d33e, L"SimSun", L"Arial", 0, 936},
{0x01e4f102, L"YouYuan", L"Arial", 1, 936},
{0x030549dc, L"LiSu", L"Arial", 1, 936},
@@ -265,7 +275,7 @@ static const XFA_FONTINFO g_XFAFontsMap[] = {
{0xfef135f8, L"AdobeHeitiStd-Regular", L"Batang,Century,Dotum", 0, 936},
};
#elif _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_
-static const XFA_FONTINFO g_XFAFontsMap[] = {
+const XFA_FONTINFO g_XFAFontsMap[] = {
{0x01d5d33e, L"SimSun",
L"WenQuanYi Zen Hei Mono,AR PL UMing CN,AR PL UMing HK,AR PL UMing TW,AR "
L"PL UMing TW MBE",
@@ -854,7 +864,7 @@ static const XFA_FONTINFO g_XFAFontsMap[] = {
0, 936},
};
#elif _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
-static const XFA_FONTINFO g_XFAFontsMap[] = {
+const XFA_FONTINFO g_XFAFontsMap[] = {
{0x01d5d33e, L"SimSun", L"STHeiti,Heiti TC,STFangsong", 0, 936},
{0x01e4f102, L"YouYuan", L"STHeiti,Heiti TC,STFangsong", 1, 936},
{0x030549dc, L"LiSu", L"STHeiti,Heiti TC,STFangsong", 1, 936},
@@ -1255,7 +1265,7 @@ static const XFA_FONTINFO g_XFAFontsMap[] = {
{0xfef135f8, L"AdobeHeitiStd-Regular", L"Heiti TC,STHeiti", 0, 936},
};
#elif _FXM_PLATFORM_ == _FXM_PLATFORM_ANDROID_
-static const XFA_FONTINFO g_XFAFontsMap[] = {
+const XFA_FONTINFO g_XFAFontsMap[] = {
{0x01d5d33e, L"SimSun", L"Droid Sans Fallback", 0, 936},
{0x01e4f102, L"YouYuan", L"Droid Sans Fallback", 1, 936},
{0x030549dc, L"LiSu", L"Droid Sans Fallback", 1, 936},
@@ -1693,51 +1703,40 @@ static const XFA_FONTINFO g_XFAFontsMap[] = {
{0xfef135f8, L"AdobeHeitiStd-Regular", L"Droid Sans Fallback", 0, 936},
};
#endif
-void XFA_LocalFontNameToEnglishName(const CFX_WideStringC& wsLocalName,
- CFX_WideString& wsEnglishName) {
- wsEnglishName = wsLocalName;
+
+CFX_WideString XFA_LocalFontNameToEnglishName(
+ const CFX_WideStringC& wsLocalName) {
uint32_t dwLocalNameHash = FX_HashCode_GetW(wsLocalName, true);
- int32_t iStart = 0;
- int32_t iEnd = sizeof(g_XFAFontsMap) / sizeof(XFA_FONTINFO) - 1;
- int32_t iMid = 0;
- do {
- iMid = (iStart + iEnd) / 2;
- uint32_t dwFontNameHash = g_XFAFontsMap[iMid].dwFontNameHash;
- if (dwFontNameHash == dwLocalNameHash) {
- wsEnglishName = g_XFAFontsMap[iMid].pPsName;
- break;
- } else if (dwFontNameHash < dwLocalNameHash) {
- iStart = iMid + 1;
- } else {
- iEnd = iMid - 1;
- }
- } while (iEnd >= iStart);
+ const XFA_FONTINFO* pEnd = g_XFAFontsMap + FX_ArraySize(g_XFAFontsMap);
+ const XFA_FONTINFO* pFontInfo =
+ std::lower_bound(g_XFAFontsMap, pEnd, dwLocalNameHash,
+ [](const XFA_FONTINFO& entry, uint32_t hash) {
+ return entry.dwFontNameHash < hash;
+ });
+ if (pFontInfo < pEnd && pFontInfo->dwFontNameHash == dwLocalNameHash)
+ return pFontInfo->pPsName;
+ return CFX_WideString(wsLocalName);
}
+
const XFA_FONTINFO* XFA_GetFontINFOByFontName(
const CFX_WideStringC& wsFontName) {
CFX_WideString wsFontNameTemp(wsFontName);
wsFontNameTemp.Remove(L' ');
uint32_t dwCurFontNameHash =
FX_HashCode_GetW(wsFontNameTemp.AsStringC(), true);
- int32_t iStart = 0;
- int32_t iEnd = sizeof(g_XFAFontsMap) / sizeof(XFA_FONTINFO) - 1;
- int32_t iMid = 0;
- const XFA_FONTINFO* pFontInfo = nullptr;
- do {
- iMid = (iStart + iEnd) / 2;
- uint32_t dwFontNameHash = g_XFAFontsMap[iMid].dwFontNameHash;
- if (dwFontNameHash == dwCurFontNameHash) {
- pFontInfo = &g_XFAFontsMap[iMid];
- break;
- } else if (dwFontNameHash < dwCurFontNameHash) {
- iStart = iMid + 1;
- } else {
- iEnd = iMid - 1;
- }
- } while (iEnd >= iStart);
- return pFontInfo;
+ const XFA_FONTINFO* pEnd = g_XFAFontsMap + FX_ArraySize(g_XFAFontsMap);
+ const XFA_FONTINFO* pFontInfo =
+ std::lower_bound(g_XFAFontsMap, pEnd, dwCurFontNameHash,
+ [](const XFA_FONTINFO& entry, uint32_t hash) {
+ return entry.dwFontNameHash < hash;
+ });
+ if (pFontInfo < pEnd && pFontInfo->dwFontNameHash == dwCurFontNameHash)
+ return pFontInfo;
+ return nullptr;
}
+} // namespace
+
CXFA_DefFontMgr::CXFA_DefFontMgr() {}
CXFA_DefFontMgr::~CXFA_DefFontMgr() {
@@ -1798,8 +1797,8 @@ CFGAS_GEFont* CXFA_DefFontMgr::GetDefaultFont(
CFGAS_GEFont* pFont =
pFDEFontMgr->LoadFont(L"Arial Narrow", dwFontStyles, wCodePage);
if (!pFont) {
- pFont = pFDEFontMgr->LoadFont((const FX_WCHAR*)nullptr, dwFontStyles,
- wCodePage);
+ pFont = pFDEFontMgr->LoadFont(static_cast<const FX_WCHAR*>(nullptr),
+ dwFontStyles, wCodePage);
}
ASSERT(pFont);
@@ -1807,32 +1806,21 @@ CFGAS_GEFont* CXFA_DefFontMgr::GetDefaultFont(
m_CacheFonts.Add(pFont);
return pFont;
}
-struct XFA_PDFFONTNAME {
- const FX_CHAR* lpPsName;
- const FX_CHAR* lpNormal;
- const FX_CHAR* lpBold;
- const FX_CHAR* lpItalic;
- const FX_CHAR* lpBoldItalic;
-};
-const XFA_PDFFONTNAME g_XFAPDFFontName[] = {
- {"Adobe PI Std", "AdobePIStd", "AdobePIStd", "AdobePIStd", "AdobePIStd"},
- {"Myriad Pro Light", "MyriadPro-Light", "MyriadPro-Semibold",
- "MyriadPro-LightIt", "MyriadPro-SemiboldIt"},
-};
-CXFA_PDFFontMgr::CXFA_PDFFontMgr(CXFA_FFDoc* pDoc) {
- m_pDoc = pDoc;
-}
+
+CXFA_PDFFontMgr::CXFA_PDFFontMgr(CXFA_FFDoc* pDoc) : m_pDoc(pDoc) {}
+
CXFA_PDFFontMgr::~CXFA_PDFFontMgr() {
for (const auto& pair : m_FontMap) {
if (pair.second)
pair.second->Release();
}
}
-CFGAS_GEFont* CXFA_PDFFontMgr::FindFont(CFX_ByteString strPsName,
- FX_BOOL bBold,
- FX_BOOL bItalic,
+
+CFGAS_GEFont* CXFA_PDFFontMgr::FindFont(const CFX_ByteString& strPsName,
+ bool bBold,
+ bool bItalic,
CPDF_Font** pDstPDFFont,
- FX_BOOL bStrictMatch) {
+ bool bStrictMatch) {
CPDF_Document* pDoc = m_pDoc->GetPDFDoc();
if (!pDoc) {
return nullptr;
@@ -1846,12 +1834,13 @@ CFGAS_GEFont* CXFA_PDFFontMgr::FindFont(CFX_ByteString strPsName,
if (!pFontSetDict) {
return nullptr;
}
- strPsName.Remove(' ');
+ CFX_ByteString name = strPsName;
+ name.Remove(' ');
IFGAS_FontMgr* pFDEFontMgr = m_pDoc->GetApp()->GetFDEFontMgr();
for (const auto& it : *pFontSetDict) {
const CFX_ByteString& key = it.first;
CPDF_Object* pObj = it.second;
- if (!PsNameMatchDRFontName(strPsName.AsStringC(), bBold, bItalic, key,
+ if (!PsNameMatchDRFontName(name.AsStringC(), bBold, bItalic, key,
bStrictMatch)) {
continue;
}
@@ -1875,7 +1864,7 @@ CFGAS_GEFont* CXFA_PDFFontMgr::FindFont(CFX_ByteString strPsName,
CFGAS_GEFont* CXFA_PDFFontMgr::GetFont(const CFX_WideStringC& wsFontFamily,
uint32_t dwFontStyles,
CPDF_Font** pPDFFont,
- FX_BOOL bStrictMatch) {
+ bool bStrictMatch) {
uint32_t dwHashCode = FX_HashCode_GetW(wsFontFamily, false);
CFX_ByteString strKey;
strKey.Format("%u%u", dwHashCode, dwFontStyles);
@@ -1884,8 +1873,8 @@ CFGAS_GEFont* CXFA_PDFFontMgr::GetFont(const CFX_WideStringC& wsFontFamily,
return it->second;
CFX_ByteString bsPsName =
CFX_ByteString::FromUnicode(CFX_WideString(wsFontFamily));
- FX_BOOL bBold = (dwFontStyles & FX_FONTSTYLE_Bold) == FX_FONTSTYLE_Bold;
- FX_BOOL bItalic = (dwFontStyles & FX_FONTSTYLE_Italic) == FX_FONTSTYLE_Italic;
+ bool bBold = (dwFontStyles & FX_FONTSTYLE_Bold) == FX_FONTSTYLE_Bold;
+ bool bItalic = (dwFontStyles & FX_FONTSTYLE_Italic) == FX_FONTSTYLE_Italic;
CFX_ByteString strFontName = PsNameToFontName(bsPsName, bBold, bItalic);
CFGAS_GEFont* pFont =
FindFont(strFontName, bBold, bItalic, pPDFFont, bStrictMatch);
@@ -1896,46 +1885,48 @@ CFGAS_GEFont* CXFA_PDFFontMgr::GetFont(const CFX_WideStringC& wsFontFamily,
CFX_ByteString CXFA_PDFFontMgr::PsNameToFontName(
const CFX_ByteString& strPsName,
- FX_BOOL bBold,
- FX_BOOL bItalic) {
- int32_t nCount = sizeof(g_XFAPDFFontName) / sizeof(XFA_PDFFONTNAME);
- for (int32_t i = 0; i < nCount; i++) {
- if (strPsName == g_XFAPDFFontName[i].lpPsName) {
- int32_t index = 1 + ((bItalic << 1) | bBold);
- return *(&g_XFAPDFFontName[i].lpPsName + index);
+ bool bBold,
+ bool bItalic) {
+ for (size_t i = 0; i < FX_ArraySize(g_XFAPDFFontName); ++i) {
+ if (strPsName == g_XFAPDFFontName[i][0]) {
+ size_t index = 1;
+ if (bBold)
+ ++index;
+ if (bItalic)
+ index += 2;
+ return g_XFAPDFFontName[i][index];
}
}
return strPsName;
}
-FX_BOOL CXFA_PDFFontMgr::PsNameMatchDRFontName(
- const CFX_ByteStringC& bsPsName,
- FX_BOOL bBold,
- FX_BOOL bItalic,
- const CFX_ByteString& bsDRFontName,
- FX_BOOL bStrictMatch) {
+bool CXFA_PDFFontMgr::PsNameMatchDRFontName(const CFX_ByteStringC& bsPsName,
+ bool bBold,
+ bool bItalic,
+ const CFX_ByteString& bsDRFontName,
+ bool bStrictMatch) {
CFX_ByteString bsDRName = bsDRFontName;
bsDRName.Remove('-');
int32_t iPsLen = bsPsName.GetLength();
int32_t nIndex = bsDRName.Find(bsPsName);
- if (nIndex != -1 && !bStrictMatch) {
- return TRUE;
- }
- if (nIndex != 0) {
- return FALSE;
- }
+ if (nIndex != -1 && !bStrictMatch)
+ return true;
+
+ if (nIndex != 0)
+ return false;
+
int32_t iDifferLength = bsDRName.GetLength() - iPsLen;
if (iDifferLength > 1 || (bBold || bItalic)) {
int32_t iBoldIndex = bsDRName.Find("Bold");
- FX_BOOL bBoldFont = iBoldIndex > 0;
- if (bBold ^ bBoldFont) {
- return FALSE;
- }
+ bool bBoldFont = iBoldIndex > 0;
+ if (bBold != bBoldFont)
+ return false;
+
if (bBoldFont) {
iDifferLength =
std::min(iDifferLength - 4, bsDRName.GetLength() - iBoldIndex - 4);
}
- FX_BOOL bItalicFont = TRUE;
+ bool bItalicFont = true;
if (bsDRName.Find("Italic") > 0) {
iDifferLength -= 6;
} else if (bsDRName.Find("It") > 0) {
@@ -1943,35 +1934,35 @@ FX_BOOL CXFA_PDFFontMgr::PsNameMatchDRFontName(
} else if (bsDRName.Find("Oblique") > 0) {
iDifferLength -= 7;
} else {
- bItalicFont = FALSE;
- }
- if (bItalic ^ bItalicFont) {
- return FALSE;
+ bItalicFont = false;
}
+ if (bItalic != bItalicFont)
+ return false;
+
if (iDifferLength > 1) {
CFX_ByteString bsDRTailer = bsDRName.Right(iDifferLength);
if (bsDRTailer == "MT" || bsDRTailer == "PSMT" ||
bsDRTailer == "Regular" || bsDRTailer == "Reg") {
- return TRUE;
+ return true;
}
- if (bBoldFont || bItalicFont) {
- return FALSE;
- }
- FX_BOOL bMatch = FALSE;
+ if (bBoldFont || bItalicFont)
+ return false;
+
+ bool bMatch = false;
switch (bsPsName.GetAt(iPsLen - 1)) {
case 'L': {
if (bsDRName.Right(5) == "Light") {
- bMatch = TRUE;
+ bMatch = true;
}
} break;
case 'R': {
if (bsDRName.Right(7) == "Regular" || bsDRName.Right(3) == "Reg") {
- bMatch = TRUE;
+ bMatch = true;
}
} break;
case 'M': {
if (bsDRName.Right(5) == "Medium") {
- bMatch = TRUE;
+ bMatch = true;
}
} break;
default:
@@ -1980,22 +1971,27 @@ FX_BOOL CXFA_PDFFontMgr::PsNameMatchDRFontName(
return bMatch;
}
}
- return TRUE;
+ return true;
}
-FX_BOOL CXFA_PDFFontMgr::GetCharWidth(CFGAS_GEFont* pFont,
- FX_WCHAR wUnicode,
- int32_t& iWidth,
- FX_BOOL bCharCode) {
+
+bool CXFA_PDFFontMgr::GetCharWidth(const CFGAS_GEFont* pFont,
+ FX_WCHAR wUnicode,
+ bool bCharCode,
+ int32_t* pWidth) {
if (wUnicode != 0x20 || bCharCode)
- return FALSE;
+ return false;
auto it = m_FDE2PDFFont.find(pFont);
if (it == m_FDE2PDFFont.end())
- return FALSE;
+ return false;
CPDF_Font* pPDFFont = it->second;
- iWidth = pPDFFont->GetCharWidthF(pPDFFont->CharCodeFromUnicode(wUnicode));
- return TRUE;
+ *pWidth = pPDFFont->GetCharWidthF(pPDFFont->CharCodeFromUnicode(wUnicode));
+ return true;
+}
+
+void CXFA_PDFFontMgr::SetFont(const CFGAS_GEFont* pFont, CPDF_Font* pPDFFont) {
+ m_FDE2PDFFont[pFont] = pPDFFont;
}
CXFA_FontMgr::CXFA_FontMgr() {}
@@ -2012,15 +2008,16 @@ CFGAS_GEFont* CXFA_FontMgr::GetFont(CXFA_FFDoc* hDoc,
auto iter = m_FontMap.find(bsKey);
if (iter != m_FontMap.end())
return iter->second;
- CFX_WideString wsEnglishName;
- XFA_LocalFontNameToEnglishName(wsFontFamily, wsEnglishName);
+
+ CFX_WideString wsEnglishName = XFA_LocalFontNameToEnglishName(wsFontFamily);
auto it = m_PDFFontMgrMap.find(hDoc);
CXFA_PDFFontMgr* pMgr =
it != m_PDFFontMgrMap.end() ? it->second.get() : nullptr;
CPDF_Font* pPDFFont = nullptr;
CFGAS_GEFont* pFont = nullptr;
if (pMgr) {
- pFont = pMgr->GetFont(wsEnglishName.AsStringC(), dwFontStyles, &pPDFFont);
+ pFont =
+ pMgr->GetFont(wsEnglishName.AsStringC(), dwFontStyles, &pPDFFont, TRUE);
if (pFont)
return pFont;
}
@@ -2040,7 +2037,7 @@ CFGAS_GEFont* CXFA_FontMgr::GetFont(CXFA_FFDoc* hDoc,
}
if (pFont) {
if (pPDFFont) {
- pMgr->m_FDE2PDFFont[pFont] = pPDFFont;
+ pMgr->SetFont(pFont, pPDFFont);
pFont->SetFontProvider(pMgr);
}
m_FontMap[bsKey] = pFont;
diff --git a/xfa/fxfa/include/xfa_fontmgr.h b/xfa/fxfa/include/xfa_fontmgr.h
index 2d2a74f2ba..6147dbc5c7 100644
--- a/xfa/fxfa/include/xfa_fontmgr.h
+++ b/xfa/fxfa/include/xfa_fontmgr.h
@@ -51,29 +51,30 @@ class CXFA_PDFFontMgr {
CFGAS_GEFont* GetFont(const CFX_WideStringC& wsFontFamily,
uint32_t dwFontStyles,
CPDF_Font** pPDFFont,
- FX_BOOL bStrictMatch = TRUE);
- FX_BOOL GetCharWidth(CFGAS_GEFont* pFont,
- FX_WCHAR wUnicode,
- int32_t& iWidth,
- FX_BOOL bCharCode);
- std::map<CFGAS_GEFont*, CPDF_Font*> m_FDE2PDFFont;
+ bool bStrictMatch);
+ bool GetCharWidth(const CFGAS_GEFont* pFont,
+ FX_WCHAR wUnicode,
+ bool bCharCode,
+ int32_t* pWidth);
+ void SetFont(const CFGAS_GEFont* pFont, CPDF_Font* pPDFFont);
protected:
- CFGAS_GEFont* FindFont(CFX_ByteString strFamilyName,
- FX_BOOL bBold,
- FX_BOOL bItalic,
+ CFGAS_GEFont* FindFont(const CFX_ByteString& strFamilyName,
+ bool bBold,
+ bool bItalic,
CPDF_Font** pPDFFont,
- FX_BOOL bStrictMatch = TRUE);
+ bool bStrictMatch);
CFX_ByteString PsNameToFontName(const CFX_ByteString& strPsName,
- FX_BOOL bBold,
- FX_BOOL bItalic);
- FX_BOOL PsNameMatchDRFontName(const CFX_ByteStringC& bsPsName,
- FX_BOOL bBold,
- FX_BOOL bItalic,
- const CFX_ByteString& bsDRFontName,
- FX_BOOL bStrictMatch = TRUE);
-
- CXFA_FFDoc* m_pDoc;
+ bool bBold,
+ bool bItalic);
+ bool PsNameMatchDRFontName(const CFX_ByteStringC& bsPsName,
+ bool bBold,
+ bool bItalic,
+ const CFX_ByteString& bsDRFontName,
+ bool bStrictMatch);
+
+ CXFA_FFDoc* const m_pDoc;
+ std::map<const CFGAS_GEFont*, CPDF_Font*> m_FDE2PDFFont;
std::map<CFX_ByteString, CFGAS_GEFont*> m_FontMap;
};