Merge branch 'demo-polish' into 'master'

Demo polish

See merge request GNOME/gtk!2420
This commit is contained in:
Matthias Clasen 2020-08-09 04:28:31 +00:00
commit 0f7b2159b6
3 changed files with 28 additions and 1 deletions

View File

@ -1,4 +1,3 @@
#include "config.h"
#include <gtk/gtk.h>

View File

@ -244,6 +244,23 @@ fontify_text (const char *format,
GBytes *stderr_buf = NULL;
GError *error = NULL;
char *format_arg;
GtkSettings *settings;
char *theme;
gboolean prefer_dark;
const char *style_arg;
settings = gtk_settings_get_default ();
g_object_get (settings,
"gtk-theme-name", &theme,
"gtk-application-prefer-dark-theme", &prefer_dark,
NULL);
if (prefer_dark || strcmp (theme, "HighContrastInverse") == 0)
style_arg = "--style=edit-vim-dark";
else
style_arg = "--style=edit-kwrite";
g_free (theme);
format_arg = g_strconcat ("--syntax=", format, NULL);
subprocess = g_subprocess_new (G_SUBPROCESS_FLAGS_STDIN_PIPE |
@ -253,6 +270,7 @@ fontify_text (const char *format,
"highlight",
format_arg,
"--out-format=pango",
style_arg,
NULL);
g_free (format_arg);
@ -328,8 +346,13 @@ fontify (const char *format,
{
char *markup;
gsize len;
char *p;
markup = g_bytes_unref_to_data (bytes, &len);
/* highlight puts a span with font and size around its output,
* which we don't want.
*/
for (p = markup + strlen ("<span "); *p != '>'; p++) *p = ' ';
gtk_text_buffer_delete (source_buffer, &start, &end);
gtk_text_buffer_insert_markup (source_buffer, &start, markup, len);
g_free (markup);
@ -379,6 +402,7 @@ display_text (const char *format,
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (textview), GTK_WRAP_WORD);
gtk_text_view_set_pixels_above_lines (GTK_TEXT_VIEW (textview), 2);
gtk_text_view_set_pixels_below_lines (GTK_TEXT_VIEW (textview), 2);
gtk_text_view_set_monospace (GTK_TEXT_VIEW (textview), TRUE);
buffer = gtk_text_buffer_new (NULL);
gtk_text_buffer_set_text (buffer, g_bytes_get_data (bytes, NULL), g_bytes_get_size (bytes));

View File

@ -134,6 +134,10 @@
<property name="bottom-margin">20</property>
<property name="editable">0</property>
<property name="cursor-visible">0</property>
<property name="monospace">1</property>
<property name="wrap-mode">word</property>
<property name="pixels-above-lines">2</property>
<property name="pixels-below-lines">2</property>
</object>
</child>
</object>