aboutsummaryrefslogtreecommitdiff
path: root/data
diff options
context:
space:
mode:
authorWilliam Hua <william.hua@canonical.com>2013-06-05 20:45:45 -0400
committerWilliam Hua <william.hua@canonical.com>2013-06-05 20:45:45 -0400
commit91ddc799bd01ce206e2822ae4b6c58b087efc6b6 (patch)
tree825bb36978c56d40980be45c7fb09bacef60fc59 /data
parent97e9428331438a66fb78696b736d7046e96889cb (diff)
downloadayatana-indicator-keyboard-91ddc799bd01ce206e2822ae4b6c58b087efc6b6.tar.gz
ayatana-indicator-keyboard-91ddc799bd01ce206e2822ae4b6c58b087efc6b6.tar.bz2
ayatana-indicator-keyboard-91ddc799bd01ce206e2822ae4b6c58b087efc6b6.zip
Align text within icons properly.
Diffstat (limited to 'data')
-rw-r--r--data/Makefile.am5
-rw-r--r--data/icon-1.svg.in13
-rw-r--r--data/icon.svg.in12
-rw-r--r--data/main.vala113
4 files changed, 123 insertions, 20 deletions
diff --git a/data/Makefile.am b/data/Makefile.am
index 125289bb..b65c47ff 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -9,17 +9,22 @@ indicator_keyboard_icon_generator_SOURCES = main.vala \
$(top_srcdir)/lib/common.vala
indicator_keyboard_icon_generator_VALAFLAGS = $(AM_VALAFLAGS) \
--pkg gee-1.0 \
+ --pkg fontconfig \
+ --pkg freetype2 \
+ --pkg pangoft2 \
--pkg gtk+-3.0 \
--pkg GDesktopEnums-3.0 \
--pkg gnome-desktop-3.0 \
--pkg Xkl-1.0
indicator_keyboard_icon_generator_CFLAGS = $(AM_CFLAGS) \
$(GEE_CFLAGS) \
+ $(PANGOFT2_CFLAGS) \
$(GTK_CFLAGS) \
$(GNOME_DESKTOP_CFLAGS) \
$(LIBXKLAVIER_CFLAGS)
indicator_keyboard_icon_generator_LDFLAGS = $(AM_LDFLAGS) \
$(GEE_LIBS) \
+ $(PANGOFT2_LIBS) \
$(GTK_LIBS) \
$(GNOME_DESKTOP_LIBS) \
$(LIBXKLAVIER_LIBS)
diff --git a/data/icon-1.svg.in b/data/icon-1.svg.in
index 1ce1a822..5bda1548 100644
--- a/data/icon-1.svg.in
+++ b/data/icon-1.svg.in
@@ -1 +1,12 @@
-<?xml version="1.0" encoding="UTF-8"?><svg version="1.1" width="22" height="22"><defs><mask id="m"><rect x="0" y="0" width="22" height="22" style="fill:white"/><text x="@LAYOUT_X@" y="@LAYOUT_Y@" style="font-size:12px;font-weight:500;fill:black;font-family:Ubuntu">@LAYOUT@</text><text x="@SUBSCRIPT_X@" y="@SUBSCRIPT_Y@" style="font-size:10px;font-weight:500;fill:black;font-family:Ubuntu">@SUBSCRIPT@</text></mask></defs><rect x="0" y="0" width="22" height="22" rx="4" mask="url(#m)" style="fill:@COLOUR@"/></svg>
+<?xml version="1.0" encoding="UTF-8"?>
+
+<svg version="1.1" width="@WIDTH@" height="@HEIGHT@">
+ <defs>
+ <mask id="m">
+ <rect x="0" y="0" width="@WIDTH@" height="@HEIGHT@" style="fill:white" />
+ <text x="@LAYOUT_X@" y="@LAYOUT_Y@" style="@LAYOUT_FONT@;fill:black">@LAYOUT@</text>
+ <text x="@SUBSCRIPT_X@" y="@SUBSCRIPT_Y@" style="@SUBSCRIPT_FONT@;fill:black">@SUBSCRIPT@</text>
+ </mask>
+ </defs>
+ <rect x="0" y="0" width="@WIDTH@" height="@HEIGHT@" rx="@RADIUS@" mask="url(#m)" style="fill:@COLOUR@" />
+</svg>
diff --git a/data/icon.svg.in b/data/icon.svg.in
index e223c017..672cd131 100644
--- a/data/icon.svg.in
+++ b/data/icon.svg.in
@@ -1 +1,11 @@
-<?xml version="1.0" encoding="UTF-8"?><svg version="1.1" width="22" height="22"><defs><mask id="m"><rect x="0" y="0" width="22" height="22" style="fill:white"/><text x="@LAYOUT_X@" y="@LAYOUT_Y@" style="font-size:12px;font-weight:500;fill:black;font-family:Ubuntu">@LAYOUT@</text></mask></defs><rect x="0" y="0" width="22" height="22" rx="4" mask="url(#m)" style="fill:@COLOUR@"/></svg>
+<?xml version="1.0" encoding="UTF-8"?>
+
+<svg version="1.1" width="@WIDTH@" height="@HEIGHT@">
+ <defs>
+ <mask id="m">
+ <rect x="0" y="0" width="@WIDTH@" height="@HEIGHT@" style="fill:white" />
+ <text x="@LAYOUT_X@" y="@LAYOUT_Y@" style="@LAYOUT_FONT@;fill:black">@LAYOUT@</text>
+ </mask>
+ </defs>
+ <rect x="0" y="0" width="@WIDTH@" height="@HEIGHT@" rx="@RADIUS@" mask="url(#m)" style="fill:@COLOUR@" />
+</svg>
diff --git a/data/main.vala b/data/main.vala
index 2c28ace7..f942a591 100644
--- a/data/main.vala
+++ b/data/main.vala
@@ -1,17 +1,31 @@
int main (string[] args) {
var force = false;
+ var width = 220.0;
+ var height = 220.0;
+ var radius = 40.0;
var colour = "grey";
+ var font = "Ubuntu";
+ var weight = 500;
+ var layout_size = 120;
+ var subscript_size = 80;
string output_path = null;
string no_subscript_path = null;
string with_subscript_path = null;
- OptionEntry[] options = new OptionEntry[6];
+ OptionEntry[] options = new OptionEntry[13];
options[0] = { "force", 'f', 0, OptionArg.NONE, ref force, "Overwrite existing files" };
- options[1] = { "colour", 'c', 0, OptionArg.STRING, ref colour, "Icon colour", "COLOUR" };
- options[2] = { "output", 'o', 0, OptionArg.FILENAME, ref output_path, "Output directory", "PATH" };
- options[3] = { "no-subscript", 's', 0, OptionArg.FILENAME, ref no_subscript_path, "Icon template", "PATH" };
- options[4] = { "with-subscript", 'S', 0, OptionArg.FILENAME, ref with_subscript_path, "Subscript icon template", "PATH" };
- options[5] = { null };
+ options[1] = { "width", 'w', 0, OptionArg.DOUBLE, ref width, "Icon width", "DOUBLE" };
+ options[2] = { "height", 'h', 0, OptionArg.DOUBLE, ref height, "Icon height", "DOUBLE" };
+ options[3] = { "radius", 'r', 0, OptionArg.DOUBLE, ref radius, "Icon radius", "DOUBLE" };
+ options[4] = { "colour", 'c', 0, OptionArg.STRING, ref colour, "Icon colour", "COLOUR" };
+ options[5] = { "font", 'f', 0, OptionArg.STRING, ref font, "Font family", "NAME" };
+ options[6] = { "weight", 'W', 0, OptionArg.INT, ref weight, "Font weight (100 to 1000)", "INT" };
+ options[7] = { "layout-size", 's', 0, OptionArg.INT, ref layout_size, "Layout font size", "INT" };
+ options[8] = { "subscript-size", 'S', 0, OptionArg.INT, ref subscript_size, "Subscript font size", "INT" };
+ options[9] = { "output", 'o', 0, OptionArg.FILENAME, ref output_path, "Output directory", "PATH" };
+ options[10] = { "no-subscript", 'i', 0, OptionArg.FILENAME, ref no_subscript_path, "Icon template", "PATH" };
+ options[11] = { "with-subscript", 'I', 0, OptionArg.FILENAME, ref with_subscript_path, "Subscript icon template", "PATH" };
+ options[12] = { null };
try {
var context = new OptionContext ("- generate keyboard layout icons");
@@ -78,27 +92,70 @@ int main (string[] args) {
try {
uint8[] contents;
+ var layout_font = @"font-family:$font;font-weight:$weight;font-size:$layout_size";
+ var subscript_font = @"font-family:$font;font-weight:$weight;font-size:$subscript_size";
+
File.new_for_path (no_subscript_path).load_contents (null, out contents, null);
- no_subscript_data = ((string) contents).replace ("@COLOUR@", colour);
+ no_subscript_data = (string) contents;
+ no_subscript_data = no_subscript_data.replace ("@WIDTH@", @"$width");
+ no_subscript_data = no_subscript_data.replace ("@HEIGHT@", @"$height");
+ no_subscript_data = no_subscript_data.replace ("@RADIUS@", @"$radius");
+ no_subscript_data = no_subscript_data.replace ("@COLOUR@", colour);
+ no_subscript_data = no_subscript_data.replace ("@LAYOUT_FONT@", layout_font);
+ no_subscript_data = no_subscript_data.replace ("@SUBSCRIPT_FONT@", subscript_font);
File.new_for_path (with_subscript_path).load_contents (null, out contents, null);
- with_subscript_data = ((string) contents).replace ("@COLOUR@", colour);
+ with_subscript_data = (string) contents;
+ with_subscript_data = with_subscript_data.replace ("@WIDTH@", @"$width");
+ with_subscript_data = with_subscript_data.replace ("@HEIGHT@", @"$height");
+ with_subscript_data = with_subscript_data.replace ("@RADIUS@", @"$radius");
+ with_subscript_data = with_subscript_data.replace ("@COLOUR@", colour);
+ with_subscript_data = with_subscript_data.replace ("@LAYOUT_FONT@", layout_font);
+ with_subscript_data = with_subscript_data.replace ("@SUBSCRIPT_FONT@", subscript_font);
} catch (Error error) {
stderr.printf ("error: %s\n", error.message);
return 4;
}
+ var font_map = new PangoFT2.FontMap ();
+ var layout_layout = new Pango.Layout (font_map.create_context ());
+ var subscript_layout = new Pango.Layout (font_map.create_context ());
+
+ var font_description = new Pango.FontDescription ();
+ font_description.set_family (font);
+ font_description.set_weight ((Pango.Weight) weight);
+ font_description.set_size (layout_size * Pango.SCALE);
+ layout_layout.set_font_description (font_description);
+
+ font_description = new Pango.FontDescription ();
+ font_description.set_family (font);
+ font_description.set_weight ((Pango.Weight) weight);
+ font_description.set_size (subscript_size * Pango.SCALE);
+ subscript_layout.set_font_description (font_description);
+
foreach (var entry in occurrences.entries) {
var layout = entry.key;
var count = entry.value;
var file = File.new_for_path (@"$output_path/$layout.svg");
if (force || !file.query_exists (null)) {
- var output_data = no_subscript_data;
+ int layout_width;
+ int layout_height;
+
+ layout_layout.set_text (layout, -1);
+ layout_layout.get_size (out layout_width, out layout_height);
+ var layout_baseline = layout_layout.get_baseline ();
+ var layout_x = 0.5 * (width - 1.0 * layout_width / Pango.SCALE);
+ var layout_y = 0.5 * (height - 1.0 * layout_height / Pango.SCALE) + 1.0 * layout_baseline / Pango.SCALE;
+
+ var output_data = no_subscript_data;
output_data = output_data.replace ("@LAYOUT@", layout);
- output_data = output_data.replace ("@LAYOUT_X@", "3.5");
- output_data = output_data.replace ("@LAYOUT_Y@", "15.5");
+ output_data = output_data.replace ("@LAYOUT_X@", @"$layout_x");
+ output_data = output_data.replace ("@LAYOUT_Y@", @"$layout_y");
+ output_data = output_data.replace ("@SUBSCRIPT@", "");
+ output_data = output_data.replace ("@SUBSCRIPT_X@", "0");
+ output_data = output_data.replace ("@SUBSCRIPT_Y@", "0");
try {
file.replace_contents (output_data.data, null, false, FileCreateFlags.REPLACE_DESTINATION, null, null);
@@ -108,21 +165,41 @@ int main (string[] args) {
}
if (count > 1) {
- var partial_data = with_subscript_data;
+ int layout_width;
+ int layout_height;
+
+ layout_layout.set_text (layout, -1);
+ layout_layout.get_size (out layout_width, out layout_height);
+ var layout_baseline = layout_layout.get_baseline ();
+ var layout_y = 0.5 * (height - 1.0 * layout_height / Pango.SCALE) + 1.0 * layout_baseline / Pango.SCALE;
+
+ var partial_data = with_subscript_data;
partial_data = partial_data.replace ("@LAYOUT@", layout);
+ partial_data = partial_data.replace ("@LAYOUT_Y@", @"$layout_y");
for (var i = 1; i <= count; i++) {
file = File.new_for_path (@"$output_path/$layout-$i.svg");
if (force || !file.query_exists (null)) {
- var output_data = partial_data;
+ var subscript = @"$i";
+ int subscript_width;
+ int subscript_height;
+
+ subscript_layout.set_text (subscript, -1);
+ subscript_layout.get_size (out subscript_width, out subscript_height);
+ var subscript_baseline = subscript_layout.get_baseline ();
- output_data = output_data.replace ("@LAYOUT_X@", "3.5");
- output_data = output_data.replace ("@LAYOUT_Y@", "15.5");
- output_data = output_data.replace ("@SUBSCRIPT@", @"$i");
- output_data = output_data.replace ("@SUBSCRIPT_X@", "15");
- output_data = output_data.replace ("@SUBSCRIPT_Y@", "10");
+ var layout_x = 0.5 * (width - 1.0 * (layout_width + subscript_width) / Pango.SCALE);
+ var subscript_x = layout_x + 1.0 * layout_width / Pango.SCALE;
+ var subscript_y = layout_y - 0.5 * subscript_height / Pango.SCALE + 1.0 * subscript_baseline / Pango.SCALE;
+
+ var output_data = partial_data;
+ output_data = output_data.replace ("@LAYOUT_X@", @"$layout_x");
+ output_data = output_data.replace ("@LAYOUT_Y@", @"$layout_y");
+ output_data = output_data.replace ("@SUBSCRIPT@", subscript);
+ output_data = output_data.replace ("@SUBSCRIPT_X@", @"$subscript_x");
+ output_data = output_data.replace ("@SUBSCRIPT_Y@", @"$subscript_y");
try {
file.replace_contents (output_data.data, null, false, FileCreateFlags.REPLACE_DESTINATION, null, null);