Remove dead dimensions code in fxbarcode.

Remove more exceptions.

Change-Id: I3b8b8b9837b0010b1e0060ddd56e93c78f9f0fb5
Reviewed-on: https://pdfium-review.googlesource.com/4410
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/BUILD.gn b/BUILD.gn
index 8cdc903..c4cc895 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -1224,8 +1224,6 @@
 
   static_library("fxbarcode") {
     sources = [
-      "fxbarcode/BC_Dimension.cpp",
-      "fxbarcode/BC_Dimension.h",
       "fxbarcode/BC_Library.cpp",
       "fxbarcode/BC_Library.h",
       "fxbarcode/BC_TwoDimWriter.cpp",
diff --git a/fxbarcode/BC_Dimension.cpp b/fxbarcode/BC_Dimension.cpp
deleted file mode 100644
index 03cfa7e..0000000
--- a/fxbarcode/BC_Dimension.cpp
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-// Original code is licensed as follows:
-/*
- * Copyright 2012 ZXing authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "fxbarcode/BC_Dimension.h"
-#include "fxbarcode/datamatrix/BC_Encoder.h"
-
-CBC_Dimension::CBC_Dimension() {}
-CBC_Dimension::CBC_Dimension(int32_t width, int32_t height, int32_t& e) {
-  if (width < 0 || height < 0) {
-    e = BCExceptionHeightAndWidthMustBeAtLeast1;
-  }
-  m_width = width;
-  m_height = height;
-}
-CBC_Dimension::~CBC_Dimension() {}
-int32_t CBC_Dimension::getWidth() {
-  return m_width;
-}
-int32_t CBC_Dimension::getHeight() {
-  return m_height;
-}
-int32_t CBC_Dimension::hashCode() {
-  return m_width * 32713 + m_height;
-}
-CFX_WideString CBC_Dimension::toString() {
-  return (wchar_t)(m_width + (wchar_t)'x' + m_height);
-}
diff --git a/fxbarcode/BC_Dimension.h b/fxbarcode/BC_Dimension.h
deleted file mode 100644
index fc24bf9..0000000
--- a/fxbarcode/BC_Dimension.h
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef FXBARCODE_BC_DIMENSION_H_
-#define FXBARCODE_BC_DIMENSION_H_
-
-#include <cstdint>
-
-#include "core/fxcrt/fx_string.h"
-
-class CBC_Dimension {
- public:
-  CBC_Dimension();
-  CBC_Dimension(int32_t width, int32_t height, int32_t& e);
-  virtual ~CBC_Dimension();
-  int32_t getWidth();
-  int32_t getHeight();
-  int32_t hashCode();
-  CFX_WideString toString();
-
- private:
-  int32_t m_width;
-  int32_t m_height;
-};
-
-#endif  // FXBARCODE_BC_DIMENSION_H_
diff --git a/fxbarcode/datamatrix/BC_ASCIIEncoder.cpp b/fxbarcode/datamatrix/BC_ASCIIEncoder.cpp
index 2d7b9d7..7b277fe 100644
--- a/fxbarcode/datamatrix/BC_ASCIIEncoder.cpp
+++ b/fxbarcode/datamatrix/BC_ASCIIEncoder.cpp
@@ -20,13 +20,14 @@
  * limitations under the License.
  */
 
-#include "fxbarcode/BC_Dimension.h"
 #include "fxbarcode/datamatrix/BC_ASCIIEncoder.h"
+
 #include "fxbarcode/datamatrix/BC_Encoder.h"
 #include "fxbarcode/datamatrix/BC_EncoderContext.h"
 #include "fxbarcode/datamatrix/BC_HighLevelEncoder.h"
 #include "fxbarcode/datamatrix/BC_SymbolInfo.h"
 #include "fxbarcode/datamatrix/BC_SymbolShapeHint.h"
+#include "fxbarcode/utils.h"
 
 CBC_ASCIIEncoder::CBC_ASCIIEncoder() {}
 CBC_ASCIIEncoder::~CBC_ASCIIEncoder() {}
diff --git a/fxbarcode/datamatrix/BC_Base256Encoder.cpp b/fxbarcode/datamatrix/BC_Base256Encoder.cpp
index dd49c8e..a360f63 100644
--- a/fxbarcode/datamatrix/BC_Base256Encoder.cpp
+++ b/fxbarcode/datamatrix/BC_Base256Encoder.cpp
@@ -20,13 +20,14 @@
  * limitations under the License.
  */
 
-#include "fxbarcode/BC_Dimension.h"
 #include "fxbarcode/datamatrix/BC_Base256Encoder.h"
+
 #include "fxbarcode/datamatrix/BC_Encoder.h"
 #include "fxbarcode/datamatrix/BC_EncoderContext.h"
 #include "fxbarcode/datamatrix/BC_HighLevelEncoder.h"
 #include "fxbarcode/datamatrix/BC_SymbolInfo.h"
 #include "fxbarcode/datamatrix/BC_SymbolShapeHint.h"
+#include "fxbarcode/utils.h"
 
 CBC_Base256Encoder::CBC_Base256Encoder() {}
 CBC_Base256Encoder::~CBC_Base256Encoder() {}
diff --git a/fxbarcode/datamatrix/BC_C40Encoder.cpp b/fxbarcode/datamatrix/BC_C40Encoder.cpp
index 7c3f4e7..e8aa679 100644
--- a/fxbarcode/datamatrix/BC_C40Encoder.cpp
+++ b/fxbarcode/datamatrix/BC_C40Encoder.cpp
@@ -20,14 +20,30 @@
  * limitations under the License.
  */
 
-#include "fxbarcode/BC_Dimension.h"
-#include "fxbarcode/common/BC_CommonBitMatrix.h"
 #include "fxbarcode/datamatrix/BC_C40Encoder.h"
+
+#include "fxbarcode/common/BC_CommonBitMatrix.h"
 #include "fxbarcode/datamatrix/BC_Encoder.h"
 #include "fxbarcode/datamatrix/BC_EncoderContext.h"
 #include "fxbarcode/datamatrix/BC_HighLevelEncoder.h"
 #include "fxbarcode/datamatrix/BC_SymbolInfo.h"
 #include "fxbarcode/datamatrix/BC_SymbolShapeHint.h"
+#include "fxbarcode/utils.h"
+
+namespace {
+
+CFX_WideString EncodeToCodewords(const CFX_WideString& sb, int32_t startPos) {
+  wchar_t c1 = sb.GetAt(startPos);
+  wchar_t c2 = sb.GetAt(startPos + 1);
+  wchar_t c3 = sb.GetAt(startPos + 2);
+  int32_t v = (1600 * c1) + (40 * c2) + c3 + 1;
+  wchar_t cw[2];
+  cw[0] = static_cast<wchar_t>(v / 256);
+  cw[1] = static_cast<wchar_t>(v % 256);
+  return CFX_WideString(cw);
+}
+
+}  // namespace
 
 CBC_C40Encoder::CBC_C40Encoder() {}
 CBC_C40Encoder::~CBC_C40Encoder() {}
@@ -85,7 +101,7 @@
 }
 void CBC_C40Encoder::writeNextTriplet(CBC_EncoderContext& context,
                                       CFX_WideString& buffer) {
-  context.writeCodewords(encodeToCodewords(buffer, 0));
+  context.writeCodewords(EncodeToCodewords(buffer, 0));
   buffer.Delete(0, 3);
 }
 void CBC_C40Encoder::handleEOD(CBC_EncoderContext& context,
@@ -186,15 +202,3 @@
   context.resetSymbolInfo();
   return lastCharSize;
 }
-CFX_WideString CBC_C40Encoder::encodeToCodewords(CFX_WideString sb,
-                                                 int32_t startPos) {
-  wchar_t c1 = sb.GetAt(startPos);
-  wchar_t c2 = sb.GetAt(startPos + 1);
-  wchar_t c3 = sb.GetAt(startPos + 2);
-  int32_t v = (1600 * c1) + (40 * c2) + c3 + 1;
-  wchar_t cw1 = (wchar_t)(v / 256);
-  wchar_t cw2 = (wchar_t)(v % 256);
-  CFX_WideString b1(cw1);
-  CFX_WideString b2(cw2);
-  return b1 + b2;
-}
diff --git a/fxbarcode/datamatrix/BC_C40Encoder.h b/fxbarcode/datamatrix/BC_C40Encoder.h
index 2174049..ad8669d 100644
--- a/fxbarcode/datamatrix/BC_C40Encoder.h
+++ b/fxbarcode/datamatrix/BC_C40Encoder.h
@@ -9,6 +9,8 @@
 
 #include "fxbarcode/datamatrix/BC_Encoder.h"
 
+class CFX_WideString;
+
 class CBC_C40Encoder : public CBC_Encoder {
  public:
   CBC_C40Encoder();
@@ -32,7 +34,6 @@
                                 CFX_WideString& removed,
                                 int32_t lastCharSize,
                                 int32_t& e);
-  static CFX_WideString encodeToCodewords(CFX_WideString sb, int32_t startPos);
 };
 
 #endif  // FXBARCODE_DATAMATRIX_BC_C40ENCODER_H_
