Actually implement modify_font

This commit is contained in:
Kovid Goyal 2022-07-15 12:27:42 +05:30
parent 1aa50b73a1
commit 03df0c3cca
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 22 additions and 6 deletions

View File

@ -331,6 +331,20 @@ python_send_to_gpu(FONTS_DATA_HANDLE fg, unsigned int x, unsigned int y, unsigne
} }
} }
static void
adjust_metric(unsigned int *metric, float adj, AdjustmentUnit unit, double dpi) {
if (adj == 0.f) return;
int a = 0;
switch (unit) {
case POINT:
a = ((long)round((adj * (dpi / 72.0)))); break;
case PERCENT:
*metric = (int)roundf((fabsf(adj) * (float)*metric) / 100.f); return;
case PIXEL:
a = (int)roundf(adj); break;
}
*metric = (a < 0 && -a > (int)*metric) ? 0 : *metric + a;
}
static void static void
calc_cell_metrics(FontGroup *fg) { calc_cell_metrics(FontGroup *fg) {
@ -358,6 +372,11 @@ calc_cell_metrics(FontGroup *fg) {
#undef MIN_WIDTH #undef MIN_WIDTH
#undef MIN_HEIGHT #undef MIN_HEIGHT
#undef MAX_DIM #undef MAX_DIM
#define A(which, dpi) adjust_metric(&which, OPT(which).val, OPT(which).unit, fg->logical_dpi_##dpi);
A(underline_thickness, y); A(underline_position, y); A(strikethrough_thickness, y); A(strikethrough_position, y);
#undef A
underline_position = MIN(cell_height - 1, underline_position); underline_position = MIN(cell_height - 1, underline_position);
// ensure there is at least a couple of pixels available to render styled underlines // ensure there is at least a couple of pixels available to render styled underlines
while (underline_position > baseline + 1 && cell_height - underline_position < 2) underline_position--; while (underline_position > baseline + 1 && cell_height - underline_position < 2) underline_position--;

View File

@ -120,11 +120,8 @@ parse_font_mod_size(PyObject *val, float *sz, AdjustmentUnit *unit) {
PyObject *mv = PyObject_GetAttrString(val, "mod_value"); PyObject *mv = PyObject_GetAttrString(val, "mod_value");
if (mv) { if (mv) {
*sz = PyFloat_AsFloat(PyTuple_GET_ITEM(mv, 0)); *sz = PyFloat_AsFloat(PyTuple_GET_ITEM(mv, 0));
switch (PyLong_AsLong(PyTuple_GET_ITEM(mv, 1))) { long u = PyLong_AsLong(PyTuple_GET_ITEM(mv, 1));
case 0: *unit = POINT; break; switch (u) { case POINT: case PERCENT: case PIXEL: *unit = u; break; }
case 1: *unit = PIXEL; break;
case 2: *unit = PERCENT; break;
}
} }
} }

View File

@ -21,7 +21,7 @@ typedef struct {
size_t len; size_t len;
} UrlPrefix; } UrlPrefix;
typedef enum AdjustmentUnit { POINT, PERCENT, PIXEL } AdjustmentUnit; typedef enum AdjustmentUnit { POINT = 0, PERCENT = 1, PIXEL = 2 } AdjustmentUnit;
typedef struct { typedef struct {
monotonic_t visual_bell_duration, cursor_blink_interval, cursor_stop_blinking_after, mouse_hide_wait, click_interval; monotonic_t visual_bell_duration, cursor_blink_interval, cursor_stop_blinking_after, mouse_hide_wait, click_interval;