Get rid of a multiplier in the 1D barcode implementation.
The multiplier is always set to 1.
Change-Id: I8e4ef2a79f887d94b0050dc7ae8891814094f9f9
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/100911
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/fxbarcode/oned/BC_OneDimWriter.cpp b/fxbarcode/oned/BC_OneDimWriter.cpp
index 4bca114..dc39f5d 100644
--- a/fxbarcode/oned/BC_OneDimWriter.cpp
+++ b/fxbarcode/oned/BC_OneDimWriter.cpp
@@ -175,8 +175,7 @@
bool CBC_OneDimWriter::ShowChars(WideStringView contents,
CFX_RenderDevice* device,
const CFX_Matrix& matrix,
- int32_t barWidth,
- int32_t multiple) {
+ int32_t barWidth) {
if (!device || !m_pFont)
return false;
@@ -249,7 +248,7 @@
}
return m_locTextLoc == BC_TEXT_LOC::kNone || !contents.Contains(' ') ||
- ShowChars(contents, device, matrix, m_barWidth, m_multiple);
+ ShowChars(contents, device, matrix, m_barWidth);
}
bool CBC_OneDimWriter::RenderResult(WideStringView contents,
@@ -267,26 +266,25 @@
m_outputHScale =
m_Width > 0 ? static_cast<float>(m_Width) / static_cast<float>(codeLength)
: 1.0;
- m_multiple = 1;
const int32_t outputWidth = codeLength;
m_barWidth = m_Width;
m_output.clear();
- m_output.reserve(codeOldLength * m_multiple);
- for (int32_t inputX = 0, outputX = leftPadding * m_multiple;
- inputX < codeOldLength; ++inputX, outputX += m_multiple) {
+ m_output.reserve(codeOldLength);
+ for (int32_t inputX = 0, outputX = leftPadding; inputX < codeOldLength;
+ ++inputX, ++outputX) {
if (code[inputX] != 1)
continue;
if (outputX >= outputWidth)
return true;
- if (outputX + m_multiple > outputWidth && outputWidth - outputX > 0) {
+ if (outputX + 1 > outputWidth && outputWidth - outputX > 0) {
RenderVerticalBars(outputX, outputWidth - outputX);
return true;
}
- RenderVerticalBars(outputX, m_multiple);
+ RenderVerticalBars(outputX, /*width=*/1);
}
return true;
}
diff --git a/fxbarcode/oned/BC_OneDimWriter.h b/fxbarcode/oned/BC_OneDimWriter.h
index 83efb99..efe43d4 100644
--- a/fxbarcode/oned/BC_OneDimWriter.h
+++ b/fxbarcode/oned/BC_OneDimWriter.h
@@ -57,8 +57,7 @@
virtual bool ShowChars(WideStringView contents,
CFX_RenderDevice* device,
const CFX_Matrix& matrix,
- int32_t barWidth,
- int32_t multiple);
+ int32_t barWidth);
void ShowDeviceChars(CFX_RenderDevice* device,
const CFX_Matrix& matrix,
const ByteString str,
@@ -97,7 +96,6 @@
std::vector<CFX_Path> m_output;
int32_t m_barWidth;
- int32_t m_multiple;
float m_outputHScale;
};
diff --git a/fxbarcode/oned/BC_OnedEAN13Writer.cpp b/fxbarcode/oned/BC_OnedEAN13Writer.cpp
index 02aab8c..e2433d9 100644
--- a/fxbarcode/oned/BC_OnedEAN13Writer.cpp
+++ b/fxbarcode/oned/BC_OnedEAN13Writer.cpp
@@ -120,51 +120,47 @@
bool CBC_OnedEAN13Writer::ShowChars(WideStringView contents,
CFX_RenderDevice* device,
const CFX_Matrix& matrix,
- int32_t barWidth,
- int32_t multiple) {
+ int32_t barWidth) {
if (!device)
return false;
- int32_t leftPadding = 7 * multiple;
- int32_t leftPosition = 3 * multiple + leftPadding;
+ constexpr float kLeftPosition = 10.0f;
ByteString str = FX_UTF8Encode(contents);
size_t length = str.GetLength();
std::vector<TextCharPos> charpos(length);
int32_t iFontSize = static_cast<int32_t>(fabs(m_fFontSize));
int32_t iTextHeight = iFontSize + 1;
ByteString tempStr = str.Substr(1, 6);
- int32_t strWidth = multiple * 42;
+ constexpr int32_t kWidth = 42;
CFX_Matrix matr(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0);
- CFX_FloatRect rect((float)leftPosition, (float)(m_Height - iTextHeight),
- (float)(leftPosition + strWidth - 0.5), (float)m_Height);
+ CFX_FloatRect rect(kLeftPosition, (float)(m_Height - iTextHeight),
+ kLeftPosition + kWidth - 0.5, (float)m_Height);
matr.Concat(matrix);
FX_RECT re = matr.TransformRect(rect).GetOuterRect();
device->FillRect(re, kBackgroundColor);
- CFX_FloatRect rect1(
- (float)(leftPosition + 47 * multiple), (float)(m_Height - iTextHeight),
- (float)(leftPosition + 47 * multiple + strWidth - 0.5), (float)m_Height);
+ CFX_FloatRect rect1(kLeftPosition + 47, (float)(m_Height - iTextHeight),
+ kLeftPosition + 47 + kWidth - 0.5, (float)m_Height);
CFX_Matrix matr1(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0);
matr1.Concat(matrix);
re = matr1.TransformRect(rect1).GetOuterRect();
device->FillRect(re, kBackgroundColor);
- int32_t strWidth1 = multiple * 7;
CFX_Matrix matr2(m_outputHScale, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f);
- CFX_FloatRect rect2(0.0f, (float)(m_Height - iTextHeight),
- (float)strWidth1 - 0.5f, (float)m_Height);
+ CFX_FloatRect rect2(0.0f, (float)(m_Height - iTextHeight), 6.5f,
+ (float)m_Height);
matr2.Concat(matrix);
re = matr2.TransformRect(rect2).GetOuterRect();
device->FillRect(re, kBackgroundColor);
- float blank = 0.0;
+ float blank = 0.0f;
length = tempStr.GetLength();
- strWidth = static_cast<int32_t>(strWidth * m_outputHScale);
+ int32_t strWidth = static_cast<int32_t>(kWidth * m_outputHScale);
CalcTextInfo(tempStr, &charpos[1], m_pFont, (float)strWidth, iFontSize,
blank);
{
CFX_Matrix affine_matrix1(1.0, 0.0, 0.0, -1.0,
- (float)leftPosition * m_outputHScale,
+ kLeftPosition * m_outputHScale,
(float)(m_Height - iTextHeight) + iFontSize);
affine_matrix1.Concat(matrix);
device->DrawNormalText(pdfium::make_span(charpos).subspan(1, length),
@@ -176,10 +172,9 @@
CalcTextInfo(tempStr, &charpos[7], m_pFont, (float)strWidth, iFontSize,
blank);
{
- CFX_Matrix affine_matrix1(
- 1.0, 0.0, 0.0, -1.0,
- (float)(leftPosition + 47 * multiple) * m_outputHScale,
- (float)(m_Height - iTextHeight + iFontSize));
+ 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),
@@ -187,8 +182,7 @@
}
tempStr = str.First(1);
length = tempStr.GetLength();
- strWidth = multiple * 7;
- strWidth = static_cast<int32_t>(strWidth * m_outputHScale);
+ strWidth = 7 * static_cast<int32_t>(strWidth * m_outputHScale);
CalcTextInfo(tempStr, charpos.data(), m_pFont, (float)strWidth, iFontSize,
blank);
diff --git a/fxbarcode/oned/BC_OnedEAN13Writer.h b/fxbarcode/oned/BC_OnedEAN13Writer.h
index c2d701d..6975fa5 100644
--- a/fxbarcode/oned/BC_OnedEAN13Writer.h
+++ b/fxbarcode/oned/BC_OnedEAN13Writer.h
@@ -30,8 +30,7 @@
bool ShowChars(WideStringView contents,
CFX_RenderDevice* device,
const CFX_Matrix& matrix,
- int32_t barWidth,
- int32_t multiple) override;
+ int32_t barWidth) override;
int32_t m_codeWidth;
};
diff --git a/fxbarcode/oned/BC_OnedEAN8Writer.cpp b/fxbarcode/oned/BC_OnedEAN8Writer.cpp
index a542fdf..1d3e07e 100644
--- a/fxbarcode/oned/BC_OnedEAN8Writer.cpp
+++ b/fxbarcode/oned/BC_OnedEAN8Writer.cpp
@@ -117,43 +117,41 @@
bool CBC_OnedEAN8Writer::ShowChars(WideStringView contents,
CFX_RenderDevice* device,
const CFX_Matrix& matrix,
- int32_t barWidth,
- int32_t multiple) {
+ int32_t barWidth) {
if (!device)
return false;
- int32_t leftPosition = 3 * multiple;
+ constexpr float kLeftPosition = 3.0f;
ByteString str = FX_UTF8Encode(contents);
size_t iLength = str.GetLength();
std::vector<TextCharPos> charpos(iLength);
ByteString tempStr = str.First(4);
size_t iLen = tempStr.GetLength();
- int32_t strWidth = 7 * multiple * 4;
- float blank = 0.0;
+ constexpr int32_t kWidth = 28;
+ float blank = 0.0f;
int32_t iFontSize = static_cast<int32_t>(fabs(m_fFontSize));
int32_t iTextHeight = iFontSize + 1;
CFX_Matrix matr(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0);
- CFX_FloatRect rect((float)leftPosition, (float)(m_Height - iTextHeight),
- (float)(leftPosition + strWidth - 0.5), (float)m_Height);
+ CFX_FloatRect rect(kLeftPosition, (float)(m_Height - iTextHeight),
+ kLeftPosition + kWidth - 0.5, (float)m_Height);
matr.Concat(matrix);
FX_RECT re = matr.TransformRect(rect).GetOuterRect();
device->FillRect(re, kBackgroundColor);
CFX_Matrix matr1(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0);
- CFX_FloatRect rect1(
- (float)(leftPosition + 33 * multiple), (float)(m_Height - iTextHeight),
- (float)(leftPosition + 33 * multiple + strWidth - 0.5), (float)m_Height);
+ CFX_FloatRect rect1(kLeftPosition + 33, (float)(m_Height - iTextHeight),
+ kLeftPosition + 33 + kWidth - 0.5, (float)m_Height);
matr1.Concat(matrix);
re = matr1.TransformRect(rect1).GetOuterRect();
device->FillRect(re, kBackgroundColor);
- strWidth = static_cast<int32_t>(strWidth * m_outputHScale);
+ int32_t strWidth = static_cast<int32_t>(kWidth * m_outputHScale);
CalcTextInfo(tempStr, charpos.data(), m_pFont, (float)strWidth, iFontSize,
blank);
{
CFX_Matrix affine_matrix1(1.0, 0.0, 0.0, -1.0,
- (float)leftPosition * m_outputHScale,
+ kLeftPosition * m_outputHScale,
(float)(m_Height - iTextHeight + iFontSize));
affine_matrix1.Concat(matrix);
device->DrawNormalText(pdfium::make_span(charpos).first(iLen), m_pFont,
@@ -165,10 +163,9 @@
CalcTextInfo(tempStr, &charpos[4], m_pFont, (float)strWidth, iFontSize,
blank);
{
- CFX_Matrix affine_matrix1(
- 1.0, 0.0, 0.0, -1.0,
- (float)(leftPosition + 33 * multiple) * m_outputHScale,
- (float)(m_Height - iTextHeight + iFontSize));
+ 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,
static_cast<float>(iFontSize), affine_matrix1,
diff --git a/fxbarcode/oned/BC_OnedEAN8Writer.h b/fxbarcode/oned/BC_OnedEAN8Writer.h
index f8a42d9..252db9f 100644
--- a/fxbarcode/oned/BC_OnedEAN8Writer.h
+++ b/fxbarcode/oned/BC_OnedEAN8Writer.h
@@ -33,8 +33,7 @@
bool ShowChars(WideStringView contents,
CFX_RenderDevice* device,
const CFX_Matrix& matrix,
- int32_t barWidth,
- int32_t multiple) override;
+ int32_t barWidth) override;
static constexpr int32_t kDefaultCodeWidth = 3 + (7 * 4) + 5 + (7 * 4) + 3;
int32_t m_codeWidth = kDefaultCodeWidth;
diff --git a/fxbarcode/oned/BC_OnedUPCAWriter.cpp b/fxbarcode/oned/BC_OnedUPCAWriter.cpp
index 00cb37c..3534a76 100644
--- a/fxbarcode/oned/BC_OnedUPCAWriter.cpp
+++ b/fxbarcode/oned/BC_OnedUPCAWriter.cpp
@@ -94,59 +94,53 @@
bool CBC_OnedUPCAWriter::ShowChars(WideStringView contents,
CFX_RenderDevice* device,
const CFX_Matrix& matrix,
- int32_t barWidth,
- int32_t multiple) {
+ int32_t barWidth) {
if (!device)
return false;
- int32_t leftPadding = 7 * multiple;
- int32_t leftPosition = 10 * multiple + leftPadding;
+ constexpr float kLeftPosition = 17.0f;
ByteString str = FX_UTF8Encode(contents);
size_t length = str.GetLength();
std::vector<TextCharPos> charpos(length);
ByteString tempStr = str.Substr(1, 5);
- float strWidth = (float)35 * multiple;
- float blank = 0.0;
+ constexpr float kWidth = 35.0f;
+ float blank = 0.0f;
length = tempStr.GetLength();
int32_t iFontSize = static_cast<int32_t>(fabs(m_fFontSize));
int32_t iTextHeight = iFontSize + 1;
CFX_Matrix matr(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0);
- CFX_FloatRect rect((float)leftPosition, (float)(m_Height - iTextHeight),
- (float)(leftPosition + strWidth - 0.5), (float)m_Height);
+ CFX_FloatRect rect(kLeftPosition, (float)(m_Height - iTextHeight),
+ kLeftPosition + kWidth - 0.5, (float)m_Height);
matr.Concat(matrix);
FX_RECT re = matr.TransformRect(rect).GetOuterRect();
device->FillRect(re, kBackgroundColor);
CFX_Matrix matr1(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0);
- CFX_FloatRect rect1((float)(leftPosition + 40 * multiple),
- (float)(m_Height - iTextHeight),
- (float)((leftPosition + 40 * multiple) + strWidth - 0.5),
- (float)m_Height);
+ CFX_FloatRect rect1(kLeftPosition + 40, (float)(m_Height - iTextHeight),
+ kLeftPosition + 40 + kWidth - 0.5, (float)m_Height);
matr1.Concat(matrix);
re = matr1.TransformRect(rect1).GetOuterRect();
device->FillRect(re, kBackgroundColor);
- float strWidth1 = (float)multiple * 7;
+ constexpr float kWidth1 = 7.0f;
CFX_Matrix matr2(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0);
- CFX_FloatRect rect2(0.0, (float)(m_Height - iTextHeight),
- (float)strWidth1 - 1, (float)m_Height);
+ CFX_FloatRect rect2(0.0, (float)(m_Height - iTextHeight), kWidth1 - 1,
+ (float)m_Height);
matr2.Concat(matrix);
re = matr2.TransformRect(rect2).GetOuterRect();
device->FillRect(re, kBackgroundColor);
CFX_Matrix matr3(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0);
- CFX_FloatRect rect3((float)(leftPosition + 85 * multiple),
- (float)(m_Height - iTextHeight),
- (float)((leftPosition + 85 * multiple) + strWidth1 - 0.5),
- (float)m_Height);
+ CFX_FloatRect rect3(kLeftPosition + 85, (float)(m_Height - iTextHeight),
+ kLeftPosition + 85 + kWidth1 - 0.5, (float)m_Height);
matr3.Concat(matrix);
re = matr3.TransformRect(rect3).GetOuterRect();
device->FillRect(re, kBackgroundColor);
- strWidth = strWidth * m_outputHScale;
+ float strWidth = kWidth * m_outputHScale;
CalcTextInfo(tempStr, &charpos[1], m_pFont, strWidth, iFontSize, blank);
{
CFX_Matrix affine_matrix1(1.0, 0.0, 0.0, -1.0,
- (float)leftPosition * m_outputHScale,
+ kLeftPosition * m_outputHScale,
(float)(m_Height - iTextHeight + iFontSize));
affine_matrix1.Concat(matrix);
device->DrawNormalText(pdfium::make_span(charpos).subspan(1, length),
@@ -157,10 +151,9 @@
length = tempStr.GetLength();
CalcTextInfo(tempStr, &charpos[6], m_pFont, strWidth, iFontSize, blank);
{
- CFX_Matrix affine_matrix1(
- 1.0, 0.0, 0.0, -1.0,
- (float)(leftPosition + 40 * multiple) * m_outputHScale,
- (float)(m_Height - iTextHeight + iFontSize));
+ 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),
@@ -168,8 +161,7 @@
}
tempStr = str.First(1);
length = tempStr.GetLength();
- strWidth = (float)multiple * 7;
- strWidth = strWidth * m_outputHScale;
+ strWidth = 7 * m_outputHScale;
CalcTextInfo(tempStr, charpos.data(), m_pFont, strWidth, iFontSize, blank);
{
@@ -184,10 +176,9 @@
length = tempStr.GetLength();
CalcTextInfo(tempStr, &charpos[11], m_pFont, strWidth, iFontSize, blank);
{
- CFX_Matrix affine_matrix1(
- 1.0, 0.0, 0.0, -1.0,
- (float)(leftPosition + 85 * multiple) * m_outputHScale,
- (float)(m_Height - iTextHeight + iFontSize));
+ 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),
diff --git a/fxbarcode/oned/BC_OnedUPCAWriter.h b/fxbarcode/oned/BC_OnedUPCAWriter.h
index e9ed964..60c1536 100644
--- a/fxbarcode/oned/BC_OnedUPCAWriter.h
+++ b/fxbarcode/oned/BC_OnedUPCAWriter.h
@@ -33,8 +33,7 @@
bool ShowChars(WideStringView contents,
CFX_RenderDevice* device,
const CFX_Matrix& matrix,
- int32_t barWidth,
- int32_t multiple) override;
+ int32_t barWidth) override;
std::unique_ptr<CBC_OnedEAN13Writer> m_subWriter;
};