Player icon indicating copy to clipboard operation
Player copied to clipboard

Support Freetype+Harfbuzz

Open Ghabry opened this issue 9 years ago • 22 comments

Will be needed to handle complex scripts that use combining diacritic marks.

Ghabry avatar Feb 01 '16 12:02 Ghabry

@pureexe do RPG Maker 2000/2003 Thai-scripted games exist? (Apart of your translation). Because RPG Maker 2000 resolution is small, and Thai script for 6×12px width (half width) looks too small to display all diacritics, maybe is worth to break the half fixed width limitation of RPG_RT and use a variable width (or even 12×12px full width) in EasyRPG Player. However, if there exist games translated already, maybe they won't fit if they use too long lines (RPG Maker allows 50 half-width glyphs per line).

fdelapena avatar Feb 01 '16 19:02 fdelapena

For now, We don't have any Thai scripted game created with RPG Maker 2000/2003 yet.

but 12x12 is enough for display thai character.

this is yanderella with nearly correct thai language display.

We use moded RM2000 font you can download it here.

https://www.dropbox.com/s/n6w75c3m0sv5c7n/rm2000.fon?dl=0

and run with this game file (this is test not full game so file just 4MB) http://www.mediafire.com/download/yz4yjzzeiqo9fdz/yanderella-thai-test.rar

pureexe avatar Feb 02 '16 01:02 pureexe

Could you write this text normally here on github? So we can see how the correct rendering should look like.

Ghabry avatar Feb 02 '16 07:02 Ghabry

กาลครั้งหนึ่งนานมาแล้ว มีหญิงสาวสวยนามว่า ซินเดอเรลล่า

pureexe avatar Feb 02 '16 08:02 pureexe

Okay by measuring I would say that we need at least 22 pixel of height to fit everything with something above (รั้) and below (ญิ) beautifully. Needs some testing if freetype can somehow squash this in less.

I think the long term solution for this is to modify the whole rendering code of the Player to render with more pixels...

Ghabry avatar Feb 02 '16 09:02 Ghabry

@pureexe how readable would you consider this?

test

It is just a font rendering test using a fixed width font (Arundina Sans Mono) using freetype+harfbuzz at 11 px height (with auto width), seems to fit exactly 6 px width as RPG_RT does, which is good.

fdelapena avatar Feb 02 '16 23:02 fdelapena

@fdelapena wow! pretty good. it's 100% display correctly.

pureexe avatar Feb 02 '16 23:02 pureexe

@fdelapena That's great! It seemed to display perfectly. Only that the fonts looked a bit blurry but that's not a big problem anyways.

Thank you for showing that to us!

We will looking forward to see RM2000/2003 to be able to support Thai perfectly.

whateverzone avatar Feb 03 '16 15:02 whateverzone

@whateverzone I'm currently investigating ways to improve the rendering by using higher resolutions. This will result in great font rendering because doubling the resolution already gives 4 times the pixel. But the blurry font is a good start. When a better rendering is implemented it will "just work" without any ingame changes :)

@fdelapena I would be interested in a screenshot without AA :D

Ghabry avatar Feb 03 '16 15:02 Ghabry

@Ghabry Wow! Thank you for telling me that! I hope your investigation goes well. We really want to see RM2000/2003's games with Thai version and also translation works such as Ib, Wadanohara etc.

Thank you very much for helping us ^^.

whateverzone avatar Feb 03 '16 16:02 whateverzone

Here some real rendering tests in the engine. Without harfbuzz, so the diacritics are wrong:

Normal resolution (1x / 320x240) screenshot_6

HiRes (2x / 640x480): screenshot_7

Ghabry avatar Feb 06 '16 22:02 Ghabry

@Ghabry Can you make diacritics display correctly?

pureexe avatar Feb 08 '16 11:02 pureexe

@pureexe Not with the current codebase. But is of course possible to implement. The font rendering on the screenshot is already modified code, so this is the first step for fixing diacritics. Just wanted to show you a real version so you can check how readable 1x and 2x is. Do you consider 1x readable?

Ghabry avatar Feb 08 '16 14:02 Ghabry

@Ghabry I confirmed 1x and 2x is readable font.

@whateverzone Do you think is it readable?

pureexe avatar Feb 08 '16 14:02 pureexe

@pureexe Yes, I do.

whateverzone avatar Feb 08 '16 14:02 whateverzone

Update for the Thai people. Working again on this, hope I can get some results soon ^^ (around November)

Ghabry avatar Oct 02 '16 21:10 Ghabry

Thank you for working on this again.

pureexe avatar Oct 02 '16 23:10 pureexe

Hello! It's been a while. I just wondered if you are still working on this or not.

whateverzone avatar Oct 03 '17 14:10 whateverzone

Yes, I finally made some progress :D. Though this is still not complete because I also have to rework the messagebox code which renders char-by-char and this won't work with harfbuzz.

screenshot_20171029_215343

Ghabry avatar Oct 29 '17 20:10 Ghabry

I think the 1bit-rendering looks better on that resolution:

screenshot_20171029_230731

Ghabry avatar Oct 29 '17 22:10 Ghabry

Works now in message boxes. Due to tecnical reasons (need to split at most \-command codes) the rendering gets worse as I can't render in one go. To fix this I would need to analyze the right part of the bounding box and crop the empty rows :/

Well and some stuff just can't be simulated because Freetype moves some glyphs below others for esthetics.

screenshot_20171030_191550

Using a different "Hinter". Does this look better or worse?

screenshot_20171030_194450

Ghabry avatar Oct 30 '17 18:10 Ghabry

About the configuration. I don't want to support font-config or any font substitution now because have no idea how to use this and not worth the afford by now imo.

I would propose a configuration in the RPG_RT.ini:

[EasyRPG]
Font=Arial;12;Mincho;11
Font2=Verdana;11

The font depends on which Font is selected for the system graphic. When one font is not defined it uses the normal built-in one.

Assuming the System graphic Font is the 1st this will look in the "Font" folder of the game for Arial.ttf and Mincho.ttf and render Arial glyphs with size 12 and when a glyph is missing in the font it renders a Mincho glyph with size 11.

As a "flow chart":

           Missing              Missing           Missing
Arial 12pt -------> Mincho 11pt -------> built-in -------> <?>

Same for the command line: --font and --font2

Ghabry avatar Oct 30 '17 19:10 Ghabry

WIP Harfbuzz branch: https://github.com/Ghabry/easyrpg-player/commits/harfbuzz

Wasn't that hard. Only lost two hours because I forgot to divide offset with 64 :facepalm: . Not very intuitive because normal Freetype doesn't need this divide for offset (bitmap) :roll_eyes:

Size calculation has some bugs and it doesn't work for the message box yet. The message box is hard to do because the text appears glyph by glyph and it has all this command processing etc.

Comparison (click to enlarge):

Left is w/o HB, Right is w/ HB

The Thai rendering of the stacked glyphs is correct now (trust me, I compared this with SDL_TTF and in Chrome ;))

out

Spot the difference ;) (look for ligatures and letters that are "moved under" other letters like e.g. in case of 'To')

out2

Ghabry avatar Nov 06 '22 02:11 Ghabry

Added (Experimental) shaping support for Window Message. Even works properly for color codes etc. :)

screenshot_12

Sans Serif vs. Serif:

กาลครั้งหนึ่ง Alexกำลังเรียนภาษาไทย Unicodeเจ๋งมาก!

out

@pureexe better late than never I guess :thinking:

Ghabry avatar Nov 06 '22 11:11 Ghabry

Looking good! Better late than never 😊

pureexe avatar Nov 07 '22 13:11 pureexe