Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions core/libs/prx/libfontconfig/Export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ static bool IsSubset(const FcCharSet& subset, const FcCharSet& superset) {
return true;
}

static bool ReadCharmapEncoding(FreeType::GuestFaceRec* face, std::int32_t& encoding, bool& hasCharmap) {
FreeType::GuestCharMapRec* charmap = nullptr;
if (!CopyGuestIn(&charmap, &face->charmap, sizeof(charmap))) return false;
hasCharmap = (charmap != nullptr);
if (!hasCharmap) {
encoding = 0;
return true;
}
return CopyGuestIn(&encoding, &charmap->encoding, sizeof(encoding));
}

extern "C" {

FcConfig* APS5_VABI FcConfigGetCurrent() {
Expand Down Expand Up @@ -133,12 +144,15 @@ FcCharSet* APS5_VABI FcCharSetCreate() {

std::uint32_t APS5_VABI FcFreeTypeCharIndex(FreeType::GuestFaceRec* face, std::uint32_t character) {
if (!face) return 0;
std::int32_t current = 0;
bool hasCharmap = false;
if (!ReadCharmapEncoding(face, current, hasCharmap)) return 0;
constexpr std::array encodings{FT_ENCODING_UNICODE, FT_ENCODING_MS_SYMBOL};
const auto current = face->charmap ? face->charmap->encoding : 0;
const std::size_t initial = current == encodings[1] ? 1 : 0;
const std::size_t initial = (hasCharmap && current == encodings[1]) ? 1 : 0;
for (std::size_t offset = 0; offset < encodings.size(); ++offset) {
const auto encoding = encodings[(initial + offset) % encodings.size()];
if ((!face->charmap || face->charmap->encoding != encoding) &&
if (!ReadCharmapEncoding(face, current, hasCharmap)) return 0;
if ((!hasCharmap || current != encoding) &&
FT_Select_Charmap_nid_postfix(face, encoding) != 0) continue;
if (const auto glyph = FT_Get_Char_Index_nid_postfix(face, character)) return glyph;
if (character < 0x100 && encoding == FT_ENCODING_MS_SYMBOL) {
Expand Down
4 changes: 4 additions & 0 deletions core/libs/tests/GuestFontconfigCharIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ std::vector<unsigned char> SymbolOnlyFont(std::uint32_t codepoint, int width) {

int main() {
Require(FcFreeTypeCharIndex(nullptr, 'A') == 0);
Require(FcFreeTypeCharIndex(reinterpret_cast<FreeType::GuestFaceRec*>(std::uintptr_t{0x10}), 'A') == 0);
FreeType::GuestFaceRec unreadableCharmapFace{};
unreadableCharmapFace.charmap = reinterpret_cast<FreeType::GuestCharMapRec*>(std::uintptr_t{0x10});
Require(FcFreeTypeCharIndex(&unreadableCharmapFace, 'A') == 0);
const auto font = SquareGlyphFont('A', 700, true);
FreeType::GuestLibrary* library = nullptr;
Require(FT_Init_FreeType_nid_postfix(&library) == 0);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# libfontconfig

## change [FreeType character lookup]

- [FreeType character lookup](../../../core/libs/prx/libfontconfig/Export.cpp): `FcFreeTypeCharIndex` follows the pinned Fontconfig `fcfreetype.c` search order: current Unicode or Microsoft Symbol charmap first, then the other; symbol characters below U+0100 also try U+F000 offset. It calls libSceFreeType's guest face exports, so only faces created by that adapter are supported. The console's Fontconfig version, call signature and behavior are unmeasured. Returning 0 for an unreadable guest face or charmap pointer through `GuestCopyIn_nid_no_patch` is a host-safety fallback.
Loading