Skip to content

Commit 871e442

Browse files
committed
Get orientation from RGBA setting
1 parent 5eb2d0a commit 871e442

File tree

5 files changed

+34
-41
lines changed

5 files changed

+34
-41
lines changed

kitty/config_data.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,12 @@ def box_drawing_scale(x):
295295
and very thick lines.
296296
'''))
297297

298+
o('subpixel_rendering', False, long_text=_('''
299+
Use subpixel rendering instead of grayscale in freetype. Impacts performance,
300+
but may look better on low DPI screens. Possible values are :code:`none`,
301+
:code:`lcd`, and :code:`lcd_v`.
302+
'''))
303+
298304
# }}}
299305

300306
g('cursor') # {{{
@@ -955,21 +961,6 @@ def macos_option_as_alt(x):
955961
light and dark backgrounds. WARNING: this might make your mouse cursor
956962
invisible on dual GPU machines.'''))
957963

958-
959-
def to_subpixel_options(x):
960-
x = x.lower()
961-
if x == 'lcd':
962-
return 1
963-
if x == 'lcd_v':
964-
return 2
965-
return 0
966-
967-
968-
o('subpixel_rendering', 'none', option_type=to_subpixel_options, long_text=_('''
969-
Use subpixel rendering instead of grayscale in freetype. Impacts performance,
970-
but may look better on low DPI screens. Possible values are :code:`none`,
971-
:code:`lcd`, and :code:`lcd_v`.
972-
'''))
973964
# }}}
974965

975966
g('shortcuts') # {{{

