Make modify_font available to C code

This commit is contained in:
Kovid Goyal
2022-07-15 11:06:24 +05:30
parent ee931a17b0
commit 14f4a8d28e
6 changed files with 41 additions and 7 deletions

View File

@@ -390,7 +390,7 @@ def generate_class(defn: Definition, loc: str) -> Tuple[str, str]:
return class_def, '\n'.join(preamble + ['', ''] + tc_lines)
def generate_c_conversion(loc: str, ctypes: List[Option]) -> str:
def generate_c_conversion(loc: str, ctypes: List[Union[Option, MultiOption]]) -> str:
lines: List[str] = []
basic_converters = {
'int': 'PyLong_AsLong', 'uint': 'PyLong_AsUnsignedLong', 'bool': 'PyObject_IsTrue',
@@ -437,7 +437,7 @@ def write_output(loc: str, defn: Definition) -> None:
f.write(f'{tc}\n')
ctypes = []
for opt in defn.root_group.iter_all_non_groups():
if isinstance(opt, Option) and opt.ctype:
if isinstance(opt, (Option, MultiOption)) and opt.ctype:
ctypes.append(opt)
if ctypes:
c = generate_c_conversion(loc, ctypes)

View File

@@ -2,7 +2,7 @@ try:
from typing import TypedDict, NamedTuple
except ImportError:
TypedDict = dict
from enum import Enum, auto
from enum import Enum, IntEnum, auto
class ListedFont(TypedDict):
@@ -32,9 +32,9 @@ class ModificationType(Enum):
size = auto()
class ModificationUnit(Enum):
pt = auto()
percent = auto()
class ModificationUnit(IntEnum):
pt = 0
percent = 1
class ModificationValue(NamedTuple):

View File

@@ -216,7 +216,7 @@ You can do this with e.g.::
'''
)
opt('+modify_font', '',
opt('+modify_font', '', ctype='!modify_font',
option_type='modify_font',
add_to_default=False,
long_text='''

View File

@@ -83,6 +83,19 @@ convert_from_opts_disable_ligatures(PyObject *py_opts, Options *opts) {
Py_DECREF(ret);
}
static void
convert_from_python_modify_font(PyObject *val, Options *opts) {
modify_font(val, opts);
}
static void
convert_from_opts_modify_font(PyObject *py_opts, Options *opts) {
PyObject *ret = PyObject_GetAttrString(py_opts, "modify_font");
if (ret == NULL) return;
convert_from_python_modify_font(ret, opts);
Py_DECREF(ret);
}
static void
convert_from_python_cursor_shape(PyObject *val, Options *opts) {
opts->cursor_shape = PyLong_AsLong(val);
@@ -1046,6 +1059,8 @@ convert_opts_from_python_opts(PyObject *py_opts, Options *opts) {
if (PyErr_Occurred()) return false;
convert_from_opts_disable_ligatures(py_opts, opts);
if (PyErr_Occurred()) return false;
convert_from_opts_modify_font(py_opts, opts);
if (PyErr_Occurred()) return false;
convert_from_opts_cursor_shape(py_opts, opts);
if (PyErr_Occurred()) return false;
convert_from_opts_cursor_beam_thickness(py_opts, opts);

View File

@@ -115,6 +115,22 @@ window_logo_path(PyObject *src, Options *opts) { STR_SETTER(default_window_logo)
#undef STR_SETTER
static void
parse_font_mod_size(PyObject *val, float *sz, bool *is_percent) {
PyObject *mv = PyObject_GetAttrString(val, "mod_value");
if (mv) {
*sz = PyFloat_AsFloat(PyTuple_GET_ITEM(mv, 0));
*is_percent = PyLong_AsLong(PyTuple_GET_ITEM(mv, 1)) == 1;
}
}
static void
modify_font(PyObject *mf, Options *opts) {
#define S(which) { PyObject *v = PyDict_GetItemString(mf, #which); if (v) parse_font_mod_size(v, &opts->which.val, &opts->which.is_percent); }
S(underline_position); S(underline_thickness); S(strikethrough_thickness); S(strikethrough_position);
#undef S
}
static MouseShape
pointer_shape(PyObject *shape_name) {
const char *name = PyUnicode_AsUTF8(shape_name);

View File

@@ -84,6 +84,9 @@ typedef struct {
} tab_bar_margin_height;
long macos_menubar_title_max_length;
int macos_colorspace;
struct {
float val; bool is_percent;
} underline_position, underline_thickness, strikethrough_position, strikethrough_thickness;
} Options;
typedef struct WindowLogoRenderData {