Remove CFX_Face::GetRec() callers from CFGAS_FontMgr
Rewrite code that access struct FT_FaceRec_ fields directly.
1) Call CFX_Face::GetFamilyName() instead of accessing family_name.
2) Change CFGAS_FontMgr::RegisterFaces() to tell RegisterFace() the
face index, instead of retrieving the same value from face_index.
3) Add CFX_Face::GetNumFaces() to encapsulate the code that accesses
num_faces.
Bug: 460068801
Change-Id: I2b79ee6d13fb4ef76adf07e60a58ea8690b39d46
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/138172
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxge/cfx_face.cpp b/core/fxge/cfx_face.cpp
index 995affc..ecfd21f 100644
--- a/core/fxge/cfx_face.cpp
+++ b/core/fxge/cfx_face.cpp
@@ -857,6 +857,12 @@
return !error;
}
+#if defined(PDF_ENABLE_XFA)
+int CFX_Face::GetNumFaces() const {
+ return pdfium::checked_cast<int>(GetRec()->num_faces);
+}
+#endif
+
#if BUILDFLAG(IS_WIN)
bool CFX_Face::CanEmbed() {
FT_UShort fstype = FT_Get_FSType_Flags(GetRec());
diff --git a/core/fxge/cfx_face.h b/core/fxge/cfx_face.h
index 64dd422..d16aeba 100644
--- a/core/fxge/cfx_face.h
+++ b/core/fxge/cfx_face.h
@@ -145,6 +145,10 @@
bool SetPixelSize(uint32_t width, uint32_t height);
+#if defined(PDF_ENABLE_XFA)
+ int GetNumFaces() const;
+#endif
+
#if BUILDFLAG(IS_WIN)
bool CanEmbed();
#endif
diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp
index ffac5e8..6fa9dc1 100644
--- a/xfa/fgas/font/cfgas_fontmgr.cpp
+++ b/xfa/fgas/font/cfgas_fontmgr.cpp
@@ -27,7 +27,6 @@
#include "core/fxcrt/fx_extension.h"
#include "core/fxcrt/fx_memcpy_wrappers.h"
#include "core/fxcrt/fx_system.h"
-#include "core/fxcrt/numerics/safe_conversions.h"
#include "core/fxcrt/span.h"
#include "core/fxcrt/stl_util.h"
#include "core/fxge/cfx_font.h"
@@ -706,6 +705,7 @@
}
void CFGAS_FontMgr::RegisterFace(RetainPtr<CFX_Face> face,
+ int face_index,
const WideString& wsFaceName) {
if (!face->IsScalable()) {
return;
@@ -743,27 +743,29 @@
}
font->family_names_ = GetNames(table);
font->family_names_.push_back(
- WideString::FromUTF8(face->GetRec()->family_name));
+ WideString::FromUTF8(face->GetFamilyName().AsStringView()));
font->face_name_ = wsFaceName;
- font->face_index_ = pdfium::checked_cast<int32_t>(face->GetRec()->face_index);
+ font->face_index_ = face_index;
installed_fonts_.push_back(std::move(font));
}
void CFGAS_FontMgr::RegisterFaces(
const RetainPtr<IFX_SeekableReadStream>& font_stream,
const WideString& wsFaceName) {
- int32_t index = 0;
- int32_t num_faces = 0;
+ int index = 0;
+ int num_faces = 0;
do {
- RetainPtr<CFX_Face> face = LoadFace(font_stream, index++);
+ RetainPtr<CFX_Face> face = LoadFace(font_stream, index);
if (!face) {
+ ++index;
continue;
}
// All faces keep number of faces. It can be retrieved from any one face.
if (num_faces == 0) {
- num_faces = pdfium::checked_cast<int32_t>(face->GetRec()->num_faces);
+ num_faces = face->GetNumFaces();
}
- RegisterFace(face, wsFaceName);
+ RegisterFace(face, index, wsFaceName);
+ ++index;
} while (index < num_faces);
}
diff --git a/xfa/fgas/font/cfgas_fontmgr.h b/xfa/fgas/font/cfgas_fontmgr.h
index 85b84f9..5c6fc4d 100644
--- a/xfa/fgas/font/cfgas_fontmgr.h
+++ b/xfa/fgas/font/cfgas_fontmgr.h
@@ -121,7 +121,9 @@
#else // BUILDFLAG(IS_WIN)
bool EnumFontsFromFontMapper();
- void RegisterFace(RetainPtr<CFX_Face> face, const WideString& wsFaceName);
+ void RegisterFace(RetainPtr<CFX_Face> face,
+ int face_index,
+ const WideString& wsFaceName);
void RegisterFaces(const RetainPtr<IFX_SeekableReadStream>& font_stream,
const WideString& wsFaceName);
std::vector<CFGAS_FontDescriptorInfo> MatchFonts(FX_CodePage wCodePage,