Make CBC_CodeBase::SetTextLocation() virtual.

Do the same for a few other CBC_CodeBase methods, instead of trying to
implement virtual methods manually using memory pointers.

Change-Id: Iec0e3a4f8eabc54962c7ac0a00a1b80b192ff474
Reviewed-on: https://pdfium-review.googlesource.com/42600
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/fxbarcode/cbc_codabar.h b/fxbarcode/cbc_codabar.h
index 036c65f..7fc518b 100644
--- a/fxbarcode/cbc_codabar.h
+++ b/fxbarcode/cbc_codabar.h
@@ -20,15 +20,14 @@
   ~CBC_Codabar() override;
 
   // CBC_OneCode:
+  BC_TYPE GetType() override;
   bool Encode(const WideStringView& contents) override;
   bool RenderDevice(CFX_RenderDevice* device,
                     const CFX_Matrix* matrix) override;
-  BC_TYPE GetType() override;
-
-  bool SetStartChar(char start);
-  bool SetEndChar(char end);
-  bool SetTextLocation(BC_TEXT_LOC location);
-  bool SetWideNarrowRatio(int8_t ratio);
+  bool SetTextLocation(BC_TEXT_LOC location) override;
+  bool SetWideNarrowRatio(int8_t ratio) override;
+  bool SetStartChar(char start) override;
+  bool SetEndChar(char end) override;
 
  private:
   CBC_OnedCodaBarWriter* GetOnedCodaBarWriter();
diff --git a/fxbarcode/cbc_code128.h b/fxbarcode/cbc_code128.h
index 61bed6f..ccd5a38 100644
--- a/fxbarcode/cbc_code128.h
+++ b/fxbarcode/cbc_code128.h
@@ -20,12 +20,11 @@
   ~CBC_Code128() override;
 
   // CBC_OneCode:
+  BC_TYPE GetType() override;
   bool Encode(const WideStringView& contents) override;
   bool RenderDevice(CFX_RenderDevice* device,
                     const CFX_Matrix* matrix) override;
-  BC_TYPE GetType() override;
-
-  bool SetTextLocation(BC_TEXT_LOC loction);
+  bool SetTextLocation(BC_TEXT_LOC location) override;
 
  private:
   CBC_OnedCode128Writer* GetOnedCode128Writer();
diff --git a/fxbarcode/cbc_code39.h b/fxbarcode/cbc_code39.h
index 83c8daa..4e240b7 100644
--- a/fxbarcode/cbc_code39.h
+++ b/fxbarcode/cbc_code39.h
@@ -21,13 +21,12 @@
   ~CBC_Code39() override;
 
   // CBC_OneCode:
+  BC_TYPE GetType() override;
   bool Encode(const WideStringView& contents) override;
   bool RenderDevice(CFX_RenderDevice* device,
                     const CFX_Matrix* matrix) override;
-  BC_TYPE GetType() override;
-
-  bool SetTextLocation(BC_TEXT_LOC location);
-  bool SetWideNarrowRatio(int8_t ratio);
+  bool SetTextLocation(BC_TEXT_LOC location) override;
+  bool SetWideNarrowRatio(int8_t ratio) override;
 
  private:
   CBC_OnedCode39Writer* GetOnedCode39Writer();
diff --git a/fxbarcode/cbc_codebase.cpp b/fxbarcode/cbc_codebase.cpp
index 2278f93..b723f55 100644
--- a/fxbarcode/cbc_codebase.cpp
+++ b/fxbarcode/cbc_codebase.cpp
@@ -30,6 +30,26 @@
 
 CBC_CodeBase::~CBC_CodeBase() {}
 
+bool CBC_CodeBase::SetTextLocation(BC_TEXT_LOC location) {
+  return false;
+}
+
+bool CBC_CodeBase::SetWideNarrowRatio(int8_t ratio) {
+  return false;
+}
+
+bool CBC_CodeBase::SetStartChar(char start) {
+  return false;
+}
+
+bool CBC_CodeBase::SetEndChar(char end) {
+  return false;
+}
+
+bool CBC_CodeBase::SetErrorCorrectionLevel(int32_t level) {
+  return false;
+}
+
 bool CBC_CodeBase::SetCharEncoding(int32_t encoding) {
   return m_pBCWriter->SetCharEncoding(encoding);
 }
diff --git a/fxbarcode/cbc_codebase.h b/fxbarcode/cbc_codebase.h
index aab98da..e0f402d 100644
--- a/fxbarcode/cbc_codebase.h
+++ b/fxbarcode/cbc_codebase.h
@@ -29,6 +29,11 @@
   virtual bool Encode(const WideStringView& contents) = 0;
   virtual bool RenderDevice(CFX_RenderDevice* device,
                             const CFX_Matrix* matrix) = 0;
+  virtual bool SetTextLocation(BC_TEXT_LOC location);
+  virtual bool SetWideNarrowRatio(int8_t ratio);
+  virtual bool SetStartChar(char start);
+  virtual bool SetEndChar(char end);
+  virtual bool SetErrorCorrectionLevel(int32_t level);
 
   bool SetCharEncoding(int32_t encoding);
   bool SetModuleHeight(int32_t moduleHeight);
diff --git a/fxbarcode/cbc_pdf417i.h b/fxbarcode/cbc_pdf417i.h
index ec68600..b12fa74 100644
--- a/fxbarcode/cbc_pdf417i.h
+++ b/fxbarcode/cbc_pdf417i.h
@@ -24,8 +24,7 @@
   bool RenderDevice(CFX_RenderDevice* device,
                     const CFX_Matrix* matrix) override;
   BC_TYPE GetType() override;
