From e647799f6a2f7f747c9f55d9f0ce08dcdfbd53f4 Mon Sep 17 00:00:00 2001 From: tsepez Date: Thu, 5 Jan 2017 12:57:00 -0800 Subject: Properly ref-count CFGAS_GEFont with CFX_RetainPtr. We worry about cyclical references, but no leaks found. Review-Url: https://codereview.chromium.org/2609423003 --- xfa/fgas/layout/fgas_rtfbreak.cpp | 28 ++++++++++++++-------------- xfa/fgas/layout/fgas_rtfbreak.h | 7 ++++--- xfa/fgas/layout/fgas_textbreak.cpp | 25 +++++++++++-------------- xfa/fgas/layout/fgas_textbreak.h | 6 +++--- xfa/fgas/layout/fgas_unicode.h | 13 +++++++------ 5 files changed, 39 insertions(+), 40 deletions(-) (limited to 'xfa/fgas/layout') diff --git a/xfa/fgas/layout/fgas_rtfbreak.cpp b/xfa/fgas/layout/fgas_rtfbreak.cpp index 8e4fbf7969..cacb77fcf8 100644 --- a/xfa/fgas/layout/fgas_rtfbreak.cpp +++ b/xfa/fgas/layout/fgas_rtfbreak.cpp @@ -93,13 +93,10 @@ void CFX_RTFBreak::SetLayoutStyles(uint32_t dwLayoutStyles) { m_iRotation %= 4; } -void CFX_RTFBreak::SetFont(CFGAS_GEFont* pFont) { - if (!pFont) { +void CFX_RTFBreak::SetFont(const CFX_RetainPtr& pFont) { + if (!pFont || pFont == m_pFont) return; - } - if (m_pFont == pFont) { - return; - } + SetBreakStatus(); m_pFont = pFont; m_iDefChar = 0; @@ -111,6 +108,7 @@ void CFX_RTFBreak::SetFont(CFGAS_GEFont* pFont) { } } } + void CFX_RTFBreak::SetFontSize(FX_FLOAT fFontSize) { int32_t iFontSize = FXSYS_round(fFontSize * 20.0f); if (m_iFontSize == iFontSize) { @@ -1184,7 +1182,7 @@ int32_t CFX_RTFBreak::GetDisplayPos(const FX_RTFTEXTOBJ* pText, const FX_WCHAR* pStr = pText->pStr; int32_t* pWidths = pText->pWidths; int32_t iLength = pText->iLength - 1; - CFGAS_GEFont* pFont = pText->pFont; + CFX_RetainPtr pFont = pText->pFont; uint32_t dwStyles = pText->dwLayoutStyles; CFX_RectF rtText(*pText->pRect); bool bRTLPiece = FX_IsOdd(pText->iBidiLevel); @@ -1419,9 +1417,9 @@ int32_t CFX_RTFBreak::GetDisplayPos(const FX_RTFTEXTOBJ* pText, int32_t CFX_RTFBreak::GetCharRects(const FX_RTFTEXTOBJ* pText, CFX_RectFArray& rtArray, bool bCharBBox) const { - if (!pText || pText->iLength < 1) { + if (!pText || pText->iLength < 1) return 0; - } + ASSERT(pText->pStr && pText->pWidths && pText->pFont && pText->pRect); const FX_WCHAR* pStr = pText->pStr; int32_t* pWidths = pText->pWidths; @@ -1431,15 +1429,15 @@ int32_t CFX_RTFBreak::GetCharRects(const FX_RTFTEXTOBJ* pText, FX_FLOAT fFontSize = pText->fFontSize; int32_t iFontSize = FXSYS_round(fFontSize * 20.0f); FX_FLOAT fScale = fFontSize / 1000.0f; - CFGAS_GEFont* pFont = pText->pFont; - if (!pFont) { + CFX_RetainPtr pFont = pText->pFont; + if (!pFont) bCharBBox = false; - } + CFX_Rect bbox; bbox.Set(0, 0, 0, 0); - if (bCharBBox) { + if (bCharBBox) bCharBBox = pFont->GetBBox(bbox); - } + FX_FLOAT fLeft = std::max(0.0f, bbox.left * fScale); FX_FLOAT fHeight = FXSYS_fabs(bbox.height * fScale); rtArray.RemoveAll(); @@ -1566,3 +1564,5 @@ FX_RTFTEXTOBJ::FX_RTFTEXTOBJ() wLineBreakChar(L'\n'), iHorizontalScale(100), iVerticalScale(100) {} + +FX_RTFTEXTOBJ::~FX_RTFTEXTOBJ() {} diff --git a/xfa/fgas/layout/fgas_rtfbreak.h b/xfa/fgas/layout/fgas_rtfbreak.h index de2497ed1d..c281192553 100644 --- a/xfa/fgas/layout/fgas_rtfbreak.h +++ b/xfa/fgas/layout/fgas_rtfbreak.h @@ -67,11 +67,12 @@ class CFGAS_GEFont; struct FX_RTFTEXTOBJ { FX_RTFTEXTOBJ(); + ~FX_RTFTEXTOBJ(); const FX_WCHAR* pStr; int32_t* pWidths; int32_t iLength; - CFGAS_GEFont* pFont; + CFX_RetainPtr pFont; FX_FLOAT fFontSize; uint32_t dwLayoutStyles; int32_t iCharRotation; @@ -222,7 +223,7 @@ class CFX_RTFBreak { void SetLineStartPos(FX_FLOAT fLinePos); uint32_t GetLayoutStyles() const { return m_dwLayoutStyles; } void SetLayoutStyles(uint32_t dwLayoutStyles); - void SetFont(CFGAS_GEFont* pFont); + void SetFont(const CFX_RetainPtr& pFont); void SetFontSize(FX_FLOAT fFontSize); void SetTabWidth(FX_FLOAT fTabWidth); void AddPositionedTab(FX_FLOAT fTabPos); @@ -294,7 +295,7 @@ class CFX_RTFBreak { bool m_bVertical; bool m_bSingleLine; bool m_bCharCode; - CFGAS_GEFont* m_pFont; + CFX_RetainPtr m_pFont; int32_t m_iFontHeight; int32_t m_iFontSize; int32_t m_iTabWidth; diff --git a/xfa/fgas/layout/fgas_textbreak.cpp b/xfa/fgas/layout/fgas_textbreak.cpp index a3f8e9841d..a9d35a3cd7 100644 --- a/xfa/fgas/layout/fgas_textbreak.cpp +++ b/xfa/fgas/layout/fgas_textbreak.cpp @@ -112,13 +112,10 @@ void CFX_TxtBreak::SetLayoutStyles(uint32_t dwLayoutStyles) { m_iRotation %= 4; } -void CFX_TxtBreak::SetFont(CFGAS_GEFont* pFont) { - if (!pFont) { +void CFX_TxtBreak::SetFont(const CFX_RetainPtr& pFont) { + if (!pFont || pFont == m_pFont) return; - } - if (m_pFont == pFont) { - return; - } + SetBreakStatus(); m_pFont = pFont; m_iDefChar = 0; @@ -1214,7 +1211,7 @@ int32_t CFX_TxtBreak::GetDisplayPos(const FX_TXTRUN* pTxtRun, const FX_WCHAR* pStr = pTxtRun->wsStr.c_str(); int32_t* pWidths = pTxtRun->pWidths; int32_t iLength = pTxtRun->iLength - 1; - CFGAS_GEFont* pFont = pTxtRun->pFont; + CFX_RetainPtr pFont = pTxtRun->pFont; uint32_t dwStyles = pTxtRun->dwStyles; CFX_RectF rtText(*pTxtRun->pRect); bool bRTLPiece = (pTxtRun->dwCharStyles & FX_TXTCHARSTYLE_OddBidiLevel) != 0; @@ -1593,9 +1590,9 @@ int32_t CFX_TxtBreak::GetDisplayPos(const FX_TXTRUN* pTxtRun, int32_t CFX_TxtBreak::GetCharRects(const FX_TXTRUN* pTxtRun, CFX_RectFArray& rtArray, bool bCharBBox) const { - if (!pTxtRun || pTxtRun->iLength < 1) { + if (!pTxtRun || pTxtRun->iLength < 1) return 0; - } + IFX_TxtAccess* pAccess = pTxtRun->pAccess; const FDE_TEXTEDITPIECE* pIdentity = pTxtRun->pIdentity; const FX_WCHAR* pStr = pTxtRun->wsStr.c_str(); @@ -1606,15 +1603,15 @@ int32_t CFX_TxtBreak::GetCharRects(const FX_TXTRUN* pTxtRun, FX_FLOAT fFontSize = pTxtRun->fFontSize; int32_t iFontSize = FXSYS_round(fFontSize * 20.0f); FX_FLOAT fScale = fFontSize / 1000.0f; - CFGAS_GEFont* pFont = pTxtRun->pFont; - if (!pFont) { + CFX_RetainPtr pFont = pTxtRun->pFont; + if (!pFont) bCharBBox = false; - } + CFX_Rect bbox; bbox.Set(0, 0, 0, 0); - if (bCharBBox) { + if (bCharBBox) bCharBBox = pFont->GetBBox(bbox); - } + FX_FLOAT fLeft = std::max(0.0f, bbox.left * fScale); FX_FLOAT fHeight = FXSYS_fabs(bbox.height * fScale); rtArray.RemoveAll(); diff --git a/xfa/fgas/layout/fgas_textbreak.h b/xfa/fgas/layout/fgas_textbreak.h index 7bae6cd46e..36602749c7 100644 --- a/xfa/fgas/layout/fgas_textbreak.h +++ b/xfa/fgas/layout/fgas_textbreak.h @@ -93,7 +93,7 @@ struct FX_TXTRUN { CFX_WideString wsStr; int32_t* pWidths; int32_t iLength; - CFGAS_GEFont* pFont; + CFX_RetainPtr pFont; FX_FLOAT fFontSize; uint32_t dwStyles; int32_t iHorizontalScale; @@ -206,7 +206,7 @@ class CFX_TxtBreak { void SetLinePos(FX_FLOAT fLinePos); uint32_t GetLayoutStyles() const { return m_dwLayoutStyles; } void SetLayoutStyles(uint32_t dwLayoutStyles); - void SetFont(CFGAS_GEFont* pFont); + void SetFont(const CFX_RetainPtr& pFont); void SetFontSize(FX_FLOAT fFontSize); void SetTabWidth(FX_FLOAT fTabWidth, bool bEquidistant); void SetDefaultChar(FX_WCHAR wch); @@ -280,7 +280,7 @@ class CFX_TxtBreak { bool m_bCombText; int32_t m_iArabicContext; int32_t m_iCurArabicContext; - CFGAS_GEFont* m_pFont; + CFX_RetainPtr m_pFont; int32_t m_iFontSize; bool m_bEquidistant; int32_t m_iTabWidth; diff --git a/xfa/fgas/layout/fgas_unicode.h b/xfa/fgas/layout/fgas_unicode.h index f7a0d201d9..b404d6728a 100644 --- a/xfa/fgas/layout/fgas_unicode.h +++ b/xfa/fgas/layout/fgas_unicode.h @@ -18,11 +18,12 @@ typedef CFX_MassArrayTemplate CFX_TPOArray; void FX_TEXTLAYOUT_PieceSort(CFX_TPOArray& tpos, int32_t iStart, int32_t iEnd); -typedef bool (*FX_AdjustCharDisplayPos)(FX_WCHAR wch, - bool bMBCSCode, - CFGAS_GEFont* pFont, - FX_FLOAT fFontSize, - bool bVertical, - CFX_PointF& ptOffset); +typedef bool (*FX_AdjustCharDisplayPos)( + FX_WCHAR wch, + bool bMBCSCode, + const CFX_RetainPtr& pFont, + FX_FLOAT fFontSize, + bool bVertical, + CFX_PointF& ptOffset); #endif // XFA_FGAS_LAYOUT_FGAS_UNICODE_H_ -- cgit v1.2.3