[glom] utils_ui: Properly parse the pango font name.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] utils_ui: Properly parse the pango font name.
- Date: Mon, 16 May 2016 18:46:50 +0000 (UTC)
commit bc1c51d99e1f25c5d4004ed4659cacc47eb268a4
Author: Murray Cumming <murrayc murrayc com>
Date: Mon May 16 20:46:41 2016 +0200
utils_ui: Properly parse the pango font name.
glom/utils_ui.cc | 12 ++++++++++--
glom/utils_ui.h | 6 +++++-
2 files changed, 15 insertions(+), 3 deletions(-)
---
diff --git a/glom/utils_ui.cc b/glom/utils_ui.cc
index 4e008b9..fcf24d3 100644
--- a/glom/utils_ui.cc
+++ b/glom/utils_ui.cc
@@ -601,9 +601,17 @@ void UiUtils::container_remove_all(Gtk::Container& container)
}
}
-void UiUtils::load_font_into_css_provider(Gtk::Widget& widget, const Glib::ustring& font)
+void UiUtils::load_font_into_css_provider(Gtk::Widget& widget, const Glib::ustring& pango_font_name)
{
- const auto css = "* { font-family: " + font + "; }";
+ const Pango::FontDescription font_desc(pango_font_name);
+ const auto font_family = font_desc.get_family();
+ const auto font_size = font_desc.get_size();
+ const auto css =
+ "* {\n" +
+ (font_family.empty() ? "" : " font-family: " + font_desc.get_family() + ";\n") +
+ (font_size == 0 ? "" : " font-size: " + std::to_string(font_size / PANGO_SCALE) + "pt;\n") +
+ "}";
+
load_into_css_provider(widget, css);
}
diff --git a/glom/utils_ui.h b/glom/utils_ui.h
index cd514b4..1b383c2 100644
--- a/glom/utils_ui.h
+++ b/glom/utils_ui.h
@@ -108,7 +108,11 @@ void treeview_delete_all_columns(Gtk::TreeView* treeview);
void container_remove_all(Gtk::Container& container);
-void load_font_into_css_provider(Gtk::Widget& widget, const Glib::ustring& font);
+/**
+ * @param pango_font_name A font description in the syntax accepted by the Pango::FontDescription
constructor.
+ */
+void load_font_into_css_provider(Gtk::Widget& widget, const Glib::ustring& pango_font_name);
+
void load_color_into_css_provider(Gtk::Widget& widget, const Glib::ustring& color);
void load_background_color_into_css_provider(Gtk::Widget& widget, const Glib::ustring& color);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]