[script] Add font selection argument to text to image capability

Enables scripts to choose the font they want with a sixth argument to
Image.Text API:
new_image = Image.Text("Hello", 1, 1, 1, 1, "DejaVu Bold,Italic 18");
This commit is contained in:
Anisse Astier 2010-09-02 16:53:25 +01:00 committed by Charlie Brej
parent 984f4d9643
commit 5e8e039a00
2 changed files with 17 additions and 3 deletions

View file

@ -158,8 +158,9 @@ static script_return_t image_text (script_state_t *state,
script_lib_image_data_t *data = user_data;
ply_pixel_buffer_t *image;
ply_label_t *label;
script_obj_t *alpha_obj;
script_obj_t *alpha_obj, *font_obj;
int width, height;
char *font;
char *text = script_obj_hash_get_string (state->local, "text");
@ -178,10 +179,21 @@ static script_return_t image_text (script_state_t *state,
alpha = 1;
script_obj_unref(alpha_obj);
font_obj = script_obj_hash_peek_element (state->local, "font");
if (script_obj_is_string (font_obj))
font = script_obj_as_string (font_obj);
else
font = NULL;
script_obj_unref(font_obj);
if (!text) return script_return_obj_null ();
label = ply_label_new ();
ply_label_set_text (label, text);
if (font)
ply_label_set_font (label, font);
ply_label_set_color (label, red, green, blue, alpha);
ply_label_show (label, NULL, 0, 0);
@ -192,6 +204,7 @@ static script_return_t image_text (script_state_t *state,
ply_label_draw_area (label, image, 0, 0, width, height);
free (text);
free (font);
ply_label_free (label);
return script_return_obj (script_obj_new_native (image, data->class));
@ -245,6 +258,7 @@ script_lib_image_data_t *script_lib_image_setup (script_state_t *state,
"green",
"blue",
"alpha",
"font",
NULL);
script_obj_unref (image_hash);

View file

@ -14,9 +14,9 @@ Image.Scale = fun (width, height)
return Image.Adopt (this._Scale(width, height));
};
Image.Text = fun (text, red, green, blue, alpha)
Image.Text = fun (text, red, green, blue, alpha, font)
{
return Image.Adopt (Image._Text (text, red, green, blue, alpha));
return Image.Adopt (Image._Text (text, red, green, blue, alpha, font));
};
Image |= fun (filename)