Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 50429a1

Browse files
committed
More flexible font setting (mainly for the Mac).
1 parent 0bd2441 commit 50429a1

1 file changed

Lines changed: 47 additions & 4 deletions

File tree

Modules/stdwinmodule.c

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,11 +459,54 @@ drawing_setfont(self, args)
459459
drawingobject *self;
460460
object *args;
461461
{
462-
TEXTATTR saveattr, winattr;
463-
object *str;
464-
if (!getstrarg(args, &str))
462+
object *font, *style;
463+
int size;
464+
if (args == NULL) {
465+
err_badarg();
465466
return NULL;
466-
wsetfont(getstringvalue(str));
467+
}
468+
if (is_stringobject(args)) {
469+
font = args;
470+
style = NULL;
471+
size = 0;
472+
}
473+
else if (is_tupleobject(args)) {
474+
int n = gettuplesize(args);
475+
if (n == 2) {
476+
if (!getstrintarg(args, &font, &size))
477+
return NULL;
478+
style = NULL;
479+
}
480+
else if (!getstrstrintarg(args, &font, &style, &size))
481+
return NULL;
482+
}
483+
else {
484+
err_badarg();
485+
return NULL;
486+
}
487+
if (getstringsize(font) != 0)
488+
wsetfont(getstringvalue(font));
489+
if (style != NULL) {
490+
switch (*getstringvalue(style)) {
491+
case 'b':
492+
wsetbold();
493+
break;
494+
case 'i':
495+
wsetitalic();
496+
break;
497+
case 'o':
498+
wsetbolditalic();
499+
break;
500+
case 'u':
501+
wsetunderline();
502+
break;
503+
default:
504+
wsetplain();
505+
break;
506+
}
507+
}
508+
if (size != 0)
509+
wsetsize(size);
467510
INCREF(None);
468511
return None;
469512
}

0 commit comments

Comments
 (0)