Get rid of "exceptions" in CBC_OneDimWriter::AppendPattern().
They can never happen. Also delete CBC_QRCoder::At() which throws
"exceptions" but it never gets called.
Change-Id: I1b46352d97bb20f1da79e1e67b4523ee8131db79
Reviewed-on: https://pdfium-review.googlesource.com/c/45770
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 8630b36..a282765 100644
--- a/fxbarcode/oned/BC_OneDimWriter.cpp
+++ b/fxbarcode/oned/BC_OneDimWriter.cpp
@@ -90,20 +90,15 @@
int32_t pos,
const int8_t* pattern,
int32_t patternLength,
- int32_t startColor,
- int32_t& e) {
- if (startColor != 0 && startColor != 1) {
- e = BCExceptionValueMustBeEither0or1;
- return 0;
- }
- uint8_t color = (uint8_t)startColor;
+ bool startColor) {
+ bool color = startColor;
int32_t numAdded = 0;
for (int32_t i = 0; i < patternLength; i++) {
for (int32_t j = 0; j < pattern[i]; j++) {
- target[pos++] = color;
+ target[pos++] = color ? 1 : 0;
numAdded += 1;
}
- color ^= 1;
+ color = !color;
}
return numAdded;
}
diff --git a/fxbarcode/oned/BC_OneDimWriter.h b/fxbarcode/oned/BC_OneDimWriter.h
index 34048bc..35d3ca0 100644
--- a/fxbarcode/oned/BC_OneDimWriter.h
+++ b/fxbarcode/oned/BC_OneDimWriter.h
@@ -53,31 +53,30 @@
int32_t hints);
virtual uint8_t* EncodeImpl(const ByteString& contents,
int32_t& outLength) = 0;
- virtual void CalcTextInfo(const ByteString& text,
- FXTEXT_CHARPOS* charPos,
- CFX_Font* cFont,
- float geWidth,
- int32_t fontSize,
- float& charsLen);
virtual bool ShowChars(const WideStringView& contents,
CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t barWidth,
int32_t multiple);
- virtual void ShowDeviceChars(CFX_RenderDevice* device,
- const CFX_Matrix* matrix,
- const ByteString str,
- float geWidth,
- FXTEXT_CHARPOS* pCharPos,
- float locX,
- float locY,
- int32_t barWidth);
- virtual int32_t AppendPattern(uint8_t* target,
- int32_t pos,
- const int8_t* pattern,
- int32_t patternLength,
- int32_t startColor,
- int32_t& e);
+ void ShowDeviceChars(CFX_RenderDevice* device,
+ const CFX_Matrix* matrix,
+ const ByteString str,
+ float geWidth,
+ FXTEXT_CHARPOS* pCharPos,
+ float locX,
+ float locY,
+ int32_t barWidth);
+ void CalcTextInfo(const ByteString& text,
+ FXTEXT_CHARPOS* charPos,
+ CFX_Font* cFont,
+ float geWidth,
+ int32_t fontSize,
+ float& charsLen);
+ int32_t AppendPattern(uint8_t* target,
+ int32_t pos,
+ const int8_t* pattern,
+ int32_t patternLength,
+ bool startColor);
void RenderVerticalBars(int32_t outputX, int32_t width, int32_t height);
diff --git a/fxbarcode/oned/BC_OnedCode128Writer.cpp b/fxbarcode/oned/BC_OnedCode128Writer.cpp
index 7a16280..c8d1128 100644
--- a/fxbarcode/oned/BC_OnedCode128Writer.cpp
+++ b/fxbarcode/oned/BC_OnedCode128Writer.cpp
@@ -157,10 +157,7 @@
int32_t pos = 0;
for (size_t i = 0; i < patterns.size(); ++i) {
const int8_t* pattern = CODE_PATTERNS[patterns[i]];
- int32_t e = BCExceptionNO;
- pos += AppendPattern(result.get(), pos, pattern, kPatternSize, 1, e);
- if (e != BCExceptionNO)
- return nullptr;
+ pos += AppendPattern(result.get(), pos, pattern, kPatternSize, true);
}
return result.release();
}
diff --git a/fxbarcode/oned/BC_OnedCode39Writer.cpp b/fxbarcode/oned/BC_OnedCode39Writer.cpp
index 50862c9..4fa2fb5 100644
--- a/fxbarcode/oned/BC_OnedCode39Writer.cpp
+++ b/fxbarcode/oned/BC_OnedCode39Writer.cpp
@@ -187,15 +187,10 @@
outlength = codeWidth;
std::unique_ptr<uint8_t, FxFreeDeleter> result(FX_Alloc(uint8_t, codeWidth));
ToIntArray(kOnedCode39CharacterEncoding[39], widths);
- int32_t e = BCExceptionNO;
- int32_t pos = AppendPattern(result.get(), 0, widths, 9, 1, e);
- if (e != BCExceptionNO)
- return nullptr;
+ int32_t pos = AppendPattern(result.get(), 0, widths, 9, true);
int8_t narrowWhite[] = {1};
- pos += AppendPattern(result.get(), pos, narrowWhite, 1, 0, e);
- if (e != BCExceptionNO)
- return nullptr;
+ pos += AppendPattern(result.get(), pos, narrowWhite, 1, false);
for (int32_t l = m_iContentLen - 1; l >= 0; l--) {
for (size_t i = 0; i < kOnedCode39AlphabetLen; i++) {
@@ -203,18 +198,12 @@
continue;
ToIntArray(kOnedCode39CharacterEncoding[i], widths);
- pos += AppendPattern(result.get(), pos, widths, 9, 1, e);
- if (e != BCExceptionNO)
- return nullptr;
+ pos += AppendPattern(result.get(), pos, widths, 9, true);
}
- pos += AppendPattern(result.get(), pos, narrowWhite, 1, 0, e);
- if (e != BCExceptionNO)
- return nullptr;
+ pos += AppendPattern(result.get(), pos, narrowWhite, 1, false);
}
ToIntArray(kOnedCode39CharacterEncoding[39], widths);
- pos += AppendPattern(result.get(), pos, widths, 9, 1, e);
- if (e != BCExceptionNO)
- return nullptr;
+ pos += AppendPattern(result.get(), pos, widths, 9, true);
auto* result_ptr = result.get();
for (int32_t i = 0; i < codeWidth / 2; i++) {
diff --git a/fxbarcode/oned/BC_OnedEAN13Writer.cpp b/fxbarcode/oned/BC_OnedEAN13Writer.cpp
index 8d4f864..d35a281 100644
--- a/fxbarcode/oned/BC_OnedEAN13Writer.cpp
+++ b/fxbarcode/oned/BC_OnedEAN13Writer.cpp
@@ -103,10 +103,7 @@
std::unique_ptr<uint8_t, FxFreeDeleter> result(
FX_Alloc(uint8_t, m_codeWidth));
int32_t pos = 0;
- int32_t e = BCExceptionNO;
- pos += AppendPattern(result.get(), pos, kOnedEAN13StartPattern, 3, 1, e);
- if (e != BCExceptionNO)
- return nullptr;
+ pos += AppendPattern(result.get(), pos, kOnedEAN13StartPattern, 3, true);
int32_t i = 0;
for (i = 1; i <= 6; i++) {
@@ -114,23 +111,15 @@
if ((parities >> (6 - i) & 1) == 1) {
digit += 10;
}
- pos += AppendPattern(result.get(), pos, L_AND_G_PATTERNS[digit], 4, 0, e);
- if (e != BCExceptionNO)
- return nullptr;
+ pos += AppendPattern(result.get(), pos, L_AND_G_PATTERNS[digit], 4, false);
}
- pos += AppendPattern(result.get(), pos, kOnedEAN13MiddlePattern, 5, 0, e);
- if (e != BCExceptionNO)
- return nullptr;
+ pos += AppendPattern(result.get(), pos, kOnedEAN13MiddlePattern, 5, false);
for (i = 7; i <= 12; i++) {
int32_t digit = FXSYS_DecimalCharToInt(contents[i]);
- pos += AppendPattern(result.get(), pos, kOnedEAN13LPattern[digit], 4, 1, e);
- if (e != BCExceptionNO)
- return nullptr;
+ pos += AppendPattern(result.get(), pos, kOnedEAN13LPattern[digit], 4, true);
}
- pos += AppendPattern(result.get(), pos, kOnedEAN13StartPattern, 3, 1, e);
- if (e != BCExceptionNO)
- return nullptr;
+ pos += AppendPattern(result.get(), pos, kOnedEAN13StartPattern, 3, true);
return result.release();
}
diff --git a/fxbarcode/oned/BC_OnedEAN8Writer.cpp b/fxbarcode/oned/BC_OnedEAN8Writer.cpp
index 71c93df..741a3e7 100644
--- a/fxbarcode/oned/BC_OnedEAN8Writer.cpp
+++ b/fxbarcode/oned/BC_OnedEAN8Writer.cpp
@@ -106,31 +106,20 @@
std::unique_ptr<uint8_t, FxFreeDeleter> result(
FX_Alloc(uint8_t, m_codeWidth));
int32_t pos = 0;
- int32_t e = BCExceptionNO;
- pos += AppendPattern(result.get(), pos, kOnedEAN8StartPattern, 3, 1, e);
- if (e != BCExceptionNO)
- return nullptr;
+ pos += AppendPattern(result.get(), pos, kOnedEAN8StartPattern, 3, true);
int32_t i = 0;
for (i = 0; i <= 3; i++) {
int32_t digit = FXSYS_DecimalCharToInt(contents[i]);
- pos += AppendPattern(result.get(), pos, kOnedEAN8LPattern[digit], 4, 0, e);
- if (e != BCExceptionNO)
- return nullptr;
+ pos += AppendPattern(result.get(), pos, kOnedEAN8LPattern[digit], 4, false);
}
- pos += AppendPattern(result.get(), pos, kOnedEAN8MiddlePattern, 5, 0, e);
- if (e != BCExceptionNO)
- return nullptr;
+ pos += AppendPattern(result.get(), pos, kOnedEAN8MiddlePattern, 5, false);
for (i = 4; i <= 7; i++) {
int32_t digit = FXSYS_DecimalCharToInt(contents[i]);
- pos += AppendPattern(result.get(), pos, kOnedEAN8LPattern[digit], 4, 1, e);
- if (e != BCExceptionNO)
- return nullptr;
+ pos += AppendPattern(result.get(), pos, kOnedEAN8LPattern[digit], 4, true);
}
- pos += AppendPattern(result.get(), pos, kOnedEAN8StartPattern, 3, 1, e);
- if (e != BCExceptionNO)
- return nullptr;
+ pos += AppendPattern(result.get(), pos, kOnedEAN8StartPattern, 3, true);
return result.release();
}
diff --git a/fxbarcode/qrcode/BC_QRCoder.cpp b/fxbarcode/qrcode/BC_QRCoder.cpp
index b0a24fa..fe96c5f 100644
--- a/fxbarcode/qrcode/BC_QRCoder.cpp
+++ b/fxbarcode/qrcode/BC_QRCoder.cpp
@@ -77,20 +77,11 @@
return m_numRSBlocks;
}
-CBC_CommonByteMatrix* CBC_QRCoder::GetMatrix() const {
+const CBC_CommonByteMatrix* CBC_QRCoder::GetMatrix() const {
return m_matrix.get();
}
-int32_t CBC_QRCoder::At(int32_t x, int32_t y, int32_t& e) {
- int32_t value = m_matrix->Get(x, y);
- if (!(value == 0 || value == 1)) {
- e = BCExceptionValueMustBeEither0or1;
- return 0;
- }
- return value;
-}
-
-bool CBC_QRCoder::IsValid() {
+bool CBC_QRCoder::IsValid() const {
return m_mode && m_ecLevel && m_version != -1 && m_matrixWidth != -1 &&
m_maskPattern != -1 && m_numTotalBytes != -1 && m_numDataBytes != -1 &&
m_numECBytes != -1 && m_numRSBlocks != -1 &&
diff --git a/fxbarcode/qrcode/BC_QRCoder.h b/fxbarcode/qrcode/BC_QRCoder.h
index af53ded..7b7e680 100644
--- a/fxbarcode/qrcode/BC_QRCoder.h
+++ b/fxbarcode/qrcode/BC_QRCoder.h
@@ -33,10 +33,9 @@
int32_t GetNumDataBytes() const;
int32_t GetNumECBytes() const;
int32_t GetNumRSBlocks() const;
- CBC_CommonByteMatrix* GetMatrix() const;
+ const CBC_CommonByteMatrix* GetMatrix() const;
- int32_t At(int32_t x, int32_t y, int32_t& e);
- bool IsValid();
+ bool IsValid() const;
void SetMode(CBC_QRCoderMode* value);
void SetECLevel(const CBC_QRCoderErrorCorrectionLevel* ecLevel);
diff --git a/fxbarcode/utils.h b/fxbarcode/utils.h
index bb3bc1c..bd2688e 100644
--- a/fxbarcode/utils.h
+++ b/fxbarcode/utils.h
@@ -24,7 +24,6 @@
#define BCExceptionNO 0
#define BCExceptionIllegalArgument 16
-#define BCExceptionValueMustBeEither0or1 50
#define BCExceptionGeneric 107
#endif // FXBARCODE_UTILS_H_