feat(font): port shadPS4's sceFont and sceFontFt on FreeType #58

Merged
oneandonlydean merged 3 commits from upstream-pr/58 into main 2026-09-28 22:07:31 +00:00
oneandonlydean commented 2026-09-28 03:46:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-09-28T03:46:19Z.


What

Every libSceFont, libSceFont.native and libSceFontFt export was NotImplemented, and a retail title renders its text through them. This ports shadPS4's sceFont/sceFontFt implementation on top of FreeType.

Licensing: the code comes from shadPS4, which is GPL-2.0-or-later. That's compatible with this project's GPL-2.0-only, and every ported file keeps shadPS4's SPDX copyright and license header.

How

  • Layout: libSceFont and libSceFont.native are built from the same sources through FontLibrary.cmake, and libSceFontFt provides the FreeType driver and renderer tables (sceFontSelectLibraryFt, sceFontSelectRendererFt).
  • Implemented:
    • memory init/term, library and renderer create/destroy (with and without edition), device cache buffers;
    • opening fonts from memory, files (through the guest path resolver) and instances, plus sceFontCloseFont (not implemented in shadPS4);
    • binding renderers, scale/DPI/slant/weight and style frames;
    • glyph metrics, kerning and layout, rendering glyphs into render surfaces, generated glyphs and outlines;
    • text sources, strings, characters and writing.
  • Changes from shadPS4:
    • Its system-font support is removed, because the system fonts aren't available here. sceFontSupportSystemFonts still succeeds, but sceFontOpenFontSet returns SCE_FONT_ERROR_FONT_OPEN_FAILED for a known system font set, and SCE_FONT_ERROR_NO_SUPPORT_FONTSET for an unknown one.
    • Functions that were stubs returning success now throw NotImplemented.
  • The old Font* placeholder types in SceTypes.hpp are removed. The libraries have their own headers now, and nothing else used those types.
  • Still throwing NotImplemented:
    • libSceFont: sceFontCharacterGetSyllableStringState, sceFontCharactersRefersTextCodes, sceFontControl, sceFontCreateGraphicsDevice, sceFontCreateGraphicsService, sceFontCreateGraphicsServiceWithEdition, sceFontCreateWords, sceFontCreateWritingLine, sceFontDefineAttribute, sceFontDestroyGraphicsDevice, sceFontDestroyGraphicsService, sceFontDestroyWords, sceFontDestroyWritingLine, sceFontDettachDeviceCacheBuffer, sceFontGetAttribute, sceFontGetCharGlyphCode, sceFontGetFontGlyphsCount, sceFontGetFontGlyphsOutlineProfile, sceFontGetFontMetrics, sceFontGetFontResolution, sceFontGetFontStyleInformation, sceFontGetGlyphExpandBufferState, sceFontGetPixelResolution, sceFontGetRenderScaledKerning, sceFontGetResolutionDpi, sceFontGetScriptLanguage, sceFontGetTypographicDesign, sceFontGlyphDefineAttribute, sceFontGlyphGetAttribute, sceFontGlyphRenderImage, sceFontGlyphRenderImageHorizontal, sceFontGlyphRenderImageVertical, sceFontGraphicsBeginFrame, sceFontGraphicsDrawingCancel, sceFontGraphicsDrawingFinish, sceFontGraphicsEndFrame, sceFontGraphicsExchangeResource, sceFontGraphicsFillMethodInit, sceFontGraphicsFillPlotInit, sceFontGraphicsFillPlotSetLayout, sceFontGraphicsFillPlotSetMapping, sceFontGraphicsFillRatesInit, sceFontGraphicsFillRatesSetFillEffect, sceFontGraphicsFillRatesSetLayout, sceFontGraphicsFillRatesSetMapping, sceFontGraphicsGetDeviceUsage, sceFontGraphicsRegionInit, sceFontGraphicsRegionInitCircular, sceFontGraphicsRegionInitRoundish, sceFontGraphicsRelease, sceFontGraphicsRenderResource, sceFontGraphicsSetFramePolicy, sceFontGraphicsSetupClipping, sceFontGraphicsSetupColorRates, sceFontGraphicsSetupFillMethod, sceFontGraphicsSetupFillRates, sceFontGraphicsSetupGlyphFill, sceFontGraphicsSetupGlyphFillPlot, sceFontGraphicsSetupHandleDefault, sceFontGraphicsSetupLocation, sceFontGraphicsSetupPositioning, sceFontGraphicsSetupRotation, sceFontGraphicsSetupScaling, sceFontGraphicsSetupShapeFill, sceFontGraphicsSetupShapeFillPlot, sceFontGraphicsStructureCanvas, sceFontGraphicsStructureCanvasSequence, sceFontGraphicsStructureDesign, sceFontGraphicsStructureDesignResource, sceFontGraphicsStructureSurfaceTexture, sceFontGraphicsUpdateClipping, sceFontGraphicsUpdateColorRates, sceFontGraphicsUpdateFillMethod, sceFontGraphicsUpdateFillRates, sceFontGraphicsUpdateGlyphFill, sceFontGraphicsUpdateGlyphFillPlot, sceFontGraphicsUpdateLocation, sceFontGraphicsUpdatePositioning, sceFontGraphicsUpdateRotation, sceFontGraphicsUpdateScaling, sceFontGraphicsUpdateShapeFill, sceFontGraphicsUpdateShapeFillPlot, sceFontSetScriptLanguage, sceFontSetTypographicDesign, sceFontSupportGlyphs, sceFontTextCodesStepBack, sceFontTextCodesStepNext, sceFontWordsFindWordCharacters, sceFontWritingLineClear, sceFontWritingLineGetOrderingSpace, sceFontWritingLineGetRenderMetrics, sceFontWritingLineRefersRenderStep, sceFontWritingLineWritesOrder.
    • libSceFontFt: sceFontFtInitAliases, sceFontFtSetAliasFont, sceFontFtSetAliasPath, sceFontFtTermAliases, the sceFontFtSupport* format selectors and sceFontSelectGlyphsFt.