-
-  bool SetErrorCorrectionLevel(int32_t level);
+  bool SetErrorCorrectionLevel(int32_t level) override;
 
  private:
   CBC_PDF417Writer* GetPDF417Writer();
diff --git a/fxbarcode/cbc_qrcode.h b/fxbarcode/cbc_qrcode.h
index 59d57ac..8502933 100644
--- a/fxbarcode/cbc_qrcode.h
+++ b/fxbarcode/cbc_qrcode.h
@@ -24,8 +24,7 @@
   bool RenderDevice(CFX_RenderDevice* device,
                     const CFX_Matrix* matrix) override;
   BC_TYPE GetType() override;
-
-  bool SetErrorCorrectionLevel(int32_t level);
+  bool SetErrorCorrectionLevel(int32_t level) override;
 
  private:
   CBC_QRCodeWriter* GetQRCodeWriter();
diff --git a/fxbarcode/oned/BC_OnedCode39Writer.h b/fxbarcode/oned/BC_OnedCode39Writer.h
index 0791062..97ef7a2 100644
--- a/fxbarcode/oned/BC_OnedCode39Writer.h
+++ b/fxbarcode/oned/BC_OnedCode39Writer.h
@@ -29,7 +29,7 @@
   WideString FilterContents(const WideStringView& contents) override;
   WideString RenderTextContents(const WideStringView& contents) override;
 
-  virtual bool SetTextLocation(BC_TEXT_LOC loction);
+  virtual bool SetTextLocation(BC_TEXT_LOC location);
   virtual bool SetWideNarrowRatio(int8_t ratio);
 
   bool encodedContents(const WideStringView& contents, WideString* result);
diff --git a/xfa/fwl/cfx_barcode.cpp b/xfa/fwl/cfx_barcode.cpp
index 583fa9c..1d13062 100644
--- a/xfa/fwl/cfx_barcode.cpp
+++ b/xfa/fwl/cfx_barcode.cpp
@@ -204,82 +204,23 @@
 }
 
 bool CFX_Barcode::SetTextLocation(BC_TEXT_LOC location) {
-  typedef bool (CBC_CodeBase::*memptrtype)(BC_TEXT_LOC);
-  memptrtype memptr = nullptr;
-  switch (GetType()) {
-    case BC_CODE39:
-      memptr = (memptrtype)&CBC_Code39::SetTextLocation;
-      break;
-    case BC_CODABAR:
-      memptr = (memptrtype)&CBC_Codabar::SetTextLocation;
-      break;
-    case BC_CODE128:
-    case BC_CODE128_B:
-    case BC_CODE128_C:
-      memptr = (memptrtype)&CBC_Code128::SetTextLocation;
-      break;
-    default:
-      break;
-  }
-  return m_pBCEngine && memptr ? (m_pBCEngine.get()->*memptr)(location) : false;
+  return m_pBCEngine && m_pBCEngine->SetTextLocation(location);
 }
 
 bool CFX_Barcode::SetWideNarrowRatio(int8_t ratio) {
-  typedef bool (CBC_CodeBase::*memptrtype)(int8_t);
-  memptrtype memptr = nullptr;
-  switch (GetType()) {
-    case BC_CODE39:
-      memptr = (memptrtype)&CBC_Code39::SetWideNarrowRatio;
-      break;
-    case BC_CODABAR:
-      memptr = (memptrtype)&CBC_Codabar::SetWideNarrowRatio;
-      break;
-    default:
-      break;
-  }
-  return m_pBCEngine && memptr ? (m_pBCEngine.get()->*memptr)(ratio) : false;
+  return m_pBCEngine && m_pBCEngine->SetWideNarrowRatio(ratio);
 }
 
 bool CFX_Barcode::SetStartChar(char start) {
-  typedef bool (CBC_CodeBase::*memptrtype)(char);
-  memptrtype memptr = nullptr;
-  switch (GetType()) {
-    case BC_CODABAR:
-      memptr = (memptrtype)&CBC_Codabar::SetStartChar;
-      break;
-    default:
-      break;
-  }
-  return m_pBCEngine && memptr ? (m_pBCEngine.get()->*memptr)(start) : false;
+  return m_pBCEngine && m_pBCEngine->SetStartChar(start);
 }
 
 bool CFX_Barcode::SetEndChar(char end) {
-  typedef bool (CBC_CodeBase::*memptrtype)(char);
-  memptrtype memptr = nullptr;
-  switch (GetType()) {
-    case BC_CODABAR:
-      memptr = (memptrtype)&CBC_Codabar::SetEndChar;
-      break;
-    default:
-      break;
-  }
-  return m_pBCEngine && memptr ? (m_pBCEngine.get()->*memptr)(end) : false;
+  return m_pBCEngine && m_pBCEngine->SetEndChar(end);
 }
 
 bool CFX_Barcode::SetErrorCorrectionLevel(int32_t level) {
-  typedef bool (CBC_CodeBase::*memptrtype)(int32_t);
-  memptrtype memptr = nullptr;
-  switch (GetType()) {
-    case BC_QR_CODE:
-      memptr = (memptrtype)&CBC_QRCode::SetErrorCorrectionLevel;
-      break;
-    case BC_PDF417:
-      memptr = (memptrtype)&CBC_PDF417I::SetErrorCorrectionLevel;
-      break;
-    default:
-      return false;
-  }
-  return m_pBCEngine && memptr ? (m_pBCEngine.get()->*memptr)(level) : false;
+  return m_pBCEngine && m_pBCEngine->SetErrorCorrectionLevel(level);
 }
 
 bool CFX_Barcode::Encode(const WideStringView& contents) {