diff options
author | Lei Zhang <thestig@chromium.org> | 2018-10-18 17:37:42 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-10-18 17:37:42 +0000 |
commit | 2486456feae06bd0dd2254f1569cf2cfb8d04104 (patch) | |
tree | 7235e10f956c1e4bc54e733c9730108a8d05c5c9 | |
parent | 631a9e726578659ade3c37c4c274a1c5a1ee9a7b (diff) | |
download | pdfium-2486456feae06bd0dd2254f1569cf2cfb8d04104.tar.xz |
Convert CXFA_LoaderContext to a struct.
It only has members and they are all public. Initialize them in the
header, remove an unused one, and remove the "m_" prefix.
Change-Id: Ia4a0b673794f82afddfc6c1bd3a73700cb968259
Reviewed-on: https://pdfium-review.googlesource.com/c/44255
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
-rw-r--r-- | xfa/fxfa/cxfa_loadercontext.cpp | 16 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_loadercontext.h | 33 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_textlayout.cpp | 153 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_textlayout.h | 4 |
4 files changed, 98 insertions, 108 deletions
diff --git a/xfa/fxfa/cxfa_loadercontext.cpp b/xfa/fxfa/cxfa_loadercontext.cpp index 05ba9f19d1..5f6605019e 100644 --- a/xfa/fxfa/cxfa_loadercontext.cpp +++ b/xfa/fxfa/cxfa_loadercontext.cpp @@ -6,16 +6,8 @@ #include "xfa/fxfa/cxfa_loadercontext.h" -CXFA_LoaderContext::CXFA_LoaderContext() - : m_bSaveLineHeight(false), - m_fWidth(0), - m_fHeight(0), - m_fLastPos(0), - m_fStartLineOffset(0), - m_iChar(0), - m_iTotalLines(-1), - m_dwFlags(0), - m_pXMLNode(nullptr), - m_pNode(nullptr) {} +#include "core/fxcrt/css/cfx_csscomputedstyle.h" -CXFA_LoaderContext::~CXFA_LoaderContext() {} +CXFA_LoaderContext::CXFA_LoaderContext() = default; + +CXFA_LoaderContext::~CXFA_LoaderContext() = default; diff --git a/xfa/fxfa/cxfa_loadercontext.h b/xfa/fxfa/cxfa_loadercontext.h index a6d8fb0eeb..87a795be9c 100644 --- a/xfa/fxfa/cxfa_loadercontext.h +++ b/xfa/fxfa/cxfa_loadercontext.h @@ -9,32 +9,31 @@ #include <vector> -#include "core/fxcrt/css/cfx_csscomputedstyle.h" #include "core/fxcrt/fx_system.h" +#include "core/fxcrt/retain_ptr.h" #include "core/fxcrt/unowned_ptr.h" +class CFX_CSSComputedStyle; class CFX_XMLNode; class CXFA_Node; -class CXFA_LoaderContext { - public: +struct CXFA_LoaderContext { CXFA_LoaderContext(); ~CXFA_LoaderContext(); - bool m_bSaveLineHeight; - float m_fWidth; - float m_fHeight; - float m_fLastPos; - float m_fStartLineOffset; - int32_t m_iChar; - int32_t m_iLines; - int32_t m_iTotalLines; - uint32_t m_dwFlags; - UnownedPtr<const CFX_XMLNode> m_pXMLNode; - UnownedPtr<CXFA_Node> m_pNode; - RetainPtr<CFX_CSSComputedStyle> m_pParentStyle; - std::vector<float> m_lineHeights; - std::vector<float> m_BlocksHeight; + bool bSaveLineHeight = false; + float fWidth = 0; + float fHeight = 0; + float fLastPos = 0; + float fStartLineOffset = 0; + int32_t iChar = 0; + int32_t iTotalLines = -1; + uint32_t dwFlags = 0; + UnownedPtr<const CFX_XMLNode> pXMLNode; + UnownedPtr<CXFA_Node> pNode; + RetainPtr<CFX_CSSComputedStyle> pParentStyle; + std::vector<float> lineHeights; + std::vector<float> blocksHeight; }; #endif // XFA_FXFA_CXFA_LOADERCONTEXT_H_ diff --git a/xfa/fxfa/cxfa_textlayout.cpp b/xfa/fxfa/cxfa_textlayout.cpp index 6e91a59864..ec36bcb7a3 100644 --- a/xfa/fxfa/cxfa_textlayout.cpp +++ b/xfa/fxfa/cxfa_textlayout.cpp @@ -274,19 +274,19 @@ float CXFA_TextLayout::GetLayoutHeight() { if (!m_pLoader) return 0; - if (m_pLoader->m_lineHeights.empty() && m_pLoader->m_fWidth > 0) { - CFX_SizeF szMax(m_pLoader->m_fWidth, m_pLoader->m_fHeight); - m_pLoader->m_bSaveLineHeight = true; - m_pLoader->m_fLastPos = 0; + if (m_pLoader->lineHeights.empty() && m_pLoader->fWidth > 0) { + CFX_SizeF szMax(m_pLoader->fWidth, m_pLoader->fHeight); + m_pLoader->bSaveLineHeight = true; + m_pLoader->fLastPos = 0; CFX_SizeF szDef = CalcSize(szMax, szMax); - m_pLoader->m_bSaveLineHeight = false; + m_pLoader->bSaveLineHeight = false; return szDef.height; } - float fHeight = m_pLoader->m_fHeight; + float fHeight = m_pLoader->fHeight; if (fHeight < 0.1f) { fHeight = 0; - for (float value : m_pLoader->m_lineHeights) + for (float value : m_pLoader->lineHeights) fHeight += value; } return fHeight; @@ -297,23 +297,23 @@ float CXFA_TextLayout::StartLayout(float fWidth) { m_pLoader = pdfium::MakeUnique<CXFA_LoaderContext>(); if (fWidth < 0 || - (m_pLoader->m_fWidth > -1 && fabs(fWidth - m_pLoader->m_fWidth) > 0)) { - m_pLoader->m_lineHeights.clear(); + (m_pLoader->fWidth > -1 && fabs(fWidth - m_pLoader->fWidth) > 0)) { + m_pLoader->lineHeights.clear(); m_Blocks.clear(); Unload(); - m_pLoader->m_fStartLineOffset = 0; + m_pLoader->fStartLineOffset = 0; } - m_pLoader->m_fWidth = fWidth; + m_pLoader->fWidth = fWidth; if (fWidth >= 0) return fWidth; CFX_SizeF szMax; - m_pLoader->m_bSaveLineHeight = true; - m_pLoader->m_fLastPos = 0; + m_pLoader->bSaveLineHeight = true; + m_pLoader->fLastPos = 0; CFX_SizeF szDef = CalcSize(szMax, szMax); - m_pLoader->m_bSaveLineHeight = false; + m_pLoader->bSaveLineHeight = false; return szDef.width; } @@ -329,7 +329,7 @@ float CXFA_TextLayout::DoLayout(int32_t iBlockIndex, if (fHeight < 0) fHeight = GetLayoutHeight(); - m_pLoader->m_fHeight = fHeight; + m_pLoader->fHeight = fHeight; if (fContentAreaHeight < 0) return fCalcHeight; @@ -342,11 +342,11 @@ float CXFA_TextLayout::DoLayout(int32_t iBlockIndex, fHeight /= 2.0f; else if (iAlign != XFA_AttributeEnum::Bottom) fHeight = 0; - m_pLoader->m_fStartLineOffset = fHeight; + m_pLoader->fStartLineOffset = fHeight; } } - float fLinePos = m_pLoader->m_fStartLineOffset; + float fLinePos = m_pLoader->fStartLineOffset; int32_t iLineIndex = 0; if (iBlockCount > 1) { if (iBlockCount >= (iBlockIndex + 1) * 2) { @@ -354,16 +354,16 @@ float CXFA_TextLayout::DoLayout(int32_t iBlockIndex, } else { iLineIndex = m_Blocks[iBlockCount - 1] + m_Blocks[iBlockCount - 2]; } - if (!m_pLoader->m_BlocksHeight.empty()) { + if (!m_pLoader->blocksHeight.empty()) { for (int32_t i = 0; i < iBlockIndex; i++) - fLinePos -= m_pLoader->m_BlocksHeight[i * 2 + 1]; + fLinePos -= m_pLoader->blocksHeight[i * 2 + 1]; } } - int32_t iCount = pdfium::CollectionSize<int32_t>(m_pLoader->m_lineHeights); + int32_t iCount = pdfium::CollectionSize<int32_t>(m_pLoader->lineHeights); int32_t i = 0; for (i = iLineIndex; i < iCount; i++) { - float fLineHeight = m_pLoader->m_lineHeights[i]; + float fLineHeight = m_pLoader->lineHeights[i]; if (i == iLineIndex && fLineHeight - fContentAreaHeight > 0.001) return 0; @@ -377,13 +377,13 @@ float CXFA_TextLayout::DoLayout(int32_t iBlockIndex, } if (i == iLineIndex) { if (fCalcHeight <= fLinePos) { - if (pdfium::CollectionSize<int32_t>(m_pLoader->m_BlocksHeight) > + if (pdfium::CollectionSize<int32_t>(m_pLoader->blocksHeight) > iBlockIndex * 2 && - (m_pLoader->m_BlocksHeight[iBlockIndex * 2] == iBlockIndex)) { - m_pLoader->m_BlocksHeight[iBlockIndex * 2 + 1] = fCalcHeight; + (m_pLoader->blocksHeight[iBlockIndex * 2] == iBlockIndex)) { + m_pLoader->blocksHeight[iBlockIndex * 2 + 1] = fCalcHeight; } else { - m_pLoader->m_BlocksHeight.push_back(iBlockIndex); - m_pLoader->m_BlocksHeight.push_back(fCalcHeight); + m_pLoader->blocksHeight.push_back(iBlockIndex); + m_pLoader->blocksHeight.push_back(fCalcHeight); } } return fCalcHeight; @@ -425,8 +425,8 @@ float CXFA_TextLayout::Layout(const CFX_SizeF& size) { Unload(); m_pBreak = CreateBreak(true); if (m_pLoader) { - m_pLoader->m_iTotalLines = -1; - m_pLoader->m_iChar = 0; + m_pLoader->iTotalLines = -1; + m_pLoader->iChar = 0; } m_iLines = 0; @@ -440,38 +440,38 @@ float CXFA_TextLayout::Layout(const CFX_SizeF& size) { bool CXFA_TextLayout::Layout(int32_t iBlock) { if (!m_pLoader || iBlock < 0 || iBlock >= CountBlocks()) return false; - if (m_pLoader->m_fWidth < 1) + if (m_pLoader->fWidth < 1) return false; - m_pLoader->m_iTotalLines = -1; + m_pLoader->iTotalLines = -1; m_iLines = 0; float fLinePos = 0; CXFA_Node* pNode = nullptr; - CFX_SizeF szText(m_pLoader->m_fWidth, m_pLoader->m_fHeight); + CFX_SizeF szText(m_pLoader->fWidth, m_pLoader->fHeight); int32_t iCount = pdfium::CollectionSize<int32_t>(m_Blocks); int32_t iBlocksHeightCount = - pdfium::CollectionSize<int32_t>(m_pLoader->m_BlocksHeight); + pdfium::CollectionSize<int32_t>(m_pLoader->blocksHeight); iBlocksHeightCount /= 2; if (iBlock < iBlocksHeightCount) return true; if (iBlock == iBlocksHeightCount) { Unload(); m_pBreak = CreateBreak(true); - fLinePos = m_pLoader->m_fStartLineOffset; + fLinePos = m_pLoader->fStartLineOffset; for (int32_t i = 0; i < iBlocksHeightCount; i++) - fLinePos -= m_pLoader->m_BlocksHeight[i * 2 + 1]; + fLinePos -= m_pLoader->blocksHeight[i * 2 + 1]; - m_pLoader->m_iChar = 0; + m_pLoader->iChar = 0; if (iCount > 1) - m_pLoader->m_iTotalLines = m_Blocks[iBlock * 2 + 1]; + m_pLoader->iTotalLines = m_Blocks[iBlock * 2 + 1]; Loader(szText.width, &fLinePos, true); - if (iCount == 0 && m_pLoader->m_fStartLineOffset < 0.1f) + if (iCount == 0 && m_pLoader->fStartLineOffset < 0.1f) UpdateAlign(szText.height, fLinePos); } else if (m_pTextDataNode) { iBlock *= 2; if (iBlock < iCount - 2) - m_pLoader->m_iTotalLines = m_Blocks[iBlock + 1]; + m_pLoader->iTotalLines = m_Blocks[iBlock + 1]; m_pBreak->Reset(); if (m_bRichText) { @@ -479,14 +479,14 @@ bool CXFA_TextLayout::Layout(int32_t iBlock) { if (!pContainerNode) return true; - const CFX_XMLNode* pXMLNode = m_pLoader->m_pXMLNode.Get(); + const CFX_XMLNode* pXMLNode = m_pLoader->pXMLNode.Get(); if (!pXMLNode) return true; const CFX_XMLNode* pSaveXMLNode = pXMLNode; for (; pXMLNode; pXMLNode = pXMLNode->GetNextSibling()) { if (!LoadRichText(pXMLNode, szText.width, &fLinePos, - m_pLoader->m_pParentStyle, true, nullptr, true, false, + m_pLoader->pParentStyle, true, nullptr, true, false, 0)) { break; } @@ -496,8 +496,8 @@ bool CXFA_TextLayout::Layout(int32_t iBlock) { if (pXMLNode == pContainerNode) break; if (!LoadRichText(pXMLNode, szText.width, &fLinePos, - m_pLoader->m_pParentStyle, true, nullptr, false, - false, 0)) { + m_pLoader->pParentStyle, true, nullptr, false, false, + 0)) { break; } pSaveXMLNode = pXMLNode; @@ -506,14 +506,14 @@ bool CXFA_TextLayout::Layout(int32_t iBlock) { continue; for (; pXMLNode; pXMLNode = pXMLNode->GetNextSibling()) { if (!LoadRichText(pXMLNode, szText.width, &fLinePos, - m_pLoader->m_pParentStyle, true, nullptr, true, - false, 0)) { + m_pLoader->pParentStyle, true, nullptr, true, false, + 0)) { break; } } } } else { - pNode = m_pLoader->m_pNode.Get(); + pNode = m_pLoader->pNode.Get(); if (!pNode) return true; LoadText(pNode, szText.width, &fLinePos, true); @@ -531,21 +531,21 @@ void CXFA_TextLayout::ItemBlocks(const CFX_RectF& rtText, int32_t iBlockIndex) { return; int32_t iCountHeight = - pdfium::CollectionSize<int32_t>(m_pLoader->m_lineHeights); + pdfium::CollectionSize<int32_t>(m_pLoader->lineHeights); if (iCountHeight == 0) return; bool bEndItem = true; int32_t iBlockCount = pdfium::CollectionSize<int32_t>(m_Blocks); - float fLinePos = m_pLoader->m_fStartLineOffset; + float fLinePos = m_pLoader->fStartLineOffset; int32_t iLineIndex = 0; if (iBlockIndex > 0) { int32_t iBlockHeightCount = - pdfium::CollectionSize<int32_t>(m_pLoader->m_BlocksHeight); + pdfium::CollectionSize<int32_t>(m_pLoader->blocksHeight); iBlockHeightCount /= 2; if (iBlockHeightCount >= iBlockIndex) { for (int32_t i = 0; i < iBlockIndex; i++) - fLinePos -= m_pLoader->m_BlocksHeight[i * 2 + 1]; + fLinePos -= m_pLoader->blocksHeight[i * 2 + 1]; } else { fLinePos = 0; } @@ -554,7 +554,7 @@ void CXFA_TextLayout::ItemBlocks(const CFX_RectF& rtText, int32_t iBlockIndex) { int32_t i = 0; for (i = iLineIndex; i < iCountHeight; i++) { - float fLineHeight = m_pLoader->m_lineHeights[i]; + float fLineHeight = m_pLoader->lineHeights[i]; if (fLinePos + fLineHeight - rtText.height > 0.001) { m_Blocks.push_back(iLineIndex); m_Blocks.push_back(i - iLineIndex); @@ -700,7 +700,7 @@ void CXFA_TextLayout::LoadText(CXFA_Node* pNode, wsText.TrimRight(L" "); bool bRet = AppendChar(wsText, pLinePos, fSpaceAbove, bSavePieces); if (bRet && m_pLoader) - m_pLoader->m_pNode = pNode; + m_pLoader->pNode = pNode; else EndBreak(CFX_BreakType::Paragraph, pLinePos, bSavePieces); } @@ -730,8 +730,7 @@ bool CXFA_TextLayout::LoadRichText( bool bCurLi = false; const CFX_XMLElement* pElement = nullptr; if (pContext) { - if (m_bBlockContinue || - (m_pLoader && pXMLNode == m_pLoader->m_pXMLNode)) { + if (m_bBlockContinue || (m_pLoader && pXMLNode == m_pLoader->pXMLNode)) { m_bBlockContinue = true; } if (pXMLNode->GetType() == FX_XMLNODE_Text) { @@ -809,24 +808,24 @@ bool CXFA_TextLayout::LoadRichText( if (m_pLoader) { if (wsText.GetLength() > 0 && - (m_pLoader->m_dwFlags & XFA_LOADERCNTXTFLG_FILTERSPACE)) { + (m_pLoader->dwFlags & XFA_LOADERCNTXTFLG_FILTERSPACE)) { wsText.TrimLeft(L" "); } if (CFX_CSSDisplay::Block == eDisplay) { - m_pLoader->m_dwFlags |= XFA_LOADERCNTXTFLG_FILTERSPACE; + m_pLoader->dwFlags |= XFA_LOADERCNTXTFLG_FILTERSPACE; } else if (CFX_CSSDisplay::Inline == eDisplay && - (m_pLoader->m_dwFlags & XFA_LOADERCNTXTFLG_FILTERSPACE)) { - m_pLoader->m_dwFlags &= ~XFA_LOADERCNTXTFLG_FILTERSPACE; + (m_pLoader->dwFlags & XFA_LOADERCNTXTFLG_FILTERSPACE)) { + m_pLoader->dwFlags &= ~XFA_LOADERCNTXTFLG_FILTERSPACE; } else if (wsText.GetLength() > 0 && (0x20 == wsText[wsText.GetLength() - 1])) { - m_pLoader->m_dwFlags |= XFA_LOADERCNTXTFLG_FILTERSPACE; + m_pLoader->dwFlags |= XFA_LOADERCNTXTFLG_FILTERSPACE; } else if (wsText.GetLength() != 0) { - m_pLoader->m_dwFlags &= ~XFA_LOADERCNTXTFLG_FILTERSPACE; + m_pLoader->dwFlags &= ~XFA_LOADERCNTXTFLG_FILTERSPACE; } } if (wsText.GetLength() > 0) { - if (!m_pLoader || m_pLoader->m_iChar == 0) { + if (!m_pLoader || m_pLoader->iChar == 0) { auto pUserData = pdfium::MakeRetain<CXFA_TextUserData>( bContentNode ? pParentStyle : pStyle, pLinkData); m_pBreak->SetUserData(pUserData); @@ -834,11 +833,11 @@ bool CXFA_TextLayout::LoadRichText( if (AppendChar(wsText, pLinePos, 0, bSavePieces)) { if (m_pLoader) - m_pLoader->m_dwFlags &= ~XFA_LOADERCNTXTFLG_FILTERSPACE; + m_pLoader->dwFlags &= ~XFA_LOADERCNTXTFLG_FILTERSPACE; if (IsEnd(bSavePieces)) { - if (m_pLoader && m_pLoader->m_iTotalLines > -1) { - m_pLoader->m_pXMLNode = pXMLNode; - m_pLoader->m_pParentStyle = pParentStyle; + if (m_pLoader && m_pLoader->iTotalLines > -1) { + m_pLoader->pXMLNode = pXMLNode; + m_pLoader->pParentStyle = pParentStyle; } return false; } @@ -861,7 +860,7 @@ bool CXFA_TextLayout::LoadRichText( if (m_pLoader) { if (CFX_CSSDisplay::Block == eDisplay) - m_pLoader->m_dwFlags |= XFA_LOADERCNTXTFLG_FILTERSPACE; + m_pLoader->dwFlags |= XFA_LOADERCNTXTFLG_FILTERSPACE; } if (bCurLi) EndBreak(CFX_BreakType::Line, pLinePos, bSavePieces); @@ -882,9 +881,9 @@ bool CXFA_TextLayout::LoadRichText( m_pTabstopContext->RemoveAll(); } if (IsEnd(bSavePieces)) { - if (m_pLoader && m_pLoader->m_iTotalLines > -1) { - m_pLoader->m_pXMLNode = pXMLNode->GetNextSibling(); - m_pLoader->m_pParentStyle = pParentStyle; + if (m_pLoader && m_pLoader->iTotalLines > -1) { + m_pLoader->pXMLNode = pXMLNode->GetNextSibling(); + m_pLoader->pParentStyle = pParentStyle; } return false; } @@ -900,7 +899,7 @@ bool CXFA_TextLayout::AppendChar(const WideString& wsText, CFX_BreakType dwStatus = CFX_BreakType::None; int32_t iChar = 0; if (m_pLoader) - iChar = m_pLoader->m_iChar; + iChar = m_pLoader->iChar; int32_t iLength = wsText.GetLength(); for (int32_t i = iChar; i < iLength; i++) { @@ -913,7 +912,7 @@ bool CXFA_TextLayout::AppendChar(const WideString& wsText, AppendTextLine(dwStatus, pLinePos, bSavePieces, false); if (IsEnd(bSavePieces)) { if (m_pLoader) - m_pLoader->m_iChar = i; + m_pLoader->iChar = i; return true; } if (dwStatus == CFX_BreakType::Paragraph && m_bRichText) @@ -921,7 +920,7 @@ bool CXFA_TextLayout::AppendChar(const WideString& wsText, } } if (m_pLoader) - m_pLoader->m_iChar = 0; + m_pLoader->iChar = 0; return false; } @@ -929,8 +928,8 @@ bool CXFA_TextLayout::AppendChar(const WideString& wsText, bool CXFA_TextLayout::IsEnd(bool bSavePieces) { if (!bSavePieces) return false; - if (m_pLoader && m_pLoader->m_iTotalLines > 0) - return m_iLines >= m_pLoader->m_iTotalLines; + if (m_pLoader && m_pLoader->iTotalLines > 0) + return m_iLines >= m_pLoader->iTotalLines; return false; } @@ -1089,10 +1088,10 @@ void CXFA_TextLayout::AppendTextLine(CFX_BreakType dwStatus, } *pLinePos += fLineStep; m_fMaxWidth = std::max(m_fMaxWidth, fLineWidth); - if (m_pLoader && m_pLoader->m_bSaveLineHeight) { - float fHeight = *pLinePos - m_pLoader->m_fLastPos; - m_pLoader->m_fLastPos = *pLinePos; - m_pLoader->m_lineHeights.push_back(fHeight); + if (m_pLoader && m_pLoader->bSaveLineHeight) { + float fHeight = *pLinePos - m_pLoader->fLastPos; + m_pLoader->fLastPos = *pLinePos; + m_pLoader->lineHeights.push_back(fHeight); } } diff --git a/xfa/fxfa/cxfa_textlayout.h b/xfa/fxfa/cxfa_textlayout.h index 09740b3e6b..97e1d652d5 100644 --- a/xfa/fxfa/cxfa_textlayout.h +++ b/xfa/fxfa/cxfa_textlayout.h @@ -18,17 +18,17 @@ class CFDE_RenderDevice; class CFX_CSSComputedStyle; -class CFX_RenderDevice; class CFX_RTFBreak; +class CFX_RenderDevice; class CFX_XMLNode; class CXFA_LinkUserData; -class CXFA_LoaderContext; class CXFA_Node; class CXFA_PieceLine; class CXFA_TextPiece; class CXFA_TextProvider; class CXFA_TextTabstopsContext; class FXTEXT_CHARPOS; +struct CXFA_LoaderContext; struct FX_RTFTEXTOBJ; class CXFA_TextLayout { |