diff --git a/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp b/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp
index 54b7312..f45c338 100644
--- a/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp
+++ b/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp
@@ -24,7 +24,6 @@
 
 #include <memory>
 
-#include "fxbarcode/BC_Dimension.h"
 #include "fxbarcode/BC_TwoDimWriter.h"
 #include "fxbarcode/BC_UtilCodingConvert.h"
 #include "fxbarcode/BC_Writer.h"
@@ -121,16 +120,14 @@
 
   CBC_SymbolShapeHint::SymbolShapeHint shape =
       CBC_SymbolShapeHint::FORCE_SQUARE;
-  CBC_Dimension* minSize = nullptr;
-  CBC_Dimension* maxSize = nullptr;
   CFX_WideString ecLevel;
   int32_t e = BCExceptionNO;
-  CFX_WideString encoded = CBC_HighLevelEncoder::encodeHighLevel(
-      contents, ecLevel, shape, minSize, maxSize, e);
+  CFX_WideString encoded =
+      CBC_HighLevelEncoder::encodeHighLevel(contents, ecLevel, shape, e);
   if (e != BCExceptionNO)
     return nullptr;
-  CBC_SymbolInfo* symbolInfo = CBC_SymbolInfo::lookup(
-      encoded.GetLength(), shape, minSize, maxSize, true, e);
+  CBC_SymbolInfo* symbolInfo =
+      CBC_SymbolInfo::lookup(encoded.GetLength(), shape, true, e);
   if (e != BCExceptionNO)
     return nullptr;
   CFX_WideString codewords =
diff --git a/fxbarcode/datamatrix/BC_EdifactEncoder.cpp b/fxbarcode/datamatrix/BC_EdifactEncoder.cpp
index 954dcbc..9231b1e 100644
--- a/fxbarcode/datamatrix/BC_EdifactEncoder.cpp
+++ b/fxbarcode/datamatrix/BC_EdifactEncoder.cpp
@@ -22,34 +22,127 @@
 
 #include "fxbarcode/datamatrix/BC_EdifactEncoder.h"
 
-#include "fxbarcode/BC_Dimension.h"
+#include <algorithm>
+
 #include "fxbarcode/common/BC_CommonBitMatrix.h"
 #include "fxbarcode/datamatrix/BC_Encoder.h"
 #include "fxbarcode/datamatrix/BC_EncoderContext.h"
 #include "fxbarcode/datamatrix/BC_HighLevelEncoder.h"
 #include "fxbarcode/datamatrix/BC_SymbolInfo.h"
 #include "fxbarcode/datamatrix/BC_SymbolShapeHint.h"
