Skip to content
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

RFC: Better Text Rendering for cairo / lua #1501

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2a0db1d
lua text: Supporting infra
simotek Jan 14, 2023
79b81a6
lua text: initial implementation.
simotek Feb 14, 2023
24706e8
Add the ability to center and right align text.
simotek Apr 11, 2023
d5d20e8
lua text: Remove test code
simotek Apr 12, 2023
b625e93
lua text: Supporting infra
simotek Jan 14, 2023
4077ad5
lua text: initial implementation.
simotek Feb 14, 2023
00b2ec0
Commit the WIP so I can merge it
simotek Feb 12, 2024
5036cc4
Fix for #1698
simotek Feb 14, 2024
488b450
Fix comment hb-unicode.h should be hb-common.h
simotek Feb 14, 2024
b0063e5
Swap to using optional parameters
simotek Feb 14, 2024
945ce1f
Add Hack for RTL positioning
simotek Feb 15, 2024
dc7c0e0
Remove Top to Bottom Fixme's they are fixed
simotek Feb 15, 2024
ca1be94
Merge branch 'lua-text-helper2' into lua-text-helper3
simotek Feb 15, 2024
47c45af
Some general cleanup post merge
simotek Feb 15, 2024
7553faf
Attempt to fix workflows by adding freetype dep
simotek Feb 15, 2024
2c74058
Probably actually need freetype6
simotek Feb 15, 2024
7e2a662
Try again, I don't understand Ubuntu
simotek Feb 15, 2024
ac50fa7
Try something from google
simotek Feb 15, 2024
ba71b73
lua-text: Move to caching fonts in C
simotek Feb 21, 2024
8f34c9d
Revert "Fix for #1698"
simotek Feb 22, 2024
9ba643c
docs: tolua++ now works with more then lua5.1
simotek Feb 22, 2024
f4f7462
lua-text: Add docs.
simotek Feb 22, 2024
e5482ca
lua-text: Fix build with
simotek Mar 5, 2024
f9676c6
Merge branch 'main' into lua-text-helper3
simotek Oct 17, 2024
78b222f
lua-text use cairo_fill_preserve
simotek Oct 29, 2024
9fc5fa9
Doc: Implement feedback from #1501 for tables
simotek Nov 18, 2024
755c700
Merge branch 'main' into lua-text-helper3
simotek Nov 18, 2024
872d87b
lua-text: Another shot at fixing workflows
simotek Nov 18, 2024
b1bd605
cmake: try and use find_package for freetype
simotek Nov 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/build-and-test-linux.yaml
simotek marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ jobs:
libcurl4-gnutls-dev \
libcurl4-gnutls-dev \
libdbus-glib-1-dev \
libfreetype6-dev \
libstdc++6 \
libglib2.0-dev \
libical-dev \
libimlib2-dev \
Expand Down Expand Up @@ -137,6 +139,7 @@ jobs:
-DBUILD_LUA_CAIRO=ON \
-DBUILD_LUA_IMLIB2=ON \
-DBUILD_LUA_RSVG=${RSVG_ENABLED} \
-DBUILD_LUA_TEXT=ON \
-DBUILD_MYSQL=ON \
-DBUILD_NVIDIA=ON \
-DBUILD_PULSEAUDIO=ON \
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ jobs:
libcurl4-gnutls-dev \
libcurl4-gnutls-dev \
libdbus-glib-1-dev \
libfreetype6-dev \
libstdc++6 \
libglib2.0-dev \
libical-dev \
libimlib2-dev \
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/publish-appimage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ jobs:
libcairo2-dev \
libcurl4-gnutls-dev \
libdbus-glib-1-dev \
libfreetype6-dev \
libstdc++6 \
libfuse2 \
libglib2.0-dev \
libical-dev \
Expand Down
3 changes: 3 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@ Mikko Sysikaski <sisu at users dot sourceforge dot net>
Sceptik <sceptik at users dot sourceforge dot net>
--quiet patch

Simon Lees <sflees at suse dot de>
lua text

Stepan Zastupov <redchrom at gmail dot com>
WiFi signal level detection support on FreeBSD

