Move NormalizeFontMetric() out of CPDF_Font

Move this static method out of CPDF_Font, as it can be a standalone
function now. Move it into core/fxge, so it can be used by other
core/fxge code in the near future.

Change-Id: I185d988cf5164abcf907ddf214030497133d82d9
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/115771
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Dominik Röttsches <drott@chromium.org>
Reviewed-by: Thomas Sepez <tsepez@google.com>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/font/cpdf_font.cpp b/core/fpdfapi/font/cpdf_font.cpp
index 6726cf8..7432814 100644
--- a/core/fpdfapi/font/cpdf_font.cpp
+++ b/core/fpdfapi/font/cpdf_font.cpp
@@ -35,7 +35,6 @@
 #include "core/fxge/fx_font.h"
 #include "third_party/base/check.h"
 #include "third_party/base/numerics/clamped_math.h"
-#include "third_party/base/numerics/safe_conversions.h"
 
 namespace {
 
@@ -408,16 +407,6 @@
 }
 
 // static
-int CPDF_Font::NormalizeFontMetric(int64_t value, uint16_t upem) {
-  if (upem == 0) {
-    return pdfium::base::saturated_cast<int>(value);
-  }
-
-  const double scaled_value = (value * 1000.0 + upem / 2) / upem;
-  return pdfium::base::saturated_cast<int>(scaled_value);
-}
-
-// static
 FX_RECT CPDF_Font::GetCharBBoxForFace(const RetainPtr<CFX_Face>& face) {
   FXFT_FaceRec* rec = face->GetRec();
   pdfium::base::ClampedNumeric<FT_Pos> left = FXFT_Get_Glyph_HoriBearingX(rec);
diff --git a/core/fpdfapi/font/cpdf_font.h b/core/fpdfapi/font/cpdf_font.h
index 7c733eb..84e45a9 100644
--- a/core/fpdfapi/font/cpdf_font.h
+++ b/core/fpdfapi/font/cpdf_font.h
@@ -139,11 +139,6 @@
   CPDF_Font(CPDF_Document* pDocument, RetainPtr<CPDF_Dictionary> pFontDict);
   ~CPDF_Font() override;
 
-  // Take a font metric `value` and scale it down by the font's `upem`. If the
-  // font is not scalable, i.e. `upem` is 0, then return `value` as is.
-  // If the computed result is excessively large and does not fit in an int,
-  // NormalizeFontMetric() handles that with `saturated_cast()`.
-  static int NormalizeFontMetric(int64_t value, uint16_t upem);
   static FX_RECT GetCharBBoxForFace(const RetainPtr<CFX_Face>& face);
 
   // Commonly used wrappers for UseTTCharmap().
diff --git a/core/fxge/fx_font.cpp b/core/fxge/fx_font.cpp
index f0f3576..887629b 100644
--- a/core/fxge/fx_font.cpp
+++ b/core/fxge/fx_font.cpp
@@ -4,6 +4,8 @@
 
 #include "core/fxge/fx_font.h"
 
+#include <stdint.h>
+
 #include <algorithm>
 
 #include "core/fxcrt/fx_safe_types.h"
@@ -13,6 +15,7 @@
 #include "core/fxge/dib/cfx_dibitmap.h"
 #include "core/fxge/freetype/fx_freetype.h"
 #include "core/fxge/text_glyph_pos.h"
+#include "third_party/base/numerics/safe_conversions.h"
 
 namespace {
 
@@ -144,3 +147,12 @@
   FXFT_adobe_name_from_unicode(glyph_name, unicode);
   return ByteString(glyph_name);
 }
+
+int NormalizeFontMetric(int64_t value, uint16_t upem) {
+  if (upem == 0) {
+    return pdfium::base::saturated_cast<int>(value);
+  }
+
+  const double scaled_value = (value * 1000.0 + upem / 2) / upem;
+  return pdfium::base::saturated_cast<int>(scaled_value);
+}
diff --git a/core/fxge/fx_font.h b/core/fxge/fx_font.h
index daa48cd..2644e62 100644
--- a/core/fxge/fx_font.h
+++ b/core/fxge/fx_font.h
@@ -7,6 +7,8 @@
 #ifndef CORE_FXGE_FX_FONT_H_
 #define CORE_FXGE_FX_FONT_H_
 
+#include <stdint.h>
+
 #include <vector>
 
 #include "core/fxcrt/bytestring.h"
@@ -94,4 +96,10 @@
 wchar_t UnicodeFromAdobeName(const char* name);
 ByteString AdobeNameFromUnicode(wchar_t unicode);
 
+// Take a font metric `value` and scale it down by the font's `upem`. If the
+// font is not scalable, i.e. `upem` is 0, then return `value` as is.
+// If the computed result is excessively large and does not fit in an int,
+// NormalizeFontMetric() handles that with `saturated_cast()`.
+int NormalizeFontMetric(int64_t value, uint16_t upem);
+
 #endif  // CORE_FXGE_FX_FONT_H_