From 4f6fdbe6adf0d90886b9deb5666996603cf1207c Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Wed, 9 Mar 2016 13:24:25 -0800 Subject: Structs shouldn't inherit from CFX_Target. There are some assumptions in the code that CAPS_NAMED structs are POD, and can be memcpy'd, malloc'd, etc. CFX_Target adds a virtual dtor, which is not what is desired for many of these, so resolve by making each a CAPS_Named class or by removing the inheritence. In the process XFA_TextPiece was found to be malloc'd despite having a ctor. Move this to |new|, noting that the object is never freed (and goes out of existence when the allocator's pool is destroyed). BUG=pdfium:432 R=dsinclair@chromium.org Review URL: https://codereview.chromium.org/1780753002 . --- xfa/src/fxfa/app/xfa_fftext.cpp | 2 +- xfa/src/fxfa/app/xfa_textlayout.cpp | 21 ++++++++++----------- xfa/src/fxfa/app/xfa_textlayout.h | 13 +++++++------ 3 files changed, 18 insertions(+), 18 deletions(-) (limited to 'xfa/src/fxfa') diff --git a/xfa/src/fxfa/app/xfa_fftext.cpp b/xfa/src/fxfa/app/xfa_fftext.cpp index 2e9abb9f81..95d408ce71 100644 --- a/xfa/src/fxfa/app/xfa_fftext.cpp +++ b/xfa/src/fxfa/app/xfa_fftext.cpp @@ -163,7 +163,7 @@ const FX_WCHAR* CXFA_FFText::GetLinkURLAtPoint(FX_FLOAT fx, FX_FLOAT fy) { CXFA_PieceLine* pPieceLine = pPieceLines->GetAt(i); int32_t iPieces = pPieceLine->m_textPieces.GetSize(); for (int32_t j = 0; j < iPieces; j++) { - XFA_TEXTPIECE* pPiece = pPieceLine->m_textPieces.GetAt(j); + XFA_TextPiece* pPiece = pPieceLine->m_textPieces.GetAt(j); if (pPiece->pLinkData && pPiece->rtPiece.Contains(x, y)) { return pPiece->pLinkData->GetLinkURL(); } diff --git a/xfa/src/fxfa/app/xfa_textlayout.cpp b/xfa/src/fxfa/app/xfa_textlayout.cpp index e8a23b1523..b8a9ec433e 100644 --- a/xfa/src/fxfa/app/xfa_textlayout.cpp +++ b/xfa/src/fxfa/app/xfa_textlayout.cpp @@ -1256,7 +1256,7 @@ FX_BOOL CXFA_TextLayout::DrawString(CFX_RenderDevice* pFxDevice, int32_t iPieces = pPieceLine->m_textPieces.GetSize(); int32_t j = 0; for (j = 0; j < iPieces; j++) { - const XFA_TEXTPIECE* pPiece = pPieceLine->m_textPieces.GetAt(j); + const XFA_TextPiece* pPiece = pPieceLine->m_textPieces.GetAt(j); int32_t iChars = pPiece->iChars; if (iCharCount < iChars) { FX_Free(pCharPos); @@ -1296,7 +1296,7 @@ void CXFA_TextLayout::UpdateAlign(FX_FLOAT fHeight, FX_FLOAT fBottom) { CXFA_PieceLine* pPieceLine = m_pieceLines.GetAt(i); int32_t iPieces = pPieceLine->m_textPieces.GetSize(); for (int32_t j = 0; j < iPieces; j++) { - XFA_TEXTPIECE* pPiece = pPieceLine->m_textPieces.GetAt(j); + XFA_TextPiece* pPiece = pPieceLine->m_textPieces.GetAt(j); CFX_RectF& rect = pPiece->rtPiece; rect.top += fHeight; } @@ -1651,7 +1651,7 @@ void CXFA_TextLayout::DoTabstops(IFDE_CSSComputedStyle* pStyle, if (iPieces == 0) { return; } - XFA_TEXTPIECE* pPiece = pPieceLine->m_textPieces.GetAt(iPieces - 1); + XFA_TextPiece* pPiece = pPieceLine->m_textPieces.GetAt(iPieces - 1); int32_t& iTabstopsIndex = m_pTabstopContext->m_iTabIndex; int32_t iCount = m_textParser.CountTabs(pStyle); if (iTabstopsIndex > m_pTabstopContext->m_iTabCount - 1) { @@ -1662,7 +1662,7 @@ void CXFA_TextLayout::DoTabstops(IFDE_CSSComputedStyle* pStyle, m_pTabstopContext->m_bTabstops = TRUE; FX_FLOAT fRight = 0; if (iPieces > 1) { - XFA_TEXTPIECE* p = pPieceLine->m_textPieces.GetAt(iPieces - 2); + XFA_TextPiece* p = pPieceLine->m_textPieces.GetAt(iPieces - 2); fRight = p->rtPiece.right(); } m_pTabstopContext->m_fTabWidth = @@ -1718,8 +1718,7 @@ void CXFA_TextLayout::AppendTextLine(FX_DWORD dwStatus, if (pUserData) pStyle = pUserData->m_pStyle; FX_FLOAT fVerScale = pPiece->m_iVerticalScale / 100.0f; - XFA_TEXTPIECE* pTP = - (XFA_TEXTPIECE*)m_pAllocator->Alloc(sizeof(XFA_TEXTPIECE)); + XFA_TextPiece* pTP = FXTARGET_NewWith(m_pAllocator) XFA_TextPiece(); pTP->pszText = (FX_WCHAR*)m_pAllocator->Alloc(pPiece->m_iChars * sizeof(FX_WCHAR)); pTP->pWidths = @@ -1765,7 +1764,7 @@ void CXFA_TextLayout::AppendTextLine(FX_DWORD dwStatus, DoTabstops(pStyle, pPieceLine); } for (i = 0; i < iPieces; i++) { - XFA_TEXTPIECE* pTP = pPieceLine->m_textPieces.GetAt(i); + XFA_TextPiece* pTP = pPieceLine->m_textPieces.GetAt(i); FX_FLOAT& fTop = pTP->rtPiece.top; FX_FLOAT fBaseLineTemp = fTop; fTop = fLinePos + fLineStep - pTP->rtPiece.height - fBaseLineTemp; @@ -1847,7 +1846,7 @@ void CXFA_TextLayout::RenderString(IFDE_RenderDevice* pDevice, int32_t iPiece, FXTEXT_CHARPOS* pCharPos, const CFX_Matrix& tmDoc2Device) { - const XFA_TEXTPIECE* pPiece = pPieceLine->m_textPieces.GetAt(iPiece); + const XFA_TextPiece* pPiece = pPieceLine->m_textPieces.GetAt(iPiece); int32_t iCount = GetDisplayPos(pPiece, pCharPos); if (iCount > 0) { pBrush->SetColor(pPiece->dwColor); @@ -1862,7 +1861,7 @@ void CXFA_TextLayout::RenderPath(IFDE_RenderDevice* pDevice, int32_t iPiece, FXTEXT_CHARPOS* pCharPos, const CFX_Matrix& tmDoc2Device) { - XFA_TEXTPIECE* pPiece = pPieceLine->m_textPieces.GetAt(iPiece); + XFA_TextPiece* pPiece = pPieceLine->m_textPieces.GetAt(iPiece); FX_BOOL bNoUnderline = pPiece->iUnderline < 1 || pPiece->iUnderline > 2; FX_BOOL bNoLineThrough = pPiece->iLineThrough < 1 || pPiece->iLineThrough > 2; if (bNoUnderline && bNoLineThrough) { @@ -1969,7 +1968,7 @@ void CXFA_TextLayout::RenderPath(IFDE_RenderDevice* pDevice, XFA_RenderPathRet: pPath->Release(); } -int32_t CXFA_TextLayout::GetDisplayPos(const XFA_TEXTPIECE* pPiece, +int32_t CXFA_TextLayout::GetDisplayPos(const XFA_TextPiece* pPiece, FXTEXT_CHARPOS* pCharPos, FX_BOOL bCharCode) { if (pPiece == NULL) { @@ -1981,7 +1980,7 @@ int32_t CXFA_TextLayout::GetDisplayPos(const XFA_TEXTPIECE* pPiece, } return m_pBreak->GetDisplayPos(&tr, pCharPos, bCharCode); } -FX_BOOL CXFA_TextLayout::ToRun(const XFA_TEXTPIECE* pPiece, FX_RTFTEXTOBJ& tr) { +FX_BOOL CXFA_TextLayout::ToRun(const XFA_TextPiece* pPiece, FX_RTFTEXTOBJ& tr) { int32_t iLength = pPiece->iChars; if (iLength < 1) { return FALSE; diff --git a/xfa/src/fxfa/app/xfa_textlayout.h b/xfa/src/fxfa/app/xfa_textlayout.h index bcace9d9d6..2d8d1bf15e 100644 --- a/xfa/src/fxfa/app/xfa_textlayout.h +++ b/xfa/src/fxfa/app/xfa_textlayout.h @@ -243,9 +243,10 @@ class CXFA_TextUserData : public IFX_Unknown, public CFX_Target { FX_DWORD m_dwRefCount; }; -struct XFA_TEXTPIECE : public CFX_Target { - XFA_TEXTPIECE() : pszText(nullptr), pFont(nullptr), pLinkData(nullptr) {} - ~XFA_TEXTPIECE() { +class XFA_TextPiece : public CFX_Target { + public: + XFA_TextPiece() : pszText(nullptr), pFont(nullptr), pLinkData(nullptr) {} + ~XFA_TextPiece() { if (pLinkData) pLinkData->Release(); } @@ -265,7 +266,7 @@ struct XFA_TEXTPIECE : public CFX_Target { CFX_RectF rtPiece; CXFA_LinkUserData* pLinkData; }; -typedef CFX_ArrayTemplate CXFA_PieceArray; +typedef CFX_ArrayTemplate CXFA_PieceArray; class CXFA_PieceLine : public CFX_Target { public: @@ -399,10 +400,10 @@ class CXFA_TextLayout { int32_t iPiece, FXTEXT_CHARPOS* pCharPos, const CFX_Matrix& tmDoc2Device); - int32_t GetDisplayPos(const XFA_TEXTPIECE* pPiece, + int32_t GetDisplayPos(const XFA_TextPiece* pPiece, FXTEXT_CHARPOS* pCharPos, FX_BOOL bCharCode = FALSE); - FX_BOOL ToRun(const XFA_TEXTPIECE* pPiece, FX_RTFTEXTOBJ& tr); + FX_BOOL ToRun(const XFA_TextPiece* pPiece, FX_RTFTEXTOBJ& tr); void DoTabstops(IFDE_CSSComputedStyle* pStyle, CXFA_PieceLine* pPieceLine); FX_BOOL Layout(int32_t iBlock); int32_t CountBlocks() const; -- cgit v1.2.3