Page 1 of 1
Font layouting
Posted: Wed Apr 06, 2016 9:12 am
by max
Hey guys,
I've ported
cairo to supersede my old self-made painting libraries I've written for the GUI of Ghost. I have freetype2 as the backend. I had a text layouting functionality that used the glyphs provided by freetype and did the layouting itself. This works okay for normal text, but will fail for UTF-8 and those special fancy-text-things like ligatures. Cairo itself provides some-sort-of API for text rendering, but when searching for info I mostly read that it only has a toy API and you should use something proper like
Pango to layout glyphs for UTF-8 texts.
So I tried to port Pango - I ported expat, fontconfig and harfbuzz for the missing dependencies.. But what's still missing is "glib" - that Gnome/GTK utility library. I'm not really willing to port that sort of stuff on my OS..
Questions I have for anyone who has some experience with this:
* Can you properly layout UTF-8 only with Cairo? Are there any sources/documentation that show how?
* Alternatively, can you build Pango without glib?
* Or is there a good, lightweight alternative to Pango that doesn't bring all that bulk and just layouts text?
It really bugs me that those libraries use thousands of dependencies and completely loose portability; why the hell am I forced to have that weird fontconfig stuff to layout text
Any help is greatly appreciated.
BTW: I thought about writing a little in the Wiki about how to program a more complex user interface, if there is interest let me know.
Greets
Re: Font layouting
Posted: Wed Apr 06, 2016 3:38 pm
by gerryg400
Hi max,
max wrote:* Can you properly layout UTF-8 only with Cairo? Are there any sources/documentation that show how?
Cairo expects your characters to be in UTF-8 format. I have the opposite problem because internally I use wchar_t format and when I need to render them convert the characters one-by-one to UTF-8 and call cairo_show_text() for each character.
max wrote:* Alternatively, can you build Pango without glib?
Probably not. I tried but failed.
max wrote:* Or is there a good, lightweight alternative to Pango that doesn't bring all that bulk and just layouts text?
Don't think so.
At the moment I use the toy interface. One day I hope to find the time to re-visit this and do it a little better.
Re: Font layouting
Posted: Thu Apr 07, 2016 1:13 am
by max
Hi gerryg400,
thanks for your reply. I guess they use those util functions of glib a lot in pango, so we won't have a chance to use it without. The only alternative I found was something like ICU, but it's also not really for the purpose.
I guess I'll modify my previous version (you can see the stuff
here) and try to use the glyph stuff that cairo gives. There's this function
cairo_scaled_font_text_to_glyphs that seems to be able to do the conversion as needed, not sure about the practicability though. I'll add some infos here if I find something out.
The guys from freetype2 are working on a layouting library, I hope this one will do good one day:
http://freetype.sourceforge.net/ftlayout/
Greets
Re: Font layouting
Posted: Sun Apr 17, 2016 11:42 pm
by JoeEagar
Unicode layouting is a royal pain. The good news is that Latin languages are easy. If you do need more advanced Unicode support (e.g. Asian languages, combining characters, etc), you might want to look at how wine handles this (win32 has a really great unicode layout api). See:
https://github.com/wine-mirror/wine/tre ... dlls/usp10
Re: Font layouting
Posted: Mon Apr 18, 2016 9:21 am
by max
JoeEagar wrote:Unicode layouting is a royal pain. The good news is that Latin languages are easy. If you do need more advanced Unicode support (e.g. Asian languages, combining characters, etc), you might want to look at how wine handles this (win32 has a really great unicode layout api). See:
https://github.com/wine-mirror/wine/tre ... dlls/usp10
Well right for latin languages it's straight-forward and my freetype-only implementation was already working quite well. I'll have a look at this when I come to more exotic texts.
I think I've gotten closer to getting the proper functions for freetype2 and cairo only, but the documentation for the cairo text stuff is really incomplete and I'm missing some connections here. I made a
StackOverflow question here, maybe there is someone out there who has tried something similar.
Re: Font layouting
Posted: Tue Apr 19, 2016 9:05 am
by embryo2
max wrote:I've ported
cairo to supersede my old self-made painting libraries I've written for the GUI of Ghost.
What stops you from continue to develop your own libraries? Is there a hard to resolve design issue?
max wrote:BTW: I thought about writing a little in the Wiki about how to program a more complex user interface, if there is interest let me know.
Can you outline a plan for it? Or a content, if you wish.
Re: Font layouting
Posted: Tue Apr 19, 2016 11:11 am
by max
embryo2 wrote:What stops you from continue to develop your own libraries? Is there a hard to resolve design issue?
Implementing the extensive painting functionality (gradients, paths, alphablending, various renderings) in a performance-efficient way (like cairo does with lib-pixman using SSE) is very time-consuming and complex. It's not something that you can just hack together yourself and expect a good output. Also I feel it's not scope of my project of developing a nice OS, reusing a great library is fine.
embryo2 wrote:Can you outline a plan for it? Or a content, if you wish.
Well the current article about
GUI's is quite incomplete. It should explain important concepts like structuring the window hierarchy well, blitting only stuff that changed, having an interface where programs can create components etc.. Also I could not find
any proper source around the internet that talks about how to implement a window system from scratch. I would try to cover these points, provide ways how to start, and in general how doing that stuff is possible.
Re: Font layouting
Posted: Wed Apr 20, 2016 4:36 am
by embryo2
max wrote:embryo2 wrote:What stops you from continue to develop your own libraries? Is there a hard to resolve design issue?
Implementing the extensive painting functionality (gradients, paths, alphablending, various renderings) in a performance-efficient way (like cairo does with lib-pixman using SSE) is very time-consuming and complex.
The font related subject has distracted me a bit from rich painting functionality. But how the encoding (utf-8) is related to the drawing? The translation from a character to a symbol id is straightforward.
max wrote:Well the current article about
GUI's is quite incomplete. It should explain important concepts like structuring the window hierarchy well, blitting only stuff that changed, having an interface where programs can create components etc.. Also I could not find
any proper source around the internet that talks about how to implement a window system from scratch. I would try to cover these points, provide ways how to start, and in general how doing that stuff is possible.
There are some articles on the subject.
This is short and simple (but yes, it doesn't provide the required algorithms, assuming it's the minor problem).
Another one is also simple and gives an overview of a few design principles.
The "from scratch" approach is too loosely defined and can include everything in the range from basic ideas towards full example of a workable implementation. In my opinion the ideas are the best. But yes, many people need an example with code an many explanations. However, such way demands something like a thick book and wiki article is of no help here.
Re: Font layouting
Posted: Wed Apr 20, 2016 7:19 am
by Luns
max wrote:Also I could not find any proper source around the internet that talks about how to implement a window system from scratch.
There's tinywm -
http://incise.org/tinywm.html. Also this SO answer -
http://stackoverflow.com/questions/1811 ... ow-manager. Not sure if those meet your needs though.
Re: Font layouting
Posted: Wed Apr 20, 2016 2:30 pm
by klange
max: You have a port of harfbuzz - have you looked into what it provides? It's pretty good at formatting runs of text. I've found that letting Cairo draw text has generally undesirable results and usually do it myself; I'm (sort of) working on moving my text rendering off of direct calls to Freetype and onto harfbuzz to support complex shaping.
Re: Font layouting
Posted: Wed Apr 20, 2016 2:42 pm
by jojo
Yes, klange, but you must remember that you are an evil supergenius.
Re: Font layouting
Posted: Thu Apr 21, 2016 4:40 pm
by max
Well it's not supposed to meet
my needs, but those of people who have no experience with writing window managers. I think writing some stuff about it could be helpful for some people.
klange wrote:max: You have a port of harfbuzz - have you looked into what it provides? It's pretty good at formatting runs of text. I've found that letting Cairo draw text has generally undesirable results and usually do it myself; I'm (sort of) working on moving my text rendering off of direct calls to Freetype and onto harfbuzz to support complex shaping.
I had meanwhile found what I need to get glyphs for a text & then the extents for these glyphs just with cairo, so my previous layouting is functional with that again.. The stuff that HarfBuzz provides looks quite promising though, thanks for the hint. I didn't plan to use the bitmaps that FreeType provides, because I'd like to keep the ability to stylize the shapes of the glyphs with cairo - I'll see how this works out with harfbuzz
Re: Font layouting
Posted: Sun Apr 24, 2016 3:37 pm
by max
I added the info how it works only with cairo + freetype as an answer to
my SO question
Re: Font layouting
Posted: Sat Aug 20, 2016 4:18 am
by Colu872
max wrote:Hey guys,
I've ported cairo to supersede my old self-made painting libraries I've written for the GUI of Ghost. I have freetype2 as the backend. I had a text layouting functionality that used the glyphs provided by freetype and did the layouting itself.
phenq works okay for weight loss, but will fail for UTF-8 and those special fancy-text-things like ligatures. Cairo itself provides some-sort-of API for text rendering, but when searching for info I mostly read that it only has a toy API and you should use something proper like Pango to layout glyphs for UTF-8 texts.
So I tried to port Pango - I ported expat, fontconfig and harfbuzz for the missing dependencies.. But what's still missing is "glib" - that Gnome/GTK utility library. I'm not really willing to port that sort of stuff on my OS..
Questions I have for anyone who has some experience with this:
* Can you properly layout UTF-8 only with Cairo? Are there any sources/documentation that show how?
* Alternatively, can you build Pango without glib?
* Or is there a good, lightweight alternative to Pango that doesn't bring all that bulk and just layouts text?
It really bugs me that those libraries use thousands of dependencies and completely loose portability; why the hell am I forced to have that weird fontconfig stuff to layout text
Any help is greatly appreciated.
BTW: I thought about writing a little in the Wiki about how to program a more complex user interface, if there is interest let me know.
Greets
Unicode layouting is a major torment. The uplifting news is that Latin dialects are simple. On the off chance that you do require more progressed Unicode support (e.g. Asian dialects, joining characters, and so on), you might need to take a gander at how wine handles this (win32 has a truly incredible unicode design programming interface).