Use Optional in place of out param in cfx_cttgsubtable.cpp

-- mark constructors explicit to fix pre-existing submit warning.

Change-Id: Ib9eb8355814fad83e336f4630287e69f22d483ef
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/81412
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/font/cfx_cttgsubtable.cpp b/core/fpdfapi/font/cfx_cttgsubtable.cpp
index 4631582..a566f98 100644
--- a/core/fpdfapi/font/cfx_cttgsubtable.cpp
+++ b/core/fpdfapi/font/cfx_cttgsubtable.cpp
@@ -57,38 +57,40 @@
 }
 
 uint32_t CFX_CTTGSUBTable::GetVerticalGlyph(uint32_t glyphnum) const {
-  uint32_t vglyphnum = 0;
   for (uint32_t item : m_featureSet) {
-    if (GetVerticalGlyphSub(FeatureList[item], glyphnum, &vglyphnum))
-      break;
+    Optional<uint32_t> result =
+        GetVerticalGlyphSub(FeatureList[item], glyphnum);
+    if (result.has_value())
+      return result.value();
   }
-  return vglyphnum;
+  return 0;
 }
 
-bool CFX_CTTGSUBTable::GetVerticalGlyphSub(const TFeatureRecord& feature,
-                                           uint32_t glyphnum,
-                                           uint32_t* vglyphnum) const {
+Optional<uint32_t> CFX_CTTGSUBTable::GetVerticalGlyphSub(
+    const TFeatureRecord& feature,
+    uint32_t glyphnum) const {
   for (int index : feature.LookupListIndices) {
     if (!pdfium::IndexInBounds(LookupList, index))
       continue;
-    if (LookupList[index].LookupType == 1 &&
-        GetVerticalGlyphSub2(LookupList[index], glyphnum, vglyphnum)) {
-      return true;
-    }
+    if (LookupList[index].LookupType != 1)
+      continue;
+    Optional<uint32_t> result =
+        GetVerticalGlyphSub2(LookupList[index], glyphnum);
+    if (result.has_value())
+      return result.value();
   }
-  return false;
+  return pdfium::nullopt;
 }
 
-bool CFX_CTTGSUBTable::GetVerticalGlyphSub2(const TLookup& lookup,
-                                            uint32_t glyphnum,
-                                            uint32_t* vglyphnum) const {
+Optional<uint32_t> CFX_CTTGSUBTable::GetVerticalGlyphSub2(
+    const TLookup& lookup,
+    uint32_t glyphnum) const {
   for (const auto& subTable : lookup.SubTables) {
     switch (subTable->SubstFormat) {
       case 1: {
         auto* tbl1 = static_cast<TSubTable1*>(subTable.get());
         if (GetCoverageIndex(tbl1->Coverage.get(), glyphnum) >= 0) {
-          *vglyphnum = glyphnum + tbl1->DeltaGlyphID;
-          return true;
+          return glyphnum + tbl1->DeltaGlyphID;
         }
         break;
       }
@@ -96,14 +98,13 @@
         auto* tbl2 = static_cast<TSubTable2*>(subTable.get());
         int index = GetCoverageIndex(tbl2->Coverage.get(), glyphnum);
         if (pdfium::IndexInBounds(tbl2->Substitutes, index)) {
-          *vglyphnum = tbl2->Substitutes[index];
-          return true;
+          return tbl2->Substitutes[index];
         }
         break;
       }
     }
   }
-  return false;
+  return pdfium::nullopt;
 }
 
 int CFX_CTTGSUBTable::GetCoverageIndex(TCoverageFormatBase* Coverage,
diff --git a/core/fpdfapi/font/cfx_cttgsubtable.h b/core/fpdfapi/font/cfx_cttgsubtable.h
index fecd262..6dc9860 100644
--- a/core/fpdfapi/font/cfx_cttgsubtable.h
+++ b/core/fpdfapi/font/cfx_cttgsubtable.h
@@ -15,6 +15,7 @@
 
 #include "core/fxcrt/fx_memory_wrappers.h"
 #include "core/fxge/fx_freetype.h"
+#include "third_party/base/optional.h"
 
 class CFX_CTTGSUBTable {
  public:
@@ -61,21 +62,21 @@
   };
 
   struct TCoverageFormatBase {
-    TCoverageFormatBase(uint16_t format) : CoverageFormat(format) {}
+    explicit TCoverageFormatBase(uint16_t format) : CoverageFormat(format) {}
     virtual ~TCoverageFormatBase() = default;
 
     const uint16_t CoverageFormat;
   };
 
   struct TCoverageFormat1 final : public TCoverageFormatBase {
-    TCoverageFormat1(size_t initial_size);
+    explicit TCoverageFormat1(size_t initial_size);
     ~TCoverageFormat1() override;
 
     std::vector<uint16_t, FxAllocAllocator<uint16_t>> GlyphArray;
   };
 
   struct TCoverageFormat2 final : public TCoverageFormatBase {
-    TCoverageFormat2(size_t initial_size);
+    explicit TCoverageFormat2(size_t initial_size);
     ~TCoverageFormat2() override;
 
     std::vector<TRangeRecord> RangeRecords;
@@ -90,7 +91,7 @@
   };
 
   struct TSubTableBase {
-    TSubTableBase(uint16_t format);
+    explicit TSubTableBase(uint16_t format);
     virtual ~TSubTableBase();
 
     const uint16_t SubstFormat;
@@ -136,12 +137,10 @@
   std::unique_ptr<TSubTable1> ParseSingleSubstFormat1(FT_Bytes raw);
   std::unique_ptr<TSubTable2> ParseSingleSubstFormat2(FT_Bytes raw);
 
-  bool GetVerticalGlyphSub(const TFeatureRecord& feature,
-                           uint32_t glyphnum,
-                           uint32_t* vglyphnum) const;
-  bool GetVerticalGlyphSub2(const TLookup& lookup,
-                            uint32_t glyphnum,
-                            uint32_t* vglyphnum) const;
+  Optional<uint32_t> GetVerticalGlyphSub(const TFeatureRecord& feature,
+                                         uint32_t glyphnum) const;
+  Optional<uint32_t> GetVerticalGlyphSub2(const TLookup& lookup,
+                                          uint32_t glyphnum) const;
   int GetCoverageIndex(TCoverageFormatBase* Coverage, uint32_t g) const;
 
   uint8_t GetUInt8(FT_Bytes& p) const;