diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2016-02-03 15:20:52 +0100 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2016-02-03 15:31:56 +0100 |
commit | a1fa7643092ba2e1ee2cbe38392fba3d15c6718d (patch) | |
tree | 30c18a875c1d291dac0ff317083489b1b431a087 | |
parent | 45413d04eacfd9dc23904cb4893918309d3a6a36 (diff) | |
download | sciteco-a1fa7643092ba2e1ee2cbe38392fba3d15c6718d.tar.gz |
Gtk UI: automatically configure font of the command line
* This uses the font and size of STYLE_DEFAULT.
* We cannot just pass the font down to the user CSS.
There are no font variables in Gtk CSS.
Therefore we configure the command line widget directly.
This can still be overwritten by an user CSS.
* Instead of using the deprecated gtk_widget_modify_font(),
we generate CSS. Ugly, but still better than writing our
own style provider.
* Font setting is exposed to the user using a new optional
Q-Reg "lexer.font". The numeric part is the point size
multiplied with 100 (fractional point size).
* Font setting in lexer.auto is skipped in Curses
where it is irrelevant anyway to speed up startup.
* Perhaps the "Monospace" font name is also a good default
value instead of Courier?
fixup
-rw-r--r-- | lib/lexer.tes | 4 | ||||
-rw-r--r-- | sample.teco_ini | 4 | ||||
-rw-r--r-- | src/interface-gtk/interface-gtk.cpp | 40 | ||||
-rw-r--r-- | src/interface-gtk/interface-gtk.h | 2 |
4 files changed, 35 insertions, 15 deletions
diff --git a/lib/lexer.tes b/lib/lexer.tes index af89c0e..89a2fd5 100644 --- a/lib/lexer.tes +++ b/lib/lexer.tes @@ -8,6 +8,10 @@ } @[lexer.auto]{ + 0EJ-1"> :Q[lexer.font]"> + 32ESSTYLESETFONTQ[lexer.font] + Q[lexer.font],32ESSTYLESETSIZEFRACTIONAL + ' ' :M[color.init] [_ :Q*"= Oend ' diff --git a/sample.teco_ini b/sample.teco_ini index cddb939..cd2a6cf 100644 --- a/sample.teco_ini +++ b/sample.teco_ini @@ -39,6 +39,10 @@ EMQ[$SCITECOPATH]/session.tes !end!} 0,32ED +! Tweak the default font name and size. + The size unit is 1pt/100 ! +! [lexer.font]Monospace 1300U[lexer.font] ! + ! Uncomment to enable default keyboard macros and function keys ! ! EMQ[$SCITECOPATH]/fnkeys.tes ! diff --git a/src/interface-gtk/interface-gtk.cpp b/src/interface-gtk/interface-gtk.cpp index a2d2a1b..ca14f2f 100644 --- a/src/interface-gtk/interface-gtk.cpp +++ b/src/interface-gtk/interface-gtk.cpp @@ -258,7 +258,6 @@ InterfaceGtk::main_impl(int &argc, char **&argv) gtk_widget_set_name(cmdline_widget, "sciteco-cmdline"); gtk_entry_set_has_frame(GTK_ENTRY(cmdline_widget), FALSE); gtk_editable_set_editable(GTK_EDITABLE(cmdline_widget), FALSE); - widget_set_font(cmdline_widget, "Courier"); g_signal_connect(G_OBJECT(cmdline_widget), "key-press-event", G_CALLBACK(cmdline_key_pressed_cb), event_queue); gtk_box_pack_start(GTK_BOX(vbox), cmdline_widget, FALSE, FALSE, 0); @@ -513,21 +512,29 @@ InterfaceGtk::popup_clear_impl(void) } void -InterfaceGtk::widget_set_font(GtkWidget *widget, const gchar *font_name) -{ - PangoFontDescription *font_desc; - - font_desc = pango_font_description_from_string(font_name); - gtk_widget_modify_font(widget, font_desc); - pango_font_description_free(font_desc); -} - -void InterfaceGtk::set_css_variables_from_view(ViewGtk *view) { + guint font_size; gchar buffer[256]; /* + * Unfortunately, we cannot use CSS variables to pass around + * font names and sizes, necessary for styling the command line + * widget. + * Therefore we just style it using generated CSS here. + * This one of the few non-deprecated ways that Gtk leaves us + * to set a custom font name. + * CSS customizations have to take that into account. + * NOTE: We don't actually know apriori how + * large our buffer should be, but luckily STYLEGETFONT with + * a sptr==0 will return only the size. + * This is undocumented in the Scintilla docs. + */ + gchar font_name[view->ssm(SCI_STYLEGETFONT, STYLE_DEFAULT) + 1]; + view->ssm(SCI_STYLEGETFONT, STYLE_DEFAULT, (sptr_t)font_name); + font_size = view->ssm(SCI_STYLEGETSIZEFRACTIONAL, STYLE_DEFAULT); + + /* * Generates a CSS that sets some predefined color variables. * This effectively "exports" Scintilla styles into the CSS * world. @@ -540,11 +547,18 @@ InterfaceGtk::set_css_variables_from_view(ViewGtk *view) "@define-color sciteco_default_fg_color " CSS_COLOR_FORMAT ";" "@define-color sciteco_default_bg_color " CSS_COLOR_FORMAT ";" "@define-color sciteco_calltip_fg_color " CSS_COLOR_FORMAT ";" - "@define-color sciteco_calltip_bg_color " CSS_COLOR_FORMAT ";", + "@define-color sciteco_calltip_bg_color " CSS_COLOR_FORMAT ";" + "#%s{" + "font: %s %u.%u" + "}", bgr2rgb(view->ssm(SCI_STYLEGETFORE, STYLE_DEFAULT)), bgr2rgb(view->ssm(SCI_STYLEGETBACK, STYLE_DEFAULT)), bgr2rgb(view->ssm(SCI_STYLEGETFORE, STYLE_CALLTIP)), - bgr2rgb(view->ssm(SCI_STYLEGETBACK, STYLE_CALLTIP))); + bgr2rgb(view->ssm(SCI_STYLEGETBACK, STYLE_CALLTIP)), + gtk_widget_get_name(cmdline_widget), + font_name, + font_size / SC_FONT_SIZE_MULTIPLIER, + font_size % SC_FONT_SIZE_MULTIPLIER); /* * The GError and return value has been deprecated. diff --git a/src/interface-gtk/interface-gtk.h b/src/interface-gtk/interface-gtk.h index e43b7bf..7762ee4 100644 --- a/src/interface-gtk/interface-gtk.h +++ b/src/interface-gtk/interface-gtk.h @@ -168,8 +168,6 @@ public: void handle_key_press(bool is_shift, bool is_ctl, guint keyval); private: - static void widget_set_font(GtkWidget *widget, const gchar *font_name); - void set_css_variables_from_view(ViewGtk *view); void refresh_info(void); |