diff --git a/src/chat_control_base.py b/src/chat_control_base.py index d52ffb461..687819d28 100644 --- a/src/chat_control_base.py +++ b/src/chat_control_base.py @@ -343,8 +343,6 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools): self.msg_textview.drag_dest_set(Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT, self.dnd_list, Gdk.DragAction.COPY) - self.update_font() - # Hook up send button widget = self.xml.get_object('send_button') id_ = widget.connect('clicked', self._on_send_button_clicked) @@ -896,11 +894,6 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools): gtkgui_helpers.popup_emoticons_under_button(menu, widget, self.parent_win) - def update_font(self): - font = Pango.FontDescription(gajim.config.get('conversation_font')) - self.conv_textview.tv.override_font(font) - self.msg_textview.override_font(font) - def update_tags(self): self.conv_textview.update_tags() diff --git a/src/config.py b/src/config.py index 56f12448a..ae41646aa 100644 --- a/src/config.py +++ b/src/config.py @@ -881,14 +881,7 @@ class PreferencesWindow: else: font = '' gajim.config.set(text, font) - self.update_text_font() - - def update_text_font(self): - """ - Update text font in opened chat windows - """ - for ctrl in self._get_all_controls(): - ctrl.update_font() + gtkgui_helpers.load_css() def on_incoming_nick_colorbutton_color_set(self, widget): self.on_preference_widget_color_set(widget, 'inmsgcolor') diff --git a/src/conversation_textview.py b/src/conversation_textview.py index 065f59119..753d3c2d1 100644 --- a/src/conversation_textview.py +++ b/src/conversation_textview.py @@ -238,8 +238,8 @@ class ConversationTextview(GObject.GObject): self.change_cursor = False self.last_time_printout = 0 - font = Pango.FontDescription(gajim.config.get('conversation_font')) - self.tv.override_font(font) + style = self.tv.get_style_context() + style.add_class('font_custom') buffer_ = self.tv.get_buffer() end_iter = buffer_.get_end_iter() buffer_.create_mark('end', end_iter, False) diff --git a/src/gtkgui_helpers.py b/src/gtkgui_helpers.py index 19a2b7662..3771bfb91 100644 --- a/src/gtkgui_helpers.py +++ b/src/gtkgui_helpers.py @@ -1141,6 +1141,8 @@ def convert_config_to_css(): css += '.theme_{cls} {node} {{ {attr}: {color}; }}\n'.format( cls=key, node=node, attr=attr, color=value) + css += add_css_font() + return css def add_css_class(widget, class_name): @@ -1154,3 +1156,24 @@ def add_css_class(widget, class_name): def remove_css_class(widget, class_name): style = widget.get_style_context() style.remove_class('theme_' + class_name) + +def add_css_font(): + conversation_font = gajim.config.get('conversation_font') + if not conversation_font: + return '' + font = Pango.FontDescription(conversation_font) + unit = "pt" if Gtk.check_version(3, 22, 0) is None else "px" + css = """ + .font_custom {{ + font-family: {family}; + font-size: {size}{unit}; + font-weight: {weight}; + }}""".format( + family=font.get_family(), + size=int(round(font.get_size() / Pango.SCALE)), + unit=unit, + weight=int(font.get_weight())) + css = css.replace("font-size: 0{unit};".format(unit=unit), "") + css = css.replace("font-weight: 0;", "") + css = "\n".join(filter(lambda x: x.strip(), css.splitlines())) + return css