diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-03-21 11:31:25 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-03-21 15:55:35 +0000 |
commit | 5c529e6318d46121a5ea38d3edb42c8d9f580fe8 (patch) | |
tree | f11ae317bb4cdb94e69e9b1ae1a6db6342218b61 /xfa/fgas/layout | |
parent | a766a958c5867a2a5562095ad03f72290db18b98 (diff) | |
download | pdfium-5c529e6318d46121a5ea38d3edb42c8d9f580fe8.tar.xz |
Combine more RTF and TXT Break code
This Cl conbines several more methods from RTFBreak and TXTBreak into
the common Break baseclass.
Change-Id: Ibe2236eb4fd30faab239e7c9c8b578164014eb39
Reviewed-on: https://pdfium-review.googlesource.com/3108
Reviewed-by: Nicolás Peña <npm@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fgas/layout')
-rw-r--r-- | xfa/fgas/layout/cfx_break.cpp | 59 | ||||
-rw-r--r-- | xfa/fgas/layout/cfx_break.h | 11 | ||||
-rw-r--r-- | xfa/fgas/layout/fgas_rtfbreak.cpp | 72 | ||||
-rw-r--r-- | xfa/fgas/layout/fgas_rtfbreak.h | 8 | ||||
-rw-r--r-- | xfa/fgas/layout/fgas_textbreak.cpp | 63 | ||||
-rw-r--r-- | xfa/fgas/layout/fgas_textbreak.h | 7 |
6 files changed, 80 insertions, 140 deletions
diff --git a/xfa/fgas/layout/cfx_break.cpp b/xfa/fgas/layout/cfx_break.cpp index a8280b1161..52236f3176 100644 --- a/xfa/fgas/layout/cfx_break.cpp +++ b/xfa/fgas/layout/cfx_break.cpp @@ -7,6 +7,9 @@ #include "xfa/fgas/layout/cfx_break.h" #include <algorithm> +#include <vector> + +#include "third_party/base/stl_util.h" namespace { @@ -18,6 +21,7 @@ CFX_Break::CFX_Break(uint32_t dwLayoutStyles) : m_eCharType(FX_CHARTYPE_Unknown), m_bSingleLine(false), m_bCombText(false), + m_dwIdentity(0), m_dwLayoutStyles(dwLayoutStyles), m_iLineStart(0), m_iLineWidth(2000000), @@ -88,6 +92,21 @@ void CFX_Break::SetFontSize(float fFontSize) { FontChanged(); } +void CFX_Break::SetBreakStatus() { + ++m_dwIdentity; + int32_t iCount = m_pCurLine->CountChars(); + if (iCount < 1) + return; + + CFX_Char* tc = m_pCurLine->GetChar(iCount - 1); + if (tc->m_dwStatus == CFX_BreakType::None) + tc->m_dwStatus = CFX_BreakType::Piece; +} + +FX_CHARTYPE CFX_Break::GetUnifiedCharType(FX_CHARTYPE chartype) const { + return chartype >= FX_CHARTYPE_ArabicAlef ? FX_CHARTYPE_Arabic : chartype; +} + void CFX_Break::FontChanged() { m_iDefChar = 0; if (!m_pFont || m_wDefChar == 0xFEFF) @@ -140,3 +159,43 @@ void CFX_Break::SetLineBoundary(float fLineStart, float fLineEnd) { m_pCurLine->m_iStart = std::min(m_pCurLine->m_iStart, m_iLineWidth); m_pCurLine->m_iStart = std::max(m_pCurLine->m_iStart, m_iLineStart); } + +CFX_Char* CFX_Break::GetLastChar(int32_t index, + bool bOmitChar, + bool bRichText) const { + std::vector<CFX_Char>& tca = m_pCurLine->m_LineChars; + if (!pdfium::IndexInBounds(tca, index)) + return nullptr; + + int32_t iStart = pdfium::CollectionSize<int32_t>(tca) - 1; + while (iStart > -1) { + CFX_Char* pTC = &tca[iStart--]; + if (((bRichText && pTC->m_iCharWidth < 0) || bOmitChar) && + pTC->GetCharType() == FX_CHARTYPE_Combination) { + continue; + } + if (--index < 0) + return pTC; + } + return nullptr; +} + +int32_t CFX_Break::CountBreakPieces() const { + return HasLine() ? pdfium::CollectionSize<int32_t>( + m_Line[m_iReadyLineIndex].m_LinePieces) + : 0; +} + +const CFX_BreakPiece* CFX_Break::GetBreakPieceUnstable(int32_t index) const { + if (!HasLine()) + return nullptr; + if (!pdfium::IndexInBounds(m_Line[m_iReadyLineIndex].m_LinePieces, index)) + return nullptr; + return &m_Line[m_iReadyLineIndex].m_LinePieces[index]; +} + +void CFX_Break::ClearBreakPieces() { + if (HasLine()) + m_Line[m_iReadyLineIndex].Clear(); + m_iReadyLineIndex = -1; +} diff --git a/xfa/fgas/layout/cfx_break.h b/xfa/fgas/layout/cfx_break.h index 631cc5aaa1..4a7185bd70 100644 --- a/xfa/fgas/layout/cfx_break.h +++ b/xfa/fgas/layout/cfx_break.h @@ -50,14 +50,23 @@ class CFX_Break { void SetParagraphBreakChar(wchar_t wch); void SetDefaultChar(wchar_t wch); - virtual void SetBreakStatus() = 0; + int32_t CountBreakPieces() const; + const CFX_BreakPiece* GetBreakPieceUnstable(int32_t index) const; + void ClearBreakPieces(); + + CFX_Char* GetLastChar(int32_t index, bool bOmitChar, bool bRichText) const; protected: explicit CFX_Break(uint32_t dwLayoutStyles); + void SetBreakStatus(); + bool HasLine() const { return m_iReadyLineIndex >= 0; } + FX_CHARTYPE GetUnifiedCharType(FX_CHARTYPE dwType) const; + FX_CHARTYPE m_eCharType; bool m_bSingleLine; bool m_bCombText; + uint32_t m_dwIdentity; uint32_t m_dwLayoutStyles; int32_t m_iLineStart; int32_t m_iLineWidth; diff --git a/xfa/fgas/layout/fgas_rtfbreak.cpp b/xfa/fgas/layout/fgas_rtfbreak.cpp index 81fbea0cc6..07a3cefa69 100644 --- a/xfa/fgas/layout/fgas_rtfbreak.cpp +++ b/xfa/fgas/layout/fgas_rtfbreak.cpp @@ -17,8 +17,7 @@ CFX_RTFBreak::CFX_RTFBreak(uint32_t dwLayoutStyles) : CFX_Break(dwLayoutStyles), m_bPagination(false), m_iAlignment(CFX_RTFLineAlignment::Left), - m_pUserData(nullptr), - m_dwIdentity(0) { + m_pUserData(nullptr) { SetBreakStatus(); m_bPagination = !!(m_dwLayoutStyles & FX_LAYOUTSTYLE_Pagination); } @@ -50,40 +49,6 @@ void CFX_RTFBreak::SetUserData(const CFX_RetainPtr<CFX_Retainable>& pUserData) { m_pUserData = pUserData; } -void CFX_RTFBreak::SetBreakStatus() { - ++m_dwIdentity; - int32_t iCount = m_pCurLine->CountChars(); - if (iCount < 1) - return; - - CFX_Char* tc = m_pCurLine->GetChar(iCount - 1); - if (tc->m_dwStatus == CFX_BreakType::None) - tc->m_dwStatus = CFX_BreakType::Piece; -} - -CFX_Char* CFX_RTFBreak::GetLastChar(int32_t index) const { - std::vector<CFX_Char>& tca = m_pCurLine->m_LineChars; - int32_t iCount = pdfium::CollectionSize<int32_t>(tca); - if (index < 0 || index >= iCount) - return nullptr; - - int32_t iStart = iCount - 1; - while (iStart > -1) { - CFX_Char* pTC = &tca[iStart--]; - if (pTC->m_iCharWidth >= 0 || - pTC->GetCharType() != FX_CHARTYPE_Combination) { - if (--index < 0) - return pTC; - } - } - return nullptr; -} - -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 { return m_PositionedTabs.empty() ? m_iLineStart : m_PositionedTabs.back(); } @@ -167,7 +132,7 @@ void CFX_RTFBreak::AppendChar_Combination(CFX_Char* pCurChar) { iCharWidth *= m_iFontSize; iCharWidth = iCharWidth * m_iHorizontalScale / 100; - CFX_Char* pLastChar = GetLastChar(0); + CFX_Char* pLastChar = GetLastChar(0, false, true); if (pLastChar && pLastChar->GetCharType() > FX_CHARTYPE_Combination) iCharWidth = -iCharWidth; else @@ -224,10 +189,10 @@ CFX_BreakType CFX_RTFBreak::AppendChar_Arabic(CFX_Char* pCurChar) { bool bAlef = false; if (m_eCharType >= FX_CHARTYPE_ArabicAlef && m_eCharType <= FX_CHARTYPE_ArabicDistortion) { - pLastChar = GetLastChar(1); + pLastChar = GetLastChar(1, false, true); if (pLastChar) { m_pCurLine->m_iWidth -= pLastChar->m_iCharWidth; - CFX_Char* pPrevChar = GetLastChar(2); + CFX_Char* pPrevChar = GetLastChar(2, false, true); wForm = pdfium::arabic::GetFormChar(pLastChar, pPrevChar, pCurChar); bAlef = (wForm == 0xFEFF && pLastChar->GetCharType() == FX_CHARTYPE_ArabicAlef); @@ -292,7 +257,7 @@ CFX_BreakType CFX_RTFBreak::EndBreak(CFX_BreakType dwStatus) { return m_pCurLine->m_LinePieces.back().m_dwStatus; } - if (HasRTFLine()) { + if (HasLine()) { if (!m_Line[m_iReadyLineIndex].m_LinePieces.empty()) { if (dwStatus != CFX_BreakType::Piece) m_Line[m_iReadyLineIndex].m_LinePieces.back().m_dwStatus = dwStatus; @@ -324,7 +289,7 @@ CFX_BreakType CFX_RTFBreak::EndBreak(CFX_BreakType dwStatus) { m_pCurLine = pNextLine; m_pCurLine->m_iStart = m_iLineStart; - CFX_Char* pTC = GetLastChar(0); + CFX_Char* pTC = GetLastChar(0, false, true); m_eCharType = pTC ? pTC->GetCharType() : FX_CHARTYPE_Unknown; return dwStatus; } @@ -698,31 +663,6 @@ void CFX_RTFBreak::SplitTextLine(CFX_BreakLine* pCurLine, } } -int32_t CFX_RTFBreak::CountBreakPieces() const { - return HasRTFLine() ? pdfium::CollectionSize<int32_t>( - m_Line[m_iReadyLineIndex].m_LinePieces) - : 0; -} - -const CFX_BreakPiece* CFX_RTFBreak::GetBreakPieceUnstable(int32_t index) const { - if (!HasRTFLine()) - return nullptr; - - const std::vector<CFX_BreakPiece>& pRTFPieces = - m_Line[m_iReadyLineIndex].m_LinePieces; - if (!pdfium::IndexInBounds(pRTFPieces, index)) - return nullptr; - - return &pRTFPieces[index]; -} - -void CFX_RTFBreak::ClearBreakPieces() { - if (HasRTFLine()) - m_Line[m_iReadyLineIndex].Clear(); - - m_iReadyLineIndex = -1; -} - int32_t CFX_RTFBreak::GetDisplayPos(const FX_RTFTEXTOBJ* pText, FXTEXT_CHARPOS* pCharPos, bool bCharCode) const { diff --git a/xfa/fgas/layout/fgas_rtfbreak.h b/xfa/fgas/layout/fgas_rtfbreak.h index 865b17ffb3..7cbd250218 100644 --- a/xfa/fgas/layout/fgas_rtfbreak.h +++ b/xfa/fgas/layout/fgas_rtfbreak.h @@ -56,9 +56,6 @@ class CFX_RTFBreak : public CFX_Break { void AddPositionedTab(float fTabPos); CFX_BreakType EndBreak(CFX_BreakType dwStatus); - int32_t CountBreakPieces() const; - const CFX_BreakPiece* GetBreakPieceUnstable(int32_t index) const; - void ClearBreakPieces(); int32_t GetDisplayPos(const FX_RTFTEXTOBJ* pText, FXTEXT_CHARPOS* pCharPos, @@ -74,10 +71,6 @@ class CFX_RTFBreak : public CFX_Break { CFX_BreakType AppendChar_Control(CFX_Char* pCurChar); CFX_BreakType AppendChar_Arabic(CFX_Char* pCurChar); CFX_BreakType AppendChar_Others(CFX_Char* pCurChar); - void SetBreakStatus() override; - CFX_Char* GetLastChar(int32_t index) const; - bool HasRTFLine() const { return m_iReadyLineIndex >= 0; } - FX_CHARTYPE GetUnifiedCharType(FX_CHARTYPE chartype) const; int32_t GetLastPositionedTab() const; bool GetPositionedTab(int32_t* iTabPos) const; @@ -100,7 +93,6 @@ class CFX_RTFBreak : public CFX_Break { std::vector<int32_t> m_PositionedTabs; CFX_RTFLineAlignment m_iAlignment; CFX_RetainPtr<CFX_Retainable> m_pUserData; - uint32_t m_dwIdentity; }; #endif // XFA_FGAS_LAYOUT_FGAS_RTFBREAK_H_ diff --git a/xfa/fgas/layout/fgas_textbreak.cpp b/xfa/fgas/layout/fgas_textbreak.cpp index 41091700fb..c21d6bba3a 100644 --- a/xfa/fgas/layout/fgas_textbreak.cpp +++ b/xfa/fgas/layout/fgas_textbreak.cpp @@ -46,37 +46,6 @@ void CFX_TxtBreak::SetCombWidth(float fCombWidth) { m_iCombWidth = FXSYS_round(fCombWidth * 20000.0f); } -void CFX_TxtBreak::SetBreakStatus() { - int32_t iCount = m_pCurLine->CountChars(); - if (iCount < 1) - return; - - CFX_Char* pTC = m_pCurLine->GetChar(iCount - 1); - if (pTC->m_dwStatus == CFX_BreakType::None) - pTC->m_dwStatus = CFX_BreakType::Piece; -} -CFX_Char* CFX_TxtBreak::GetLastChar(int32_t index, bool bOmitChar) const { - std::vector<CFX_Char>& ca = m_pCurLine->m_LineChars; - int32_t iCount = pdfium::CollectionSize<int32_t>(ca); - if (index < 0 || index >= iCount) - return nullptr; - - int32_t iStart = iCount - 1; - while (iStart > -1) { - CFX_Char* pTC = &ca[iStart--]; - if (bOmitChar && pTC->GetCharType() == FX_CHARTYPE_Combination) - continue; - if (--index < 0) - return pTC; - } - return nullptr; -} - -inline FX_CHARTYPE CFX_TxtBreak::GetUnifiedCharType( - FX_CHARTYPE chartype) const { - return chartype >= FX_CHARTYPE_ArabicAlef ? FX_CHARTYPE_Arabic : chartype; -} - void CFX_TxtBreak::AppendChar_PageLoad(CFX_Char* pCurChar, uint32_t dwProps) { pCurChar->m_dwStatus = CFX_BreakType::None; pCurChar->m_dwCharStyles = m_iAlignment | (1 << 8); @@ -91,7 +60,7 @@ void CFX_TxtBreak::AppendChar_Combination(CFX_Char* pCurChar) { iCharWidth = m_iCombWidth; } else { wForm = wch; - CFX_Char* pLastChar = GetLastChar(0, false); + CFX_Char* pLastChar = GetLastChar(0, false, false); if (pLastChar && (pLastChar->m_dwCharStyles & FX_TXTCHARSTYLE_ArabicShadda) == 0) { bool bShadda = false; @@ -162,13 +131,13 @@ CFX_BreakType CFX_TxtBreak::AppendChar_Arabic(CFX_Char* pCurChar) { bool bAlef = false; if (!m_bCombText && m_eCharType >= FX_CHARTYPE_ArabicAlef && m_eCharType <= FX_CHARTYPE_ArabicDistortion) { - pLastChar = GetLastChar(1); + pLastChar = GetLastChar(1, true, false); if (pLastChar) { iCharWidth = pLastChar->m_iCharWidth; if (iCharWidth > 0) iLineWidth -= iCharWidth; - CFX_Char* pPrevChar = GetLastChar(2); + CFX_Char* pPrevChar = GetLastChar(2, true, false); wForm = pdfium::arabic::GetFormChar(pLastChar, pPrevChar, pCurChar); bAlef = (wForm == 0xFEFF && pLastChar->GetCharType() == FX_CHARTYPE_ArabicAlef); @@ -514,7 +483,7 @@ CFX_BreakType CFX_TxtBreak::EndBreak(CFX_BreakType dwStatus) { return m_pCurLine->m_LinePieces.back().m_dwStatus; } - if (HasTxtLine()) { + if (HasLine()) { if (!m_Line[m_iReadyLineIndex].m_LinePieces.empty()) { if (dwStatus != CFX_BreakType::Piece) m_Line[m_iReadyLineIndex].m_LinePieces.back().m_dwStatus = dwStatus; @@ -542,7 +511,7 @@ CFX_BreakType CFX_TxtBreak::EndBreak(CFX_BreakType dwStatus) { } m_pCurLine = pNextLine; - CFX_Char* pTC = GetLastChar(0, false); + CFX_Char* pTC = GetLastChar(0, false, false); m_eCharType = pTC ? pTC->GetCharType() : FX_CHARTYPE_Unknown; return dwStatus; @@ -682,28 +651,6 @@ void CFX_TxtBreak::SplitTextLine(CFX_BreakLine* pCurLine, pNextLine->m_iWidth = iWidth; } -int32_t CFX_TxtBreak::CountBreakPieces() const { - return HasTxtLine() ? pdfium::CollectionSize<int32_t>( - m_Line[m_iReadyLineIndex].m_LinePieces) - : 0; -} - -const CFX_BreakPiece* CFX_TxtBreak::GetBreakPiece(int32_t index) const { - if (!HasTxtLine()) - return nullptr; - - if (!pdfium::IndexInBounds(m_Line[m_iReadyLineIndex].m_LinePieces, index)) - return nullptr; - - return &m_Line[m_iReadyLineIndex].m_LinePieces[index]; -} - -void CFX_TxtBreak::ClearBreakPieces() { - if (HasTxtLine()) - m_Line[m_iReadyLineIndex].Clear(); - m_iReadyLineIndex = -1; -} - struct FX_FORMCHAR { uint16_t wch; uint16_t wForm; diff --git a/xfa/fgas/layout/fgas_textbreak.h b/xfa/fgas/layout/fgas_textbreak.h index 439a7ee15b..81aaf58219 100644 --- a/xfa/fgas/layout/fgas_textbreak.h +++ b/xfa/fgas/layout/fgas_textbreak.h @@ -64,9 +64,6 @@ class CFX_TxtBreak : public CFX_Break { void SetAlignment(int32_t iAlignment); void SetCombWidth(float fCombWidth); CFX_BreakType EndBreak(CFX_BreakType dwStatus); - int32_t CountBreakPieces() const; - const CFX_BreakPiece* GetBreakPiece(int32_t index) const; - void ClearBreakPieces(); int32_t GetDisplayPos(const FX_TXTRUN* pTxtRun, FXTEXT_CHARPOS* pCharPos, @@ -84,10 +81,6 @@ class CFX_TxtBreak : public CFX_Break { CFX_BreakType AppendChar_Arabic(CFX_Char* pCurChar); CFX_BreakType AppendChar_Others(CFX_Char* pCurChar); - void SetBreakStatus() override; - CFX_Char* GetLastChar(int32_t index, bool bOmitChar = true) const; - bool HasTxtLine() const { return m_iReadyLineIndex >= 0; } - FX_CHARTYPE GetUnifiedCharType(FX_CHARTYPE dwType) const; void ResetContextCharStyles(); bool EndBreak_SplitLine(CFX_BreakLine* pNextLine, bool bAllChars); void EndBreak_BidiLine(std::deque<FX_TPO>* tpos, CFX_BreakType dwStatus); |