New build dependency: FreeType is found with find_package(Freetype REQUIRED). I've only built this on Linux against the system FreeType. The Windows/MinGW build is untested. How would you like FreeType provided there? For example, a submodule in 3rdparty like SDL2, or should it stay a system package?

Testing

New guest_font test (lifecycle and error paths; rendering needs font data, which the repository doesn't ship):

  • Lifecycle: create and destroy a library and a renderer through the FreeType tables, with a counting allocator. Every allocation is freed, and double destroy and double term are rejected.
  • sceFontOpenFontSet: fails before system fonts are supported; after support, returns FONT_OPEN_FAILED for a known set and NO_SUPPORT_FONTSET for an unknown one, and rejects a bad open mode and a null library.
  • sceFontOpenFontMemory: fails before external fonts are supported, rejects a null buffer, and returns NO_SUPPORT_FORMAT for bytes that aren't a font.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4658994062 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/58). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-09-28T03:46:19Z. --- ### What Every `libSceFont`, `libSceFont.native` and `libSceFontFt` export was `NotImplemented`, and a retail title renders its text through them. This ports shadPS4's `sceFont`/`sceFontFt` implementation on top of FreeType. **Licensing:** the code comes from shadPS4, which is GPL-2.0-or-later. That's compatible with this project's GPL-2.0-only, and every ported file keeps shadPS4's SPDX copyright and license header. ### How - **Layout:** `libSceFont` and `libSceFont.native` are built from the same sources through `FontLibrary.cmake`, and `libSceFontFt` provides the FreeType driver and renderer tables (`sceFontSelectLibraryFt`, `sceFontSelectRendererFt`). - **Implemented:** - memory init/term, library and renderer create/destroy (with and without edition), device cache buffers; - opening fonts from memory, files (through the guest path resolver) and instances, plus `sceFontCloseFont` (not implemented in shadPS4); - binding renderers, scale/DPI/slant/weight and style frames; - glyph metrics, kerning and layout, rendering glyphs into render surfaces, generated glyphs and outlines; - text sources, strings, characters and writing. - **Changes from shadPS4:** - Its system-font support is removed, because the system fonts aren't available here. `sceFontSupportSystemFonts` still succeeds, but `sceFontOpenFontSet` returns `SCE_FONT_ERROR_FONT_OPEN_FAILED` for a known system font set, and `SCE_FONT_ERROR_NO_SUPPORT_FONTSET` for an unknown one. - Functions that were stubs returning success now throw `NotImplemented`. - The old `Font*` placeholder types in `SceTypes.hpp` are removed. The libraries have their own headers now, and nothing else used those types. - **Still throwing `NotImplemented`:** - libSceFont: `sceFontCharacterGetSyllableStringState`, `sceFontCharactersRefersTextCodes`, `sceFontControl`, `sceFontCreateGraphicsDevice`, `sceFontCreateGraphicsService`, `sceFontCreateGraphicsServiceWithEdition`, `sceFontCreateWords`, `sceFontCreateWritingLine`, `sceFontDefineAttribute`, `sceFontDestroyGraphicsDevice`, `sceFontDestroyGraphicsService`, `sceFontDestroyWords`, `sceFontDestroyWritingLine`, `sceFontDettachDeviceCacheBuffer`, `sceFontGetAttribute`, `sceFontGetCharGlyphCode`, `sceFontGetFontGlyphsCount`, `sceFontGetFontGlyphsOutlineProfile`, `sceFontGetFontMetrics`, `sceFontGetFontResolution`, `sceFontGetFontStyleInformation`, `sceFontGetGlyphExpandBufferState`, `sceFontGetPixelResolution`, `sceFontGetRenderScaledKerning`, `sceFontGetResolutionDpi`, `sceFontGetScriptLanguage`, `sceFontGetTypographicDesign`, `sceFontGlyphDefineAttribute`, `sceFontGlyphGetAttribute`, `sceFontGlyphRenderImage`, `sceFontGlyphRenderImageHorizontal`, `sceFontGlyphRenderImageVertical`, `sceFontGraphicsBeginFrame`, `sceFontGraphicsDrawingCancel`, `sceFontGraphicsDrawingFinish`, `sceFontGraphicsEndFrame`, `sceFontGraphicsExchangeResource`, `sceFontGraphicsFillMethodInit`, `sceFontGraphicsFillPlotInit`, `sceFontGraphicsFillPlotSetLayout`, `sceFontGraphicsFillPlotSetMapping`, `sceFontGraphicsFillRatesInit`, `sceFontGraphicsFillRatesSetFillEffect`, `sceFontGraphicsFillRatesSetLayout`, `sceFontGraphicsFillRatesSetMapping`, `sceFontGraphicsGetDeviceUsage`, `sceFontGraphicsRegionInit`, `sceFontGraphicsRegionInitCircular`, `sceFontGraphicsRegionInitRoundish`, `sceFontGraphicsRelease`, `sceFontGraphicsRenderResource`, `sceFontGraphicsSetFramePolicy`, `sceFontGraphicsSetupClipping`, `sceFontGraphicsSetupColorRates`, `sceFontGraphicsSetupFillMethod`, `sceFontGraphicsSetupFillRates`, `sceFontGraphicsSetupGlyphFill`, `sceFontGraphicsSetupGlyphFillPlot`, `sceFontGraphicsSetupHandleDefault`, `sceFontGraphicsSetupLocation`, `sceFontGraphicsSetupPositioning`, `sceFontGraphicsSetupRotation`, `sceFontGraphicsSetupScaling`, `sceFontGraphicsSetupShapeFill`, `sceFontGraphicsSetupShapeFillPlot`, `sceFontGraphicsStructureCanvas`, `sceFontGraphicsStructureCanvasSequence`, `sceFontGraphicsStructureDesign`, `sceFontGraphicsStructureDesignResource`, `sceFontGraphicsStructureSurfaceTexture`, `sceFontGraphicsUpdateClipping`, `sceFontGraphicsUpdateColorRates`, `sceFontGraphicsUpdateFillMethod`, `sceFontGraphicsUpdateFillRates`, `sceFontGraphicsUpdateGlyphFill`, `sceFontGraphicsUpdateGlyphFillPlot`, `sceFontGraphicsUpdateLocation`, `sceFontGraphicsUpdatePositioning`, `sceFontGraphicsUpdateRotation`, `sceFontGraphicsUpdateScaling`, `sceFontGraphicsUpdateShapeFill`, `sceFontGraphicsUpdateShapeFillPlot`, `sceFontSetScriptLanguage`, `sceFontSetTypographicDesign`, `sceFontSupportGlyphs`, `sceFontTextCodesStepBack`, `sceFontTextCodesStepNext`, `sceFontWordsFindWordCharacters`, `sceFontWritingLineClear`, `sceFontWritingLineGetOrderingSpace`, `sceFontWritingLineGetRenderMetrics`, `sceFontWritingLineRefersRenderStep`, `sceFontWritingLineWritesOrder`. - libSceFontFt: `sceFontFtInitAliases`, `sceFontFtSetAliasFont`, `sceFontFtSetAliasPath`, `sceFontFtTermAliases`, the `sceFontFtSupport*` format selectors and `sceFontSelectGlyphsFt`. **New build dependency:** FreeType is found with `find_package(Freetype REQUIRED)`. I've only built this on Linux against the system FreeType. The Windows/MinGW build is untested. How would you like FreeType provided there? For example, a submodule in `3rdparty` like SDL2, or should it stay a system package? ### Testing New `guest_font` test (lifecycle and error paths; rendering needs font data, which the repository doesn't ship): - **Lifecycle:** create and destroy a library and a renderer through the FreeType tables, with a counting allocator. Every allocation is freed, and double destroy and double term are rejected. - **`sceFontOpenFontSet`:** fails before system fonts are supported; after support, returns `FONT_OPEN_FAILED` for a known set and `NO_SUPPORT_FONTSET` for an unknown one, and rejects a bad open mode and a null library. - **`sceFontOpenFontMemory`:** fails before external fonts are supported, rejects a null buffer, and returns `NO_SUPPORT_FORMAT` for bytes that aren't a font.
boykopovar commented 2026-09-28 06:48:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by boykopovar on 2026-09-28T06:48:06Z.


As I understand it, this requires the presence of a library in the system. find_package(Freetype REQUIRED). Is it possible to add the library as a submodule and build from source?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5864904403 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/58#issuecomment-5864904403). Originally posted by [boykopovar](https://github.com/boykopovar) on 2026-09-28T06:48:06Z. --- As I understand it, this requires the presence of a library in the system. `find_package(Freetype REQUIRED)`. Is it possible to add the library as a submodule and build from source?
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!58
No description provided.