Cleanup some nits in CFX_Font

Change-Id: I30b59c794fc855fd36c33da3c60053ae08b3dac1
Reviewed-on: https://pdfium-review.googlesource.com/5910
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
diff --git a/core/fxge/fx_font.h b/core/fxge/fx_font.h
index 946c713..5ef1a7d 100644
--- a/core/fxge/fx_font.h
+++ b/core/fxge/fx_font.h
@@ -100,8 +100,7 @@
 
 #ifdef PDF_ENABLE_XFA
   bool LoadFile(const CFX_RetainPtr<IFX_SeekableReadStream>& pFile,
-                int nFaceIndex = 0,
-                int* pFaceCount = nullptr);
+                int nFaceIndex);
 
   bool LoadClone(const CFX_Font* pFont);
   void SetFace(FXFT_Face face);
@@ -135,10 +134,6 @@
   CFX_ByteString GetFaceName() const;
   bool IsTTFont() const;
   bool GetBBox(FX_RECT& bbox);
-  int GetHeight() const;
-  int GetULPos() const;
-  int GetULthickness() const;
-  int GetMaxAdvanceWidth() const;
   bool IsEmbedded() const { return m_bEmbedded; }
   uint8_t* GetSubData() const { return m_pGsubData; }
   void SetSubData(uint8_t* data) { m_pGsubData = data; }
@@ -165,8 +160,7 @@
 
  private:
   friend class CFX_FaceCache;
-  CFX_PathData* LoadGlyphPathImpl(uint32_t glyph_index,
-                                  int dest_width = 0) const;
+  CFX_PathData* LoadGlyphPathImpl(uint32_t glyph_index, int dest_width) const;
   CFX_FaceCache* GetFaceCache() const;
   void ReleasePlatformResource();
   void DeleteFace();
@@ -231,8 +225,8 @@
 
 FX_RECT FXGE_GetGlyphsBBox(const std::vector<FXTEXT_GLYPHPOS>& glyphs,
                            int anti_alias,
-                           float retinaScaleX = 1.0f,
-                           float retinaScaleY = 1.0f);
+                           float retinaScaleX,
+                           float retinaScaleY);
 
 CFX_ByteString GetNameFromTT(const uint8_t* name_table,
                              uint32_t name_table_size,
diff --git a/core/fxge/ge/cfx_font.cpp b/core/fxge/ge/cfx_font.cpp
index 1a45fd3..229ede7 100644
--- a/core/fxge/ge/cfx_font.cpp
+++ b/core/fxge/ge/cfx_font.cpp
@@ -46,13 +46,7 @@
 
   IFX_SeekableReadStream* pFile =
       static_cast<IFX_SeekableReadStream*>(stream->descriptor.pointer);
-  if (!pFile)
-    return 0;
-
-  if (!pFile->ReadBlock(buffer, offset, count))
-    return 0;
-
-  return count;
+  return pFile && pFile->ReadBlock(buffer, offset, count) ? count : 0;
 }
 
 void FTStreamClose(FXFT_Stream stream) {}
