Skip to content

text-freetype2: Fix font index retrieval and increase texture buffer size; add support for Cyrillic characters in glyph caching - #13290

Open
reyohoho wants to merge 3 commits into
obsproject:masterfrom
reyohoho:fix_freetype2_text_sometimes_skips_letters
Open

reyohoho wants to merge 3 commits into
obsproject:masterfrom
reyohoho:fix_freetype2_text_sometimes_skips_letters

Conversation

@reyohoho

@reyohoho reyohoho commented Apr 4, 2026 •

Copy link
Copy Markdown

Description

Fix multiple issues in text-freetype2 that cause glyphs to be silently dropped on Linux:

  1. Fix FC_INDEX retrieval in Fontconfig (find-font-unix.c): FcPatternGetInteger was called with value index 1 instead of 0, requesting a non-existent second value. For TTC/OTC font collections, this caused the wrong face (with incomplete glyph coverage) to be loaded.
  2. Increase glyph atlas from 2048×2048 to 4096×4096 (text-freetype2.c): At larger font sizes (e.g. v2 default 256px), the atlas overflows after caching Latin glyphs. cache_glyphs hits break on "Out of space", and fill_vertex_buffer skips uncached glyphs — producing missing characters.
  3. Pre-cache Cyrillic in cache_standard_glyphs (text-functionality.c): Only ASCII was pre-cached. Cyrillic letters are now included alongside Latin.

Motivation and Context

Fixes #11819
On Linux, text-freetype2 renders strings with missing characters — especially Cyrillic. Windows is unaffected because it uses text-gdiplus, which has no fixed-size atlas.

How Has This Been Tested?

  • Built patched text-freetype2.so on Arch Linux (GCC 15.2.1) against OBS 32.1.1 (Flatpak).
  • Cyrillic text via OBS WebSocket (SetInputSettings) renders completely.
  • No "Out of space trying to render glyphs" warnings at font sizes up to 256px with mixed Latin/Cyrillic.
  • Latin text unaffected.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the master branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

@Fenrirthviti

Copy link
Copy Markdown
Member

If these are distinct bug fixes, please split the commits.

reyohoho added 3 commits April 5, 2026 08:46
FcPatternGetInteger was called with value list index
1 instead of 0, requesting a non-existent second
value. For TTC/OTC font collections where the matched
face has a non-zero index, this caused the wrong face
to be loaded — potentially one with incomplete
character coverage, resulting in missing glyphs.
Increase the glyph texture atlas from 2048x2048 to
4096x4096. At larger font sizes the atlas overflows
after caching standard Latin glyphs, causing
cache_glyphs to break early with "Out of space".
Uncached glyphs are then silently skipped in
fill_vertex_buffer, producing missing characters.
Add Cyrillic uppercase and lowercase characters to
cache_standard_glyphs alongside the existing ASCII
Latin set, so they are available on first render
without relying on on-demand caching.
@reyohoho
reyohoho force-pushed the fix_freetype2_text_sometimes_skips_letters branch from 7e9f2ca to 4d92dcf Compare April 5, 2026 05:49
@reyohoho reyohoho changed the title text-freetype2: Fix font index retrieval and increase texture buffer … text-freetype2: Fix font index retrieval and increase texture buffer size; add support for Cyrillic characters in glyph caching Apr 5, 2026
@WizardCM WizardCM added the kind/bug Categorizes issue or PR as related to a bug. label Apr 18, 2026
vpacher pushed a commit to vpacher/obs-studio that referenced this pull request Oct 18, 2026
…bs-rust#1411)

* test/cmocka: Add failing test for a font that is not face 0 of its file

The Text (FreeType 2) source on Linux loads the first face of a font file
whatever face fontconfig matched (obsproject/obs-studio#11819). A face of
a .ttc/.otc collection, such as Noto Sans CJK SC, TC or KR, or a named
instance of a variable font, such as Adwaita Sans Bold, renders as face
0.

test_text_freetype2_face_index points fontconfig at a directory that
holds only text-collection.ttc, a two-face collection generated by
test/cmocka/data/text-collection.py from synthetic outlines ("OBS
Collection Fixture" Regular as face 0, Bold as face 1), and asks
get_font_path() for each style.

Fails 1 of 2: bold_resolves_to_face_1 ("Bold resolved to face 0 of
.../text-collection.ttc (expected 1)"). Regular passes. Needs no display.

Refs obs-rust#1409.

* text-freetype2: Read the matched font's face index from fontconfig

get_font_path() read FC_INDEX with FcPatternGetInteger(match, FC_INDEX,
1, ...). The third argument is the position among the property's values,
and a matched pattern has one index, at position 0. The call always
failed, fc_index kept its default 0, and FT_New_Face() loaded the first
face of the file (obsproject/obs-studio#11819).

So any font that is not face 0 of its file rendered as face 0: Bold and
the other named instances of a variable font (Adwaita Sans Bold is index
458752 in AdwaitaSans-Regular.ttf), and the faces of a .ttc collection
(Noto Sans CJK SC is face 2 of NotoSansCJK-Regular.ttc; it rendered as
the JP face 0).

Port of the first commit of obsproject/obs-studio#13290 by reyohoho. The
other two commits there (a larger glyph atlas, pre-cached Cyrillic) are
covered here by obs-rust#196's atlas fix and are not part of this change.

test_text_freetype2_face_index: 2 of 2. In the app, Adwaita Sans Bold now
renders bold (513 -> 525 px wide, ink 0.185 -> 0.273 at 96 px), and Noto
Sans CJK SC renders the SC glyphs instead of JP's.

Fixes obs-rust#1409.

Co-Authored-By: reyohoho <[email protected]>

---------

Co-authored-by: reyohoho <[email protected]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Categorizes issue or PR as related to a bug.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Linux] FreeType2 text sometimes skips letters

3 participants