summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-03-01 11:23:14 -0500
committerChromium commit bot <commit-bot@chromium.org>2017-03-01 20:44:33 +0000
commitbef73893d919514110cf3b724fad88965d9399e7 (patch)
tree9075f0562dd31886bc8409b3e7de25887d690a00
parentb4a261855b34b4c8d938118762ae609a34a3ae99 (diff)
downloadpdfium-bef73893d919514110cf3b724fad88965d9399e7.tar.xz
Return values instead of out params
This Cl converts CFX_RTFPiece::GetString and CFX_RTFPiece::GetWidths to return CFX_WideString and std::vector<int32_t> respectively instead of taking pointers out parameters. Change-Id: Ie153caa0336861b3efa9b8ce26f75f0e019526e9 Reviewed-on: https://pdfium-review.googlesource.com/2882 Reviewed-by: Nicolás Peña <npm@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
-rw-r--r--xfa/fgas/layout/fgas_rtfbreak.cpp29
-rw-r--r--xfa/fgas/layout/fgas_rtfbreak.h32
-rw-r--r--xfa/fxfa/app/cxfa_textlayout.cpp14
-rw-r--r--xfa/fxfa/app/xfa_textpiece.cpp8
-rw-r--r--xfa/fxfa/app/xfa_textpiece.h6
5 files changed, 41 insertions, 48 deletions
diff --git a/xfa/fgas/layout/fgas_rtfbreak.cpp b/xfa/fgas/layout/fgas_rtfbreak.cpp
index dd3f34c739..fdc9a57038 100644
--- a/xfa/fgas/layout/fgas_rtfbreak.cpp
+++ b/xfa/fgas/layout/fgas_rtfbreak.cpp
@@ -882,11 +882,8 @@ int32_t CFX_RTFBreak::GetDisplayPos(const FX_RTFTEXTOBJ* pText,
if (!pText || pText->iLength < 1)
return 0;
- ASSERT(pText->pStr && pText->pWidths && pText->pFont && pText->pRect);
+ ASSERT(pText->pFont && pText->pRect);
- const FX_WCHAR* pStr = pText->pStr;
- int32_t* pWidths = pText->pWidths;
- int32_t iLength = pText->iLength - 1;
CFX_RetainPtr<CFGAS_GEFont> pFont = pText->pFont;
CFX_RectF rtText(*pText->pRect);
bool bRTLPiece = FX_IsOdd(pText->iBidiLevel);
@@ -920,9 +917,9 @@ int32_t CFX_RTFBreak::GetDisplayPos(const FX_RTFTEXTOBJ* pText,
fY += fAscent;
int32_t iCount = 0;
- for (int32_t i = 0; i <= iLength; i++) {
- wch = *pStr++;
- iWidth = *pWidths++;
+ for (int32_t i = 0; i < pText->iLength; i++) {
+ wch = pText->pStr[i];
+ iWidth = pText->pWidths[i];
dwProps = FX_GetUnicodeProperties(wch);
dwCharType = (dwProps & FX_CHARTYPEBITSMASK);
if (dwCharType == FX_CHARTYPE_ArabicAlef && iWidth == 0) {
@@ -942,10 +939,10 @@ int32_t CFX_RTFBreak::GetDisplayPos(const FX_RTFTEXTOBJ* pText,
iCharWidth /= iFontSize;
wForm = wch;
if (dwCharType >= FX_CHARTYPE_ArabicAlef) {
- if (i < iLength) {
- wNext = *pStr;
- if (*pWidths < 0 && i + 1 < iLength)
- wNext = pStr[1];
+ if (i + 1 < pText->iLength) {
+ wNext = pText->pStr[i + 1];
+ if (pText->pWidths[i + 1] < 0 && i + 2 < pText->iLength)
+ wNext = pText->pStr[i + 2];
} else {
wNext = 0xFEFF;
}
@@ -1040,14 +1037,12 @@ CFX_RTFLine::~CFX_RTFLine() {
}
FX_RTFTEXTOBJ::FX_RTFTEXTOBJ()
- : pStr(nullptr),
- pWidths(nullptr),
- iLength(0),
- pFont(nullptr),
- fFontSize(12.0f),
- iBidiLevel(0),
+ : pFont(nullptr),
pRect(nullptr),
wLineBreakChar(L'\n'),
+ fFontSize(12.0f),
+ iLength(0),
+ iBidiLevel(0),
iHorizontalScale(100),
iVerticalScale(100) {}
diff --git a/xfa/fgas/layout/fgas_rtfbreak.h b/xfa/fgas/layout/fgas_rtfbreak.h
index 81ec60ee48..55b99ae298 100644
--- a/xfa/fgas/layout/fgas_rtfbreak.h
+++ b/xfa/fgas/layout/fgas_rtfbreak.h
@@ -33,14 +33,14 @@ struct FX_RTFTEXTOBJ {
FX_RTFTEXTOBJ();
~FX_RTFTEXTOBJ();
- const FX_WCHAR* pStr;
- int32_t* pWidths;
- int32_t iLength;
+ CFX_WideString pStr;
+ std::vector<int32_t> pWidths;
CFX_RetainPtr<CFGAS_GEFont> pFont;
- FX_FLOAT fFontSize;
- int32_t iBidiLevel;
const CFX_RectF* pRect;
FX_WCHAR wLineBreakChar;
+ FX_FLOAT fFontSize;
+ int32_t iLength;
+ int32_t iBidiLevel;
int32_t iHorizontalScale;
int32_t iVerticalScale;
};
@@ -59,18 +59,20 @@ class CFX_RTFPiece {
return (*m_pChars)[m_iStartChar + index];
}
- void GetString(FX_WCHAR* pText) const {
- ASSERT(pText);
- int32_t iEndChar = m_iStartChar + m_iChars;
- for (int32_t i = m_iStartChar; i < iEndChar; i++)
- *pText++ = static_cast<FX_WCHAR>((*m_pChars)[i].m_wCharCode);
+ CFX_WideString GetString() const {
+ CFX_WideString ret;
+ ret.Reserve(m_iChars);
+ for (int32_t i = m_iStartChar; i < m_iStartChar + m_iChars; i++)
+ ret += static_cast<FX_WCHAR>((*m_pChars)[i].m_wCharCode);
+ return ret;
}
- void GetWidths(int32_t* pWidths) const {
- ASSERT(pWidths);
- int32_t iEndChar = m_iStartChar + m_iChars;
- for (int32_t i = m_iStartChar; i < iEndChar; i++)
- *pWidths++ = (*m_pChars)[i].m_iCharWidth;
+ std::vector<int32_t> GetWidths() const {
+ std::vector<int32_t> ret;
+ ret.reserve(m_iChars);
+ for (int32_t i = m_iStartChar; i < m_iStartChar + m_iChars; i++)
+ ret.push_back((*m_pChars)[i].m_iCharWidth);
+ return ret;
}
void Reset() {
diff --git a/xfa/fxfa/app/cxfa_textlayout.cpp b/xfa/fxfa/app/cxfa_textlayout.cpp
index 9735dc7b13..715dbb32dd 100644
--- a/xfa/fxfa/app/cxfa_textlayout.cpp
+++ b/xfa/fxfa/app/cxfa_textlayout.cpp
@@ -999,10 +999,10 @@ void CXFA_TextLayout::DoTabstops(CFDE_CSSComputedStyle* pStyle,
} else if (dwAlign == FX_HashCode_GetW(L"decimal", false)) {
int32_t iChars = pPiece->iChars;
for (int32_t i = 0; i < iChars; i++) {
- if (pPiece->pszText[i] == L'.')
+ if (pPiece->szText[i] == L'.')
break;
- fLeft += pPiece->pWidths[i] / 20000.0f;
+ fLeft += pPiece->Widths[i] / 20000.0f;
}
}
m_pTabstopContext->m_fLeft =
@@ -1041,11 +1041,9 @@ void CXFA_TextLayout::AppendTextLine(CFX_RTFBreakType dwStatus,
FX_FLOAT fVerScale = pPiece->m_iVerticalScale / 100.0f;
auto pTP = pdfium::MakeUnique<XFA_TextPiece>();
- pTP->pszText = FX_Alloc(FX_WCHAR, pPiece->m_iChars);
- pTP->pWidths = FX_Alloc(int32_t, pPiece->m_iChars);
pTP->iChars = pPiece->m_iChars;
- pPiece->GetString(pTP->pszText);
- pPiece->GetWidths(pTP->pWidths);
+ pTP->szText = pPiece->GetString();
+ pTP->Widths = pPiece->GetWidths();
pTP->iBidiLevel = pPiece->m_iBidiLevel;
pTP->iHorScale = pPiece->m_iHorizontalScale;
pTP->iVerScale = pPiece->m_iVerticalScale;
@@ -1301,10 +1299,10 @@ bool CXFA_TextLayout::ToRun(const XFA_TextPiece* pPiece, FX_RTFTEXTOBJ* tr) {
if (iLength < 1)
return false;
- tr->pStr = pPiece->pszText;
+ tr->pStr = pPiece->szText;
tr->pFont = pPiece->pFont;
tr->pRect = &pPiece->rtPiece;
- tr->pWidths = pPiece->pWidths;
+ tr->pWidths = pPiece->Widths;
tr->iLength = iLength;
tr->fFontSize = pPiece->fFontSize;
tr->iBidiLevel = pPiece->iBidiLevel;
diff --git a/xfa/fxfa/app/xfa_textpiece.cpp b/xfa/fxfa/app/xfa_textpiece.cpp
index e65cc16667..c53e45f91a 100644
--- a/xfa/fxfa/app/xfa_textpiece.cpp
+++ b/xfa/fxfa/app/xfa_textpiece.cpp
@@ -8,10 +8,6 @@
#include "xfa/fxfa/app/cxfa_linkuserdata.h"
-XFA_TextPiece::XFA_TextPiece()
- : pszText(nullptr), pWidths(nullptr), pFont(nullptr) {}
+XFA_TextPiece::XFA_TextPiece() {}
-XFA_TextPiece::~XFA_TextPiece() {
- FX_Free(pszText);
- FX_Free(pWidths);
-}
+XFA_TextPiece::~XFA_TextPiece() {}
diff --git a/xfa/fxfa/app/xfa_textpiece.h b/xfa/fxfa/app/xfa_textpiece.h
index 6c7b3d4217..6802df5566 100644
--- a/xfa/fxfa/app/xfa_textpiece.h
+++ b/xfa/fxfa/app/xfa_textpiece.h
@@ -7,6 +7,8 @@
#ifndef XFA_FXFA_APP_XFA_TEXTPIECE_H_
#define XFA_FXFA_APP_XFA_TEXTPIECE_H_
+#include <vector>
+
#include "core/fxcrt/fx_basic.h"
#include "core/fxcrt/fx_coordinates.h"
#include "core/fxcrt/fx_string.h"
@@ -20,9 +22,9 @@ class XFA_TextPiece {
XFA_TextPiece();
~XFA_TextPiece();
- FX_WCHAR* pszText;
+ CFX_WideString szText;
+ std::vector<int32_t> Widths;
int32_t iChars;
- int32_t* pWidths;
int32_t iHorScale;
int32_t iVerScale;
int32_t iBidiLevel;