@@ -103,7 +97,7 @@
 }
 
 int Outline_MoveTo(const FXFT_Vector* to, void* user) {
-  OUTLINE_PARAMS* param = (OUTLINE_PARAMS*)user;
+  OUTLINE_PARAMS* param = static_cast<OUTLINE_PARAMS*>(user);
 
   Outline_CheckEmptyContour(param);
 
@@ -118,7 +112,7 @@
 }
 
 int Outline_LineTo(const FXFT_Vector* to, void* user) {
-  OUTLINE_PARAMS* param = (OUTLINE_PARAMS*)user;
+  OUTLINE_PARAMS* param = static_cast<OUTLINE_PARAMS*>(user);
 
   param->m_pPath->AppendPoint(
       CFX_PointF(to->x / param->m_CoordUnit, to->y / param->m_CoordUnit),
@@ -132,7 +126,7 @@
 int Outline_ConicTo(const FXFT_Vector* control,
                     const FXFT_Vector* to,
                     void* user) {
-  OUTLINE_PARAMS* param = (OUTLINE_PARAMS*)user;
+  OUTLINE_PARAMS* param = static_cast<OUTLINE_PARAMS*>(user);
 
   param->m_pPath->AppendPoint(
       CFX_PointF((param->m_CurX + (control->x - param->m_CurX) * 2 / 3) /
@@ -159,7 +153,7 @@
                     const FXFT_Vector* control2,
                     const FXFT_Vector* to,
                     void* user) {
-  OUTLINE_PARAMS* param = (OUTLINE_PARAMS*)user;
+  OUTLINE_PARAMS* param = static_cast<OUTLINE_PARAMS*>(user);
 
   param->m_pPath->AppendPoint(CFX_PointF(control1->x / param->m_CoordUnit,
                                          control1->y / param->m_CoordUnit),
@@ -289,11 +283,10 @@
 
 void CFX_Font::DeleteFace() {
   ClearFaceCache();
-  if (m_bEmbedded) {
+  if (m_bEmbedded)
     FXFT_Done_Face(m_Face);
-  } else {
+  else
     CFX_GEModule::Get()->GetFontMgr()->ReleaseFace(m_Face);
-  }
   m_Face = nullptr;
 }
 
@@ -318,8 +311,7 @@
 
 #ifdef PDF_ENABLE_XFA
 bool CFX_Font::LoadFile(const CFX_RetainPtr<IFX_SeekableReadStream>& pFile,
-                        int nFaceIndex,
-                        int* pFaceCount) {
+                        int nFaceIndex) {
   m_bEmbedded = false;
 
   CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr();
@@ -330,8 +322,6 @@
   if (!LoadFileImp(library, &m_Face, pFile, nFaceIndex, &stream))
     return false;
 
-  if (pFaceCount)
-    *pFaceCount = (int)m_Face->num_faces;
   m_pOwnedStream = stream.release();
   FXFT_Set_Pixel_Sizes(m_Face, 0, 64);
   return true;
@@ -348,6 +338,7 @@
       FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH);
   if (err)
     return 0;
+
   int width = EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face),
                         FXFT_Get_Glyph_HoriAdvance(m_Face));
   return width;
@@ -364,14 +355,13 @@
 }
 
 bool CFX_Font::IsTTFont() const {
-  if (!m_Face)
-    return false;
-  return FXFT_Is_Face_TT_OT(m_Face) == FXFT_FACE_FLAG_SFNT;
+  return m_Face && FXFT_Is_Face_TT_OT(m_Face) == FXFT_FACE_FLAG_SFNT;
 }
 
 int CFX_Font::GetAscent() const {
   if (!m_Face)
     return 0;
+
   return EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face),
                    FXFT_Get_Face_Ascender(m_Face));
 }
@@ -379,6 +369,7 @@
 int CFX_Font::GetDescent() const {
   if (!m_Face)
     return 0;
+
   return EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face),
                    FXFT_Get_Face_Descender(m_Face));
 }
@@ -391,18 +382,21 @@
     int error = FXFT_Set_Char_Size(m_Face, 0, 1000 * 64, 72, 72);
     if (error)
       return false;
+
     error = FXFT_Load_Glyph(m_Face, glyph_index,
                             FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH);
     if (error)
       return false;
+
     FXFT_BBox cbox;
     FT_Glyph glyph;
-    error = FXFT_Get_Glyph(((FXFT_Face)m_Face)->glyph, &glyph);
+    error = FXFT_Get_Glyph(m_Face->glyph, &glyph);
     if (error)
       return false;
+
     FXFT_Glyph_Get_CBox(glyph, FXFT_GLYPH_BBOX_PIXELS, &cbox);
-    int pixel_size_x = ((FXFT_Face)m_Face)->size->metrics.x_ppem,
-        pixel_size_y = ((FXFT_Face)m_Face)->size->metrics.y_ppem;
+    int pixel_size_x = m_Face->size->metrics.x_ppem,
+        pixel_size_y = m_Face->size->metrics.y_ppem;
     if (pixel_size_x == 0 || pixel_size_y == 0) {
       bbox.left = cbox.xMin;
       bbox.right = cbox.xMax;
@@ -414,10 +408,10 @@
       bbox.top = cbox.yMax * 1000 / pixel_size_y;
       bbox.bottom = cbox.yMin * 1000 / pixel_size_y;
     }
-    if (bbox.top > FXFT_Get_Face_Ascender(m_Face))
-      bbox.top = FXFT_Get_Face_Ascender(m_Face);
-    if (bbox.bottom < FXFT_Get_Face_Descender(m_Face))
-      bbox.bottom = FXFT_Get_Face_Descender(m_Face);
+    bbox.top = std::min(bbox.top,
+                        static_cast<int32_t>(FXFT_Get_Face_Ascender(m_Face)));
+    bbox.bottom = std::max(
+        bbox.bottom, static_cast<int32_t>(FXFT_Get_Face_Descender(m_Face)));
     FT_Done_Glyph(glyph);
     return FXFT_Set_Pixel_Sizes(m_Face, 0, 64) == 0;
   }
