Skip to content

Commit cb68244

Browse files
committed
use mode enums in _imagingft.c
1 parent 268b090 commit cb68244

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

src/_imagingft.c

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ font_getlength(FontObject *self, PyObject *args) {
529529
int horizontal_dir; /* is primary axis horizontal? */
530530
int mask = 0; /* is FT_LOAD_TARGET_MONO enabled? */
531531
int color = 0; /* is FT_LOAD_COLOR enabled? */
532-
const char *mode = NULL;
532+
const char *mode_name = NULL;
533533
const char *dir = NULL;
534534
const char *lang = NULL;
535535
PyObject *features = Py_None;
@@ -538,15 +538,16 @@ font_getlength(FontObject *self, PyObject *args) {
538538
/* calculate size and bearing for a given string */
539539

540540
if (!PyArg_ParseTuple(
541-
args, "O|zzOz:getlength", &string, &mode, &dir, &features, &lang
541+
args, "O|zzOz:getlength", &string, &mode_name, &dir, &features, &lang
542542
)) {
543543
return NULL;
544544
}
545545

546546
horizontal_dir = dir && strcmp(dir, "ttb") == 0 ? 0 : 1;
547547

548-
mask = mode && strcmp(mode, "1") == 0;
549-
color = mode && strcmp(mode, "RGBA") == 0;
548+
const ModeID mode = findModeID(mode_name);
549+
mask = mode == IMAGING_MODE_1;
550+
color = mode == IMAGING_MODE_RGBA;
550551

551552
count = text_layout(string, self, dir, features, lang, &glyph_info, mask, color);
552553
if (PyErr_Occurred()) {
@@ -758,7 +759,7 @@ font_getsize(FontObject *self, PyObject *args) {
758759
int horizontal_dir; /* is primary axis horizontal? */
759760
int mask = 0; /* is FT_LOAD_TARGET_MONO enabled? */
760761
int color = 0; /* is FT_LOAD_COLOR enabled? */
761-
const char *mode = NULL;
762+
const char *mode_name = NULL;
762763
const char *dir = NULL;
763764
const char *lang = NULL;
764765
const char *anchor = NULL;
@@ -768,15 +769,23 @@ font_getsize(FontObject *self, PyObject *args) {
768769
/* calculate size and bearing for a given string */
769770

770771
if (!PyArg_ParseTuple(
771-
args, "O|zzOzz:getsize", &string, &mode, &dir, &features, &lang, &anchor
772+
args,
773+
"O|zzOzz:getsize",
774+
&string,
775+
&mode_name,
776+
&dir,
777+
&features,
778+
&lang,
779+
&anchor
772780
)) {
773781
return NULL;
774782
}
775783

776784
horizontal_dir = dir && strcmp(dir, "ttb") == 0 ? 0 : 1;
777785

778-
mask = mode && strcmp(mode, "1") == 0;
779-
color = mode && strcmp(mode, "RGBA") == 0;
786+
const ModeID mode = findModeID(mode_name);
787+
mask = mode == IMAGING_MODE_1;
788+
color = mode == IMAGING_MODE_RGBA;
780789

781790
count = text_layout(string, self, dir, features, lang, &glyph_info, mask, color);
782791
if (PyErr_Occurred()) {
@@ -842,7 +851,7 @@ font_render(FontObject *self, PyObject *args) {
842851
float stroke_width = 0;
843852
PY_LONG_LONG foreground_ink_long = 0;
844853
unsigned int foreground_ink;
845-
const char *mode = NULL;
854+
const char *mode_name = NULL;
846855
const char *dir = NULL;
847856
const char *lang = NULL;
848857
const char *anchor = NULL;
@@ -862,7 +871,7 @@ font_render(FontObject *self, PyObject *args) {
862871
"OO|zzOzfzLffO:render",
863872
&string,
864873
&fill,
865-
&mode,
874+
&mode_name,
866875
&dir,
867876
&features,
868877
&lang,
@@ -875,8 +884,9 @@ font_render(FontObject *self, PyObject *args) {
875884
return NULL;
876885
}
877886

878-
mask = mode && strcmp(mode, "1") == 0;
879-
color = mode && strcmp(mode, "RGBA") == 0;
887+
const ModeID mode = findModeID(mode_name);
888+
mask = mode == IMAGING_MODE_1;
889+
color = mode == IMAGING_MODE_RGBA;
880890

881891
foreground_ink = foreground_ink_long;
882892

0 commit comments

Comments
 (0)