kitty/freetype.c

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -388,16 +388,17 @@ populate_processed_bitmap(FT_GlyphSlotRec *slot, FT_Bitmap *bitmap, ProcessedBit
388388
static inline bool
389389
render_bitmap(Face *self, int glyph_id, ProcessedBitmap *ans, unsigned int cell_width, unsigned int cell_height, unsigned int num_cells, bool bold, bool italic, bool rescale, FONTS_DATA_HANDLE fg) {
390390
int flags = FT_LOAD_RENDER;
391-
switch (OPT(subpixel_rendering)) {
392-
case SUBPIXEL_LCD:
393-
flags |= FT_LOAD_TARGET_LCD;
394-
break;
395-
case SUBPIXEL_LCD_V:
396-
flags |= FT_LOAD_TARGET_LCD_V;
397-
break;
398-
case SUBPIXEL_NONE:
399-
default:
400-
break;
391+
if (OPT(subpixel_rendering)) {
392+
switch (self->rgba) {
393+
case FC_RGBA_RGB:
394+
case FC_RGBA_BGR:
395+
flags |= FT_LOAD_TARGET_LCD;
396+
break;
397+
case FC_RGBA_VRGB:
398+
case FC_RGBA_VBGR:
399+
flags |= FT_LOAD_TARGET_LCD_V;
400+
break;
401+
}
401402
}
402403
if (!load_glyph(self, glyph_id, flags)) return false;
403404
unsigned int max_width = cell_width * num_cells;
@@ -670,17 +671,21 @@ render_simple_text_impl(PyObject *s, const char *text, unsigned int baseline) {
670671
int error = FT_Load_Glyph(self->face, glyph_index, FT_LOAD_DEFAULT);
671672
if (error) continue;
672673
int flags = 0;
673-
switch (OPT(subpixel_rendering)) {
674-
case SUBPIXEL_LCD:
675-
flags |= FT_RENDER_MODE_LCD;
676-
break;
677-
case SUBPIXEL_LCD_V:
678-
flags |= FT_RENDER_MODE_LCD_V;
679-
break;
680-
case SUBPIXEL_NONE:
681-
default:
674+
if (OPT(subpixel_rendering)) {
675+
switch (self->rgba) {
676+
case FC_RGBA_RGB:
677+
case FC_RGBA_BGR:
678+
flags |= FT_RENDER_MODE_LCD;
679+
break;
680+
case FC_RGBA_VRGB:
681+
case FC_RGBA_VBGR:
682+
flags |= FT_RENDER_MODE_LCD_V;
683+
break;
684+
default:
685+
flags |= FT_RENDER_MODE_LCD;
686+
}
687+
} else {
682688
flags |= FT_RENDER_MODE_NORMAL;
683-
break;
684689
}
685690
error = FT_Render_Glyph(self->face->glyph, flags);
686691
if (error) continue;

kitty/glfw.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,6 @@ create_os_window(PyObject UNUSED *self, PyObject *args) {
514514
// blank the window once so that there is no initial flash of color
515515
// changing, in case the background color is not black
516516
blank_canvas(is_semi_transparent ? OPT(background_opacity) : 1.0f);
517-
bool is_subpixel_enabled = (OPT(subpixel_rendering) == SUBPIXEL_LCD || OPT(subpixel_rendering) == SUBPIXEL_LCD_V);
518517
#ifndef __APPLE__
519518
if (is_first_window) glfwSwapInterval(OPT(sync_to_monitor) && !global_state.is_wayland ? 1 : 0);
520519
#endif
@@ -527,7 +526,7 @@ create_os_window(PyObject UNUSED *self, PyObject *args) {
527526
glfwShowWindow(glfw_window);
528527
}
529528
if (is_first_window) {
530-
PyObject *ret = PyObject_CallFunction(load_programs, "OO", is_semi_transparent ? Py_True : Py_False, is_subpixel_enabled ? Py_True : Py_False);
529+
PyObject *ret = PyObject_CallFunction(load_programs, "OO", is_semi_transparent ? Py_True : Py_False, OPT(subpixel_rendering) ? Py_True : Py_False);
531530
if (ret == NULL) return NULL;
532531
Py_DECREF(ret);
533532
#ifdef __APPLE__

kitty/state.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ PYWRAP1(set_options) {
408408
S(macos_window_resizable, PyObject_IsTrue);
409409
S(macos_hide_from_tasks, PyObject_IsTrue);
410410
S(macos_thicken_font, PyFloat_AsDouble);
411-
S(subpixel_rendering, PyLong_AsLong);
411+
S(subpixel_rendering, PyObject_IsTrue);
412412
S(tab_bar_min_tabs, PyLong_AsUnsignedLong);
413413
S(disable_ligatures, PyLong_AsLong);
414414
S(resize_draw_strategy, PyLong_AsLong);

kitty/state.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
typedef enum { LEFT_EDGE, TOP_EDGE, RIGHT_EDGE, BOTTOM_EDGE } Edge;
1414
typedef enum { RESIZE_DRAW_STATIC, RESIZE_DRAW_SCALED, RESIZE_DRAW_BLANK, RESIZE_DRAW_SIZE } ResizeDrawStrategy;
1515

16-
typedef enum { SUBPIXEL_NONE, SUBPIXEL_LCD, SUBPIXEL_LCD_V } SubpixelRendering;
17-
1816
typedef struct {
1917
double visual_bell_duration, cursor_blink_interval, cursor_stop_blinking_after, mouse_hide_wait, click_interval, wheel_scroll_multiplier, touch_scroll_multiplier;
2018
bool enable_audio_bell;
@@ -28,7 +26,7 @@ typedef struct {
2826
double repaint_delay, input_delay;
2927
bool focus_follows_mouse, hide_window_decorations;
3028
bool macos_hide_from_tasks, macos_quit_when_last_window_closed, macos_window_resizable, macos_traditional_fullscreen, macos_show_window_title_in_menubar;
31-
SubpixelRendering subpixel_rendering;
29+
bool subpixel_rendering;
3230
unsigned int macos_option_as_alt;
3331
float macos_thicken_font;
3432
int adjust_line_height_px, adjust_column_width_px;

0 commit comments

Comments
 (0)