@@ -448,24 +442,20 @@
 bool CFX_Font::IsItalic() const {
   if (!m_Face)
     return false;
-
   if (FXFT_Is_Face_Italic(m_Face) == FXFT_STYLE_FLAG_ITALIC)
     return true;
+
   CFX_ByteString str(FXFT_Get_Face_Style_Name(m_Face));
   str.MakeLower();
   return str.Find("italic") != -1;
 }
 
 bool CFX_Font::IsBold() const {
-  if (!m_Face)
-    return false;
-  return FXFT_Is_Face_Bold(m_Face) == FXFT_STYLE_FLAG_BOLD;
+  return m_Face && FXFT_Is_Face_Bold(m_Face) == FXFT_STYLE_FLAG_BOLD;
 }
 
 bool CFX_Font::IsFixedWidth() const {
-  if (!m_Face)
-    return false;
-  return FXFT_Is_Face_fixedwidth(m_Face) != 0;
+  return m_Face && FXFT_Is_Face_fixedwidth(m_Face) != 0;
 }
 
 CFX_ByteString CFX_Font::GetPsName() const {
@@ -483,6 +473,7 @@
     return CFX_ByteString();
   if (m_Face)
     return CFX_ByteString(FXFT_Get_Face_Family_Name(m_Face));
+
   return m_pSubstFont->m_Family;
 }
 
@@ -490,9 +481,8 @@
   if (!m_Face && !m_pSubstFont)
     return CFX_ByteString();
   if (m_Face) {
-    CFX_ByteString facename;
     CFX_ByteString style = CFX_ByteString(FXFT_Get_Face_Style_Name(m_Face));
-    facename = GetFamilyName();
+    CFX_ByteString facename = GetFamilyName();
     if (facename.IsEmpty())
       facename = "Untitled";
     if (!style.IsEmpty() && style != "Regular")
@@ -505,6 +495,7 @@
 bool CFX_Font::GetBBox(FX_RECT& bbox) {
   if (!m_Face)
     return false;
+
   int em = FXFT_Get_Face_UnitsPerEM(m_Face);
   if (em == 0) {
     bbox.left = FXFT_Get_Face_xMin(m_Face);
@@ -520,22 +511,6 @@
   return true;
 }
 
-int CFX_Font::GetHeight() const {
-  if (!m_Face)
-    return 0;
-
-  return EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face),
-                   FXFT_Get_Face_Height(m_Face));
-}
-
-int CFX_Font::GetMaxAdvanceWidth() const {
-  if (!m_Face)
-    return 0;
-
-  return EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face),
-                   FXFT_Get_Face_MaxAdvanceWidth(m_Face));
-}
-
 CFX_FaceCache* CFX_Font::GetFaceCache() const {
   if (!m_FaceCache)
     m_FaceCache = CFX_GEModule::Get()->GetFontCache()->GetCachedFace(this);
@@ -550,22 +525,6 @@
   CFX_GEModule::Get()->GetFontCache()->ReleaseCachedFace(this);
 }
 
-int CFX_Font::GetULPos() const {
-  if (!m_Face)
-    return 0;
-
-  return EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face),
-                   FXFT_Get_Face_UnderLinePosition(m_Face));
-}
-
-int CFX_Font::GetULthickness() const {
-  if (!m_Face)
-    return 0;
-
-  return EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face),
-                   FXFT_Get_Face_UnderLineThickness(m_Face));
-}
-
 void CFX_Font::AdjustMMParams(int glyph_index,
                               int dest_width,
                               int weight) const {
@@ -573,11 +532,13 @@
   FXFT_Get_MM_Var(m_Face, &pMasters);
   if (!pMasters)
     return;
+
   long coords[2];
   if (weight == 0)
     coords[0] = FXFT_Get_MM_Axis_Def(FXFT_Get_MM_Axis(pMasters, 0)) / 65536;
   else
     coords[0] = weight;
+
   if (dest_width == 0) {
     coords[1] = FXFT_Get_MM_Axis_Def(FXFT_Get_MM_Axis(pMasters, 1)) / 65536;
   } else {
@@ -630,9 +591,8 @@
       else
         ft_matrix.xy -= ft_matrix.xx * skew / 100;
     }
-    if (m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM) {
+    if (m_pSubstFont->m_SubstFlags & FXFONT_SUBST_MM)
       AdjustMMParams(glyph_index, dest_width, m_pSubstFont->m_Weight);
-    }
   }
   ScopedFontTransform scoped_transform(m_Face, &ft_matrix);
   int load_flags = FXFT_LOAD_NO_BITMAP;
diff --git a/core/fxge/ge/cfx_renderdevice.cpp b/core/fxge/ge/cfx_renderdevice.cpp
index 3949837..f9153d1 100644
--- a/core/fxge/ge/cfx_renderdevice.cpp
+++ b/core/fxge/ge/cfx_renderdevice.cpp
@@ -961,7 +961,7 @@
   if (anti_alias < FXFT_RENDER_MODE_LCD && glyphs.size() > 1)
     AdjustGlyphSpace(&glyphs);
 
-  FX_RECT bmp_rect1 = FXGE_GetGlyphsBBox(glyphs, anti_alias);
+  FX_RECT bmp_rect1 = FXGE_GetGlyphsBBox(glyphs, anti_alias, 1.0f, 1.0f);
   if (scale_x > 1 && scale_y > 1) {
     bmp_rect1.left--;
     bmp_rect1.top--;