Expand Down
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ RUN apt-get update \
libcairo2-dev \
libcurl4-openssl-dev \
libdbus-glib-1-dev \
libfontconfig-dev \
libfreetype-dev \
libharfbuzz-dev \
libical-dev \
libimlib2-dev \
libircclient-dev \
Expand Down Expand Up @@ -76,6 +79,7 @@ RUN sh -c 'if [ "$X11" = "yes" ] ; then \
-DBUILD_LUA_CAIRO=ON \
-DBUILD_LUA_IMLIB2=ON \
-DBUILD_LUA_RSVG=ON \
-DBUILD_LUA_TEXT=ON \
-DBUILD_MYSQL=ON \
-DBUILD_NVIDIA=ON \
-DBUILD_PULSEAUDIO=ON \
Expand All @@ -98,6 +102,7 @@ RUN sh -c 'if [ "$X11" = "yes" ] ; then \
-DBUILD_LUA_CAIRO=ON \
-DBUILD_LUA_IMLIB2=ON \
-DBUILD_LUA_RSVG=ON \
-DBUILD_LUA_TEXT=ON \
-DBUILD_MYSQL=ON \
-DBUILD_PULSEAUDIO=ON \
-DBUILD_RSS=ON \
Expand All @@ -121,6 +126,9 @@ RUN apt-get update \
libcairo2 \
libcurl4 \
libdbus-glib-1-2 \
libfontconfig1 \
libfreetype6 \
libharfbuzz-gobject0 \
libical3 \
libimlib2 \
libircclient1 \
Expand Down
1 change: 1 addition & 0 deletions appimage/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ cmake -G Ninja \
-DBUILD_LUA_CAIRO=ON \
-DBUILD_LUA_IMLIB2=ON \
-DBUILD_LUA_RSVG=ON \
-DBUILD_LUA_TEXT=ON \
-DBUILD_MYSQL=ON \
-DBUILD_NVIDIA=ON \
-DBUILD_PULSEAUDIO=ON \
Expand Down
1 change: 1 addition & 0 deletions cmake/ConkyBuildOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ dependent_option(BUILD_LUA_IMLIB2 "Build Imlib2 bindings for Lua" false
"BUILD_X11;BUILD_IMLIB2" false
"Imlib2 Lua bindings require X11 and Imlib2")
option(BUILD_LUA_RSVG "Build rsvg bindings for Lua" false)
option(BUILD_LUA_TEXT "Build Fontconfig Freetype and Harfbuzz bindings for Lua" false)

option(BUILD_AUDACIOUS "Build audacious (music player) support" false)

Expand Down
12 changes: 12 additions & 0 deletions cmake/ConkyPlatformChecks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,18 @@ if(BUILD_GUI)
set(luarsvg_libs ${RSVG_LIBRARIES} ${LUA_LIBRARIES})
set(luarsvg_includes ${RSVG_INCLUDE_DIRS} ${LUA_INCLUDE_DIR})
endif(BUILD_LUA_RSVG)

if(BUILD_LUA_TEXT)
if(FREETYPE_INCLUDE_DIR_freetype2)
set(FREETYPE_FOUND true)
else(FREETYPE_INCLUDE_DIR_freetype2)
message(FATAL_ERROR "Unable to find freetype library")
endif(FREETYPE_INCLUDE_DIR_freetype2)
PKG_CHECK_MODULES(FONTCONFIG REQUIRED fontconfig)
PKG_CHECK_MODULES(HARFBUZZ REQUIRED harfbuzz)
set(luatext_libs ${FREETYPE_LIBRARIES} ${FONTCONFIG_LIBRARIES} ${HARFBUZZ_LIBRARIES} ${LUA_LIBRARIES})
set(luatext_includes ${FREETYPE_INCLUDE_DIR_freetype2} ${FONTCONFIG_INCLUDE_DIRS} ${HARFBUZZ_INCLUDE_DIRS} ${LUA_INCLUDE_DIRS})
endif(BUILD_LUA_TEXT)
endif(BUILD_GUI)

if(BUILD_AUDACIOUS)
Expand Down
2 changes: 2 additions & 0 deletions cmake/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@

#cmakedefine BUILD_LUA_RSVG 1

#cmakedefine BUILD_LUA_TEXT 1

#cmakedefine BUILD_IBM 1

#cmakedefine BUILD_RSS 1
Expand Down
44 changes: 42 additions & 2 deletions doc/lua.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
---
desc: |-
Conky features a Lua Programming API, and also ships with Lua bindings
for some useful libraries. Note that the bindings require tolua++, which
currently only compiles against Lua 5.1.
for some useful libraries. Note that the bindings require tolua++.

To use Lua Conky, you first need to make sure you have a version of
Conky with Lua support enabled (`conky -v` will report this).
Expand Down Expand Up @@ -185,3 +184,44 @@ values:
- name: RsvgDimensionData:get()
desc: |-
Gets the values of an existing RsvgDimensionData.
- name: cairo_text_hp_show(cr, x, y, text, font, font_size, alignment, language, script, direction)
desc: |-
Renders text to a cairo_t using harfbuzz and freetype, this provides significantly
better text rendering then using cairo's inbuilt functions.