+#include "fxbarcode/utils.h"
+
+namespace {
+
+CFX_WideString EncodeToCodewords(const CFX_WideString& sb, int32_t startPos) {
+  int32_t len = sb.GetLength() - startPos;
+  if (len == 0)
+    return CFX_WideString();
+
+  wchar_t c1 = sb.GetAt(startPos);
+  wchar_t c2 = len >= 2 ? sb.GetAt(startPos + 1) : 0;
+  wchar_t c3 = len >= 3 ? sb.GetAt(startPos + 2) : 0;
+  wchar_t c4 = len >= 4 ? sb.GetAt(startPos + 3) : 0;
+  int32_t v = (c1 << 18) + (c2 << 12) + (c3 << 6) + c4;
+  constexpr int32_t kBuflen = 3;
+  wchar_t cw[kBuflen];
+  cw[0] = static_cast<wchar_t>((v >> 16) & 255);
+  cw[1] = static_cast<wchar_t>((v >> 8) & 255);
+  cw[2] = static_cast<wchar_t>(v & 255);
+  return CFX_WideString(cw, std::min(len, kBuflen));
+}
+
+bool HandleEOD(CBC_EncoderContext* context, const CFX_WideString& buffer) {
+  int32_t count = buffer.GetLength();
+  if (count == 0)
+    return true;
+  if (count > 4)
+    return false;
+
+  if (count == 1) {
+    int32_t e = BCExceptionNO;
+    context->updateSymbolInfo(e);
+    if (e != BCExceptionNO)
+      return false;
+
+    int32_t available =
+        context->m_symbolInfo->m_dataCapacity - context->getCodewordCount();
+    int32_t remaining = context->getRemainingCharacters();
+    if (remaining == 0 && available <= 2)
+      return true;
+  }
+
+  int32_t restChars = count - 1;
+  CFX_WideString encoded = EncodeToCodewords(buffer, 0);
+  if (encoded.IsEmpty())
+    return false;
+
+  bool endOfSymbolReached = !context->hasMoreCharacters();
+  bool restInAscii = endOfSymbolReached && restChars <= 2;
+  if (restChars <= 2) {
+    int32_t e = BCExceptionNO;
+    context->updateSymbolInfo(context->getCodewordCount() + restChars, e);
+    if (e != BCExceptionNO)
+      return false;
+
+    int32_t available =
+        context->m_symbolInfo->m_dataCapacity - context->getCodewordCount();
+    if (available >= 3) {
+      restInAscii = false;
+      context->updateSymbolInfo(
+          context->getCodewordCount() + encoded.GetLength(), e);
+      if (e != BCExceptionNO)
+        return false;
+    }
+  }
+
+  if (restInAscii) {
+    context->resetSymbolInfo();
+    context->m_pos -= restChars;
+  } else {
+    context->writeCodewords(encoded);
+  }
+  context->signalEncoderChange(ASCII_ENCODATION);
+  return true;
+}
+
+void encodeChar(wchar_t c, CFX_WideString* sb, int32_t& e) {
+  if (c >= ' ' && c <= '?') {
+    *sb += c;
+  } else if (c >= '@' && c <= '^') {
+    *sb += (wchar_t)(c - 64);
+  } else {
+    e = BCExceptionIllegalArgument;
+  }
+}
+
+}  // namespace
 
 CBC_EdifactEncoder::CBC_EdifactEncoder() {}
+
 CBC_EdifactEncoder::~CBC_EdifactEncoder() {}
+
 int32_t CBC_EdifactEncoder::getEncodingMode() {
   return EDIFACT_ENCODATION;
 }
+
 void CBC_EdifactEncoder::Encode(CBC_EncoderContext& context, int32_t& e) {
   CFX_WideString buffer;
   while (context.hasMoreCharacters()) {
     wchar_t c = context.getCurrentChar();
-    encodeChar(c, buffer, e);
+    encodeChar(c, &buffer, e);
     if (e != BCExceptionNO) {
       return;
     }
     context.m_pos++;
     int32_t count = buffer.GetLength();
     if (count >= 4) {
-      context.writeCodewords(encodeToCodewords(buffer, 0, e));
-      if (e != BCExceptionNO) {
+      CFX_WideString encoded = EncodeToCodewords(buffer, 0);
+      if (encoded.IsEmpty()) {
+        e = BCExceptionGeneric;
         return;
       }
+      context.writeCodewords(encoded);
       buffer.Delete(0, 4);
       int32_t newMode = CBC_HighLevelEncoder::lookAheadTest(
           context.m_msg, context.m_pos, getEncodingMode());
@@ -59,97 +152,7 @@
       }
     }
   }
-  buffer += (wchar_t)31;
-  handleEOD(context, buffer, e);
-}
-void CBC_EdifactEncoder::handleEOD(CBC_EncoderContext& context,
-                                   CFX_WideString buffer,
-                                   int32_t& e) {
-  int32_t count = buffer.GetLength();
-  if (count == 0) {
-    return;
-  }
-  if (count == 1) {
-    context.updateSymbolInfo(e);
-    if (e != BCExceptionNO) {
-      return;
-    }
-    int32_t available =
-        context.m_symbolInfo->m_dataCapacity - context.getCodewordCount();
-    int32_t remaining = context.getRemainingCharacters();
-    if (remaining == 0 && available <= 2) {
-      return;
-    }
-  }
-  if (count > 4) {
-    e = BCExceptionIllegalStateCountMustNotExceed4;
-    return;
-  }
-  int32_t restChars = count - 1;
-  CFX_WideString encoded = encodeToCodewords(buffer, 0, e);
-  if (e != BCExceptionNO) {
-    return;
-  }
-  bool endOfSymbolReached = !context.hasMoreCharacters();
-  bool restInAscii = endOfSymbolReached && restChars <= 2;
-  if (restChars <= 2) {
-    context.updateSymbolInfo(context.getCodewordCount() + restChars, e);
-    if (e != BCExceptionNO) {
-      return;
-    }
-    int32_t available =
-        context.m_symbolInfo->m_dataCapacity - context.getCodewordCount();
-    if (available >= 3) {
-      restInAscii = false;
-      context.updateSymbolInfo(context.getCodewordCount() + encoded.GetLength(),
-                               e);
-      if (e != BCExceptionNO) {
-        return;
-      }
-    }
-  }
-  if (restInAscii) {
-    context.resetSymbolInfo();
-    context.m_pos -= restChars;
-  } else {
-    context.writeCodewords(encoded);
-  }
-  context.signalEncoderChange(ASCII_ENCODATION);
-}
-
-void CBC_EdifactEncoder::encodeChar(wchar_t c, CFX_WideString& sb, int32_t& e) {
-  if (c >= ' ' && c <= '?') {
-    sb += c;
-  } else if (c >= '@' && c <= '^') {
-    sb += (wchar_t)(c - 64);
-  } else {
-    e = BCExceptionIllegalArgument;
-  }
-}
-
-CFX_WideString CBC_EdifactEncoder::encodeToCodewords(CFX_WideString sb,
-                                                     int32_t startPos,
-                                                     int32_t& e) {
-  int32_t len = sb.GetLength() - startPos;
-  if (len == 0) {
-    e = BCExceptionNoContents;
-    return CFX_WideString();
-  }
-  wchar_t c1 = sb.GetAt(startPos);
-  wchar_t c2 = len >= 2 ? sb.GetAt(startPos + 1) : 0;
-  wchar_t c3 = len >= 3 ? sb.GetAt(startPos + 2) : 0;
-  wchar_t c4 = len >= 4 ? sb.GetAt(startPos + 3) : 0;
-  int32_t v = (c1 << 18) + (c2 << 12) + (c3 << 6) + c4;
-  wchar_t cw1 = (wchar_t)((v >> 16) & 255);
-  wchar_t cw2 = (wchar_t)((v >> 8) & 255);
-  wchar_t cw3 = (wchar_t)(v & 255);
-  CFX_WideString res;
-  res += cw1;
-  if (len >= 2) {
-    res += cw2;
-  }
-  if (len >= 3) {
-    res += cw3;
-  }
-  return res;
+  buffer += static_cast<wchar_t>(31);
+  if (!HandleEOD(&context, buffer))
+    e = BCExceptionGeneric;
 }
