]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
script: Add alignment argument to Image.Text
authorAnisse Astier <anisse@astier.eu>
Tue, 7 Aug 2012 08:22:09 +0000 (10:22 +0200)
committerRay Strode <rstrode@redhat.com>
Wed, 8 Aug 2012 19:52:45 +0000 (15:52 -0400)
Enables scripts to choose the text alignment they want with a seventh
argument to Image.Text API:

    new_image = Image.Text("Hello\n"
                           "Plymouth aligned world",
                            1, 1, 1, 1,
                           "DejaVu Bold,Italic 18",
                           "center");

This argument can be ignored, the default being left aligned.
Possible values are "left", "center", or "right".

http://lists.freedesktop.org/archives/plymouth/2012-August/000676.html

src/libply-splash-core/ply-terminal.h
src/libply-splash-core/ply-text-display.c
src/plugins/splash/script/script-lib-image.c
src/plugins/splash/script/script-lib-image.script

index 8b4b0177e3866455bda141c93c65fb358e19c014..41b751534193399f393238bab9a13c07a5d583fe 100644 (file)
@@ -45,7 +45,6 @@ typedef enum
   PLY_TERMINAL_COLOR_MAGENTA,
   PLY_TERMINAL_COLOR_CYAN,
   PLY_TERMINAL_COLOR_WHITE,
-  PLY_TERMINAL_COLOR_DEFAULT = PLY_TERMINAL_COLOR_WHITE + 2
 } ply_terminal_color_t;
 
 typedef enum
index 7cabd98f4a67bfff41bfcf3e487053317f81458e..0d84e5becf781d2c6046962d8a7b30555d5ee62a 100644 (file)
 #define FOREGROUND_COLOR_BASE 30
 #endif
 
+#ifndef FOREGROUND_DEFAULT_COLOR
+#define FOREGROUND_DEFAULT_COLOR 39
+#endif
+
 #ifndef BACKGROUND_COLOR_BASE
 #define BACKGROUND_COLOR_BASE 40
 #endif
 
+#ifndef BACKGROUND_DEFAULT_COLOR
+#define BACKGROUND_DEFAULT_COLOR 49
+#endif
+
 #ifndef TEXT_PALETTE_SIZE
 #define TEXT_PALETTE_SIZE 48
 #endif
@@ -186,6 +194,17 @@ ply_text_display_set_background_color (ply_text_display_t   *display,
   display->background_color = color;
 }
 
+void
+ply_text_display_reset_background_color (ply_text_display_t *display)
+{
+
+  ply_terminal_write (display->terminal,
+                      COLOR_SEQUENCE_FORMAT,
+                      BACKGROUND_DEFAULT_COLOR);
+
+  display->background_color = color;
+}
+
 void
 ply_text_display_set_foreground_color (ply_text_display_t       *display,
                                        ply_terminal_color_t  color)
@@ -197,6 +216,16 @@ ply_text_display_set_foreground_color (ply_text_display_t       *display,
   display->foreground_color = color;
 }
 
+void
+ply_text_display_reset_foreground_color (ply_text_display_t *display)
+{
+  ply_terminal_write (display->terminal,
+                      COLOR_SEQUENCE_FORMAT,
+                      FOREGROUND_DEFAULT_COLOR);
+
+  display->foreground_color = color;
+}
+
 ply_terminal_color_t
 ply_text_display_get_background_color (ply_text_display_t *display)
 {
index 20aec36527ce9be5ac6f0b99ffc445e2d2718fe5..5be27fbedde4509f994c5492b13f4ba6cd602f60 100644 (file)
@@ -24,6 +24,7 @@
 #include "ply-label.h"
 #include "ply-pixel-buffer.h"
 #include "ply-utils.h"
+#include "ply-logger.h"
 #include "script.h"
 #include "script-parse.h"
 #include "script-object.h"
@@ -158,8 +159,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, *font_obj;
+  script_obj_t *alpha_obj, *font_obj, *align_obj;
   int width, height;
+  int align = PLY_LABEL_ALIGN_LEFT;
   char *font;
   
   char *text = script_obj_hash_get_string (state->local, "text");
@@ -188,12 +190,32 @@ static script_return_t image_text (script_state_t *state,
 
   script_obj_unref(font_obj);
 
+  align_obj = script_obj_hash_peek_element(state->local, "align");
+
+  if (script_obj_is_string(align_obj)) {
+    char *align_str = script_obj_as_string(align_obj);
+
+    if(!strcmp("left", align_str))
+      align = PLY_LABEL_ALIGN_LEFT;
+    else if(!strcmp("center", align_str))
+      align = PLY_LABEL_ALIGN_CENTER;
+    else if(!strcmp("right", align_str))
+      align = PLY_LABEL_ALIGN_RIGHT;
+    else
+      ply_error("Unrecognized Image.Text alignment string '%s'. "
+             "Expecting 'left', 'center', or 'right'\n",
+               align_str);
+    free(align_str);
+  }
+  script_obj_unref(align_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_alignment(label, align);
   ply_label_set_color (label, red, green, blue, alpha);
   ply_label_show (label, NULL, 0, 0);
   
@@ -259,6 +281,7 @@ script_lib_image_data_t *script_lib_image_setup (script_state_t *state,
                               "blue",
                               "alpha",
                               "font",
+                              "align",
                               NULL);
 
   script_obj_unref (image_hash);
index 4fa377f4771f223b3de44253331e0bbe11d7dfb0..00b1c19c2b06f2d5c303d7cb7bf747ae692266cf 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, font)
+Image.Text = fun (text, red, green, blue, alpha, font, align)
 {
-  return Image.Adopt (Image._Text (text, red, green, blue, alpha, font));
+  return Image.Adopt (Image._Text (text, red, green, blue, alpha, font, align));
 };
 
 Image |= fun (filename)