Make undercurl_style available to C code

This commit is contained in:
Kovid Goyal
2024-12-11 11:04:22 +05:30
parent 0fb49f4139
commit 9f84c32808
4 changed files with 35 additions and 2 deletions

View File

@@ -208,7 +208,7 @@ lines.
''' '''
) )
opt('undercurl_style', 'thin-sparse', opt('undercurl_style', 'thin-sparse', ctype='undercurl_style',
choices=('thin-sparse', 'thin-dense', 'thick-sparse', 'thick-dense'), choices=('thin-sparse', 'thin-dense', 'thick-sparse', 'thick-dense'),
long_text=''' long_text='''
The style with which undercurls are rendered. This option takes the form The style with which undercurls are rendered. This option takes the form

View File

@@ -70,6 +70,19 @@ convert_from_opts_modify_font(PyObject *py_opts, Options *opts) {
Py_DECREF(ret); Py_DECREF(ret);
} }
static void
convert_from_python_undercurl_style(PyObject *val, Options *opts) {
opts->undercurl_style = undercurl_style(val);
}
static void
convert_from_opts_undercurl_style(PyObject *py_opts, Options *opts) {
PyObject *ret = PyObject_GetAttrString(py_opts, "undercurl_style");
if (ret == NULL) return;
convert_from_python_undercurl_style(ret, opts);
Py_DECREF(ret);
}
static void static void
convert_from_python_text_composition_strategy(PyObject *val, Options *opts) { convert_from_python_text_composition_strategy(PyObject *val, Options *opts) {
text_composition_strategy(val, opts); text_composition_strategy(val, opts);
@@ -1148,6 +1161,8 @@ convert_opts_from_python_opts(PyObject *py_opts, Options *opts) {
if (PyErr_Occurred()) return false; if (PyErr_Occurred()) return false;
convert_from_opts_modify_font(py_opts, opts); convert_from_opts_modify_font(py_opts, opts);
if (PyErr_Occurred()) return false; if (PyErr_Occurred()) return false;
convert_from_opts_undercurl_style(py_opts, opts);
if (PyErr_Occurred()) return false;
convert_from_opts_text_composition_strategy(py_opts, opts); convert_from_opts_text_composition_strategy(py_opts, opts);
if (PyErr_Occurred()) return false; if (PyErr_Occurred()) return false;
convert_from_opts_cursor_shape(py_opts, opts); convert_from_opts_cursor_shape(py_opts, opts);

View File

@@ -58,6 +58,23 @@ window_title_in(PyObject *title_in) {
return ALL; return ALL;
} }
static inline unsigned
undercurl_style(PyObject *x) {
RAII_PyObject(thick, PyUnicode_FromString("thick"));
RAII_PyObject(dense, PyUnicode_FromString("dense"));
unsigned ans = 0;
int ret;
switch ((ret = PyUnicode_Find(x, dense, 0, PyUnicode_GET_LENGTH(x), 1))) {
case -2: PyErr_Clear(); case -1: break;
default: ans |= 1;
}
switch ((ret = PyUnicode_Find(x, thick, 0, PyUnicode_GET_LENGTH(x), 1))) {
case -2: PyErr_Clear(); case -1: break;
default: ans |= 2;
}
return ans;
}
static inline UnderlineHyperlinks static inline UnderlineHyperlinks
underline_hyperlinks(PyObject *x) { underline_hyperlinks(PyObject *x) {
const char *in = PyUnicode_AsUTF8(x); const char *in = PyUnicode_AsUTF8(x);
@@ -440,7 +457,7 @@ tab_bar_margin_height(PyObject *val, Options *opts) {
opts->tab_bar_margin_height.inner = PyFloat_AsDouble(PyTuple_GET_ITEM(val, 1)); opts->tab_bar_margin_height.inner = PyFloat_AsDouble(PyTuple_GET_ITEM(val, 1));
} }
static void static inline void
window_logo_scale(PyObject *src, Options *opts) { window_logo_scale(PyObject *src, Options *opts) {
opts->window_logo_scale.width = PyFloat_AsFloat(PyTuple_GET_ITEM(src, 0)); opts->window_logo_scale.width = PyFloat_AsFloat(PyTuple_GET_ITEM(src, 0));
opts->window_logo_scale.height = PyFloat_AsFloat(PyTuple_GET_ITEM(src, 1)); opts->window_logo_scale.height = PyFloat_AsFloat(PyTuple_GET_ITEM(src, 1));

View File

@@ -123,6 +123,7 @@ typedef struct {
} *entries; } *entries;
} font_features; } font_features;
struct { Animation *cursor, *visual_bell; } animation; struct { Animation *cursor, *visual_bell; } animation;
unsigned undercurl_style;
} Options; } Options;
typedef struct WindowLogoRenderData { typedef struct WindowLogoRenderData {