Use size_t in CFDE_TextOut::Line.
Use pdfium::CollectionSize() in fewer places and remove some impossible
code.
Change-Id: I2bb3af78931b0bf85b93cfbc4be6f5ebbcddad8b
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/70215
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/xfa/fde/cfde_textout.cpp b/xfa/fde/cfde_textout.cpp
index ea028b4..b11366f 100644
--- a/xfa/fde/cfde_textout.cpp
+++ b/xfa/fde/cfde_textout.cpp
@@ -298,18 +298,15 @@
device->SetClip_Rect(rtClip.GetOuterRect());
for (auto& line : m_ttoLines) {
- int32_t iPieces = line.GetSize();
- for (int32_t i = 0; i < iPieces; ++i) {
+ for (size_t i = 0; i < line.GetSize(); ++i) {
Piece* pPiece = line.GetPieceAtIndex(i);
- if (!pPiece)
+ size_t szCount = GetDisplayPos(pPiece);
+ if (szCount == 0)
continue;
- size_t szCount = GetDisplayPos(pPiece);
- if (szCount > 0) {
- CFDE_TextOut::DrawString(device, m_TxtColor, m_pFont,
- {m_CharPos.data(), szCount}, m_fFontSize,
- m_Matrix);
- }
+ CFDE_TextOut::DrawString(device, m_TxtColor, m_pFont,
+ {m_CharPos.data(), szCount}, m_fFontSize,
+ m_Matrix);
}
}
device->RestoreState(false);
@@ -429,7 +426,7 @@
m_iCurPiece = pLine->AddPiece(m_iCurPiece, piece);
if (bEnd) {
- int32_t iPieces = pLine->GetSize();
+ size_t iPieces = pLine->GetSize();
if (m_iCurPiece < iPieces)
pLine->RemoveLast(iPieces - m_iCurPiece - 1);
}
@@ -452,11 +449,11 @@
void CFDE_TextOut::ReloadLinePiece(Line* pLine, const CFX_RectF& rect) {
pdfium::span<const wchar_t> text_span = m_wsText.span();
+ size_t iPieceIndex = 0;
+ size_t iPieceCount = pLine->GetSize();
Piece* pPiece = pLine->GetPieceAtIndex(0);
int32_t iStartChar = pPiece->iStartChar;
- int32_t iPieceCount = pLine->GetSize();
int32_t iPieceWidths = 0;
- int32_t iPieceIndex = 0;
CFX_BreakType dwBreakStatus = CFX_BreakType::None;
m_fLinePos = pPiece->rtPiece.top;
while (iPieceIndex < iPieceCount) {
@@ -498,9 +495,8 @@
return;
for (auto& line : m_ttoLines) {
- int32_t iPieces = line.GetSize();
- for (int32_t j = 0; j < iPieces; j++)
- line.GetPieceAtIndex(j)->rtPiece.top += fInc;
+ for (size_t i = 0; i < line.GetSize(); ++i)
+ line.GetPieceAtIndex(i)->rtPiece.top += fInc;
}
}
@@ -532,28 +528,24 @@
CFDE_TextOut::Line::~Line() = default;
-int32_t CFDE_TextOut::Line::AddPiece(int32_t index, const Piece& piece) {
- if (index >= pdfium::CollectionSize<int32_t>(pieces_)) {
+size_t CFDE_TextOut::Line::AddPiece(size_t index, const Piece& piece) {
+ if (index >= pieces_.size()) {
pieces_.push_back(piece);
- return pdfium::CollectionSize<int32_t>(pieces_);
+ return pieces_.size();
}
pieces_[index] = piece;
return index;
}
-int32_t CFDE_TextOut::Line::GetSize() const {
- return pdfium::CollectionSize<int32_t>(pieces_);
+size_t CFDE_TextOut::Line::GetSize() const {
+ return pieces_.size();
}
-CFDE_TextOut::Piece* CFDE_TextOut::Line::GetPieceAtIndex(int32_t index) {
- return pdfium::IndexInBounds(pieces_, index) ? &pieces_[index] : nullptr;
+CFDE_TextOut::Piece* CFDE_TextOut::Line::GetPieceAtIndex(size_t index) {
+ CHECK(pdfium::IndexInBounds(pieces_, index));
+ return &pieces_[index];
}
-void CFDE_TextOut::Line::RemoveLast(int32_t count) {
- if (count < 0)
- return;
-
- pieces_.erase(
- pieces_.end() - std::min(count, pdfium::CollectionSize<int32_t>(pieces_)),
- pieces_.end());
+void CFDE_TextOut::Line::RemoveLast(size_t count) {
+ pieces_.erase(pieces_.end() - std::min(count, pieces_.size()), pieces_.end());
}
diff --git a/xfa/fde/cfde_textout.h b/xfa/fde/cfde_textout.h
index 70712e5..bd6b482 100644
--- a/xfa/fde/cfde_textout.h
+++ b/xfa/fde/cfde_textout.h
@@ -71,10 +71,10 @@
bool new_reload() const { return new_reload_; }
void set_new_reload(bool reload) { new_reload_ = reload; }
- int32_t AddPiece(int32_t index, const Piece& piece);
- int32_t GetSize() const;
- Piece* GetPieceAtIndex(int32_t index);
- void RemoveLast(int32_t count);
+ size_t AddPiece(size_t index, const Piece& piece);
+ size_t GetSize() const;
+ Piece* GetPieceAtIndex(size_t index);
+ void RemoveLast(size_t count);
private:
bool new_reload_ = false;
@@ -113,7 +113,7 @@
CFX_Matrix m_Matrix;
std::deque<Line> m_ttoLines;
int32_t m_iCurLine = 0;
- int32_t m_iCurPiece = 0;
+ size_t m_iCurPiece = 0;
int32_t m_iTotalLines = 0;
std::vector<TextCharPos> m_CharPos;
};