Skip to content

plugins/text-freetype2: Clean up file access code#13467

Open
Lain-B wants to merge 6 commits into
obsproject:masterfrom
Lain-B:fix-freetype-null-chars
Open

plugins/text-freetype2: Clean up file access code#13467
Lain-B wants to merge 6 commits into
obsproject:masterfrom
Lain-B:fix-freetype-null-chars

Conversation

@Lain-B

@Lain-B Lain-B commented May 25, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR contains numerous fixes for file access with the text-freetype2 text source:

  1. Remove redundant/deprecated Windows-only UTF16 code -- the freetype2 text source is deprecated on Windows and no one, even on Windows, is actually going to use UTF16 BOM text files. I don't know why that code was even there. Just completely pointless code.
  2. Fix fread() parameter usage, it was using size instead of count for the number of bytes to read, which technically still works but is backwards from how its intended to be used.
  3. Optimize "log mode" file reads. It was calling countless fread() calls one single character at a time while trying to find the appropriate place to start reading from. Once I saw this situation I couldn't just not fix it. It was insane. I changed it to read in reasonable chunks of 1k bytes and analyze that data chunk by chunk instead.
  4. Minor refactor of file reading code. Some unnecessarily duplicated code. Probably more out there in the rest of the source but I'm keeping it to the file-related code for this PR for now to prevent my sanity levels from dropping too low.
  5. Ignore null bytes when reading text files, which was what I was originally trying to just fix, but which lead me down a rabbit hole of other issues in the surrounding code.

Fixes #7595

Motivation and Context

In my journey of investigating #7595 (that many have proposed fixes to over the years), I realized that there was quite a few things to fix with file reading. This is the culmination of those fixes.

There are probably more things that could probably be fixed in text-freetype2 -- I would argue the source needs to be completely rewritten from scratch with a text renderer that also handles text shaping properly -- but I would prefer to keep it focused on just fixing the issue properly, and fixing a few related issues and not like, bike shed the god forsaken text-freetype2 source to death.

If someone wants to rewrite this thing then please do, this thing needs a bulldozer. I just want to get the issues and those other PRs closed to remove some ancient gunk from our repository.

How Has This Been Tested?

Tested on Linux. Tested file reading to ensure that it worked, tested log mode to ensure that it also still worked properly.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)

Checklist:

  • I have read the contributing document.
  • My code has been run through clang-format.
  • My code follows the project's style guidelines
  • My code is not on the master branch.
  • My code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation. (N/A)

Lain-B added 3 commits May 24, 2026 18:18
This code is Windows-only, where the source is already deprecated.
This improves support for large text file sizes when using log mode and
fixes types that were unnecessarily inconsistent.
The `size` parameter of fread should be consistent with the type used
with the array you're reading into, while `count` should specify how
many of that type you're reading. Considering we're reading an array of
characters, `size` should be the size of a `char` (1) and `count` should
be the number of characters we want to read.
@WizardCM WizardCM added kind/bug Categorizes issue or PR as related to a bug. kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. labels May 25, 2026
@Lain-B Lain-B force-pushed the fix-freetype-null-chars branch from 70d48a4 to 8b33d16 Compare May 27, 2026 00:52
Lain-B added 3 commits May 26, 2026 17:53
Log mode would call fread() for single individual characters from end of
the file to the beginning in order to check to see where it has to start
reading from. This seems unnecessarily unoptimal, so fix this to read
1024 byte chunks and check to see where to start from that way. Should
result in far fewer unnecessary fread() calls.

(Author note: I would just make this read the whole file, but I am
doing it this way under the assumption that there are users who may use
this with very large files of log data.)
Files might sometimes contain '\0' characters, which would cause all
text after the '\0' characters to not be included.

Fixes obsproject#7595
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. kind/enhancement Enhancements are not bugs or new features but can improve usability or performance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

'Text (FreeType 2)' element only reading first line of file (when 'Read from file' is checked)

2 participants