Merge pull request #461 from oneandonlydean/feat/font-system-font-sets

feat(font): open system font sets from a font directory
This commit is contained in:
Dean
2026-10-06 10:30:44 +13:00
committed by GitHub
12 changed files with 492 additions and 54 deletions
+6 -1
View File
@@ -12,8 +12,13 @@ if(BUILD_TESTING)
target_include_directories(guest_font_tests PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(guest_font_tests PRIVATE libSceFont libSceFontFt libc)
add_test(NAME guest_font COMMAND guest_font_tests)
add_test_executable(guest_system_font_tests ${LIBS_INCLUDE_DIR}/tests/GuestSystemFont.cpp)
target_include_directories(guest_system_font_tests PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(guest_system_font_tests PRIVATE libSceFont libSceFontFt libc)
configure_windows_unwind(guest_system_font_tests)
add_test(NAME guest_system_font COMMAND guest_system_font_tests)
if(WIN32)
set_tests_properties(guest_font PROPERTIES ENVIRONMENT_MODIFICATION
set_tests_properties(guest_font guest_system_font PROPERTIES ENVIRONMENT_MODIFICATION
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceFont>")
endif()
endif()
@@ -7,6 +7,7 @@ function(add_sce_font_library target)
${fontDir}/src/Render.cpp
${fontDir}/src/State.cpp
${fontDir}/src/Style.cpp
${fontDir}/src/SystemFont.cpp
${fontDir}/src/Text.cpp
${fontDir}/src/Unimplemented.cpp
)
@@ -23,6 +23,7 @@ constexpr std::uint16_t STYLE_FRAME_MAGIC = 0x0F09;
constexpr std::uint32_t LOCK_BIT = 0x80000000u;
constexpr std::uint32_t OPEN_BIT = 0x40000000u;
constexpr std::uint32_t COUNT_MASK = 0x0FFFFFFFu;
constexpr std::uint64_t SYSFONT_FLAG_SYSTEM_SET = 0x100u;
constexpr std::size_t HORIZONTAL_LAYOUT_SIZE = 0x30;
constexpr std::size_t HORIZONTAL_LINE_ADVANCE = 0x00;
@@ -6,6 +6,9 @@
#include <cstddef>
#include <cstdint>
#include <filesystem>
#include <memory>
#include <optional>
#include <vector>
#include <ft2build.h>
@@ -21,7 +24,7 @@ constexpr std::uint8_t STYLE_FRAME_FLAG_WEIGHT = 0x04;
constexpr float POINTS_PER_INCH = 72.0f;
struct FontState {
std::vector<unsigned char> faceData;
std::shared_ptr<const std::vector<unsigned char>> faceData;
FT_Face face = nullptr;
float scaleW = 16.0f;
float scaleH = 16.0f;
@@ -48,6 +51,11 @@ struct GeneratedGlyph {
bool outlineInitialized = false;
};
struct SystemFontFile {
std::filesystem::path path;
std::uint32_t subFontIndex = 0;
};
struct RenderSurfaceSystemUse {
FontStyleFrame* styleframe;
float catchedScale;
@@ -70,12 +78,18 @@ void** EntryObjectSlot(FontCtxEntry* entry, std::uint32_t modeLow);
FontCtxEntry* AcquireFontCtxEntry(void* ctx, std::uint32_t index, std::uint32_t modeLow, FontObj** outObject, std::uint32_t* outLockWord);
void ReleaseFontCtxEntryLock(FontCtxEntry* entry, std::uint32_t modeLow, std::uint32_t lockWord);
FontObj* FindSubFont(FontObj* head, std::uint32_t subFontIndex);
void* FontContext(const FontLibNative* library, const FontHandleNative* font);
void ReleaseFontObjectsForHandle(FontHandleNative* font);
FontState* TryGetState(FontHandle handle);
FontState& ResetState(FontHandle handle);
void RemoveState(FontHandle handle);
void LoadStateFace(FontState& state, std::vector<unsigned char> bytes, std::uint32_t subFontIndex);
void LoadStateFace(FontState& state, std::shared_ptr<const std::vector<unsigned char>> bytes, std::uint32_t subFontIndex);
bool IsSystemFontSet(std::uint32_t fontSetType);
std::vector<SystemFontFile> SystemFontCandidates(std::uint32_t fontSetType);
std::filesystem::path SystemFontDirectory();
std::optional<SystemFontFile> FindSystemFontFile(std::uint32_t fontSetType);
void TrackGeneratedGlyph(FontGlyph glyph);
bool ForgetGeneratedGlyph(FontGlyph glyph);
+5 -5
View File
@@ -212,7 +212,7 @@ int Font::ComputeHorizontalLayout(FontHandle handle, const StyleStateBlock* styl
auto* font = GetNativeFont(handle);
if (!font) return fail();
auto* library = static_cast<FontLibNative*>(font->library);
if (!library || !library->external_fonts_ctx) return fail();
if (!library || !FontContext(library, font)) return fail();
const SysDriver* driver = library->sys_driver;
if (!driver || !driver->set_char_with_dpi || !driver->set_char_default_dpi || !driver->compute_layout || !style) return fail();
const std::uint32_t modeLow = font->flags & 0x0Fu;
@@ -226,7 +226,7 @@ int Font::ComputeHorizontalLayout(FontHandle handle, const StyleStateBlock* styl
if (static_cast<std::int32_t>(fontId) >= 0) {
FontObj* head = nullptr;
std::uint32_t lockWord = 0;
auto* entry = AcquireFontCtxEntry(library->external_fonts_ctx, fontId, modeLow, &head, &lockWord);
auto* entry = AcquireFontCtxEntry(FontContext(library, font), fontId, modeLow, &head, &lockWord);
if (!entry) return fail();
FontObj* match = FindSubFont(head, font->open_info.sub_font_index);
int rc = SCE_FONT_ERROR_FATAL;
@@ -288,7 +288,7 @@ int Font::ComputeVerticalLayout(FontHandle handle, const StyleStateBlock* style,
};
auto* font = GetNativeFont(handle);
auto* library = font ? static_cast<FontLibNative*>(font->library) : nullptr;
if (!library || !library->external_fonts_ctx || !library->sys_driver) return fail(SCE_FONT_ERROR_INVALID_FONT_HANDLE);
if (!library || !FontContext(library, font) || !library->sys_driver) return fail(SCE_FONT_ERROR_INVALID_FONT_HANDLE);
const SysDriver* driver = library->sys_driver;
const std::uint32_t modeLow = font->flags & 0x0Fu;
const std::uint32_t fontId = font->open_info.ctx_entry_index;
@@ -303,7 +303,7 @@ int Font::ComputeVerticalLayout(FontHandle handle, const StyleStateBlock* style,
if (static_cast<std::int32_t>(fontId) >= 0) {
FontObj* head = nullptr;
std::uint32_t lockWord = 0;
auto* entry = AcquireFontCtxEntry(library->external_fonts_ctx, fontId, modeLow, &head, &lockWord);
auto* entry = AcquireFontCtxEntry(FontContext(library, font), fontId, modeLow, &head, &lockWord);
FontObj* obj = FindSubFont(head, font->open_info.sub_font_index);
if (!entry || !obj) {
if (entry) ReleaseFontCtxEntryLock(entry, modeLow, lockWord);
@@ -454,7 +454,7 @@ int Font::RenderCharGlyphImageCore(FontHandle handle, std::uint32_t code, FontRe
const StyleStateBlock* style = ResolveSurfaceStyleState(&font->cached_style.state, surface, surfaceStyle);
FontObj* obj = nullptr;
std::uint32_t lockWord = 0;
auto* entry = AcquireFontCtxEntry(library->external_fonts_ctx, font->open_info.ctx_entry_index, modeLow, &obj, &lockWord);
auto* entry = AcquireFontCtxEntry(FontContext(library, font), font->open_info.ctx_entry_index, modeLow, &obj, &lockWord);
obj = FindSubFont(obj, font->open_info.sub_font_index);
if (!entry || !obj) {
if (entry) ReleaseFontCtxEntryLock(entry, modeLow, lockWord);
+48 -39
View File
@@ -1,13 +1,15 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <algorithm>
#include <array>
#include <atomic>
#include <cstring>
#include <filesystem>
#include <fstream>
#include <iterator>
#include <map>
#include <memory>
#include <mutex>
#include <optional>
#include <string>
#include <utility>
#include <vector>
@@ -18,28 +20,11 @@ namespace {
using namespace Font;
constexpr std::array<std::uint32_t, 88> SYSTEM_FONT_SET_TYPES = {
0x18070043u, 0x18070044u, 0x18070045u, 0x18070047u, 0x18070053u, 0x18070054u,
0x18070055u, 0x18070057u, 0x180700C3u, 0x180700C4u, 0x180700C5u, 0x180700C7u,
0x18070444u, 0x18070447u, 0x18070454u, 0x18070457u, 0x180704C4u, 0x180704C7u,
0x18071053u, 0x18071054u, 0x18071055u, 0x18071057u, 0x18071454u, 0x18071457u,
0x18072444u, 0x18072447u, 0x180724C4u, 0x180724C7u, 0x18073454u, 0x18073457u,
0x180734D4u, 0x180734D7u, 0x18078044u, 0x180780C4u, 0x18079054u, 0x1807A044u,
0x1807A0C4u, 0x1807A444u, 0x1807A4C4u, 0x1807AC44u, 0x1807ACC4u, 0x1807B054u,
0x1807B0D4u, 0x1807B454u, 0x1807B4D4u, 0x1807BC54u, 0x1807BCD4u, 0x18080444u,
0x18080447u, 0x18080454u, 0x18080457u, 0x180804C4u, 0x180804C7u, 0x18081454u,
0x18081457u, 0x18082444u, 0x18082447u, 0x180824C4u, 0x180824C7u, 0x18083454u,
0x18083457u, 0x180834D4u, 0x180834D7u, 0x1808A444u, 0x1808A4C4u, 0x1808B454u,
0x1808B4D4u, 0x180C8044u, 0x180C80C4u, 0x180C9054u, 0x180CA044u, 0x180CA0C4u,
0x180CAC44u, 0x180CACC4u, 0x180CB054u, 0x180CB0D4u, 0x180CBC54u, 0x180CBCD4u,
0x18170043u, 0x18170044u, 0x18170045u, 0x18170047u, 0x18170444u, 0x18170447u,
0x18370044u, 0x18370047u, 0x18370444u, 0x18370447u,
};
constexpr std::uint16_t HANDLE_OWNED = 0x10;
struct OpenRequest {
FontLibNative* library;
void* context;
std::uint32_t modeLow;
std::uint32_t driverMode;
const void* source;
@@ -111,7 +96,7 @@ void SetOpenFlags(FontLibNative* library, std::uint32_t modeLow) {
if ((flags & secondBit) != 0) library->sysfont_flags |= 2;
}
std::uint32_t ClaimExternalEntry(FontCtxHeader* header, const OpenRequest& request) {
std::uint32_t ClaimEntry(FontCtxHeader* header, const OpenRequest& request) {
AcquireWordLock(header->lock_word);
auto* entries = static_cast<FontCtxEntry*>(header->base);
std::uint32_t entryIndex = 0xFFFFFFFFu;
@@ -140,7 +125,7 @@ std::uint32_t ClaimExternalEntry(FontCtxHeader* header, const OpenRequest& reque
return entryIndex;
}
int OpenExternalFont(const OpenRequest& request, std::uint32_t libraryLock, FontHandle* pFontHandle) {
int OpenFontInContext(const OpenRequest& request, std::uint32_t libraryLock, FontHandle* pFontHandle) {
FontLibNative* library = request.library;
FontHandle handle = PrepareHandle(library, *pFontHandle);
if (!handle) {
@@ -154,8 +139,8 @@ int OpenExternalFont(const OpenRequest& request, std::uint32_t libraryLock, Font
*pFontHandle = nullptr;
return rc;
};
auto* header = static_cast<FontCtxHeader*>(library->external_fonts_ctx);
const std::uint32_t entryIndex = ClaimExternalEntry(header, request);
auto* header = static_cast<FontCtxHeader*>(request.context);
const std::uint32_t entryIndex = ClaimEntry(header, request);
if (entryIndex == 0xFFFFFFFFu) return fail(SCE_FONT_ERROR_FONT_OPEN_MAX);
const std::uint32_t packedId = request.uniqueId == -1 ? entryIndex + 0x40000000u : (static_cast<std::uint32_t>(request.uniqueId) | 0x80000000u);
FontObj* fontObj = nullptr;
@@ -183,6 +168,7 @@ int OpenExternalFont(const OpenRequest& request, std::uint32_t libraryLock, Font
}
if (needOpen) {
SetOpenFlags(library, request.modeLow);
if (request.context == library->sysfonts_ctx) library->sysfont_flags |= SYSFONT_FLAG_SYSTEM_SET;
rc = driver->open(library, request.driverMode, request.source, request.sourceSize, request.subFontIndex, packedId, &fontObj);
library->sysfont_flags = 0;
if (rc == SCE_FONT_OK) {
@@ -221,11 +207,23 @@ int BeginOpen(FontLibrary library, FontHandle* pFontHandle, std::uint32_t& libra
return rc;
}
bool ReadFileBytes(const std::filesystem::path& path, std::vector<unsigned char>& bytes) {
std::shared_ptr<const std::vector<unsigned char>> ReadFileBytes(const std::filesystem::path& path) {
std::ifstream file(path, std::ios::binary);
if (!file) return false;
bytes.assign(std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>());
return !file.bad();
if (!file) return nullptr;
std::vector<unsigned char> bytes{std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()};
if (file.bad()) return nullptr;
return std::make_shared<const std::vector<unsigned char>>(std::move(bytes));
}
std::shared_ptr<const std::vector<unsigned char>> SystemFontBytes(const std::filesystem::path& path) {
static std::mutex mutex;
static std::map<std::filesystem::path, std::weak_ptr<const std::vector<unsigned char>>> loaded;
std::lock_guard lock(mutex);
auto& slot = loaded[path];
if (auto bytes = slot.lock()) return bytes;
auto bytes = ReadFileBytes(path);
slot = bytes;
return bytes;
}
void CopyStyleToCache(FontHandleNative* font) {
@@ -250,11 +248,11 @@ int APS5_VABI sceFontOpenFontMemory(FontLibrary library, const void* fontAddress
if (pFontHandle) *pFontHandle = nullptr;
return SCE_FONT_ERROR_INVALID_PARAMETER;
}
const OpenRequest request{lib, 1, 1, fontAddress, fontSize, true, subFontIndex, uniqueId};
const int rc = OpenExternalFont(request, libraryLock, pFontHandle);
const OpenRequest request{lib, lib->external_fonts_ctx, 1, 1, fontAddress, fontSize, true, subFontIndex, uniqueId};
const int rc = OpenFontInContext(request, libraryLock, pFontHandle);
if (rc != SCE_FONT_OK) return rc;
const auto* bytes = static_cast<const unsigned char*>(fontAddress);
LoadStateFace(ResetState(*pFontHandle), std::vector<unsigned char>(bytes, bytes + fontSize), subFontIndex);
LoadStateFace(ResetState(*pFontHandle), std::make_shared<const std::vector<unsigned char>>(bytes, bytes + fontSize), subFontIndex);
return SCE_FONT_OK;
}
@@ -278,12 +276,11 @@ int APS5_VABI sceFontOpenFontFile(FontLibrary library, const char* path, std::ui
*pFontHandle = nullptr;
return SCE_FONT_ERROR_INVALID_PARAMETER;
}
const OpenRequest request{lib, modeLow, modeLow + 4, hostPathString.c_str(), 0, false, subFontIndex, uniqueId};
const int rc = OpenExternalFont(request, libraryLock, pFontHandle);
const OpenRequest request{lib, lib->external_fonts_ctx, modeLow, modeLow + 4, hostPathString.c_str(), 0, false, subFontIndex, uniqueId};
const int rc = OpenFontInContext(request, libraryLock, pFontHandle);
if (rc != SCE_FONT_OK) return rc;
std::vector<unsigned char> bytes;
FontState& state = ResetState(*pFontHandle);
if (ReadFileBytes(hostPath, bytes)) LoadStateFace(state, std::move(bytes), subFontIndex);
if (auto bytes = ReadFileBytes(hostPath)) LoadStateFace(state, std::move(bytes), subFontIndex);
return SCE_FONT_OK;
}
@@ -309,7 +306,7 @@ int APS5_VABI sceFontOpenFontInstance(FontHandle fontHandle, FontHandle setupFon
const std::uint32_t modeLow = source->flags & 0x0Fu;
const std::uint32_t subFontIndex = source->open_info.sub_font_index;
const std::uint32_t entryIndex = source->open_info.ctx_entry_index;
auto* header = static_cast<FontCtxHeader*>(library->external_fonts_ctx);
auto* header = static_cast<FontCtxHeader*>(FontContext(library, source));
if (!header) return fail(SCE_FONT_ERROR_INVALID_FONT_HANDLE);
FontHandle target = setupFont;
bool owned = false;
@@ -371,7 +368,7 @@ int APS5_VABI sceFontOpenFontInstance(FontHandle fontHandle, FontHandle setupFon
if (FontState* sourceState = TryGetState(fontHandle)) {
targetState.scaleW = sourceState->scaleW;
targetState.scaleH = sourceState->scaleH;
if (!sourceState->faceData.empty()) LoadStateFace(targetState, sourceState->faceData, subFontIndex);
if (sourceState->faceData && !sourceState->faceData->empty()) LoadStateFace(targetState, sourceState->faceData, subFontIndex);
}
if (pFontHandle) *pFontHandle = target;
return SCE_FONT_OK;
@@ -385,6 +382,8 @@ int APS5_VABI sceFontOpenFontSet(FontLibrary library, std::uint32_t fontSetType,
return SCE_FONT_ERROR_INVALID_LIBRARY;
}
if (!pFontHandle) return SCE_FONT_ERROR_INVALID_PARAMETER;
const std::optional<SystemFontFile> file = FindSystemFontFile(fontSetType);
APS5_LOG_OUT("fontSetType=0x%08X file=%s", fontSetType, file ? file->path.string().c_str() : "(none)");
std::uint32_t libraryLock = 0;
if (!AcquireLibraryLock(lib, libraryLock)) {
*pFontHandle = nullptr;
@@ -399,10 +398,20 @@ int APS5_VABI sceFontOpenFontSet(FontLibrary library, std::uint32_t fontSetType,
rc = SCE_FONT_ERROR_INVALID_MEMORY;
} else if (!lib->sysfonts_ctx) {
rc = SCE_FONT_ERROR_NO_SUPPORT_FUNCTION;
} else if (std::find(SYSTEM_FONT_SET_TYPES.begin(), SYSTEM_FONT_SET_TYPES.end(), fontSetType) == SYSTEM_FONT_SET_TYPES.end()) {
} else if (!IsSystemFontSet(fontSetType)) {
rc = SCE_FONT_ERROR_NO_SUPPORT_FONTSET;
} else {
} else if (!file) {
rc = SCE_FONT_ERROR_FONT_OPEN_FAILED;
} else {
const std::string hostPathString = file->path.string();
const OpenRequest request{lib, lib->sysfonts_ctx, openMode, openMode + 4, hostPathString.c_str(), 0, false, file->subFontIndex, static_cast<std::int32_t>(fontSetType)};
const int openRc = OpenFontInContext(request, libraryLock, pFontHandle);
if (openRc == SCE_FONT_ERROR_FS_OPEN_FAILED || openRc == SCE_FONT_ERROR_NO_SUPPORT_FORMAT) return SCE_FONT_ERROR_FONT_OPEN_FAILED;
if (openRc != SCE_FONT_OK) return openRc;
GetNativeFont(*pFontHandle)->open_info.fontset_flags = fontSetType;
FontState& state = ResetState(*pFontHandle);
if (auto bytes = SystemFontBytes(file->path)) LoadStateFace(state, std::move(bytes), file->subFontIndex);
return SCE_FONT_OK;
}
ReleaseLibraryLock(lib, libraryLock);
*pFontHandle = nullptr;
+8 -4
View File
@@ -193,6 +193,10 @@ Font::FontObj* Font::FindSubFont(FontObj* head, std::uint32_t subFontIndex) {
return nullptr;
}
void* Font::FontContext(const FontLibNative* library, const FontHandleNative* font) {
return font->open_info.fontset_flags != 0 ? library->sysfonts_ctx : library->external_fonts_ctx;
}
void Font::ReleaseFontObjectsForHandle(FontHandleNative* font) {
auto* library = static_cast<FontLibNative*>(font->library);
if (!library || library->magic != LIBRARY_MAGIC || !library->sys_driver || !library->sys_driver->close) return;
@@ -201,7 +205,7 @@ void Font::ReleaseFontObjectsForHandle(FontHandleNative* font) {
const std::uint32_t modeLow = font->flags & 0x0Fu;
FontObj* head = nullptr;
std::uint32_t lockWord = 0;
auto* entry = AcquireFontCtxEntry(library->external_fonts_ctx, fontId, modeLow, &head, &lockWord);
auto* entry = AcquireFontCtxEntry(FontContext(library, font), fontId, modeLow, &head, &lockWord);
if (!entry) return;
FontObj* match = FindSubFont(head, font->open_info.sub_font_index);
const std::uint32_t openFlag = lockWord & OPEN_BIT;
@@ -243,16 +247,16 @@ void Font::RemoveState(FontHandle handle) {
fontStates.erase(handle);
}
void Font::LoadStateFace(FontState& state, std::vector<unsigned char> bytes, std::uint32_t subFontIndex) {
void Font::LoadStateFace(FontState& state, std::shared_ptr<const std::vector<unsigned char>> bytes, std::uint32_t subFontIndex) {
if (state.face) {
FT_Done_Face(state.face);
state.face = nullptr;
}
state.faceData = std::move(bytes);
const FT_Library library = HostFreeTypeLibrary();
if (!library || state.faceData.empty()) return;
if (!library || !state.faceData || state.faceData->empty()) return;
FT_Face face = nullptr;
if (FT_New_Memory_Face(library, state.faceData.data(), static_cast<FT_Long>(state.faceData.size()), static_cast<FT_Long>(subFontIndex), &face) != 0) return;
if (FT_New_Memory_Face(library, state.faceData->data(), static_cast<FT_Long>(state.faceData->size()), static_cast<FT_Long>(subFontIndex), &face) != 0) return;
FT_Select_Charmap(face, FT_ENCODING_UNICODE);
state.face = face;
}
+131
View File
@@ -0,0 +1,131 @@
#include <algorithm>
#include <array>
#include <cstdlib>
#include <stdexcept>
#include <string_view>
#include <system_error>
#ifdef _WIN32
#include <windows.h>
#endif
#include "prx/libSceFont/include/FontInternal.hpp"
namespace {
constexpr std::array<std::uint32_t, 120> SYSTEM_FONT_SET_TYPES = {
0x18070043u, 0x18070044u, 0x18070045u, 0x18070047u, 0x18070053u, 0x18070054u,
0x18070055u, 0x18070057u, 0x180700C3u, 0x180700C4u, 0x180700C5u, 0x180700C7u,
0x18070444u, 0x18070447u, 0x18070454u, 0x18070457u, 0x180704C4u, 0x180704C7u,
0x18071053u, 0x18071054u, 0x18071055u, 0x18071057u, 0x18071454u, 0x18071457u,
0x18072444u, 0x18072447u, 0x180724C4u, 0x180724C7u, 0x18073454u, 0x18073457u,
0x180734D4u, 0x180734D7u, 0x18078044u, 0x180780C4u, 0x18079054u, 0x1807A044u,
0x1807A0C4u, 0x1807A444u, 0x1807A4C4u, 0x1807AC44u, 0x1807ACC4u, 0x1807B054u,
0x1807B0D4u, 0x1807B454u, 0x1807B4D4u, 0x1807BC54u, 0x1807BCD4u, 0x18080444u,
0x18080447u, 0x18080454u, 0x18080457u, 0x180804C4u, 0x180804C7u, 0x18081454u,
0x18081457u, 0x18082444u, 0x18082447u, 0x180824C4u, 0x180824C7u, 0x18083454u,
0x18083457u, 0x180834D4u, 0x180834D7u, 0x1808A444u, 0x1808A4C4u, 0x1808B454u,
0x1808B4D4u, 0x180C8044u, 0x180C80C4u, 0x180C9054u, 0x180CA044u, 0x180CA0C4u,
0x180CAC44u, 0x180CACC4u, 0x180CB054u, 0x180CB0D4u, 0x180CBC54u, 0x180CBCD4u,
0x18170043u, 0x18170044u, 0x18170045u, 0x18170047u, 0x18170444u, 0x18170447u,
0x18370044u, 0x18370047u, 0x18370444u, 0x18370447u, 0x1A070543u, 0x1A070547u,
0x1A070553u, 0x1A070557u, 0x1A0705C3u, 0x1A0705C7u, 0x1A071553u, 0x1A071557u,
0x1A072543u, 0x1A072547u, 0x1A0725C3u, 0x1A0725C7u, 0x1A073553u, 0x1A073557u,
0x1A0735D3u, 0x1A0735D7u, 0x1A080543u, 0x1A080547u, 0x1A080553u, 0x1A080557u,
0x1A0805C3u, 0x1A0805C7u, 0x1A081553u, 0x1A081557u, 0x1A082543u, 0x1A082547u,
0x1A0825C3u, 0x1A0825C7u, 0x1A083553u, 0x1A083557u, 0x1A0835D3u, 0x1A0835D7u,
};
enum class Family { Latin, LatinItalic, Typewriter, Vietnamese, Thai, Japanese, ChineseGb };
struct FamilyFiles {
std::array<std::string_view, 4> system;
std::array<std::string_view, 4> substitute;
std::uint32_t substituteSubFont;
};
constexpr std::array<FamilyFiles, 7> FAMILY_FILES = {{
{{"SST-Light.otf", "SST-Roman.otf", "SST-Medium.otf", "SST-Bold.otf"},
{"NotoSans-Light.ttf", "NotoSans-Regular.ttf", "NotoSans-Medium.ttf", "NotoSans-Bold.ttf"}, 0},
{{"SST-LightItalic.otf", "SST-Italic.otf", "SST-MediumItalic.otf", "SST-BoldItalic.otf"},
{"NotoSans-LightItalic.ttf", "NotoSans-Italic.ttf", "NotoSans-MediumItalic.ttf", "NotoSans-BoldItalic.ttf"}, 0},
{{"SSTTypewriter-Roman.otf", "SSTTypewriter-Roman.otf", "SSTTypewriter-Roman.otf", "SSTTypewriter-Bd.otf"},
{"NotoSansMono-Light.ttf", "NotoSansMono-Regular.ttf", "NotoSansMono-Medium.ttf", "NotoSansMono-Bold.ttf"}, 0},
{{"SSTVietnamese-Light.otf", "SSTVietnamese-Roman.otf", "SSTVietnamese-Medium.otf", "SSTVietnamese-Bold.otf"},
{"NotoSans-Light.ttf", "NotoSans-Regular.ttf", "NotoSans-Medium.ttf", "NotoSans-Bold.ttf"}, 0},
{{"SSTThai-Light.otf", "SSTThai-Roman.otf", "SSTThai-Medium.otf", "SSTThai-Bold.otf"},
{"NotoSansThai-Light.ttf", "NotoSansThai-Regular.ttf", "NotoSansThai-Medium.ttf", "NotoSansThai-Bold.ttf"}, 0},
{{"SSTJpPro-Regular.otf", "SSTJpPro-Regular.otf", "SSTJpPro-Regular.otf", "SSTJpPro-Bold.otf"},
{"NotoSansCJK-Light.ttc", "NotoSansCJK-Regular.ttc", "NotoSansCJK-Medium.ttc", "NotoSansCJK-Bold.ttc"}, 0},
{{"DFHEI5-SONY.ttf", "DFHEI5-SONY.ttf", "DFHEI5-SONY.ttf", "DFHEI5-SONY.ttf"},
{"NotoSansCJK-Light.ttc", "NotoSansCJK-Regular.ttc", "NotoSansCJK-Medium.ttc", "NotoSansCJK-Bold.ttc"}, 2},
}};
Family FamilyOf(std::uint32_t fontSetType) {
const std::uint32_t region = (fontSetType >> 16) & 0xFFu;
const std::uint32_t scripts = (fontSetType >> 8) & 0xFEu;
const bool vietnamese = (fontSetType & 0x10u) != 0;
switch (region) {
case 0x17: return Family::LatinItalic;
case 0x37: return Family::Typewriter;
case 0x08: return scripts == 0x04 && vietnamese ? Family::Vietnamese : Family::Japanese;
case 0x0C: return Family::ChineseGb;
default:
if (scripts == 0x10) return Family::Thai;
if (scripts == 0 && vietnamese) return Family::Vietnamese;
return Family::Latin;
}
}
std::size_t WeightOf(std::uint32_t fontSetType) {
switch (fontSetType & 0x0Fu) {
case 0x3: return 0;
case 0x5: return 2;
case 0x7: return 3;
default: return 1;
}
}
std::filesystem::path ExecutableDirectory() {
#ifdef _WIN32
wchar_t module[MAX_PATH];
const auto length = GetModuleFileNameW(nullptr, module, MAX_PATH);
if (length == 0 || length == MAX_PATH) throw std::runtime_error("libSceFont: cannot locate the executable");
return std::filesystem::path(module).parent_path();
#else
return std::filesystem::read_symlink("/proc/self/exe").parent_path();
#endif
}
}
bool Font::IsSystemFontSet(std::uint32_t fontSetType) {
return std::find(SYSTEM_FONT_SET_TYPES.begin(), SYSTEM_FONT_SET_TYPES.end(), fontSetType) != SYSTEM_FONT_SET_TYPES.end();
}
std::vector<Font::SystemFontFile> Font::SystemFontCandidates(std::uint32_t fontSetType) {
if (!IsSystemFontSet(fontSetType)) return {};
const FamilyFiles& files = FAMILY_FILES[static_cast<std::size_t>(FamilyOf(fontSetType))];
const std::size_t weight = WeightOf(fontSetType);
return {{std::filesystem::path(files.system[weight]), 0}, {std::filesystem::path(files.substitute[weight]), files.substituteSubFont}};
}
std::filesystem::path Font::SystemFontDirectory() {
const char* configured = std::getenv("ANYPS5_SYSTEM_FONTS");
if (!configured || configured[0] == '\0') return ExecutableDirectory() / "anyps5-fonts";
const std::filesystem::path directory(configured);
std::error_code error;
if (!std::filesystem::is_directory(directory, error)) throw std::runtime_error("libSceFont: ANYPS5_SYSTEM_FONTS is not a directory: " + directory.string());
return directory;
}
std::optional<Font::SystemFontFile> Font::FindSystemFontFile(std::uint32_t fontSetType) {
const std::vector<SystemFontFile> candidates = SystemFontCandidates(fontSetType);
if (candidates.empty()) return std::nullopt;
const std::filesystem::path directory = SystemFontDirectory();
for (const SystemFontFile& candidate : candidates) {
std::error_code error;
const std::filesystem::path path = directory / candidate.path;
if (std::filesystem::is_regular_file(path, error)) return SystemFontFile{path, candidate.subFontIndex};
}
return std::nullopt;
}
+53 -3
View File
@@ -5,6 +5,7 @@
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <limits>
@@ -26,6 +27,8 @@ struct FtLibraryContext {
const FontMemoryInterface* iface;
FT_Memory memory;
FT_Library library;
FT_Memory hostMemory;
FT_Library hostLibrary;
};
void* FtAlloc(FT_Memory memory, long size) {
@@ -58,6 +61,42 @@ void* FtRealloc(FT_Memory memory, long currentSize, long newSize, void* block) {
return result;
}
void* HostAlloc(FT_Memory, long size) {
return size > 0 ? std::malloc(static_cast<std::size_t>(size)) : nullptr;
}
void HostFree(FT_Memory, void* block) {
std::free(block);
}
void* HostRealloc(FT_Memory, long, long newSize, void* block) {
if (newSize <= 0) {
std::free(block);
return nullptr;
}
return std::realloc(block, static_cast<std::size_t>(newSize));
}
FT_Library SystemFontLibrary(FtLibraryContext* ctx) {
if (ctx->hostLibrary) return ctx->hostLibrary;
auto* hostMemory = static_cast<FT_Memory>(ctx->iface->alloc(ctx->allocCtx, sizeof(FT_MemoryRec_)));
if (!hostMemory) return nullptr;
std::memset(hostMemory, 0, sizeof(*hostMemory));
hostMemory->user = ctx;
hostMemory->alloc = &HostAlloc;
hostMemory->free = &HostFree;
hostMemory->realloc = &HostRealloc;
FT_Library hostLibrary = nullptr;
if (FT_New_Library(hostMemory, &hostLibrary) != 0 || !hostLibrary) {
ctx->iface->dealloc(ctx->allocCtx, hostMemory);
return nullptr;
}
FT_Add_Default_Modules(hostLibrary);
ctx->hostMemory = hostMemory;
ctx->hostLibrary = hostLibrary;
return hostLibrary;
}
void WriteU16(std::uint8_t* out, std::size_t offset, std::uint16_t value) {
std::memcpy(out + offset, &value, sizeof(value));
}
@@ -131,6 +170,14 @@ int APS5_VABI LibraryTerm(FontLibNative* library) {
FT_Done_Library(ctx->library);
ctx->library = nullptr;
}
if (ctx->hostLibrary) {
FT_Done_Library(ctx->hostLibrary);
ctx->hostLibrary = nullptr;
}
if (ctx->hostMemory) {
freeFn(library->alloc_ctx, ctx->hostMemory);
ctx->hostMemory = nullptr;
}
if (ctx->memory) {
freeFn(library->alloc_ctx, ctx->memory);
ctx->memory = nullptr;
@@ -162,12 +209,15 @@ int APS5_VABI LibraryOpenFont(FontLibNative* library, std::uint32_t mode, const
}
auto* ctx = static_cast<FtLibraryContext*>(library->fontset_registry);
if (!ctx || !ctx->library) return SCE_FONT_ERROR_INVALID_LIBRARY;
const bool systemSet = (library->sysfont_flags & SYSFONT_FLAG_SYSTEM_SET) != 0;
FT_Library* ftLibrary = systemSet ? &ctx->hostLibrary : &ctx->library;
if (systemSet && !SystemFontLibrary(ctx)) return SCE_FONT_ERROR_ALLOCATION_FAILED;
FT_Face face = nullptr;
FT_Error error;
if (fromMemory) {
error = FT_New_Memory_Face(ctx->library, static_cast<const FT_Byte*>(fontAddress), static_cast<FT_Long>(fontSize), static_cast<FT_Long>(subFontIndex), &face);
error = FT_New_Memory_Face(*ftLibrary, static_cast<const FT_Byte*>(fontAddress), static_cast<FT_Long>(fontSize), static_cast<FT_Long>(subFontIndex), &face);
} else {
error = FT_New_Face(ctx->library, static_cast<const char*>(fontAddress), static_cast<FT_Long>(subFontIndex), &face);
error = FT_New_Face(*ftLibrary, static_cast<const char*>(fontAddress), static_cast<FT_Long>(subFontIndex), &face);
}
if (error != 0 || !face) {
if (fromMemory || error == FT_Err_Unknown_File_Format) return SCE_FONT_ERROR_NO_SUPPORT_FORMAT;
@@ -186,7 +236,7 @@ int APS5_VABI LibraryOpenFont(FontLibNative* library, std::uint32_t mode, const
obj->next = *inoutFontObj;
if (obj->next) obj->next->prev = obj;
obj->ft_face = face;
obj->ft_ctx_0x58 = &ctx->library;
obj->ft_ctx_0x58 = ftLibrary;
*inoutFontObj = obj;
return SCE_FONT_OK;
}
+218
View File
@@ -0,0 +1,218 @@
#include "prx/libSceFont/include/FontTypes.hpp"
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <filesystem>
#include <fstream>
#include <initializer_list>
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>
extern "C" {
int APS5_VABI sceFontMemoryInit(FontMemory*, void*, std::uint32_t, const FontMemoryInterface*, void*, FontMemoryDestroyFunction, void*);
int APS5_VABI sceFontCreateLibrary(const FontMemory*, const void*, FontLibrary*);
int APS5_VABI sceFontDestroyLibrary(FontLibrary*);
int APS5_VABI sceFontSupportSystemFonts(FontLibrary);
int APS5_VABI sceFontSupportExternalFonts(FontLibrary, std::uint32_t, std::uint32_t);
int APS5_VABI sceFontOpenFontSet(FontLibrary, std::uint32_t, std::uint32_t, const FontOpenDetail*, FontHandle*);
int APS5_VABI sceFontOpenFontMemory(FontLibrary, const void*, std::uint32_t, const FontOpenDetail*, FontHandle*);
int APS5_VABI sceFontOpenFontInstance(FontHandle, FontHandle, FontHandle*);
int APS5_VABI sceFontCloseFont(FontHandle);
int APS5_VABI sceFontSetScalePixel(FontHandle, float, float);
int APS5_VABI sceFontGetCharGlyphMetrics(FontHandle, std::uint32_t, FontGlyphMetrics*);
int APS5_VABI sceFontGetHorizontalLayout(FontHandle, FontHorizontalLayout*);
const void* APS5_VABI sceFontSelectLibraryFt(int);
}
static void Check(bool value, int line) {
if (!value) {
std::fprintf(stderr, "System font check failed at line %d\n", line);
std::abort();
}
}
#define Require(value) Check((value), __LINE__)
static int allocations = 0;
static void* APS5_VABI Allocate(void*, std::uint32_t size) {
++allocations;
return std::malloc(size);
}
static void APS5_VABI Release(void*, void* pointer) {
if (pointer) --allocations;
std::free(pointer);
}
static void Put16(std::vector<unsigned char>& out, std::uint32_t value) {
out.push_back(static_cast<unsigned char>(value >> 8));
out.push_back(static_cast<unsigned char>(value));
}
static void Put32(std::vector<unsigned char>& out, std::uint32_t value) {
Put16(out, value >> 16);
Put16(out, value & 0xFFFFu);
}
static void PutAll16(std::vector<unsigned char>& out, std::initializer_list<int> values) {
for (const int value : values) Put16(out, static_cast<std::uint32_t>(static_cast<std::uint16_t>(value)));
}
static std::vector<unsigned char> SquareGlyphFont(std::uint32_t codepoint, int width) {
std::vector<unsigned char> head;
Put32(head, 0x00010000u);
Put32(head, 0x00010000u);
Put32(head, 0);
Put32(head, 0x5F0F3CF5u);
PutAll16(head, {0x000B, 1000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, width, 800, 0, 8, 2, 0, 0});
std::vector<unsigned char> hhea;
Put32(hhea, 0x00010000u);
PutAll16(hhea, {800, -200, 0, width, 0, 0, width, 1, 0, 0, 0, 0, 0, 0, 0, 2});
std::vector<unsigned char> maxp;
Put32(maxp, 0x00010000u);
PutAll16(maxp, {2, 4, 1, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0});
std::vector<unsigned char> hmtx;
PutAll16(hmtx, {width, 0, width, 100});
std::vector<unsigned char> glyf;
PutAll16(glyf, {1, 100, 0, width - 100, 700, 3, 0});
glyf.insert(glyf.end(), {1, 1, 1, 1});
PutAll16(glyf, {100, 0, width - 200, 0, 0, 700, 0, -700});
std::vector<unsigned char> loca;
PutAll16(loca, {0, 0, static_cast<int>(glyf.size() / 2)});
std::vector<unsigned char> cmap;
PutAll16(cmap, {0, 1, 3, 1});
Put32(cmap, 12);
PutAll16(cmap, {4, 32, 0, 4, 4, 1, 0, static_cast<int>(codepoint), 0xFFFF, 0, static_cast<int>(codepoint), 0xFFFF, 1 - static_cast<int>(codepoint), 1, 0, 0});
const std::vector<std::pair<const char*, const std::vector<unsigned char>*>> tables = {
{"cmap", &cmap}, {"glyf", &glyf}, {"head", &head}, {"hhea", &hhea}, {"hmtx", &hmtx}, {"loca", &loca}, {"maxp", &maxp}};
std::vector<unsigned char> font;
Put32(font, 0x00010000u);
PutAll16(font, {static_cast<int>(tables.size()), 64, 2, static_cast<int>(tables.size()) * 16 - 64});
std::uint32_t offset = 12 + static_cast<std::uint32_t>(tables.size()) * 16;
for (const auto& [tag, data] : tables) {
font.insert(font.end(), tag, tag + 4);
Put32(font, 0);
Put32(font, offset);
Put32(font, static_cast<std::uint32_t>(data->size()));
offset += (static_cast<std::uint32_t>(data->size()) + 3u) & ~3u;
}
for (const auto& [tag, data] : tables) {
font.insert(font.end(), data->begin(), data->end());
font.resize((font.size() + 3u) & ~std::size_t{3});
}
return font;
}
static void WriteFile(const std::filesystem::path& path, const std::vector<unsigned char>& bytes) {
std::ofstream file(path, std::ios::binary);
file.write(reinterpret_cast<const char*>(bytes.data()), static_cast<std::streamsize>(bytes.size()));
Require(static_cast<bool>(file));
}
static void SetFontDirectory(const std::filesystem::path& directory) {
#ifdef _WIN32
Require(_putenv_s("ANYPS5_SYSTEM_FONTS", directory.string().c_str()) == 0);
#else
Require(::setenv("ANYPS5_SYSTEM_FONTS", directory.string().c_str(), 1) == 0);
#endif
}
static float AdvanceOf(FontHandle font, std::uint32_t code) {
FontGlyphMetrics metrics{};
Require(sceFontGetCharGlyphMetrics(font, code, &metrics) == SCE_FONT_OK);
return metrics.Horizontal.advance;
}
int main() {
constexpr std::uint32_t EuropeanLight = 0x180700C3u;
constexpr std::uint32_t EuropeanBold = 0x180700C7u;
constexpr std::uint32_t EuropeanItalic = 0x18170044u;
constexpr std::uint32_t ThaiMedium = 0x18071055u;
constexpr std::uint32_t VietnameseBold = 0x18070057u;
constexpr std::uint32_t JapaneseJg2Light = 0x1A0835D3u;
constexpr std::uint32_t ChineseGb = 0x180CB0D4u;
const std::filesystem::path root = std::filesystem::temp_directory_path() / "anyps5_guest_system_font";
std::filesystem::remove_all(root);
const std::filesystem::path empty = root / "empty";
const std::filesystem::path fonts = root / "fonts";
std::filesystem::create_directories(empty);
std::filesystem::create_directories(fonts);
WriteFile(fonts / "SST-Bold.otf", SquareGlyphFont('A', 700));
WriteFile(fonts / "NotoSans-Bold.ttf", SquareGlyphFont('A', 300));
WriteFile(fonts / "NotoSans-Light.ttf", SquareGlyphFont('A', 500));
WriteFile(fonts / "SST-Italic.otf", SquareGlyphFont('A', 520));
WriteFile(fonts / "NotoSansThai-Medium.ttf", SquareGlyphFont(0x0E01, 540));
WriteFile(fonts / "SSTVietnamese-Bold.otf", SquareGlyphFont(0x1EA0, 560));
WriteFile(fonts / "NotoSansCJK-Light.ttc", SquareGlyphFont(0x3042, 580));
const FontMemoryInterface iface{Allocate, Release, nullptr, nullptr, nullptr, nullptr};
FontMemory memory{};
Require(sceFontMemoryInit(&memory, nullptr, 0, &iface, nullptr, nullptr, nullptr) == SCE_FONT_OK);
FontLibrary library = nullptr;
Require(sceFontCreateLibrary(&memory, sceFontSelectLibraryFt(0), &library) == SCE_FONT_OK);
Require(sceFontSupportSystemFonts(library) == SCE_FONT_OK);
FontHandle font = nullptr;
SetFontDirectory(empty);
Require(sceFontOpenFontSet(library, EuropeanBold, 1, nullptr, &font) == SCE_FONT_ERROR_FONT_OPEN_FAILED && font == nullptr);
Require(sceFontOpenFontSet(library, 0x18070046u, 1, nullptr, &font) == SCE_FONT_ERROR_NO_SUPPORT_FONTSET && font == nullptr);
SetFontDirectory(root / "missing");
bool threw = false;
try {
sceFontOpenFontSet(library, EuropeanBold, 1, nullptr, &font);
} catch (const std::runtime_error&) {
threw = true;
}
Require(threw);
SetFontDirectory(fonts);
const int beforeOpen = allocations;
Require(sceFontOpenFontSet(library, EuropeanBold, 1, nullptr, &font) == SCE_FONT_OK && font != nullptr);
Require(allocations - beforeOpen == 3);
Require(sceFontSetScalePixel(font, 100.0f, 100.0f) == SCE_FONT_OK);
Require(AdvanceOf(font, 'A') == 70.0f);
FontGlyphMetrics metrics{};
Require(sceFontGetCharGlyphMetrics(font, 'B', &metrics) == SCE_FONT_ERROR_NO_SUPPORT_GLYPH);
FontHorizontalLayout layout{};
Require(sceFontGetHorizontalLayout(font, &layout) == SCE_FONT_OK && layout.baselineOffset > 0.0f && layout.lineAdvance >= layout.baselineOffset);
FontHandle again = nullptr;
Require(sceFontOpenFontSet(library, EuropeanBold, 2, nullptr, &again) == SCE_FONT_OK && again != font);
FontHandle instance = nullptr;
Require(sceFontOpenFontInstance(font, nullptr, &instance) == SCE_FONT_OK && instance != nullptr);
Require(sceFontGetHorizontalLayout(instance, &layout) == SCE_FONT_OK && layout.baselineOffset > 0.0f);
const std::vector<std::pair<std::uint32_t, std::pair<std::uint32_t, float>>> expected = {
{EuropeanLight, {'A', 50.0f}}, {EuropeanItalic, {'A', 52.0f}}, {ThaiMedium, {0x0E01, 54.0f}},
{VietnameseBold, {0x1EA0, 56.0f}}, {JapaneseJg2Light, {0x3042, 58.0f}}};
for (const auto& [type, glyph] : expected) {
FontHandle set = nullptr;
Require(sceFontOpenFontSet(library, type, 1, nullptr, &set) == SCE_FONT_OK);
Require(sceFontSetScalePixel(set, 100.0f, 100.0f) == SCE_FONT_OK);
Require(AdvanceOf(set, glyph.first) == glyph.second);
Require(sceFontCloseFont(set) == SCE_FONT_OK);
}
Require(sceFontCloseFont(again) == SCE_FONT_OK);
FontHandle missing = nullptr;
Require(sceFontOpenFontSet(library, ChineseGb, 1, nullptr, &missing) == SCE_FONT_ERROR_FONT_OPEN_FAILED && missing == nullptr);
std::filesystem::remove(fonts / "SST-Bold.otf");
FontHandle substitute = nullptr;
Require(sceFontOpenFontSet(library, EuropeanBold, 3, nullptr, &substitute) == SCE_FONT_OK);
Require(sceFontSetScalePixel(substitute, 100.0f, 100.0f) == SCE_FONT_OK);
Require(AdvanceOf(substitute, 'A') == 30.0f);
Require(AdvanceOf(font, 'A') == 70.0f);
Require(sceFontSupportExternalFonts(library, 2, 0x52) == SCE_FONT_OK);
const std::vector<unsigned char> external = SquareGlyphFont('A', 900);
FontHandle memoryFont = nullptr;
Require(sceFontOpenFontMemory(library, external.data(), static_cast<std::uint32_t>(external.size()), nullptr, &memoryFont) == SCE_FONT_OK);
Require(sceFontSetScalePixel(memoryFont, 100.0f, 100.0f) == SCE_FONT_OK);
Require(AdvanceOf(memoryFont, 'A') == 90.0f);
Require(sceFontGetHorizontalLayout(memoryFont, &layout) == SCE_FONT_OK);
for (FontHandle handle : {font, instance, substitute, memoryFont}) Require(sceFontCloseFont(handle) == SCE_FONT_OK);
Require(sceFontDestroyLibrary(&library) == SCE_FONT_OK);
Require(allocations == 0);
std::filesystem::remove_all(root);
}
+1
View File
@@ -127,3 +127,4 @@ Throughout the project, every function at every stage either **does exactly what
- [64-bit LDS atomics](../../core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvMemoryInstructions.cpp) (`ds_*_u64`, `ds_*_b64`, `ds_*_f64`) read and write the two dwords under a workgroup lock stored after the guest LDS, as LDS is a 32-bit array without 64-bit atomics. They are atomic with respect to each other only: 32-bit accesses to the same dwords issued concurrently are not ordered by the lock. 64-bit GDS atomics throw. `ds_min/max(_rtn)_f64` and `ds_cmpst(_rtn)_f64` follow the NaN and signed-zero rules measured for the f32 forms; the f64 forms were not measured on hardware.
- [wcsrtombs_s](../../core/libs/prx/libc/src/Multibyte.cpp) (libc) follows the console's `libc.prx`, but a runtime-constraint violation only returns its error: the default handler there writes the message and a newline to `stderr` before returning, which is not done here. Conversion uses the C locale of `wcrtomb` (`MB_CUR_MAX` 1), so the path where a multibyte character does not fit the remaining space is not reached
- [Thread exit destructors](../../core/libs/prx/libSceLibcInternal/Export.cpp) (libSceLibcInternal) run when a libkernel thread finishes; on the main or a host thread only `_sceLibcInternalThreadDtors` runs them, as `exit` does, else they are dropped
- [sceFontOpenFontSet](../../core/libs/prx/libSceFont/src/SystemFont.cpp) (libSceFont) opens only the primary file of a system font set. Characters the console takes from the set's other files (Hangul, Thai and Arabic in Japanese and Chinese sets, Arabic in European sets) are reported as unsupported glyphs. The console file names are those of the PS4 firmware; the names of the PS5-only JG2 sets (`0x1A......`) are unknown, so they use the SSTJpPro files. When a console file is missing, an openly licensed substitute (Noto Sans, Noto Sans Mono, Noto Sans Thai, Noto Sans CJK) is loaded instead. It is not the system font: its metrics differ, so text width, line height and wrapping differ from the console. System font faces are loaded by FreeType in host memory, not in the font memory the title passes to the library: FreeType needs about 1 MiB per CJK face, which the title's font memory is not sized for.
+4
View File
@@ -85,6 +85,10 @@ Windows PowerShell:
.\app.exe
```
### System fonts
Games that open the console's system font sets (`sceFontOpenFontSet`) need font files in an `anyps5-fonts/` directory beside the output executable; set `ANYPS5_SYSTEM_FONTS` to use another directory. Files dumped from the console are used under their own names (`SST-Roman.otf`, `SST-Bold.otf`, `SSTJpPro-Regular.otf`, ...). Without them, these openly licensed substitutes are used when present: `NotoSans-{Light,Regular,Medium,Bold}.ttf` and `NotoSans-{LightItalic,Italic,MediumItalic,BoldItalic}.ttf` (Latin and Vietnamese), `NotoSansMono-{Light,Regular,Medium,Bold}.ttf` (typewriter), `NotoSansThai-{Light,Regular,Medium,Bold}.ttf` (Thai) and `NotoSansCJK-{Light,Regular,Medium,Bold}.ttc` (Japanese and Chinese). Without either, opening a system font set fails and the game shows no text in those fonts.
## Exit codes
`0`: conversion succeeded. `1`: invalid arguments. `2`: conversion failed; the error is printed to stderr. With `--autorun`, successful conversion returns the launched application's exit code.