diff options
author | Lei Zhang <thestig@chromium.org> | 2018-10-18 17:07:37 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-10-18 17:07:37 +0000 |
commit | 631a9e726578659ade3c37c4c274a1c5a1ee9a7b (patch) | |
tree | aa45dd35593c180f996139bf50fbc0d2d521a93e /xfa/fxfa/cxfa_textlayout.cpp | |
parent | 859312428770b89c01c5e9b9e06d5f53f7cd3afe (diff) | |
download | pdfium-631a9e726578659ade3c37c4c274a1c5a1ee9a7b.tar.xz |
Clean up CXFA_TextLayout.
- Forward declare more.
- Initialize members in the header.
- Move code into anonymous function and fix nits.
Change-Id: I5fda66266ead631ae63461b6455d516dbec629fc
Reviewed-on: https://pdfium-review.googlesource.com/c/44254
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'xfa/fxfa/cxfa_textlayout.cpp')
-rw-r--r-- | xfa/fxfa/cxfa_textlayout.cpp | 72 |
1 files changed, 36 insertions, 36 deletions
diff --git a/xfa/fxfa/cxfa_textlayout.cpp b/xfa/fxfa/cxfa_textlayout.cpp index 49cb13a714..6e91a59864 100644 --- a/xfa/fxfa/cxfa_textlayout.cpp +++ b/xfa/fxfa/cxfa_textlayout.cpp @@ -21,6 +21,7 @@ #include "third_party/base/stl_util.h" #include "xfa/fde/cfde_textout.h" #include "xfa/fgas/font/cfgas_gefont.h" +#include "xfa/fgas/layout/cfx_rtfbreak.h" #include "xfa/fxfa/cxfa_linkuserdata.h" #include "xfa/fxfa/cxfa_loadercontext.h" #include "xfa/fxfa/cxfa_pieceline.h" @@ -35,16 +36,37 @@ #define XFA_LOADERCNTXTFLG_FILTERSPACE 0x001 +namespace { + +void ProcessText(WideString* pText) { + int32_t iLen = pText->GetLength(); + if (iLen == 0) + return; + + int32_t iTrimLeft = 0; + { + // Span's lifetime must end before ReleaseBuffer() below. + pdfium::span<wchar_t> psz = pText->GetBuffer(iLen); + wchar_t wPrev = 0; + for (int32_t i = 0; i < iLen; i++) { + wchar_t wch = psz[i]; + if (wch < 0x20) + wch = 0x20; + if (wch == 0x20 && wPrev == 0x20) + continue; + + wPrev = wch; + psz[iTrimLeft++] = wch; + } + } + pText->ReleaseBuffer(iTrimLeft); +} + +} // namespace + CXFA_TextLayout::CXFA_TextLayout(CXFA_FFDoc* doc, CXFA_TextProvider* pTextProvider) - : m_bHasBlock(false), - m_pDoc(doc), - m_pTextProvider(pTextProvider), - m_pTextDataNode(nullptr), - m_bRichText(false), - m_iLines(0), - m_fMaxWidth(0), - m_bBlockContinue(true) { + : m_pDoc(doc), m_pTextProvider(pTextProvider) { ASSERT(m_pTextProvider); } @@ -360,7 +382,7 @@ float CXFA_TextLayout::DoLayout(int32_t iBlockIndex, (m_pLoader->m_BlocksHeight[iBlockIndex * 2] == iBlockIndex)) { m_pLoader->m_BlocksHeight[iBlockIndex * 2 + 1] = fCalcHeight; } else { - m_pLoader->m_BlocksHeight.push_back((float)iBlockIndex); + m_pLoader->m_BlocksHeight.push_back(iBlockIndex); m_pLoader->m_BlocksHeight.push_back(fCalcHeight); } } @@ -783,7 +805,7 @@ bool CXFA_TextLayout::LoadRichText( int32_t iLength = wsText.GetLength(); if (iLength > 0 && bContentNode && !bSpaceRun) - ProcessText(wsText); + ProcessText(&wsText); if (m_pLoader) { if (wsText.GetLength() > 0 && @@ -912,30 +934,6 @@ bool CXFA_TextLayout::IsEnd(bool bSavePieces) { return false; } -void CXFA_TextLayout::ProcessText(WideString& wsText) { - int32_t iLen = wsText.GetLength(); - if (iLen == 0) - return; - - int32_t iTrimLeft = 0; - { - // Span's lifetime must end before ReleaseBuffer() below. - pdfium::span<wchar_t> psz = wsText.GetBuffer(iLen); - wchar_t wPrev = 0; - for (int32_t i = 0; i < iLen; i++) { - wchar_t wch = psz[i]; - if (wch < 0x20) - wch = 0x20; - if (wch == 0x20 && wPrev == 0x20) - continue; - - wPrev = wch; - psz[iTrimLeft++] = wch; - } - } - wsText.ReleaseBuffer(iTrimLeft); -} - void CXFA_TextLayout::EndBreak(CFX_BreakType dwStatus, float* pLinePos, bool bSavePieces) { @@ -1041,7 +1039,8 @@ void CXFA_TextLayout::AppendTextLine(CFX_BreakType dwStatus, pTP->fFontSize = m_textParser.GetFontSize(m_pTextProvider, pStyle.Get()); pTP->rtPiece.left = pPiece->m_iStartPos / 20000.0f; pTP->rtPiece.width = pPiece->m_iWidth / 20000.0f; - pTP->rtPiece.height = (float)pPiece->m_iFontSize * fVerScale / 20.0f; + pTP->rtPiece.height = + static_cast<float>(pPiece->m_iFontSize) * fVerScale / 20.0f; float fBaseLineTemp = m_textParser.GetBaseline(m_pTextProvider, pStyle.Get()); pTP->rtPiece.top = fBaseLineTemp; @@ -1079,7 +1078,8 @@ void CXFA_TextLayout::AppendTextLine(CFX_BreakType dwStatus, m_pTextProvider, pStyle.Get(), m_iLines == 0, fVerScale); if (fBaseLine > 0) { float fLineHeightTmp = - fBaseLine + (float)pPiece->m_iFontSize * fVerScale / 20.0f; + fBaseLine + + static_cast<float>(pPiece->m_iFontSize) * fVerScale / 20.0f; if (fLineHeight < fLineHeightTmp) { fLineHeight = fLineHeightTmp; } |