Rename FPDFFont_GetFontName() to FPDFFont_GetFamilyName()
Since FPDFFont_GetFontName() calls CFX_Font::GetFamilyName() internally,
change its name to match what it actually does. As-is, one can confuse
its behavior with that of FPDFText_GetFontInfo(), which also claims to
return the font name.
Change-Id: I6efcbfa0d21eb43bfd37d67a6b55d6bf15e1d866
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/121911
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Tom Sepez <tsepez@google.com>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/fpdfsdk/fpdf_edit_embeddertest.cpp b/fpdfsdk/fpdf_edit_embeddertest.cpp
index 9e0b8a7..6b80f65 100644
--- a/fpdfsdk/fpdf_edit_embeddertest.cpp
+++ b/fpdfsdk/fpdf_edit_embeddertest.cpp
@@ -2917,7 +2917,7 @@
TEST_F(FPDFEditEmbedderTest, TextFontProperties) {
// bad object tests
EXPECT_FALSE(FPDFTextObj_GetFont(nullptr));
- EXPECT_EQ(0U, FPDFFont_GetFontName(nullptr, nullptr, 5));
+ EXPECT_EQ(0U, FPDFFont_GetFamilyName(nullptr, nullptr, 5));
EXPECT_EQ(-1, FPDFFont_GetFlags(nullptr));
EXPECT_EQ(-1, FPDFFont_GetWeight(nullptr));
EXPECT_FALSE(FPDFFont_GetItalicAngle(nullptr, nullptr));
@@ -2970,21 +2970,21 @@
}
{
- // FPDFFont_GetFontName() positive testing.
- unsigned long size = FPDFFont_GetFontName(font, nullptr, 0);
+ // FPDFFont_GetFamilyName() positive testing.
+ unsigned long size = FPDFFont_GetFamilyName(font, nullptr, 0);
const char kExpectedFontName[] = "Liberation Serif";
ASSERT_EQ(sizeof(kExpectedFontName), size);
std::vector<char> font_name(size);
- ASSERT_EQ(size, FPDFFont_GetFontName(font, font_name.data(), size));
+ ASSERT_EQ(size, FPDFFont_GetFamilyName(font, font_name.data(), size));
ASSERT_STREQ(kExpectedFontName, font_name.data());
- // FPDFFont_GetFontName() negative testing.
- ASSERT_EQ(0U, FPDFFont_GetFontName(nullptr, nullptr, 0));
+ // FPDFFont_GetFamilyName() negative testing.
+ ASSERT_EQ(0U, FPDFFont_GetFamilyName(nullptr, nullptr, 0));
font_name.resize(2);
font_name[0] = 'x';
font_name[1] = '\0';
- size = FPDFFont_GetFontName(font, font_name.data(), font_name.size());
+ size = FPDFFont_GetFamilyName(font, font_name.data(), font_name.size());
ASSERT_EQ(sizeof(kExpectedFontName), size);
ASSERT_STREQ("x", font_name.data());
}
diff --git a/fpdfsdk/fpdf_edittext.cpp b/fpdfsdk/fpdf_edittext.cpp
index 9fcf7dd..9126c61 100644
--- a/fpdfsdk/fpdf_edittext.cpp
+++ b/fpdfsdk/fpdf_edittext.cpp
@@ -850,14 +850,15 @@
}
FPDF_EXPORT unsigned long FPDF_CALLCONV
-FPDFFont_GetFontName(FPDF_FONT font, char* buffer, unsigned long length) {
- auto* pFont = CPDFFontFromFPDFFont(font);
- if (!pFont)
+FPDFFont_GetFamilyName(FPDF_FONT font, char* buffer, unsigned long length) {
+ auto* cfont = CPDFFontFromFPDFFont(font);
+ if (!cfont) {
return 0;
+ }
// SAFETY: required from caller.
auto result_span = UNSAFE_BUFFERS(SpanFromFPDFApiArgs(buffer, length));
- ByteString name = pFont->GetFont()->GetFamilyName();
+ ByteString name = cfont->GetFont()->GetFamilyName();
pdfium::span<const char> name_span = name.span_with_terminator();
fxcrt::try_spancpy(result_span, name_span);
return static_cast<unsigned long>(name_span.size());
diff --git a/fpdfsdk/fpdf_view_c_api_test.c b/fpdfsdk/fpdf_view_c_api_test.c
index 6ccea4e..ee8ef35 100644
--- a/fpdfsdk/fpdf_view_c_api_test.c
+++ b/fpdfsdk/fpdf_view_c_api_test.c
@@ -164,9 +164,9 @@
CHK(FPDFFont_Close);
CHK(FPDFFont_GetAscent);
CHK(FPDFFont_GetDescent);
+ CHK(FPDFFont_GetFamilyName);
CHK(FPDFFont_GetFlags);
CHK(FPDFFont_GetFontData);
- CHK(FPDFFont_GetFontName);
CHK(FPDFFont_GetGlyphPath);
CHK(FPDFFont_GetGlyphWidth);
CHK(FPDFFont_GetIsEmbedded);
diff --git a/public/fpdf_edit.h b/public/fpdf_edit.h
index deae22f..9607b2e 100644
--- a/public/fpdf_edit.h
+++ b/public/fpdf_edit.h
@@ -1356,20 +1356,20 @@
FPDF_EXPORT FPDF_FONT FPDF_CALLCONV FPDFTextObj_GetFont(FPDF_PAGEOBJECT text);
// Experimental API.
-// Get the font name of a font.
+// Get the family name of a font.
//
// font - the handle to the font object.
// buffer - the address of a buffer that receives the font name.
// length - the size, in bytes, of |buffer|.
//
-// Returns the number of bytes in the font name (including the trailing NUL
+// Returns the number of bytes in the family name (including the trailing NUL
// character) on success, 0 on error.
//
// Regardless of the platform, the |buffer| is always in UTF-8 encoding.
// If |length| is less than the returned length, or |buffer| is NULL, |buffer|
// will not be modified.
FPDF_EXPORT unsigned long FPDF_CALLCONV
-FPDFFont_GetFontName(FPDF_FONT font, char* buffer, unsigned long length);
+FPDFFont_GetFamilyName(FPDF_FONT font, char* buffer, unsigned long length);
// Experimental API.
// Get the decoded data from the |font| object.