Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(77)

Side by Side Diff: ui/gtk3/emojier.vala

Issue 320700043: ui/gtk3: Integrate custom rendering to use HarfBuzz glyph info Base URL: git@github.com:ibus/ibus.git@master
Patch Set: Fix rhbz#1490733 Created 6 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gtk3/Makefile.am ('k') | ui/gtk3/ibusfontset.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* vim:set et sts=4 sw=4: 1 /* vim:set et sts=4 sw=4:
2 * 2 *
3 * ibus - The Input Bus 3 * ibus - The Input Bus
4 * 4 *
5 * Copyright (c) 2017 Takao Fujiwara <takao.fujiwara1@gmail.com> 5 * Copyright (c) 2017 Takao Fujiwara <takao.fujiwara1@gmail.com>
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public 8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version. 10 * version 2.1 of the License, or (at your option) any later version.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 vexpand : true, 73 vexpand : true,
74 halign : Gtk.Align.FILL, 74 halign : Gtk.Align.FILL,
75 valign : Gtk.Align.FILL, 75 valign : Gtk.Align.FILL,
76 row_spacing : 5, 76 row_spacing : 5,
77 column_spacing : 5, 77 column_spacing : 5,
78 border_width : 2 78 border_width : 2
79 ); 79 );
80 } 80 }
81 } 81 }
82 private class EWhiteLabel : Gtk.Label { 82 private class EWhiteLabel : Gtk.Label {
83 #if ENABLE_HARFBUZZ_FOR_EMOJI
84 IBus.RequisitionEx m_requisition;
85 #endif
83 public EWhiteLabel(string text) { 86 public EWhiteLabel(string text) {
84 GLib.Object( 87 GLib.Object(
85 name : "IBusEmojierWhiteLabel" 88 name : "IBusEmojierWhiteLabel"
86 ); 89 );
87 if (text != "") 90 if (text != "")
88 set_label(text); 91 set_label(text);
89 } 92 }
93 #if ENABLE_HARFBUZZ_FOR_EMOJI
94 private void get_preferred_size_with_hb(out int minimum_width,
95 out int natural_width,
96 out int minimum_height,
97 out int natural_height) {
98 minimum_width = 0;
99 natural_width = 0;
100 minimum_height = 0;
101 natural_height = 0;
102 var text = this.get_text();
103 if (text == null || text == "")
104 return;
105 var context = this.get_pango_context();
106 var language = context.get_language();
107 update_fontset(language);
108 Cairo.RectangleInt widest = Cairo.RectangleInt();
109 m_requisition = m_fontset.get_preferred_size_hb(text, out widest);
110 minimum_width = widest.width;
111 natural_width = widest.width;
112 minimum_height = widest.height;
113 natural_height = widest.height;
114 }
115 public override void get_preferred_width(out int minimum_width,
116 out int natural_width) {
117 get_preferred_size_with_hb(out minimum_width,
118 out natural_width,
119 null, null);
120 }
121 public override void get_preferred_height(out int minimum_height,
122 out int natural_height) {
123 get_preferred_size_with_hb(null, null,
124 out minimum_height,
125 out natural_height);
126 }
127 public override bool draw(Cairo.Context cr) {
128 if (m_fontset == null)
129 return true;
130 if (m_requisition == null)
131 return true;
132 if (m_requisition.cairo_lines == null)
133 return true;
134 var style_context = get_style_context();
135 Gtk.Allocation allocation;
136 get_allocation(out allocation);
137 style_context.render_background(cr,
138 0, 0,
139 allocation.width,
140 allocation.height);
141 Gdk.RGBA *normal_fg = null;
142 style_context.get(Gtk.StateFlags.NORMAL,
143 "color",
144 out normal_fg);
145 cr.set_operator(Cairo.Operator.OVER);
146 cr.set_source_rgba(normal_fg.red, normal_fg.green, normal_fg.blue,
147 normal_fg.alpha);
148 cr.save();
149 double x = 0.0;
150 double y = 0.0;
151 if (allocation.width > m_requisition.width)
152 x = (allocation.width - m_requisition.width) / 2.0;
153 if (allocation.height > m_requisition.height)
154 y = (allocation.height - m_requisition.height) / 2.0;
155 cr.translate(x, y);
156 m_fontset.draw_cairo_with_requisition_ex(cr, m_requisition);
157 cr.restore();
158 normal_fg.free();
159 normal_fg = null;
160 return true;
161 }
162 #endif
90 } 163 }
91 private class ESelectedLabel : Gtk.Label { 164 private class ESelectedLabel : EWhiteLabel {
92 public ESelectedLabel(string text) { 165 public ESelectedLabel(string text) {
93 GLib.Object( 166 GLib.Object(
94 name : "IBusEmojierSelectedLabel" 167 name : "IBusEmojierSelectedLabel"
95 ); 168 );
96 if (text != "") 169 if (text != "")
97 set_label(text); 170 set_label(text);
98 } 171 }
99 } 172 }
100 private class EGoldLabel : Gtk.Label { 173 private class EGoldLabel : EWhiteLabel {
101 public EGoldLabel(string text) { 174 public EGoldLabel(string text) {
102 GLib.Object( 175 GLib.Object(
103 name : "IBusEmojierGoldLabel" 176 name : "IBusEmojierGoldLabel"
104 ); 177 );
105 if (text != "") 178 if (text != "")
106 set_label(text); 179 set_label(text);
107 } 180 }
108 } 181 }
109 private class EPaddedLabel : Gtk.Label { 182 private class EPaddedLabel : Gtk.Label {
110 public EPaddedLabel(string text, 183 public EPaddedLabel(string text,
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 private static uint m_partial_match_condition; 278 private static uint m_partial_match_condition;
206 private static bool m_show_emoji_variant = false; 279 private static bool m_show_emoji_variant = false;
207 private static GLib.HashTable<string, GLib.SList<string>>? 280 private static GLib.HashTable<string, GLib.SList<string>>?
208 m_annotation_to_emojis_dict; 281 m_annotation_to_emojis_dict;
209 private static GLib.HashTable<string, IBus.EmojiData>? 282 private static GLib.HashTable<string, IBus.EmojiData>?
210 m_emoji_to_data_dict; 283 m_emoji_to_data_dict;
211 private static GLib.HashTable<string, GLib.SList<string>>? 284 private static GLib.HashTable<string, GLib.SList<string>>?
212 m_category_to_emojis_dict; 285 m_category_to_emojis_dict;
213 private static GLib.HashTable<string, GLib.SList<string>>? 286 private static GLib.HashTable<string, GLib.SList<string>>?
214 m_emoji_to_emoji_variants_dict; 287 m_emoji_to_emoji_variants_dict;
288 #if ENABLE_HARFBUZZ_FOR_EMOJI
289 private static IBus.FontSet m_fontset;
290 #endif
215 291
216 private ThemedRGBA m_rgba; 292 private ThemedRGBA m_rgba;
217 private Gtk.Box m_vbox; 293 private Gtk.Box m_vbox;
218 private ETitleLabelBox m_title; 294 private ETitleLabelBox m_title;
219 private EEntry m_entry; 295 private EEntry m_entry;
220 private string? m_backward; 296 private string? m_backward;
221 private int m_backward_index = -1; 297 private int m_backward_index = -1;
222 private EScrolledWindow? m_scrolled_window = null; 298 private EScrolledWindow? m_scrolled_window = null;
223 private EListBox m_list_box; 299 private EListBox m_list_box;
224 private bool m_is_running = false; 300 private bool m_is_running = false;
(...skipping 1377 matching lines...) Expand 10 before | Expand all | Expand 10 after
1602 int y = (monitor_area.y + monitor_area.height 1678 int y = (monitor_area.y + monitor_area.height
1603 - allocation.height)/2; 1679 - allocation.height)/2;
1604 move(x, y); 1680 move(x, y);
1605 1681
1606 uint32 timestamp = event.get_time(); 1682 uint32 timestamp = event.get_time();
1607 present_with_time(timestamp); 1683 present_with_time(timestamp);
1608 m_entry.set_activates_default(true); 1684 m_entry.set_activates_default(true);
1609 } 1685 }
1610 1686
1611 1687
1688 #if ENABLE_HARFBUZZ_FOR_EMOJI
1689 private static void update_fontset(Pango.Language language) {
1690 if (m_fontset != null) {
1691 m_fontset.set_family(m_emoji_font_family);
1692 m_fontset.set_size(m_emoji_font_size);
1693 m_fontset.set_language(language.to_string());
1694 m_fontset.update_fcfontset();
1695 } else {
1696 m_fontset = new IBus.FontSet.with_font(
1697 m_emoji_font_family,
1698 m_emoji_font_size,
1699 language.to_string());
1700 }
1701 }
1702 #endif
1703
1612 public static bool has_loaded_emoji_dict() { 1704 public static bool has_loaded_emoji_dict() {
1613 if (m_emoji_to_data_dict == null) 1705 if (m_emoji_to_data_dict == null)
1614 return false; 1706 return false;
1615 GLib.List keys = m_emoji_to_data_dict.get_keys(); 1707 GLib.List keys = m_emoji_to_data_dict.get_keys();
1616 if (keys.length() == 0) 1708 if (keys.length() == 0)
1617 return false; 1709 return false;
1618 return true; 1710 return true;
1619 } 1711 }
1620 1712
1621 1713
(...skipping 10 matching lines...) Expand all
1632 public static void set_emoji_font(string? emoji_font) { 1724 public static void set_emoji_font(string? emoji_font) {
1633 return_if_fail(emoji_font != null && emoji_font != ""); 1725 return_if_fail(emoji_font != null && emoji_font != "");
1634 Pango.FontDescription font_desc = 1726 Pango.FontDescription font_desc =
1635 Pango.FontDescription.from_string(emoji_font); 1727 Pango.FontDescription.from_string(emoji_font);
1636 string font_family = font_desc.get_family(); 1728 string font_family = font_desc.get_family();
1637 if (font_family != null) 1729 if (font_family != null)
1638 m_emoji_font_family = font_family; 1730 m_emoji_font_family = font_family;
1639 int font_size = font_desc.get_size() / Pango.SCALE; 1731 int font_size = font_desc.get_size() / Pango.SCALE;
1640 if (font_size != 0) 1732 if (font_size != 0)
1641 m_emoji_font_size = font_size; 1733 m_emoji_font_size = font_size;
1734 #if ENABLE_HARFBUZZ_FOR_EMOJI
1735 var widget = new Gtk.Label("");
1736 update_fontset(widget.get_pango_context().get_language());
1737 #endif
1642 } 1738 }
1643 1739
1644 1740
1645 public static void set_partial_match(bool has_partial_match) { 1741 public static void set_partial_match(bool has_partial_match) {
1646 m_has_partial_match = has_partial_match; 1742 m_has_partial_match = has_partial_match;
1647 } 1743 }
1648 1744
1649 public static void set_partial_match_length(int length) { 1745 public static void set_partial_match_length(int length) {
1650 if (length < 1) 1746 if (length < 1)
1651 return; 1747 return;
(...skipping 18 matching lines...) Expand all
1670 m_favorites += favorite; 1766 m_favorites += favorite;
1671 } 1767 }
1672 for(int i = 0; i < unowned_favorite_annotations.length; i++) { 1768 for(int i = 0; i < unowned_favorite_annotations.length; i++) {
1673 string? favorite_annotation = unowned_favorite_annotations[i]; 1769 string? favorite_annotation = unowned_favorite_annotations[i];
1674 GLib.return_if_fail(favorite_annotation != null); 1770 GLib.return_if_fail(favorite_annotation != null);
1675 m_favorite_annotations += favorite_annotation; 1771 m_favorite_annotations += favorite_annotation;
1676 } 1772 }
1677 update_favorite_emoji_dict(); 1773 update_favorite_emoji_dict();
1678 } 1774 }
1679 } 1775 }
OLDNEW
« no previous file with comments | « ui/gtk3/Makefile.am ('k') | ui/gtk3/ibusfontset.h » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b