Skip to content

Commit 6976e52

Browse files
author
Yaya-Cout
committed
[python/kandinsky] Allow selecting italic font for draw_string using 7th argument
1 parent 4630052 commit 6976e52

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

python/port/mod/kandinsky/modkandinsky.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,18 @@ mp_obj_t modkandinsky_draw_string(size_t n_args, const mp_obj_t * args) {
6262
KDPoint point(mp_obj_get_int(args[1]), mp_obj_get_int(args[2]));
6363
KDColor textColor = (n_args >= 4) ? MicroPython::Color::Parse(args[3]) : Palette::PrimaryText;
6464
KDColor backgroundColor = (n_args >= 5) ? MicroPython::Color::Parse(args[4]) : Palette::HomeBackground;
65-
const KDFont * font = (n_args >= 6) ? ((mp_obj_is_true(args[5])) ? KDFont::SmallFont : KDFont::LargeFont) : KDFont::LargeFont;
65+
bool bigFont = (n_args >= 6) ? mp_obj_is_true(args[5]) : false;
66+
bool isItalic = (n_args >= 7) ? mp_obj_is_true(args[6]) : false;
67+
const KDFont * font = KDFont::LargeFont;
68+
if (bigFont && !isItalic) {
69+
font = KDFont::LargeFont;
70+
} else if (!bigFont && !isItalic) {
71+
font = KDFont::SmallFont;
72+
} else if (bigFont && isItalic) {
73+
font = KDFont::ItalicLargeFont;
74+
} else if (!bigFont && isItalic) {
75+
font = KDFont::ItalicSmallFont;
76+
}
6677
MicroPython::ExecutionEnvironment::currentExecutionEnvironment()->displaySandbox();
6778
KDIonContext::sharedContext()->drawString(text, point, font, textColor, backgroundColor);
6879
return mp_const_none;

python/port/mod/kandinsky/modkandinsky_table.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modkandinsky_color_obj, 1, 3, modkandinsky_color);
44
STATIC MP_DEFINE_CONST_FUN_OBJ_2(modkandinsky_get_pixel_obj, modkandinsky_get_pixel);
55
STATIC MP_DEFINE_CONST_FUN_OBJ_3(modkandinsky_set_pixel_obj, modkandinsky_set_pixel);
6-
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modkandinsky_draw_string_obj, 3, 6, modkandinsky_draw_string);
6+
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modkandinsky_draw_string_obj, 3, 7, modkandinsky_draw_string);
77
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modkandinsky_draw_line_obj, 5, 5, modkandinsky_draw_line);
88
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modkandinsky_draw_circle_obj, 4, 4, modkandinsky_draw_circle);
99
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modkandinsky_fill_rect_obj, 5, 5, modkandinsky_fill_rect);

0 commit comments

Comments
 (0)