Re-enable pdfium_noshorten_config on android.
Add casts between FT_Long (which may be 64 bits of which 32
are used) and int32_t in a few places.
-- Convert FPF_GetHashCode_StringA()to size_t and remove unreachable
"-1 means unknown size" path.
-- Rewrite FPF_SKIANormalizeFontName() to match
FPF_GetHashCode_StringA()
Change-Id: I64f4190fbcdd92bb4b468a3f5d20a06bac068ed7
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/91214
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxge/BUILD.gn b/core/fxge/BUILD.gn
index 23437a1..18b15b7 100644
--- a/core/fxge/BUILD.gn
+++ b/core/fxge/BUILD.gn
@@ -161,9 +161,6 @@
"android/cfx_androidfontinfo.h",
"android/fx_android_impl.cpp",
]
-
- # TODO(tsepez): Enable on Android.
- configs -= [ "../../:pdfium_noshorten_config" ]
}
if (is_linux || is_chromeos || is_fuchsia) {
diff --git a/core/fxge/android/cfpf_skiafont.cpp b/core/fxge/android/cfpf_skiafont.cpp
index df1139e..fbfdbdd 100644
--- a/core/fxge/android/cfpf_skiafont.cpp
+++ b/core/fxge/android/cfpf_skiafont.cpp
@@ -57,8 +57,9 @@
FT_LOAD_NO_SCALE | FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH)) {
return 0;
}
- return FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(GetFaceRec()),
- FXFT_Get_Glyph_HoriAdvance(GetFaceRec()));
+ return static_cast<int32_t>(
+ FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(GetFaceRec()),
+ FXFT_Get_Glyph_HoriAdvance(GetFaceRec())));
}
int32_t CFPF_SkiaFont::GetAscent() const {
@@ -95,10 +96,10 @@
FT_Glyph_Get_CBox(glyph, FT_GLYPH_BBOX_PIXELS, &cbox);
int32_t x_ppem = GetFaceRec()->size->metrics.x_ppem;
int32_t y_ppem = GetFaceRec()->size->metrics.y_ppem;
- rtBBox.left = FPF_EM_ADJUST(x_ppem, cbox.xMin);
- rtBBox.right = FPF_EM_ADJUST(x_ppem, cbox.xMax);
- rtBBox.top = FPF_EM_ADJUST(y_ppem, cbox.yMax);
- rtBBox.bottom = FPF_EM_ADJUST(y_ppem, cbox.yMin);
+ rtBBox.left = static_cast<int32_t>(FPF_EM_ADJUST(x_ppem, cbox.xMin));
+ rtBBox.right = static_cast<int32_t>(FPF_EM_ADJUST(x_ppem, cbox.xMax));
+ rtBBox.top = static_cast<int32_t>(FPF_EM_ADJUST(y_ppem, cbox.yMax));
+ rtBBox.bottom = static_cast<int32_t>(FPF_EM_ADJUST(y_ppem, cbox.yMin));
rtBBox.top = std::min(rtBBox.top, GetAscent());
rtBBox.bottom = std::max(rtBBox.bottom, GetDescent());
FT_Done_Glyph(glyph);
@@ -108,16 +109,20 @@
FT_LOAD_NO_SCALE | FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH)) {
return false;
}
- rtBBox.left = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(GetFaceRec()),
- FXFT_Get_Glyph_HoriBearingX(GetFaceRec()));
- rtBBox.bottom = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(GetFaceRec()),
- FXFT_Get_Glyph_HoriBearingY(GetFaceRec()));
- rtBBox.right = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(GetFaceRec()),
- FXFT_Get_Glyph_HoriBearingX(GetFaceRec()) +
- FXFT_Get_Glyph_Width(GetFaceRec()));
- rtBBox.top = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(GetFaceRec()),
- FXFT_Get_Glyph_HoriBearingY(GetFaceRec()) -
- FXFT_Get_Glyph_Height(GetFaceRec()));
+ rtBBox.left = static_cast<int32_t>(
+ FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(GetFaceRec()),
+ FXFT_Get_Glyph_HoriBearingX(GetFaceRec())));
+ rtBBox.bottom = static_cast<int32_t>(
+ FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(GetFaceRec()),
+ FXFT_Get_Glyph_HoriBearingY(GetFaceRec())));
+ rtBBox.right = static_cast<int32_t>(
+ FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(GetFaceRec()),
+ FXFT_Get_Glyph_HoriBearingX(GetFaceRec()) +
+ FXFT_Get_Glyph_Width(GetFaceRec())));
+ rtBBox.top = static_cast<int32_t>(
+ FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(GetFaceRec()),
+ FXFT_Get_Glyph_HoriBearingY(GetFaceRec()) -
+ FXFT_Get_Glyph_Height(GetFaceRec())));
return true;
}
@@ -125,14 +130,18 @@
if (!m_Face) {
return false;
}
- rtBBox.left = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(GetFaceRec()),
- FXFT_Get_Face_xMin(GetFaceRec()));
- rtBBox.top = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(GetFaceRec()),
- FXFT_Get_Face_yMin(GetFaceRec()));
- rtBBox.right = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(GetFaceRec()),
- FXFT_Get_Face_xMax(GetFaceRec()));
- rtBBox.bottom = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(GetFaceRec()),
- FXFT_Get_Face_yMax(GetFaceRec()));
+ rtBBox.left =
+ static_cast<int32_t>(FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(GetFaceRec()),
+ FXFT_Get_Face_xMin(GetFaceRec())));
+ rtBBox.top =
+ static_cast<int32_t>(FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(GetFaceRec()),
+ FXFT_Get_Face_yMin(GetFaceRec())));
+ rtBBox.right =
+ static_cast<int32_t>(FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(GetFaceRec()),
+ FXFT_Get_Face_xMax(GetFaceRec())));
+ rtBBox.bottom =
+ static_cast<int32_t>(FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(GetFaceRec()),
+ FXFT_Get_Face_yMax(GetFaceRec())));
return true;
}
@@ -149,7 +158,7 @@
auto* info = static_cast<TT_Postscript*>(
FT_Get_Sfnt_Table(GetFaceRec(), ft_sfnt_post));
- return info ? info->italicAngle : 0;
+ return info ? static_cast<int32_t>(info->italicAngle) : 0;
}
uint32_t CFPF_SkiaFont::GetFontData(uint32_t dwTable,
diff --git a/core/fxge/android/cfpf_skiafontmgr.cpp b/core/fxge/android/cfpf_skiafontmgr.cpp
index 88b94e4..6cbb019 100644
--- a/core/fxge/android/cfpf_skiafontmgr.cpp
+++ b/core/fxge/android/cfpf_skiafontmgr.cpp
@@ -65,18 +65,6 @@
return 0;
}
-uint32_t FPF_GetHashCode_StringA(const char* pStr, int32_t iLength) {
- if (!pStr)
- return 0;
- if (iLength < 0)
- iLength = strlen(pStr);
- const char* pStrEnd = pStr + iLength;
- uint32_t uHashCode = 0;
- while (pStr < pStrEnd)
- uHashCode = 31 * uHashCode + tolower(*pStr++);
- return uHashCode;
-}
-
enum FPF_SKIACHARSET {
FPF_SKIACHARSET_Ansi = 1 << 0,
FPF_SKIACHARSET_Default = 1 << 1,
@@ -135,17 +123,21 @@
return FPF_SKIACHARSET_Default;
}
-uint32_t FPF_SKIANormalizeFontName(ByteStringView bsfamily) {
- uint32_t dwHash = 0;
- int32_t iLength = bsfamily.GetLength();
- const char* pBuffer = bsfamily.unterminated_c_str();
- for (int32_t i = 0; i < iLength; i++) {
- char ch = pBuffer[i];
+uint32_t FPF_GetHashCode_StringA(ByteStringView bsStr) {
+ uint32_t uHashCode = 0;
+ for (char ch : bsStr)
+ uHashCode = 31 * uHashCode + tolower(ch);
+ return uHashCode;
+}
+
+uint32_t FPF_SKIANormalizeFontName(ByteStringView bsFamily) {
+ uint32_t uHashCode = 0;
+ for (char ch : bsFamily) {
if (ch == ' ' || ch == '-' || ch == ',')
continue;
- dwHash = 31 * dwHash + tolower(ch);
+ uHashCode = 31 * uHashCode + tolower(ch);
}
- return dwHash;
+ return uHashCode;
}
uint32_t FPF_SKIAGetFamilyHash(ByteStringView bsFamily,
@@ -159,7 +151,7 @@
if (FontStyleIsSerif(dwStyle))
bsFont += "Serif";
bsFont += static_cast<uint8_t>(uCharset);
- return FPF_GetHashCode_StringA(bsFont.c_str(), bsFont.GetLength());
+ return FPF_GetHashCode_StringA(bsFont.AsStringView());
}
bool FPF_SkiaIsCJK(FX_Charset uCharset) {