-
-
Notifications
You must be signed in to change notification settings - Fork 219
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
Add ligatures support via libatures
#1671
Draft
Guldoman
wants to merge
6
commits into
lite-xl:master
Choose a base branch
from
Guldoman:PR_integrate_libatures
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Guldoman
force-pushed
the
PR_integrate_libatures
branch
from
December 1, 2023 02:19
ea647aa
to
1e513c5
Compare
|
Should be fixed by diff --git a/src/api/renderer.c b/src/api/renderer.c
index 81df4c4..84883ca 100644
--- a/src/api/renderer.c
+++ b/src/api/renderer.c
@@ -24,6 +24,18 @@ unsigned char default_ligature_features[][4] = {
#define n_default_features (sizeof(default_features) / sizeof(default_features[0]))
#define n_default_ligature_features (sizeof(default_ligature_features) / sizeof(default_ligature_features[0]))
+static size_t get_table_size(lua_State *L, int index) {
+ if (index < 0)
+ index = lua_gettop(L) + index + 1;
+ size_t counter = 0;
+ lua_pushnil(L);
+ while (lua_next(L, index) != 0) {
+ counter++;
+ lua_pop(L, 1); // pop value
+ }
+ return counter;
+}
+
static int font_get_options(
lua_State *L,
ERenFontAntialiasing *antialiasing,
@@ -92,7 +104,7 @@ static int font_get_options(
lua_getfield(L, 3, "ligatures");
if (lua_istable(L, -1)) {
liga_options->n_features = 0;
- size_t n_features = n_default_features + n_default_ligature_features + luaL_len(L, -1);
+ size_t n_features = n_default_features + n_default_ligature_features + get_table_size(L, -1);
liga_options->features = calloc(n_features, sizeof(unsigned char [4]));
// Handle default features
for (size_t i = 0; i < n_default_features; i++) {
@@ -121,7 +133,12 @@ static int font_get_options(
lua_pushnil(L);
while (lua_next(L, -2) != 0) {
size_t taglen;
- const char* tagname = luaL_checklstring(L, -2, &taglen);
+ const char* tagname;
+ if (lua_isinteger(L, -2)) {
+ tagname = luaL_checklstring(L, -1, &taglen);
+ } else {
+ tagname = luaL_checklstring(L, -2, &taglen);
+ }
if (taglen != 4) {
return luaL_error(
L,
@@ -134,7 +151,6 @@ static int font_get_options(
}
lua_pop(L, 1); // pop value
}
- lua_pop(L, 1); // pop key
} else if(lua_toboolean(L, -1)) {
size_t n_features = n_default_features + n_default_ligature_features;
liga_options->features = malloc(n_features * sizeof(unsigned char [4])); This also adds support for specifying features directly, like I'll push this when I can. |
Guldoman
force-pushed
the
PR_integrate_libatures
branch
2 times, most recently
from
February 21, 2024 19:34
11e5e6d
to
6898432
Compare
This allows for ligature options in the format: `ligatures = {dlig = false, "ss01", "ss05"}`
Guldoman
force-pushed
the
PR_integrate_libatures
branch
from
July 5, 2024 03:30
c4da8ad
to
4735923
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Initial glue code to make use of my
libatures
library.This is an alternative to the implementation using
harfbuzz
in #1659.The main advantages of using
libatures
instead ofharfbuzz
are mainly due to the reduced complexity of the library and increased control.This also adds configuration support for ligatures, by providing a new entry in the
options
table ofrenderer.font.load
.By default ligatures are disabled except for the
rvrn
,ccmp
,rlig
and required features.Enabling ligatures by setting the option
ligatures
totrue
will add thecalt
,liga
,clig
anddlig
features.It's possible to fully customize the loaded features by setting
ligatures
to a table which contains the name of the feature as key, and a boolean as value (set tofalse
to disable a "default" feature,true
to enable generic features).For example, setting
ligatures = { ss01 = true, ccmp = false }
will result inss01
to be enabled, as well as all the "default" features, except forccmp
.Closes #66.