diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-03-01 15:59:06 -0500 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-03-01 22:33:08 +0000 |
commit | 65ec174225546abdc977c8f4c92e792e44ca4e0a (patch) | |
tree | 87e42d8ba51ee6d838e006a3b43120a99c55ddc1 /xfa/fgas/layout/fgas_rtfbreak.cpp | |
parent | e65d62cb8a67b776439142ee4a62cc0c3cd66f08 (diff) | |
download | pdfium-65ec174225546abdc977c8f4c92e792e44ca4e0a.tar.xz |
Convert positioned tabs to std::vectorchromium/3028
This Cl changes from an CFX_ArrayTemplate to a std::vector and cleans up the
supporting code.
Change-Id: If07cb4fbd5fb9bcb078b5792a74ea62527cdd9a4
Reviewed-on: https://pdfium-review.googlesource.com/2884
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Nicolás Peña <npm@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'xfa/fgas/layout/fgas_rtfbreak.cpp')
-rw-r--r-- | xfa/fgas/layout/fgas_rtfbreak.cpp | 50 |
1 files changed, 18 insertions, 32 deletions
diff --git a/xfa/fgas/layout/fgas_rtfbreak.cpp b/xfa/fgas/layout/fgas_rtfbreak.cpp index fdc9a57038..648897818f 100644 --- a/xfa/fgas/layout/fgas_rtfbreak.cpp +++ b/xfa/fgas/layout/fgas_rtfbreak.cpp @@ -41,7 +41,6 @@ CFX_RTFBreak::CFX_RTFBreak(uint32_t dwLayoutStyles) m_iFontHeight(240), m_iFontSize(240), m_iTabWidth(720000), - m_PositionedTabs(), m_wDefChar(0xFEFF), m_iDefChar(0), m_wLineBreakChar(L'\n'), @@ -65,7 +64,6 @@ CFX_RTFBreak::CFX_RTFBreak(uint32_t dwLayoutStyles) CFX_RTFBreak::~CFX_RTFBreak() { Reset(); - m_PositionedTabs.RemoveAll(); } void CFX_RTFBreak::SetLineBoundary(FX_FLOAT fLineStart, FX_FLOAT fLineEnd) { @@ -122,20 +120,13 @@ void CFX_RTFBreak::SetTabWidth(FX_FLOAT fTabWidth) { } void CFX_RTFBreak::AddPositionedTab(FX_FLOAT fTabPos) { - int32_t iLineEnd = m_iBoundaryEnd; - int32_t iTabPos = FXSYS_round(fTabPos * 20000.0f) + m_iBoundaryStart; - if (iTabPos > iLineEnd) - iTabPos = iLineEnd; - if (m_PositionedTabs.Find(iTabPos, 0) > -1) + int32_t iTabPos = std::min(FXSYS_round(fTabPos * 20000.0f) + m_iBoundaryStart, + m_iBoundaryEnd); + auto it = std::lower_bound(m_PositionedTabs.begin(), m_PositionedTabs.end(), + iTabPos); + if (it != m_PositionedTabs.end() && *it == iTabPos) return; - - int32_t iCount = m_PositionedTabs.GetSize(); - int32_t iFind = 0; - for (; iFind < iCount; iFind++) { - if (m_PositionedTabs[iFind] > iTabPos) - break; - } - m_PositionedTabs.InsertAt(iFind, iTabPos); + m_PositionedTabs.insert(it, iTabPos); } void CFX_RTFBreak::SetLineBreakTolerance(FX_FLOAT fTolerance) { @@ -222,21 +213,17 @@ inline FX_CHARTYPE CFX_RTFBreak::GetUnifiedCharType( } int32_t CFX_RTFBreak::GetLastPositionedTab() const { - int32_t iCount = m_PositionedTabs.GetSize(); - if (iCount < 1) - return m_iBoundaryStart; - return m_PositionedTabs[iCount - 1]; + return m_PositionedTabs.empty() ? m_iBoundaryStart : m_PositionedTabs.back(); } 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]; - return true; - } - } - return false; + auto it = std::upper_bound(m_PositionedTabs.begin(), m_PositionedTabs.end(), + *iTabPos); + if (it == m_PositionedTabs.end()) + return false; + + *iTabPos = *it; + return true; } CFX_RTFBreakType CFX_RTFBreak::AppendChar(FX_WCHAR wch) { @@ -739,7 +726,7 @@ int32_t CFX_RTFBreak::GetBreakPos(std::vector<CFX_RTFChar>& tca, CFX_RTFChar* pCharArray = tca.data(); CFX_RTFChar* pCur = pCharArray + iLength; - iLength--; + --iLength; if (bAllChars) pCur->m_nBreakType = FX_LBT_UNKNOWN; @@ -922,12 +909,11 @@ int32_t CFX_RTFBreak::GetDisplayPos(const FX_RTFTEXTOBJ* pText, iWidth = pText->pWidths[i]; dwProps = FX_GetUnicodeProperties(wch); dwCharType = (dwProps & FX_CHARTYPEBITSMASK); - if (dwCharType == FX_CHARTYPE_ArabicAlef && iWidth == 0) { - wPrev = 0xFEFF; + if (iWidth == 0) { + if (dwCharType == FX_CHARTYPE_ArabicAlef) + wPrev = 0xFEFF; continue; } - if (iWidth == 0) - continue; iCharWidth = FXSYS_abs(iWidth); bEmptyChar = |