diff --git a/fxbarcode/datamatrix/BC_EdifactEncoder.h b/fxbarcode/datamatrix/BC_EdifactEncoder.h
index 6fe0934..eb59222 100644
--- a/fxbarcode/datamatrix/BC_EdifactEncoder.h
+++ b/fxbarcode/datamatrix/BC_EdifactEncoder.h
@@ -17,15 +17,6 @@
   // CBC_Encoder
   int32_t getEncodingMode() override;
   void Encode(CBC_EncoderContext& context, int32_t& e) override;
-
- private:
-  static void handleEOD(CBC_EncoderContext& context,
-                        CFX_WideString buffer,
-                        int32_t& e);
-  static void encodeChar(wchar_t c, CFX_WideString& sb, int32_t& e);
-  static CFX_WideString encodeToCodewords(CFX_WideString sb,
-                                          int32_t startPos,
-                                          int32_t& e);
 };
 
 #endif  // FXBARCODE_DATAMATRIX_BC_EDIFACTENCODER_H_
diff --git a/fxbarcode/datamatrix/BC_Encoder.h b/fxbarcode/datamatrix/BC_Encoder.h
index 40d491c..be1730f 100644
--- a/fxbarcode/datamatrix/BC_Encoder.h
+++ b/fxbarcode/datamatrix/BC_Encoder.h
@@ -7,7 +7,7 @@
 #ifndef FXBARCODE_DATAMATRIX_BC_ENCODER_H_
 #define FXBARCODE_DATAMATRIX_BC_ENCODER_H_
 
-#include "fxbarcode/utils.h"
+#include <stdint.h>
 
 class CBC_EncoderContext;
 
diff --git a/fxbarcode/datamatrix/BC_EncoderContext.cpp b/fxbarcode/datamatrix/BC_EncoderContext.cpp
index 8fe5bf5..0411d03 100644
--- a/fxbarcode/datamatrix/BC_EncoderContext.cpp
+++ b/fxbarcode/datamatrix/BC_EncoderContext.cpp
@@ -20,16 +20,17 @@
  * limitations under the License.
  */
 
-#include "fxbarcode/BC_Dimension.h"
+#include "fxbarcode/datamatrix/BC_EncoderContext.h"
+
 #include "fxbarcode/BC_UtilCodingConvert.h"
 #include "fxbarcode/common/BC_CommonBitMatrix.h"
 #include "fxbarcode/datamatrix/BC_Encoder.h"
-#include "fxbarcode/datamatrix/BC_EncoderContext.h"
 #include "fxbarcode/datamatrix/BC_SymbolInfo.h"
 #include "fxbarcode/datamatrix/BC_SymbolShapeHint.h"
+#include "fxbarcode/utils.h"
 
