]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
[script] Add font selection argument to text to image capability
authorAnisse Astier <anisse@astier.eu>
Thu, 2 Sep 2010 15:53:25 +0000 (16:53 +0100)
committerCharlie Brej <cbrej@cs.man.ac.uk>
Thu, 2 Sep 2010 15:53:25 +0000 (16:53 +0100)
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");

src/plugins/splash/script/script-lib-image.c
src/plugins/splash/script/script-lib-image.script

index 12c3278f35b44816648b4488096287786da52529..20aec36527ce9be5ac6f0b99ffc445e2d2718fe5 100644 (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);
index 015a2f501f694297dd19b54c8dcb4797a163baf9..4fa377f4771f223b3de44253331e0bbe11d7dfb0 100644 (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)