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

SDL_ttf + HarfBuzz #62

Closed
SDLBugzilla opened this issue Feb 11, 2021 · 1 comment
Closed

SDL_ttf + HarfBuzz #62

SDLBugzilla opened this issue Feb 11, 2021 · 1 comment
Assignees
Milestone

Comments

@SDLBugzilla
Copy link
Collaborator

This bug report was migrated from our old Bugzilla tracker.

These attachments are available in the static archive:

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

Comments on the original bug report:

On 2015-06-30 17:18:34 +0000, Sylvain wrote:

Here's a ticket with a modification of SDL_ttf to get it working with the text shaping engine "HarfBuzz" (http://www.freedesktop.org/wiki/Software/HarfBuzz).

SDL_ttf render correctly many languages, but for a few others there are troubles : wrong glyphs, inversed characters, bad positioning.
For instance, all this languages render incorrectly: arabic, bengali, burmese, hindi, kannada, khmer, lao, malayalam, marathi, nepali, persian, sinhala, tamil, telugu, thai.

The issue is that SDL_tff library has to process the string before rendering it, in order to do things like "typographic ligature" and "contextual pattern substitutions".
Those rules are stored in the font ".ttf" file, in the GSUB table (http://partners.adobe.com/public/developer/opentype/index_table_formats1.html), this quite difficult to decode and also to apply.
That's what HarfBuzz does (among other things).

The patch is not meant to be merged because it adds a new dependency that may not be wanted. But, if you plan to render some of the previous languages, you definitely need it.
I have tried ~70 languages, on Linux + Android with success.

On 2015-06-30 17:19:03 +0000, Sylvain wrote:

Created attachment 2208
SDL_ttf.c + HarfBuzz

On 2015-06-30 17:20:03 +0000, Sylvain wrote:

Created attachment 2209
Two new APIs to choose the rendering direction + script

On 2015-06-30 17:20:43 +0000, Sylvain wrote:

Created attachment 2210
compilation file for Android

On 2015-06-30 17:24:58 +0000, Sylvain wrote:

More information:

The file contains also this patch: https://bugzilla.libsdl.org/show_bug.cgi?id=2749

Once you have downloaded the source of HarfBuzz, you need to configure it not to add extra dependencies:
ie: ./configure --with-icu=no --with-cairo=no --with-glib=no --with-gobject=no

Plus, you need to call "make" once, even if it fails (e.g. on android), so that it generates some internal state machine/automate.

On 2015-08-18 20:11:37 +0000, Sylvain wrote:

Created attachment 2247
Android.mk for HarfBuzz

Android.mk used to compile HarfBuzz on Android

On 2019-04-02 08:07:49 +0000, Sylvain wrote:

Created attachment 3722
SDL_ttf.c + HarfBuzz

Update to use HarfBuzz with latest SDL_ttf.c

On 2019-04-02 08:08:21 +0000, Sylvain wrote:

Created attachment 3723
SDL_ttf.h + HarfBuzz

On 2019-04-02 08:10:22 +0000, Sylvain wrote:

Created attachment 3724
Android.mk for HarfBuzz 2.3.1

This is the Android.mk to use for Harfbuzz 2.3.1

On 2019-04-02 08:11:11 +0000, Sylvain wrote:

Created attachment 3725
Android.mk for HarfBuzz 2.3.1

mark previous ones as obsolete

On 2019-04-02 08:12:55 +0000, Sylvain wrote:

Created attachment 3726
Modified Android.mk for SDL_ttf

On 2019-04-04 21:36:03 +0000, Sam Lantinga wrote:

Is it possible to make this a configure option (disabled by default) so we can merge this and make it an option for people?

On 2019-04-05 07:46:40 +0000, Sylvain wrote:

Ok, I'll add this.
So with the source package external/harfbuzz-2.3.1
and a setting in Android.mk to be able to build

On 2019-04-05 13:44:27 +0000, Sylvain wrote:

Just added !

external/harfbuzz-2.3.1 from https://github.com/harfbuzz/harfbuzz/releases
with docs, test and ChangeLog

It needs an Android.mk and a config.h
https://hg.libsdl.org/SDL_ttf/rev/868bbc9fbf4c
Maybe we don't need the config.h because there is a HAVE_CONFIG_H, not sure..

SDL_ttf is patch to use harfbuzz
https://hg.libsdl.org/SDL_ttf/rev/b357aefce885

On 2019-08-29 09:23:10 +0000, Rene Dudfield wrote:

Hello. Thanks!

We (pygame) are very interested in this, as a lot of users have requested this feature. The pygame issue is here for anyone interested in following along: pygame/pygame#464

On 2019-08-29 10:29:20 +0000, Sylvain wrote:

Hello,

You just need the latest head source of SDL_ttf, and compiles with TTF_USE_HARFBUZZ or SUPPORT_HARFBUZZ for Android.

Then pick the right font, set script var (I think sometimes it helps), and renders text. The code is tested on Android, IOS, MacosX, Linux, Windows 10. You maybe need to update your build configuration.

Latest version also include assembly optimizations, bug fix, and subpixel positioning. (https://hg.libsdl.org/SDL_ttf/rev/9f46efc0fde2 )

On 2019-08-29 11:27:47 +0000, Rene Dudfield wrote:

Hello. Thanks for the tips. Some very nice changes coming up in SDL_ttf indeed.

What do you mean by "set script var"?

On 2019-08-29 11:53:01 +0000, Sylvain wrote:

I meant TTF_SetScript() to tell harfbuzz the language/script.

On 2019-08-29 12:04:21 +0000, Rene Dudfield wrote:

Ah yes.

How does a user know which script to set for a font?

On 2019-08-29 13:10:35 +0000, Sylvain wrote:

Because of the language he want to write. See harfbuzz doc for scripts.

He also has to choose his fonts, because not all fonts render all languages.

I think HB also has a function to auto detect script.

On 2020-07-28 20:02:30 +0000, Mehdi Sadeghi wrote:

While trying to add RTL to INSTEAD game engine I came across this patch. Since Sylvain has already made a patch and Sam showed the green light for merging it as an option, is there any chance to move this forward?

Thanks for spending your (free) time on this.

On 2020-07-28 21:25:20 +0000, Sylvain wrote:

hi thanks,
many things were merged in the SDL_ttf head already
see
https://hg.libsdl.org/SDL_ttf/
https://hg.libsdl.org/SDL_ttf/shortlog

On 2020-07-29 12:22:51 +0000, Mehdi Sadeghi wrote:

(In reply to Sylvain from comment # 21)

hi thanks,
many things were merged in the SDL_ttf head already
see
https://hg.libsdl.org/SDL_ttf/
https://hg.libsdl.org/SDL_ttf/shortlog

Would you mind pointing me to the right compile procedure to get the latest SDL_ttf compiled for Linux desktop (not Android) with HarfBuzz support included?

I was initially able to compile SDL_ttf with your patch from here (https://discourse.libsdl.org/t/sdl-for-farsi-or-persian-text/25292/7) and by calling TTF_SetDirection( HB_DIRECTION_RTL ) and TTF_SetScript(HB_SCRIPT_ARABIC), and using a ttf font such as DejaVuSans.ttf I could see proper rendered text.

However, with the latest changes, no matter what I do I get boxes again. Probably I have messed up things when fighting with cmake and make to enable the feature. The program compiles though, so it means the functions are there but have no effect.

Thanks in advance for any tips.

On 2020-07-29 12:31:26 +0000, Sylvain wrote:

Edit the SDL_ttf.c source and set TTF_USE_HARFBUZZ to 1, or define it from upper level.
Compile with configure for instance. you need to also provide include and library path to harfbuzz.

On 2020-07-29 12:31:46 +0000, Sylvain wrote:

you still need TTF_SetDirection( HB_DIRECTION_RTL ) and TTF_SetScript(HB_SCRIPT_ARABIC),

On 2020-07-29 21:16:35 +0000, Mehdi Sadeghi wrote:

(In reply to Sylvain from comment # 23)

Edit the SDL_ttf.c source and set TTF_USE_HARFBUZZ to 1, or define it from
upper level.
Compile with configure for instance. you need to also provide include and
library path to harfbuzz.

sorry, it was my fault. The font in my program was pointing to a wrong file. I changed the SDL_ttf.c and it worked like charm. However, I was unable to set it via configure. Is there any specific configure flag for it? I searched the autotools source files and even tried to define the variable using AC_DEFINE to no avail.

On 2020-07-30 12:43:17 +0000, Sylvain wrote:

sorry there was no configure modification.
though you can set some CFLAGS environment variable to set the TTF_USE_HARFBUZZ define.

Fell free to submit a patch so it can be enable with configure, but sync with Sam about the usual way to do it.

On 2021-02-01 19:41:02 +0000, Mehdi Sadeghi wrote:

I though I'll let you know that this change is now included in the emscripten-core by default, i.e. TTF_USE_HARFBUZZ is set to 1. Providing -s USE_SDL_TTF=2 when compiling should be enough to compile C code to WASM with HarfBuzz support.

See:
emscripten-core/emscripten@1690a58#diff-874f33563125619a7a5cb567ebe523c59258662d69858d78d24d947b275f9c6cR40

On 2021-02-02 07:15:35 +0000, Sylvain wrote:

Ok, thanks for heads up!

@slouken
Copy link
Collaborator

slouken commented Dec 31, 2021

This is implemented for SDL_ttf 2.0.18.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants