Encapsulate FT_Set_Pixel_Sizes()
Add CFX_Face::SetPixelSize() and change callers to use that instead of
calling FT_Set_Pixel_Sizes() directly.
Bug: pdfium:2037
Change-Id: I8f8b0df6e9dcfe7c3290c2d7f0c25c1c3bbc99d5
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/116390
Reviewed-by: Dominik Röttsches <drott@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxge/android/cfpf_skiafontmgr.cpp b/core/fxge/android/cfpf_skiafontmgr.cpp
index baa4e38..3052617 100644
--- a/core/fxge/android/cfpf_skiafontmgr.cpp
+++ b/core/fxge/android/cfpf_skiafontmgr.cpp
@@ -335,7 +335,7 @@
if (!face)
return nullptr;
- FT_Set_Pixel_Sizes(face->GetRec(), 0, 64);
+ face->SetPixelSize(0, 64);
return face;
}
diff --git a/core/fxge/cfx_face.cpp b/core/fxge/cfx_face.cpp
index 7d9cd0f..7b1458a 100644
--- a/core/fxge/cfx_face.cpp
+++ b/core/fxge/cfx_face.cpp
@@ -778,6 +778,11 @@
return !error;
}
+bool CFX_Face::SetPixelSize(uint32_t width, uint32_t height) {
+ FT_Error error = FT_Set_Pixel_Sizes(GetRec(), width, height);
+ return !error;
+}
+
#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 ce8d693..1cba75f 100644
--- a/core/fxge/cfx_face.h
+++ b/core/fxge/cfx_face.h
@@ -117,6 +117,8 @@
void SetCharMapByIndex(size_t index);
bool SelectCharMap(fxge::FontEncoding encoding);
+ bool SetPixelSize(uint32_t width, uint32_t height);
+
#if BUILDFLAG(IS_WIN)
bool CanEmbed();
#endif
diff --git a/core/fxge/cfx_font.cpp b/core/fxge/cfx_font.cpp
index ff97860..98ab8ea 100644
--- a/core/fxge/cfx_font.cpp
+++ b/core/fxge/cfx_font.cpp
@@ -191,7 +191,7 @@
m_pOwnedFile = std::move(pFile);
m_pOwnedStreamRec = std::move(pStreamRec);
- FT_Set_Pixel_Sizes(m_Face->GetRec(), 0, 64);
+ m_Face->SetPixelSize(0, 64);
return true;
}
@@ -317,8 +317,9 @@
result.bottom =
std::max(result.bottom, static_cast<int>(m_Face->GetDescender()));
FT_Done_Glyph(glyph);
- if (FT_Set_Pixel_Sizes(m_Face->GetRec(), 0, 64) != 0)
+ if (!m_Face->SetPixelSize(0, 64)) {
return std::nullopt;
+ }
return result;
}
constexpr int kFlag = FT_LOAD_NO_SCALE | FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH;
diff --git a/core/fxge/cfx_fontmgr.cpp b/core/fxge/cfx_fontmgr.cpp
index a7070e1..f04b7dd 100644
--- a/core/fxge/cfx_fontmgr.cpp
+++ b/core/fxge/cfx_fontmgr.cpp
@@ -119,11 +119,9 @@
RetainPtr<CFX_Face> face =
CFX_Face::New(m_FTLibrary.get(), std::move(pDesc), span,
static_cast<FT_Long>(face_index));
- if (!face)
+ if (!face || !face->SetPixelSize(64, 64)) {
return nullptr;
-
- if (FT_Set_Pixel_Sizes(face->GetRec(), 64, 64) != 0)
- return nullptr;
+ }
return face;
}
diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp
index eb3d8ae..c1f516d 100644
--- a/xfa/fgas/font/cfgas_fontmgr.cpp
+++ b/xfa/fgas/font/cfgas_fontmgr.cpp
@@ -517,7 +517,7 @@
ft_sfree(ftStream);
return nullptr;
}
- FT_Set_Pixel_Sizes(pFace->GetRec(), 0, 64);
+ pFace->SetPixelSize(0, 64);
return pFace;
}