-CBC_EncoderContext::CBC_EncoderContext(const CFX_WideString msg,
-                                       CFX_WideString ecLevel,
+CBC_EncoderContext::CBC_EncoderContext(const CFX_WideString& msg,
+                                       const CFX_WideString& ecLevel,
                                        int32_t& e) {
   CFX_ByteString dststr;
   CBC_UtilCodingConvert::UnicodeToUTF8(msg, dststr);
@@ -48,21 +49,11 @@
   m_pos = 0;
   m_symbolInfo = nullptr;
   m_skipAtEnd = 0;
-  m_maxSize = nullptr;
-  m_minSize = nullptr;
 }
 CBC_EncoderContext::~CBC_EncoderContext() {}
 void CBC_EncoderContext::setSymbolShape(SymbolShapeHint shape) {
   m_shape = shape;
 }
-void CBC_EncoderContext::setSizeConstraints(CBC_Dimension* minSize,
-                                            CBC_Dimension* maxSize) {
-  m_maxSize = maxSize;
-  m_minSize = minSize;
-}
-CFX_WideString CBC_EncoderContext::getMessage() {
-  return m_msg;
-}
 void CBC_EncoderContext::setSkipAtEnd(int32_t count) {
   m_skipAtEnd = count;
 }
@@ -72,9 +63,11 @@
 wchar_t CBC_EncoderContext::getCurrent() {
   return m_msg.GetAt(m_pos);
 }
-void CBC_EncoderContext::writeCodewords(CFX_WideString codewords) {
+
+void CBC_EncoderContext::writeCodewords(const CFX_WideString& codewords) {
   m_codewords += codewords;
 }
+
 void CBC_EncoderContext::writeCodeword(wchar_t codeword) {
   m_codewords += codeword;
 }
@@ -98,8 +91,7 @@
 }
 void CBC_EncoderContext::updateSymbolInfo(int32_t len, int32_t& e) {
   if (!m_symbolInfo || len > m_symbolInfo->m_dataCapacity) {
-    m_symbolInfo =
-        CBC_SymbolInfo::lookup(len, m_shape, m_minSize, m_maxSize, true, e);
+    m_symbolInfo = CBC_SymbolInfo::lookup(len, m_shape, true, e);
     if (e != BCExceptionNO)
       return;
   }
diff --git a/fxbarcode/datamatrix/BC_EncoderContext.h b/fxbarcode/datamatrix/BC_EncoderContext.h
index 6be8241..e225933 100644
--- a/fxbarcode/datamatrix/BC_EncoderContext.h
+++ b/fxbarcode/datamatrix/BC_EncoderContext.h
@@ -7,25 +7,23 @@
 #ifndef FXBARCODE_DATAMATRIX_BC_ENCODERCONTEXT_H_
 #define FXBARCODE_DATAMATRIX_BC_ENCODERCONTEXT_H_
 
+#include "core/fxcrt/cfx_widestring.h"
 #include "fxbarcode/datamatrix/BC_SymbolShapeHint.h"
 
 class CBC_SymbolInfo;
-class CBC_Dimension;
 
 class CBC_EncoderContext : public CBC_SymbolShapeHint {
  public:
-  CBC_EncoderContext(const CFX_WideString msg,
-                     CFX_WideString ecLevel,
+  CBC_EncoderContext(const CFX_WideString& msg,
+                     const CFX_WideString& ecLevel,
                      int32_t& e);
   ~CBC_EncoderContext() override;
 
   void setSymbolShape(SymbolShapeHint shape);
-  void setSizeConstraints(CBC_Dimension* minSize, CBC_Dimension* maxSize);
-  CFX_WideString getMessage();
   void setSkipAtEnd(int32_t count);
   wchar_t getCurrentChar();
   wchar_t getCurrent();
-  void writeCodewords(CFX_WideString codewords);
+  void writeCodewords(const CFX_WideString& codewords);
   void writeCodeword(wchar_t codeword);
   int32_t getCodewordCount();
   void signalEncoderChange(int32_t encoding);
@@ -48,8 +46,6 @@
 
  private:
   SymbolShapeHint m_shape;
-  CBC_Dimension* m_minSize;
-  CBC_Dimension* m_maxSize;
   int32_t m_skipAtEnd;
 };
 
diff --git a/fxbarcode/datamatrix/BC_ErrorCorrection.cpp b/fxbarcode/datamatrix/BC_ErrorCorrection.cpp
index 43bdc24..cd2355b 100644
--- a/fxbarcode/datamatrix/BC_ErrorCorrection.cpp
+++ b/fxbarcode/datamatrix/BC_ErrorCorrection.cpp
@@ -20,12 +20,14 @@
  * limitations under the License.
  */
 
+#include "fxbarcode/datamatrix/BC_ErrorCorrection.h"
+
 #include <vector>
 
 #include "fxbarcode/datamatrix/BC_Encoder.h"
-#include "fxbarcode/datamatrix/BC_ErrorCorrection.h"
 #include "fxbarcode/datamatrix/BC_SymbolInfo.h"
 #include "fxbarcode/datamatrix/BC_SymbolShapeHint.h"
+#include "fxbarcode/utils.h"
 
 namespace {
 
diff --git a/fxbarcode/datamatrix/BC_ErrorCorrection.h b/fxbarcode/datamatrix/BC_ErrorCorrection.h
index f09763d..97a2e48 100644
--- a/fxbarcode/datamatrix/BC_ErrorCorrection.h
+++ b/fxbarcode/datamatrix/BC_ErrorCorrection.h
@@ -7,6 +7,8 @@
 #ifndef FXBARCODE_DATAMATRIX_BC_ERRORCORRECTION_H_
 #define FXBARCODE_DATAMATRIX_BC_ERRORCORRECTION_H_
 
+#include "core/fxcrt/cfx_widestring.h"
+
 class CBC_SymbolInfo;
 
 class CBC_ErrorCorrection {
diff --git a/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp b/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp
index f9fb080..cc85c83 100644
--- a/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp
+++ b/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp
@@ -20,11 +20,12 @@
  * limitations under the License.
  */
 
+#include "fxbarcode/datamatrix/BC_HighLevelEncoder.h"
+
 #include <limits>
 #include <memory>
 #include <vector>
 
-#include "fxbarcode/BC_Dimension.h"
 #include "fxbarcode/BC_UtilCodingConvert.h"
 #include "fxbarcode/common/BC_CommonBitMatrix.h"
 #include "fxbarcode/datamatrix/BC_ASCIIEncoder.h"
@@ -33,7 +34,6 @@
 #include "fxbarcode/datamatrix/BC_EdifactEncoder.h"
 #include "fxbarcode/datamatrix/BC_Encoder.h"
 #include "fxbarcode/datamatrix/BC_EncoderContext.h"
-#include "fxbarcode/datamatrix/BC_HighLevelEncoder.h"
 #include "fxbarcode/datamatrix/BC_SymbolInfo.h"
 #include "fxbarcode/datamatrix/BC_SymbolShapeHint.h"
 #include "fxbarcode/datamatrix/BC_TextEncoder.h"
@@ -69,19 +69,16 @@
 CFX_WideString CBC_HighLevelEncoder::encodeHighLevel(CFX_WideString msg,
                                                      CFX_WideString ecLevel,
                                                      int32_t& e) {
-  return encodeHighLevel(msg, ecLevel, FORCE_NONE, nullptr, nullptr, e);
+  return encodeHighLevel(msg, ecLevel, FORCE_NONE, e);
 }
 CFX_WideString CBC_HighLevelEncoder::encodeHighLevel(CFX_WideString msg,
                                                      CFX_WideString ecLevel,
                                                      SymbolShapeHint shape,
-                                                     CBC_Dimension* minSize,
-                                                     CBC_Dimension* maxSize,
                                                      int32_t& e) {
   CBC_EncoderContext context(msg, ecLevel, e);
   if (e != BCExceptionNO)
     return CFX_WideString();
   context.setSymbolShape(shape);
-  context.setSizeConstraints(minSize, maxSize);
   if ((msg.Mid(0, 6) == MACRO_05_HEADER) &&
       (msg.Mid(msg.GetLength() - 1, 1) == MACRO_TRAILER)) {
     context.writeCodeword(MACRO_05);
diff --git a/fxbarcode/datamatrix/BC_HighLevelEncoder.h b/fxbarcode/datamatrix/BC_HighLevelEncoder.h
index 12b8cab..6f0db29 100644
--- a/fxbarcode/datamatrix/BC_HighLevelEncoder.h
+++ b/fxbarcode/datamatrix/BC_HighLevelEncoder.h
@@ -9,6 +9,7 @@
 
 #include <vector>
 
+#include "core/fxcrt/cfx_widestring.h"
 #include "fxbarcode/datamatrix/BC_SymbolShapeHint.h"
 
 #define ASCII_ENCODATION 0
@@ -30,8 +31,6 @@
   static CFX_WideString encodeHighLevel(CFX_WideString msg,
                                         CFX_WideString ecLevel,
                                         SymbolShapeHint shape,
-                                        CBC_Dimension* minSize,
-                                        CBC_Dimension* maxSize,
                                         int32_t& e);
   static int32_t lookAheadTest(CFX_WideString msg,
                                int32_t startpos,
diff --git a/fxbarcode/datamatrix/BC_SymbolInfo.cpp b/fxbarcode/datamatrix/BC_SymbolInfo.cpp
index f98370b..5d12f1c 100644
--- a/fxbarcode/datamatrix/BC_SymbolInfo.cpp
+++ b/fxbarcode/datamatrix/BC_SymbolInfo.cpp
@@ -22,11 +22,11 @@
 
 #include "fxbarcode/datamatrix/BC_SymbolInfo.h"
 
-#include "fxbarcode/BC_Dimension.h"
 #include "fxbarcode/common/BC_CommonBitMatrix.h"
 #include "fxbarcode/datamatrix/BC_DataMatrixSymbolInfo144.h"
 #include "fxbarcode/datamatrix/BC_Encoder.h"
 #include "fxbarcode/datamatrix/BC_SymbolShapeHint.h"
+#include "fxbarcode/utils.h"
 
 namespace {
 
@@ -133,37 +133,14 @@
                                        SymbolShapeHint shape,
                                        bool fail,
                                        int32_t& e) {
-  return lookup(dataCodewords, shape, nullptr, nullptr, fail, e);
-}
-CBC_SymbolInfo* CBC_SymbolInfo::lookup(int32_t dataCodewords,
-                                       SymbolShapeHint shape,
-                                       CBC_Dimension* minSize,
-                                       CBC_Dimension* maxSize,
-                                       bool fail,
-                                       int32_t& e) {
   for (size_t i = 0; i < kSymbolsCount; i++) {
     CBC_SymbolInfo* symbol = g_symbols[i];
-    if (shape == FORCE_SQUARE && symbol->m_rectangular) {
+    if ((shape == FORCE_SQUARE && symbol->m_rectangular) ||
+        (shape == FORCE_RECTANGLE && !symbol->m_rectangular)) {
       continue;
     }
-    if (shape == FORCE_RECTANGLE && !symbol->m_rectangular) {
-      continue;
-    }
-    if (minSize && (symbol->getSymbolWidth(e) < minSize->getWidth() ||
-                    symbol->getSymbolHeight(e) < minSize->getHeight())) {
-      if (e != BCExceptionNO)
-        return nullptr;
-      continue;
-    }
-    if (maxSize && (symbol->getSymbolWidth(e) > maxSize->getWidth() ||
-                    symbol->getSymbolHeight(e) > maxSize->getHeight())) {
-      if (e != BCExceptionNO)
-        return nullptr;
-      continue;
-    }
-    if (dataCodewords <= symbol->m_dataCapacity) {
+    if (dataCodewords <= symbol->m_dataCapacity)
       return symbol;
-    }
   }
   if (fail)
     e = BCExceptionIllegalDataCodewords;
diff --git a/fxbarcode/datamatrix/BC_SymbolInfo.h b/fxbarcode/datamatrix/BC_SymbolInfo.h
index 36ed01d..0a5cd20 100644
--- a/fxbarcode/datamatrix/BC_SymbolInfo.h
+++ b/fxbarcode/datamatrix/BC_SymbolInfo.h
@@ -11,8 +11,6 @@
 #include "core/fxcrt/fx_system.h"
 #include "fxbarcode/datamatrix/BC_SymbolShapeHint.h"
 
-class CBC_Dimension;
-
 class CBC_SymbolInfo : public CBC_SymbolShapeHint {
  public:
   CBC_SymbolInfo(bool rectangular,
@@ -38,12 +36,6 @@
                                 SymbolShapeHint shape,
                                 bool fail,
                                 int32_t& e);
-  static CBC_SymbolInfo* lookup(int32_t dataCodewords,
-                                SymbolShapeHint shape,
-                                CBC_Dimension* minSize,
-                                CBC_Dimension* maxSize,
-                                bool fail,
-                                int32_t& e);
   int32_t getHorizontalDataRegions(int32_t& e);
   int32_t getVerticalDataRegions(int32_t& e);
   int32_t getSymbolDataWidth(int32_t& e);
diff --git a/fxbarcode/datamatrix/BC_TextEncoder.cpp b/fxbarcode/datamatrix/BC_TextEncoder.cpp
index 53f92c3..ec7ff47 100644
--- a/fxbarcode/datamatrix/BC_TextEncoder.cpp
+++ b/fxbarcode/datamatrix/BC_TextEncoder.cpp
@@ -1,5 +1,3 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
@@ -22,7 +20,6 @@
 
 #include "fxbarcode/datamatrix/BC_TextEncoder.h"
 
-#include "fxbarcode/BC_Dimension.h"
 #include "fxbarcode/common/BC_CommonBitMatrix.h"
 #include "fxbarcode/datamatrix/BC_C40Encoder.h"
 #include "fxbarcode/datamatrix/BC_Encoder.h"
@@ -30,6 +27,7 @@
 #include "fxbarcode/datamatrix/BC_HighLevelEncoder.h"
 #include "fxbarcode/datamatrix/BC_SymbolInfo.h"
 #include "fxbarcode/datamatrix/BC_SymbolShapeHint.h"
+#include "fxbarcode/utils.h"
 
 CBC_TextEncoder::CBC_TextEncoder() {}
 CBC_TextEncoder::~CBC_TextEncoder() {}
diff --git a/fxbarcode/datamatrix/BC_X12Encoder.cpp b/fxbarcode/datamatrix/BC_X12Encoder.cpp
index 9103908..04bf958 100644
--- a/fxbarcode/datamatrix/BC_X12Encoder.cpp
+++ b/fxbarcode/datamatrix/BC_X12Encoder.cpp
@@ -22,7 +22,6 @@
 
 #include "fxbarcode/datamatrix/BC_X12Encoder.h"
 
-#include "fxbarcode/BC_Dimension.h"
 #include "fxbarcode/common/BC_CommonBitMatrix.h"
 #include "fxbarcode/datamatrix/BC_C40Encoder.h"
 #include "fxbarcode/datamatrix/BC_Encoder.h"
@@ -30,6 +29,7 @@
 #include "fxbarcode/datamatrix/BC_HighLevelEncoder.h"
 #include "fxbarcode/datamatrix/BC_SymbolInfo.h"
 #include "fxbarcode/datamatrix/BC_SymbolShapeHint.h"
+#include "fxbarcode/utils.h"
 
 CBC_X12Encoder::CBC_X12Encoder() {}
 CBC_X12Encoder::~CBC_X12Encoder() {}
diff --git a/fxbarcode/pdf417/BC_PDF417.cpp b/fxbarcode/pdf417/BC_PDF417.cpp
index 7907150..9844798 100644
--- a/fxbarcode/pdf417/BC_PDF417.cpp
+++ b/fxbarcode/pdf417/BC_PDF417.cpp
@@ -399,48 +399,49 @@
   return m_barcodeMatrix.get();
 }
 
-void CBC_PDF417::generateBarcodeLogic(CFX_WideString msg,
-                                      int32_t errorCorrectionLevel,
-                                      int32_t& e) {
+bool CBC_PDF417::generateBarcodeLogic(CFX_WideString msg,
+                                      int32_t errorCorrectionLevel) {
   int32_t errorCorrectionCodeWords =
       CBC_PDF417ErrorCorrection::getErrorCorrectionCodewordCount(
-          errorCorrectionLevel, e);
-  if (e != BCExceptionNO)
-    return;
+          errorCorrectionLevel);
+  if (errorCorrectionCodeWords < 0)
+    return false;
+
+  int32_t e = BCExceptionNO;
   CFX_WideString highLevel =
       CBC_PDF417HighLevelEncoder::encodeHighLevel(msg, m_compaction, e);
   if (e != BCExceptionNO)
-    return;
+    return false;
   int32_t sourceCodeWords = highLevel.GetLength();
-  std::vector<int32_t>* dimension =
-      determineDimensions(sourceCodeWords, errorCorrectionCodeWords, e);
-  if (e != BCExceptionNO)
-    return;
-  int32_t cols = (*dimension)[0];
-  int32_t rows = (*dimension)[1];
-  delete dimension;
+  std::vector<int32_t> dimensions =
+      determineDimensions(sourceCodeWords, errorCorrectionCodeWords);
+  if (dimensions.size() != 2)
+    return false;
+  int32_t cols = dimensions[0];
+  int32_t rows = dimensions[1];
   int32_t pad = getNumberOfPadCodewords(sourceCodeWords,
                                         errorCorrectionCodeWords, cols, rows);
-  if (sourceCodeWords + errorCorrectionCodeWords + 1 > 929) {
-    e = BCExceptionEncodedMessageContainsTooManyCodeWords;
-    return;
-  }
+  if (sourceCodeWords + errorCorrectionCodeWords + 1 > 929)
+    return false;
+
   int32_t n = sourceCodeWords + pad + 1;
   CFX_WideString sb;
   sb += (wchar_t)n;
   sb += highLevel;
-  for (int32_t i = 0; i < pad; i++) {
+  for (int32_t i = 0; i < pad; i++)
     sb += (wchar_t)900;
-  }
+
   CFX_WideString dataCodewords(sb);
-  CFX_WideString ec = CBC_PDF417ErrorCorrection::generateErrorCorrection(
-      dataCodewords, errorCorrectionLevel, e);
-  if (e != BCExceptionNO)
-    return;
+  CFX_WideString ec;
+  if (!CBC_PDF417ErrorCorrection::generateErrorCorrection(
+          dataCodewords, errorCorrectionLevel, &ec)) {
+    return false;
+  }
   CFX_WideString fullCodewords = dataCodewords + ec;
   m_barcodeMatrix = pdfium::MakeUnique<CBC_BarcodeMatrix>(rows, cols);
   encodeLowLevel(fullCodewords, cols, rows, errorCorrectionLevel,
                  m_barcodeMatrix.get());
+  return true;
 }
 
 void CBC_PDF417::setDimensions(int32_t maxCols,
@@ -536,49 +537,41 @@
   }
 }
 
-std::vector<int32_t>* CBC_PDF417::determineDimensions(
+std::vector<int32_t> CBC_PDF417::determineDimensions(
     int32_t sourceCodeWords,
-    int32_t errorCorrectionCodeWords,
-    int32_t& e) {
+    int32_t errorCorrectionCodeWords) const {
+  std::vector<int32_t> dimensions;
   float ratio = 0.0f;
-  std::vector<int32_t>* dimension = nullptr;
   for (int32_t cols = m_minCols; cols <= m_maxCols; cols++) {
     int32_t rows =
         calculateNumberOfRows(sourceCodeWords, errorCorrectionCodeWords, cols);
-    if (rows < m_minRows) {
+    if (rows < m_minRows)
       break;
-    }
-    if (rows > m_maxRows) {
+    if (rows > m_maxRows)
       continue;
-    }
     float newRatio =
         ((17 * cols + 69) * DEFAULT_MODULE_WIDTH) / (rows * HEIGHT);
-    if (dimension &&
+    if (!dimensions.empty() &&
         fabsf(newRatio - PREFERRED_RATIO) > fabsf(ratio - PREFERRED_RATIO)) {
       continue;
     }
     ratio = newRatio;
-    delete dimension;
-    dimension = new std::vector<int32_t>;
-    dimension->push_back(cols);
-    dimension->push_back(rows);
+    dimensions.resize(2);
+    dimensions[0] = cols;
+    dimensions[1] = rows;
   }
-  if (!dimension) {
+  if (dimensions.empty()) {
     int32_t rows = calculateNumberOfRows(sourceCodeWords,
                                          errorCorrectionCodeWords, m_minCols);
     if (rows < m_minRows) {
-      dimension = new std::vector<int32_t>;
-      dimension->push_back(m_minCols);
-      dimension->push_back(m_minRows);
+      dimensions.resize(2);
+      dimensions[0] = m_minCols;
+      dimensions[1] = m_minRows;
     } else if (rows >= 3 && rows <= 90) {
-      dimension = new std::vector<int32_t>;
-      dimension->push_back(m_minCols);
-      dimension->push_back(rows);
+      dimensions.resize(2);
+      dimensions[0] = m_minCols;
+      dimensions[1] = rows;
     }
   }
-  if (!dimension) {
-    e = BCExceptionUnableToFitMessageInColumns;
-    return nullptr;
-  }
-  return dimension;
+  return dimensions;
 }
diff --git a/fxbarcode/pdf417/BC_PDF417.h b/fxbarcode/pdf417/BC_PDF417.h
index bc36ea5..f5ca2de 100644
--- a/fxbarcode/pdf417/BC_PDF417.h
+++ b/fxbarcode/pdf417/BC_PDF417.h
@@ -23,9 +23,7 @@
   virtual ~CBC_PDF417();
 
   CBC_BarcodeMatrix* getBarcodeMatrix();
-  void generateBarcodeLogic(CFX_WideString msg,
-                            int32_t errorCorrectionLevel,
-                            int32_t& e);
+  bool generateBarcodeLogic(CFX_WideString msg, int32_t errorCorrectionLevel);
   void setDimensions(int32_t maxCols,
                      int32_t minCols,
                      int32_t maxRows,
@@ -52,9 +50,9 @@
                       int32_t r,
                       int32_t errorCorrectionLevel,
                       CBC_BarcodeMatrix* logic);
-  std::vector<int32_t>* determineDimensions(int32_t sourceCodeWords,
-                                            int32_t errorCorrectionCodeWords,
-                                            int32_t& e);
+  std::vector<int32_t> determineDimensions(
+      int32_t sourceCodeWords,
+      int32_t errorCorrectionCodeWords) const;
 
   std::unique_ptr<CBC_BarcodeMatrix> m_barcodeMatrix;
   bool m_compact;
diff --git a/fxbarcode/pdf417/BC_PDF417ErrorCorrection.cpp b/fxbarcode/pdf417/BC_PDF417ErrorCorrection.cpp
index abdd113..6f1d794 100644
--- a/fxbarcode/pdf417/BC_PDF417ErrorCorrection.cpp
+++ b/fxbarcode/pdf417/BC_PDF417ErrorCorrection.cpp
@@ -21,7 +21,8 @@
  */
 
 #include "fxbarcode/pdf417/BC_PDF417ErrorCorrection.h"
-#include "fxbarcode/utils.h"
+
+#include <vector>
 
 namespace {
 
@@ -124,47 +125,24 @@
 CBC_PDF417ErrorCorrection::CBC_PDF417ErrorCorrection() {}
 CBC_PDF417ErrorCorrection::~CBC_PDF417ErrorCorrection() {}
 int32_t CBC_PDF417ErrorCorrection::getErrorCorrectionCodewordCount(
-    int32_t errorCorrectionLevel,
-    int32_t& e) {
-  if (errorCorrectionLevel < 0 || errorCorrectionLevel > 8) {
-    e = BCExceptionErrorCorrectionLevelMustBeBetween0And8;
+    int32_t errorCorrectionLevel) {
+  if (errorCorrectionLevel < 0 || errorCorrectionLevel > 8)
     return -1;
-  }
   return 1 << (errorCorrectionLevel + 1);
 }
 
-int32_t CBC_PDF417ErrorCorrection::getRecommendedMinimumErrorCorrectionLevel(
-    int32_t n,
-    int32_t& e) {
-  if (n <= 0) {
-    e = BCExceptionIllegalArgumentnMustBeAbove0;
-    return -1;
-  }
-  if (n <= 40) {
-    return 2;
-  }
-  if (n <= 160) {
-    return 3;
-  }
-  if (n <= 320) {
-    return 4;
-  }
-  if (n <= 863) {
-    return 5;
-  }
-  e = BCExceptionNoRecommendationPossible;
-  return -1;
-}
-
-CFX_WideString CBC_PDF417ErrorCorrection::generateErrorCorrection(
-    CFX_WideString dataCodewords,
+bool CBC_PDF417ErrorCorrection::generateErrorCorrection(
+    const CFX_WideString& dataCodewords,
     int32_t errorCorrectionLevel,
-    int32_t& e) {
-  int32_t k = getErrorCorrectionCodewordCount(errorCorrectionLevel, e);
-  if (e != BCExceptionNO)
-    return L" ";
-  wchar_t* ech = FX_Alloc(wchar_t, k);
-  memset(ech, 0, k * sizeof(wchar_t));
+    CFX_WideString* result) {
+  assert(result);
+  assert(result->IsEmpty());
+
+  int32_t k = getErrorCorrectionCodewordCount(errorCorrectionLevel);
+  if (k < 0)
+    return false;
+
+  std::vector<wchar_t> ech(k);
   int32_t sld = dataCodewords.GetLength();
   for (int32_t i = 0; i < sld; i++) {
     int32_t t1 = (dataCodewords.GetAt(i) + ech[k - 1]) % 929;
@@ -179,13 +157,11 @@
     t3 = 929 - t2;
     ech[0] = (wchar_t)(t3 % 929);
   }
-  CFX_WideString sb;
+  result->Reserve(k);
   for (int32_t j = k - 1; j >= 0; j--) {
-    if (ech[j] != 0) {
-      ech[j] = (wchar_t)(929 - ech[j]);
-    }
-    sb += (wchar_t)ech[j];
+    if (ech[j] != 0)
+      ech[j] = static_cast<wchar_t>(929) - ech[j];
+    *result += ech[j];
   }
-  FX_Free(ech);
-  return sb;
+  return true;
 }
diff --git a/fxbarcode/pdf417/BC_PDF417ErrorCorrection.h b/fxbarcode/pdf417/BC_PDF417ErrorCorrection.h
index d1c6eed..3a84ef5 100644
--- a/fxbarcode/pdf417/BC_PDF417ErrorCorrection.h
+++ b/fxbarcode/pdf417/BC_PDF417ErrorCorrection.h
@@ -16,13 +16,10 @@
   CBC_PDF417ErrorCorrection();
   virtual ~CBC_PDF417ErrorCorrection();
 
-  static int32_t getErrorCorrectionCodewordCount(int32_t errorCorrectionLevel,
-                                                 int32_t& e);
-  static int32_t getRecommendedMinimumErrorCorrectionLevel(int32_t n,
-                                                           int32_t& e);
-  static CFX_WideString generateErrorCorrection(CFX_WideString dataCodewords,
-                                                int32_t errorCorrectionLevel,
-                                                int32_t& e);
+  static int32_t getErrorCorrectionCodewordCount(int32_t errorCorrectionLevel);
+  static bool generateErrorCorrection(const CFX_WideString& dataCodewords,
+                                      int32_t errorCorrectionLevel,
+                                      CFX_WideString* result);
 };
 
 #endif  // FXBARCODE_PDF417_BC_PDF417ERRORCORRECTION_H_
diff --git a/fxbarcode/pdf417/BC_PDF417Writer.cpp b/fxbarcode/pdf417/BC_PDF417Writer.cpp
index 6f06321..2f6fc9e 100644
--- a/fxbarcode/pdf417/BC_PDF417Writer.cpp
+++ b/fxbarcode/pdf417/BC_PDF417Writer.cpp
@@ -60,9 +60,7 @@
     encoder.setDimensions(col, col, 90, 3);
   else if (row >= 3 && row <= 90)
     encoder.setDimensions(30, 1, row, row);
-  int32_t e = BCExceptionNO;
-  encoder.generateBarcodeLogic(contents, m_iCorrectLevel, e);
-  if (e != BCExceptionNO)
+  if (!encoder.generateBarcodeLogic(contents, m_iCorrectLevel))
     return nullptr;
 
   int32_t lineThickness = 2;
diff --git a/fxbarcode/utils.h b/fxbarcode/utils.h
index 6f49695..e3fd1ac 100644
--- a/fxbarcode/utils.h
+++ b/fxbarcode/utils.h
@@ -59,9 +59,7 @@
 #define BCFORMAT_ECLEVEL_H 3
 #include <ctype.h>
 #define BCExceptionNO 0
-#define BCExceptionHeightAndWidthMustBeAtLeast1 5
 #define BCExceptionIllegalArgument 16
-#define BCExceptionNoContents 26
 #define BCExceptionDegreeIsNegative 31
 #define BCExceptionAIsZero 37
 #define BCExceptionValueMustBeEither0or1 50
@@ -80,16 +78,10 @@
 #define BCExceptionIllegalDataCodewords 88
 #define BCExceptionCannotHandleThisNumberOfDataRegions 89
 #define BCExceptionIllegalStateUnexpectedCase 90
-#define BCExceptionIllegalStateCountMustNotExceed4 91
 #define BCExceptionIllegalStateMessageLengthInvalid 92
 #define BCExceptionIllegalArgumentNotGigits 93
 #define BCExceptionIllegalStateIllegalMode 94
 #define BCExceptionNonEncodableCharacterDetected 96
-#define BCExceptionErrorCorrectionLevelMustBeBetween0And8 97
-#define BCExceptionNoRecommendationPossible 98
-#define BCExceptionIllegalArgumentnMustBeAbove0 99
-#define BCExceptionUnableToFitMessageInColumns 100
-#define BCExceptionEncodedMessageContainsTooManyCodeWords 101
 #define BCExceptionGeneric 107
 
 #endif  // FXBARCODE_UTILS_H_