Clang-format //fxbarcode
Change-Id: Iad0cc6dca332a501a5671427bb9281bafa76027f
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/130691
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/fxbarcode/BC_TwoDimWriter.cpp b/fxbarcode/BC_TwoDimWriter.cpp
index c249a89..fb297a6 100644
--- a/fxbarcode/BC_TwoDimWriter.cpp
+++ b/fxbarcode/BC_TwoDimWriter.cpp
@@ -24,8 +24,9 @@
bool CBC_TwoDimWriter::RenderResult(pdfium::span<const uint8_t> code,
int32_t codeWidth,
int32_t codeHeight) {
- if (code.empty())
+ if (code.empty()) {
return false;
+ }
input_width_ = codeWidth;
input_height_ = codeHeight;
diff --git a/fxbarcode/BC_Writer.cpp b/fxbarcode/BC_Writer.cpp
index 3198da6..23d7d32 100644
--- a/fxbarcode/BC_Writer.cpp
+++ b/fxbarcode/BC_Writer.cpp
@@ -11,16 +11,18 @@
CBC_Writer::~CBC_Writer() = default;
bool CBC_Writer::SetModuleHeight(int32_t moduleHeight) {
- if (moduleHeight > 10 || moduleHeight < 1)
+ if (moduleHeight > 10 || moduleHeight < 1) {
return false;
+ }
module_height_ = moduleHeight;
return true;
}
bool CBC_Writer::SetModuleWidth(int32_t moduleWidth) {
- if (moduleWidth > 10 || moduleWidth < 1)
+ if (moduleWidth > 10 || moduleWidth < 1) {
return false;
+ }
module_width_ = moduleWidth;
return true;
diff --git a/fxbarcode/cbc_codabar.cpp b/fxbarcode/cbc_codabar.cpp
index 214a233..1e324b2 100644
--- a/fxbarcode/cbc_codabar.cpp
+++ b/fxbarcode/cbc_codabar.cpp
@@ -33,8 +33,9 @@
bool CBC_Codabar::Encode(WideStringView contents) {
auto* pWriter = GetOnedCodaBarWriter();
- if (!pWriter->CheckContentValidity(contents))
+ if (!pWriter->CheckContentValidity(contents)) {
return false;
+ }
render_contents_ = pWriter->FilterContents(contents);
ByteString byteString = render_contents_.ToUTF8();
diff --git a/fxbarcode/cbc_code128.cpp b/fxbarcode/cbc_code128.cpp
index 240b644..a0277c7 100644
--- a/fxbarcode/cbc_code128.cpp
+++ b/fxbarcode/cbc_code128.cpp
@@ -33,12 +33,14 @@
bool CBC_Code128::Encode(WideStringView contents) {
auto* pWriter = GetOnedCode128Writer();
- if (!pWriter->CheckContentValidity(contents))
+ if (!pWriter->CheckContentValidity(contents)) {
return false;
+ }
WideString content(contents);
- if (contents.GetLength() % 2 && pWriter->GetType() == BC_TYPE::kCode128C)
+ if (contents.GetLength() % 2 && pWriter->GetType() == BC_TYPE::kCode128C) {
content += '0';
+ }
render_contents_ = pWriter->FilterContents(content.AsStringView());
ByteString byteString = render_contents_.ToUTF8();
diff --git a/fxbarcode/cbc_code39.cpp b/fxbarcode/cbc_code39.cpp
index 28e3903..d4a9884 100644
--- a/fxbarcode/cbc_code39.cpp
+++ b/fxbarcode/cbc_code39.cpp
@@ -33,8 +33,9 @@
bool CBC_Code39::Encode(WideStringView contents) {
auto* pWriter = GetOnedCode39Writer();
- if (!pWriter->CheckContentValidity(contents))
+ if (!pWriter->CheckContentValidity(contents)) {
return false;
+ }
WideString filtercontents = pWriter->FilterContents(contents);
render_contents_ = pWriter->RenderTextContents(contents);
diff --git a/fxbarcode/cbc_eancode.cpp b/fxbarcode/cbc_eancode.cpp
index f2261b1..6b96935 100644
--- a/fxbarcode/cbc_eancode.cpp
+++ b/fxbarcode/cbc_eancode.cpp
@@ -22,8 +22,9 @@
bool CBC_EANCode::Encode(WideStringView contents) {
auto* pWriter = GetOneDimEANWriter();
- if (!pWriter->CheckContentValidity(contents))
+ if (!pWriter->CheckContentValidity(contents)) {
return false;
+ }
render_contents_ = Preprocess(contents);
ByteString str = render_contents_.ToUTF8();
@@ -44,8 +45,9 @@
size_t length = encoded_contents.GetLength();
size_t max_length = GetMaxLength();
if (length <= max_length) {
- for (size_t i = 0; i < max_length - length; i++)
+ for (size_t i = 0; i < max_length - length; i++) {
encoded_contents.InsertAtFront(L'0');
+ }
ByteString str = encoded_contents.ToUTF8();
int32_t checksum = pWriter->CalcChecksum(str);
diff --git a/fxbarcode/cbc_pdf417i.cpp b/fxbarcode/cbc_pdf417i.cpp
index fc5a586..c3b82f0 100644
--- a/fxbarcode/cbc_pdf417i.cpp
+++ b/fxbarcode/cbc_pdf417i.cpp
@@ -42,8 +42,9 @@
CBC_PDF417I::~CBC_PDF417I() = default;
bool CBC_PDF417I::Encode(WideStringView contents) {
- if (contents.GetLength() > kMaxPDF417InputLengthBytes)
+ if (contents.GetLength() > kMaxPDF417InputLengthBytes) {
return false;
+ }
auto* pWriter = GetPDF417Writer();
CBC_PDF417Writer::EncodeResult result = pWriter->Encode(contents);
diff --git a/fxbarcode/common/reedsolomon/BC_ReedSolomon.cpp b/fxbarcode/common/reedsolomon/BC_ReedSolomon.cpp
index 401e454..c63ffa4 100644
--- a/fxbarcode/common/reedsolomon/BC_ReedSolomon.cpp
+++ b/fxbarcode/common/reedsolomon/BC_ReedSolomon.cpp
@@ -43,8 +43,9 @@
for (size_t d = cached_generators_.size(); d <= degree; ++d) {
CBC_ReedSolomonGF256Poly temp_poly(field_, {1, field_->Exp(d - 1)});
auto nextGenerator = lastGenerator->Multiply(&temp_poly);
- if (!nextGenerator)
+ if (!nextGenerator) {
return nullptr;
+ }
lastGenerator = nextGenerator.get();
cached_generators_.push_back(std::move(nextGenerator));
@@ -55,36 +56,44 @@
bool CBC_ReedSolomonEncoder::Encode(std::vector<int32_t>* toEncode,
size_t ecBytes) {
- if (ecBytes == 0)
+ if (ecBytes == 0) {
return false;
+ }
- if (toEncode->size() <= ecBytes)
+ if (toEncode->size() <= ecBytes) {
return false;
+ }
CBC_ReedSolomonGF256Poly* generator = BuildGenerator(ecBytes);
- if (!generator)
+ if (!generator) {
return false;
+ }
size_t dataBytes = toEncode->size() - ecBytes;
std::vector<int32_t> infoCoefficients(dataBytes);
- for (size_t x = 0; x < dataBytes; x++)
+ for (size_t x = 0; x < dataBytes; x++) {
infoCoefficients[x] = (*toEncode)[x];
+ }
CBC_ReedSolomonGF256Poly info(field_, infoCoefficients);
auto infoTemp = info.MultiplyByMonomial(ecBytes, 1);
- if (!infoTemp)
+ if (!infoTemp) {
return false;
+ }
auto remainder = infoTemp->Divide(generator);
- if (!remainder)
+ if (!remainder) {
return false;
+ }
const auto& coefficients = remainder->GetCoefficients();
size_t numZeroCoefficients =
ecBytes > coefficients.size() ? ecBytes - coefficients.size() : 0;
- for (size_t i = 0; i < numZeroCoefficients; i++)
+ for (size_t i = 0; i < numZeroCoefficients; i++) {
(*toEncode)[dataBytes + i] = 0;
- for (size_t y = 0; y < coefficients.size(); y++)
+ }
+ for (size_t y = 0; y < coefficients.size(); y++) {
(*toEncode)[dataBytes + numZeroCoefficients + y] = coefficients[y];
+ }
return true;
}
diff --git a/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp b/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp
index 311a026..fae1c09 100644
--- a/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp
+++ b/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp
@@ -53,11 +53,13 @@
std::unique_ptr<CBC_ReedSolomonGF256Poly> CBC_ReedSolomonGF256::BuildMonomial(
int32_t degree,
int32_t coefficient) {
- if (degree < 0)
+ if (degree < 0) {
return nullptr;
+ }
- if (coefficient == 0)
+ if (coefficient == 0) {
return zero_->Clone();
+ }
std::vector<int32_t> coefficients(degree + 1);
coefficients[0] = coefficient;
@@ -74,8 +76,9 @@
}
std::optional<int32_t> CBC_ReedSolomonGF256::Inverse(int32_t a) {
- if (a == 0)
+ if (a == 0) {
return std::nullopt;
+ }
return exp_table_[255 - log_table_[a]];
}
diff --git a/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp b/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp
index 082cbfe..33fb74d 100644
--- a/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp
+++ b/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.cpp
@@ -50,8 +50,9 @@
coefficients_ = field_->GetZero()->GetCoefficients();
} else {
coefficients_.resize(coefficients.size() - firstNonZero);
- for (size_t i = firstNonZero, j = 0; i < coefficients.size(); i++, j++)
+ for (size_t i = firstNonZero, j = 0; i < coefficients.size(); i++, j++) {
coefficients_[j] = coefficients[i];
+ }
}
}
@@ -80,20 +81,24 @@
std::unique_ptr<CBC_ReedSolomonGF256Poly>
CBC_ReedSolomonGF256Poly::AddOrSubtract(const CBC_ReedSolomonGF256Poly* other) {
- if (IsZero())
+ if (IsZero()) {
return other->Clone();
- if (other->IsZero())
+ }
+ if (other->IsZero()) {
return Clone();
+ }
std::vector<int32_t> smallerCoefficients = coefficients_;
std::vector<int32_t> largerCoefficients = other->GetCoefficients();
- if (smallerCoefficients.size() > largerCoefficients.size())
+ if (smallerCoefficients.size() > largerCoefficients.size()) {
std::swap(smallerCoefficients, largerCoefficients);
+ }
std::vector<int32_t> sumDiff(largerCoefficients.size());
size_t lengthDiff = largerCoefficients.size() - smallerCoefficients.size();
- for (size_t i = 0; i < lengthDiff; ++i)
+ for (size_t i = 0; i < lengthDiff; ++i) {
sumDiff[i] = largerCoefficients[i];
+ }
for (size_t i = lengthDiff; i < largerCoefficients.size(); ++i) {
sumDiff[i] = CBC_ReedSolomonGF256::AddOrSubtract(
@@ -104,8 +109,9 @@
std::unique_ptr<CBC_ReedSolomonGF256Poly> CBC_ReedSolomonGF256Poly::Multiply(
const CBC_ReedSolomonGF256Poly* other) {
- if (IsZero() || other->IsZero())
+ if (IsZero() || other->IsZero()) {
return field_->GetZero()->Clone();
+ }
const std::vector<int32_t>& aCoefficients = coefficients_;
const std::vector<int32_t>& bCoefficients = other->GetCoefficients();
@@ -125,36 +131,43 @@
std::unique_ptr<CBC_ReedSolomonGF256Poly>
CBC_ReedSolomonGF256Poly::MultiplyByMonomial(int32_t degree,
int32_t coefficient) const {
- if (degree < 0)
+ if (degree < 0) {
return nullptr;
- if (coefficient == 0)
+ }
+ if (coefficient == 0) {
return field_->GetZero()->Clone();
+ }
size_t size = coefficients_.size();
std::vector<int32_t> product(size + degree);
- for (size_t i = 0; i < size; i++)
+ for (size_t i = 0; i < size; i++) {
product[i] = field_->Multiply(coefficients_[i], coefficient);
+ }
return std::make_unique<CBC_ReedSolomonGF256Poly>(field_, product);
}
std::unique_ptr<CBC_ReedSolomonGF256Poly> CBC_ReedSolomonGF256Poly::Divide(
const CBC_ReedSolomonGF256Poly* other) {
- if (other->IsZero())
+ if (other->IsZero()) {
return nullptr;
+ }
auto quotient = field_->GetZero()->Clone();
- if (!quotient)
+ if (!quotient) {
return nullptr;
+ }
auto remainder = Clone();
- if (!remainder)
+ if (!remainder) {
return nullptr;
+ }
int32_t denominatorLeadingTerm = other->GetCoefficients(other->GetDegree());
std::optional<int32_t> inverseDenominatorLeadingTeam =
field_->Inverse(denominatorLeadingTerm);
- if (!inverseDenominatorLeadingTeam.has_value())
+ if (!inverseDenominatorLeadingTeam.has_value()) {
return nullptr;
+ }
while (remainder->GetDegree() >= other->GetDegree() && !remainder->IsZero()) {
int32_t degreeDifference = remainder->GetDegree() - other->GetDegree();
@@ -162,17 +175,21 @@
field_->Multiply(remainder->GetCoefficients((remainder->GetDegree())),
inverseDenominatorLeadingTeam.value());
auto term = other->MultiplyByMonomial(degreeDifference, scale);
- if (!term)
+ if (!term) {
return nullptr;
+ }
auto iteratorQuotient = field_->BuildMonomial(degreeDifference, scale);
- if (!iteratorQuotient)
+ if (!iteratorQuotient) {
return nullptr;
+ }
quotient = quotient->AddOrSubtract(iteratorQuotient.get());
- if (!quotient)
+ if (!quotient) {
return nullptr;
+ }
remainder = remainder->AddOrSubtract(term.get());
- if (!remainder)
+ if (!remainder) {
return nullptr;
+ }
}
return remainder;
}
diff --git a/fxbarcode/datamatrix/BC_ASCIIEncoder.cpp b/fxbarcode/datamatrix/BC_ASCIIEncoder.cpp
index d221430..3b8f23a 100644
--- a/fxbarcode/datamatrix/BC_ASCIIEncoder.cpp
+++ b/fxbarcode/datamatrix/BC_ASCIIEncoder.cpp
@@ -77,8 +77,9 @@
if (n >= 2) {
std::optional<wchar_t> code = EncodeASCIIDigits(
context->msg_[context->pos_], context->msg_[context->pos_ + 1]);
- if (!code.has_value())
+ if (!code.has_value()) {
return false;
+ }
context->writeCodeword(code.value());
context->pos_ += 2;
diff --git a/fxbarcode/datamatrix/BC_Base256Encoder.cpp b/fxbarcode/datamatrix/BC_Base256Encoder.cpp
index ad7fb5f..ae07751 100644
--- a/fxbarcode/datamatrix/BC_Base256Encoder.cpp
+++ b/fxbarcode/datamatrix/BC_Base256Encoder.cpp
@@ -32,8 +32,9 @@
wchar_t Randomize255State(wchar_t ch, int32_t position) {
int32_t pseudoRandom = ((149 * position) % 255) + 1;
int32_t tempVariable = ch + pseudoRandom;
- if (tempVariable <= 255)
+ if (tempVariable <= 255) {
return static_cast<wchar_t>(tempVariable);
+ }
return static_cast<wchar_t>(tempVariable - 256);
}
@@ -70,8 +71,9 @@
int32_t lengthFieldSize = 1;
int32_t currentSize =
context->getCodewordCount() + dataCount + lengthFieldSize;
- if (!context->UpdateSymbolInfo(currentSize))
+ if (!context->UpdateSymbolInfo(currentSize)) {
return false;
+ }
bool mustPad = (context->symbol_info_->data_capacity() - currentSize) > 0;
if (context->hasMoreCharacters() || mustPad) {
diff --git a/fxbarcode/datamatrix/BC_C40Encoder.cpp b/fxbarcode/datamatrix/BC_C40Encoder.cpp
index 70b6c80..ad27cad 100644
--- a/fxbarcode/datamatrix/BC_C40Encoder.cpp
+++ b/fxbarcode/datamatrix/BC_C40Encoder.cpp
@@ -61,13 +61,15 @@
wchar_t c = context->getCurrentChar();
context->pos_++;
int32_t lastCharSize = EncodeChar(c, &buffer);
- if (lastCharSize <= 0)
+ if (lastCharSize <= 0) {
return false;
+ }
size_t unwritten = (buffer.GetLength() / 3) * 2;
int32_t curCodewordCount = context->getCodewordCount() + unwritten;
- if (!context->UpdateSymbolInfo(curCodewordCount))
+ if (!context->UpdateSymbolInfo(curCodewordCount)) {
return false;
+ }
int32_t available =
context->symbol_info_->data_capacity() - curCodewordCount;
@@ -75,15 +77,17 @@
if ((buffer.GetLength() % 3) == 2) {
if (available < 2 || available > 2) {
lastCharSize = BacktrackOneCharacter(context, &buffer, lastCharSize);
- if (lastCharSize < 0)
+ if (lastCharSize < 0) {
return false;
+ }
}
}
while ((buffer.GetLength() % 3) == 1 &&
((lastCharSize <= 3 && available != 1) || lastCharSize > 3)) {
lastCharSize = BacktrackOneCharacter(context, &buffer, lastCharSize);
- if (lastCharSize < 0)
+ if (lastCharSize < 0) {
return false;
+ }
}
break;
}
@@ -112,27 +116,31 @@
size_t unwritten = (buffer->GetLength() / 3) * 2;
size_t rest = buffer->GetLength() % 3;
int32_t curCodewordCount = context->getCodewordCount() + unwritten;
- if (!context->UpdateSymbolInfo(curCodewordCount))
+ if (!context->UpdateSymbolInfo(curCodewordCount)) {
return false;
+ }
int32_t available = context->symbol_info_->data_capacity() - curCodewordCount;
if (rest == 2) {
*buffer += (wchar_t)'\0';
- while (buffer->GetLength() >= 3)
+ while (buffer->GetLength() >= 3) {
WriteNextTriplet(context, buffer);
+ }
if (context->hasMoreCharacters()) {
context->writeCodeword(CBC_HighLevelEncoder::C40_UNLATCH);
}
} else if (available == 1 && rest == 1) {
- while (buffer->GetLength() >= 3)
+ while (buffer->GetLength() >= 3) {
WriteNextTriplet(context, buffer);
+ }
if (context->hasMoreCharacters()) {
context->writeCodeword(CBC_HighLevelEncoder::C40_UNLATCH);
}
context->pos_--;
} else if (rest == 0) {
- while (buffer->GetLength() >= 3)
+ while (buffer->GetLength() >= 3) {
WriteNextTriplet(context, buffer);
+ }
if (available > 0 || context->hasMoreCharacters()) {
context->writeCodeword(CBC_HighLevelEncoder::C40_UNLATCH);
}
@@ -200,16 +208,18 @@
}
size_t count = buffer->GetLength();
- if (count < static_cast<size_t>(lastCharSize))
+ if (count < static_cast<size_t>(lastCharSize)) {
return -1;
+ }
buffer->Delete(count - lastCharSize, lastCharSize);
context->pos_--;
wchar_t c = context->getCurrentChar();
WideString removed;
int32_t len = EncodeChar(c, &removed);
- if (len <= 0)
+ if (len <= 0) {
return -1;
+ }
context->resetSymbolInfo();
return len;
diff --git a/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp b/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp
index b384b46..da44d9f 100644
--- a/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp
+++ b/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp
@@ -112,18 +112,21 @@
int32_t* pOutWidth,
int32_t* pOutHeight) {
WideString encoded = CBC_HighLevelEncoder::EncodeHighLevel(contents);
- if (encoded.IsEmpty())
+ if (encoded.IsEmpty()) {
return DataVector<uint8_t>();
+ }
const CBC_SymbolInfo* pSymbolInfo =
CBC_SymbolInfo::Lookup(encoded.GetLength(), false);
- if (!pSymbolInfo)
+ if (!pSymbolInfo) {
return DataVector<uint8_t>();
+ }
WideString codewords =
CBC_ErrorCorrection::EncodeECC200(encoded, pSymbolInfo);
- if (codewords.IsEmpty())
+ if (codewords.IsEmpty()) {
return DataVector<uint8_t>();
+ }
int32_t width = pSymbolInfo->GetSymbolDataWidth();
DCHECK(width);
diff --git a/fxbarcode/datamatrix/BC_EdifactEncoder.cpp b/fxbarcode/datamatrix/BC_EdifactEncoder.cpp
index 9960acb..4459c2b 100644
--- a/fxbarcode/datamatrix/BC_EdifactEncoder.cpp
+++ b/fxbarcode/datamatrix/BC_EdifactEncoder.cpp
@@ -33,8 +33,9 @@
WideString EncodeToEdifactCodewords(const WideString& sb) {
size_t len = sb.GetLength();
- if (len == 0)
+ if (len == 0) {
return WideString();
+ }
wchar_t c1 = sb[0];
wchar_t c2 = len >= 2 ? sb[1] : 0;
@@ -53,32 +54,38 @@
bool HandleEOD(CBC_EncoderContext* context, const WideString& buffer) {
size_t count = buffer.GetLength();
- if (count == 0)
+ if (count == 0) {
return true;
- if (count > 4)
+ }
+ if (count > 4) {
return false;
+ }
if (count == 1) {
- if (!context->UpdateSymbolInfo())
+ if (!context->UpdateSymbolInfo()) {
return false;
+ }
int32_t available =
context->symbol_info_->data_capacity() - context->getCodewordCount();
int32_t remaining = context->getRemainingCharacters();
- if (remaining == 0 && available <= 2)
+ if (remaining == 0 && available <= 2) {
return true;
+ }
}
int32_t restChars = count - 1;
WideString encoded = EncodeToEdifactCodewords(buffer);
- if (encoded.IsEmpty())
+ if (encoded.IsEmpty()) {
return false;
+ }
bool endOfSymbolReached = !context->hasMoreCharacters();
bool restInAscii = endOfSymbolReached && restChars <= 2;
if (restChars <= 2) {
- if (!context->UpdateSymbolInfo(context->getCodewordCount() + restChars))
+ if (!context->UpdateSymbolInfo(context->getCodewordCount() + restChars)) {
return false;
+ }
int32_t available =
context->symbol_info_->data_capacity() - context->getCodewordCount();
@@ -129,15 +136,17 @@
WideString buffer;
while (context->hasMoreCharacters()) {
wchar_t c = context->getCurrentChar();
- if (!AppendEncodedChar(c, &buffer))
+ if (!AppendEncodedChar(c, &buffer)) {
return false;
+ }
context->pos_++;
size_t count = buffer.GetLength();
if (count >= 4) {
WideString encoded = EncodeToEdifactCodewords(buffer);
- if (encoded.IsEmpty())
+ if (encoded.IsEmpty()) {
return false;
+ }
context->writeCodewords(encoded);
buffer.Delete(0, 4);
diff --git a/fxbarcode/datamatrix/BC_ErrorCorrection.cpp b/fxbarcode/datamatrix/BC_ErrorCorrection.cpp
index 2b5d567..3a0697c 100644
--- a/fxbarcode/datamatrix/BC_ErrorCorrection.cpp
+++ b/fxbarcode/datamatrix/BC_ErrorCorrection.cpp
@@ -159,8 +159,9 @@
++table;
}
- if (table >= kFactorTableNum)
+ if (table >= kFactorTableNum) {
return WideString();
+ }
auto ecc = FixedSizeDataVector<uint16_t>::Zeroed(numECWords);
pdfium::span<uint16_t> ecc_span = ecc.span();
@@ -183,8 +184,9 @@
}
WideString strecc;
strecc.Reserve(numECWords);
- for (size_t i = 0; i < numECWords; ++i)
+ for (size_t i = 0; i < numECWords; ++i) {
strecc.InsertAtBack(static_cast<wchar_t>(ecc_span[numECWords - i - 1]));
+ }
DCHECK(!strecc.IsEmpty());
return strecc;
@@ -194,15 +196,17 @@
WideString CBC_ErrorCorrection::EncodeECC200(const WideString& codewords,
const CBC_SymbolInfo* symbolInfo) {
- if (codewords.GetLength() != symbolInfo->data_capacity())
+ if (codewords.GetLength() != symbolInfo->data_capacity()) {
return WideString();
+ }
WideString sb = codewords;
size_t blockCount = symbolInfo->GetInterleavedBlockCount();
if (blockCount == 1) {
WideString ecc = CreateECCBlock(codewords, symbolInfo->error_codewords());
- if (ecc.IsEmpty())
+ if (ecc.IsEmpty()) {
return WideString();
+ }
sb += ecc;
} else {
std::vector<size_t> dataSizes(blockCount);
@@ -217,19 +221,23 @@
size_t max_error_sizes =
*std::max_element(errorSizes.begin(), errorSizes.end()) * blockCount;
sb.Reserve(sb.GetLength() + max_error_sizes);
- for (size_t i = 0; i < max_error_sizes; ++i)
+ for (size_t i = 0; i < max_error_sizes; ++i) {
sb.InsertAtBack(0);
+ }
for (size_t block = 0; block < blockCount; ++block) {
WideString temp;
- if (symbolInfo->data_capacity() > block)
+ if (symbolInfo->data_capacity() > block) {
temp.Reserve((symbolInfo->data_capacity() - block / blockCount) + 1);
- for (size_t d = block; d < symbolInfo->data_capacity(); d += blockCount)
+ }
+ for (size_t d = block; d < symbolInfo->data_capacity(); d += blockCount) {
temp.InsertAtBack(static_cast<wchar_t>(codewords[d]));
+ }
WideString ecc = CreateECCBlock(temp, errorSizes[block]);
- if (ecc.IsEmpty())
+ if (ecc.IsEmpty()) {
return WideString();
+ }
for (size_t pos = 0, i = block; i < errorSizes[block] * blockCount;
++pos, i += blockCount) {
diff --git a/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp b/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp
index df3696d..75c73b6 100644
--- a/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp
+++ b/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp
@@ -73,19 +73,22 @@
(*intCharCounts)[i] = current;
if (min > current) {
min = current;
- for (auto& m : *mins)
+ for (auto& m : *mins) {
m = 0;
+ }
}
- if (min == current)
+ if (min == current) {
(*mins)[i]++;
+ }
}
return min;
}
int32_t GetMinimumCount(const std::array<uint8_t, kEncoderCount>& mins) {
int32_t count = 0;
- for (const auto& m : mins)
+ for (const auto& m : mins) {
count += m;
+ }
return count;
}
@@ -123,12 +126,14 @@
static constexpr size_t kMaxNumericInputLength = 3116;
// Exit early if the input is too long. It will fail no matter what.
- if (msg.GetLength() > kMaxNumericInputLength)
+ if (msg.GetLength() > kMaxNumericInputLength) {
return WideString();
+ }
CBC_EncoderContext context(msg);
- if (context.HasCharactersOutsideISO88591Encoding())
+ if (context.HasCharactersOutsideISO88591Encoding()) {
return WideString();
+ }
if (msg.Back() == kMacroTrailer) {
WideString left = msg.First(6);
@@ -152,8 +157,9 @@
encoders.push_back(std::make_unique<CBC_Base256Encoder>());
Encoding encodingMode = Encoding::ASCII;
while (context.hasMoreCharacters()) {
- if (!encoders[EncoderIndex(encodingMode)]->Encode(&context))
+ if (!encoders[EncoderIndex(encodingMode)]->Encode(&context)) {
return WideString();
+ }
if (context.new_encoding_ != Encoding::UNKNOWN) {
encodingMode = context.new_encoding_;
@@ -161,20 +167,24 @@
}
}
size_t len = context.codewords_.GetLength();
- if (!context.UpdateSymbolInfo())
+ if (!context.UpdateSymbolInfo()) {
return WideString();
+ }
size_t capacity = context.symbol_info_->data_capacity();
if (len < capacity) {
- if (encodingMode != Encoding::ASCII && encodingMode != Encoding::BASE256)
+ if (encodingMode != Encoding::ASCII && encodingMode != Encoding::BASE256) {
context.writeCodeword(0x00fe);
+ }
}
WideString codewords = context.codewords_;
- if (codewords.GetLength() < capacity)
+ if (codewords.GetLength() < capacity) {
codewords += kPad;
+ }
- while (codewords.GetLength() < capacity)
+ while (codewords.GetLength() < capacity) {
codewords += Randomize253State(kPad, codewords.GetLength() + 1);
+ }
DCHECK(!codewords.IsEmpty());
return codewords;
@@ -185,8 +195,9 @@
const WideString& msg,
size_t startpos,
CBC_HighLevelEncoder::Encoding currentMode) {
- if (startpos >= msg.GetLength())
+ if (startpos >= msg.GetLength()) {
return currentMode;
+ }
std::array<float, kEncoderCount> charCounts;
if (currentMode == Encoding::ASCII) {
@@ -202,18 +213,23 @@
std::array<int32_t, kEncoderCount> intCharCounts;
std::array<uint8_t, kEncoderCount> mins;
int32_t min = FindMinimums(charCounts, &intCharCounts, &mins);
- if (intCharCounts[EncoderIndex(Encoding::ASCII)] == min)
+ if (intCharCounts[EncoderIndex(Encoding::ASCII)] == min) {
return Encoding::ASCII;
+ }
const int32_t minCount = GetMinimumCount(mins);
if (minCount == 1) {
- if (mins[EncoderIndex(Encoding::BASE256)] > 0)
+ if (mins[EncoderIndex(Encoding::BASE256)] > 0) {
return Encoding::BASE256;
- if (mins[EncoderIndex(Encoding::EDIFACT)] > 0)
+ }
+ if (mins[EncoderIndex(Encoding::EDIFACT)] > 0) {
return Encoding::EDIFACT;
- if (mins[EncoderIndex(Encoding::TEXT)] > 0)
+ }
+ if (mins[EncoderIndex(Encoding::TEXT)] > 0) {
return Encoding::TEXT;
- if (mins[EncoderIndex(Encoding::X12)] > 0)
+ }
+ if (mins[EncoderIndex(Encoding::X12)] > 0) {
return Encoding::X12;
+ }
}
return Encoding::C40;
}
@@ -222,57 +238,63 @@
charsProcessed++;
{
auto& count = charCounts[EncoderIndex(Encoding::ASCII)];
- if (FXSYS_IsDecimalDigit(c))
+ if (FXSYS_IsDecimalDigit(c)) {
count += 0.5;
- else if (IsExtendedASCII(c))
+ } else if (IsExtendedASCII(c)) {
count = ceilf(count) + 2;
- else
+ } else {
count = ceilf(count) + 1;
+ }
}
{
auto& count = charCounts[EncoderIndex(Encoding::C40)];
- if (IsNativeC40(c))
+ if (IsNativeC40(c)) {
count += 2.0f / 3.0f;
- else if (IsExtendedASCII(c))
+ } else if (IsExtendedASCII(c)) {
count += 8.0f / 3.0f;
- else
+ } else {
count += 4.0f / 3.0f;
+ }
}
{
auto& count = charCounts[EncoderIndex(Encoding::TEXT)];
- if (IsNativeText(c))
+ if (IsNativeText(c)) {
count += 2.0f / 3.0f;
- else if (IsExtendedASCII(c))
+ } else if (IsExtendedASCII(c)) {
count += 8.0f / 3.0f;
- else
+ } else {
count += 4.0f / 3.0f;
+ }
}
{
auto& count = charCounts[EncoderIndex(Encoding::X12)];
- if (IsNativeX12(c))
+ if (IsNativeX12(c)) {
count += 2.0f / 3.0f;
- else if (IsExtendedASCII(c))
+ } else if (IsExtendedASCII(c)) {
count += 13.0f / 3.0f;
- else
+ } else {
count += 10.0f / 3.0f;
+ }
}
{
auto& count = charCounts[EncoderIndex(Encoding::EDIFACT)];
- if (IsNativeEDIFACT(c))
+ if (IsNativeEDIFACT(c)) {
count += 3.0f / 4.0f;
- else if (IsExtendedASCII(c))
+ } else if (IsExtendedASCII(c)) {
count += 17.0f / 4.0f;
- else
+ } else {
count += 13.0f / 4.0f;
+ }
}
charCounts[EncoderIndex(Encoding::BASE256)]++;
- if (charsProcessed < 4)
+ if (charsProcessed < 4) {
continue;
+ }
std::array<int32_t, kEncoderCount> intCharCounts;
std::array<uint8_t, kEncoderCount> mins;
@@ -297,24 +319,30 @@
return Encoding::BASE256;
}
if (minCount == 1) {
- if (mins[EncoderIndex(Encoding::EDIFACT)] > 0)
+ if (mins[EncoderIndex(Encoding::EDIFACT)] > 0) {
return Encoding::EDIFACT;
- if (mins[EncoderIndex(Encoding::TEXT)] > 0)
+ }
+ if (mins[EncoderIndex(Encoding::TEXT)] > 0) {
return Encoding::TEXT;
- if (mins[EncoderIndex(Encoding::X12)] > 0)
+ }
+ if (mins[EncoderIndex(Encoding::X12)] > 0) {
return Encoding::X12;
+ }
}
if (c40_count + 1 < ascii_count && c40_count + 1 < bet_min) {
- if (c40_count < x12_count)
+ if (c40_count < x12_count) {
return Encoding::C40;
+ }
if (c40_count == x12_count) {
size_t p = startpos + charsProcessed + 1;
while (p < msg.GetLength()) {
wchar_t tc = msg[p];
- if (IsX12TermSep(tc))
+ if (IsX12TermSep(tc)) {
return Encoding::X12;
- if (!IsNativeX12(tc))
+ }
+ if (!IsNativeX12(tc)) {
break;
+ }
p++;
}
return Encoding::C40;
diff --git a/fxbarcode/datamatrix/BC_SymbolInfo.cpp b/fxbarcode/datamatrix/BC_SymbolInfo.cpp
index e69acc4..0144096 100644
--- a/fxbarcode/datamatrix/BC_SymbolInfo.cpp
+++ b/fxbarcode/datamatrix/BC_SymbolInfo.cpp
@@ -57,8 +57,9 @@
// static
void CBC_SymbolInfo::Initialize() {
- for (size_t i = 0; i < kSymbolDataSize; ++i)
+ for (size_t i = 0; i < kSymbolDataSize; ++i) {
g_symbols[i] = new CBC_SymbolInfo(&kSymbolData[i]);
+ }
g_symbols[kSymbolDataSize] = new CBC_DataMatrixSymbolInfo144();
}
@@ -78,11 +79,13 @@
bool allow_rectangular) {
for (size_t i = 0; i < kSymbolsCount; ++i) {
CBC_SymbolInfo* symbol = g_symbols[i];
- if (symbol->is_rectangular() && !allow_rectangular)
+ if (symbol->is_rectangular() && !allow_rectangular) {
continue;
+ }
- if (data_codewords <= symbol->data_capacity())
+ if (data_codewords <= symbol->data_capacity()) {
return symbol;
+ }
}
return nullptr;
}
diff --git a/fxbarcode/datamatrix/BC_TextEncoder.cpp b/fxbarcode/datamatrix/BC_TextEncoder.cpp
index 80672cf..2066898 100644
--- a/fxbarcode/datamatrix/BC_TextEncoder.cpp
+++ b/fxbarcode/datamatrix/BC_TextEncoder.cpp
@@ -85,8 +85,9 @@
*sb += (wchar_t)(c - 123 + 27);
return 2;
}
- if (c < 0x0080)
+ if (c < 0x0080) {
return 0;
+ }
*sb += (wchar_t)'\1';
*sb += (wchar_t)0x001e;
diff --git a/fxbarcode/datamatrix/BC_X12Encoder.cpp b/fxbarcode/datamatrix/BC_X12Encoder.cpp
index 532d1e3..0f9fe28 100644
--- a/fxbarcode/datamatrix/BC_X12Encoder.cpp
+++ b/fxbarcode/datamatrix/BC_X12Encoder.cpp
@@ -42,8 +42,9 @@
while (context->hasMoreCharacters()) {
wchar_t c = context->getCurrentChar();
context->pos_++;
- if (EncodeChar(c, &buffer) <= 0)
+ if (EncodeChar(c, &buffer) <= 0) {
return false;
+ }
size_t count = buffer.GetLength();
if ((count % 3) == 0) {
@@ -62,8 +63,9 @@
bool CBC_X12Encoder::HandleEOD(CBC_EncoderContext* context,
WideString* buffer) {
- if (!context->UpdateSymbolInfo())
+ if (!context->UpdateSymbolInfo()) {
return false;
+ }
int32_t available =
context->symbol_info_->data_capacity() - context->getCodewordCount();
@@ -83,19 +85,20 @@
}
int32_t CBC_X12Encoder::EncodeChar(wchar_t c, WideString* sb) {
- if (c == '\r')
+ if (c == '\r') {
*sb += (wchar_t)'\0';
- else if (c == '*')
+ } else if (c == '*') {
*sb += (wchar_t)'\1';
- else if (c == '>')
+ } else if (c == '>') {
*sb += (wchar_t)'\2';
- else if (c == ' ')
+ } else if (c == ' ') {
*sb += (wchar_t)'\3';
- else if (FXSYS_IsDecimalDigit(c))
+ } else if (FXSYS_IsDecimalDigit(c)) {
*sb += (wchar_t)(c - 48 + 4);
- else if (FXSYS_IsUpperASCII(c))
+ } else if (FXSYS_IsUpperASCII(c)) {
*sb += (wchar_t)(c - 65 + 14);
- else
+ } else {
return 0;
+ }
return 1;
}
diff --git a/fxbarcode/oned/BC_OneDimWriter.cpp b/fxbarcode/oned/BC_OneDimWriter.cpp
index adaaa29..de689b9 100644
--- a/fxbarcode/oned/BC_OneDimWriter.cpp
+++ b/fxbarcode/oned/BC_OneDimWriter.cpp
@@ -66,8 +66,9 @@
}
bool CBC_OneDimWriter::SetFont(CFX_Font* cFont) {
- if (!cFont)
+ if (!cFont) {
return false;
+ }
font_ = cFont;
return true;
@@ -93,8 +94,9 @@
size_t added = 0;
size_t pos = 0;
for (const int8_t pattern_value : pattern) {
- for (int32_t i = 0; i < pattern_value; ++i)
+ for (int32_t i = 0; i < pattern_value; ++i) {
target[pos++] = color ? 1 : 0;
+ }
added += pattern_value;
color = !color;
}
@@ -194,8 +196,9 @@
int32_t iFontSize = static_cast<int32_t>(fabs(font_size_));
int32_t iTextHeight = iFontSize + 1;
CalcTextInfo(str, charpos, font_, geWidth, iFontSize, charsLen);
- if (charsLen < 1)
+ if (charsLen < 1) {
return true;
+ }
int32_t locX = 0;
int32_t locY = 0;
@@ -255,8 +258,9 @@
bool CBC_OneDimWriter::RenderResult(WideStringView contents,
pdfium::span<const uint8_t> code) {
- if (code.empty())
+ if (code.empty()) {
return false;
+ }
module_height_ = std::max(module_height_, 20);
const size_t original_codelength = code.size();
@@ -271,12 +275,14 @@
output_.clear();
output_.reserve(original_codelength);
for (size_t i = 0; i < original_codelength; ++i) {
- if (code[i] != 1)
+ if (code[i] != 1) {
continue;
+ }
size_t output_index = i + leftPadding;
- if (output_index >= codelength)
+ if (output_index >= codelength) {
return true;
+ }
output_.emplace_back();
output_.back().AppendRect(output_index, 0.0f, output_index + 1, 1.0f);
diff --git a/fxbarcode/oned/BC_OnedCodaBarWriter.cpp b/fxbarcode/oned/BC_OnedCodaBarWriter.cpp
index 9625a66..449a5be 100644
--- a/fxbarcode/oned/BC_OnedCodaBarWriter.cpp
+++ b/fxbarcode/oned/BC_OnedCodaBarWriter.cpp
@@ -50,8 +50,9 @@
'8', '9', '-', '$', '/', ':', '+', '.'};
bool IsValidChar(wchar_t ch, bool isContent) {
- if (ch > 0x7F)
+ if (ch > 0x7F) {
return false;
+ }
char narrow_ch = static_cast<char>(ch);
return pdfium::Contains(kContentChars, narrow_ch) ||
@@ -65,16 +66,18 @@
CBC_OnedCodaBarWriter::~CBC_OnedCodaBarWriter() = default;
bool CBC_OnedCodaBarWriter::SetStartChar(char start) {
- if (!pdfium::Contains(kStartEndChars, start))
+ if (!pdfium::Contains(kStartEndChars, start)) {
return false;
+ }
ch_start_ = start;
return true;
}
bool CBC_OnedCodaBarWriter::SetEndChar(char end) {
- if (!pdfium::Contains(kStartEndChars, end))
+ if (!pdfium::Contains(kStartEndChars, end)) {
return false;
+ }
ch_end_ = end;
return true;
@@ -89,8 +92,9 @@
}
bool CBC_OnedCodaBarWriter::SetWideNarrowRatio(int8_t ratio) {
- if (ratio < 2 || ratio > 3)
+ if (ratio < 2 || ratio > 3) {
return false;
+ }
wide_narr_ratio_ = ratio;
return true;
@@ -112,8 +116,9 @@
index++;
continue;
}
- if (!IsValidChar(ch, true))
+ if (!IsValidChar(ch, true)) {
continue;
+ }
filtercontents += ch;
}
return filtercontents;
diff --git a/fxbarcode/oned/BC_OnedCode128Writer.cpp b/fxbarcode/oned/BC_OnedCode128Writer.cpp
index eaa74e2..bf1564e 100644
--- a/fxbarcode/oned/BC_OnedCode128Writer.cpp
+++ b/fxbarcode/oned/BC_OnedCode128Writer.cpp
@@ -109,8 +109,9 @@
i++;
continue;
}
- if (ch >= 32 && ch <= limit)
+ if (ch >= 32 && ch <= limit) {
filtered += ch;
+ }
}
return filtered;
}
@@ -120,8 +121,9 @@
}
DataVector<uint8_t> CBC_OnedCode128Writer::Encode(const ByteString& contents) {
- if (contents.GetLength() < 1 || contents.GetLength() > 80)
+ if (contents.GetLength() < 1 || contents.GetLength() > 80) {
return DataVector<uint8_t>();
+ }
std::vector<int32_t> patterns;
int32_t checkSum = 0;
@@ -137,8 +139,9 @@
content_len_ = contents.GetLength() + 3;
int32_t codeWidth = 0;
for (const auto& patternIndex : patterns) {
- for (size_t i = 0; i < kPatternSize; ++i)
+ for (size_t i = 0; i < kPatternSize; ++i) {
codeWidth += kCodePatternTable[patternIndex][i];
+ }
}
DataVector<uint8_t> result(codeWidth);
auto result_span = pdfium::make_span(result);
diff --git a/fxbarcode/oned/BC_OnedCode39Writer.cpp b/fxbarcode/oned/BC_OnedCode39Writer.cpp
index 575c01d..8a698d5 100644
--- a/fxbarcode/oned/BC_OnedCode39Writer.cpp
+++ b/fxbarcode/oned/BC_OnedCode39Writer.cpp
@@ -62,21 +62,24 @@
}
char CalcCheckSum(const ByteString& contents) {
- if (contents.GetLength() > 80)
+ if (contents.GetLength() > 80) {
return '*';
+ }
int32_t checksum = 0;
for (const auto& c : contents) {
size_t j = 0;
for (; j < kOnedCode39AlphabetLen; j++) {
if (kOnedCode39Alphabet[j] == c) {
- if (c != '*')
+ if (c != '*') {
checksum += j;
+ }
break;
}
}
- if (j >= kOnedCode39AlphabetLen)
+ if (j >= kOnedCode39AlphabetLen) {
return '*';
+ }
}
return kOnedCode39Checksum[checksum % std::size(kOnedCode39Checksum)];
}
@@ -111,8 +114,9 @@
continue;
}
ch = FXSYS_ToUpperASCII(ch);
- if (IsInOnedCode39Alphabet(ch))
+ if (IsInOnedCode39Alphabet(ch)) {
filtercontents += ch;
+ }
}
return filtercontents;
}
@@ -128,8 +132,9 @@
i++;
continue;
}
- if (IsInOnedCode39Alphabet(FXSYS_ToUpperASCII(ch)))
+ if (IsInOnedCode39Alphabet(FXSYS_ToUpperASCII(ch))) {
renderContents += ch;
+ }
}
return renderContents;
}
@@ -139,8 +144,9 @@
}
bool CBC_OnedCode39Writer::SetWideNarrowRatio(int8_t ratio) {
- if (ratio < 2 || ratio > 3)
+ if (ratio < 2 || ratio > 3) {
return false;
+ }
wide_narr_ratio_ = ratio;
return true;
@@ -148,8 +154,9 @@
DataVector<uint8_t> CBC_OnedCode39Writer::Encode(const ByteString& contents) {
char checksum = CalcCheckSum(contents);
- if (checksum == '*')
+ if (checksum == '*') {
return DataVector<uint8_t>();
+ }
std::array<uint8_t, kArraySize> widths = {};
static constexpr int32_t kWideStrideNum = 3;
@@ -168,8 +175,9 @@
continue;
}
ToIntArray(kOnedCode39CharacterEncoding[i], wide_narr_ratio_, widths);
- for (size_t k = 0; k < kArraySize; k++)
+ for (size_t k = 0; k < kArraySize; k++) {
code_width += widths[k];
+ }
}
}
DataVector<uint8_t> result(code_width);
@@ -209,8 +217,9 @@
ByteString str = checksumContent.ToUTF8();
char checksum;
checksum = CalcCheckSum(str);
- if (checksum == '*')
+ if (checksum == '*') {
return false;
+ }
str += checksum;
*result += checksum;
}
@@ -220,7 +229,8 @@
bool CBC_OnedCode39Writer::RenderResult(WideStringView contents,
pdfium::span<const uint8_t> code) {
WideString encodedCon;
- if (!encodedContents(contents, &encodedCon))
+ if (!encodedContents(contents, &encodedCon)) {
return false;
+ }
return CBC_OneDimWriter::RenderResult(encodedCon.AsStringView(), code);
}
diff --git a/fxbarcode/oned/BC_OnedEAN13Writer.cpp b/fxbarcode/oned/BC_OnedEAN13Writer.cpp
index 8410f4c..ebb48e8 100644
--- a/fxbarcode/oned/BC_OnedEAN13Writer.cpp
+++ b/fxbarcode/oned/BC_OnedEAN13Writer.cpp
@@ -88,8 +88,9 @@
i++;
continue;
}
- if (FXSYS_IsDecimalDigit(ch))
+ if (FXSYS_IsDecimalDigit(ch)) {
filtercontents += ch;
+ }
}
return filtercontents;
}
@@ -99,8 +100,9 @@
}
DataVector<uint8_t> CBC_OnedEAN13Writer::Encode(const ByteString& contents) {
- if (contents.GetLength() != 13)
+ if (contents.GetLength() != 13) {
return DataVector<uint8_t>();
+ }
data_length_ = 13;
int32_t firstDigit = FXSYS_DecimalCharToInt(contents.Front());
@@ -132,8 +134,9 @@
CFX_RenderDevice* device,
const CFX_Matrix& matrix,
int32_t barWidth) {
- if (!device)
+ if (!device) {
return false;
+ }
static constexpr float kLeftPosition = 10.0f;
ByteString str = FX_UTF8Encode(contents);
diff --git a/fxbarcode/oned/BC_OnedEAN8Writer.cpp b/fxbarcode/oned/BC_OnedEAN8Writer.cpp
index e452bd2..e87c878 100644
--- a/fxbarcode/oned/BC_OnedEAN8Writer.cpp
+++ b/fxbarcode/oned/BC_OnedEAN8Writer.cpp
@@ -67,8 +67,9 @@
}
void CBC_OnedEAN8Writer::SetTextLocation(BC_TEXT_LOC location) {
- if (location == BC_TEXT_LOC::kBelowEmbed)
+ if (location == BC_TEXT_LOC::kBelowEmbed) {
loc_text_loc_ = location;
+ }
}
bool CBC_OnedEAN8Writer::CheckContentValidity(WideStringView contents) {
@@ -87,8 +88,9 @@
i++;
continue;
}
- if (FXSYS_IsDecimalDigit(ch))
+ if (FXSYS_IsDecimalDigit(ch)) {
filtercontents += ch;
+ }
}
return filtercontents;
}
@@ -98,8 +100,9 @@
}
DataVector<uint8_t> CBC_OnedEAN8Writer::Encode(const ByteString& contents) {
- if (contents.GetLength() != 8)
+ if (contents.GetLength() != 8) {
return {};
+ }
DataVector<uint8_t> result(code_width_);
auto result_span = pdfium::make_span(result);
@@ -125,8 +128,9 @@
CFX_RenderDevice* device,
const CFX_Matrix& matrix,
int32_t barWidth) {
- if (!device)
+ if (!device) {
return false;
+ }
static constexpr float kLeftPosition = 3.0f;
ByteString str = FX_UTF8Encode(contents);
diff --git a/fxbarcode/oned/BC_OnedEANChecksum.cpp b/fxbarcode/oned/BC_OnedEANChecksum.cpp
index c1fbab4..6752b04 100644
--- a/fxbarcode/oned/BC_OnedEANChecksum.cpp
+++ b/fxbarcode/oned/BC_OnedEANChecksum.cpp
@@ -11,10 +11,11 @@
int32_t even = 0;
size_t parity = 1;
for (size_t i = contents.GetLength(); i > 0; i--) {
- if (parity % 2)
+ if (parity % 2) {
odd += FXSYS_DecimalCharToInt(contents[i - 1]);
- else
+ } else {
even += FXSYS_DecimalCharToInt(contents[i - 1]);
+ }
parity++;
}
return (10 - (odd * 3 + even) % 10) % 10;
diff --git a/fxbarcode/oned/BC_OnedUPCAWriter.cpp b/fxbarcode/oned/BC_OnedUPCAWriter.cpp
index d597409..45c1e5d 100644
--- a/fxbarcode/oned/BC_OnedUPCAWriter.cpp
+++ b/fxbarcode/oned/BC_OnedUPCAWriter.cpp
@@ -57,8 +57,9 @@
i++;
continue;
}
- if (FXSYS_IsDecimalDigit(ch))
+ if (FXSYS_IsDecimalDigit(ch)) {
filtercontents += ch;
+ }
}
return filtercontents;
}
@@ -94,8 +95,9 @@
CFX_RenderDevice* device,
const CFX_Matrix& matrix,
int32_t barWidth) {
- if (!device)
+ if (!device) {
return false;
+ }
static constexpr float kLeftPosition = 17.0f;
ByteString str = FX_UTF8Encode(contents);
diff --git a/fxbarcode/pdf417/BC_PDF417.cpp b/fxbarcode/pdf417/BC_PDF417.cpp
index 91c2726..8ca2c28 100644
--- a/fxbarcode/pdf417/BC_PDF417.cpp
+++ b/fxbarcode/pdf417/BC_PDF417.cpp
@@ -369,19 +369,22 @@
int32_t errorCorrectionCodeWords =
CBC_PDF417ErrorCorrection::GetErrorCorrectionCodewordCount(
errorCorrectionLevel);
- if (errorCorrectionCodeWords < 0)
+ if (errorCorrectionCodeWords < 0) {
return false;
+ }
std::optional<WideString> high_level =
CBC_PDF417HighLevelEncoder::EncodeHighLevel(msg);
- if (!high_level.has_value())
+ if (!high_level.has_value()) {
return false;
+ }
size_t sourceCodeWords = high_level.value().GetLength();
std::vector<int32_t> dimensions =
determineDimensions(sourceCodeWords, errorCorrectionCodeWords);
- if (dimensions.size() != 2)
+ if (dimensions.size() != 2) {
return false;
+ }
int32_t cols = dimensions[0];
int32_t rows = dimensions[1];
int32_t pad = getNumberOfPadCodewords(sourceCodeWords,
@@ -398,15 +401,17 @@
WideString sb;
sb += (wchar_t)n;
sb += high_level.value();
- for (int32_t i = 0; i < pad; i++)
+ for (int32_t i = 0; i < pad; i++) {
sb += (wchar_t)900;
+ }
WideString dataCodewords(sb);
std::optional<WideString> ec =
CBC_PDF417ErrorCorrection::GenerateErrorCorrection(dataCodewords,
errorCorrectionLevel);
- if (!ec.has_value())
+ if (!ec.has_value()) {
return false;
+ }
WideString fullCodewords = dataCodewords + ec.value();
barcode_matrix_ = std::make_unique<CBC_BarcodeMatrix>(cols, rows);
diff --git a/fxbarcode/pdf417/BC_PDF417ErrorCorrection.cpp b/fxbarcode/pdf417/BC_PDF417ErrorCorrection.cpp
index 987937f..c74e260 100644
--- a/fxbarcode/pdf417/BC_PDF417ErrorCorrection.cpp
+++ b/fxbarcode/pdf417/BC_PDF417ErrorCorrection.cpp
@@ -131,8 +131,9 @@
// static
int32_t CBC_PDF417ErrorCorrection::GetErrorCorrectionCodewordCount(
int32_t errorCorrectionLevel) {
- if (errorCorrectionLevel < 0 || errorCorrectionLevel > 8)
+ if (errorCorrectionLevel < 0 || errorCorrectionLevel > 8) {
return -1;
+ }
return 1 << (errorCorrectionLevel + 1);
}
@@ -141,8 +142,9 @@
const WideString& dataCodewords,
int32_t errorCorrectionLevel) {
int32_t k = GetErrorCorrectionCodewordCount(errorCorrectionLevel);
- if (k < 0)
+ if (k < 0) {
return std::nullopt;
+ }
DataVector<wchar_t> ech(k);
size_t sld = dataCodewords.GetLength();
@@ -162,8 +164,9 @@
WideString result;
result.Reserve(k);
for (int32_t j = k - 1; j >= 0; j--) {
- if (ech[j] != 0)
+ if (ech[j] != 0) {
ech[j] = static_cast<wchar_t>(929) - ech[j];
+ }
result += ech[j];
}
return result;
diff --git a/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.cpp b/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.cpp
index c8354a3..e3ec29c 100644
--- a/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.cpp
+++ b/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.cpp
@@ -87,8 +87,9 @@
result.Reserve(len);
for (size_t i = 0; i < len; i++) {
wchar_t ch = bytes[i] & 0xff;
- if (ch == '?' && bytes[i] != '?')
+ if (ch == '?' && bytes[i] != '?') {
return std::nullopt;
+ }
result += ch;
}
@@ -119,12 +120,14 @@
} else {
std::optional<size_t> b =
DetermineConsecutiveBinaryCount(result, bytes.unsigned_span(), p);
- if (!b.has_value())
+ if (!b.has_value()) {
return std::nullopt;
+ }
size_t b_value = b.value();
- if (b_value == 0)
+ if (b_value == 0) {
b_value = 1;
+ }
if (b_value == 1 && encodingMode == EncodingMode::kText) {
EncodeBinary(bytes.unsigned_span(), p, 1, EncodingMode::kText, &sb);
} else {
@@ -154,10 +157,11 @@
switch (submode) {
case SubMode::kAlpha:
if (IsAlphaUpperOrSpace(ch)) {
- if (ch == ' ')
+ if (ch == ' ') {
tmp += 26;
- else
+ } else {
tmp += ch - 65;
+ }
break;
}
if (IsAlphaLowerOrSpace(ch)) {
@@ -177,10 +181,11 @@
break;
case SubMode::kLower:
if (IsAlphaLowerOrSpace(ch)) {
- if (ch == ' ')
+ if (ch == ' ') {
tmp += 26;
- else
+ } else {
tmp += ch - 97;
+ }
break;
}
if (IsAlphaUpperOrSpace(ch)) {
@@ -248,8 +253,9 @@
h = tmp[i];
}
}
- if ((len % 2) != 0)
+ if ((len % 2) != 0) {
*sb += (h * 30) + 29;
+ }
return submode;
}
@@ -258,8 +264,9 @@
size_t count,
EncodingMode startmode,
WideString* sb) {
- if (count == 1 && startmode == EncodingMode::kText)
+ if (count == 1 && startmode == EncodingMode::kText) {
*sb += kShiftToByte;
+ }
size_t idx = startpos;
if (count >= 6) {
@@ -275,13 +282,15 @@
chars[i] = (t % 900);
t /= 900;
}
- for (size_t i = 5; i >= 1; i--)
+ for (size_t i = 5; i >= 1; i--) {
*sb += (chars[i - 1]);
+ }
idx += 6;
}
}
- if (idx < startpos + count)
+ if (idx < startpos + count) {
*sb += kLatchToBytePadded;
+ }
for (size_t i = idx; i < startpos + count; i++) {
int32_t ch = bytes[i] & 0xff;
*sb += ch;
@@ -304,8 +313,9 @@
tmp += c;
bigint = bigint / num900;
} while (!bigint.isZero());
- for (size_t i = tmp.GetLength(); i >= 1; i--)
+ for (size_t i = tmp.GetLength(); i >= 1; i--) {
*sb += tmp[i - 1];
+ }
idx += len;
}
}
@@ -321,8 +331,9 @@
while (FXSYS_IsDecimalDigit(ch) && idx < len) {
count++;
idx++;
- if (idx < len)
+ if (idx < len) {
ch = msg[idx];
+ }
}
}
return count;
@@ -339,16 +350,20 @@
while (numericCount < 13 && FXSYS_IsDecimalDigit(ch) && idx < len) {
numericCount++;
idx++;
- if (idx < len)
+ if (idx < len) {
ch = msg[idx];
+ }
}
- if (numericCount >= 13)
+ if (numericCount >= 13) {
return idx - startpos - numericCount;
- if (numericCount > 0)
+ }
+ if (numericCount > 0) {
continue;
+ }
ch = msg[idx];
- if (!IsText(ch))
+ if (!IsText(ch)) {
break;
+ }
idx++;
}
return idx - startpos;
@@ -367,26 +382,31 @@
while (numericCount < 13 && FXSYS_IsDecimalDigit(ch)) {
numericCount++;
size_t i = idx + numericCount;
- if (i >= len)
+ if (i >= len) {
break;
+ }
ch = msg[i];
}
- if (numericCount >= 13)
+ if (numericCount >= 13) {
return idx - startpos;
+ }
size_t textCount = 0;
while (textCount < 5 && IsText(ch)) {
textCount++;
size_t i = idx + textCount;
- if (i >= len)
+ if (i >= len) {
break;
+ }
ch = msg[i];
}
- if (textCount >= 5)
+ if (textCount >= 5) {
return idx - startpos;
+ }
ch = msg[idx];
- if (bytes[idx] == 63 && ch != '?')
+ if (bytes[idx] == 63 && ch != '?') {
return std::nullopt;
+ }
idx++;
}
return idx - startpos;
diff --git a/fxbarcode/pdf417/BC_PDF417Writer.cpp b/fxbarcode/pdf417/BC_PDF417Writer.cpp
index 3734e18..352e150 100644
--- a/fxbarcode/pdf417/BC_PDF417Writer.cpp
+++ b/fxbarcode/pdf417/BC_PDF417Writer.cpp
@@ -64,12 +64,13 @@
CBC_PDF417 encoder;
int32_t col = (width_ / module_width_ - 69) / 17;
int32_t row = height_ / (module_width_ * 20);
- if (row >= 3 && row <= 90 && col >= 1 && col <= 30)
+ if (row >= 3 && row <= 90 && col >= 1 && col <= 30) {
encoder.setDimensions(col, 1, row, 3);
- else if (col >= 1 && col <= 30)
+ } else if (col >= 1 && col <= 30) {
encoder.setDimensions(col, col, 90, 3);
- else if (row >= 3 && row <= 90)
+ } else if (row >= 3 && row <= 90) {
encoder.setDimensions(30, 1, row, row);
+ }
if (!encoder.GenerateBarcodeLogic(contents, error_correction_level())) {
return {DataVector<uint8_t>(), 0, 0};
}
diff --git a/fxbarcode/qrcode/BC_QRCodeWriter.cpp b/fxbarcode/qrcode/BC_QRCodeWriter.cpp
index 8796ffb..68fc06f 100644
--- a/fxbarcode/qrcode/BC_QRCodeWriter.cpp
+++ b/fxbarcode/qrcode/BC_QRCodeWriter.cpp
@@ -69,8 +69,9 @@
return DataVector<uint8_t>();
}
CBC_QRCoder qr;
- if (!CBC_QRCoderEncoder::Encode(contents, ec, &qr))
+ if (!CBC_QRCoderEncoder::Encode(contents, ec, &qr)) {
return DataVector<uint8_t>();
+ }
*pOutWidth = qr.GetMatrixWidth();
*pOutHeight = qr.GetMatrixWidth();
diff --git a/fxbarcode/qrcode/BC_QRCoderBitVector.cpp b/fxbarcode/qrcode/BC_QRCoderBitVector.cpp
index 0166820..074c8f0 100644
--- a/fxbarcode/qrcode/BC_QRCoderBitVector.cpp
+++ b/fxbarcode/qrcode/BC_QRCoderBitVector.cpp
@@ -71,8 +71,9 @@
}
void CBC_QRCoderBitVector::AppendBitVector(const CBC_QRCoderBitVector* bits) {
- for (size_t i = 0; i < bits->Size(); i++)
+ for (size_t i = 0; i < bits->Size(); i++) {
AppendBit(bits->At(i));
+ }
}
bool CBC_QRCoderBitVector::XOR(const CBC_QRCoderBitVector* other) {
@@ -81,8 +82,9 @@
}
pdfium::span<const uint8_t> other_span = other->GetArray();
- for (size_t i = 0; i < sizeInBytes(); ++i)
+ for (size_t i = 0; i < sizeInBytes(); ++i) {
array_[i] ^= other_span[i];
+ }
return true;
}
diff --git a/fxbarcode/qrcode/BC_QRCoderEncoder.cpp b/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
index 294bdca..e1514fb 100644
--- a/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
+++ b/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
@@ -66,11 +66,13 @@
25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35});
int32_t GetAlphaNumericCode(int32_t code) {
- if (code < 32)
+ if (code < 32) {
return -1;
+ }
size_t code_index = static_cast<size_t>(code - 32);
- if (code_index >= std::size(kAlphaNumericTable))
+ if (code_index >= std::size(kAlphaNumericTable)) {
return -1;
+ }
return kAlphaNumericTable[code_index];
}
@@ -102,13 +104,15 @@
size_t i = 0;
while (i < length) {
int32_t code1 = GetAlphaNumericCode(content[i]);
- if (code1 == -1)
+ if (code1 == -1) {
return false;
+ }
if (i + 1 < length) {
int32_t code2 = GetAlphaNumericCode(content[i + 1]);
- if (code2 == -1)
+ if (code2 == -1) {
return false;
+ }
bits->AppendBits(code1 * 45 + code2, 11);
i += 2;
@@ -121,8 +125,9 @@
}
bool Append8BitBytes(const ByteString& content, CBC_QRCoderBitVector* bits) {
- for (char c : content)
+ for (char c : content) {
bits->AppendBits(c, 8);
+ }
return true;
}
@@ -135,13 +140,16 @@
CBC_QRCoderMode* mode,
CBC_QRCoderBitVector* bits) {
const auto* qcv = CBC_QRCoderVersion::GetVersionForNumber(version);
- if (!qcv)
+ if (!qcv) {
return false;
+ }
int32_t numBits = mode->GetCharacterCountBits(qcv->GetVersionNumber());
- if (numBits == 0)
+ if (numBits == 0) {
return false;
- if (numBits > ((1 << numBits) - 1))
+ }
+ if (numBits > ((1 << numBits) - 1)) {
return true;
+ }
bits->AppendBits(numLetters, numBits);
return true;
@@ -150,12 +158,15 @@
bool AppendBytes(const ByteString& content,
CBC_QRCoderMode* mode,
CBC_QRCoderBitVector* bits) {
- if (mode == CBC_QRCoderMode::sNUMERIC)
+ if (mode == CBC_QRCoderMode::sNUMERIC) {
return AppendNumericBytes(content, bits);
- if (mode == CBC_QRCoderMode::sALPHANUMERIC)
+ }
+ if (mode == CBC_QRCoderMode::sALPHANUMERIC) {
return AppendAlphaNumericBytes(content, bits);
- if (mode == CBC_QRCoderMode::sBYTE)
+ }
+ if (mode == CBC_QRCoderMode::sBYTE) {
return Append8BitBytes(content, bits);
+ }
return false;
}
@@ -235,8 +246,9 @@
int32_t blockID,
int32_t* numDataBytesInBlock,
int32_t* numECBytesInBlock) {
- if (blockID >= numRSBlocks)
+ if (blockID >= numRSBlocks) {
return;
+ }
int32_t numRsBlocksInGroup2 = numTotalBytes % numRSBlocks;
int32_t numRsBlocksInGroup1 = numRSBlocks - numRsBlocksInGroup2;
@@ -257,25 +269,30 @@
bool TerminateBits(int32_t numDataBytes, CBC_QRCoderBitVector* bits) {
size_t capacity = numDataBytes << 3;
- if (bits->Size() > capacity)
+ if (bits->Size() > capacity) {
return false;
+ }
- for (int32_t i = 0; i < 4 && bits->Size() < capacity; ++i)
+ for (int32_t i = 0; i < 4 && bits->Size() < capacity; ++i) {
bits->AppendBit(0);
+ }
int32_t numBitsInLastByte = bits->Size() % 8;
if (numBitsInLastByte > 0) {
int32_t numPaddingBits = 8 - numBitsInLastByte;
- for (int32_t j = 0; j < numPaddingBits; ++j)
+ for (int32_t j = 0; j < numPaddingBits; ++j) {
bits->AppendBit(0);
+ }
}
- if (bits->Size() % 8 != 0)
+ if (bits->Size() % 8 != 0) {
return false;
+ }
int32_t numPaddingBytes = numDataBytes - bits->sizeInBytes();
- for (int32_t k = 0; k < numPaddingBytes; ++k)
+ for (int32_t k = 0; k < numPaddingBytes; ++k) {
bits->AppendBits(k % 2 ? 0x11 : 0xec, 8);
+ }
return bits->Size() == capacity;
}
@@ -291,10 +308,12 @@
return CBC_QRCoderMode::sBYTE;
}
}
- if (hasAlphaNumeric)
+ if (hasAlphaNumeric) {
return CBC_QRCoderMode::sALPHANUMERIC;
- if (hasNumeric)
+ }
+ if (hasNumeric) {
return CBC_QRCoderMode::sNUMERIC;
+ }
return CBC_QRCoderMode::sBYTE;
}
@@ -305,8 +324,9 @@
CBC_QRCoderBitVector* result) {
DCHECK(numTotalBytes >= 0);
DCHECK(numDataBytes >= 0);
- if (bits->sizeInBytes() != static_cast<size_t>(numDataBytes))
+ if (bits->sizeInBytes() != static_cast<size_t>(numDataBytes)) {
return false;
+ }
int32_t dataBytesOffset = 0;
size_t maxNumDataBytes = 0;
@@ -318,16 +338,18 @@
GetNumDataBytesAndNumECBytesForBlockID(numTotalBytes, numDataBytes,
numRSBlocks, i, &numDataBytesInBlock,
&numEcBytesInBlock);
- if (numDataBytesInBlock < 0 || numEcBytesInBlock <= 0)
+ if (numDataBytesInBlock < 0 || numEcBytesInBlock <= 0) {
return false;
+ }
DataVector<uint8_t> dataBytes(numDataBytesInBlock);
fxcrt::Copy(bits->GetArray().subspan(dataBytesOffset, numDataBytesInBlock),
dataBytes);
DataVector<uint8_t> ecBytes = GenerateECBytes(dataBytes, numEcBytesInBlock);
- if (ecBytes.empty())
+ if (ecBytes.empty()) {
return false;
+ }
maxNumDataBytes = std::max(maxNumDataBytes, dataBytes.size());
maxNumEcBytes = std::max(maxNumEcBytes, ecBytes.size());
@@ -335,21 +357,24 @@
blocks[i].ecc = std::move(ecBytes);
dataBytesOffset += numDataBytesInBlock;
}
- if (numDataBytes != dataBytesOffset)
+ if (numDataBytes != dataBytesOffset) {
return false;
+ }
for (size_t x = 0; x < maxNumDataBytes; x++) {
for (size_t j = 0; j < blocks.size(); j++) {
const DataVector<uint8_t>& dataBytes = blocks[j].data;
- if (x < dataBytes.size())
+ if (x < dataBytes.size()) {
result->AppendBits(dataBytes[x], 8);
+ }
}
}
for (size_t y = 0; y < maxNumEcBytes; y++) {
for (size_t l = 0; l < blocks.size(); l++) {
const DataVector<uint8_t>& ecBytes = blocks[l].ecc;
- if (y < ecBytes.size())
+ if (y < ecBytes.size()) {
result->AppendBits(ecBytes[y], 8);
+ }
}
}
return static_cast<size_t>(numTotalBytes) == result->sizeInBytes();
@@ -376,11 +401,13 @@
ByteString utf8Data = FX_UTF8Encode(content);
CBC_QRCoderMode* mode = ChooseMode(utf8Data);
CBC_QRCoderBitVector dataBits;
- if (!AppendBytes(utf8Data, mode, &dataBits))
+ if (!AppendBytes(utf8Data, mode, &dataBits)) {
return false;
+ }
int32_t numInputBytes = dataBits.sizeInBytes();
- if (!InitQRCode(numInputBytes, ecLevel, qrCode))
+ if (!InitQRCode(numInputBytes, ecLevel, qrCode)) {
return false;
+ }
CBC_QRCoderBitVector headerAndDataBits;
AppendModeInfo(mode, &headerAndDataBits);
int32_t numLetters = mode == CBC_QRCoderMode::sBYTE ? dataBits.sizeInBytes()
@@ -390,8 +417,9 @@
return false;
}
headerAndDataBits.AppendBitVector(&dataBits);
- if (!TerminateBits(qrCode->GetNumDataBytes(), &headerAndDataBits))
+ if (!TerminateBits(qrCode->GetNumDataBytes(), &headerAndDataBits)) {
return false;
+ }
CBC_QRCoderBitVector finalBits;
if (!InterleaveWithECBytes(&headerAndDataBits, qrCode->GetNumTotalBytes(),
qrCode->GetNumDataBytes(),
@@ -403,8 +431,9 @@
qrCode->GetMatrixWidth(), qrCode->GetMatrixWidth());
std::optional<int32_t> maskPattern = ChooseMaskPattern(
&finalBits, qrCode->GetECLevel(), qrCode->GetVersion(), matrix.get());
- if (!maskPattern.has_value())
+ if (!maskPattern.has_value()) {
return false;
+ }
qrCode->SetMaskPattern(maskPattern.value());
if (!CBC_QRCoderMatrixUtil::BuildMatrix(
diff --git a/fxbarcode/qrcode/BC_QRCoderMaskUtil.cpp b/fxbarcode/qrcode/BC_QRCoderMaskUtil.cpp
index a7695be..94bcf76 100644
--- a/fxbarcode/qrcode/BC_QRCoderMaskUtil.cpp
+++ b/fxbarcode/qrcode/BC_QRCoderMaskUtil.cpp
@@ -152,8 +152,9 @@
size_t height = matrix->GetHeight();
for (size_t y = 0; y < height; ++y) {
for (size_t x = 0; x < width; ++x) {
- if (array[y * width + x] == 1)
+ if (array[y * width + x] == 1) {
numDarkCells += 1;
+ }
}
}
size_t numTotalCells = matrix->GetHeight() * matrix->GetWidth();
diff --git a/fxbarcode/qrcode/BC_QRCoderMatrixUtil.cpp b/fxbarcode/qrcode/BC_QRCoderMatrixUtil.cpp
index 1d3d6a1..0fe6228 100644
--- a/fxbarcode/qrcode/BC_QRCoderMatrixUtil.cpp
+++ b/fxbarcode/qrcode/BC_QRCoderMatrixUtil.cpp
@@ -132,8 +132,9 @@
int32_t x = matrix->GetWidth() - 1;
int32_t y = matrix->GetHeight() - 1;
while (x > 0) {
- if (x == 6)
+ if (x == 6) {
x -= 1;
+ }
while (y >= 0 && y < static_cast<int32_t>(matrix->GetHeight())) {
if (y == 6) {
@@ -153,8 +154,9 @@
bit = 0;
}
DCHECK(CBC_QRCoder::IsValidMaskPattern(maskPattern));
- if (CBC_QRCoderMaskUtil::GetDataMaskBit(maskPattern, xx, y))
+ if (CBC_QRCoderMaskUtil::GetDataMaskBit(maskPattern, xx, y)) {
bit ^= 0x01;
+ }
matrix->Set(xx, y, bit);
}
y += direction;
@@ -178,8 +180,9 @@
bool MakeTypeInfoBits(const CBC_QRCoderErrorCorrectionLevel* ecLevel,
int32_t maskPattern,
CBC_QRCoderBitVector* bits) {
- if (!CBC_QRCoder::IsValidMaskPattern(maskPattern))
+ if (!CBC_QRCoder::IsValidMaskPattern(maskPattern)) {
return false;
+ }
int32_t typeInfo = (ecLevel->GetBits() << 3) | maskPattern;
bits->AppendBits(typeInfo, 5);
@@ -187,8 +190,9 @@
bits->AppendBits(bchCode, 10);
CBC_QRCoderBitVector maskBits;
maskBits.AppendBits(TYPE_INFO_MASK_PATTERN, 15);
- if (!bits->XOR(&maskBits))
+ if (!bits->XOR(&maskBits)) {
return false;
+ }
DCHECK_EQ(bits->Size(), 15);
return true;
@@ -205,8 +209,9 @@
int32_t maskPattern,
CBC_CommonByteMatrix* matrix) {
CBC_QRCoderBitVector typeInfoBits;
- if (!MakeTypeInfoBits(ecLevel, maskPattern, &typeInfoBits))
+ if (!MakeTypeInfoBits(ecLevel, maskPattern, &typeInfoBits)) {
return false;
+ }
for (size_t i = 0; i < typeInfoBits.Size(); i++) {
int32_t bit = typeInfoBits.At(typeInfoBits.Size() - 1 - i);
@@ -227,8 +232,9 @@
}
void MaybeEmbedVersionInfo(int32_t version, CBC_CommonByteMatrix* matrix) {
- if (version < 7)
+ if (version < 7) {
return;
+ }
CBC_QRCoderBitVector versionInfoBits;
MakeVersionInfoBits(version, &versionInfoBits);
@@ -246,24 +252,29 @@
bool EmbedTimingPatterns(CBC_CommonByteMatrix* matrix) {
for (size_t i = 8; i + 8 < matrix->GetWidth(); i++) {
const uint8_t bit = static_cast<uint8_t>((i + 1) % 2);
- if (!IsValidValue(matrix->Get(i, 6)))
+ if (!IsValidValue(matrix->Get(i, 6))) {
return false;
+ }
- if (IsEmpty(matrix->Get(i, 6)))
+ if (IsEmpty(matrix->Get(i, 6))) {
matrix->Set(i, 6, bit);
+ }
- if (!IsValidValue(matrix->Get(6, i)))
+ if (!IsValidValue(matrix->Get(6, i))) {
return false;
+ }
- if (IsEmpty(matrix->Get(6, i)))
+ if (IsEmpty(matrix->Get(6, i))) {
matrix->Set(6, i, bit);
+ }
}
return true;
}
bool EmbedDarkDotAtLeftBottomCorner(CBC_CommonByteMatrix* matrix) {
- if (matrix->Get(8, matrix->GetHeight() - 8) == 0)
+ if (matrix->Get(8, matrix->GetHeight() - 8) == 0) {
return false;
+ }
matrix->Set(8, matrix->GetHeight() - 8, 1);
return true;
@@ -273,8 +284,9 @@
int32_t yStart,
CBC_CommonByteMatrix* matrix) {
for (int32_t x = 0; x < 8; x++) {
- if (!IsEmpty(matrix->Get(xStart + x, yStart)))
+ if (!IsEmpty(matrix->Get(xStart + x, yStart))) {
return false;
+ }
matrix->Set(xStart + x, yStart, 0);
}
@@ -285,8 +297,9 @@
int32_t yStart,
CBC_CommonByteMatrix* matrix) {
for (int32_t y = 0; y < 7; y++) {
- if (!IsEmpty(matrix->Get(xStart, yStart + y)))
+ if (!IsEmpty(matrix->Get(xStart, yStart + y))) {
return false;
+ }
matrix->Set(xStart, yStart + y, 0);
}
@@ -313,8 +326,9 @@
CBC_CommonByteMatrix* matrix) {
for (int32_t y = 0; y < 7; y++) {
for (int32_t x = 0; x < 7; x++) {
- if (!IsEmpty(matrix->Get(xStart + x, yStart + y)))
+ if (!IsEmpty(matrix->Get(xStart + x, yStart + y))) {
return false;
+ }
matrix->Set(xStart + x, yStart + y, kPositionDetectionPatternTable[y][x]);
}
@@ -324,16 +338,22 @@
bool EmbedPositionDetectionPatternsAndSeparators(CBC_CommonByteMatrix* matrix) {
static constexpr int32_t pdpWidth = 7;
- if (!EmbedPositionDetectionPattern(0, 0, matrix))
+ if (!EmbedPositionDetectionPattern(0, 0, matrix)) {
return false;
- if (!EmbedPositionDetectionPattern(matrix->GetWidth() - pdpWidth, 0, matrix))
+ }
+ if (!EmbedPositionDetectionPattern(matrix->GetWidth() - pdpWidth, 0,
+ matrix)) {
return false;
- if (!EmbedPositionDetectionPattern(0, matrix->GetWidth() - pdpWidth, matrix))
+ }
+ if (!EmbedPositionDetectionPattern(0, matrix->GetWidth() - pdpWidth,
+ matrix)) {
return false;
+ }
static constexpr int32_t hspWidth = 8;
- if (!EmbedHorizontalSeparationPattern(0, hspWidth - 1, matrix))
+ if (!EmbedHorizontalSeparationPattern(0, hspWidth - 1, matrix)) {
return false;
+ }
if (!EmbedHorizontalSeparationPattern(matrix->GetWidth() - hspWidth,
hspWidth - 1, matrix)) {
return false;
@@ -344,8 +364,9 @@
}
static constexpr int32_t vspSize = 7;
- if (!EmbedVerticalSeparationPattern(vspSize, 0, matrix))
+ if (!EmbedVerticalSeparationPattern(vspSize, 0, matrix)) {
return false;
+ }
if (!EmbedVerticalSeparationPattern(matrix->GetHeight() - vspSize - 1, 0,
matrix)) {
return false;
@@ -359,8 +380,9 @@
bool MaybeEmbedPositionAdjustmentPatterns(int32_t version,
CBC_CommonByteMatrix* matrix) {
- if (version < 2)
+ if (version < 2) {
return true;
+ }
const size_t index = version - 2;
if (index >= std::size(kPositionCoordinatePatternTable)) {
@@ -370,16 +392,19 @@
const auto& coordinates = kPositionCoordinatePatternTable[index];
for (size_t i = 0; i < kNumCoordinate; i++) {
const int32_t y = coordinates[i];
- if (y == 0)
+ if (y == 0) {
break;
+ }
for (size_t j = 0; j < kNumCoordinate; j++) {
const int32_t x = coordinates[j];
- if (x == 0)
+ if (x == 0) {
break;
+ }
if (IsEmpty(matrix->Get(x, y))) {
- if (!EmbedPositionAdjustmentPattern(x - 2, y - 2, matrix))
+ if (!EmbedPositionAdjustmentPattern(x - 2, y - 2, matrix)) {
return false;
+ }
}
}
}
@@ -387,14 +412,18 @@
}
bool EmbedBasicPatterns(int32_t version, CBC_CommonByteMatrix* matrix) {
- if (!EmbedPositionDetectionPatternsAndSeparators(matrix))
+ if (!EmbedPositionDetectionPatternsAndSeparators(matrix)) {
return false;
- if (!EmbedDarkDotAtLeftBottomCorner(matrix))
+ }
+ if (!EmbedDarkDotAtLeftBottomCorner(matrix)) {
return false;
- if (!MaybeEmbedPositionAdjustmentPatterns(version, matrix))
+ }
+ if (!MaybeEmbedPositionAdjustmentPatterns(version, matrix)) {
return false;
- if (!EmbedTimingPatterns(matrix))
+ }
+ if (!EmbedTimingPatterns(matrix)) {
return false;
+ }
return true;
}
@@ -406,15 +435,18 @@
int32_t version,
int32_t maskPattern,
CBC_CommonByteMatrix* matrix) {
- if (!dataBits || !matrix)
+ if (!dataBits || !matrix) {
return false;
+ }
matrix->Fill(0xff);
- if (!EmbedBasicPatterns(version, matrix))
+ if (!EmbedBasicPatterns(version, matrix)) {
return false;
- if (!EmbedTypeInfo(ecLevel, maskPattern, matrix))
+ }
+ if (!EmbedTypeInfo(ecLevel, maskPattern, matrix)) {
return false;
+ }
MaybeEmbedVersionInfo(version, matrix);
return EmbedDataBits(dataBits, maskPattern, matrix);
diff --git a/fxbarcode/qrcode/BC_QRCoderMode.cpp b/fxbarcode/qrcode/BC_QRCoderMode.cpp
index 4a28d5f..d60e676 100644
--- a/fxbarcode/qrcode/BC_QRCoderMode.cpp
+++ b/fxbarcode/qrcode/BC_QRCoderMode.cpp
@@ -63,12 +63,13 @@
}
int32_t offset;
- if (number <= 9)
+ if (number <= 9) {
offset = 0;
- else if (number <= 26)
+ } else if (number <= 26) {
offset = 1;
- else
+ } else {
offset = 2;
+ }
int32_t result = character_count_bits_for_versions_[offset];
DCHECK(result != 0);
diff --git a/fxbarcode/qrcode/BC_QRCoderVersion.cpp b/fxbarcode/qrcode/BC_QRCoderVersion.cpp
index 6f79061..f51569b 100644
--- a/fxbarcode/qrcode/BC_QRCoderVersion.cpp
+++ b/fxbarcode/qrcode/BC_QRCoderVersion.cpp
@@ -67,8 +67,9 @@
std::make_unique<CBC_QRCoderVersion>(i + 1, kQRCoderECBDataTable[i]));
}
}
- if (versionNumber < 1 || versionNumber > kMaxVersion)
+ if (versionNumber < 1 || versionNumber > kMaxVersion) {
return nullptr;
+ }
return (*g_VERSION)[versionNumber - 1].get();
}