Font layouting

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
max
Member
Member
Posts: 616
Joined: Mon Mar 05, 2012 11:23 am
Libera.chat IRC: maxdev
Location: Germany
Contact:

Font layouting

Post 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 #-o
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
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Font layouting

Post 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.
If a trainstation is where trains stop, what is a workstation ?
User avatar
max
Member
Member
Posts: 616
Joined: Mon Mar 05, 2012 11:23 am
Libera.chat IRC: maxdev
Location: Germany
Contact:

Re: Font layouting

Post 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
JoeEagar
Posts: 6
Joined: Tue Mar 15, 2016 8:46 am
Libera.chat IRC: joeedh

Re: Font layouting

Post 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
User avatar
max
Member
Member
Posts: 616
Joined: Mon Mar 05, 2012 11:23 am
Libera.chat IRC: maxdev
Location: Germany
Contact:

Re: Font layouting

Post 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.
embryo2
Member
Member
Posts: 397
Joined: Wed Jun 03, 2015 5:03 am

Re: Font layouting

Post 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.
My previous account (embryo) was accidentally deleted, so I have no chance but to use something new. But may be it was a good lesson about software reliability :)
User avatar
max
Member
Member
Posts: 616
Joined: Mon Mar 05, 2012 11:23 am
Libera.chat IRC: maxdev
Location: Germany
Contact:

Re: Font layouting

Post 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.
embryo2
Member
Member
Posts: 397
Joined: Wed Jun 03, 2015 5:03 am

Re: Font layouting

Post 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.
My previous account (embryo) was accidentally deleted, so I have no chance but to use something new. But may be it was a good lesson about software reliability :)
Luns
Member
Member
Posts: 56
Joined: Sun May 01, 2011 12:15 am

Re: Font layouting

Post 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.
klange
Member
Member
Posts: 679
Joined: Wed Mar 30, 2011 12:31 am
Libera.chat IRC: klange
Discord: klange

Re: Font layouting

Post 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.

Image
User avatar
jojo
Member
Member
Posts: 138
Joined: Mon Apr 18, 2016 9:50 am
Libera.chat IRC: jojo
Location: New York New York

Re: Font layouting

Post by jojo »

Yes, klange, but you must remember that you are an evil supergenius.
User avatar
max
Member
Member
Posts: 616
Joined: Mon Mar 05, 2012 11:23 am
Libera.chat IRC: maxdev
Location: Germany
Contact:

Re: Font layouting

Post by max »

Luns wrote: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.
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 :)
User avatar
max
Member
Member
Posts: 616
Joined: Mon Mar 05, 2012 11:23 am
Libera.chat IRC: maxdev
Location: Germany
Contact:

Re: Font layouting

Post by max »

I added the info how it works only with cairo + freetype as an answer to my SO question :)
Colu872
Posts: 1
Joined: Sat Aug 20, 2016 4:15 am

Re: Font layouting

Post 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 #-o
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).
Post Reply