Change CPDF_Font::GetNextChar()'s in-out parameter to pass by pointer. Instead of passing by non-const reference. Adjust the override in CPDF_CIDFont and CPDF_CMap::GetNextChar() as well. Change-Id: I0ee6dc21077101cbeeb0e334498075fc463a2d65 Reviewed-on: https://pdfium-review.googlesource.com/39492 Reviewed-by: Nicolás Peña Moreno <npm@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/font/cpdf_cidfont.cpp b/core/fpdfapi/font/cpdf_cidfont.cpp index b25b728..b73e0b8 100644 --- a/core/fpdfapi/font/cpdf_cidfont.cpp +++ b/core/fpdfapi/font/cpdf_cidfont.cpp
@@ -736,8 +736,8 @@ } uint32_t CPDF_CIDFont::GetNextChar(const ByteStringView& pString, - size_t& offset) const { - return m_pCMap->GetNextChar(pString, offset); + size_t* pOffset) const { + return m_pCMap->GetNextChar(pString, pOffset); } int CPDF_CIDFont::GetCharSize(uint32_t charcode) const {
diff --git a/core/fpdfapi/font/cpdf_cidfont.h b/core/fpdfapi/font/cpdf_cidfont.h index 43c1184..ab074fb 100644 --- a/core/fpdfapi/font/cpdf_cidfont.h +++ b/core/fpdfapi/font/cpdf_cidfont.h
@@ -47,7 +47,7 @@ uint32_t GetCharWidthF(uint32_t charcode) override; FX_RECT GetCharBBox(uint32_t charcode) override; uint32_t GetNextChar(const ByteStringView& pString, - size_t& offset) const override; + size_t* pOffset) const override; size_t CountChar(const ByteStringView& pString) const override; int AppendChar(char* str, uint32_t charcode) const override; bool IsVertWriting() const override;
diff --git a/core/fpdfapi/font/cpdf_cmap.cpp b/core/fpdfapi/font/cpdf_cmap.cpp index f3ef829..ee8f264 100644 --- a/core/fpdfapi/font/cpdf_cmap.cpp +++ b/core/fpdfapi/font/cpdf_cmap.cpp
@@ -338,7 +338,8 @@ } uint32_t CPDF_CMap::GetNextChar(const ByteStringView& pString, - size_t& offset) const { + size_t* pOffset) const { + size_t& offset = *pOffset; auto pBytes = pString.span(); switch (m_CodingScheme) { case OneByte: { @@ -422,7 +423,7 @@ size_t count = 0; size_t offset = 0; while (offset < pString.GetLength()) { - GetNextChar(pString, offset); + GetNextChar(pString, &offset); count++; } return count;
diff --git a/core/fpdfapi/font/cpdf_cmap.h b/core/fpdfapi/font/cpdf_cmap.h index 781f0f9..b3c09d5 100644 --- a/core/fpdfapi/font/cpdf_cmap.h +++ b/core/fpdfapi/font/cpdf_cmap.h
@@ -62,7 +62,7 @@ uint16_t CIDFromCharCode(uint32_t charcode) const; int GetCharSize(uint32_t charcode) const; - uint32_t GetNextChar(const ByteStringView& pString, size_t& offset) const; + uint32_t GetNextChar(const ByteStringView& pString, size_t* pOffset) const; size_t CountChar(const ByteStringView& pString) const; int AppendChar(char* str, uint32_t charcode) const;
diff --git a/core/fpdfapi/font/cpdf_font.cpp b/core/fpdfapi/font/cpdf_font.cpp index a243ceb..f75f696 100644 --- a/core/fpdfapi/font/cpdf_font.cpp +++ b/core/fpdfapi/font/cpdf_font.cpp
@@ -275,7 +275,7 @@ size_t offset = 0; uint32_t width = 0; while (offset < pString.GetLength()) - width += GetCharWidthF(GetNextChar(pString, offset)); + width += GetCharWidthF(GetNextChar(pString, &offset)); return width; } @@ -330,13 +330,13 @@ } uint32_t CPDF_Font::GetNextChar(const ByteStringView& pString, - size_t& offset) const { + size_t* pOffset) const { if (pString.IsEmpty()) return 0; - uint8_t ch = offset < pString.GetLength() ? pString[offset++] - : pString[pString.GetLength() - 1]; - return static_cast<uint32_t>(ch); + size_t& offset = *pOffset; + return offset < pString.GetLength() ? pString[offset++] + : pString[pString.GetLength() - 1]; } bool CPDF_Font::IsStandardFont() const {
diff --git a/core/fpdfapi/font/cpdf_font.h b/core/fpdfapi/font/cpdf_font.h index 0174a67..f5d0bac 100644 --- a/core/fpdfapi/font/cpdf_font.h +++ b/core/fpdfapi/font/cpdf_font.h
@@ -54,7 +54,7 @@ virtual bool IsVertWriting() const; virtual bool IsUnicodeCompatible() const; virtual uint32_t GetNextChar(const ByteStringView& pString, - size_t& offset) const; + size_t* pOffset) const; virtual size_t CountChar(const ByteStringView& pString) const; virtual int AppendChar(char* buf, uint32_t charcode) const; virtual int GlyphFromCharCode(uint32_t charcode, bool* pVertGlyph) = 0;
diff --git a/core/fpdfapi/page/cpdf_textobject.cpp b/core/fpdfapi/page/cpdf_textobject.cpp index 9da96f5..84428fe 100644 --- a/core/fpdfapi/page/cpdf_textobject.cpp +++ b/core/fpdfapi/page/cpdf_textobject.cpp
@@ -165,7 +165,7 @@ size_t offset = 0; while (offset < segment.GetLength()) { ASSERT(index < m_CharCodes.size()); - m_CharCodes[index++] = pFont->GetNextChar(segment, offset); + m_CharCodes[index++] = pFont->GetNextChar(segment, &offset); } if (i != nSegs - 1) { m_CharPos[index - 1] = kernings[i];
diff --git a/core/fpdfapi/render/cpdf_textrenderer.cpp b/core/fpdfapi/render/cpdf_textrenderer.cpp index 7aeddf0..dd25d03 100644 --- a/core/fpdfapi/render/cpdf_textrenderer.cpp +++ b/core/fpdfapi/render/cpdf_textrenderer.cpp
@@ -94,7 +94,7 @@ positions.resize(nChars - 1); float cur_pos = 0; for (int i = 0; i < nChars; i++) { - codes[i] = pFont->GetNextChar(str.AsStringView(), offset); + codes[i] = pFont->GetNextChar(str.AsStringView(), &offset); if (i) positions[i - 1] = cur_pos; cur_pos += pFont->GetCharWidthF(codes[i]) * font_size / 1000;