summaryrefslogtreecommitdiff
path: root/xfa/fxfa
diff options
context:
space:
mode:
Diffstat (limited to 'xfa/fxfa')
-rw-r--r--xfa/fxfa/app/cxfa_linkuserdata.cpp17
-rw-r--r--xfa/fxfa/app/cxfa_linkuserdata.h17
-rw-r--r--xfa/fxfa/app/cxfa_textlayout.cpp35
-rw-r--r--xfa/fxfa/app/cxfa_textlayout.h2
-rw-r--r--xfa/fxfa/app/cxfa_textuserdata.cpp22
-rw-r--r--xfa/fxfa/app/cxfa_textuserdata.h22
-rw-r--r--xfa/fxfa/app/xfa_textpiece.cpp5
-rw-r--r--xfa/fxfa/app/xfa_textpiece.h4
8 files changed, 39 insertions, 85 deletions
diff --git a/xfa/fxfa/app/cxfa_linkuserdata.cpp b/xfa/fxfa/app/cxfa_linkuserdata.cpp
index f1e15f406d..4128cd8822 100644
--- a/xfa/fxfa/app/cxfa_linkuserdata.cpp
+++ b/xfa/fxfa/app/cxfa_linkuserdata.cpp
@@ -7,21 +7,6 @@
#include "xfa/fxfa/app/cxfa_linkuserdata.h"
CXFA_LinkUserData::CXFA_LinkUserData(FX_WCHAR* pszText)
- : m_dwRefCount(1), m_wsURLContent(pszText) {}
+ : m_wsURLContent(pszText) {}
CXFA_LinkUserData::~CXFA_LinkUserData() {}
-
-uint32_t CXFA_LinkUserData::Retain() {
- return ++m_dwRefCount;
-}
-
-uint32_t CXFA_LinkUserData::Release() {
- uint32_t dwRefCount = --m_dwRefCount;
- if (dwRefCount <= 0)
- delete this;
- return dwRefCount;
-}
-
-const FX_WCHAR* CXFA_LinkUserData::GetLinkURL() {
- return m_wsURLContent.c_str();
-}
diff --git a/xfa/fxfa/app/cxfa_linkuserdata.h b/xfa/fxfa/app/cxfa_linkuserdata.h
index 621398ecb3..852b467648 100644
--- a/xfa/fxfa/app/cxfa_linkuserdata.h
+++ b/xfa/fxfa/app/cxfa_linkuserdata.h
@@ -7,23 +7,22 @@
#ifndef XFA_FXFA_APP_CXFA_LINKUSERDATA_H_
#define XFA_FXFA_APP_CXFA_LINKUSERDATA_H_
+#include "core/fxcrt/cfx_retain_ptr.h"
#include "core/fxcrt/fx_basic.h"
#include "core/fxcrt/fx_string.h"
#include "core/fxcrt/fx_system.h"
-class CXFA_LinkUserData : public IFX_Retainable {
+class CXFA_LinkUserData : public CFX_Retainable {
public:
- explicit CXFA_LinkUserData(FX_WCHAR* pszText);
- ~CXFA_LinkUserData() override;
-
- // IFX_Retainable:
- uint32_t Retain() override;
- uint32_t Release() override;
+ template <typename T, typename... Args>
+ friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args);
- const FX_WCHAR* GetLinkURL();
+ const FX_WCHAR* GetLinkURL() const { return m_wsURLContent.c_str(); }
protected:
- uint32_t m_dwRefCount;
+ explicit CXFA_LinkUserData(FX_WCHAR* pszText);
+ ~CXFA_LinkUserData() override;
+
CFX_WideString m_wsURLContent;
};
diff --git a/xfa/fxfa/app/cxfa_textlayout.cpp b/xfa/fxfa/app/cxfa_textlayout.cpp
index cc9c653a39..86f49eda89 100644
--- a/xfa/fxfa/app/cxfa_textlayout.cpp
+++ b/xfa/fxfa/app/cxfa_textlayout.cpp
@@ -476,7 +476,7 @@ bool CXFA_TextLayout::Layout(int32_t iBlock) {
for (; pXMLNode;
pXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::NextSibling)) {
if (!LoadRichText(pXMLNode, szText, fLinePos, m_pLoader->m_pParentStyle,
- true)) {
+ true, nullptr)) {
break;
}
}
@@ -495,7 +495,7 @@ bool CXFA_TextLayout::Layout(int32_t iBlock) {
for (; pXMLNode;
pXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::NextSibling)) {
if (!LoadRichText(pXMLNode, szText, fLinePos,
- m_pLoader->m_pParentStyle, true)) {
+ m_pLoader->m_pParentStyle, true, nullptr)) {
break;
}
}
@@ -655,7 +655,8 @@ bool CXFA_TextLayout::Loader(const CFX_SizeF& szText,
m_textParser.DoParse(pXMLContainer, m_pTextProvider);
auto pRootStyle = m_textParser.CreateRootStyle(m_pTextProvider);
- LoadRichText(pXMLContainer, szText, fLinePos, pRootStyle, bSavePieces);
+ LoadRichText(pXMLContainer, szText, fLinePos, pRootStyle, bSavePieces,
+ nullptr);
}
} else {
LoadText(m_pTextDataNode, szText, fLinePos, bSavePieces);
@@ -702,7 +703,7 @@ bool CXFA_TextLayout::LoadRichText(
FX_FLOAT& fLinePos,
const CFX_RetainPtr<CFDE_CSSComputedStyle>& pParentStyle,
bool bSavePieces,
- CXFA_LinkUserData* pLinkData,
+ CFX_RetainPtr<CXFA_LinkUserData> pLinkData,
bool bEndBreak,
bool bIsOl,
int32_t iLiCount) {
@@ -764,7 +765,7 @@ bool CXFA_TextLayout::LoadRichText(
ASSERT(pElement);
pElement->GetString(L"href", wsLinkContent);
if (!wsLinkContent.IsEmpty()) {
- pLinkData = new CXFA_LinkUserData(
+ pLinkData = pdfium::MakeRetain<CXFA_LinkUserData>(
wsLinkContent.GetBuffer(wsLinkContent.GetLength()));
wsLinkContent.ReleaseBuffer(wsLinkContent.GetLength());
}
@@ -818,10 +819,7 @@ bool CXFA_TextLayout::LoadRichText(
if (wsText.GetLength() > 0) {
if (!m_pLoader || m_pLoader->m_iChar == 0) {
- if (pLinkData)
- pLinkData->Retain();
-
- CXFA_TextUserData* pUserData = new CXFA_TextUserData(
+ auto pUserData = pdfium::MakeRetain<CXFA_TextUserData>(
bContentNode ? pParentStyle : pStyle, pLinkData);
m_pBreak->SetUserData(pUserData);
}
@@ -877,12 +875,6 @@ bool CXFA_TextLayout::LoadRichText(
if (m_pTabstopContext)
m_pTabstopContext->RemoveAll();
}
- if (wsName == FX_WSTRC(L"a")) {
- if (pLinkData) {
- pLinkData->Release();
- pLinkData = nullptr;
- }
- }
if (IsEnd(bSavePieces)) {
if (m_pLoader && m_pLoader->m_iTotalLines > -1) {
m_pLoader->m_pXMLNode =
@@ -1042,7 +1034,8 @@ void CXFA_TextLayout::AppendTextLine(uint32_t dwStatus,
int32_t i = 0;
for (i = 0; i < iPieces; i++) {
const CFX_RTFPiece* pPiece = m_pBreak->GetBreakPiece(i);
- CXFA_TextUserData* pUserData = (CXFA_TextUserData*)pPiece->m_pUserData;
+ CXFA_TextUserData* pUserData =
+ static_cast<CXFA_TextUserData*>(pPiece->m_pUserData.Get());
if (pUserData)
pStyle = pUserData->m_pStyle;
FX_FLOAT fVerScale = pPiece->m_iVerticalScale / 100.0f;
@@ -1082,12 +1075,7 @@ void CXFA_TextLayout::AppendTextLine(uint32_t dwStatus,
fBaseLine = -fBaseLineTemp;
}
fLineStep = std::max(fLineStep, fLineHeight);
- if (pUserData && pUserData->m_pLinkData) {
- pUserData->m_pLinkData->Retain();
- pTP->pLinkData = pUserData->m_pLinkData;
- } else {
- pTP->pLinkData = nullptr;
- }
+ pTP->pLinkData = pUserData ? pUserData->m_pLinkData : nullptr;
pPieceLine->m_textPieces.push_back(std::move(pTP));
DoTabstops(pStyle.Get(), pPieceLine);
}
@@ -1103,7 +1091,8 @@ void CXFA_TextLayout::AppendTextLine(uint32_t dwStatus,
FX_FLOAT fLineWidth = 0;
for (int32_t i = 0; i < iPieces; i++) {
const CFX_RTFPiece* pPiece = m_pBreak->GetBreakPiece(i);
- CXFA_TextUserData* pUserData = (CXFA_TextUserData*)pPiece->m_pUserData;
+ CXFA_TextUserData* pUserData =
+ static_cast<CXFA_TextUserData*>(pPiece->m_pUserData.Get());
if (pUserData)
pStyle = pUserData->m_pStyle;
FX_FLOAT fVerScale = pPiece->m_iVerticalScale / 100.0f;
diff --git a/xfa/fxfa/app/cxfa_textlayout.h b/xfa/fxfa/app/cxfa_textlayout.h
index a9d45f2ec3..1210056a01 100644
--- a/xfa/fxfa/app/cxfa_textlayout.h
+++ b/xfa/fxfa/app/cxfa_textlayout.h
@@ -84,7 +84,7 @@ class CXFA_TextLayout {
FX_FLOAT& fLinePos,
const CFX_RetainPtr<CFDE_CSSComputedStyle>& pParentStyle,
bool bSavePieces,
- CXFA_LinkUserData* pLinkData = nullptr,
+ CFX_RetainPtr<CXFA_LinkUserData> pLinkData,
bool bEndBreak = true,
bool bIsOl = false,
int32_t iLiCount = 0);
diff --git a/xfa/fxfa/app/cxfa_textuserdata.cpp b/xfa/fxfa/app/cxfa_textuserdata.cpp
index e436ab2ae9..e4e549316a 100644
--- a/xfa/fxfa/app/cxfa_textuserdata.cpp
+++ b/xfa/fxfa/app/cxfa_textuserdata.cpp
@@ -13,25 +13,11 @@
CXFA_TextUserData::CXFA_TextUserData(
const CFX_RetainPtr<CFDE_CSSComputedStyle>& pStyle)
- : m_pStyle(pStyle), m_pLinkData(nullptr), m_dwRefCount(0) {}
+ : m_pStyle(pStyle) {}
CXFA_TextUserData::CXFA_TextUserData(
const CFX_RetainPtr<CFDE_CSSComputedStyle>& pStyle,
- CXFA_LinkUserData* pLinkData)
- : m_pStyle(pStyle), m_pLinkData(pLinkData), m_dwRefCount(0) {}
+ const CFX_RetainPtr<CXFA_LinkUserData>& pLinkData)
+ : m_pStyle(pStyle), m_pLinkData(pLinkData) {}
-CXFA_TextUserData::~CXFA_TextUserData() {
- if (m_pLinkData)
- m_pLinkData->Release();
-}
-
-uint32_t CXFA_TextUserData::Retain() {
- return ++m_dwRefCount;
-}
-
-uint32_t CXFA_TextUserData::Release() {
- uint32_t dwRefCount = --m_dwRefCount;
- if (dwRefCount == 0)
- delete this;
- return dwRefCount;
-}
+CXFA_TextUserData::~CXFA_TextUserData() {}
diff --git a/xfa/fxfa/app/cxfa_textuserdata.h b/xfa/fxfa/app/cxfa_textuserdata.h
index 1eb3b8acb3..b0eff73f2e 100644
--- a/xfa/fxfa/app/cxfa_textuserdata.h
+++ b/xfa/fxfa/app/cxfa_textuserdata.h
@@ -7,28 +7,26 @@
#ifndef XFA_FXFA_APP_CXFA_TEXTUSERDATA_H_
#define XFA_FXFA_APP_CXFA_TEXTUSERDATA_H_
+#include "core/fxcrt/cfx_retain_ptr.h"
#include "core/fxcrt/fx_basic.h"
class CFDE_CSSComputedStyle;
class CXFA_LinkUserData;
-class CXFA_TextUserData : public IFX_Retainable {
+class CXFA_TextUserData : public CFX_Retainable {
public:
- explicit CXFA_TextUserData(
- const CFX_RetainPtr<CFDE_CSSComputedStyle>& pStyle);
- CXFA_TextUserData(const CFX_RetainPtr<CFDE_CSSComputedStyle>& pStyle,
- CXFA_LinkUserData* pLinkData);
- ~CXFA_TextUserData() override;
-
- // IFX_Retainable:
- uint32_t Retain() override;
- uint32_t Release() override;
+ template <typename T, typename... Args>
+ friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args);
CFX_RetainPtr<CFDE_CSSComputedStyle> m_pStyle;
- CXFA_LinkUserData* m_pLinkData;
+ CFX_RetainPtr<CXFA_LinkUserData> m_pLinkData;
protected:
- uint32_t m_dwRefCount;
+ explicit CXFA_TextUserData(
+ const CFX_RetainPtr<CFDE_CSSComputedStyle>& pStyle);
+ CXFA_TextUserData(const CFX_RetainPtr<CFDE_CSSComputedStyle>& pStyle,
+ const CFX_RetainPtr<CXFA_LinkUserData>& pLinkData);
+ ~CXFA_TextUserData() override;
};
#endif // XFA_FXFA_APP_CXFA_TEXTUSERDATA_H_
diff --git a/xfa/fxfa/app/xfa_textpiece.cpp b/xfa/fxfa/app/xfa_textpiece.cpp
index 933af6c92f..e65cc16667 100644
--- a/xfa/fxfa/app/xfa_textpiece.cpp
+++ b/xfa/fxfa/app/xfa_textpiece.cpp
@@ -9,12 +9,9 @@
#include "xfa/fxfa/app/cxfa_linkuserdata.h"
XFA_TextPiece::XFA_TextPiece()
- : pszText(nullptr), pWidths(nullptr), pFont(nullptr), pLinkData(nullptr) {}
+ : pszText(nullptr), pWidths(nullptr), pFont(nullptr) {}
XFA_TextPiece::~XFA_TextPiece() {
- if (pLinkData)
- pLinkData->Release();
-
FX_Free(pszText);
FX_Free(pWidths);
}
diff --git a/xfa/fxfa/app/xfa_textpiece.h b/xfa/fxfa/app/xfa_textpiece.h
index 2b74155afd..6c7b3d4217 100644
--- a/xfa/fxfa/app/xfa_textpiece.h
+++ b/xfa/fxfa/app/xfa_textpiece.h
@@ -29,11 +29,11 @@ class XFA_TextPiece {
int32_t iUnderline;
int32_t iPeriod;
int32_t iLineThrough;
- CFX_RetainPtr<CFGAS_GEFont> pFont;
FX_ARGB dwColor;
FX_FLOAT fFontSize;
CFX_RectF rtPiece;
- CXFA_LinkUserData* pLinkData;
+ CFX_RetainPtr<CFGAS_GEFont> pFont;
+ CFX_RetainPtr<CXFA_LinkUserData> pLinkData;
};
#endif // XFA_FXFA_APP_XFA_TEXTPIECE_H_