mirror of
https://gitlab.freedesktop.org/plymouth/plymouth.git
synced 2026-05-07 17:48:01 +02:00
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
This commit is contained in:
parent
96d8d38698
commit
468c53a128
4 changed files with 55 additions and 4 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue