start work on porting box drawing to C

This commit is contained in:
Kovid Goyal
2024-12-20 08:09:06 +05:30
parent ec3a6cc26e
commit fdb9b17943
9 changed files with 614 additions and 61 deletions

View File

@@ -199,7 +199,7 @@ might cause rendering artifacts, so use with care.
''')
opt('box_drawing_scale', '0.001, 1, 1.5, 2',
option_type='box_drawing_scale',
option_type='box_drawing_scale', ctype='!box_drawing_scale',
long_text='''
The sizes of the lines used for the box drawing Unicode characters. These values
are in pts. They will be scaled by the monitor DPI to arrive at a pixel value.

View File

@@ -70,6 +70,19 @@ convert_from_opts_modify_font(PyObject *py_opts, Options *opts) {
Py_DECREF(ret);
}
static void
convert_from_python_box_drawing_scale(PyObject *val, Options *opts) {
box_drawing_scale(val, opts);
}
static void
convert_from_opts_box_drawing_scale(PyObject *py_opts, Options *opts) {
PyObject *ret = PyObject_GetAttrString(py_opts, "box_drawing_scale");
if (ret == NULL) return;
convert_from_python_box_drawing_scale(ret, opts);
Py_DECREF(ret);
}
static void
convert_from_python_undercurl_style(PyObject *val, Options *opts) {
opts->undercurl_style = undercurl_style(val);
@@ -1174,6 +1187,8 @@ convert_opts_from_python_opts(PyObject *py_opts, Options *opts) {
if (PyErr_Occurred()) return false;
convert_from_opts_modify_font(py_opts, opts);
if (PyErr_Occurred()) return false;
convert_from_opts_box_drawing_scale(py_opts, opts);
if (PyErr_Occurred()) return false;
convert_from_opts_undercurl_style(py_opts, opts);
if (PyErr_Occurred()) return false;
convert_from_opts_underline_exclusion(py_opts, opts);

View File

@@ -390,6 +390,13 @@ underline_exclusion(PyObject *val, Options *opts) {
else opts->underline_exclusion.unit = 0;
}
static inline void
box_drawing_scale(PyObject *val, Options *opts) {
for (unsigned i = 0; i < MIN(arraysz(opts->box_drawing_scale), (size_t)PyTuple_GET_SIZE(val)); i++) {
opts->box_drawing_scale[i] = PyFloat_AsFloat(PyTuple_GET_ITEM(val, i));
}
}
static inline void
text_composition_strategy(PyObject *val, Options *opts) {
if (!PyUnicode_Check(val)) { PyErr_SetString(PyExc_TypeError, "text_rendering_strategy must be a string"); return; }