Spanify methods in BC_OneDimWriter
Bug: pdfium:2155
Change-Id: If1812cbf546137b08166b73e367f9ca5b0679748
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/119511
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Thomas Sepez <tsepez@google.com>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/fxbarcode/oned/BC_OneDimWriter.cpp b/fxbarcode/oned/BC_OneDimWriter.cpp
index 469fb49..2e9093d 100644
--- a/fxbarcode/oned/BC_OneDimWriter.cpp
+++ b/fxbarcode/oned/BC_OneDimWriter.cpp
@@ -20,11 +20,6 @@
* limitations under the License.
*/
-#if defined(UNSAFE_BUFFERS_BUILD)
-// TODO(crbug.com/pdfium/2154): resolve buffer safety issues.
-#pragma allow_unsafe_buffers
-#endif
-
#include "fxbarcode/oned/BC_OneDimWriter.h"
#include <math.h>
@@ -107,7 +102,7 @@
}
void CBC_OneDimWriter::CalcTextInfo(const ByteString& text,
- TextCharPos* charPos,
+ pdfium::span<TextCharPos> charPos,
CFX_Font* cFont,
float geWidth,
int32_t fontSize,
@@ -156,7 +151,7 @@
const CFX_Matrix& matrix,
const ByteString str,
float geWidth,
- TextCharPos* pCharPos,
+ pdfium::span<TextCharPos> pCharPos,
float locX,
float locY,
int32_t barWidth) {
@@ -172,7 +167,7 @@
CFX_Matrix affine_matrix(1.0, 0.0, 0.0, -1.0, (float)locX,
(float)(locY + iFontSize));
affine_matrix.Concat(matrix);
- device->DrawNormalText(pdfium::make_span(pCharPos, str.GetLength()), m_pFont,
+ device->DrawNormalText(pCharPos.first(str.GetLength()), m_pFont,
static_cast<float>(iFontSize), affine_matrix,
m_fontColor, GetTextRenderOptions());
}
@@ -197,7 +192,7 @@
}
int32_t iFontSize = static_cast<int32_t>(fabs(m_fFontSize));
int32_t iTextHeight = iFontSize + 1;
- CalcTextInfo(str, charpos.data(), m_pFont, geWidth, iFontSize, charsLen);
+ CalcTextInfo(str, charpos, m_pFont, geWidth, iFontSize, charsLen);
if (charsLen < 1)
return true;
@@ -226,7 +221,7 @@
geWidth = (float)barWidth;
break;
}
- ShowDeviceChars(device, matrix, str, geWidth, charpos.data(), (float)locX,
+ ShowDeviceChars(device, matrix, str, geWidth, charpos, (float)locX,
(float)locY, barWidth);
return true;
}
diff --git a/fxbarcode/oned/BC_OneDimWriter.h b/fxbarcode/oned/BC_OneDimWriter.h
index 085f27a..1251d4e 100644
--- a/fxbarcode/oned/BC_OneDimWriter.h
+++ b/fxbarcode/oned/BC_OneDimWriter.h
@@ -63,12 +63,12 @@
const CFX_Matrix& matrix,
const ByteString str,
float geWidth,
- TextCharPos* pCharPos,
+ pdfium::span<TextCharPos> pCharPos,
float locX,
float locY,
int32_t barWidth);
void CalcTextInfo(const ByteString& text,
- TextCharPos* charPos,
+ pdfium::span<TextCharPos> charPos,
CFX_Font* cFont,
float geWidth,
int32_t fontSize,
diff --git a/fxbarcode/oned/BC_OnedEAN13Writer.cpp b/fxbarcode/oned/BC_OnedEAN13Writer.cpp
index 9ef53bd..65917f9 100644
--- a/fxbarcode/oned/BC_OnedEAN13Writer.cpp
+++ b/fxbarcode/oned/BC_OnedEAN13Writer.cpp
@@ -156,41 +156,41 @@
length = tempStr.GetLength();
int32_t strWidth = static_cast<int32_t>(kWidth * m_outputHScale);
- CalcTextInfo(tempStr, &charpos[1], m_pFont, (float)strWidth, iFontSize,
- blank);
+ pdfium::span<TextCharPos> charpos_span = pdfium::make_span(charpos);
+ CalcTextInfo(tempStr, charpos_span.subspan(1), m_pFont, (float)strWidth,
+ iFontSize, blank);
{
CFX_Matrix affine_matrix1(1.0, 0.0, 0.0, -1.0,
kLeftPosition * m_outputHScale,
(float)(m_Height - iTextHeight) + iFontSize);
affine_matrix1.Concat(matrix);
- device->DrawNormalText(pdfium::make_span(charpos).subspan(1, length),
- m_pFont, static_cast<float>(iFontSize),
- affine_matrix1, m_fontColor, GetTextRenderOptions());
+ device->DrawNormalText(charpos_span.subspan(1, length), m_pFont,
+ static_cast<float>(iFontSize), affine_matrix1,
+ m_fontColor, GetTextRenderOptions());
}
tempStr = str.Substr(7, 6);
length = tempStr.GetLength();
- CalcTextInfo(tempStr, &charpos[7], m_pFont, (float)strWidth, iFontSize,
- blank);
+ CalcTextInfo(tempStr, charpos_span.subspan(7), m_pFont, (float)strWidth,
+ iFontSize, blank);
{
CFX_Matrix affine_matrix1(1.0, 0.0, 0.0, -1.0,
(kLeftPosition + 47) * m_outputHScale,
(float)(m_Height - iTextHeight + iFontSize));
affine_matrix1.Concat(matrix);
- device->DrawNormalText(pdfium::make_span(charpos).subspan(7, length),
- m_pFont, static_cast<float>(iFontSize),
- affine_matrix1, m_fontColor, GetTextRenderOptions());
+ device->DrawNormalText(charpos_span.subspan(7, length), m_pFont,
+ static_cast<float>(iFontSize), affine_matrix1,
+ m_fontColor, GetTextRenderOptions());
}
tempStr = str.First(1);
length = tempStr.GetLength();
strWidth = 7 * static_cast<int32_t>(strWidth * m_outputHScale);
- CalcTextInfo(tempStr, charpos.data(), m_pFont, (float)strWidth, iFontSize,
- blank);
+ CalcTextInfo(tempStr, charpos, m_pFont, (float)strWidth, iFontSize, blank);
{
CFX_Matrix affine_matrix1(1.0, 0.0, 0.0, -1.0, 0.0,
(float)(m_Height - iTextHeight + iFontSize));
affine_matrix1.Concat(matrix);
- device->DrawNormalText(pdfium::make_span(charpos).first(length), m_pFont,
+ device->DrawNormalText(charpos_span.first(length), m_pFont,
static_cast<float>(iFontSize), affine_matrix1,
m_fontColor, GetTextRenderOptions());
}
diff --git a/fxbarcode/oned/BC_OnedEAN8Writer.cpp b/fxbarcode/oned/BC_OnedEAN8Writer.cpp
index d2dd393..2cf46a6 100644
--- a/fxbarcode/oned/BC_OnedEAN8Writer.cpp
+++ b/fxbarcode/oned/BC_OnedEAN8Writer.cpp
@@ -147,27 +147,27 @@
device->FillRect(re, kBackgroundColor);
int32_t strWidth = static_cast<int32_t>(kWidth * m_outputHScale);
- CalcTextInfo(tempStr, charpos.data(), m_pFont, (float)strWidth, iFontSize,
- blank);
+ pdfium::span<TextCharPos> charpos_span = pdfium::make_span(charpos);
+ CalcTextInfo(tempStr, charpos, m_pFont, (float)strWidth, iFontSize, blank);
{
CFX_Matrix affine_matrix1(1.0, 0.0, 0.0, -1.0,
kLeftPosition * m_outputHScale,
(float)(m_Height - iTextHeight + iFontSize));
affine_matrix1.Concat(matrix);
- device->DrawNormalText(pdfium::make_span(charpos).first(iLen), m_pFont,
+ device->DrawNormalText(charpos_span.first(iLen), m_pFont,
static_cast<float>(iFontSize), affine_matrix1,
m_fontColor, GetTextRenderOptions());
}
tempStr = str.Substr(4, 4);
iLen = tempStr.GetLength();
- CalcTextInfo(tempStr, &charpos[4], m_pFont, (float)strWidth, iFontSize,
- blank);
+ CalcTextInfo(tempStr, charpos_span.subspan(4), m_pFont, (float)strWidth,
+ iFontSize, blank);
{
CFX_Matrix affine_matrix1(1.0, 0.0, 0.0, -1.0,
(kLeftPosition + 33) * m_outputHScale,
(float)(m_Height - iTextHeight + iFontSize));
affine_matrix1.Concat(matrix);
- device->DrawNormalText(pdfium::make_span(charpos).subspan(4, iLen), m_pFont,
+ device->DrawNormalText(charpos_span.subspan(4, iLen), m_pFont,
static_cast<float>(iFontSize), affine_matrix1,
m_fontColor, GetTextRenderOptions());
}
diff --git a/fxbarcode/oned/BC_OnedUPCAWriter.cpp b/fxbarcode/oned/BC_OnedUPCAWriter.cpp
index 55a6a02..140f200 100644
--- a/fxbarcode/oned/BC_OnedUPCAWriter.cpp
+++ b/fxbarcode/oned/BC_OnedUPCAWriter.cpp
@@ -136,52 +136,56 @@
device->FillRect(re, kBackgroundColor);
float strWidth = kWidth * m_outputHScale;
- CalcTextInfo(tempStr, &charpos[1], m_pFont, strWidth, iFontSize, blank);
+ pdfium::span<TextCharPos> charpos_span = pdfium::make_span(charpos);
+ CalcTextInfo(tempStr, charpos_span.subspan(1), m_pFont, strWidth, iFontSize,
+ blank);
{
CFX_Matrix affine_matrix1(1.0, 0.0, 0.0, -1.0,
kLeftPosition * m_outputHScale,
(float)(m_Height - iTextHeight + iFontSize));
affine_matrix1.Concat(matrix);
- device->DrawNormalText(pdfium::make_span(charpos).subspan(1, length),
- m_pFont, static_cast<float>(iFontSize),
- affine_matrix1, m_fontColor, GetTextRenderOptions());
+ device->DrawNormalText(charpos_span.subspan(1, length), m_pFont,
+ static_cast<float>(iFontSize), affine_matrix1,
+ m_fontColor, GetTextRenderOptions());
}
tempStr = str.Substr(6, 5);
length = tempStr.GetLength();
- CalcTextInfo(tempStr, &charpos[6], m_pFont, strWidth, iFontSize, blank);
+ CalcTextInfo(tempStr, charpos_span.subspan(6), m_pFont, strWidth, iFontSize,
+ blank);
{
CFX_Matrix affine_matrix1(1.0, 0.0, 0.0, -1.0,
(kLeftPosition + 40) * m_outputHScale,
(float)(m_Height - iTextHeight + iFontSize));
affine_matrix1.Concat(matrix);
- device->DrawNormalText(pdfium::make_span(charpos).subspan(6, length),
- m_pFont, static_cast<float>(iFontSize),
- affine_matrix1, m_fontColor, GetTextRenderOptions());
+ device->DrawNormalText(charpos_span.subspan(6, length), m_pFont,
+ static_cast<float>(iFontSize), affine_matrix1,
+ m_fontColor, GetTextRenderOptions());
}
tempStr = str.First(1);
length = tempStr.GetLength();
strWidth = 7 * m_outputHScale;
- CalcTextInfo(tempStr, charpos.data(), m_pFont, strWidth, iFontSize, blank);
+ CalcTextInfo(tempStr, charpos, m_pFont, strWidth, iFontSize, blank);
{
CFX_Matrix affine_matrix1(1.0, 0.0, 0.0, -1.0, 0,
(float)(m_Height - iTextHeight + iFontSize));
affine_matrix1.Concat(matrix);
- device->DrawNormalText(pdfium::make_span(charpos).first(length), m_pFont,
+ device->DrawNormalText(charpos_span.first(length), m_pFont,
static_cast<float>(iFontSize), affine_matrix1,
m_fontColor, GetTextRenderOptions());
}
tempStr = str.Substr(11, 1);
length = tempStr.GetLength();
- CalcTextInfo(tempStr, &charpos[11], m_pFont, strWidth, iFontSize, blank);
+ CalcTextInfo(tempStr, charpos_span.subspan(11), m_pFont, strWidth, iFontSize,
+ blank);
{
CFX_Matrix affine_matrix1(1.0, 0.0, 0.0, -1.0,
(kLeftPosition + 85) * m_outputHScale,
(float)(m_Height - iTextHeight + iFontSize));
affine_matrix1.Concat(matrix);
- device->DrawNormalText(pdfium::make_span(charpos).subspan(11, length),
- m_pFont, static_cast<float>(iFontSize),
- affine_matrix1, m_fontColor, GetTextRenderOptions());
+ device->DrawNormalText(charpos_span.subspan(11, length), m_pFont,
+ static_cast<float>(iFontSize), affine_matrix1,
+ m_fontColor, GetTextRenderOptions());
}
return true;
}