diff options
author | William Hua <william.hua@canonical.com> | 2013-06-05 20:45:45 -0400 |
---|---|---|
committer | William Hua <william.hua@canonical.com> | 2013-06-05 20:45:45 -0400 |
commit | 91ddc799bd01ce206e2822ae4b6c58b087efc6b6 (patch) | |
tree | 825bb36978c56d40980be45c7fb09bacef60fc59 | |
parent | 97e9428331438a66fb78696b736d7046e96889cb (diff) | |
download | ayatana-indicator-keyboard-91ddc799bd01ce206e2822ae4b6c58b087efc6b6.tar.gz ayatana-indicator-keyboard-91ddc799bd01ce206e2822ae4b6c58b087efc6b6.tar.bz2 ayatana-indicator-keyboard-91ddc799bd01ce206e2822ae4b6c58b087efc6b6.zip |
Align text within icons properly.
-rw-r--r-- | configure.ac | 4 | ||||
-rw-r--r-- | data/Makefile.am | 5 | ||||
-rw-r--r-- | data/icon-1.svg.in | 13 | ||||
-rw-r--r-- | data/icon.svg.in | 12 | ||||
-rw-r--r-- | data/main.vala | 113 | ||||
-rw-r--r-- | deps/README | 12 | ||||
-rw-r--r-- | deps/fontconfig.vapi | 13 | ||||
-rw-r--r-- | deps/freetype2.vapi | 20 | ||||
-rw-r--r-- | deps/pangoft2.vapi | 33 | ||||
-rw-r--r-- | lib/Makefile.am | 4 |
10 files changed, 207 insertions, 22 deletions
diff --git a/configure.ac b/configure.ac index 39d72f56..4b6f4f1c 100644 --- a/configure.ac +++ b/configure.ac @@ -43,6 +43,10 @@ PKG_CHECK_MODULES([GTK], [gtk+-3.0]) AC_SUBST([GTK_CFLAGS]) AC_SUBST([GTK_LIBS]) +PKG_CHECK_MODULES([PANGOFT2], [pangoft2]) +AC_SUBST([PANGOFT2_CFLAGS]) +AC_SUBST([PANGOFT2_LIBS]) + PKG_CHECK_MODULES([PANGOCAIRO], [pangocairo]) AC_SUBST([PANGOCAIRO_CFLAGS]) AC_SUBST([PANGOCAIRO_LIBS]) 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); diff --git a/deps/README b/deps/README index 963a51bc..41775da2 100644 --- a/deps/README +++ b/deps/README @@ -1,3 +1,15 @@ +To generate fontconfig.vapi: + +vapigen --library fontconfig /path/to/fontconfig-2.0.gir + +To generate freetype2.vapi: + +vapigen --library freetype2 /path/to/freetype2-2.0.gir + +To generate pangoft2.vapi: + +vapigen --library pangoft2 /path/to/PangoFT2-1.0.gir + To generate gnome-desktop-3.0.vapi: vapigen --pkg gio-2.0 --pkg gtk+-3.0 --library gnome-desktop-3.0 /path/to/GnomeDesktop-3.0.gir diff --git a/deps/fontconfig.vapi b/deps/fontconfig.vapi new file mode 100644 index 00000000..dc3f450b --- /dev/null +++ b/deps/fontconfig.vapi @@ -0,0 +1,13 @@ +/* fontconfig.vapi generated by vapigen, do not modify. */ + +[CCode (cprefix = "Fc", gir_namespace = "fontconfig", gir_version = "2.0", lower_case_cprefix = "fc_")] +namespace Fc { + [CCode (cheader_filename = "fontconfig-2.0.h", has_type_id = false)] + public struct CharSet { + } + [CCode (cheader_filename = "fontconfig-2.0.h", has_type_id = false)] + public struct Pattern { + } + [CCode (cheader_filename = "fontconfig-2.0.h", cname = "FcInit")] + public static void init (); +} diff --git a/deps/freetype2.vapi b/deps/freetype2.vapi new file mode 100644 index 00000000..5403be26 --- /dev/null +++ b/deps/freetype2.vapi @@ -0,0 +1,20 @@ +/* freetype2.vapi generated by vapigen, do not modify. */ + +[CCode (cprefix = "FT", gir_namespace = "freetype2", gir_version = "2.0", lower_case_cprefix = "FT_")] +namespace FT { + [CCode (cheader_filename = "freetype2-2.0.h", cname = "FT_Bitmap", has_type_id = false)] + public struct Bitmap { + } + [CCode (cheader_filename = "freetype2-2.0.h", cname = "FT_Face", has_type_id = false)] + public struct Face { + } + [CCode (cheader_filename = "freetype2-2.0.h", cname = "FT_Int32")] + [SimpleType] + public struct Int32 : int32 { + } + [CCode (cheader_filename = "freetype2-2.0.h", cname = "FT_Library", has_type_id = false)] + public struct Library { + } + [CCode (cheader_filename = "freetype2-2.0.h", cname = "FT_Library_Version")] + public static void library_version (); +} diff --git a/deps/pangoft2.vapi b/deps/pangoft2.vapi new file mode 100644 index 00000000..8dc85109 --- /dev/null +++ b/deps/pangoft2.vapi @@ -0,0 +1,33 @@ +/* pangoft2.vapi generated by vapigen, do not modify. */ + +[CCode (cprefix = "PangoFT2", gir_namespace = "PangoFT2", gir_version = "1.0", lower_case_cprefix = "pango_ft2_")] +namespace PangoFT2 { + [CCode (cheader_filename = "pango/pangoft2.h", type_id = "pango_ft2_font_map_get_type ()")] + public class FontMap : Pango.FontMap { + [CCode (has_construct_function = false, type = "PangoFontMap*")] + public FontMap (); + public void set_default_substitute (owned PangoFT2.SubstituteFunc func); + public void set_resolution (double dpi_x, double dpi_y); + public void substitute_changed (); + } + [CCode (cheader_filename = "pango/pangoft2.h", has_target = false)] + public delegate void SubstituteFunc (Fc.Pattern pattern, void* data); + [CCode (cheader_filename = "pango/pangoft2.h")] + public static int font_get_kerning (Pango.Font font, Pango.Glyph left, Pango.Glyph right); + [CCode (cheader_filename = "pango/pangoft2.h")] + public static Pango.Glyph get_unknown_glyph (Pango.Font font); + [CCode (cheader_filename = "pango/pangoft2.h")] + public static void render (FT.Bitmap bitmap, Pango.Font font, Pango.GlyphString glyphs, int x, int y); + [CCode (cheader_filename = "pango/pangoft2.h")] + public static void render_layout (FT.Bitmap bitmap, Pango.Layout layout, int x, int y); + [CCode (cheader_filename = "pango/pangoft2.h")] + public static void render_layout_line (FT.Bitmap bitmap, Pango.LayoutLine line, int x, int y); + [CCode (cheader_filename = "pango/pangoft2.h")] + public static void render_layout_line_subpixel (FT.Bitmap bitmap, Pango.LayoutLine line, int x, int y); + [CCode (cheader_filename = "pango/pangoft2.h")] + public static void render_layout_subpixel (FT.Bitmap bitmap, Pango.Layout layout, int x, int y); + [CCode (cheader_filename = "pango/pangoft2.h")] + public static void render_transformed (FT.Bitmap bitmap, Pango.Matrix matrix, Pango.Font font, Pango.GlyphString glyphs, int x, int y); + [CCode (cheader_filename = "pango/pangoft2.h")] + public static void shutdown_display (); +} diff --git a/lib/Makefile.am b/lib/Makefile.am index 5f808108..b9aa2394 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -17,15 +17,15 @@ indicator_keyboard_service_VALAFLAGS = $(AM_VALAFLAGS) \ --pkg libgnomekbd \ --pkg ibus-1.0 indicator_keyboard_service_CFLAGS = $(AM_CFLAGS) \ - $(GTK_CFLAGS) \ $(PANGOCAIRO_CFLAGS) \ + $(GTK_CFLAGS) \ $(GNOME_DESKTOP_CFLAGS) \ $(LIBXKLAVIER_CFLAGS) \ $(LIBGNOMEKBD_CFLAGS) \ $(IBUS_CFLAGS) indicator_keyboard_service_LDFLAGS = $(AM_LDFLAGS) \ - $(GTK_LIBS) \ $(PANGOCAIRO_LIBS) \ + $(GTK_LIBS) \ $(GNOME_DESKTOP_LIBS) \ $(LIBXKLAVIER_LIBS) \ $(LIBGNOMEKBD_LIBS) \ |