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

strange bug with TTF_OpenFontIndexRW/TTF_OpenFontRW and render UTF8/Unicode string #108

Closed
SDLBugzilla opened this issue Feb 11, 2021 · 0 comments
Labels
invalid This doesn't seem right

Comments

@SDLBugzilla
Copy link
Collaborator

SDLBugzilla commented Feb 11, 2021

This bug report was migrated from our old Bugzilla tracker.

These attachments are available in the static archive:

Reported in version: 2.0.15
Reported for operating system, platform: Linux, x86_64

Comments on the original bug report:

On 2019-02-28 15:40:50 +0000, ace wrote:

Created attachment 3660
bug.c + PT Serif_Italic.ttf + Makefile

Initially this bug was found under windows in my C# project used shared libs via wrapper SDL2-CS
SDL 2.0.8
SDL_ttf 2.0.15 / 2.0.14
After bug localization i could confirm it under linux in pure c(files in attachment)
Bug description:
If you use TTF_OpenFontIndexRW or TTF_OpenFontRW for creating TTF_Font with same SDL_RWops (for creating SDL_RWops I used SDL_RWFromFile, SDL_RWFromMem, SDL_RWFromConstMem) and you render text using TTF_RenderUTF8_Blended:

first TTF_Font font_2 with russian symbol "й"
second TTF_Font font_6 with any text: text will be blank(i set TTF_STYLE_UNDERLINE to second one to indicate that it was being rendered)
You got this:
https://drive.google.com/file/d/1Fo9JFQsPJuMTW6_FDJ1ZcZ-3K8IdgUCD/view

If you don’t use russian symbol "й" in first render, you will get this:
https://drive.google.com/file/d/1qgRupAG5SFobG3NXAM46j6ilvHx1STPt/view

Finaly, if you use TTF_OpenFontIndex / TTF_OpenFont instead of TTF_OpenFontIndexRW / TTF_OpenFontRW, rendering works as it should:
https://drive.google.com/file/d/1HP0RxDoSknUHHEHIfK_HN96SYesBYlOM/view

Hope you can help me, because using TTF_OpenFontIndex instead of TTF_OpenFontIndexRW is very expensive.

On 2019-02-28 16:31:06 +0000, Sylvain wrote:

You need to rewind the RWops between the two calls of TTF_OpenFontIndexRW:

SDL_RWseek(RWops, 0, RW_SEEK_SET);

But I'm not sure why there was no error ...

On 2019-02-28 20:45:38 +0000, ace wrote:

Thanks for your comment!
Yes, it was solve problem in c, but SDL_RWseek() is macro, and unavailable in bindings (https://www.libsdl.org/languages.php)

I think good solution will be:
Calls SDL_RWseek() in TTF_OpenFontIndexRW/TTF_OpenFontRW
AND/OR
Replace this macro with function

And I'm really was confused with original version of bug:
https://drive.google.com/file/d/1COvG_VyOooe_fyu0p3DVbMZj8uMrnFL9/view
In log at picture, after every line with "Rendering [...].." next line is "Font:NN ..." , where NN is ID in array of SDL_RWops, which used to render this line.

On 2019-03-01 07:09:11 +0000, ace wrote:

I came to the conclusion that using SDL_RWseek(RWops, 0, RW_SEEK_SET) inside TTF_OpenFontIndexRW or TTF_OpenFontRW was bad idea,
so i created feature request in SDL2 tracker to replace macros with functions:
https://bugzilla.libsdl.org/show_bug.cgi?id=4526

On 2019-03-01 08:25:49 +0000, Sylvain wrote:

I also think we shouldn't reset the RWops in SDL_ttf, because user can provide a concatenated ttf files. So I marked this as resolved.

But I haven't understand the issue of your last link "original version of bug".
If there is still a issue or not. So re-opened if this is a mistake.

On 2019-03-01 09:22:57 +0000, ace wrote:

I thought this is a bug, because TTF_OpenFontIndexRW and TTF_OpenFontRW don't return NULL and generate error, if I give them RWops with position at the end of file.

About "original version of bug":
At this moment i am unable call SDL_RWseek(RWops, 0, RW_SEEK_SET) in my C# project.

I use SDL_RWFromMem to create RWops, and i wondered why it works in this way?
You can see that lines with style = 2,6,10,14 used same RWops(18) for TTF_OpenFontIndexRW, but bugged rendering only with style = 6

Or for example lines with style = 0, 4, 8, 12 - used same RWops(19) - but rendered without any problems.

On 2019-03-01 09:40:36 +0000, ace wrote:

OR you can add make small change:
if (position at the еnd of RWops) SDL_RWseek(RWops, 0, RW_SEEK_SET)

It will be solve my problem and don't broken projects, which use this undetermined behavior.

On 2019-03-01 13:47:16 +0000, Sylvain wrote:

Not sure if you can always use SEEK_END eg detect the position at the end of rwops.
For instance RWops could be a http stream (this extension: https://github.com/mgerhardy/SDL_rwhttp )

I look more in details. When it fails, it both:

  • returns 0 size metrics (except the advance which is correct)
  • returns 0 size after FT rendering.

Those are valid datas .. (like a space)

So for some reason, FreeType seems robust ...
(maybe there would things to report to FT ... http://git.savannah.gnu.org/cgit/freetype/ )

What you can do maybe, is getting a new RWops from the same memory ?

On 2019-03-01 17:32:21 +0000, ace wrote:

What you can do maybe, is getting a new RWops from the same memory ?
I implemented this already, but there is still a small memory leak - I couldn't call SDL_RWclose() cause it's macros :(

I closing this issue: will be wait https://bugzilla.libsdl.org/show_bug.cgi?id=4526
... or maybe make patch by myself (i need SDL 2.0.8, but if this feature request will be accepted, i think it will be only in next release).

Thanks for your help!)

On 2019-03-01 17:56:11 +0000, ace wrote:

I just realize that i could use freesrc=1, when calling TTF_OpenFontIndexRW, and this will be solve my problems at all.

Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

1 participant