Move all FT_Load_Glyph calls into CFX_Face for consistency
This change organizes calling FT_Load_Glyph by making sure all callers
of said function remain in core/fxge/cfx_face.cpp. A new function was
added that is called from the other files to avoid the usage of
FT_Load_Glyph in other locations (viz.
core/fpdfapi/font/cpdf_simplefont.cpp and core/fxge/cfx_font.cpp).
Bug: 452079358
Change-Id: I10f89d439451c80db6b6fc2fe97cdfc78fd73cff
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/137110
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/font/cpdf_simplefont.cpp b/core/fpdfapi/font/cpdf_simplefont.cpp
index bd2fa82..bda6fe2c 100644
--- a/core/fpdfapi/font/cpdf_simplefont.cpp
+++ b/core/fpdfapi/font/cpdf_simplefont.cpp
@@ -15,8 +15,8 @@
#include "core/fpdfapi/parser/cpdf_array.h"
#include "core/fpdfapi/parser/cpdf_dictionary.h"
#include "core/fpdfapi/parser/cpdf_name.h"
+#include "core/fxge/cfx_face.h"
#include "core/fxcrt/fx_codepage.h"
-#include "core/fxge/freetype/fx_freetype.h"
#include "core/fxge/fx_font.h"
namespace {
@@ -86,16 +86,13 @@
return;
}
- FXFT_FaceRec* face_rec = face->GetRec();
- int err =
- FT_Load_Glyph(face_rec, glyph_index,
- FT_LOAD_NO_SCALE | FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH);
+ int err = face->LoadGlyph(glyph_index, /*scale=*/false);
if (err) {
return;
}
char_bbox_[charcode] = face->GetGlyphBBox();
-
+ FXFT_FaceRec* face_rec = face->GetRec();
if (use_font_width_) {
int TT_Width = NormalizeFontMetric(FXFT_Get_Glyph_HoriAdvance(face_rec),
face->GetUnitsPerEm());
diff --git a/core/fxge/cfx_face.cpp b/core/fxge/cfx_face.cpp
index 2e40780..56a4520 100644
--- a/core/fxge/cfx_face.cpp
+++ b/core/fxge/cfx_face.cpp
@@ -664,6 +664,14 @@
return FT_Get_Name_Index(GetRec(), name);
}
+int CFX_Face::LoadGlyph(uint32_t glyph_index, bool scale) {
+ FT_Int32 args = FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH;
+ if (!scale) {
+ args |= FT_LOAD_NO_SCALE;
+ }
+ return FT_Load_Glyph(GetRec(), glyph_index, args);
+}
+
FX_RECT CFX_Face::GetCharBBox(uint32_t code, int glyph_index) {
FX_RECT rect;
FXFT_FaceRec* rec = GetRec();
diff --git a/core/fxge/cfx_face.h b/core/fxge/cfx_face.h
index 5f5ce83..fc46f98 100644
--- a/core/fxge/cfx_face.h
+++ b/core/fxge/cfx_face.h
@@ -128,6 +128,7 @@
int GetCharMapEncodingIdByIndex(size_t index) const;
fxge::FontEncoding GetCharMapEncodingByIndex(size_t index) const;
size_t GetCharMapCount() const;
+ int LoadGlyph(uint32_t glyph_index, bool scale);
void SetCharMap(CharMap map);
void SetCharMapByIndex(size_t index);
bool SelectCharMap(fxge::FontEncoding encoding);
diff --git a/core/fxge/cfx_font.cpp b/core/fxge/cfx_font.cpp
index 9dc4447..06caf1c 100644
--- a/core/fxge/cfx_font.cpp
+++ b/core/fxge/cfx_font.cpp
@@ -21,6 +21,7 @@
#include "core/fxcrt/numerics/safe_conversions.h"
#include "core/fxcrt/span.h"
#include "core/fxcrt/unowned_ptr.h"
+#include "core/fxge/cfx_face.h"
#include "core/fxge/cfx_fontcache.h"
#include "core/fxge/cfx_fontmapper.h"
#include "core/fxge/cfx_fontmgr.h"
@@ -324,8 +325,7 @@
return std::nullopt;
}
- error = FT_Load_Glyph(face_->GetRec(), glyph_index,
- FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH);
+ error = face_->LoadGlyph(glyph_index, /*scale=*/true);
if (error) {
return std::nullopt;
}
@@ -351,9 +351,7 @@
}
return result;
}
- static constexpr int kFlag =
- FT_LOAD_NO_SCALE | FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH;
- if (FT_Load_Glyph(face_->GetRec(), glyph_index, kFlag) != 0) {
+ if (face_->LoadGlyph(glyph_index, /*scale=*/false) != 0) {
return std::nullopt;
}
int em = face_->GetUnitsPerEm();