From 988599c5d81bbb568f949454580ec6001258f806 Mon Sep 17 00:00:00 2001 From: tsepez Date: Tue, 13 Dec 2016 12:45:56 -0800 Subject: Replace CFX_FloatArray with std::vector Review-Url: https://codereview.chromium.org/2567503002 --- core/fxcrt/fx_basic.h | 1 - xfa/fgas/layout/fgas_rtfbreak.cpp | 5 +- xfa/fgas/layout/fgas_rtfbreak.h | 4 +- xfa/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp | 28 +++++------ xfa/fxbarcode/datamatrix/BC_HighLevelEncoder.h | 4 +- xfa/fxfa/app/xfa_ffwidgetacc.cpp | 59 +++++++++++------------- xfa/fxfa/app/xfa_textlayout.cpp | 33 ++++++------- xfa/fxfa/app/xfa_textlayout.h | 3 +- 8 files changed, 70 insertions(+), 67 deletions(-) diff --git a/core/fxcrt/fx_basic.h b/core/fxcrt/fx_basic.h index d320e7d786..1bc4bbd588 100644 --- a/core/fxcrt/fx_basic.h +++ b/core/fxcrt/fx_basic.h @@ -317,7 +317,6 @@ class CFX_ArrayTemplate : public CFX_BasicArray { }; #ifdef PDF_ENABLE_XFA -typedef CFX_ArrayTemplate CFX_FloatArray; typedef CFX_ArrayTemplate CFX_ByteArray; typedef CFX_ArrayTemplate CFX_Int32Array; #endif // PDF_ENABLE_XFA diff --git a/xfa/fgas/layout/fgas_rtfbreak.cpp b/xfa/fgas/layout/fgas_rtfbreak.cpp index ef65bf9779..8e4fbf7969 100644 --- a/xfa/fgas/layout/fgas_rtfbreak.cpp +++ b/xfa/fgas/layout/fgas_rtfbreak.cpp @@ -10,6 +10,7 @@ #include "core/fxcrt/fx_arabic.h" #include "core/fxcrt/fx_arb.h" +#include "third_party/base/stl_util.h" #include "xfa/fgas/font/cfgas_gefont.h" #include "xfa/fgas/layout/fgas_linebreak.h" #include "xfa/fgas/layout/fgas_unicode.h" @@ -152,9 +153,9 @@ void CFX_RTFBreak::AddPositionedTab(FX_FLOAT fTabPos) { m_bOrphanLine = false; } } -void CFX_RTFBreak::SetPositionedTabs(const CFX_FloatArray& tabs) { +void CFX_RTFBreak::SetPositionedTabs(const std::vector& tabs) { m_PositionedTabs.RemoveAll(); - int32_t iCount = tabs.GetSize(); + int32_t iCount = pdfium::CollectionSize(tabs); m_PositionedTabs.SetSize(iCount); int32_t iLineEnd = m_iBoundaryEnd; int32_t iTabPos; diff --git a/xfa/fgas/layout/fgas_rtfbreak.h b/xfa/fgas/layout/fgas_rtfbreak.h index d75bbc1d31..de2497ed1d 100644 --- a/xfa/fgas/layout/fgas_rtfbreak.h +++ b/xfa/fgas/layout/fgas_rtfbreak.h @@ -7,6 +7,8 @@ #ifndef XFA_FGAS_LAYOUT_FGAS_RTFBREAK_H_ #define XFA_FGAS_LAYOUT_FGAS_RTFBREAK_H_ +#include + #include "core/fxcrt/fx_basic.h" #include "core/fxcrt/fx_ucd.h" #include "xfa/fgas/crt/fgas_memory.h" @@ -224,7 +226,7 @@ class CFX_RTFBreak { void SetFontSize(FX_FLOAT fFontSize); void SetTabWidth(FX_FLOAT fTabWidth); void AddPositionedTab(FX_FLOAT fTabPos); - void SetPositionedTabs(const CFX_FloatArray& tabs); + void SetPositionedTabs(const std::vector& tabs); void ClearPositionedTabs(); void SetDefaultChar(FX_WCHAR wch); void SetLineBreakChar(FX_WCHAR wch); diff --git a/xfa/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp b/xfa/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp index 7d81c93418..fcd668af6d 100644 --- a/xfa/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp +++ b/xfa/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp @@ -138,21 +138,21 @@ int32_t CBC_HighLevelEncoder::lookAheadTest(CFX_WideString msg, if (startpos >= msg.GetLength()) { return currentMode; } - CFX_FloatArray charCounts; + std::vector charCounts; if (currentMode == ASCII_ENCODATION) { - charCounts.Add(0); - charCounts.Add(1); - charCounts.Add(1); - charCounts.Add(1); - charCounts.Add(1); - charCounts.Add(1.25f); + charCounts.push_back(0); + charCounts.push_back(1); + charCounts.push_back(1); + charCounts.push_back(1); + charCounts.push_back(1); + charCounts.push_back(1.25f); } else { - charCounts.Add(1); - charCounts.Add(2); - charCounts.Add(2); - charCounts.Add(2); - charCounts.Add(2); - charCounts.Add(2.25f); + charCounts.push_back(1); + charCounts.push_back(2); + charCounts.push_back(2); + charCounts.push_back(2); + charCounts.push_back(2); + charCounts.push_back(2.25f); charCounts[currentMode] = 0; } int32_t charsProcessed = 0; @@ -317,7 +317,7 @@ FX_WCHAR CBC_HighLevelEncoder::randomize253State(FX_WCHAR ch, return tempVariable <= 254 ? (FX_WCHAR)tempVariable : (FX_WCHAR)(tempVariable - 254); } -int32_t CBC_HighLevelEncoder::findMinimums(CFX_FloatArray& charCounts, +int32_t CBC_HighLevelEncoder::findMinimums(std::vector& charCounts, CFX_Int32Array& intCharCounts, int32_t min, CFX_ByteArray& mins) { diff --git a/xfa/fxbarcode/datamatrix/BC_HighLevelEncoder.h b/xfa/fxbarcode/datamatrix/BC_HighLevelEncoder.h index cf04c06619..3b88f888fd 100644 --- a/xfa/fxbarcode/datamatrix/BC_HighLevelEncoder.h +++ b/xfa/fxbarcode/datamatrix/BC_HighLevelEncoder.h @@ -7,6 +7,8 @@ #ifndef XFA_FXBARCODE_DATAMATRIX_BC_HIGHLEVELENCODER_H_ #define XFA_FXBARCODE_DATAMATRIX_BC_HIGHLEVELENCODER_H_ +#include + #include "xfa/fxbarcode/datamatrix/BC_SymbolShapeHint.h" #define ASCII_ENCODATION 0 @@ -61,7 +63,7 @@ class CBC_HighLevelEncoder : public CBC_SymbolShapeHint { private: static FX_WCHAR randomize253State(FX_WCHAR ch, int32_t codewordPosition); - static int32_t findMinimums(CFX_FloatArray& charCounts, + static int32_t findMinimums(std::vector& charCounts, CFX_Int32Array& intCharCounts, int32_t min, CFX_ByteArray& mins); diff --git a/xfa/fxfa/app/xfa_ffwidgetacc.cpp b/xfa/fxfa/app/xfa_ffwidgetacc.cpp index d63a4f5151..e95c04b331 100644 --- a/xfa/fxfa/app/xfa_ffwidgetacc.cpp +++ b/xfa/fxfa/app/xfa_ffwidgetacc.cpp @@ -8,8 +8,10 @@ #include #include +#include #include "fxjs/cfxjse_value.h" +#include "third_party/base/stl_util.h" #include "xfa/fde/tto/fde_textout.h" #include "xfa/fde/xml/fde_xml_imp.h" #include "xfa/fxfa/app/xfa_ffcheckbutton.h" @@ -125,7 +127,7 @@ class CXFA_FieldLayoutData : public CXFA_WidgetLayoutData { std::unique_ptr m_pCapTextLayout; std::unique_ptr m_pCapTextProvider; std::unique_ptr m_pTextOut; - std::unique_ptr m_pFieldSplitArray; + std::vector m_FieldSplitArray; }; class CXFA_TextEditData : public CXFA_FieldLayoutData { @@ -1239,14 +1241,11 @@ bool CXFA_WidgetAcc::FindSplitPos(int32_t iBlockIndex, FX_FLOAT& fCalcHeight) { } iLinesCount = pFieldData->m_pTextOut->GetTotalLines(); } - if (!pFieldData->m_pFieldSplitArray) { - pFieldData->m_pFieldSplitArray.reset(new CFX_FloatArray); - } - CFX_FloatArray* pFieldArray = pFieldData->m_pFieldSplitArray.get(); - int32_t iFieldSplitCount = pFieldArray->GetSize(); + std::vector* pFieldArray = &pFieldData->m_FieldSplitArray; + int32_t iFieldSplitCount = pdfium::CollectionSize(*pFieldArray); for (int32_t i = 0; i < iBlockIndex * 3; i += 3) { - iLinesCount -= (int32_t)pFieldArray->GetAt(i + 1); - fHeight -= pFieldArray->GetAt(i + 2); + iLinesCount -= (int32_t)(*pFieldArray)[i + 1]; + fHeight -= (*pFieldArray)[i + 2]; } if (iLinesCount == 0) { return false; @@ -1275,20 +1274,18 @@ bool CXFA_WidgetAcc::FindSplitPos(int32_t iBlockIndex, FX_FLOAT& fCalcHeight) { break; } } - if (fStartOffset < 0.1f) { + if (fStartOffset < 0.1f) fStartOffset = 0; - } } for (int32_t i = iBlockIndex - 1; iBlockIndex > 0 && i < iBlockIndex; i++) { - fStartOffset = pFieldArray->GetAt(i * 3) - pFieldArray->GetAt(i * 3 + 2); - if (fStartOffset < 0.1f) { + fStartOffset = (*pFieldArray)[i * 3] - (*pFieldArray)[i * 3 + 2]; + if (fStartOffset < 0.1f) fStartOffset = 0; - } } if (iFieldSplitCount / 3 == (iBlockIndex + 1)) { - pFieldArray->SetAt(0, fStartOffset); + (*pFieldArray)[0] = fStartOffset; } else { - pFieldArray->Add(fStartOffset); + pFieldArray->push_back(fStartOffset); } XFA_VERSION version = GetDoc()->GetXFADoc()->GetCurVersionMode(); bool bCanSplitNoContent = false; @@ -1321,22 +1318,22 @@ bool CXFA_WidgetAcc::FindSplitPos(int32_t iBlockIndex, FX_FLOAT& fCalcHeight) { } if (fStartOffset + XFA_FLOAT_PERCISION >= fCalcHeight) { if (iFieldSplitCount / 3 == (iBlockIndex + 1)) { - pFieldArray->SetAt(iBlockIndex * 3 + 1, 0); - pFieldArray->SetAt(iBlockIndex * 3 + 2, fCalcHeight); + (*pFieldArray)[iBlockIndex * 3 + 1] = 0; + (*pFieldArray)[iBlockIndex * 3 + 2] = fCalcHeight; } else { - pFieldArray->Add(0); - pFieldArray->Add(fCalcHeight); + pFieldArray->push_back(0); + pFieldArray->push_back(fCalcHeight); } return false; } if (fCalcHeight - fStartOffset < fLineHeight) { fCalcHeight = fStartOffset; if (iFieldSplitCount / 3 == (iBlockIndex + 1)) { - pFieldArray->SetAt(iBlockIndex * 3 + 1, 0); - pFieldArray->SetAt(iBlockIndex * 3 + 2, fCalcHeight); + (*pFieldArray)[iBlockIndex * 3 + 1] = 0; + (*pFieldArray)[iBlockIndex * 3 + 2] = fCalcHeight; } else { - pFieldArray->Add(0); - pFieldArray->Add(fCalcHeight); + pFieldArray->push_back(0); + pFieldArray->push_back(fCalcHeight); } return true; } @@ -1347,11 +1344,11 @@ bool CXFA_WidgetAcc::FindSplitPos(int32_t iBlockIndex, FX_FLOAT& fCalcHeight) { if (iLineNum >= iLinesCount) { if (fCalcHeight - fStartOffset - fTextHeight >= fFontSize) { if (iFieldSplitCount / 3 == (iBlockIndex + 1)) { - pFieldArray->SetAt(iBlockIndex * 3 + 1, (FX_FLOAT)iLinesCount); - pFieldArray->SetAt(iBlockIndex * 3 + 2, fCalcHeight); + (*pFieldArray)[iBlockIndex * 3 + 1] = (FX_FLOAT)iLinesCount; + (*pFieldArray)[iBlockIndex * 3 + 2] = fCalcHeight; } else { - pFieldArray->Add((FX_FLOAT)iLinesCount); - pFieldArray->Add(fCalcHeight); + pFieldArray->push_back((FX_FLOAT)iLinesCount); + pFieldArray->push_back(fCalcHeight); } return false; } @@ -1369,11 +1366,11 @@ bool CXFA_WidgetAcc::FindSplitPos(int32_t iBlockIndex, FX_FLOAT& fCalcHeight) { FX_FLOAT fSplitHeight = iLineNum * fLineHeight + fCapReserve + fStartOffset; if (iFieldSplitCount / 3 == (iBlockIndex + 1)) { - pFieldArray->SetAt(iBlockIndex * 3 + 1, (FX_FLOAT)iLineNum); - pFieldArray->SetAt(iBlockIndex * 3 + 2, fSplitHeight); + (*pFieldArray)[iBlockIndex * 3 + 1] = (FX_FLOAT)iLineNum; + (*pFieldArray)[iBlockIndex * 3 + 2] = fSplitHeight; } else { - pFieldArray->Add((FX_FLOAT)iLineNum); - pFieldArray->Add(fSplitHeight); + pFieldArray->push_back((FX_FLOAT)iLineNum); + pFieldArray->push_back(fSplitHeight); } if (fabs(fSplitHeight - fCalcHeight) < XFA_FLOAT_PERCISION) { return false; diff --git a/xfa/fxfa/app/xfa_textlayout.cpp b/xfa/fxfa/app/xfa_textlayout.cpp index 345fc272e3..2a7161333e 100644 --- a/xfa/fxfa/app/xfa_textlayout.cpp +++ b/xfa/fxfa/app/xfa_textlayout.cpp @@ -9,6 +9,7 @@ #include #include "core/fxcrt/fx_ext.h" +#include "third_party/base/stl_util.h" #include "xfa/fde/cfde_path.h" #include "xfa/fde/css/fde_csscache.h" #include "xfa/fde/css/fde_cssstyleselector.h" @@ -1004,10 +1005,9 @@ bool CXFA_TextLayout::DoLayout(int32_t iBlockIndex, iLineIndex = m_Blocks.ElementAt(iBlockCount - 1) + m_Blocks.ElementAt(iBlockCount - 2); } - if (m_pLoader->m_BlocksHeight.GetSize() > 0) { - for (int32_t i = 0; i < iBlockIndex; i++) { - fLinePos -= m_pLoader->m_BlocksHeight.ElementAt(i * 2 + 1); - } + if (!m_pLoader->m_BlocksHeight.empty()) { + for (int32_t i = 0; i < iBlockIndex; i++) + fLinePos -= m_pLoader->m_BlocksHeight[i * 2 + 1]; } } int32_t iCount = m_pLoader->m_lineHeights.GetSize(); @@ -1028,13 +1028,13 @@ bool CXFA_TextLayout::DoLayout(int32_t iBlockIndex, } if (i == iLineIndex) { if (fCalcHeight <= fLinePos) { - if (m_pLoader->m_BlocksHeight.GetSize() > iBlockIndex * 2 && - (m_pLoader->m_BlocksHeight.GetAt(iBlockIndex * 2) == - iBlockIndex)) { - m_pLoader->m_BlocksHeight.SetAt(iBlockIndex * 2 + 1, fCalcHeight); + if (pdfium::CollectionSize(m_pLoader->m_BlocksHeight) > + iBlockIndex * 2 && + (m_pLoader->m_BlocksHeight[iBlockIndex * 2] == iBlockIndex)) { + m_pLoader->m_BlocksHeight[iBlockIndex * 2 + 1] = fCalcHeight; } else { - m_pLoader->m_BlocksHeight.Add((FX_FLOAT)iBlockIndex); - m_pLoader->m_BlocksHeight.Add(fCalcHeight); + m_pLoader->m_BlocksHeight.push_back((FX_FLOAT)iBlockIndex); + m_pLoader->m_BlocksHeight.push_back(fCalcHeight); } } return true; @@ -1103,7 +1103,8 @@ bool CXFA_TextLayout::Layout(int32_t iBlock) { CXFA_Node* pNode = nullptr; CFX_SizeF szText(m_pLoader->m_fWidth, m_pLoader->m_fHeight); int32_t iCount = m_Blocks.GetSize(); - int32_t iBlocksHeightCount = m_pLoader->m_BlocksHeight.GetSize(); + int32_t iBlocksHeightCount = + pdfium::CollectionSize(m_pLoader->m_BlocksHeight); iBlocksHeightCount /= 2; if (iBlock < iBlocksHeightCount) return true; @@ -1112,7 +1113,7 @@ bool CXFA_TextLayout::Layout(int32_t iBlock) { m_pBreak.reset(CreateBreak(true)); fLinePos = m_pLoader->m_fStartLineOffset; for (int32_t i = 0; i < iBlocksHeightCount; i++) { - fLinePos -= m_pLoader->m_BlocksHeight.ElementAt(i * 2 + 1); + fLinePos -= m_pLoader->m_BlocksHeight[i * 2 + 1]; } m_pLoader->m_iChar = 0; if (iCount > 1) @@ -1187,17 +1188,17 @@ void CXFA_TextLayout::ItemBlocks(const CFX_RectF& rtText, int32_t iBlockIndex) { FX_FLOAT fLinePos = m_pLoader->m_fStartLineOffset; int32_t iLineIndex = 0; if (iBlockIndex > 0) { - int32_t iBlockHeightCount = m_pLoader->m_BlocksHeight.GetSize(); + int32_t iBlockHeightCount = + pdfium::CollectionSize(m_pLoader->m_BlocksHeight); iBlockHeightCount /= 2; if (iBlockHeightCount >= iBlockIndex) { for (int32_t i = 0; i < iBlockIndex; i++) { - fLinePos -= m_pLoader->m_BlocksHeight.ElementAt(i * 2 + 1); + fLinePos -= m_pLoader->m_BlocksHeight[i * 2 + 1]; } } else { fLinePos = 0; } - iLineIndex = m_Blocks.ElementAt(iBlockCount - 1) + - m_Blocks.ElementAt(iBlockCount - 2); + iLineIndex = m_Blocks[iBlockCount - 1] + m_Blocks[iBlockCount - 2]; } int32_t i = 0; for (i = iLineIndex; i < iCountHeight; i++) { diff --git a/xfa/fxfa/app/xfa_textlayout.h b/xfa/fxfa/app/xfa_textlayout.h index b299f52904..26bd1634ee 100644 --- a/xfa/fxfa/app/xfa_textlayout.h +++ b/xfa/fxfa/app/xfa_textlayout.h @@ -9,6 +9,7 @@ #include #include +#include #include "xfa/fde/css/fde_css.h" #include "xfa/fde/fde_gedevice.h" @@ -155,7 +156,7 @@ class CXFA_LoaderContext { IFDE_CSSComputedStyle* m_pParentStyle; CFX_ArrayTemplate m_lineHeights; uint32_t m_dwFlags; - CFX_FloatArray m_BlocksHeight; + std::vector m_BlocksHeight; }; class CXFA_LinkUserData : public IFX_Retainable, public CFX_Target { -- cgit v1.2.3