Render Slovak carons in menus and HUD without disturbing the other text

The stock menu font (Gill Sans MT Menu) is a static 243-glyph atlas with no
Latin Extended-A, so "Pokračovať" rendered as "Pokra ova" and "Podrž" as
"Podr". Dialogue, the Nomai translator and the ship log were always fine —
they use Futura PT (663) and Space Mono (612), both of which cover Slovak.

Registering a language font via AddLanguageFont fixes the menus but flips
TextTranslation.IsLanguageLatin() to false, and the game uses that flag to
decide whether dialogue, the translator and the ship log keep their own fonts
or fall back to the language font. So the blanket fix dragged all three onto
the wrong font, oversized and clipping.

Instead: register no language font at all, and postfix only the font getters
(UIStyleManager, PromptManager, GameOverController). Each result goes through
SlovakFont.Fix, which probes the font with Font.HasCharacter and returns it
untouched unless it genuinely cannot draw Slovak — so nothing that already
renders correctly is ever replaced, and the patches are inert in every other
language.

The substitute is Cabin (SIL OFL 1.1), a humanist sans in the Gill Sans
lineage, shipped as a dynamic font with its vertical metrics rewritten to Gill
Sans MT's exact ratios so line height matches and text does not clip.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Jaroslav Beneš
2026-07-21 09:02:56 +02:00
parent 41ee614d33
commit 832a92783b
6 changed files with 312 additions and 5 deletions
+24 -5
View File
@@ -1,3 +1,4 @@
using HarmonyLib;
using OWML.Common;
using OWML.ModHelper;
@@ -6,21 +7,29 @@ namespace SlovakTranslation
/// <summary>
/// Registers Slovenčina as a selectable language via xen-42's Localization
/// Utility (xen.LocalizationUtility). All the heavy lifting lives in the
/// utility; this mod just points it at our translated strings.
/// utility; this mod just points it at our translated strings and patches the
/// few menu/HUD fonts that were never baked with Slovak glyphs (see
/// <see cref="SlovakFont"/>).
/// </summary>
public class SlovakTranslation : ModBehaviour
{
public static SlovakTranslation Instance;
/// <summary>Name the language is registered (and displayed) under.</summary>
public const string LanguageName = "Slovenčina";
/// <summary>Path (relative to the mod folder) to the translated strings.</summary>
public static string translationFile = "assets/Translation.xml";
/// <summary>The Localization Utility's API, kept for reflection in <see cref="SlovakFont"/>.</summary>
internal static ILocalizationAPI LocalizationApi;
private void Start()
{
Instance = this;
var api = ModHelper.Interaction.TryGetModApi<ILocalizationAPI>("xen.LocalizationUtility");
if (api == null)
LocalizationApi = ModHelper.Interaction.TryGetModApi<ILocalizationAPI>("xen.LocalizationUtility");
if (LocalizationApi == null)
{
ModHelper.Console.WriteLine(
"Could not find xen.LocalizationUtility — is Interplanetary Polyglot installed?",
@@ -28,8 +37,18 @@ namespace SlovakTranslation
return;
}
api.RegisterLanguage(this, "Slovenčina", translationFile);
ModHelper.Console.WriteLine("Registered language: Slovenčina", MessageType.Success);
LocalizationApi.RegisterLanguage(this, LanguageName, translationFile);
ModHelper.Console.WriteLine("Registered language: " + LanguageName, MessageType.Success);
// Deliberately *not* AddLanguageFont: that would make IsLanguageLatin false
// and pull dialogue, the translator and the ship log off their correct
// vanilla fonts. We only patch the fonts that can't draw Slovak.
SlovakFont.Load(this);
if (SlovakFont.Loaded)
{
new Harmony("Homer.SlovakTranslation").PatchAll();
ModHelper.Console.WriteLine("Slovak menu/HUD font (Cabin) loaded and patched in.", MessageType.Success);
}
}
}
}