summaryrefslogtreecommitdiff
path: root/xfa/fgas/layout
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-03-01 09:31:51 -0500
committerChromium commit bot <commit-bot@chromium.org>2017-03-01 15:33:07 +0000
commit17f31183d59ee5371c1fafdb4a72390e863320ae (patch)
treef9db49f036a6b31a654c013301598cd560f6e397 /xfa/fgas/layout
parente3409535a6ecad8006d872df680ae7eda8120c1c (diff)
downloadpdfium-17f31183d59ee5371c1fafdb4a72390e863320ae.tar.xz
Fixup RTFBreak and TextBreak nits
Change-Id: Ied5d23e18e9194e66d8be8d1057f55d83faada88 Reviewed-on: https://pdfium-review.googlesource.com/2880 Reviewed-by: Nicolás Peña <npm@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fgas/layout')
-rw-r--r--xfa/fgas/layout/fgas_rtfbreak.cpp611
-rw-r--r--xfa/fgas/layout/fgas_rtfbreak.h25
-rw-r--r--xfa/fgas/layout/fgas_textbreak.cpp536
-rw-r--r--xfa/fgas/layout/fgas_textbreak.h1
4 files changed, 579 insertions, 594 deletions
diff --git a/xfa/fgas/layout/fgas_rtfbreak.cpp b/xfa/fgas/layout/fgas_rtfbreak.cpp
index a3bf58c27b..e2cfaaaec3 100644
--- a/xfa/fgas/layout/fgas_rtfbreak.cpp
+++ b/xfa/fgas/layout/fgas_rtfbreak.cpp
@@ -15,6 +15,23 @@
#include "xfa/fgas/layout/fgas_linebreak.h"
#include "xfa/fgas/layout/fgas_unicode.h"
+namespace {
+
+typedef CFX_RTFBreakType (CFX_RTFBreak::*FX_RTFBreak_LPFAppendChar)(
+ CFX_RTFChar* pCurChar);
+const FX_RTFBreak_LPFAppendChar g_FX_RTFBreak_lpfAppendChar[16] = {
+ &CFX_RTFBreak::AppendChar_Others, &CFX_RTFBreak::AppendChar_Tab,
+ &CFX_RTFBreak::AppendChar_Others, &CFX_RTFBreak::AppendChar_Control,
+ &CFX_RTFBreak::AppendChar_Combination, &CFX_RTFBreak::AppendChar_Others,
+ &CFX_RTFBreak::AppendChar_Others, &CFX_RTFBreak::AppendChar_Arabic,
+ &CFX_RTFBreak::AppendChar_Arabic, &CFX_RTFBreak::AppendChar_Arabic,
+ &CFX_RTFBreak::AppendChar_Arabic, &CFX_RTFBreak::AppendChar_Arabic,
+ &CFX_RTFBreak::AppendChar_Arabic, &CFX_RTFBreak::AppendChar_Others,
+ &CFX_RTFBreak::AppendChar_Others, &CFX_RTFBreak::AppendChar_Others,
+};
+
+} // namespace
+
CFX_RTFBreak::CFX_RTFBreak(uint32_t dwLayoutStyles)
: m_iBoundaryStart(0),
m_iBoundaryEnd(2000000),
@@ -74,31 +91,30 @@ void CFX_RTFBreak::SetFont(const CFX_RetainPtr<CFGAS_GEFont>& pFont) {
SetBreakStatus();
m_pFont = pFont;
- m_iDefChar = 0;
- if (m_pFont) {
- m_iFontHeight = m_iFontSize;
- if (m_wDefChar != 0xFEFF) {
- m_pFont->GetCharWidth(m_wDefChar, m_iDefChar, false);
- m_iDefChar *= m_iFontSize;
- }
- }
+ FontChanged();
}
void CFX_RTFBreak::SetFontSize(FX_FLOAT fFontSize) {
int32_t iFontSize = FXSYS_round(fFontSize * 20.0f);
- if (m_iFontSize == iFontSize) {
+ if (m_iFontSize == iFontSize)
return;
- }
+
SetBreakStatus();
m_iFontSize = iFontSize;
+ FontChanged();
+}
+
+void CFX_RTFBreak::FontChanged() {
m_iDefChar = 0;
- if (m_pFont) {
- m_iFontHeight = m_iFontSize;
- if (m_wDefChar != 0xFEFF) {
- m_pFont->GetCharWidth(m_wDefChar, m_iDefChar, false);
- m_iDefChar *= m_iFontSize;
- }
- }
+ if (!m_pFont)
+ return;
+
+ m_iFontHeight = m_iFontSize;
+ if (m_wDefChar == 0xFEFF)
+ return;
+
+ m_pFont->GetCharWidth(m_wDefChar, m_iDefChar, false);
+ m_iDefChar *= m_iFontSize;
}
void CFX_RTFBreak::SetTabWidth(FX_FLOAT fTabWidth) {
@@ -172,32 +188,31 @@ void CFX_RTFBreak::SetBreakStatus() {
CFX_RTFChar* CFX_RTFBreak::GetLastChar(int32_t index) const {
std::vector<CFX_RTFChar>& tca = m_pCurLine->m_LineChars;
int32_t iCount = pdfium::CollectionSize<int32_t>(tca);
- if (index < 0 || index >= iCount) {
+ if (index < 0 || index >= iCount)
return nullptr;
- }
+
int32_t iStart = iCount - 1;
while (iStart > -1) {
CFX_RTFChar* pTC = &tca[iStart--];
if (pTC->m_iCharWidth >= 0 ||
pTC->GetCharType() != FX_CHARTYPE_Combination) {
- if (--index < 0) {
+ if (--index < 0)
return pTC;
- }
}
}
return nullptr;
}
-CFX_RTFLine* CFX_RTFBreak::GetRTFLine() const {
+const CFX_RTFLine* CFX_RTFBreak::GetRTFLine() const {
if (m_iReady == 1)
- return (CFX_RTFLine*)&m_RTFLine1;
+ return &m_RTFLine1;
if (m_iReady == 2)
- return (CFX_RTFLine*)&m_RTFLine2;
+ return &m_RTFLine2;
return nullptr;
}
-CFX_RTFPieceArray* CFX_RTFBreak::GetRTFPieces() const {
- CFX_RTFLine* pRTFLine = GetRTFLine();
+const CFX_RTFPieceArray* CFX_RTFBreak::GetRTFPieces() const {
+ const CFX_RTFLine* pRTFLine = GetRTFLine();
return pRTFLine ? &pRTFLine->m_LinePieces : nullptr;
}
@@ -205,40 +220,29 @@ inline FX_CHARTYPE CFX_RTFBreak::GetUnifiedCharType(
FX_CHARTYPE chartype) const {
return chartype >= FX_CHARTYPE_ArabicAlef ? FX_CHARTYPE_Arabic : chartype;
}
+
int32_t CFX_RTFBreak::GetLastPositionedTab() const {
int32_t iCount = m_PositionedTabs.GetSize();
- if (iCount < 1) {
+ if (iCount < 1)
return m_iBoundaryStart;
- }
return m_PositionedTabs[iCount - 1];
}
-bool CFX_RTFBreak::GetPositionedTab(int32_t& iTabPos) const {
+
+bool CFX_RTFBreak::GetPositionedTab(int32_t* iTabPos) const {
int32_t iCount = m_PositionedTabs.GetSize();
for (int32_t i = 0; i < iCount; i++) {
- if (m_PositionedTabs[i] > iTabPos) {
- iTabPos = m_PositionedTabs[i];
+ if (m_PositionedTabs[i] > *iTabPos) {
+ *iTabPos = m_PositionedTabs[i];
return true;
}
}
return false;
}
-typedef CFX_RTFBreakType (CFX_RTFBreak::*FX_RTFBreak_LPFAppendChar)(
- CFX_RTFChar* pCurChar);
-static const FX_RTFBreak_LPFAppendChar g_FX_RTFBreak_lpfAppendChar[16] = {
- &CFX_RTFBreak::AppendChar_Others, &CFX_RTFBreak::AppendChar_Tab,
- &CFX_RTFBreak::AppendChar_Others, &CFX_RTFBreak::AppendChar_Control,
- &CFX_RTFBreak::AppendChar_Combination, &CFX_RTFBreak::AppendChar_Others,
- &CFX_RTFBreak::AppendChar_Others, &CFX_RTFBreak::AppendChar_Arabic,
- &CFX_RTFBreak::AppendChar_Arabic, &CFX_RTFBreak::AppendChar_Arabic,
- &CFX_RTFBreak::AppendChar_Arabic, &CFX_RTFBreak::AppendChar_Arabic,
- &CFX_RTFBreak::AppendChar_Arabic, &CFX_RTFBreak::AppendChar_Others,
- &CFX_RTFBreak::AppendChar_Others, &CFX_RTFBreak::AppendChar_Others,
-};
CFX_RTFBreakType CFX_RTFBreak::AppendChar(FX_WCHAR wch) {
ASSERT(m_pFont && m_pCurLine);
- uint32_t dwProps = kTextLayoutCodeProperties[(uint16_t)wch];
+ uint32_t dwProps = kTextLayoutCodeProperties[static_cast<uint16_t>(wch)];
FX_CHARTYPE chartype = GetCharTypeFromProp(dwProps);
m_pCurLine->m_LineChars.emplace_back();
@@ -253,20 +257,19 @@ CFX_RTFBreakType CFX_RTFBreak::AppendChar(FX_WCHAR wch) {
pCurChar->m_iCharWidth = 0;
pCurChar->m_dwIdentity = m_dwIdentity;
pCurChar->m_pUserData = m_pUserData;
+
CFX_RTFBreakType dwRet1 = CFX_RTFBreakType::None;
if (chartype != FX_CHARTYPE_Combination &&
- GetUnifiedCharType(m_eCharType) != GetUnifiedCharType(chartype)) {
- if (m_eCharType != FX_CHARTYPE_Unknown &&
- m_pCurLine->GetLineEnd() > m_iBoundaryEnd + m_iTolerance) {
- if (m_eCharType != FX_CHARTYPE_Space || chartype != FX_CHARTYPE_Control) {
- dwRet1 = EndBreak(CFX_RTFBreakType::Line);
- int32_t iCount = m_pCurLine->CountChars();
- if (iCount > 0) {
- pCurChar = &m_pCurLine->m_LineChars[iCount - 1];
- }
- }
- }
+ GetUnifiedCharType(m_eCharType) != GetUnifiedCharType(chartype) &&
+ m_eCharType != FX_CHARTYPE_Unknown &&
+ m_pCurLine->GetLineEnd() > m_iBoundaryEnd + m_iTolerance &&
+ (m_eCharType != FX_CHARTYPE_Space || chartype != FX_CHARTYPE_Control)) {
+ dwRet1 = EndBreak(CFX_RTFBreakType::Line);
+ int32_t iCount = m_pCurLine->CountChars();
+ if (iCount > 0)
+ pCurChar = &m_pCurLine->m_LineChars[iCount - 1];
}
+
CFX_RTFBreakType dwRet2 =
(this->*g_FX_RTFBreak_lpfAppendChar[chartype >> FX_CHARTYPEBITS])(
pCurChar);
@@ -295,17 +298,18 @@ CFX_RTFBreakType CFX_RTFBreak::AppendChar_Combination(CFX_RTFChar* pCurChar) {
}
CFX_RTFBreakType CFX_RTFBreak::AppendChar_Tab(CFX_RTFChar* pCurChar) {
- if (m_dwLayoutStyles & FX_RTFLAYOUTSTYLE_ExpandTab) {
- int32_t& iLineWidth = m_pCurLine->m_iWidth;
- int32_t iCharWidth = iLineWidth;
- if (GetPositionedTab(iCharWidth))
- iCharWidth -= iLineWidth;
- else
- iCharWidth = m_iTabWidth * (iLineWidth / m_iTabWidth + 1) - iLineWidth;
+ if (!(m_dwLayoutStyles & FX_RTFLAYOUTSTYLE_ExpandTab))
+ return CFX_RTFBreakType::None;
- pCurChar->m_iCharWidth = iCharWidth;
- iLineWidth += iCharWidth;
- }
+ int32_t& iLineWidth = m_pCurLine->m_iWidth;
+ int32_t iCharWidth = iLineWidth;
+ if (GetPositionedTab(&iCharWidth))
+ iCharWidth -= iLineWidth;
+ else
+ iCharWidth = m_iTabWidth * (iLineWidth / m_iTabWidth + 1) - iLineWidth;
+
+ pCurChar->m_iCharWidth = iCharWidth;
+ iLineWidth += iCharWidth;
return CFX_RTFBreakType::None;
}
@@ -323,9 +327,8 @@ CFX_RTFBreakType CFX_RTFBreak::AppendChar_Control(CFX_RTFChar* pCurChar) {
dwRet2 = CFX_RTFBreakType::Paragraph;
break;
default:
- if (pCurChar->m_wCharCode == m_wLineBreakChar) {
+ if (pCurChar->m_wCharCode == m_wLineBreakChar)
dwRet2 = CFX_RTFBreakType::Paragraph;
- }
break;
}
if (dwRet2 != CFX_RTFBreakType::None)
@@ -336,7 +339,6 @@ CFX_RTFBreakType CFX_RTFBreak::AppendChar_Control(CFX_RTFChar* pCurChar) {
CFX_RTFBreakType CFX_RTFBreak::AppendChar_Arabic(CFX_RTFChar* pCurChar) {
CFX_RTFChar* pLastChar = nullptr;
- int32_t& iLineWidth = m_pCurLine->m_iWidth;
int32_t iCharWidth = 0;
FX_WCHAR wForm;
bool bAlef = false;
@@ -344,23 +346,24 @@ CFX_RTFBreakType CFX_RTFBreak::AppendChar_Arabic(CFX_RTFChar* pCurChar) {
m_eCharType <= FX_CHARTYPE_ArabicDistortion) {
pLastChar = GetLastChar(1);
if (pLastChar) {
- iLineWidth -= pLastChar->m_iCharWidth;
+ m_pCurLine->m_iWidth -= pLastChar->m_iCharWidth;
CFX_RTFChar* pPrevChar = GetLastChar(2);
wForm = pdfium::arabic::GetFormChar(pLastChar, pPrevChar, pCurChar);
bAlef = (wForm == 0xFEFF &&
pLastChar->GetCharType() == FX_CHARTYPE_ArabicAlef);
- if (!m_pFont->GetCharWidth(wForm, iCharWidth, false)) {
- if (!m_pFont->GetCharWidth(pLastChar->m_wCharCode, iCharWidth, false))
- iCharWidth = m_iDefChar;
+ if (!m_pFont->GetCharWidth(wForm, iCharWidth, false) &&
+ !m_pFont->GetCharWidth(pLastChar->m_wCharCode, iCharWidth, false)) {
+ iCharWidth = m_iDefChar;
}
iCharWidth *= m_iFontSize;
iCharWidth = iCharWidth * m_iHorizontalScale / 100;
pLastChar->m_iCharWidth = iCharWidth;
- iLineWidth += iCharWidth;
+ m_pCurLine->m_iWidth += iCharWidth;
iCharWidth = 0;
}
}
+
wForm = pdfium::arabic::GetFormChar(pCurChar, bAlef ? nullptr : pLastChar,
nullptr);
if (!m_pFont->GetCharWidth(wForm, iCharWidth, false) &&
@@ -371,23 +374,17 @@ CFX_RTFBreakType CFX_RTFBreak::AppendChar_Arabic(CFX_RTFChar* pCurChar) {
iCharWidth *= m_iFontSize;
iCharWidth = iCharWidth * m_iHorizontalScale / 100;
pCurChar->m_iCharWidth = iCharWidth;
- iLineWidth += iCharWidth;
+ m_pCurLine->m_iWidth += iCharWidth;
m_pCurLine->m_iArabicChars++;
- if (m_pCurLine->GetLineEnd() > m_iBoundaryEnd + m_iTolerance) {
+
+ if (m_pCurLine->GetLineEnd() > m_iBoundaryEnd + m_iTolerance)
return EndBreak(CFX_RTFBreakType::Line);
- }
return CFX_RTFBreakType::None;
}
CFX_RTFBreakType CFX_RTFBreak::AppendChar_Others(CFX_RTFChar* pCurChar) {
FX_CHARTYPE chartype = pCurChar->GetCharType();
- FX_WCHAR wForm;
- if (chartype == FX_CHARTYPE_Numeric) {
- wForm = pCurChar->m_wCharCode;
- } else {
- wForm = pCurChar->m_wCharCode;
- }
-
+ FX_WCHAR wForm = pCurChar->m_wCharCode;
int32_t iCharWidth = 0;
if (!m_pFont->GetCharWidth(wForm, iCharWidth, false))
iCharWidth = m_iDefChar;
@@ -409,7 +406,7 @@ CFX_RTFBreakType CFX_RTFBreak::EndBreak(CFX_RTFBreakType dwStatus) {
ASSERT(dwStatus != CFX_RTFBreakType::None);
m_dwIdentity++;
- CFX_RTFPieceArray* pCurPieces = &m_pCurLine->m_LinePieces;
+ const CFX_RTFPieceArray* pCurPieces = &m_pCurLine->m_LinePieces;
int32_t iCount = pCurPieces->GetSize();
if (iCount > 0) {
CFX_RTFPiece* pLastPiece = pCurPieces->GetPtrAt(--iCount);
@@ -420,7 +417,7 @@ CFX_RTFBreakType CFX_RTFBreak::EndBreak(CFX_RTFBreakType dwStatus) {
return dwStatus;
}
- CFX_RTFLine* pLastLine = GetRTFLine();
+ const CFX_RTFLine* pLastLine = GetRTFLine();
if (pLastLine) {
pCurPieces = &pLastLine->m_LinePieces;
iCount = pCurPieces->GetSize();
@@ -444,14 +441,14 @@ CFX_RTFBreakType CFX_RTFBreak::EndBreak(CFX_RTFBreakType dwStatus) {
if (dwStatus == CFX_RTFBreakType::Piece)
return dwStatus;
- m_iReady = (m_pCurLine == &m_RTFLine1) ? 1 : 2;
+ m_iReady = m_pCurLine == &m_RTFLine1 ? 1 : 2;
CFX_RTFLine* pNextLine =
- (m_pCurLine == &m_RTFLine1) ? &m_RTFLine2 : &m_RTFLine1;
+ m_pCurLine == &m_RTFLine1 ? &m_RTFLine2 : &m_RTFLine1;
bool bAllChars = m_iAlignment == CFX_RTFLineAlignment::Justified ||
m_iAlignment == CFX_RTFLineAlignment::Distributed;
CFX_TPOArray tpos(100);
if (!EndBreak_SplitLine(pNextLine, bAllChars, dwStatus)) {
- EndBreak_BidiLine(tpos, dwStatus);
+ EndBreak_BidiLine(&tpos, dwStatus);
if (!m_bPagination && m_iAlignment != CFX_RTFLineAlignment::Left)
EndBreak_Alignment(tpos, bAllChars, dwStatus);
@@ -459,6 +456,7 @@ CFX_RTFBreakType CFX_RTFBreak::EndBreak(CFX_RTFBreakType dwStatus) {
m_pCurLine = pNextLine;
m_pCurLine->m_iStart = m_iBoundaryStart;
+
CFX_RTFChar* pTC = GetLastChar(0);
m_eCharType = pTC ? pTC->GetCharType() : FX_CHARTYPE_Unknown;
return dwStatus;
@@ -469,7 +467,7 @@ bool CFX_RTFBreak::EndBreak_SplitLine(CFX_RTFLine* pNextLine,
CFX_RTFBreakType dwStatus) {
bool bDone = false;
if (m_pCurLine->GetLineEnd() > m_iBoundaryEnd + m_iTolerance) {
- CFX_RTFChar& tc = m_pCurLine->GetChar(m_pCurLine->CountChars() - 1);
+ const CFX_RTFChar& tc = m_pCurLine->GetChar(m_pCurLine->CountChars() - 1);
switch (tc.GetCharType()) {
case FX_CHARTYPE_Tab:
case FX_CHARTYPE_Control:
@@ -481,76 +479,79 @@ bool CFX_RTFBreak::EndBreak_SplitLine(CFX_RTFLine* pNextLine,
break;
}
}
- if (m_bPagination || m_pCurLine->m_iMBCSChars > 0) {
- const CFX_RTFChar* pCurChars = m_pCurLine->m_LineChars.data();
- const CFX_RTFChar* pTC;
- CFX_RTFPieceArray* pCurPieces = &m_pCurLine->m_LinePieces;
- CFX_RTFPiece tp;
- tp.m_pChars = &m_pCurLine->m_LineChars;
- bool bNew = true;
- uint32_t dwIdentity = (uint32_t)-1;
- int32_t iLast = m_pCurLine->CountChars() - 1, j = 0;
- for (int32_t i = 0; i <= iLast;) {
- pTC = pCurChars + i;
- if (bNew) {
- tp.m_iStartChar = i;
- tp.m_iStartPos += tp.m_iWidth;
- tp.m_iWidth = 0;
+
+ if (!m_bPagination && m_pCurLine->m_iMBCSChars <= 0) {
+ if (bAllChars && !bDone) {
+ int32_t endPos = m_pCurLine->GetLineEnd();
+ GetBreakPos(m_pCurLine->m_LineChars, endPos, bAllChars, true);
+ }
+ return false;
+ }
+
+ const CFX_RTFChar* pCurChars = m_pCurLine->m_LineChars.data();
+ const CFX_RTFChar* pTC;
+ CFX_RTFPieceArray* pCurPieces = &m_pCurLine->m_LinePieces;
+ CFX_RTFPiece tp;
+ tp.m_pChars = &m_pCurLine->m_LineChars;
+ bool bNew = true;
+ uint32_t dwIdentity = static_cast<uint32_t>(-1);
+ int32_t iLast = m_pCurLine->CountChars() - 1;
+ int32_t j = 0;
+ for (int32_t i = 0; i <= iLast;) {
+ pTC = pCurChars + i;
+ if (bNew) {
+ tp.m_iStartChar = i;
+ tp.m_iStartPos += tp.m_iWidth;
+ tp.m_iWidth = 0;
+ tp.m_dwStatus = pTC->m_dwStatus;
+ tp.m_iFontSize = pTC->m_iFontSize;
+ tp.m_iFontHeight = pTC->m_iFontHeight;
+ tp.m_iHorizontalScale = pTC->m_iHorizontalScale;
+ tp.m_iVerticalScale = pTC->m_iVerticalScale;
+ dwIdentity = pTC->m_dwIdentity;
+ tp.m_dwIdentity = dwIdentity;
+ tp.m_pUserData = pTC->m_pUserData;
+ j = i;
+ bNew = false;
+ }
+
+ if (i == iLast || pTC->m_dwStatus != CFX_RTFBreakType::None ||
+ pTC->m_dwIdentity != dwIdentity) {
+ tp.m_iChars = i - j;
+ if (pTC->m_dwIdentity == dwIdentity) {
tp.m_dwStatus = pTC->m_dwStatus;
- tp.m_iFontSize = pTC->m_iFontSize;
- tp.m_iFontHeight = pTC->m_iFontHeight;
- tp.m_iHorizontalScale = pTC->m_iHorizontalScale;
- tp.m_iVerticalScale = pTC->m_iVerticalScale;
- dwIdentity = pTC->m_dwIdentity;
- tp.m_dwIdentity = dwIdentity;
- tp.m_pUserData = pTC->m_pUserData;
- j = i;
- bNew = false;
- }
- if (i == iLast || pTC->m_dwStatus != CFX_RTFBreakType::None ||
- pTC->m_dwIdentity != dwIdentity) {
- tp.m_iChars = i - j;
- if (pTC->m_dwIdentity == dwIdentity) {
- tp.m_dwStatus = pTC->m_dwStatus;
- tp.m_iWidth += pTC->m_iCharWidth;
- tp.m_iChars += 1;
- i++;
- }
- pCurPieces->Add(tp);
- bNew = true;
- } else {
tp.m_iWidth += pTC->m_iCharWidth;
+ tp.m_iChars += 1;
i++;
}
+ pCurPieces->Add(tp);
+ bNew = true;
+ } else {
+ tp.m_iWidth += pTC->m_iCharWidth;
+ i++;
}
- return true;
- }
- if (bAllChars && !bDone) {
- int32_t iEndPos = m_pCurLine->GetLineEnd();
- GetBreakPos(m_pCurLine->m_LineChars, iEndPos, bAllChars, true);
}
- return false;
+ return true;
}
-void CFX_RTFBreak::EndBreak_BidiLine(CFX_TPOArray& tpos,
+
+void CFX_RTFBreak::EndBreak_BidiLine(CFX_TPOArray* tpos,
CFX_RTFBreakType dwStatus) {
FX_TPO tpo;
CFX_RTFPiece tp;
CFX_RTFChar* pTC;
- int32_t i, j;
+ int32_t i;
+ int32_t j;
std::vector<CFX_RTFChar>& chars = m_pCurLine->m_LineChars;
int32_t iCount = m_pCurLine->CountChars();
- bool bDone = (!m_bPagination && m_pCurLine->m_iArabicChars > 0);
- if (bDone) {
+ if (!m_bPagination && m_pCurLine->m_iArabicChars > 0) {
int32_t iBidiNum = 0;
for (i = 0; i < iCount; i++) {
pTC = &chars[i];
pTC->m_iBidiPos = i;
- if (pTC->GetCharType() != FX_CHARTYPE_Control) {
+ if (pTC->GetCharType() != FX_CHARTYPE_Control)
iBidiNum = i;
- }
- if (i == 0) {
+ if (i == 0)
pTC->m_iBidiLevel = 1;
- }
}
FX_BidiLine(chars, iBidiNum + 1, 0);
} else {
@@ -561,23 +562,22 @@ void CFX_RTFBreak::EndBreak_BidiLine(CFX_TPOArray& tpos,
pTC->m_iBidiOrder = 0;
}
}
+
tp.m_dwStatus = CFX_RTFBreakType::Piece;
tp.m_iStartPos = m_pCurLine->m_iStart;
tp.m_pChars = &chars;
CFX_RTFPieceArray* pCurPieces = &m_pCurLine->m_LinePieces;
- int32_t iBidiLevel = -1, iCharWidth;
- uint32_t dwIdentity = (uint32_t)-1;
- i = j = 0;
+ int32_t iBidiLevel = -1;
+ int32_t iCharWidth;
+ uint32_t dwIdentity = static_cast<uint32_t>(-1);
+ i = 0;
+ j = 0;
while (i < iCount) {
pTC = &chars[i];
if (iBidiLevel < 0) {
iBidiLevel = pTC->m_iBidiLevel;
iCharWidth = pTC->m_iCharWidth;
- if (iCharWidth < 1) {
- tp.m_iWidth = 0;
- } else {
- tp.m_iWidth = iCharWidth;
- }
+ tp.m_iWidth = iCharWidth < 1 ? 0 : iCharWidth;
tp.m_iBidiLevel = iBidiLevel;
tp.m_iBidiPos = pTC->m_iBidiOrder;
tp.m_iFontSize = pTC->m_iFontSize;
@@ -597,82 +597,83 @@ void CFX_RTFBreak::EndBreak_BidiLine(CFX_TPOArray& tpos,
tp.m_iStartChar = i;
tpo.index = j++;
tpo.pos = tp.m_iBidiPos;
- tpos.Add(tpo);
+ tpos->Add(tpo);
iBidiLevel = -1;
} else {
iCharWidth = pTC->m_iCharWidth;
- if (iCharWidth > 0) {
+ if (iCharWidth > 0)
tp.m_iWidth += iCharWidth;
- }
i++;
}
}
+
if (i > tp.m_iStartChar) {
tp.m_dwStatus = dwStatus;
tp.m_iChars = i - tp.m_iStartChar;
pCurPieces->Add(tp);
tpo.index = j;
tpo.pos = tp.m_iBidiPos;
- tpos.Add(tpo);
+ tpos->Add(tpo);
}
- j = tpos.GetSize() - 1;
- FX_TEXTLAYOUT_PieceSort(tpos, 0, j);
+ j = tpos->GetSize() - 1;
+ FX_TEXTLAYOUT_PieceSort(*tpos, 0, j);
int32_t iStartPos = m_pCurLine->m_iStart;
for (i = 0; i <= j; i++) {
- tpo = tpos.GetAt(i);
+ tpo = tpos->GetAt(i);
CFX_RTFPiece& ttp = pCurPieces->GetAt(tpo.index);
ttp.m_iStartPos = iStartPos;
iStartPos += ttp.m_iWidth;
}
}
-void CFX_RTFBreak::EndBreak_Alignment(CFX_TPOArray& tpos,
+void CFX_RTFBreak::EndBreak_Alignment(const CFX_TPOArray& tpos,
bool bAllChars,
CFX_RTFBreakType dwStatus) {
CFX_RTFPieceArray* pCurPieces = &m_pCurLine->m_LinePieces;
- int32_t iNetWidth = m_pCurLine->m_iWidth, iGapChars = 0, iCharWidth;
+ int32_t iNetWidth = m_pCurLine->m_iWidth;
+ int32_t iGapChars = 0;
+ int32_t iCharWidth;
int32_t iCount = pCurPieces->GetSize();
bool bFind = false;
uint32_t dwCharType;
- int32_t i, j;
+ int32_t i;
+ int32_t j;
FX_TPO tpo;
for (i = iCount - 1; i > -1; i--) {
tpo = tpos.GetAt(i);
CFX_RTFPiece& ttp = pCurPieces->GetAt(tpo.index);
- if (!bFind) {
+ if (!bFind)
iNetWidth = ttp.GetEndPos();
- }
+
bool bArabic = FX_IsOdd(ttp.m_iBidiLevel);
j = bArabic ? 0 : ttp.m_iChars - 1;
while (j > -1 && j < ttp.m_iChars) {
const CFX_RTFChar& tc = ttp.GetChar(j);
- if (tc.m_nBreakType == FX_LBT_DIRECT_BRK) {
+ if (tc.m_nBreakType == FX_LBT_DIRECT_BRK)
iGapChars++;
- }
+
if (!bFind || !bAllChars) {
dwCharType = tc.GetCharType();
if (dwCharType == FX_CHARTYPE_Space ||
dwCharType == FX_CHARTYPE_Control) {
if (!bFind) {
iCharWidth = tc.m_iCharWidth;
- if (bAllChars && iCharWidth > 0) {
+ if (bAllChars && iCharWidth > 0)
iNetWidth -= iCharWidth;
- }
}
} else {
bFind = true;
- if (!bAllChars) {
+ if (!bAllChars)
break;
- }
}
}
j += bArabic ? 1 : -1;
}
- if (!bAllChars && bFind) {
+ if (!bAllChars && bFind)
break;
- }
}
+
int32_t iOffset = m_iBoundaryEnd - iNetWidth;
if (iGapChars > 0 && (m_iAlignment == CFX_RTFLineAlignment::Distributed ||
(m_iAlignment == CFX_RTFLineAlignment::Justified &&
@@ -681,25 +682,23 @@ void CFX_RTFBreak::EndBreak_Alignment(CFX_TPOArray& tpos,
for (i = 0; i < iCount; i++) {
tpo = tpos.GetAt(i);
CFX_RTFPiece& ttp = pCurPieces->GetAt(tpo.index);
- if (iStart < 0) {
+ if (iStart < 0)
iStart = ttp.m_iStartPos;
- } else {
+ else
ttp.m_iStartPos = iStart;
- }
- int32_t k;
+
for (j = 0; j < ttp.m_iChars; j++) {
CFX_RTFChar& tc = ttp.GetChar(j);
- if (tc.m_nBreakType != FX_LBT_DIRECT_BRK || tc.m_iCharWidth < 0) {
+ if (tc.m_nBreakType != FX_LBT_DIRECT_BRK || tc.m_iCharWidth < 0)
continue;
- }
- k = iOffset / iGapChars;
+
+ int32_t k = iOffset / iGapChars;
tc.m_iCharWidth += k;
ttp.m_iWidth += k;
iOffset -= k;
iGapChars--;
- if (iGapChars < 1) {
+ if (iGapChars < 1)
break;
- }
}
iStart += ttp.m_iWidth;
}
@@ -739,7 +738,8 @@ int32_t CFX_RTFBreak::GetBreakPos(std::vector<CFX_RTFChar>& tca,
}
CFX_RTFChar* pCharArray = tca.data();
- CFX_RTFChar* pCur = pCharArray + iLength--;
+ CFX_RTFChar* pCur = pCharArray + iLength;
+ iLength--;
if (bAllChars)
pCur->m_nBreakType = FX_LBT_UNKNOWN;
@@ -755,15 +755,14 @@ int32_t CFX_RTFBreak::GetBreakPos(std::vector<CFX_RTFChar>& tca,
uint32_t nCur = nCodeProp & 0x003F;
bool bNeedBreak = false;
FX_LINEBREAKTYPE eType;
- if (nCur == FX_CBP_SP) {
- bNeedBreak = true;
- eType = nNext == FX_CBP_SP ? FX_LBT_PROHIBITED_BRK
- : gs_FX_LineBreak_PairTable[nCur][nNext];
- } else if (nCur == FX_CBP_TB) {
+ if (nCur == FX_CBP_TB) {
bNeedBreak = true;
eType = nNext == FX_CBP_TB ? FX_LBT_PROHIBITED_BRK
: gs_FX_LineBreak_PairTable[nCur][nNext];
} else {
+ if (nCur == FX_CBP_SP)
+ bNeedBreak = true;
+
eType = nNext == FX_CBP_SP ? FX_LBT_PROHIBITED_BRK
: gs_FX_LineBreak_PairTable[nCur][nNext];
}
@@ -816,15 +815,15 @@ void CFX_RTFBreak::SplitTextLine(CFX_RTFLine* pCurLine,
bool bAllChars) {
ASSERT(pCurLine && pNextLine);
int32_t iCount = pCurLine->CountChars();
- if (iCount < 2) {
+ if (iCount < 2)
return;
- }
+
int32_t iEndPos = pCurLine->GetLineEnd();
std::vector<CFX_RTFChar>& curChars = pCurLine->m_LineChars;
int32_t iCharPos = GetBreakPos(curChars, iEndPos, bAllChars, false);
- if (iCharPos < 0) {
+ if (iCharPos < 0)
iCharPos = 0;
- }
+
iCharPos++;
if (iCharPos >= iCount) {
pNextLine->RemoveAll(true);
@@ -832,94 +831,93 @@ void CFX_RTFBreak::SplitTextLine(CFX_RTFLine* pCurLine,
pTC->m_nBreakType = FX_LBT_UNKNOWN;
return;
}
- std::vector<CFX_RTFChar>& nextChars = pNextLine->m_LineChars;
- nextChars =
+
+ pNextLine->m_LineChars =
std::vector<CFX_RTFChar>(curChars.begin() + iCharPos, curChars.end());
curChars.erase(curChars.begin() + iCharPos, curChars.end());
pNextLine->m_iStart = pCurLine->m_iStart;
pNextLine->m_iWidth = pCurLine->GetLineEnd() - iEndPos;
pCurLine->m_iWidth = iEndPos;
curChars[iCharPos - 1].m_nBreakType = FX_LBT_UNKNOWN;
- iCount = pdfium::CollectionSize<int>(nextChars);
- CFX_RTFChar* pNextChars = nextChars.data();
- for (int32_t i = 0; i < iCount; i++) {
- CFX_RTFChar* tc = pNextChars + i;
- if (tc->GetCharType() >= FX_CHARTYPE_ArabicAlef) {
+
+ for (size_t i = 0; i < pNextLine->m_LineChars.size(); i++) {
+ if (pNextLine->m_LineChars[i].GetCharType() >= FX_CHARTYPE_ArabicAlef) {
pCurLine->m_iArabicChars--;
pNextLine->m_iArabicChars++;
}
- tc->m_dwStatus = CFX_RTFBreakType::None;
+ pNextLine->m_LineChars[i].m_dwStatus = CFX_RTFBreakType::None;
}
}
int32_t CFX_RTFBreak::CountBreakPieces() const {
- CFX_RTFPieceArray* pRTFPieces = GetRTFPieces();
+ const CFX_RTFPieceArray* pRTFPieces = GetRTFPieces();
return pRTFPieces ? pRTFPieces->GetSize() : 0;
}
const CFX_RTFPiece* CFX_RTFBreak::GetBreakPiece(int32_t index) const {
- CFX_RTFPieceArray* pRTFPieces = GetRTFPieces();
+ const CFX_RTFPieceArray* pRTFPieces = GetRTFPieces();
if (!pRTFPieces)
return nullptr;
-
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();
+ const CFX_RTFLine* pRTFLine = GetRTFLine();
if (!pRTFLine) {
rect.left = ((FX_FLOAT)m_iBoundaryStart) / 20000.0f;
rect.width = rect.height = 0;
return;
}
- rect.left = ((FX_FLOAT)pRTFLine->m_iStart) / 20000.0f;
- rect.width = ((FX_FLOAT)pRTFLine->m_iWidth) / 20000.0f;
- CFX_RTFPieceArray& rtfPieces = pRTFLine->m_LinePieces;
+
+ rect.left = static_cast<FX_FLOAT>(pRTFLine->m_iStart) / 20000.0f;
+ rect.width = static_cast<FX_FLOAT>(pRTFLine->m_iWidth) / 20000.0f;
+ const CFX_RTFPieceArray& rtfPieces = pRTFLine->m_LinePieces;
int32_t iCount = rtfPieces.GetSize();
if (iCount < 1) {
rect.width = 0;
return;
}
+
CFX_RTFPiece* pBreakPiece;
- int32_t iLineHeight = 0, iMax;
+ int32_t iLineHeight = 0;
+ int32_t iMax;
for (int32_t i = 0; i < iCount; i++) {
pBreakPiece = rtfPieces.GetPtrAt(i);
int32_t iFontHeight = FXSYS_round(pBreakPiece->m_iFontHeight *
pBreakPiece->m_iVerticalScale / 100.0f);
iMax = std::max(pBreakPiece->m_iFontSize, iFontHeight);
- if (i == 0) {
- iLineHeight = iMax;
- } else if (iLineHeight < iMax) {
+ if (i == 0 || iLineHeight < iMax)
iLineHeight = iMax;
- }
}
- rect.height = ((FX_FLOAT)iLineHeight) / 20.0f;
+ rect.height = static_cast<FX_FLOAT>(iLineHeight) / 20.0f;
}
+
void CFX_RTFBreak::ClearBreakPieces() {
- CFX_RTFLine* pRTFLine = GetRTFLine();
- if (pRTFLine) {
- pRTFLine->RemoveAll(true);
- }
+ const CFX_RTFLine* pRTFLine = GetRTFLine();
+ if (pRTFLine)
+ const_cast<CFX_RTFLine*>(pRTFLine)->RemoveAll(true);
m_iReady = 0;
}
+
void CFX_RTFBreak::Reset() {
m_eCharType = FX_CHARTYPE_Unknown;
m_RTFLine1.RemoveAll(true);
m_RTFLine2.RemoveAll(true);
}
+
int32_t CFX_RTFBreak::GetDisplayPos(const FX_RTFTEXTOBJ* pText,
FXTEXT_CHARPOS* pCharPos,
bool bCharCode,
CFX_WideString* pWSForms,
FX_AdjustCharDisplayPos pAdjustPos) const {
- if (!pText || pText->iLength < 1) {
+ if (!pText || pText->iLength < 1)
return 0;
- }
+
ASSERT(pText->pStr && pText->pWidths && pText->pFont && pText->pRect);
+
const FX_WCHAR* pStr = pText->pStr;
int32_t* pWidths = pText->pWidths;
int32_t iLength = pText->iLength - 1;
@@ -932,16 +930,25 @@ int32_t CFX_RTFBreak::GetDisplayPos(const FX_RTFTEXTOBJ* pText,
int32_t iDescent = pFont->GetDescent();
int32_t iMaxHeight = iAscent - iDescent;
FX_FLOAT fFontHeight = fFontSize;
- FX_FLOAT fAscent = fFontHeight * (FX_FLOAT)iAscent / (FX_FLOAT)iMaxHeight;
- FX_WCHAR wch, wPrev = 0xFEFF, wNext, wForm;
- int32_t iWidth, iCharWidth, iCharHeight;
- FX_FLOAT fX, fY, fCharWidth, fCharHeight;
+ FX_FLOAT fAscent = fFontHeight * static_cast<FX_FLOAT>(iAscent) /
+ static_cast<FX_FLOAT>(iMaxHeight);
+ FX_WCHAR wch;
+ FX_WCHAR wPrev = 0xFEFF;
+ FX_WCHAR wNext;
+ FX_WCHAR wForm;
+ int32_t iWidth;
+ int32_t iCharWidth;
+ int32_t iCharHeight;
+ FX_FLOAT fX = rtText.left;
+ FX_FLOAT fY = rtText.top;
+ FX_FLOAT fCharWidth;
+ FX_FLOAT fCharHeight;
int32_t iHorScale = pText->iHorizontalScale;
int32_t iVerScale = pText->iVerticalScale;
bool bEmptyChar;
- uint32_t dwProps, dwCharType;
- fX = rtText.left;
- fY = rtText.top;
+ uint32_t dwProps;
+ uint32_t dwCharType;
+
if (bRTLPiece)
fX = rtText.right();
@@ -956,98 +963,90 @@ int32_t CFX_RTFBreak::GetDisplayPos(const FX_RTFTEXTOBJ* pText,
wPrev = 0xFEFF;
continue;
}
- if (iWidth != 0) {
- iCharWidth = iWidth;
- if (iCharWidth < 0)
- iCharWidth = -iCharWidth;
-
- bEmptyChar =
- (dwCharType >= FX_CHARTYPE_Tab && dwCharType <= FX_CHARTYPE_Control);
- if (!bEmptyChar)
- iCount++;
-
- if (pCharPos) {
- iCharWidth /= iFontSize;
- wForm = wch;
- if (dwCharType >= FX_CHARTYPE_ArabicAlef) {
- if (i < iLength) {
- wNext = *pStr;
- if (*pWidths < 0) {
- if (i + 1 < iLength) {
- wNext = pStr[1];
- }
- }
- } else {
- wNext = 0xFEFF;
- }
- wForm = pdfium::arabic::GetFormChar(wch, wPrev, wNext);
- } else if (bRTLPiece) {
- wForm = FX_GetMirrorChar(wch, dwProps, bRTLPiece, false);
+ if (iWidth == 0)
+ continue;
+
+ iCharWidth = FXSYS_abs(iWidth);
+ bEmptyChar =
+ (dwCharType >= FX_CHARTYPE_Tab && dwCharType <= FX_CHARTYPE_Control);
+ if (!bEmptyChar)
+ iCount++;
+
+ if (pCharPos) {
+ iCharWidth /= iFontSize;
+ wForm = wch;
+ if (dwCharType >= FX_CHARTYPE_ArabicAlef) {
+ if (i < iLength) {
+ wNext = *pStr;
+ if (*pWidths < 0 && i + 1 < iLength)
+ wNext = pStr[1];
+ } else {
+ wNext = 0xFEFF;
+ }
+ wForm = pdfium::arabic::GetFormChar(wch, wPrev, wNext);
+ } else if (bRTLPiece) {
+ wForm = FX_GetMirrorChar(wch, dwProps, bRTLPiece, false);
+ }
+ dwProps = FX_GetUnicodeProperties(wForm);
+
+ if (!bEmptyChar) {
+ if (bCharCode) {
+ pCharPos->m_GlyphIndex = wch;
+ } else {
+ pCharPos->m_GlyphIndex = pFont->GetGlyphIndex(wForm, false);
+ if (pCharPos->m_GlyphIndex == 0xFFFF)
+ pCharPos->m_GlyphIndex = pFont->GetGlyphIndex(wch, false);
}
- dwProps = FX_GetUnicodeProperties(wForm);
-
- if (!bEmptyChar) {
- if (bCharCode) {
- pCharPos->m_GlyphIndex = wch;
- } else {
- pCharPos->m_GlyphIndex = pFont->GetGlyphIndex(wForm, false);
- if (pCharPos->m_GlyphIndex == 0xFFFF) {
- pCharPos->m_GlyphIndex = pFont->GetGlyphIndex(wch, false);
- }
- }
#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
- pCharPos->m_ExtGID = pCharPos->m_GlyphIndex;
+ pCharPos->m_ExtGID = pCharPos->m_GlyphIndex;
#endif
- pCharPos->m_FontCharWidth = iCharWidth;
- if (pWSForms) {
- *pWSForms += wForm;
- }
- }
- iCharHeight = 1000;
-
- fCharWidth = fFontSize * iCharWidth / 1000.0f;
- fCharHeight = fFontSize * iCharHeight / 1000.0f;
- if (bRTLPiece && dwCharType != FX_CHARTYPE_Combination)
- fX -= fCharWidth;
-
- if (!bEmptyChar) {
- CFX_PointF ptOffset;
- bool bAdjusted = false;
- if (pAdjustPos) {
- bAdjusted =
- pAdjustPos(wForm, false, pFont, fFontSize, false, ptOffset);
- }
- pCharPos->m_Origin = CFX_PointF(fX + ptOffset.x, fY - ptOffset.y);
+ pCharPos->m_FontCharWidth = iCharWidth;
+ if (pWSForms)
+ *pWSForms += wForm;
+ }
+ iCharHeight = 1000;
+
+ fCharWidth = fFontSize * iCharWidth / 1000.0f;
+ fCharHeight = fFontSize * iCharHeight / 1000.0f;
+ if (bRTLPiece && dwCharType != FX_CHARTYPE_Combination)
+ fX -= fCharWidth;
+
+ if (!bEmptyChar) {
+ CFX_PointF ptOffset;
+ bool bAdjusted = false;
+ if (pAdjustPos) {
+ bAdjusted =
+ pAdjustPos(wForm, false, pFont, fFontSize, false, ptOffset);
}
- if (!bRTLPiece && dwCharType != FX_CHARTYPE_Combination)
- fX += fCharWidth;
-
- if (!bEmptyChar) {
- pCharPos->m_bGlyphAdjust = true;
- pCharPos->m_AdjustMatrix[0] = -1;
- pCharPos->m_AdjustMatrix[1] = 0;
- pCharPos->m_AdjustMatrix[2] = 0;
- pCharPos->m_AdjustMatrix[3] = 1;
- pCharPos->m_Origin.y += fAscent * iVerScale / 100.0f;
- pCharPos->m_Origin.y -= fAscent;
-
- if (iHorScale != 100 || iVerScale != 100) {
- pCharPos->m_AdjustMatrix[0] =
- pCharPos->m_AdjustMatrix[0] * iHorScale / 100.0f;
- pCharPos->m_AdjustMatrix[1] =
- pCharPos->m_AdjustMatrix[1] * iHorScale / 100.0f;
- pCharPos->m_AdjustMatrix[2] =
- pCharPos->m_AdjustMatrix[2] * iVerScale / 100.0f;
- pCharPos->m_AdjustMatrix[3] =
- pCharPos->m_AdjustMatrix[3] * iVerScale / 100.0f;
- }
- pCharPos++;
+ pCharPos->m_Origin = CFX_PointF(fX + ptOffset.x, fY - ptOffset.y);
+ }
+ if (!bRTLPiece && dwCharType != FX_CHARTYPE_Combination)
+ fX += fCharWidth;
+
+ if (!bEmptyChar) {
+ pCharPos->m_bGlyphAdjust = true;
+ pCharPos->m_AdjustMatrix[0] = -1;
+ pCharPos->m_AdjustMatrix[1] = 0;
+ pCharPos->m_AdjustMatrix[2] = 0;
+ pCharPos->m_AdjustMatrix[3] = 1;
+ pCharPos->m_Origin.y += fAscent * iVerScale / 100.0f;
+ pCharPos->m_Origin.y -= fAscent;
+
+ if (iHorScale != 100 || iVerScale != 100) {
+ pCharPos->m_AdjustMatrix[0] =
+ pCharPos->m_AdjustMatrix[0] * iHorScale / 100.0f;
+ pCharPos->m_AdjustMatrix[1] =
+ pCharPos->m_AdjustMatrix[1] * iHorScale / 100.0f;
+ pCharPos->m_AdjustMatrix[2] =
+ pCharPos->m_AdjustMatrix[2] * iVerScale / 100.0f;
+ pCharPos->m_AdjustMatrix[3] =
+ pCharPos->m_AdjustMatrix[3] * iVerScale / 100.0f;
}
+ pCharPos++;
}
}
- if (iWidth > 0) {
+ if (iWidth > 0)
wPrev = wch;
- }
}
return iCount;
}
diff --git a/xfa/fgas/layout/fgas_rtfbreak.h b/xfa/fgas/layout/fgas_rtfbreak.h
index 2389442c0d..d99a56bfa1 100644
--- a/xfa/fgas/layout/fgas_rtfbreak.h
+++ b/xfa/fgas/layout/fgas_rtfbreak.h
@@ -53,11 +53,10 @@ class CFX_RTFPiece {
void AppendChar(const CFX_RTFChar& tc) {
ASSERT(m_pChars);
m_pChars->push_back(tc);
- if (m_iWidth < 0) {
+ if (m_iWidth < 0)
m_iWidth = tc.m_iCharWidth;
- } else {
+ else
m_iWidth += tc.m_iCharWidth;
- }
m_iChars++;
}
@@ -100,9 +99,9 @@ class CFX_RTFPiece {
void Reset() {
m_dwStatus = CFX_RTFBreakType::Piece;
- if (m_iWidth > -1) {
+ if (m_iWidth > -1)
m_iStartPos += m_iWidth;
- }
+
m_iWidth = -1;
m_iStartChar += m_iChars;
m_iChars = 0;
@@ -138,23 +137,28 @@ class CFX_RTFLine {
int32_t CountChars() const {
return pdfium::CollectionSize<int32_t>(m_LineChars);
}
+
CFX_RTFChar& GetChar(int32_t index) {
ASSERT(index >= 0 && index < pdfium::CollectionSize<int32_t>(m_LineChars));
return m_LineChars[index];
}
+
CFX_RTFChar* GetCharPtr(int32_t index) {
ASSERT(index > -1 && index < pdfium::CollectionSize<int32_t>(m_LineChars));
return &m_LineChars[index];
}
+
int32_t CountPieces() const { return m_LinePieces.GetSize(); }
CFX_RTFPiece& GetPiece(int32_t index) const {
ASSERT(index > -1 && index < m_LinePieces.GetSize());
return m_LinePieces.GetAt(index);
}
+
CFX_RTFPiece* GetPiecePtr(int32_t index) const {
ASSERT(index > -1 && index < m_LinePieces.GetSize());
return m_LinePieces.GetPtrAt(index);
}
+
int32_t GetLineEnd() const { return m_iStart + m_iWidth; }
void RemoveAll(bool bLeaveMemory = false) {
m_LineChars.clear();
@@ -208,13 +212,14 @@ class CFX_RTFBreak {
CFX_RTFBreakType AppendChar_Others(CFX_RTFChar* pCurChar);
protected:
+ void FontChanged();
void SetBreakStatus();
CFX_RTFChar* GetLastChar(int32_t index) const;
- CFX_RTFLine* GetRTFLine() const;
- CFX_RTFPieceArray* GetRTFPieces() const;
+ const CFX_RTFLine* GetRTFLine() const;
+ const CFX_RTFPieceArray* GetRTFPieces() const;
FX_CHARTYPE GetUnifiedCharType(FX_CHARTYPE chartype) const;
int32_t GetLastPositionedTab() const;
- bool GetPositionedTab(int32_t& iTabPos) const;
+ bool GetPositionedTab(int32_t* iTabPos) const;
int32_t GetBreakPos(std::vector<CFX_RTFChar>& tca,
int32_t& iEndPos,
@@ -226,8 +231,8 @@ class CFX_RTFBreak {
bool EndBreak_SplitLine(CFX_RTFLine* pNextLine,
bool bAllChars,
CFX_RTFBreakType dwStatus);
- void EndBreak_BidiLine(CFX_TPOArray& tpos, CFX_RTFBreakType dwStatus);
- void EndBreak_Alignment(CFX_TPOArray& tpos,
+ void EndBreak_BidiLine(CFX_TPOArray* tpos, CFX_RTFBreakType dwStatus);
+ void EndBreak_Alignment(const CFX_TPOArray& tpos,
bool bAllChars,
CFX_RTFBreakType dwStatus);
diff --git a/xfa/fgas/layout/fgas_textbreak.cpp b/xfa/fgas/layout/fgas_textbreak.cpp
index 1ab90b23d3..69baa14c6c 100644
--- a/xfa/fgas/layout/fgas_textbreak.cpp
+++ b/xfa/fgas/layout/fgas_textbreak.cpp
@@ -86,13 +86,8 @@ void CFX_TxtBreak::SetLineWidth(FX_FLOAT fLineWidth) {
}
void CFX_TxtBreak::SetLinePos(FX_FLOAT fLinePos) {
- int32_t iLinePos = FXSYS_round(fLinePos * 20000.0f);
- if (iLinePos < 0) {
- iLinePos = 0;
- }
- if (iLinePos > m_iLineWidth) {
- iLinePos = m_iLineWidth;
- }
+ int32_t iLinePos =
+ std::min(std::max(FXSYS_round(fLinePos * 20000.0f), 0), m_iLineWidth);
m_pCurLine->m_iStart = iLinePos;
m_pCurLine->m_iWidth += iLinePos;
}
@@ -117,52 +112,52 @@ void CFX_TxtBreak::SetFont(const CFX_RetainPtr<CFGAS_GEFont>& pFont) {
SetBreakStatus();
m_pFont = pFont;
- m_iDefChar = 0;
- if (m_wDefChar != 0xFEFF && m_pFont) {
- m_pFont->GetCharWidth(m_wDefChar, m_iDefChar, false);
- m_iDefChar *= m_iFontSize;
- }
+ FontChanged();
}
void CFX_TxtBreak::SetFontSize(FX_FLOAT fFontSize) {
int32_t iFontSize = FXSYS_round(fFontSize * 20.0f);
- if (m_iFontSize == iFontSize) {
+ if (m_iFontSize == iFontSize)
return;
- }
+
SetBreakStatus();
m_iFontSize = iFontSize;
+ FontChanged();
+}
+
+void CFX_TxtBreak::FontChanged() {
m_iDefChar = 0;
- if (m_wDefChar != 0xFEFF && m_pFont) {
- m_pFont->GetCharWidth(m_wDefChar, m_iDefChar, false);
- m_iDefChar *= m_iFontSize;
- }
+ if (m_wDefChar == 0xFEFF || !m_pFont)
+ return;
+
+ m_pFont->GetCharWidth(m_wDefChar, m_iDefChar, false);
+ m_iDefChar *= m_iFontSize;
}
void CFX_TxtBreak::SetTabWidth(FX_FLOAT fTabWidth, bool bEquidistant) {
m_iTabWidth = FXSYS_round(fTabWidth * 20000.0f);
- if (m_iTabWidth < FX_TXTBREAK_MinimumTabWidth) {
+ if (m_iTabWidth < FX_TXTBREAK_MinimumTabWidth)
m_iTabWidth = FX_TXTBREAK_MinimumTabWidth;
- }
+
m_bEquidistant = bEquidistant;
}
void CFX_TxtBreak::SetDefaultChar(FX_WCHAR wch) {
m_wDefChar = wch;
m_iDefChar = 0;
- if (m_wDefChar != 0xFEFF && m_pFont) {
- m_pFont->GetCharWidth(m_wDefChar, m_iDefChar, false);
- if (m_iDefChar < 0) {
- m_iDefChar = 0;
- } else {
- m_iDefChar *= m_iFontSize;
- }
- }
+ if (m_wDefChar == 0xFEFF || !m_pFont)
+ return;
+
+ m_pFont->GetCharWidth(m_wDefChar, m_iDefChar, false);
+ if (m_iDefChar < 0)
+ m_iDefChar = 0;
+ else
+ m_iDefChar *= m_iFontSize;
}
void CFX_TxtBreak::SetParagraphBreakChar(FX_WCHAR wch) {
- if (wch != L'\r' && wch != L'\n') {
+ if (wch != L'\r' && wch != L'\n')
return;
- }
m_wParagBreakChar = wch;
}
@@ -171,14 +166,14 @@ void CFX_TxtBreak::SetLineBreakTolerance(FX_FLOAT fTolerance) {
}
void CFX_TxtBreak::SetCharRotation(int32_t iCharRotation) {
- if (iCharRotation < 0) {
+ if (iCharRotation < 0)
iCharRotation += (-iCharRotation / 4 + 1) * 4;
- } else if (iCharRotation > 3) {
+ else if (iCharRotation > 3)
iCharRotation -= (iCharRotation / 4) * 4;
- }
- if (m_iCharRotation == iCharRotation) {
+
+ if (m_iCharRotation == iCharRotation)
return;
- }
+
SetBreakStatus();
m_iCharRotation = iCharRotation;
m_iRotation = m_iLineRotation + m_iCharRotation;
@@ -194,15 +189,12 @@ void CFX_TxtBreak::SetAlignment(int32_t iAlignment) {
void CFX_TxtBreak::ResetContextCharStyles() {
m_dwContextCharStyles = m_bArabicContext ? m_iCurAlignment : m_iAlignment;
- if (m_bArabicNumber) {
+ if (m_bArabicNumber)
m_dwContextCharStyles |= FX_TXTCHARSTYLE_ArabicNumber;
- }
- if (m_bArabicComma) {
+ if (m_bArabicComma)
m_dwContextCharStyles |= FX_TXTCHARSTYLE_ArabicComma;
- }
- if ((m_bArabicContext && m_bCurRTL) || (!m_bArabicContext && m_bRTL)) {
+ if ((m_bArabicContext && m_bCurRTL) || (!m_bArabicContext && m_bRTL))
m_dwContextCharStyles |= FX_TXTCHARSTYLE_RTLReadingOrder;
- }
m_dwContextCharStyles |= (m_iArabicContext << 8);
}
@@ -211,34 +203,32 @@ void CFX_TxtBreak::SetCombWidth(FX_FLOAT fCombWidth) {
}
void CFX_TxtBreak::SetUserData(void* pUserData) {
- if (m_pUserData == pUserData) {
+ if (m_pUserData == pUserData)
return;
- }
+
SetBreakStatus();
m_pUserData = pUserData;
}
void CFX_TxtBreak::SetBreakStatus() {
- if (m_bPagination) {
+ if (m_bPagination)
return;
- }
+
int32_t iCount = m_pCurLine->CountChars();
- if (iCount < 1) {
+ if (iCount < 1)
return;
- }
+
CFX_TxtChar* pTC = m_pCurLine->GetCharPtr(iCount - 1);
- if (pTC->m_dwStatus == 0) {
+ if (pTC->m_dwStatus == 0)
pTC->m_dwStatus = FX_TXTBREAK_PieceBreak;
- }
}
void CFX_TxtBreak::SetHorizontalScale(int32_t iScale) {
- if (iScale < 0) {
+ if (iScale < 0)
iScale = 0;
- }
- if (iScale == m_iHorScale) {
+ if (iScale == m_iHorScale)
return;
- }
+
SetBreakStatus();
m_iHorScale = iScale;
}
@@ -248,6 +238,7 @@ void CFX_TxtBreak::SetCharSpace(FX_FLOAT fCharSpace) {
}
static const int32_t gs_FX_TxtLineRotations[8] = {0, 3, 1, 0, 2, 1, 3, 2};
+
int32_t CFX_TxtBreak::GetLineRotation(uint32_t dwStyles) const {
return gs_FX_TxtLineRotations[(dwStyles & 0x0E) >> 1];
}
@@ -255,18 +246,16 @@ int32_t CFX_TxtBreak::GetLineRotation(uint32_t dwStyles) const {
CFX_TxtChar* CFX_TxtBreak::GetLastChar(int32_t index, bool bOmitChar) const {
std::vector<CFX_TxtChar>& ca = *m_pCurLine->m_pLineChars.get();
int32_t iCount = pdfium::CollectionSize<int32_t>(ca);
- if (index < 0 || index >= iCount) {
+ if (index < 0 || index >= iCount)
return nullptr;
- }
+
int32_t iStart = iCount - 1;
while (iStart > -1) {
CFX_TxtChar* pTC = &ca[iStart--];
- if (bOmitChar && pTC->GetCharType() == FX_CHARTYPE_Combination) {
+ if (bOmitChar && pTC->GetCharType() == FX_CHARTYPE_Combination)
continue;
- }
- if (--index < 0) {
+ if (--index < 0)
return pTC;
- }
}
return nullptr;
}
@@ -281,10 +270,7 @@ CFX_TxtLine* CFX_TxtBreak::GetTxtLine() const {
CFX_TxtPieceArray* CFX_TxtBreak::GetTxtPieces() const {
CFX_TxtLine* pTxtLine = GetTxtLine();
- if (!pTxtLine) {
- return nullptr;
- }
- return pTxtLine->m_pLinePieces.get();
+ return pTxtLine ? pTxtLine->m_pLinePieces.get() : nullptr;
}
inline FX_CHARTYPE CFX_TxtBreak::GetUnifiedCharType(
@@ -307,11 +293,10 @@ void CFX_TxtBreak::ResetArabicContext() {
m_bCurRTL = m_bRTL;
m_iCurAlignment = m_iAlignment;
}
- if (m_bRTL) {
+ if (m_bRTL)
m_bArabicNumber = m_iArabicContext >= 1;
- } else {
+ else
m_bArabicNumber = m_iArabicContext > 1;
- }
m_bArabicNumber = m_bArabicNumber && m_bArabicShapes;
}
m_bArabicComma = m_bArabicNumber;
@@ -333,15 +318,14 @@ void CFX_TxtBreak::AppendChar_PageLoad(CFX_TxtChar* pCurChar,
: 1);
if (iArabicContext != m_iArabicContext && iArabicContext != 1) {
m_iArabicContext = iArabicContext;
- if (m_iCurArabicContext == 1) {
+ if (m_iCurArabicContext == 1)
m_iCurArabicContext = iArabicContext;
- }
+
ResetArabicContext();
if (!m_bPagination) {
CFX_TxtChar* pLastChar = GetLastChar(1, false);
- if (pLastChar && pLastChar->m_dwStatus < 1) {
+ if (pLastChar && pLastChar->m_dwStatus < 1)
pLastChar->m_dwStatus = FX_TXTBREAK_PieceBreak;
- }
}
}
}
@@ -385,9 +369,8 @@ uint32_t CFX_TxtBreak::AppendChar_Combination(CFX_TxtChar* pCurChar,
}
}
}
- if (!m_pFont->GetCharWidth(wForm, iCharWidth, false)) {
+ if (!m_pFont->GetCharWidth(wForm, iCharWidth, false))
iCharWidth = 0;
- }
}
iCharWidth *= m_iFontSize;
iCharWidth = iCharWidth * m_iHorScale / 100;
@@ -399,9 +382,9 @@ uint32_t CFX_TxtBreak::AppendChar_Combination(CFX_TxtChar* pCurChar,
uint32_t CFX_TxtBreak::AppendChar_Tab(CFX_TxtChar* pCurChar,
int32_t iRotation) {
m_eCharType = FX_CHARTYPE_Tab;
- if ((m_dwLayoutStyles & FX_TXTLAYOUTSTYLE_ExpandTab) == 0) {
+ if ((m_dwLayoutStyles & FX_TXTLAYOUTSTYLE_ExpandTab) == 0)
return FX_TXTBREAK_None;
- }
+
int32_t& iLineWidth = m_pCurLine->m_iWidth;
int32_t iCharWidth;
if (m_bCombText) {
@@ -410,18 +393,18 @@ uint32_t CFX_TxtBreak::AppendChar_Tab(CFX_TxtChar* pCurChar,
if (m_bEquidistant) {
iCharWidth = iLineWidth;
iCharWidth = m_iTabWidth * (iCharWidth / m_iTabWidth + 1) - iCharWidth;
- if (iCharWidth < FX_TXTBREAK_MinimumTabWidth) {
+ if (iCharWidth < FX_TXTBREAK_MinimumTabWidth)
iCharWidth += m_iTabWidth;
- }
} else {
iCharWidth = m_iTabWidth;
}
}
+
pCurChar->m_iCharWidth = iCharWidth;
iLineWidth += iCharWidth;
- if (!m_bSingleLine && iLineWidth >= m_iLineWidth + m_iTolerance) {
+ if (!m_bSingleLine && iLineWidth >= m_iLineWidth + m_iTolerance)
return EndBreak(FX_TXTBREAK_LineBreak);
- }
+
return FX_TXTBREAK_None;
}
@@ -443,14 +426,12 @@ uint32_t CFX_TxtBreak::AppendChar_Control(CFX_TxtChar* pCurChar,
dwRet = FX_TXTBREAK_ParagraphBreak;
break;
default:
- if (wch == m_wParagBreakChar) {
+ if (wch == m_wParagBreakChar)
dwRet = FX_TXTBREAK_ParagraphBreak;
- }
break;
}
- if (dwRet != FX_TXTBREAK_None) {
+ if (dwRet != FX_TXTBREAK_None)
dwRet = EndBreak(dwRet);
- }
}
return dwRet;
}
@@ -468,25 +449,24 @@ uint32_t CFX_TxtBreak::AppendChar_Arabic(CFX_TxtChar* pCurChar,
pLastChar = GetLastChar(1);
if (pLastChar) {
iCharWidth = pLastChar->m_iCharWidth;
- if (iCharWidth > 0) {
+ if (iCharWidth > 0)
iLineWidth -= iCharWidth;
- }
+
CFX_Char* pPrevChar = GetLastChar(2);
wForm = pdfium::arabic::GetFormChar(pLastChar, pPrevChar, pCurChar);
bAlef = (wForm == 0xFEFF &&
pLastChar->GetCharType() == FX_CHARTYPE_ArabicAlef);
int32_t iLastRotation = pLastChar->m_nRotation + m_iLineRotation;
- if (m_bVertical && (pLastChar->m_dwCharProps & 0x8000) != 0) {
+ if (m_bVertical && (pLastChar->m_dwCharProps & 0x8000) != 0)
iLastRotation++;
- }
- if (m_bVertical != FX_IsOdd(iLastRotation)) {
+ if (m_bVertical != FX_IsOdd(iLastRotation))
iCharWidth = 1000;
- } else {
+ else
m_pFont->GetCharWidth(wForm, iCharWidth, false);
- }
- if (wForm == 0xFEFF) {
+
+ if (wForm == 0xFEFF)
iCharWidth = m_iDefChar;
- }
+
iCharWidth *= m_iFontSize;
iCharWidth = iCharWidth * m_iHorScale / 100;
pLastChar->m_iCharWidth = iCharWidth;
@@ -494,29 +474,29 @@ uint32_t CFX_TxtBreak::AppendChar_Arabic(CFX_TxtChar* pCurChar,
iCharWidth = 0;
}
}
+
m_eCharType = chartype;
wForm = pdfium::arabic::GetFormChar(pCurChar, bAlef ? nullptr : pLastChar,
nullptr);
if (m_bCombText) {
iCharWidth = m_iCombWidth;
} else {
- if (m_bVertical != FX_IsOdd(iRotation)) {
+ if (m_bVertical != FX_IsOdd(iRotation))
iCharWidth = 1000;
- } else {
+ else
m_pFont->GetCharWidth(wForm, iCharWidth, false);
- }
- if (wForm == 0xFEFF) {
+
+ if (wForm == 0xFEFF)
iCharWidth = m_iDefChar;
- }
+
iCharWidth *= m_iFontSize;
iCharWidth = iCharWidth * m_iHorScale / 100;
}
pCurChar->m_iCharWidth = iCharWidth;
iLineWidth += iCharWidth;
m_pCurLine->m_iArabicChars++;
- if (!m_bSingleLine && iLineWidth > m_iLineWidth + m_iTolerance) {
+ if (!m_bSingleLine && iLineWidth > m_iLineWidth + m_iTolerance)
return EndBreak(FX_TXTBREAK_LineBreak);
- }
return FX_TXTBREAK_None;
}
@@ -542,34 +522,37 @@ uint32_t CFX_TxtBreak::AppendChar_Others(CFX_TxtChar* pCurChar,
} else if (m_bCurRTL || m_bVertical) {
wForm = FX_GetMirrorChar(wch, dwProps, m_bCurRTL, m_bVertical);
}
+
if (m_bCombText) {
iCharWidth = m_iCombWidth;
} else {
- if (m_bVertical != FX_IsOdd(iRotation)) {
+ if (m_bVertical != FX_IsOdd(iRotation))
iCharWidth = 1000;
- } else if (!m_pFont->GetCharWidth(wForm, iCharWidth, false)) {
+ else if (!m_pFont->GetCharWidth(wForm, iCharWidth, false))
iCharWidth = m_iDefChar;
- }
+
iCharWidth *= m_iFontSize;
iCharWidth = iCharWidth * m_iHorScale / 100;
}
+
iCharWidth += m_iCharSpace;
pCurChar->m_iCharWidth = iCharWidth;
iLineWidth += iCharWidth;
bool bBreak = (chartype != FX_CHARTYPE_Space ||
(m_dwPolicies & FX_TXTBREAKPOLICY_SpaceBreak) != 0);
- if (!m_bSingleLine && bBreak && iLineWidth > m_iLineWidth + m_iTolerance) {
+ if (!m_bSingleLine && bBreak && iLineWidth > m_iLineWidth + m_iTolerance)
return EndBreak(FX_TXTBREAK_LineBreak);
- }
+
return FX_TXTBREAK_None;
}
uint32_t CFX_TxtBreak::AppendChar(FX_WCHAR wch) {
- uint32_t dwProps = kTextLayoutCodeProperties[(uint16_t)wch];
+ uint32_t dwProps = kTextLayoutCodeProperties[static_cast<uint16_t>(wch)];
FX_CHARTYPE chartype = GetCharTypeFromProp(dwProps);
m_pCurLine->m_pLineChars->emplace_back();
+
CFX_TxtChar* pCurChar = &m_pCurLine->m_pLineChars->back();
- pCurChar->m_wCharCode = (uint16_t)wch;
+ pCurChar->m_wCharCode = static_cast<uint16_t>(wch);
pCurChar->m_nRotation = m_iCharRotation;
pCurChar->m_dwCharProps = dwProps;
pCurChar->m_dwCharStyles = 0;
@@ -585,22 +568,20 @@ uint32_t CFX_TxtBreak::AppendChar(FX_WCHAR wch) {
AppendChar_PageLoad(pCurChar, dwProps);
uint32_t dwRet1 = FX_TXTBREAK_None;
if (chartype != FX_CHARTYPE_Combination &&
- GetUnifiedCharType(m_eCharType) != GetUnifiedCharType(chartype)) {
- if (m_eCharType != FX_CHARTYPE_Unknown &&
- m_pCurLine->m_iWidth > m_iLineWidth + m_iTolerance && !m_bSingleLine) {
- if (m_eCharType != FX_CHARTYPE_Space || chartype != FX_CHARTYPE_Control) {
- dwRet1 = EndBreak(FX_TXTBREAK_LineBreak);
- int32_t iCount = m_pCurLine->CountChars();
- if (iCount > 0) {
- pCurChar = &(*m_pCurLine->m_pLineChars)[iCount - 1];
- }
- }
- }
+ GetUnifiedCharType(m_eCharType) != GetUnifiedCharType(chartype) &&
+ m_eCharType != FX_CHARTYPE_Unknown &&
+ m_pCurLine->m_iWidth > m_iLineWidth + m_iTolerance && !m_bSingleLine &&
+ (m_eCharType != FX_CHARTYPE_Space || chartype != FX_CHARTYPE_Control)) {
+ dwRet1 = EndBreak(FX_TXTBREAK_LineBreak);
+ int32_t iCount = m_pCurLine->CountChars();
+ if (iCount > 0)
+ pCurChar = &(*m_pCurLine->m_pLineChars)[iCount - 1];
}
+
int32_t iRotation = m_iRotation;
- if (m_bVertical && (dwProps & 0x8000) != 0) {
+ if (m_bVertical && (dwProps & 0x8000) != 0)
iRotation = (iRotation + 1) % 4;
- }
+
uint32_t dwRet2 =
(this->*g_FX_TxtBreak_lpfAppendChar[chartype >> FX_CHARTYPEBITS])(
pCurChar, iRotation);
@@ -610,9 +591,9 @@ uint32_t CFX_TxtBreak::AppendChar(FX_WCHAR wch) {
void CFX_TxtBreak::EndBreak_UpdateArabicShapes() {
ASSERT(m_bArabicShapes);
int32_t iCount = m_pCurLine->CountChars();
- if (iCount < 2) {
+ if (iCount < 2)
return;
- }
+
int32_t& iLineWidth = m_pCurLine->m_iWidth;
CFX_TxtChar* pCur = m_pCurLine->GetCharPtr(0);
bool bPrevNum = (pCur->m_dwCharStyles & FX_TXTCHARSTYLE_ArabicIndic) != 0;
@@ -632,23 +613,24 @@ void CFX_TxtBreak::EndBreak_UpdateArabicShapes() {
pNext = nullptr;
bNextNum = false;
}
+
wch = pCur->m_wCharCode;
if (wch == L'.') {
if (bPrevNum && bNextNum) {
iRotation = m_iRotation;
- if (m_bVertical && (pCur->m_dwCharProps & 0x8000) != 0) {
+ if (m_bVertical && (pCur->m_dwCharProps & 0x8000) != 0)
iRotation = ((iRotation + 1) & 0x03);
- }
+
wForm = wch == L'.' ? 0x066B : 0x066C;
iLineWidth -= pCur->m_iCharWidth;
if (m_bCombText) {
iCharWidth = m_iCombWidth;
} else {
- if (m_bVertical != FX_IsOdd(iRotation)) {
+ if (m_bVertical != FX_IsOdd(iRotation))
iCharWidth = 1000;
- } else if (!m_pFont->GetCharWidth(wForm, iCharWidth, false)) {
+ else if (!m_pFont->GetCharWidth(wForm, iCharWidth, false))
iCharWidth = m_iDefChar;
- }
+
iCharWidth *= m_iFontSize;
iCharWidth = iCharWidth * m_iHorScale / 100;
}
@@ -685,6 +667,7 @@ bool CFX_TxtBreak::EndBreak_SplitLine(CFX_TxtLine* pNextLine,
break;
}
}
+
iCount = m_pCurLine->CountChars();
CFX_TxtPieceArray* pCurPieces = m_pCurLine->m_pLinePieces.get();
CFX_TxtPiece tp;
@@ -716,7 +699,8 @@ void CFX_TxtBreak::EndBreak_BidiLine(CFX_TPOArray& tpos, uint32_t dwStatus) {
CFX_TxtPiece tp;
FX_TPO tpo;
CFX_TxtChar* pTC;
- int32_t i, j;
+ int32_t i;
+ int32_t j;
std::vector<CFX_TxtChar>& chars = *m_pCurLine->m_pLineChars.get();
int32_t iCount = m_pCurLine->CountChars();
bool bDone = (m_pCurLine->m_iArabicChars > 0 || m_bCurRTL);
@@ -725,23 +709,24 @@ void CFX_TxtBreak::EndBreak_BidiLine(CFX_TPOArray& tpos, uint32_t dwStatus) {
for (i = 0; i < iCount; i++) {
pTC = &chars[i];
pTC->m_iBidiPos = i;
- if (pTC->GetCharType() != FX_CHARTYPE_Control) {
+ if (pTC->GetCharType() != FX_CHARTYPE_Control)
iBidiNum = i;
- }
- if (i == 0) {
+ if (i == 0)
pTC->m_iBidiLevel = 1;
- }
}
FX_BidiLine(chars, iBidiNum + 1, m_bCurRTL ? 1 : 0);
}
+
CFX_TxtPieceArray* pCurPieces = m_pCurLine->m_pLinePieces.get();
if (!m_bPagination &&
(bDone || (m_dwLayoutStyles & FX_TXTLAYOUTSTYLE_MutipleFormat) != 0)) {
tp.m_dwStatus = FX_TXTBREAK_PieceBreak;
tp.m_iStartPos = m_pCurLine->m_iStart;
tp.m_pChars = m_pCurLine->m_pLineChars.get();
- int32_t iBidiLevel = -1, iCharWidth;
- i = 0, j = -1;
+ int32_t iBidiLevel = -1;
+ int32_t iCharWidth;
+ i = 0;
+ j = -1;
while (i < iCount) {
pTC = &chars[i];
if (iBidiLevel < 0) {
@@ -759,9 +744,9 @@ void CFX_TxtBreak::EndBreak_BidiLine(CFX_TPOArray& tpos, uint32_t dwStatus) {
if (iBidiLevel == pTC->m_iBidiLevel) {
tp.m_dwStatus = pTC->m_dwStatus;
iCharWidth = pTC->m_iCharWidth;
- if (iCharWidth > 0) {
+ if (iCharWidth > 0)
tp.m_iWidth += iCharWidth;
- }
+
i++;
}
tp.m_iChars = i - tp.m_iStartChar;
@@ -774,9 +759,9 @@ void CFX_TxtBreak::EndBreak_BidiLine(CFX_TPOArray& tpos, uint32_t dwStatus) {
iBidiLevel = -1;
} else {
iCharWidth = pTC->m_iCharWidth;
- if (iCharWidth > 0) {
+ if (iCharWidth > 0)
tp.m_iWidth += iCharWidth;
- }
+
i++;
}
}
@@ -824,9 +809,13 @@ void CFX_TxtBreak::EndBreak_BidiLine(CFX_TPOArray& tpos, uint32_t dwStatus) {
void CFX_TxtBreak::EndBreak_Alignment(CFX_TPOArray& tpos,
bool bAllChars,
uint32_t dwStatus) {
- int32_t iNetWidth = m_pCurLine->m_iWidth, iGapChars = 0, iCharWidth;
+ int32_t iNetWidth = m_pCurLine->m_iWidth;
+ int32_t iGapChars = 0;
+ int32_t iCharWidth;
CFX_TxtPieceArray* pCurPieces = m_pCurLine->m_pLinePieces.get();
- int32_t i, j, iCount = pCurPieces->GetSize();
+ int32_t i;
+ int32_t j;
+ int32_t iCount = pCurPieces->GetSize();
bool bFind = false;
FX_TPO tpo;
CFX_TxtChar* pTC;
@@ -834,38 +823,35 @@ void CFX_TxtBreak::EndBreak_Alignment(CFX_TPOArray& tpos,
for (i = iCount - 1; i > -1; i--) {
tpo = tpos.GetAt(i);
CFX_TxtPiece& ttp = pCurPieces->GetAt(tpo.index);
- if (!bFind) {
+ if (!bFind)
iNetWidth = ttp.GetEndPos();
- }
+
bool bArabic = FX_IsOdd(ttp.m_iBidiLevel);
j = bArabic ? 0 : ttp.m_iChars - 1;
while (j > -1 && j < ttp.m_iChars) {
pTC = ttp.GetCharPtr(j);
- if (pTC->m_nBreakType == FX_LBT_DIRECT_BRK) {
+ if (pTC->m_nBreakType == FX_LBT_DIRECT_BRK)
iGapChars++;
- }
if (!bFind || !bAllChars) {
chartype = pTC->GetCharType();
if (chartype == FX_CHARTYPE_Space || chartype == FX_CHARTYPE_Control) {
if (!bFind) {
iCharWidth = pTC->m_iCharWidth;
- if (bAllChars && iCharWidth > 0) {
+ if (bAllChars && iCharWidth > 0)
iNetWidth -= iCharWidth;
- }
}
} else {
bFind = true;
- if (!bAllChars) {
+ if (!bAllChars)
break;
- }
}
}
j += bArabic ? 1 : -1;
}
- if (!bAllChars && bFind) {
+ if (!bAllChars && bFind)
break;
- }
}
+
int32_t iOffset = m_iLineWidth - iNetWidth;
int32_t iLowerAlignment = (m_iCurAlignment & FX_TXTLINEALIGNMENT_LowerMask);
int32_t iHigherAlignment = (m_iCurAlignment & FX_TXTLINEALIGNMENT_HigherMask);
@@ -876,32 +862,29 @@ void CFX_TxtBreak::EndBreak_Alignment(CFX_TPOArray& tpos,
for (i = 0; i < iCount; i++) {
tpo = tpos.GetAt(i);
CFX_TxtPiece& ttp = pCurPieces->GetAt(tpo.index);
- if (iStart < -1) {
+ if (iStart < -1)
iStart = ttp.m_iStartPos;
- } else {
+ else
ttp.m_iStartPos = iStart;
- }
- int32_t k;
+
for (j = 0; j < ttp.m_iChars; j++) {
pTC = ttp.GetCharPtr(j);
- if (pTC->m_nBreakType != FX_LBT_DIRECT_BRK || pTC->m_iCharWidth < 0) {
+ if (pTC->m_nBreakType != FX_LBT_DIRECT_BRK || pTC->m_iCharWidth < 0)
continue;
- }
- k = iOffset / iGapChars;
+
+ int32_t k = iOffset / iGapChars;
pTC->m_iCharWidth += k;
ttp.m_iWidth += k;
iOffset -= k;
iGapChars--;
- if (iGapChars < 1) {
+ if (iGapChars < 1)
break;
- }
}
iStart += ttp.m_iWidth;
}
} else if (iLowerAlignment > FX_TXTLINEALIGNMENT_Left) {
- if (iLowerAlignment == FX_TXTLINEALIGNMENT_Center) {
+ if (iLowerAlignment == FX_TXTLINEALIGNMENT_Center)
iOffset /= 2;
- }
if (iOffset > 0) {
for (i = 0; i < iCount; i++) {
CFX_TxtPiece& ttp = pCurPieces->GetAt(i);
@@ -918,11 +901,10 @@ uint32_t CFX_TxtBreak::EndBreak(uint32_t dwStatus) {
int32_t iCount = pCurPieces->GetSize();
if (iCount > 0) {
CFX_TxtPiece* pLastPiece = pCurPieces->GetPtrAt(--iCount);
- if (dwStatus > FX_TXTBREAK_PieceBreak) {
+ if (dwStatus > FX_TXTBREAK_PieceBreak)
pLastPiece->m_dwStatus = dwStatus;
- } else {
+ else
dwStatus = pLastPiece->m_dwStatus;
- }
return dwStatus;
} else {
CFX_TxtLine* pLastLine = GetTxtLine();
@@ -931,44 +913,40 @@ uint32_t CFX_TxtBreak::EndBreak(uint32_t dwStatus) {
iCount = pCurPieces->GetSize();
if (iCount-- > 0) {
CFX_TxtPiece* pLastPiece = pCurPieces->GetPtrAt(iCount);
- if (dwStatus > FX_TXTBREAK_PieceBreak) {
+ if (dwStatus > FX_TXTBREAK_PieceBreak)
pLastPiece->m_dwStatus = dwStatus;
- } else {
+ else
dwStatus = pLastPiece->m_dwStatus;
- }
return dwStatus;
}
return FX_TXTBREAK_None;
}
+
iCount = m_pCurLine->CountChars();
- if (iCount < 1) {
+ if (iCount < 1)
return FX_TXTBREAK_None;
- }
if (!m_bPagination) {
CFX_TxtChar* pTC = m_pCurLine->GetCharPtr(iCount - 1);
pTC->m_dwStatus = dwStatus;
}
- if (dwStatus <= FX_TXTBREAK_PieceBreak) {
+ if (dwStatus <= FX_TXTBREAK_PieceBreak)
return dwStatus;
- }
}
+
m_iReady = (m_pCurLine == m_pTxtLine1.get()) ? 1 : 2;
CFX_TxtLine* pNextLine =
(m_pCurLine == m_pTxtLine1.get()) ? m_pTxtLine2.get() : m_pTxtLine1.get();
bool bAllChars = (m_iCurAlignment > FX_TXTLINEALIGNMENT_Right);
CFX_TPOArray tpos(100);
CFX_Char* pTC;
- if (m_bArabicShapes) {
+ if (m_bArabicShapes)
EndBreak_UpdateArabicShapes();
+ if (!EndBreak_SplitLine(pNextLine, bAllChars, dwStatus)) {
+ EndBreak_BidiLine(tpos, dwStatus);
+ if (!m_bPagination && m_iCurAlignment > FX_TXTLINEALIGNMENT_Left)
+ EndBreak_Alignment(tpos, bAllChars, dwStatus);
}
- if (EndBreak_SplitLine(pNextLine, bAllChars, dwStatus)) {
- goto EndBreak_Ret;
- }
- EndBreak_BidiLine(tpos, dwStatus);
- if (!m_bPagination && m_iCurAlignment > FX_TXTLINEALIGNMENT_Left) {
- EndBreak_Alignment(tpos, bAllChars, dwStatus);
- }
-EndBreak_Ret:
+
m_pCurLine = pNextLine;
pTC = GetLastChar(0, false);
m_eCharType = pTC ? pTC->GetCharType() : FX_CHARTYPE_Unknown;
@@ -984,63 +962,66 @@ int32_t CFX_TxtBreak::GetBreakPos(std::vector<CFX_TxtChar>& ca,
bool bAllChars,
bool bOnlyBrk) {
int32_t iLength = pdfium::CollectionSize<int32_t>(ca) - 1;
- if (iLength < 1) {
+ if (iLength < 1)
return iLength;
- }
- int32_t iBreak = -1, iBreakPos = -1, iIndirect = -1, iIndirectPos = -1,
- iLast = -1, iLastPos = -1;
+
+ int32_t iBreak = -1;
+ int32_t iBreakPos = -1;
+ int32_t iIndirect = -1;
+ int32_t iIndirectPos = -1;
+ int32_t iLast = -1;
+ int32_t iLastPos = -1;
if (m_bSingleLine || iEndPos <= m_iLineWidth) {
- if (!bAllChars) {
+ if (!bAllChars)
return iLength;
- }
+
iBreak = iLength;
iBreakPos = iEndPos;
}
+
bool bSpaceBreak = (m_dwPolicies & FX_TXTBREAKPOLICY_SpaceBreak) != 0;
bool bNumberBreak = (m_dwPolicies & FX_TXTBREAKPOLICY_NumberBreak) != 0;
FX_LINEBREAKTYPE eType;
- uint32_t nCodeProp, nCur, nNext;
+ uint32_t nCodeProp;
+ uint32_t nCur;
+ uint32_t nNext;
CFX_Char* pCur = &ca[iLength--];
- if (bAllChars) {
+ if (bAllChars)
pCur->m_nBreakType = FX_LBT_UNKNOWN;
- }
+
nCodeProp = pCur->m_dwCharProps;
nNext = nCodeProp & 0x003F;
int32_t iCharWidth = pCur->m_iCharWidth;
- if (iCharWidth > 0) {
+ if (iCharWidth > 0)
iEndPos -= iCharWidth;
- }
+
while (iLength >= 0) {
pCur = &ca[iLength];
nCodeProp = pCur->m_dwCharProps;
nCur = nCodeProp & 0x003F;
if (nCur == FX_CBP_SP) {
- if (nNext == FX_CBP_SP) {
+ if (nNext == FX_CBP_SP)
eType = bSpaceBreak ? FX_LBT_DIRECT_BRK : FX_LBT_PROHIBITED_BRK;
- } else {
+ else
eType = gs_FX_LineBreak_PairTable[nCur][nNext];
- }
} else if (bNumberBreak && nCur == FX_CBP_NU && nNext == FX_CBP_NU) {
eType = FX_LBT_DIRECT_BRK;
} else {
- if (nNext == FX_CBP_SP) {
+ if (nNext == FX_CBP_SP)
eType = FX_LBT_PROHIBITED_BRK;
- } else {
+ else
eType = gs_FX_LineBreak_PairTable[nCur][nNext];
- }
- }
- if (bAllChars) {
- pCur->m_nBreakType = (uint8_t)eType;
}
+ if (bAllChars)
+ pCur->m_nBreakType = static_cast<uint8_t>(eType);
if (!bOnlyBrk) {
if (m_bSingleLine || iEndPos <= m_iLineWidth ||
(nCur == FX_CBP_SP && !bSpaceBreak)) {
if (eType == FX_LBT_DIRECT_BRK && iBreak < 0) {
iBreak = iLength;
iBreakPos = iEndPos;
- if (!bAllChars) {
+ if (!bAllChars)
return iLength;
- }
} else if (eType == FX_LBT_INDIRECT_BRK && iIndirect < 0) {
iIndirect = iLength;
iIndirectPos = iEndPos;
@@ -1051,16 +1032,14 @@ int32_t CFX_TxtBreak::GetBreakPos(std::vector<CFX_TxtChar>& ca,
}
}
iCharWidth = pCur->m_iCharWidth;
- if (iCharWidth > 0) {
+ if (iCharWidth > 0)
iEndPos -= iCharWidth;
- }
}
nNext = nCodeProp & 0x003F;
iLength--;
}
- if (bOnlyBrk) {
+ if (bOnlyBrk)
return 0;
- }
if (iBreak > -1) {
iEndPos = iBreakPos;
return iBreak;
@@ -1081,15 +1060,15 @@ void CFX_TxtBreak::SplitTextLine(CFX_TxtLine* pCurLine,
bool bAllChars) {
ASSERT(pCurLine && pNextLine);
int32_t iCount = pCurLine->CountChars();
- if (iCount < 2) {
+ if (iCount < 2)
return;
- }
+
int32_t iEndPos = pCurLine->m_iWidth;
std::vector<CFX_TxtChar>& curChars = *pCurLine->m_pLineChars;
int32_t iCharPos = GetBreakPos(curChars, iEndPos, bAllChars, false);
- if (iCharPos < 0) {
+ if (iCharPos < 0)
iCharPos = 0;
- }
+
iCharPos++;
if (iCharPos >= iCount) {
pNextLine->RemoveAll(true);
@@ -1097,6 +1076,9 @@ void CFX_TxtBreak::SplitTextLine(CFX_TxtLine* pCurLine,
pTC->m_nBreakType = FX_LBT_UNKNOWN;
return;
}
+
+ // m_pLineChars is a unique_ptr<vector>. Assign the ref into nextChars
+ // so we can change the m_pLineChars vector ...
std::vector<CFX_TxtChar>& nextChars = *pNextLine->m_pLineChars;
nextChars =
std::vector<CFX_TxtChar>(curChars.begin() + iCharPos, curChars.end());
@@ -1107,17 +1089,17 @@ void CFX_TxtBreak::SplitTextLine(CFX_TxtLine* pCurLine,
iCount = pdfium::CollectionSize<int>(nextChars);
int32_t iWidth = 0;
for (int32_t i = 0; i < iCount; i++) {
- pTC = &nextChars[i];
- if (pTC->GetCharType() >= FX_CHARTYPE_ArabicAlef) {
+ if (nextChars[i].GetCharType() >= FX_CHARTYPE_ArabicAlef) {
pCurLine->m_iArabicChars--;
pNextLine->m_iArabicChars++;
}
- int32_t iCharWidth = pTC->m_iCharWidth;
+ int32_t iCharWidth = nextChars[i].m_iCharWidth;
if (iCharWidth > 0)
iWidth += iCharWidth;
if (m_bPagination)
continue;
- pTC->m_dwStatus = 0;
+
+ nextChars[i].m_dwStatus = 0;
}
pNextLine->m_iWidth = iWidth;
}
@@ -1129,26 +1111,24 @@ int32_t CFX_TxtBreak::CountBreakPieces() const {
const CFX_TxtPiece* CFX_TxtBreak::GetBreakPiece(int32_t index) const {
CFX_TxtPieceArray* pTxtPieces = GetTxtPieces();
- if (!pTxtPieces) {
+ if (!pTxtPieces)
return nullptr;
- }
- if (index < 0 || index >= pTxtPieces->GetSize()) {
+ if (index < 0 || index >= pTxtPieces->GetSize())
return nullptr;
- }
return pTxtPieces->GetPtrAt(index);
}
void CFX_TxtBreak::ClearBreakPieces() {
CFX_TxtLine* pTxtLine = GetTxtLine();
- if (pTxtLine) {
+ if (pTxtLine)
pTxtLine->RemoveAll(true);
- }
m_iReady = 0;
}
void CFX_TxtBreak::Reset() {
m_eCharType = FX_CHARTYPE_Unknown;
- m_iArabicContext = m_iCurArabicContext = 1;
+ m_iArabicContext = 1;
+ m_iCurArabicContext = 1;
ResetArabicContext();
m_pTxtLine1->RemoveAll(true);
m_pTxtLine2->RemoveAll(true);
@@ -1165,9 +1145,9 @@ int32_t CFX_TxtBreak::GetDisplayPos(const FX_TXTRUN* pTxtRun,
bool bCharCode,
CFX_WideString* pWSForms,
FX_AdjustCharDisplayPos pAdjustPos) const {
- if (!pTxtRun || pTxtRun->iLength < 1) {
+ if (!pTxtRun || pTxtRun->iLength < 1)
return 0;
- }
+
IFX_TxtAccess* pAccess = pTxtRun->pAccess;
const FDE_TEXTEDITPIECE* pIdentity = pTxtRun->pIdentity;
const FX_WCHAR* pStr = pTxtRun->wsStr.c_str();
@@ -1192,24 +1172,28 @@ int32_t CFX_TxtBreak::GetDisplayPos(const FX_TXTRUN* pTxtRun,
bool bVerticalDoc = (dwStyles & FX_TXTLAYOUTSTYLE_VerticalLayout) != 0;
bool bVerticalChar = (dwStyles & FX_TXTLAYOUTSTYLE_VerticalChars) != 0;
int32_t iRotation = GetLineRotation(dwStyles) + pTxtRun->iCharRotation;
- FX_FLOAT fX, fY, fCharWidth, fCharHeight;
+ FX_FLOAT fX = rtText.left;
+ FX_FLOAT fY;
+ FX_FLOAT fCharWidth;
+ FX_FLOAT fCharHeight;
int32_t iHorScale = pTxtRun->iHorizontalScale;
int32_t iVerScale = pTxtRun->iVerticalScale;
bool bSkipSpace = pTxtRun->bSkipSpace;
FX_FORMCHAR formChars[3];
FX_FLOAT fYBase;
- fX = rtText.left;
+
if (bVerticalDoc) {
fX += (rtText.width - fFontSize) / 2.0f;
fYBase = bRTLPiece ? rtText.bottom() : rtText.top;
fY = fYBase;
} else {
- if (bRTLPiece) {
+ if (bRTLPiece)
fX = rtText.right();
- }
+
fYBase = rtText.top + (rtText.height - fFontSize) / 2.0f;
fY = fYBase + fAscent;
}
+
int32_t iCount = 0;
int32_t iNext = 0;
FX_WCHAR wPrev = 0xFEFF;
@@ -1228,6 +1212,7 @@ int32_t CFX_TxtBreak::GetDisplayPos(const FX_TXTRUN* pTxtRun,
wch = *pStr++;
iWidth = *pWidths++;
}
+
uint32_t dwProps = FX_GetUnicodeProperties(wch);
FX_CHARTYPE chartype = GetCharTypeFromProp(dwProps);
if (chartype == FX_CHARTYPE_ArabicAlef && iWidth == 0) {
@@ -1235,6 +1220,7 @@ int32_t CFX_TxtBreak::GetDisplayPos(const FX_TXTRUN* pTxtRun,
wLast = wch;
continue;
}
+
if (chartype >= FX_CHARTYPE_ArabicAlef) {
if (i < iLength) {
if (pAccess) {
@@ -1242,31 +1228,30 @@ int32_t CFX_TxtBreak::GetDisplayPos(const FX_TXTRUN* pTxtRun,
while (iNext <= iLength) {
wNext = pAccess->GetChar(pIdentity, iNext);
dwProps = FX_GetUnicodeProperties(wNext);
- if ((dwProps & FX_CHARTYPEBITSMASK) != FX_CHARTYPE_Combination) {
+ if ((dwProps & FX_CHARTYPEBITSMASK) != FX_CHARTYPE_Combination)
break;
- }
+
iNext++;
}
- if (iNext > iLength) {
+ if (iNext > iLength)
wNext = 0xFEFF;
- }
} else {
int32_t j = -1;
do {
j++;
- if (i + j >= iLength) {
+ if (i + j >= iLength)
break;
- }
+
wNext = pStr[j];
dwProps = FX_GetUnicodeProperties(wNext);
} while ((dwProps & FX_CHARTYPEBITSMASK) == FX_CHARTYPE_Combination);
- if (i + j >= iLength) {
+ if (i + j >= iLength)
wNext = 0xFEFF;
- }
}
} else {
wNext = 0xFEFF;
}
+
wForm = pdfium::arabic::GetFormChar(wch, wPrev, wNext);
bLam = (wPrev == 0x0644 && wch == 0x0644 && wNext == 0x0647);
} else if (chartype == FX_CHARTYPE_Combination) {
@@ -1279,13 +1264,11 @@ int32_t CFX_TxtBreak::GetDisplayPos(const FX_TXTRUN* pTxtRun,
wNext = 0xFEFF;
if (pAccess) {
iNext = i + 1;
- if (iNext <= iLength) {
+ if (iNext <= iLength)
wNext = pAccess->GetChar(pIdentity, iNext);
- }
} else {
- if (i < iLength) {
+ if (i < iLength)
wNext = *pStr;
- }
}
if (wch == 0x0651) {
if (wNext >= 0x064C && wNext <= 0x0650) {
@@ -1304,67 +1287,61 @@ int32_t CFX_TxtBreak::GetDisplayPos(const FX_TXTRUN* pTxtRun,
}
} else if (chartype == FX_CHARTYPE_Numeric) {
wForm = wch;
- if (bArabicNumber) {
+ if (bArabicNumber)
wForm += 0x0630;
- }
} else if (wch == L'.') {
wForm = wch;
if (bArabicNumber) {
wNext = 0xFEFF;
if (pAccess) {
iNext = i + 1;
- if (iNext <= iLength) {
+ if (iNext <= iLength)
wNext = pAccess->GetChar(pIdentity, iNext);
- }
} else {
- if (i < iLength) {
+ if (i < iLength)
wNext = *pStr;
- }
}
- if (wNext >= L'0' && wNext <= L'9') {
+ if (wNext >= L'0' && wNext <= L'9')
wForm = 0x066B;
- }
}
} else if (wch == L',') {
wForm = wch;
- if (bArabicComma) {
+ if (bArabicComma)
wForm = 0x060C;
- }
} else if (bRTLPiece || bVerticalChar) {
wForm = FX_GetMirrorChar(wch, dwProps, bRTLPiece, bVerticalChar);
} else {
wForm = wch;
}
- if (chartype != FX_CHARTYPE_Combination) {
+ if (chartype != FX_CHARTYPE_Combination)
bShadda = false;
- }
- if (chartype < FX_CHARTYPE_ArabicAlef) {
+ if (chartype < FX_CHARTYPE_ArabicAlef)
bLam = false;
- }
+
dwProps = FX_GetUnicodeProperties(wForm);
int32_t iCharRotation = iRotation;
- if (bVerticalChar && (dwProps & 0x8000) != 0) {
+ if (bVerticalChar && (dwProps & 0x8000) != 0)
iCharRotation++;
- }
+
iCharRotation %= 4;
bool bEmptyChar =
(chartype >= FX_CHARTYPE_Tab && chartype <= FX_CHARTYPE_Control);
- if (wForm == 0xFEFF) {
+ if (wForm == 0xFEFF)
bEmptyChar = true;
- }
+
int32_t iForms = bLam ? 3 : 1;
iCount += (bEmptyChar && bSkipSpace) ? 0 : iForms;
if (!pCharPos) {
- if (iWidth > 0) {
+ if (iWidth > 0)
wPrev = wch;
- }
wLast = wch;
continue;
}
+
int32_t iCharWidth = iWidth;
- if (iCharWidth < 0) {
+ if (iCharWidth < 0)
iCharWidth = -iCharWidth;
- }
+
iCharWidth /= iFontSize;
formChars[0].wch = wch;
formChars[0].wForm = wForm;
@@ -1379,6 +1356,7 @@ int32_t CFX_TxtBreak::GetDisplayPos(const FX_TXTRUN* pTxtRun,
pFont->GetCharWidth(0x0670, iCharWidth, false);
formChars[2].iWidth = iCharWidth;
}
+
for (int32_t j = 0; j < iForms; j++) {
wForm = (FX_WCHAR)formChars[j].wForm;
iCharWidth = formChars[j].iWidth;
@@ -1394,10 +1372,10 @@ int32_t CFX_TxtBreak::GetDisplayPos(const FX_TXTRUN* pTxtRun,
pCharPos->m_ExtGID = pCharPos->m_GlyphIndex;
#endif
pCharPos->m_FontCharWidth = iCharWidth;
- if (pWSForms) {
+ if (pWSForms)
*pWSForms += wForm;
- }
}
+
int32_t iCharHeight;
if (bVerticalDoc) {
iCharHeight = iCharWidth;
@@ -1405,14 +1383,14 @@ int32_t CFX_TxtBreak::GetDisplayPos(const FX_TXTRUN* pTxtRun,
} else {
iCharHeight = 1000;
}
+
fCharWidth = fFontSize * iCharWidth / 1000.0f;
fCharHeight = fFontSize * iCharHeight / 1000.0f;
if (bRTLPiece && chartype != FX_CHARTYPE_Combination) {
- if (bVerticalDoc) {
+ if (bVerticalDoc)
fY -= fCharHeight;
- } else {
+ else
fX -= fCharWidth;
- }
}
if (!bEmptyChar || (bEmptyChar && !bSkipSpace)) {
pCharPos->m_Origin = CFX_PointF(fX, fY);
@@ -1460,12 +1438,12 @@ int32_t CFX_TxtBreak::GetDisplayPos(const FX_TXTRUN* pTxtRun,
pCharPos->m_Origin.y -= ptOffset.y;
}
if (!bRTLPiece && chartype != FX_CHARTYPE_Combination) {
- if (bVerticalDoc) {
+ if (bVerticalDoc)
fY += fCharHeight;
- } else {
+ else
fX += fCharWidth;
- }
}
+
if (!bEmptyChar || (bEmptyChar && !bSkipSpace)) {
pCharPos->m_bGlyphAdjust = true;
if (bVerticalDoc) {
@@ -1536,9 +1514,8 @@ int32_t CFX_TxtBreak::GetDisplayPos(const FX_TXTRUN* pTxtRun,
pCharPos++;
}
}
- if (iWidth > 0) {
- wPrev = (FX_WCHAR)formChars[0].wch;
- }
+ if (iWidth > 0)
+ wPrev = static_cast<FX_WCHAR>(formChars[0].wch);
wLast = wch;
}
return iCount;
@@ -1572,17 +1549,20 @@ int32_t CFX_TxtBreak::GetCharRects(const FX_TXTRUN* pTxtRun,
FX_FLOAT fHeight = FXSYS_fabs(bbox.height * fScale);
rtArray->clear();
rtArray->resize(iLength);
+
bool bVertical = (pTxtRun->dwStyles & FX_TXTLAYOUTSTYLE_VerticalLayout) != 0;
bool bSingleLine = (pTxtRun->dwStyles & FX_TXTLAYOUTSTYLE_SingleLine) != 0;
bool bCombText = (pTxtRun->dwStyles & FX_TXTLAYOUTSTYLE_CombText) != 0;
- FX_WCHAR wch, wLineBreakChar = pTxtRun->wLineBreakChar;
+ FX_WCHAR wch;
+ FX_WCHAR wLineBreakChar = pTxtRun->wLineBreakChar;
int32_t iCharSize;
- FX_FLOAT fCharSize, fStart;
- if (bVertical) {
+ FX_FLOAT fCharSize;
+ FX_FLOAT fStart;
+ if (bVertical)
fStart = bRTLPiece ? rect.bottom() : rect.top;
- } else {
+ else
fStart = bRTLPiece ? rect.right() : rect.left;
- }
+
for (int32_t i = 0; i < iLength; i++) {
if (pAccess) {
wch = pAccess->GetChar(pIdentity, i);
@@ -1591,7 +1571,7 @@ int32_t CFX_TxtBreak::GetCharRects(const FX_TXTRUN* pTxtRun,
wch = *pStr++;
iCharSize = *pWidths++;
}
- fCharSize = (FX_FLOAT)iCharSize / 20000.0f;
+ fCharSize = static_cast<FX_FLOAT>(iCharSize) / 20000.0f;
bool bRet = (!bSingleLine && FX_IsCtrlCode(wch));
if (!(wch == L'\v' || wch == L'\f' || wch == 0x2028 || wch == 0x2029 ||
(wLineBreakChar != 0xFEFF && wch == wLineBreakChar))) {
@@ -1620,6 +1600,7 @@ int32_t CFX_TxtBreak::GetCharRects(const FX_TXTRUN* pTxtRun,
}
rect.width = fCharSize;
}
+
if (bCharBBox && !bRet) {
int32_t iCharWidth = 1000;
pFont->GetCharWidth(wch, iCharWidth, false);
@@ -1627,9 +1608,8 @@ int32_t CFX_TxtBreak::GetCharRects(const FX_TXTRUN* pTxtRun,
if (iCharWidth > 0) {
fCharWidth = iCharWidth * fScale;
fRTLeft = fLeft;
- if (bCombText) {
+ if (bCombText)
fRTLeft = (rect.width - fCharWidth) / 2.0f;
- }
}
CFX_RectF rtBBoxF;
if (bVertical) {
diff --git a/xfa/fgas/layout/fgas_textbreak.h b/xfa/fgas/layout/fgas_textbreak.h
index bfd71c2987..a217d1636e 100644
--- a/xfa/fgas/layout/fgas_textbreak.h
+++ b/xfa/fgas/layout/fgas_textbreak.h
@@ -240,6 +240,7 @@ class CFX_TxtBreak {
uint32_t AppendChar_Others(CFX_TxtChar* pCurChar, int32_t iRotation);
private:
+ void FontChanged();
void SetBreakStatus();
int32_t GetLineRotation(uint32_t dwStyles) const;
CFX_TxtChar* GetLastChar(int32_t index, bool bOmitChar = true) const;