summaryrefslogtreecommitdiff
authorAnisse Astier <anisse@astier.eu>2012-08-07 08:22:09 (GMT)
committer Ray Strode <rstrode@redhat.com>2012-08-08 19:52:45 (GMT)
commit468c53a128e69809c727c9c69e166297ed66d3b5 (patch) (side-by-side diff)
tree7e67a528796dc55dc18d90c40f1cb1c17a4fcc7f
parent96d8d38698b8bb05b7a1541f2cffd63a478e2bd4 (diff)
downloadplymouth-468c53a128e69809c727c9c69e166297ed66d3b5.zip
plymouth-468c53a128e69809c727c9c69e166297ed66d3b5.tar.gz
script: Add alignment argument to Image.Text
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
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--src/libply-splash-core/ply-terminal.h1
-rw-r--r--src/libply-splash-core/ply-text-display.c29
-rw-r--r--src/plugins/splash/script/script-lib-image.c25
-rw-r--r--src/plugins/splash/script/script-lib-image.script4
4 files changed, 55 insertions, 4 deletions
diff --git a/src/libply-splash-core/ply-terminal.h b/src/libply-splash-core/ply-terminal.h
index 8b4b017..41b7515 100644
--- a/src/libply-splash-core/ply-terminal.h
+++ b/src/libply-splash-core/ply-terminal.h
@@ -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
diff --git a/src/libply-splash-core/ply-text-display.c b/src/libply-splash-core/ply-text-display.c
index 7cabd98..0d84e5b 100644
--- a/src/libply-splash-core/ply-text-display.c
+++ b/src/libply-splash-core/ply-text-display.c
@@ -82,10 +82,18 @@
#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
@@ -187,6 +195,17 @@ ply_text_display_set_background_color (ply_text_display_t *display,
}
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)
{
diff --git a/src/plugins/splash/script/script-lib-image.c b/src/plugins/splash/script/script-lib-image.c
index 20aec36..5be27fb 100644
--- a/src/plugins/splash/script/script-lib-image.c
+++ b/src/plugins/splash/script/script-lib-image.c
@@ -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);
diff --git a/src/plugins/splash/script/script-lib-image.script b/src/plugins/splash/script/script-lib-image.script
index 4fa377f..00b1c19 100644
--- a/src/plugins/splash/script/script-lib-image.script
+++ b/src/plugins/splash/script/script-lib-image.script
@@ -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)