| Argument | Description |
|---------------------|--------------------------------------------------------------------------------------|
| cr | The `cairo_t` to render to. |
| x,y | Position to render the text. |
| text | The text to render. |
| font | The name of the font to be used, `Fontconfig` is used to search for the font. |
| font_size | The font size. |
| alignment | One of `CAIRO_TEXT_ALIGN_LEFT`, `CAIRO_TEXT_ALIGN_RIGHT`, `CAIRO_TEXT_ALIGN_CENTER`. |
| | Default value: `CAIRO_TEXT_ALIGN_LEFT` |
| language | A string containing a BCP 47 language tag. |
| | Default value: `en` |
| script | A string containing a ISO 15924 script tag. |
| | Default value: auto-detect from text |
| direction | A string representing text direction eg `LTR`, `RTL` or `TTB` |
| | Default value: auto-detect from text otherwise `LTR` | |
simotek marked this conversation as resolved.
Show resolved Hide resolved
- name: width,height:cairo_text_hp_text_size(text, font, font_size, language, script, direction)
desc: |-
Used to calculate how many pixels will be required to render a string with
`cairo_text_hp_show` returns a pair of int's with `width` and `height`.

| Argument | Description |
|---------------------|--------------------------------------------------------------------------------------|
| cr | The `cairo_t` to render to. |
| text | The text to render. |
| font | The name of the font to be used, `Fontconfig` is used to search for the font. |
| font_size | The font size. |
| language | A string containing a BCP 47 language tag. |
| | Default value: `en` |
| script | A string containing a ISO 15924 script tag. |
| | Default value: auto-detect from text |
| direction | A string representing text direction eg `LTR`, `RTL` or `TTB` |
| | Default value: auto-detect from text otherwise `LTR` |
simotek marked this conversation as resolved.
Show resolved Hide resolved
- name: cairo_text_hp_delete_fonts()
desc: |-
`cairo_text_hp_show` and `cairo_text_hp_text_size` both cache internal font details,
this function clears those caches.
17 changes: 17 additions & 0 deletions lua/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ if(BUILD_X11)
print_target_properties(conky-rsvg)
endif(BUILD_LUA_RSVG)


if(BUILD_LUA_CAIRO AND BUILD_LUA_IMLIB2)
include_directories(${luacairo_includes} ${luaimlib2_includes}
${CMAKE_CURRENT_SOURCE_DIR})
Expand All @@ -90,6 +91,22 @@ if(BUILD_X11)
toluapp_lib_static)
set(lua_libs ${lua_libs} conky-cairo_imlib2_helper)
endif(BUILD_LUA_CAIRO AND BUILD_LUA_IMLIB2)

if(BUILD_LUA_CAIRO AND BUILD_LUA_TEXT)
include_directories(${luacairo_includes} ${luatext_includes}
${CMAKE_CURRENT_SOURCE_DIR})
wrap_tolua(luacairo_text_helper_src cairo_text_helper.pkg)

add_library(conky-cairo_text_helper SHARED ${luacairo_text_helper_src})
set_target_properties(conky-cairo_text_helper
PROPERTIES OUTPUT_NAME "cairo_text_helper")

target_link_libraries(conky-cairo_text_helper
${luacairo_libs}
${luatext_libs}
toluapp_lib_static)
set(lua_libs ${lua_libs} conky-cairo_text_helper)
endif(BUILD_LUA_CAIRO AND BUILD_LUA_TEXT)
endif(BUILD_X11)

install(TARGETS ${lua_libs}
Expand Down
19 changes: 19 additions & 0 deletions lua/cairo_text_helper.pkg
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
$#include <cairo.h>
$#include <libcairo_text_helper.h>

typedef enum _cairo_text_alignment {
CAIRO_TEXT_ALIGN_LEFT = 0,
CAIRO_TEXT_ALIGN_RIGHT,
CAIRO_TEXT_ALIGN_CENTER
} cairo_text_alignment_t;

void cairo_text_hp_show(cairo_t *cr, int x, int y, const char *text, const char *font, int font_size,
cairo_text_alignment_t alignment = CAIRO_TEXT_ALIGN_LEFT, const char *language = "en",
const char *script = NULL, const char *direction = NULL);

/* This function allows you to get sizing so you can layout multiple sets of text next to each other */
void cairo_text_hp_text_size(const char *text, const char *font, int font_size,
const char *language = "en", const char *script = NULL, const char *direction, int *width, int *height);

/* This will clear all currently loaded / cached fonts */
void cairo_text_hp_delete_fonts();
Loading