Do you consider to extend "draw string" with UTF8 support?
If i see it correctly, it's a rewrite of gfx_drawstring.c maybe as seperate file supporting UTF multibyte chars
https://github.com/freebasic/fbc/blob/m ... awstring.c
So you need a large symbol table with max 2^21-1 elements 16MB(64 bit 32MB):
FBGFX_CHAR char_data[256] must be changed to FBGFX_CHAR char_data[last] 'last element of font.
it has to be allocated / reallocated only when font changes.
And the for loop walking through the string has to be changed accordingly (from line 133)
Did i miss something?
Suggestion: UTF-8 Support for Draw String
-
- Posts: 252
- Joined: Mar 12, 2006 16:25
Re: Suggestion: UTF-8 Support for Draw String
I think you miss the font specials needed for full UTF-8 support.
Ie. cairo grafics library has a "toy text" support using UTF-8 input. But when you want complete UTF-8 support you've to include Pango and PangoCairo. So I think at least Pango is necessary to implement UTF-8 for FB.
Why don't you use the Pango, PangoCairo, cairo combination?
Ie. cairo grafics library has a "toy text" support using UTF-8 input. But when you want complete UTF-8 support you've to include Pango and PangoCairo. So I think at least Pango is necessary to implement UTF-8 for FB.
Why don't you use the Pango, PangoCairo, cairo combination?
-
- Posts: 252
- Joined: Mar 12, 2006 16:25
Re: Suggestion: UTF-8 Support for Draw String
Well reading UTF-8 files isn't very hard, but how do you put UTF-8 stringdata onto FBGFX buffer? I know i could use gtk+ widgets, or something else.
I plan to write a text game were i put all logic/texts into lua files/tables. Lua has no problems with utf-8 within stringdata. I tested it with a GTK3 widget and i could load a string from a lua table as label. I want to draw some simple text? Is an additional library really needed? With only lua and freebasic functions it would be ultra portable, if i could use a font with unicode support, without additional library. Does Cairo Pango work under DOS?
Recompiling wouldnt even be needed so often, because the logic is in lua files.
I plan to write a text game were i put all logic/texts into lua files/tables. Lua has no problems with utf-8 within stringdata. I tested it with a GTK3 widget and i could load a string from a lua table as label. I want to draw some simple text? Is an additional library really needed? With only lua and freebasic functions it would be ultra portable, if i could use a font with unicode support, without additional library. Does Cairo Pango work under DOS?
Recompiling wouldnt even be needed so often, because the logic is in lua files.
Re: Suggestion: UTF-8 Support for Draw String
There isn't one font for UTF-8. Several fonts are used to draw latin, cyrilic or chinese letters. The Pango library is designed to select the matching font (& style & size).RockTheSchock wrote:..., if i could use a font with unicode support, without additional library.
Neither the Pango-PangoCairo-cairo combination nor GTK+ work under DOS.RockTheSchock wrote:Does Cairo Pango work under DOS?
The output in a GTK+ label gets generated by the above mentioned combination. So if you need GUI features (or network features from Gio) I recommend to include GTK. But if you want text output only and use a home-brew GUI, it's enough to include the combination (which is part of GTK+).
You didn't mention what you're doing with the stringdata in Lua. I guess you can handle the files/tables with GLib as well (which is also part of GTK+). GLib should be faster than the Lua interpreter. libjson-glib might be attractive for easy handling of tables.
-
- Posts: 252
- Joined: Mar 12, 2006 16:25
Re: Suggestion: UTF-8 Support for Draw String
Well i searched a bit and found this:
http://bjoern.hoehrmann.de/utf-8/decoder/dfa/
Then i translated the code and combined it with a freetype example code:
http://www.freebasic-portal.de/porticul ... -1783.html
Basically you can Print a String with embedded UTF-8 characters. So if you need to display some documentation it should be possible to use this under DOS, too. You need the FreeType2 library for DOS though.
http://bjoern.hoehrmann.de/utf-8/decoder/dfa/
Then i translated the code and combined it with a freetype example code:
http://www.freebasic-portal.de/porticul ... -1783.html
Basically you can Print a String with embedded UTF-8 characters. So if you need to display some documentation it should be possible to use this under DOS, too. You need the FreeType2 library for DOS though.
Code: Select all
Dim text As String
ScreenRes 800, 240, 32
Dim ArialFont As Integer
ArialFont = GetFont(font_filename)
If ArialFont = 0 Then Print "couldn't find it": Sleep: End
text=!"schau mal, \&hE2\&h82\&hAC diese toooooooooolle textausgabe\nschaut doch gut aus. \noder?"
PrintFT 10,100,text,arialfont,23,RGB(255,255,0)
Sleep
Re: Suggestion: UTF-8 Support for Draw String
This is what cairo calls a "toy text API". It supports just a few characters. When you try to use non-latin characters (ie. cyrilic, arabian, chinese, ...) the solution fails, since the characters are not in the font.
-
- Posts: 252
- Joined: Mar 12, 2006 16:25
Re: Suggestion: UTF-8 Support for Draw String
You are right that it fails, if the selected font lacks the characters.Though you could expand the code easily to use a list of fonts, where as fallback it can look for a glyph in fontlist.
In most cases you can predict which font you want to use for the text in your application. So it's meant to display easily utf-8 characters of the font you choose to bundle with your application. There is no compatible input routine, so if you need a keyboard input you propably should use a GUI framework like GTK, QT or even SDL.
If the fonts shipped with your OS doesn't meet your needs there is Noto:
https://www.google.com/get/noto/
In most cases you can predict which font you want to use for the text in your application. So it's meant to display easily utf-8 characters of the font you choose to bundle with your application. There is no compatible input routine, so if you need a keyboard input you propably should use a GUI framework like GTK, QT or even SDL.
If the fonts shipped with your OS doesn't meet your needs there is Noto:
https://www.google.com/get/noto/
Re: Suggestion: UTF-8 Support for Draw String
I'm just wondering why you spend so much time in such a low level solution. In the same time you could have learned how to use cairo library and you could benefit from all its advanced features further on.