Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

为游戏内叠加层添加本地化支持 #600

Merged
merged 19 commits into from
May 15, 2023
Merged

为游戏内叠加层添加本地化支持 #600

merged 19 commits into from
May 15, 2023

Conversation

Blinue
Copy link
Owner

@Blinue Blinue commented May 11, 2023

使用 #592 所讨论的方式实现游戏内叠加层的本地化。这为在缩放时修改效果参数打下了基础。

ImGui 的字体没有 fallback 机制,必须手动构建。我计划根据 https://learn.microsoft.com/en-us/windows/apps/design/style/typography#fonts-for-non-latin-languages 的推荐,根据显示语言加载对应字体。

Segoe UI 本身支持不少语言:
图片
需要加载额外字体的只有:简体中文(Microsoft YaHei UI)、繁体中文(Microsoft JhengHei UI)和日语(Yu Gothic UI)

这个 PR 做了以下修改:

  1. 根据显示语言自动选择字体
  2. 实现了 CJKCharacterSetForImGui 工具导出字符表
  3. 简体中文、繁体中文和日语使用的字符表:
  4. 游戏内叠加层所有字符串的本地化

已知问题:打开叠加层会有一瞬间的卡顿,因为加载字体是同步完成的。这将在下一个 PR 中通过缓存构建完成的字体数据解决。

@Blinue Blinue added enhancement New feature or request area: localization i18n and L10n labels May 11, 2023
@Blinue
Copy link
Owner Author

Blinue commented May 12, 2023

现在有两个问题:

  1. ImGui 没有繁体中文的常用字符(简体中文有 GetGlyphRangesChineseSimplifiedCommon),我不得不使用 GetGlyphRangesChineseFull,它包含了两万多个字符,产生了巨大的 Font Atlas。
    image

  2. 日语字体虽然使用了 Yu Gothic UI,但和系统的呈现效果有点不同,系统界面上日语字符较窄。
    image
    image

@Blinue
Copy link
Owner Author

Blinue commented May 12, 2023

第二个问题已解决。YuGothM.ttc 包含了两个字体:Yu Gothic Medium 和 Yu Gothic UI,第二个才是我们需要的。
image

@Blinue
Copy link
Owner Author

Blinue commented May 13, 2023

简/繁中文和日语的 UI 字体需要大量的系统资源,因此只会在真正需要时再加载。只显示 FPS 时不会加载它们。

@Blinue
Copy link
Owner Author

Blinue commented May 13, 2023

鉴于 GetGlyphRangesChineseSimplifiedCommon 只包含 2500 个中文字符,以及为了支持繁体中文的常用字符,我会写一个字符编码导出工具,格式参考 https://github.com/ocornut/imgui/blob/bcfc1ad8f63997751a7269788511157ed872da2c/imgui_draw.cpp#L2883

GitHub
Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies - imgui/imgui_draw.cpp at bcfc1ad8f63997751a7269788511157ed872da2c · ocornut/imgui

更新:
又有了发现:https://github.com/flyinghead/flycast/blob/master/core/rend/gui_util.cpp 有繁中和简中的常用字,其中繁中 4800 多字,简中 7800 多字。对于简中通用规范汉字表里的一级字表(3500字)已经够用了,可以在性能和实用上达成平衡。

更新 2:
已实现 CJKCharacterSetForImGui 工具,以及导出了 3500 字的简体中文字符表。

@Blinue
Copy link
Owner Author

Blinue commented May 14, 2023

image

还有一个小问题,打开叠加层会有一瞬间的卡顿,因为加载字体是同步完成的。即使尽力减少字符数量,卡顿还是不可避免。

@Blinue Blinue merged commit b7e7be7 into dev May 15, 2023
@Blinue Blinue deleted the overlay-localization branch May 15, 2023 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: localization i18n and L10n enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant