From fe79da22ffd09da9d8abc5bcadd17afbe3d454d0 Mon Sep 17 00:00:00 2001 From: Yunus Shaikh <75296019+EagleBearerYS@users.noreply.github.com> Date: Sun, 25 Oct 2026 07:27:33 +0000 Subject: [PATCH] refactor(libSceFont): split RenderCodeWithStyle and ApplyStyleFrame out of the char render path RenderCharGlyphImageCore keeps its handle and bound-renderer checks and hands the rest of the render, from the glyph lookup to the output fill, to RenderCodeWithStyle, which takes the style as an argument. The surface style-frame rule moves into ApplyStyleFrame, with SurfaceStyleFrame finding a surface's valid frame, and ResolveSurfaceStyleState now calls the two. The char render calls pass the same style as before and behave as before. --- .../prx/libSceFont/include/FontInternal.hpp | 3 + core/libs/prx/libSceFont/src/Layout.cpp | 64 ++++++++++++------- 2 files changed, 43 insertions(+), 24 deletions(-) diff --git a/core/libs/prx/libSceFont/include/FontInternal.hpp b/core/libs/prx/libSceFont/include/FontInternal.hpp index 54c173835e..90ec4973f0 100644 --- a/core/libs/prx/libSceFont/include/FontInternal.hpp +++ b/core/libs/prx/libSceFont/include/FontInternal.hpp @@ -121,6 +121,9 @@ int StyleStateGetSlantRatio(const StyleStateBlock* style, float* slantRatio); int StyleStateSetWeightScale(StyleStateBlock* style, float weightXScale, float weightYScale); int StyleStateGetWeightScale(const StyleStateBlock* style, float* weightXScale, float* weightYScale, std::uint32_t* mode); bool ValidStyleFrame(const FontStyleFrame* frame); +const FontStyleFrame* SurfaceStyleFrame(const FontRenderSurface* surface); +const StyleStateBlock* ApplyStyleFrame(const StyleStateBlock* base, const FontStyleFrame* frame, StyleStateBlock& temporary); +int RenderCodeWithStyle(FontHandle handle, std::uint32_t code, const StyleStateBlock* style, FontRenderSurface* surface, float x, float y, FontGlyphMetrics* metrics, FontRenderOutput* result); std::uint8_t CachedStyleCacheFlags(const CachedStyle& style); void CachedStyleSetCacheFlags(CachedStyle& style, std::uint8_t flags); diff --git a/core/libs/prx/libSceFont/src/Layout.cpp b/core/libs/prx/libSceFont/src/Layout.cpp index 8bce6e00c2..f77e392e4c 100644 --- a/core/libs/prx/libSceFont/src/Layout.cpp +++ b/core/libs/prx/libSceFont/src/Layout.cpp @@ -68,28 +68,7 @@ void ClearVerticalLayout(std::uint8_t* outWords) { } const StyleStateBlock* ResolveSurfaceStyleState(const StyleStateBlock* cachedState, const FontRenderSurface* surface, StyleStateBlock& temporary) { - const auto* systemUse = reinterpret_cast(surface->reserved_q); - if ((surface->styleFlag & 0x1) == 0 || !ValidStyleFrame(systemUse->styleframe)) return cachedState; - const FontStyleFrame* frame = systemUse->styleframe; - temporary = *cachedState; - if ((frame->flags1 & STYLE_FRAME_FLAG_SCALE) != 0) { - temporary.scale_unit = frame->scaleUnit; - temporary.scale_w = frame->scalePixelW; - temporary.scale_h = frame->scalePixelH; - temporary.dpi_x = frame->hDpi ? frame->hDpi : 0x48; - temporary.dpi_y = frame->vDpi ? frame->vDpi : 0x48; - } else { - const std::uint32_t wantX = frame->hDpi == 0 ? temporary.dpi_x : frame->hDpi; - const std::uint32_t wantY = frame->vDpi == 0 ? temporary.dpi_y : frame->vDpi; - temporary.dpi_x = wantX != 0 ? 0x48 : 0; - temporary.dpi_y = wantY != 0 ? 0x48 : 0; - } - if ((frame->flags1 & STYLE_FRAME_FLAG_SLANT) != 0) temporary.slant_ratio = frame->slantRatio; - if ((frame->flags1 & STYLE_FRAME_FLAG_WEIGHT) != 0) { - temporary.effect_weight_x = frame->effectWeightX; - temporary.effect_weight_y = frame->effectWeightY; - } - return &temporary; + return ApplyStyleFrame(cachedState, SurfaceStyleFrame(surface), temporary); } void FillImageMetrics(FontRenderOutput* result, const FontGlyphMetrics* metrics, float x, float y) { @@ -440,6 +419,35 @@ int Font::GetCharGlyphMetrics(FontHandle handle, std::uint32_t code, FontGlyphMe return finish(SCE_FONT_OK); } +const FontStyleFrame* Font::SurfaceStyleFrame(const FontRenderSurface* surface) { + const auto* systemUse = reinterpret_cast(surface->reserved_q); + if ((surface->styleFlag & 0x1) == 0 || !ValidStyleFrame(systemUse->styleframe)) return nullptr; + return systemUse->styleframe; +} + +const StyleStateBlock* Font::ApplyStyleFrame(const StyleStateBlock* base, const FontStyleFrame* frame, StyleStateBlock& temporary) { + if (!frame) return base; + temporary = *base; + if ((frame->flags1 & STYLE_FRAME_FLAG_SCALE) != 0) { + temporary.scale_unit = frame->scaleUnit; + temporary.scale_w = frame->scalePixelW; + temporary.scale_h = frame->scalePixelH; + temporary.dpi_x = frame->hDpi ? frame->hDpi : 0x48; + temporary.dpi_y = frame->vDpi ? frame->vDpi : 0x48; + } else { + const std::uint32_t wantX = frame->hDpi == 0 ? temporary.dpi_x : frame->hDpi; + const std::uint32_t wantY = frame->vDpi == 0 ? temporary.dpi_y : frame->vDpi; + temporary.dpi_x = wantX != 0 ? 0x48 : 0; + temporary.dpi_y = wantY != 0 ? 0x48 : 0; + } + if ((frame->flags1 & STYLE_FRAME_FLAG_SLANT) != 0) temporary.slant_ratio = frame->slantRatio; + if ((frame->flags1 & STYLE_FRAME_FLAG_WEIGHT) != 0) { + temporary.effect_weight_x = frame->effectWeightX; + temporary.effect_weight_y = frame->effectWeightY; + } + return &temporary; +} + int Font::RenderCharGlyphImageCore(FontHandle handle, std::uint32_t code, FontRenderSurface* surface, float x, float y, FontGlyphMetrics* metrics, FontRenderOutput* result) { const auto fail = [&](int rc) { ClearRenderOutputs(metrics, result); @@ -451,13 +459,21 @@ int Font::RenderCharGlyphImageCore(FontHandle handle, std::uint32_t code, FontRe auto* font = GetNativeFont(handle); if (font->magic != HANDLE_MAGIC) return fail(SCE_FONT_ERROR_INVALID_FONT_HANDLE); if (!font->renderer) return fail(SCE_FONT_ERROR_NOT_BOUND_RENDERER); + StyleStateBlock surfaceStyle{}; + return RenderCodeWithStyle(handle, code, ResolveSurfaceStyleState(&font->cached_style.state, surface, surfaceStyle), surface, x, y, metrics, result); +} + +int Font::RenderCodeWithStyle(FontHandle handle, std::uint32_t code, const StyleStateBlock* style, FontRenderSurface* surface, float x, float y, FontGlyphMetrics* metrics, FontRenderOutput* result) { + const auto fail = [&](int rc) { + ClearRenderOutputs(metrics, result); + return rc; + }; + auto* font = GetNativeFont(handle); auto* library = static_cast(font->library); if (!library || library->magic != LIBRARY_MAGIC) return fail(SCE_FONT_ERROR_INVALID_FONT_HANDLE); const SysDriver* driver = library->sys_driver; if (!driver || !driver->glyph_index || !driver->set_char_with_dpi || !driver->set_char_default_dpi) return fail(SCE_FONT_ERROR_FATAL); const std::uint32_t modeLow = font->flags & 0x0Fu; - StyleStateBlock surfaceStyle{}; - const StyleStateBlock* style = ResolveSurfaceStyleState(&font->cached_style.state, surface, surfaceStyle); FontObj* obj = nullptr; std::uint32_t lockWord = 0; auto* entry = AcquireFontCtxEntry(FontContext(library, font), font->open_info.ctx_entry_index, modeLow, &obj, &lockWord);