diff options
Diffstat (limited to 'xfa/fgas/layout')
-rw-r--r-- | xfa/fgas/layout/fgas_rtfbreak.cpp | 72 | ||||
-rw-r--r-- | xfa/fgas/layout/fgas_rtfbreak.h | 18 | ||||
-rw-r--r-- | xfa/fgas/layout/fgas_rtfbreak_unittest.cpp | 16 | ||||
-rw-r--r-- | xfa/fgas/layout/fgas_textbreak.cpp | 122 | ||||
-rw-r--r-- | xfa/fgas/layout/fgas_textbreak.h | 39 |
5 files changed, 128 insertions, 139 deletions
diff --git a/xfa/fgas/layout/fgas_rtfbreak.cpp b/xfa/fgas/layout/fgas_rtfbreak.cpp index 50fda35bdd..8f1761dea8 100644 --- a/xfa/fgas/layout/fgas_rtfbreak.cpp +++ b/xfa/fgas/layout/fgas_rtfbreak.cpp @@ -149,8 +149,8 @@ void CFX_RTFBreak::SetBreakStatus() { return; CFX_RTFChar& tc = m_pCurLine->GetChar(iCount - 1); - if (tc.m_dwStatus == CFX_RTFBreakType::None) - tc.m_dwStatus = CFX_RTFBreakType::Piece; + if (tc.m_dwStatus == CFX_BreakType::None) + tc.m_dwStatus = CFX_BreakType::Piece; } CFX_RTFChar* CFX_RTFBreak::GetLastChar(int32_t index) const { @@ -190,7 +190,7 @@ bool CFX_RTFBreak::GetPositionedTab(int32_t* iTabPos) const { return true; } -CFX_RTFBreakType CFX_RTFBreak::AppendChar(FX_WCHAR wch) { +CFX_BreakType CFX_RTFBreak::AppendChar(FX_WCHAR wch) { ASSERT(m_pFont && m_pCurLine); uint32_t dwProps = kTextLayoutCodeProperties[static_cast<uint16_t>(wch)]; @@ -198,7 +198,7 @@ CFX_RTFBreakType CFX_RTFBreak::AppendChar(FX_WCHAR wch) { m_pCurLine->m_LineChars.emplace_back(); CFX_RTFChar* pCurChar = &m_pCurLine->m_LineChars.back(); - pCurChar->m_dwStatus = CFX_RTFBreakType::None; + pCurChar->m_dwStatus = CFX_BreakType::None; pCurChar->m_wCharCode = wch; pCurChar->m_dwCharProps = dwProps; pCurChar->m_iFontSize = m_iFontSize; @@ -209,19 +209,19 @@ CFX_RTFBreakType CFX_RTFBreak::AppendChar(FX_WCHAR wch) { pCurChar->m_dwIdentity = m_dwIdentity; pCurChar->m_pUserData = m_pUserData; - CFX_RTFBreakType dwRet1 = CFX_RTFBreakType::None; + CFX_BreakType dwRet1 = CFX_BreakType::None; if (chartype != FX_CHARTYPE_Combination && 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); + dwRet1 = EndBreak(CFX_BreakType::Line); int32_t iCount = m_pCurLine->CountChars(); if (iCount > 0) pCurChar = &m_pCurLine->m_LineChars[iCount - 1]; } - CFX_RTFBreakType dwRet2 = CFX_RTFBreakType::None; + CFX_BreakType dwRet2 = CFX_BreakType::None; switch (chartype) { case FX_CHARTYPE_Tab: AppendChar_Tab(pCurChar); @@ -286,31 +286,31 @@ void CFX_RTFBreak::AppendChar_Tab(CFX_RTFChar* pCurChar) { iLineWidth += iCharWidth; } -CFX_RTFBreakType CFX_RTFBreak::AppendChar_Control(CFX_RTFChar* pCurChar) { - CFX_RTFBreakType dwRet2 = CFX_RTFBreakType::None; +CFX_BreakType CFX_RTFBreak::AppendChar_Control(CFX_RTFChar* pCurChar) { + CFX_BreakType dwRet2 = CFX_BreakType::None; switch (pCurChar->m_wCharCode) { case L'\v': case 0x2028: - dwRet2 = CFX_RTFBreakType::Line; + dwRet2 = CFX_BreakType::Line; break; case L'\f': - dwRet2 = CFX_RTFBreakType::Page; + dwRet2 = CFX_BreakType::Page; break; case 0x2029: - dwRet2 = CFX_RTFBreakType::Paragraph; + dwRet2 = CFX_BreakType::Paragraph; break; default: if (pCurChar->m_wCharCode == m_wLineBreakChar) - dwRet2 = CFX_RTFBreakType::Paragraph; + dwRet2 = CFX_BreakType::Paragraph; break; } - if (dwRet2 != CFX_RTFBreakType::None) + if (dwRet2 != CFX_BreakType::None) dwRet2 = EndBreak(dwRet2); return dwRet2; } -CFX_RTFBreakType CFX_RTFBreak::AppendChar_Arabic(CFX_RTFChar* pCurChar) { +CFX_BreakType CFX_RTFBreak::AppendChar_Arabic(CFX_RTFChar* pCurChar) { CFX_RTFChar* pLastChar = nullptr; int32_t iCharWidth = 0; FX_WCHAR wForm; @@ -351,11 +351,11 @@ CFX_RTFBreakType CFX_RTFBreak::AppendChar_Arabic(CFX_RTFChar* pCurChar) { m_pCurLine->m_iArabicChars++; if (m_pCurLine->GetLineEnd() > m_iBoundaryEnd + m_iTolerance) - return EndBreak(CFX_RTFBreakType::Line); - return CFX_RTFBreakType::None; + return EndBreak(CFX_BreakType::Line); + return CFX_BreakType::None; } -CFX_RTFBreakType CFX_RTFBreak::AppendChar_Others(CFX_RTFChar* pCurChar) { +CFX_BreakType CFX_RTFBreak::AppendChar_Others(CFX_RTFChar* pCurChar) { FX_CHARTYPE chartype = pCurChar->GetCharType(); FX_WCHAR wForm = pCurChar->m_wCharCode; int32_t iCharWidth = 0; @@ -370,37 +370,37 @@ CFX_RTFBreakType CFX_RTFBreak::AppendChar_Others(CFX_RTFChar* pCurChar) { m_pCurLine->m_iWidth += iCharWidth; if (chartype != FX_CHARTYPE_Space && m_pCurLine->GetLineEnd() > m_iBoundaryEnd + m_iTolerance) { - return EndBreak(CFX_RTFBreakType::Line); + return EndBreak(CFX_BreakType::Line); } - return CFX_RTFBreakType::None; + return CFX_BreakType::None; } -CFX_RTFBreakType CFX_RTFBreak::EndBreak(CFX_RTFBreakType dwStatus) { - ASSERT(dwStatus != CFX_RTFBreakType::None); +CFX_BreakType CFX_RTFBreak::EndBreak(CFX_BreakType dwStatus) { + ASSERT(dwStatus != CFX_BreakType::None); ++m_dwIdentity; if (!m_pCurLine->m_LinePieces.empty()) { - if (dwStatus != CFX_RTFBreakType::Piece) + if (dwStatus != CFX_BreakType::Piece) m_pCurLine->m_LinePieces.back().m_dwStatus = dwStatus; return m_pCurLine->m_LinePieces.back().m_dwStatus; } if (HasRTFLine()) { if (!m_RTFLine[m_iReady].m_LinePieces.empty()) { - if (dwStatus != CFX_RTFBreakType::Piece) + if (dwStatus != CFX_BreakType::Piece) m_RTFLine[m_iReady].m_LinePieces.back().m_dwStatus = dwStatus; return m_RTFLine[m_iReady].m_LinePieces.back().m_dwStatus; } - return CFX_RTFBreakType::None; + return CFX_BreakType::None; } int32_t iCount = m_pCurLine->CountChars(); if (iCount < 1) - return CFX_RTFBreakType::None; + return CFX_BreakType::None; CFX_RTFChar& tc = m_pCurLine->GetChar(iCount - 1); tc.m_dwStatus = dwStatus; - if (dwStatus == CFX_RTFBreakType::Piece) + if (dwStatus == CFX_BreakType::Piece) return dwStatus; m_iReady = m_pCurLine == &m_RTFLine[0] ? 0 : 1; @@ -424,7 +424,7 @@ CFX_RTFBreakType CFX_RTFBreak::EndBreak(CFX_RTFBreakType dwStatus) { bool CFX_RTFBreak::EndBreak_SplitLine(CFX_RTFLine* pNextLine, bool bAllChars, - CFX_RTFBreakType dwStatus) { + CFX_BreakType dwStatus) { bool bDone = false; if (m_pCurLine->GetLineEnd() > m_iBoundaryEnd + m_iTolerance) { const CFX_RTFChar& tc = m_pCurLine->GetChar(m_pCurLine->CountChars() - 1); @@ -473,7 +473,7 @@ bool CFX_RTFBreak::EndBreak_SplitLine(CFX_RTFLine* pNextLine, bNew = false; } - if (i == iLast || pTC->m_dwStatus != CFX_RTFBreakType::None || + if (i == iLast || pTC->m_dwStatus != CFX_BreakType::None || pTC->m_dwIdentity != dwIdentity) { tp.m_iChars = i - j; if (pTC->m_dwIdentity == dwIdentity) { @@ -493,7 +493,7 @@ bool CFX_RTFBreak::EndBreak_SplitLine(CFX_RTFLine* pNextLine, } void CFX_RTFBreak::EndBreak_BidiLine(std::deque<FX_TPO>* tpos, - CFX_RTFBreakType dwStatus) { + CFX_BreakType dwStatus) { CFX_RTFChar* pTC; std::vector<CFX_RTFChar>& chars = m_pCurLine->m_LineChars; int32_t iCount = m_pCurLine->CountChars(); @@ -518,7 +518,7 @@ void CFX_RTFBreak::EndBreak_BidiLine(std::deque<FX_TPO>* tpos, } CFX_RTFPiece tp; - tp.m_dwStatus = CFX_RTFBreakType::Piece; + tp.m_dwStatus = CFX_BreakType::Piece; tp.m_iStartPos = m_pCurLine->m_iStart; tp.m_pChars = &chars; @@ -543,7 +543,7 @@ void CFX_RTFBreak::EndBreak_BidiLine(std::deque<FX_TPO>* tpos, dwIdentity = pTC->m_dwIdentity; tp.m_dwIdentity = dwIdentity; tp.m_pUserData = pTC->m_pUserData; - tp.m_dwStatus = CFX_RTFBreakType::Piece; + tp.m_dwStatus = CFX_BreakType::Piece; ++i; } else if (iBidiLevel != pTC->m_iBidiLevel || pTC->m_dwIdentity != dwIdentity) { @@ -585,7 +585,7 @@ void CFX_RTFBreak::EndBreak_BidiLine(std::deque<FX_TPO>* tpos, void CFX_RTFBreak::EndBreak_Alignment(const std::deque<FX_TPO>& tpos, bool bAllChars, - CFX_RTFBreakType dwStatus) { + CFX_BreakType dwStatus) { int32_t iNetWidth = m_pCurLine->m_iWidth; int32_t iGapChars = 0; bool bFind = false; @@ -625,7 +625,7 @@ void CFX_RTFBreak::EndBreak_Alignment(const std::deque<FX_TPO>& tpos, int32_t iOffset = m_iBoundaryEnd - iNetWidth; if (iGapChars > 0 && (m_iAlignment == CFX_RTFLineAlignment::Distributed || (m_iAlignment == CFX_RTFLineAlignment::Justified && - dwStatus != CFX_RTFBreakType::Paragraph))) { + dwStatus != CFX_BreakType::Paragraph))) { int32_t iStart = -1; for (const auto& tpo : tpos) { CFX_RTFPiece& ttp = m_pCurLine->m_LinePieces[tpo.index]; @@ -789,7 +789,7 @@ void CFX_RTFBreak::SplitTextLine(CFX_RTFLine* pCurLine, pCurLine->m_iArabicChars--; pNextLine->m_iArabicChars++; } - pNextLine->m_LineChars[i].m_dwStatus = CFX_RTFBreakType::None; + pNextLine->m_LineChars[i].m_dwStatus = CFX_BreakType::None; } } @@ -938,7 +938,7 @@ int32_t CFX_RTFBreak::GetDisplayPos(const FX_RTFTEXTOBJ* pText, } CFX_RTFPiece::CFX_RTFPiece() - : m_dwStatus(CFX_RTFBreakType::Piece), + : m_dwStatus(CFX_BreakType::Piece), m_iStartPos(0), m_iWidth(-1), m_iStartChar(0), diff --git a/xfa/fgas/layout/fgas_rtfbreak.h b/xfa/fgas/layout/fgas_rtfbreak.h index 125b06fe95..5d29e0e84f 100644 --- a/xfa/fgas/layout/fgas_rtfbreak.h +++ b/xfa/fgas/layout/fgas_rtfbreak.h @@ -76,7 +76,7 @@ class CFX_RTFPiece { return ret; } - CFX_RTFBreakType m_dwStatus; + CFX_BreakType m_dwStatus; int32_t m_iStartPos; int32_t m_iWidth; int32_t m_iStartChar; @@ -140,7 +140,7 @@ class CFX_RTFBreak { void AddPositionedTab(FX_FLOAT fTabPos); - CFX_RTFBreakType EndBreak(CFX_RTFBreakType dwStatus); + CFX_BreakType EndBreak(CFX_BreakType dwStatus); int32_t CountBreakPieces() const; const CFX_RTFPiece* GetBreakPieceUnstable(int32_t index) const; void ClearBreakPieces(); @@ -151,16 +151,16 @@ class CFX_RTFBreak { FXTEXT_CHARPOS* pCharPos, bool bCharCode) const; - CFX_RTFBreakType AppendChar(FX_WCHAR wch); + CFX_BreakType AppendChar(FX_WCHAR wch); CFX_RTFLine* GetCurrentLineForTesting() const { return m_pCurLine; } private: void AppendChar_Combination(CFX_RTFChar* pCurChar); void AppendChar_Tab(CFX_RTFChar* pCurChar); - CFX_RTFBreakType AppendChar_Control(CFX_RTFChar* pCurChar); - CFX_RTFBreakType AppendChar_Arabic(CFX_RTFChar* pCurChar); - CFX_RTFBreakType AppendChar_Others(CFX_RTFChar* pCurChar); + CFX_BreakType AppendChar_Control(CFX_RTFChar* pCurChar); + CFX_BreakType AppendChar_Arabic(CFX_RTFChar* pCurChar); + CFX_BreakType AppendChar_Others(CFX_RTFChar* pCurChar); void FontChanged(); void SetBreakStatus(); CFX_RTFChar* GetLastChar(int32_t index) const; @@ -178,11 +178,11 @@ class CFX_RTFBreak { bool bAllChars); bool EndBreak_SplitLine(CFX_RTFLine* pNextLine, bool bAllChars, - CFX_RTFBreakType dwStatus); - void EndBreak_BidiLine(std::deque<FX_TPO>* tpos, CFX_RTFBreakType dwStatus); + CFX_BreakType dwStatus); + void EndBreak_BidiLine(std::deque<FX_TPO>* tpos, CFX_BreakType dwStatus); void EndBreak_Alignment(const std::deque<FX_TPO>& tpos, bool bAllChars, - CFX_RTFBreakType dwStatus); + CFX_BreakType dwStatus); int32_t m_iBoundaryStart; int32_t m_iBoundaryEnd; diff --git a/xfa/fgas/layout/fgas_rtfbreak_unittest.cpp b/xfa/fgas/layout/fgas_rtfbreak_unittest.cpp index bbac9d5806..b20afb7103 100644 --- a/xfa/fgas/layout/fgas_rtfbreak_unittest.cpp +++ b/xfa/fgas/layout/fgas_rtfbreak_unittest.cpp @@ -54,9 +54,9 @@ TEST_F(RTFBreakTest, AddChars) { CFX_WideString str(L"Input String."); for (int32_t i = 0; i < str.GetLength(); i++) - EXPECT_EQ(CFX_RTFBreakType::None, b->AppendChar(str.GetAt(i))); + EXPECT_EQ(CFX_BreakType::None, b->AppendChar(str.GetAt(i))); - EXPECT_EQ(CFX_RTFBreakType::Paragraph, b->AppendChar(L'\n')); + EXPECT_EQ(CFX_BreakType::Paragraph, b->AppendChar(L'\n')); ASSERT_EQ(1, b->CountBreakPieces()); EXPECT_EQ(str + L"\n", b->GetBreakPieceUnstable(0)->GetString()); @@ -66,21 +66,21 @@ TEST_F(RTFBreakTest, AddChars) { str = L"Second str."; for (int32_t i = 0; i < str.GetLength(); i++) - EXPECT_EQ(CFX_RTFBreakType::None, b->AppendChar(str.GetAt(i))); + EXPECT_EQ(CFX_BreakType::None, b->AppendChar(str.GetAt(i))); // Force the end of the break at the end of the string. - b->EndBreak(CFX_RTFBreakType::Paragraph); + b->EndBreak(CFX_BreakType::Paragraph); ASSERT_EQ(1, b->CountBreakPieces()); EXPECT_EQ(str, b->GetBreakPieceUnstable(0)->GetString()); } TEST_F(RTFBreakTest, ControlCharacters) { auto b = CreateBreak(FX_RTFLAYOUTSTYLE_ExpandTab); - EXPECT_EQ(CFX_RTFBreakType::Line, b->AppendChar(L'\v')); - EXPECT_EQ(CFX_RTFBreakType::Page, b->AppendChar(L'\f')); + EXPECT_EQ(CFX_BreakType::Line, b->AppendChar(L'\v')); + EXPECT_EQ(CFX_BreakType::Page, b->AppendChar(L'\f')); // 0x2029 is the Paragraph Separator unicode character. - EXPECT_EQ(CFX_RTFBreakType::Paragraph, b->AppendChar(0x2029)); - EXPECT_EQ(CFX_RTFBreakType::Paragraph, b->AppendChar(L'\n')); + EXPECT_EQ(CFX_BreakType::Paragraph, b->AppendChar(0x2029)); + EXPECT_EQ(CFX_BreakType::Paragraph, b->AppendChar(L'\n')); ASSERT_EQ(1, b->CountBreakPieces()); EXPECT_EQ(L"\v", b->GetBreakPieceUnstable(0)->GetString()); diff --git a/xfa/fgas/layout/fgas_textbreak.cpp b/xfa/fgas/layout/fgas_textbreak.cpp index e458f4c283..832521dbee 100644 --- a/xfa/fgas/layout/fgas_textbreak.cpp +++ b/xfa/fgas/layout/fgas_textbreak.cpp @@ -16,7 +16,7 @@ namespace { -typedef uint32_t (CFX_TxtBreak::*FX_TxtBreak_LPFAppendChar)( +typedef CFX_BreakType (CFX_TxtBreak::*FX_TxtBreak_LPFAppendChar)( CFX_TxtChar* pCurChar, int32_t iRotation); const FX_TxtBreak_LPFAppendChar g_FX_TxtBreak_lpfAppendChar[16] = { @@ -35,6 +35,8 @@ bool IsCtrlCode(FX_WCHAR ch) { return dwRet == FX_CHARTYPE_Tab || dwRet == FX_CHARTYPE_Control; } +const int kMinimumTabWidth = 160000; + } // namespace CFX_TxtBreak::CFX_TxtBreak() @@ -133,10 +135,7 @@ void CFX_TxtBreak::FontChanged() { } void CFX_TxtBreak::SetTabWidth(FX_FLOAT fTabWidth, bool bEquidistant) { - m_iTabWidth = FXSYS_round(fTabWidth * 20000.0f); - if (m_iTabWidth < FX_TXTBREAK_MinimumTabWidth) - m_iTabWidth = FX_TXTBREAK_MinimumTabWidth; - + m_iTabWidth = std::max(FXSYS_round(fTabWidth * 20000.0f), kMinimumTabWidth); m_bEquidistant = bEquidistant; } @@ -214,8 +213,8 @@ void CFX_TxtBreak::SetBreakStatus() { return; CFX_TxtChar* pTC = m_pCurLine->GetCharPtr(iCount - 1); - if (pTC->m_dwStatus == 0) - pTC->m_dwStatus = FX_TXTBREAK_PieceBreak; + if (pTC->m_dwStatus == CFX_BreakType::None) + pTC->m_dwStatus = CFX_BreakType::Piece; } void CFX_TxtBreak::SetHorizontalScale(int32_t iScale) { @@ -295,7 +294,7 @@ void CFX_TxtBreak::ResetArabicContext() { void CFX_TxtBreak::AppendChar_PageLoad(CFX_TxtChar* pCurChar, uint32_t dwProps) { - pCurChar->m_dwStatus = 0; + pCurChar->m_dwStatus = CFX_BreakType::None; pCurChar->m_pUserData = m_pUserData; if (m_bArabicContext || m_bArabicShapes) { @@ -312,15 +311,15 @@ void CFX_TxtBreak::AppendChar_PageLoad(CFX_TxtChar* pCurChar, ResetArabicContext(); CFX_TxtChar* pLastChar = GetLastChar(1, false); - if (pLastChar && pLastChar->m_dwStatus < 1) - pLastChar->m_dwStatus = FX_TXTBREAK_PieceBreak; + if (pLastChar && pLastChar->m_dwStatus == CFX_BreakType::None) + pLastChar->m_dwStatus = CFX_BreakType::Piece; } } pCurChar->m_dwCharStyles = m_dwContextCharStyles; } -uint32_t CFX_TxtBreak::AppendChar_Combination(CFX_TxtChar* pCurChar, - int32_t iRotation) { +CFX_BreakType CFX_TxtBreak::AppendChar_Combination(CFX_TxtChar* pCurChar, + int32_t iRotation) { FX_WCHAR wch = pCurChar->m_wCharCode; FX_WCHAR wForm; int32_t iCharWidth = 0; @@ -361,14 +360,14 @@ uint32_t CFX_TxtBreak::AppendChar_Combination(CFX_TxtChar* pCurChar, iCharWidth = iCharWidth * m_iHorScale / 100; } pCurChar->m_iCharWidth = -iCharWidth; - return FX_TXTBREAK_None; + return CFX_BreakType::None; } -uint32_t CFX_TxtBreak::AppendChar_Tab(CFX_TxtChar* pCurChar, - int32_t iRotation) { +CFX_BreakType CFX_TxtBreak::AppendChar_Tab(CFX_TxtChar* pCurChar, + int32_t iRotation) { m_eCharType = FX_CHARTYPE_Tab; if ((m_dwLayoutStyles & FX_TXTLAYOUTSTYLE_ExpandTab) == 0) - return FX_TXTBREAK_None; + return CFX_BreakType::None; int32_t& iLineWidth = m_pCurLine->m_iWidth; int32_t iCharWidth; @@ -376,9 +375,8 @@ uint32_t CFX_TxtBreak::AppendChar_Tab(CFX_TxtChar* pCurChar, iCharWidth = m_iCombWidth; } else { if (m_bEquidistant) { - iCharWidth = iLineWidth; - iCharWidth = m_iTabWidth * (iCharWidth / m_iTabWidth + 1) - iCharWidth; - if (iCharWidth < FX_TXTBREAK_MinimumTabWidth) + iCharWidth = m_iTabWidth * (iLineWidth / m_iTabWidth + 1) - iLineWidth; + if (iCharWidth < kMinimumTabWidth) iCharWidth += m_iTabWidth; } else { iCharWidth = m_iTabWidth; @@ -388,41 +386,41 @@ uint32_t CFX_TxtBreak::AppendChar_Tab(CFX_TxtChar* pCurChar, pCurChar->m_iCharWidth = iCharWidth; iLineWidth += iCharWidth; if (!m_bSingleLine && iLineWidth >= m_iLineWidth + m_iTolerance) - return EndBreak(FX_TXTBREAK_LineBreak); + return EndBreak(CFX_BreakType::Line); - return FX_TXTBREAK_None; + return CFX_BreakType::None; } -uint32_t CFX_TxtBreak::AppendChar_Control(CFX_TxtChar* pCurChar, - int32_t iRotation) { +CFX_BreakType CFX_TxtBreak::AppendChar_Control(CFX_TxtChar* pCurChar, + int32_t iRotation) { m_eCharType = FX_CHARTYPE_Control; - uint32_t dwRet = FX_TXTBREAK_None; + CFX_BreakType dwRet = CFX_BreakType::None; if (!m_bSingleLine) { FX_WCHAR wch = pCurChar->m_wCharCode; switch (wch) { case L'\v': case 0x2028: - dwRet = FX_TXTBREAK_LineBreak; + dwRet = CFX_BreakType::Line; break; case L'\f': - dwRet = FX_TXTBREAK_PageBreak; + dwRet = CFX_BreakType::Page; break; case 0x2029: - dwRet = FX_TXTBREAK_ParagraphBreak; + dwRet = CFX_BreakType::Paragraph; break; default: if (wch == m_wParagBreakChar) - dwRet = FX_TXTBREAK_ParagraphBreak; + dwRet = CFX_BreakType::Paragraph; break; } - if (dwRet != FX_TXTBREAK_None) + if (dwRet != CFX_BreakType::None) dwRet = EndBreak(dwRet); } return dwRet; } -uint32_t CFX_TxtBreak::AppendChar_Arabic(CFX_TxtChar* pCurChar, - int32_t iRotation) { +CFX_BreakType CFX_TxtBreak::AppendChar_Arabic(CFX_TxtChar* pCurChar, + int32_t iRotation) { FX_CHARTYPE chartype = pCurChar->GetCharType(); int32_t& iLineWidth = m_pCurLine->m_iWidth; FX_WCHAR wForm; @@ -481,12 +479,12 @@ uint32_t CFX_TxtBreak::AppendChar_Arabic(CFX_TxtChar* pCurChar, iLineWidth += iCharWidth; m_pCurLine->m_iArabicChars++; if (!m_bSingleLine && iLineWidth > m_iLineWidth + m_iTolerance) - return EndBreak(FX_TXTBREAK_LineBreak); - return FX_TXTBREAK_None; + return EndBreak(CFX_BreakType::Line); + return CFX_BreakType::None; } -uint32_t CFX_TxtBreak::AppendChar_Others(CFX_TxtChar* pCurChar, - int32_t iRotation) { +CFX_BreakType CFX_TxtBreak::AppendChar_Others(CFX_TxtChar* pCurChar, + int32_t iRotation) { uint32_t dwProps = pCurChar->m_dwCharProps; FX_CHARTYPE chartype = pCurChar->GetCharType(); int32_t& iLineWidth = m_pCurLine->m_iWidth; @@ -525,13 +523,13 @@ uint32_t CFX_TxtBreak::AppendChar_Others(CFX_TxtChar* pCurChar, iLineWidth += iCharWidth; if (!m_bSingleLine && chartype != FX_CHARTYPE_Space && iLineWidth > m_iLineWidth + m_iTolerance) { - return EndBreak(FX_TXTBREAK_LineBreak); + return EndBreak(CFX_BreakType::Line); } - return FX_TXTBREAK_None; + return CFX_BreakType::None; } -uint32_t CFX_TxtBreak::AppendChar(FX_WCHAR wch) { +CFX_BreakType CFX_TxtBreak::AppendChar(FX_WCHAR wch) { uint32_t dwProps = kTextLayoutCodeProperties[static_cast<uint16_t>(wch)]; FX_CHARTYPE chartype = GetCharTypeFromProp(dwProps); m_pCurLine->m_LineChars.emplace_back(); @@ -544,20 +542,20 @@ uint32_t CFX_TxtBreak::AppendChar(FX_WCHAR wch) { pCurChar->m_iCharWidth = 0; pCurChar->m_iHorizontalScale = m_iHorScale; pCurChar->m_iVerticalScale = 100; - pCurChar->m_dwStatus = 0; + pCurChar->m_dwStatus = CFX_BreakType::None; pCurChar->m_iBidiClass = 0; pCurChar->m_iBidiLevel = 0; pCurChar->m_iBidiPos = 0; pCurChar->m_iBidiOrder = 0; pCurChar->m_pUserData = nullptr; AppendChar_PageLoad(pCurChar, dwProps); - uint32_t dwRet1 = FX_TXTBREAK_None; + CFX_BreakType dwRet1 = CFX_BreakType::None; if (chartype != FX_CHARTYPE_Combination && 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); + dwRet1 = EndBreak(CFX_BreakType::Line); int32_t iCount = m_pCurLine->CountChars(); if (iCount > 0) pCurChar = &m_pCurLine->m_LineChars[iCount - 1]; @@ -567,7 +565,7 @@ uint32_t CFX_TxtBreak::AppendChar(FX_WCHAR wch) { if (m_bVertical && (dwProps & 0x8000) != 0) iRotation = (iRotation + 1) % 4; - uint32_t dwRet2 = + CFX_BreakType dwRet2 = (this->*g_FX_TxtBreak_lpfAppendChar[chartype >> FX_CHARTYPEBITS])( pCurChar, iRotation); return std::max(dwRet1, dwRet2); @@ -628,9 +626,7 @@ void CFX_TxtBreak::EndBreak_UpdateArabicShapes() { } while (i < iCount); } -bool CFX_TxtBreak::EndBreak_SplitLine(CFX_TxtLine* pNextLine, - bool bAllChars, - uint32_t dwStatus) { +bool CFX_TxtBreak::EndBreak_SplitLine(CFX_TxtLine* pNextLine, bool bAllChars) { int32_t iCount = m_pCurLine->CountChars(); bool bDone = false; CFX_TxtChar* pTC; @@ -658,7 +654,7 @@ bool CFX_TxtBreak::EndBreak_SplitLine(CFX_TxtLine* pNextLine, } void CFX_TxtBreak::EndBreak_BidiLine(std::deque<FX_TPO>* tpos, - uint32_t dwStatus) { + CFX_BreakType dwStatus) { CFX_TxtPiece tp; FX_TPO tpo; CFX_TxtChar* pTC; @@ -682,7 +678,7 @@ void CFX_TxtBreak::EndBreak_BidiLine(std::deque<FX_TPO>* tpos, CFX_TxtPieceArray* pCurPieces = &m_pCurLine->m_LinePieces; if (bDone || (m_dwLayoutStyles & FX_TXTLAYOUTSTYLE_MutipleFormat) != 0) { - tp.m_dwStatus = FX_TXTBREAK_PieceBreak; + tp.m_dwStatus = CFX_BreakType::Piece; tp.m_iStartPos = m_pCurLine->m_iStart; tp.m_pChars = &m_pCurLine->m_LineChars; int32_t iBidiLevel = -1; @@ -700,9 +696,10 @@ void CFX_TxtBreak::EndBreak_BidiLine(std::deque<FX_TPO>* tpos, tp.m_pUserData = pTC->m_pUserData; tp.m_iHorizontalScale = pTC->m_iHorizontalScale; tp.m_iVerticalScale = pTC->m_iVerticalScale; - tp.m_dwStatus = FX_TXTBREAK_PieceBreak; + tp.m_dwStatus = CFX_BreakType::Piece; } - if (iBidiLevel != pTC->m_iBidiLevel || pTC->m_dwStatus != 0) { + if (iBidiLevel != pTC->m_iBidiLevel || + pTC->m_dwStatus != CFX_BreakType::None) { if (iBidiLevel == pTC->m_iBidiLevel) { tp.m_dwStatus = pTC->m_dwStatus; iCharWidth = pTC->m_iCharWidth; @@ -768,7 +765,7 @@ void CFX_TxtBreak::EndBreak_BidiLine(std::deque<FX_TPO>* tpos, void CFX_TxtBreak::EndBreak_Alignment(const std::deque<FX_TPO>& tpos, bool bAllChars, - uint32_t dwStatus) { + CFX_BreakType dwStatus) { int32_t iNetWidth = m_pCurLine->m_iWidth; int32_t iGapChars = 0; int32_t iCharWidth; @@ -817,7 +814,7 @@ void CFX_TxtBreak::EndBreak_Alignment(const std::deque<FX_TPO>& tpos, int32_t iHigherAlignment = (m_iCurAlignment & FX_TXTLINEALIGNMENT_HigherMask); if (iGapChars > 0 && (iHigherAlignment == FX_TXTLINEALIGNMENT_Distributed || (iHigherAlignment == FX_TXTLINEALIGNMENT_Justified && - dwStatus != FX_TXTBREAK_ParagraphBreak))) { + dwStatus != CFX_BreakType::Paragraph))) { int32_t iStart = -1; for (i = 0; i < iCount; i++) { tpo = tpos[i]; @@ -854,14 +851,13 @@ void CFX_TxtBreak::EndBreak_Alignment(const std::deque<FX_TPO>& tpos, } } -uint32_t CFX_TxtBreak::EndBreak(uint32_t dwStatus) { - ASSERT(dwStatus >= FX_TXTBREAK_PieceBreak && - dwStatus <= FX_TXTBREAK_PageBreak); +CFX_BreakType CFX_TxtBreak::EndBreak(CFX_BreakType dwStatus) { + ASSERT(dwStatus != CFX_BreakType::None); const CFX_TxtPieceArray* pCurPieces = &m_pCurLine->m_LinePieces; int32_t iCount = pCurPieces->GetSize(); if (iCount > 0) { CFX_TxtPiece* pLastPiece = pCurPieces->GetPtrAt(--iCount); - if (dwStatus > FX_TXTBREAK_PieceBreak) + if (dwStatus != CFX_BreakType::Piece) pLastPiece->m_dwStatus = dwStatus; else dwStatus = pLastPiece->m_dwStatus; @@ -873,22 +869,22 @@ 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 != CFX_BreakType::Piece) pLastPiece->m_dwStatus = dwStatus; else dwStatus = pLastPiece->m_dwStatus; return dwStatus; } - return FX_TXTBREAK_None; + return CFX_BreakType::None; } iCount = m_pCurLine->CountChars(); if (iCount < 1) - return FX_TXTBREAK_None; + return CFX_BreakType::None; CFX_TxtChar* pTC = m_pCurLine->GetCharPtr(iCount - 1); pTC->m_dwStatus = dwStatus; - if (dwStatus <= FX_TXTBREAK_PieceBreak) + if (dwStatus == CFX_BreakType::Piece) return dwStatus; } @@ -899,7 +895,7 @@ uint32_t CFX_TxtBreak::EndBreak(uint32_t dwStatus) { if (m_bArabicShapes) EndBreak_UpdateArabicShapes(); - if (!EndBreak_SplitLine(pNextLine, bAllChars, dwStatus)) { + if (!EndBreak_SplitLine(pNextLine, bAllChars)) { std::deque<FX_TPO> tpos; EndBreak_BidiLine(&tpos, dwStatus); if (m_iCurAlignment > FX_TXTLINEALIGNMENT_Left) @@ -909,7 +905,7 @@ uint32_t CFX_TxtBreak::EndBreak(uint32_t dwStatus) { m_pCurLine = pNextLine; CFX_Char* pTC = GetLastChar(0, false); m_eCharType = pTC ? pTC->GetCharType() : FX_CHARTYPE_Unknown; - if (dwStatus == FX_TXTBREAK_ParagraphBreak) { + if (dwStatus == CFX_BreakType::Paragraph) { m_iArabicContext = m_iCurArabicContext = 1; ResetArabicContext(); } @@ -1045,7 +1041,7 @@ void CFX_TxtBreak::SplitTextLine(CFX_TxtLine* pCurLine, pNextLine->m_iArabicChars++; } iWidth += std::max(0, pNextLine->m_LineChars[i].m_iCharWidth); - pNextLine->m_LineChars[i].m_dwStatus = 0; + pNextLine->m_LineChars[i].m_dwStatus = CFX_BreakType::None; } pNextLine->m_iWidth = iWidth; } @@ -1591,7 +1587,7 @@ FX_TXTRUN::~FX_TXTRUN() {} FX_TXTRUN::FX_TXTRUN(const FX_TXTRUN& other) = default; CFX_TxtPiece::CFX_TxtPiece() - : m_dwStatus(FX_TXTBREAK_PieceBreak), + : m_dwStatus(CFX_BreakType::Piece), m_iStartPos(0), m_iWidth(-1), m_iStartChar(0), diff --git a/xfa/fgas/layout/fgas_textbreak.h b/xfa/fgas/layout/fgas_textbreak.h index 72fab9d6a1..75be69b520 100644 --- a/xfa/fgas/layout/fgas_textbreak.h +++ b/xfa/fgas/layout/fgas_textbreak.h @@ -23,15 +23,6 @@ class CFX_TxtPiece; class IFX_TxtAccess; struct FDE_TEXTEDITPIECE; -#define FX_TXTBREAK_None 0x00 -#define FX_TXTBREAK_PieceBreak 0x01 -#define FX_TXTBREAK_LineBreak 0x02 -#define FX_TXTBREAK_ParagraphBreak 0x03 -#define FX_TXTBREAK_PageBreak 0x04 -#define FX_TXTBREAK_ControlChar 0x10 -#define FX_TXTBREAK_BreakChar 0x20 -#define FX_TXTBREAK_UnknownChar 0x40 -#define FX_TXTBREAK_RemoveChar 0x80 #define FX_TXTLAYOUTSTYLE_MutipleFormat 0x0001 #define FX_TXTLAYOUTSTYLE_VerticalLayout 0x0002 #define FX_TXTLAYOUTSTYLE_VerticalChars 0x0004 @@ -69,7 +60,6 @@ struct FDE_TEXTEDITPIECE; (FX_TXTLINEALIGNMENT_Right | FX_TXTLINEALIGNMENT_Distributed) #define FX_TXTLINEALIGNMENT_LowerMask 0x03 #define FX_TXTLINEALIGNMENT_HigherMask 0x0C -#define FX_TXTBREAK_MinimumTabWidth 160000 struct FX_TPO { int32_t index; @@ -78,6 +68,10 @@ struct FX_TPO { bool operator<(const FX_TPO& that) const { return pos < that.pos; } }; +inline bool CFX_BreakTypeNoneOrPiece(CFX_BreakType type) { + return type == CFX_BreakType::None || type == CFX_BreakType::Piece; +} + class IFX_TxtAccess { public: virtual ~IFX_TxtAccess() {} @@ -140,7 +134,7 @@ class CFX_TxtPiece { *pWidths++ = (*m_pChars)[i].m_iCharWidth; } - uint32_t m_dwStatus; + CFX_BreakType m_dwStatus; int32_t m_iStartPos; int32_t m_iWidth; int32_t m_iStartChar; @@ -224,8 +218,7 @@ class CFX_TxtBreak { void SetAlignment(int32_t iAlignment); void SetCombWidth(FX_FLOAT fCombWidth); void SetUserData(void* pUserData); - uint32_t AppendChar(FX_WCHAR wch); - uint32_t EndBreak(uint32_t dwStatus = FX_TXTBREAK_PieceBreak); + CFX_BreakType EndBreak(CFX_BreakType dwStatus); int32_t CountBreakPieces() const; const CFX_TxtPiece* GetBreakPiece(int32_t index) const; void ClearBreakPieces(); @@ -237,11 +230,13 @@ class CFX_TxtBreak { std::vector<CFX_RectF> GetCharRects(const FX_TXTRUN* pTxtRun, bool bCharBBox = false) const; void AppendChar_PageLoad(CFX_TxtChar* pCurChar, uint32_t dwProps); - uint32_t AppendChar_Combination(CFX_TxtChar* pCurChar, int32_t iRotation); - uint32_t AppendChar_Tab(CFX_TxtChar* pCurChar, int32_t iRotation); - uint32_t AppendChar_Control(CFX_TxtChar* pCurChar, int32_t iRotation); - uint32_t AppendChar_Arabic(CFX_TxtChar* pCurChar, int32_t iRotation); - uint32_t AppendChar_Others(CFX_TxtChar* pCurChar, int32_t iRotation); + CFX_BreakType AppendChar(FX_WCHAR wch); + CFX_BreakType AppendChar_Combination(CFX_TxtChar* pCurChar, + int32_t iRotation); + CFX_BreakType AppendChar_Tab(CFX_TxtChar* pCurChar, int32_t iRotation); + CFX_BreakType AppendChar_Control(CFX_TxtChar* pCurChar, int32_t iRotation); + CFX_BreakType AppendChar_Arabic(CFX_TxtChar* pCurChar, int32_t iRotation); + CFX_BreakType AppendChar_Others(CFX_TxtChar* pCurChar, int32_t iRotation); private: void FontChanged(); @@ -254,13 +249,11 @@ class CFX_TxtBreak { void ResetArabicContext(); void ResetContextCharStyles(); void EndBreak_UpdateArabicShapes(); - bool EndBreak_SplitLine(CFX_TxtLine* pNextLine, - bool bAllChars, - uint32_t dwStatus); - void EndBreak_BidiLine(std::deque<FX_TPO>* tpos, uint32_t dwStatus); + bool EndBreak_SplitLine(CFX_TxtLine* pNextLine, bool bAllChars); + void EndBreak_BidiLine(std::deque<FX_TPO>* tpos, CFX_BreakType dwStatus); void EndBreak_Alignment(const std::deque<FX_TPO>& tpos, bool bAllChars, - uint32_t dwStatus); + CFX_BreakType dwStatus); int32_t GetBreakPos(std::vector<CFX_TxtChar>& ca, int32_t& iEndPos, bool bAllChars = false, |