-
-
Couldn't load subscription status.
- Fork 644
Better Text Rendering for cairo / lua #1501
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
base: main
Are you sure you want to change the base?
Conversation
Add empty files and various build options for the lua text bindings Adds requirements for Fontconfig, Freetype and Harfbuzz
✅ Deploy Preview for conkyweb canceled.
|
I thought I already removed this and squashed the commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great overall, just need to add documentation to https://github.com/brndnmtthws/conky/blob/main/doc/lua.yaml for the new functions.
|
Thanks for the feedback, i'll update the docs and finish of implementing the Top to Bottom features then finish up a couple of configs to use them before sending through some updates. But its good to know i'm heading in the right direction. |
|
After trying this patches, bug #75 still exist! |
Yes that is currently to be expected, the WIP patch just had the LTR support so I could get feedback on the API, RTL is almost there I just need to finish writing the tests. Also this change only works with the lua API, however it is the first step in my project to add a toolkit to make using the lua API much simpler. Although that is further from completion. |
|
@moceap Can you confirm that the following screenshot looks ok, it should be the days of the week. I'll probably do just a little more testing of my actual real world usecases before sending through an updated pull request |
|
No it's not OK. Letters in Arabic should be connected: You write: الإثنين Look at them here in the browser, they are connected. |
Thanks for the confirmation, that's what I thought i'll have to have a closer look at whats going wrong, the left to right seems to be ok. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never used HarfBuzz, but from what I picked up googling it, the way you're using it seems fine.
|
@simotek Take a look https://github.com/HOST-Oman/libraqm, It may fast the process. |
One thing I noticed at https://github.com/HOST-Oman/libraqm/blob/9d7ca9d59dba38e777bdcd096870776dab5e6e66/src/raqm.c#L1793C1-L1793C48 is that for the RTL case they seem to have hardcoded a -1 into the calculation for character position, So I might have to have a play with that later. It seemed like hardcoding a -1 into the width of each character would solve the issue but I didn't want to just do it without seeing it documented, but the fact this other codebase is suggests its probably the right solution |
Add empty files and various build options for the lua text bindings Adds requirements for Fontconfig, Freetype and Harfbuzz
This should go into its own PR but right now I need it for my system to work.
This replaces the old approach of using a series of function declarations.
For some reason RTL positioning is wrong, it seems somewhat based on font size 1/10th font size seems to get closer to correct so run with that for now, i'll continue investigating a proper fix.
This means its possible to add borders from lua after
This time add libfreetype-dev as well.
The old version worked on openSUSE but not ubuntu's CI, this version also works on openSUSE lets see if it works in the CI
I swapped it and the XFT implementation to using cmake's |
|
I think this is finally getting close and i've finally got it doing everything I need from it. All the text in the below screenshot is using the new conky lua API including the stiff with borders and Gradients etc. The conky memory leak is unrelated and fixed in #2083 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks pretty reasonable to me. A few minor nit picks (mostly formatting related). I'm not really familiar with the implementation details or harfbuzz, so I'll trust your judgement on that.
Not related to this PR, but we should probably separate the helper header declarations from the implementation code (putting the latter into separate files).
This reverts commit c2d2b98.
|
@brndnmtthws sorry this has taken so long, I had to spend a while debugging where some memory leaks were in my testing implementation, i'm now happy that the C++ code is fine and it was a problem in other parts of my lua code. I've re reviewed this and taken on all feedback so hopefully this is in an acceptable state now. |





Description
Introduction
I have attempted to resolve #900 by creating a new lua binding specifically for doing font rendering in Cairo using Freetype and Harfbuzz, fontconfig is also used to locate the correct fonts. I have chosen to follow the approach of the
imlib2_helperbinding and not expose functions from the headers of each of these libraries but rather provide simple functions that "internally" use each of these libraries.At the time of creating this PR I have no fixed thoughts on the API other then it works for my use case and tries to balance the simple act of rendering an English string while also allowing complex options such as RTL text as requested in #75 as well as being able to center and right align text #940 and #1017. So your thoughts on the API topic would be much appreciated, once the API is finalized I will add appropriate documentation. currently this is the last major step for be before being able to move to a lua only config.
Current API Description (Happy to make changes here)
Loading a font from a file is a slow enough operation that we probably don't want to do it multiple times so I separated loading fonts and freeing memory at close into separate functions.
The next set of functions cover the "Simple" English use cases, I could have added a parameter for alignment but I was trying to keep the common Left case as simple as possible.
The next function is the "catch all" with the main implementation and allows tweeking of the internalization options such as text direction in Harfbuzz for people looking to use non latin languages.
Finally when doing layouting sometimes its useful to know how wide the final string will be so the following find the text width, again there is a simple latin version and an internationalized version. In the future I'll also provide a Height function which will be important for supporting vertical text.
Screenshot
In the following screenshot the "Cairo" text is using Cairo's built in basic text rendering, the "Conky" text is using Conky's standard text rendering and the "Freetype" strings are using this new API with Freetype and Harfbuzz rendering the text in Cairo. All these cases are just using the default settings as found on openSUSE Tumbleweed.