summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-10-18 17:07:37 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-10-18 17:07:37 +0000
commit631a9e726578659ade3c37c4c274a1c5a1ee9a7b (patch)
treeaa45dd35593c180f996139bf50fbc0d2d521a93e
parent859312428770b89c01c5e9b9e06d5f53f7cd3afe (diff)
downloadpdfium-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>
-rw-r--r--xfa/fxfa/cxfa_textlayout.cpp72
-rw-r--r--xfa/fxfa/cxfa_textlayout.h21
2 files changed, 47 insertions, 46 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;
}
diff --git a/xfa/fxfa/cxfa_textlayout.h b/xfa/fxfa/cxfa_textlayout.h
index 9baf5ec76d..09740b3e6b 100644
--- a/xfa/fxfa/cxfa_textlayout.h
+++ b/xfa/fxfa/cxfa_textlayout.h
@@ -10,10 +10,10 @@
#include <memory>
#include <vector>
+#include "core/fxcrt/cfx_char.h"
#include "core/fxcrt/css/cfx_css.h"
#include "core/fxcrt/fx_coordinates.h"
#include "core/fxcrt/fx_string.h"
-#include "xfa/fgas/layout/cfx_rtfbreak.h"
#include "xfa/fxfa/cxfa_textparser.h"
class CFDE_RenderDevice;
@@ -28,6 +28,8 @@ class CXFA_PieceLine;
class CXFA_TextPiece;
class CXFA_TextProvider;
class CXFA_TextTabstopsContext;
+class FXTEXT_CHARPOS;
+struct FX_RTFTEXTOBJ;
class CXFA_TextLayout {
public:
@@ -54,7 +56,7 @@ class CXFA_TextLayout {
return &m_pieceLines;
}
- bool m_bHasBlock;
+ bool m_bHasBlock = false;
std::vector<int32_t> m_Blocks;
private:
@@ -91,7 +93,6 @@ class CXFA_TextLayout {
bool bEndBreak);
void EndBreak(CFX_BreakType dwStatus, float* pLinePos, bool bDefault);
bool IsEnd(bool bSavePieces);
- void ProcessText(WideString& wsText);
void UpdateAlign(float fHeight, float fBottom);
void RenderString(CFX_RenderDevice* pDevice,
CXFA_PieceLine* pPieceLine,
@@ -109,18 +110,18 @@ class CXFA_TextLayout {
bool Layout(int32_t iBlock);
int32_t CountBlocks() const;
- UnownedPtr<CXFA_FFDoc> m_pDoc;
- CXFA_TextProvider* m_pTextProvider; // Raw, TextProvider owned by tree node.
- CXFA_Node* m_pTextDataNode; // Raw, this class owned by tree node.
- bool m_bRichText;
+ bool m_bRichText = false;
+ bool m_bBlockContinue = true;
+ int32_t m_iLines = 0;
+ float m_fMaxWidth = 0;
+ UnownedPtr<CXFA_FFDoc> const m_pDoc;
+ CXFA_TextProvider* const m_pTextProvider; // Raw, owned by tree node.
+ CXFA_Node* m_pTextDataNode = nullptr; // Raw, owned by tree node.
std::unique_ptr<CFX_RTFBreak> m_pBreak;
std::unique_ptr<CXFA_LoaderContext> m_pLoader;
- int32_t m_iLines;
- float m_fMaxWidth;
CXFA_TextParser m_textParser;
std::vector<std::unique_ptr<CXFA_PieceLine>> m_pieceLines;
std::unique_ptr<CXFA_TextTabstopsContext> m_pTabstopContext;
- bool m_bBlockContinue;
};
#endif // XFA_FXFA_CXFA_TEXTLAYOUT_H_