diff --git a/data/io.elementary.code.gschema.xml b/data/io.elementary.code.gschema.xml
index 185986686..114d4e10b 100644
--- a/data/io.elementary.code.gschema.xml
+++ b/data/io.elementary.code.gschema.xml
@@ -157,6 +157,11 @@
Remember the last focused document.
Restore the focused document from a previous session when opening Code.
+
+ true
+ Embolden the high contrast theme
+ Always use bold font when using the high contrast style scheme
+
''
The active project path.
diff --git a/src/Utils.vala b/src/Utils.vala
index 54f9c20a4..b59368152 100644
--- a/src/Utils.vala
+++ b/src/Utils.vala
@@ -29,7 +29,7 @@ namespace Scratch.Utils {
/* Ported (with corrections and improvements) from libdazzle
* (https://gitlab.gnome.org/GNOME/libdazzle/-/blob/master/src/util/dzl-pango.c)
*/
- public string pango_font_description_to_css (Pango.FontDescription font_descr) {
+ public string pango_font_description_to_css (Pango.FontDescription font_descr, bool embolden = false) {
var sb = new StringBuilder ("");
var mask = font_descr.get_set_fields ();
if (Pango.FontMask.FAMILY in mask) {
@@ -75,7 +75,7 @@ namespace Scratch.Utils {
}
if (Pango.FontMask.WEIGHT in mask) {
- var weight = ((int)(font_descr.get_weight () / 100 * 100)).clamp (100, 900);
+ var weight = ((int)((font_descr.get_weight () + (embolden ? 500 : 0)) / 100 * 100)).clamp (100, 900);
sb.append_printf ("font-weight: %i;", weight);
}
diff --git a/src/Widgets/HeaderBar.vala b/src/Widgets/HeaderBar.vala
index 9f95e1368..00a018197 100644
--- a/src/Widgets/HeaderBar.vala
+++ b/src/Widgets/HeaderBar.vala
@@ -164,6 +164,13 @@ public class Scratch.HeaderBar : Hdy.HeaderBar {
};
style_color_button (color_button_dark, STYLE_SCHEME_DARK);
+ var embolden_switch = new Granite.SwitchModelButton (_("Use Bold Font")) {
+ margin_bottom = 6
+ };
+
+ var embolden_revealer = new Gtk.Revealer ();
+ embolden_revealer.add (embolden_switch);
+
var color_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 3) {
homogeneous = true,
margin_top = 6,
@@ -173,8 +180,12 @@ public class Scratch.HeaderBar : Hdy.HeaderBar {
color_box.add (color_button_light);
color_box.add (color_button_dark);
+ var theme_box = new Gtk.Box (VERTICAL, 0);
+ theme_box.add (color_box);
+ theme_box.add (embolden_revealer);
+
var color_revealer = new Gtk.Revealer ();
- color_revealer.add (color_box);
+ color_revealer.add (theme_box);
var menu_separator = new Gtk.Separator (Gtk.Orientation.HORIZONTAL) {
margin_bottom = 3,
@@ -277,6 +288,13 @@ public class Scratch.HeaderBar : Hdy.HeaderBar {
GLib.BindingFlags.SYNC_CREATE | BindingFlags.INVERT_BOOLEAN
);
+ color_button_white.bind_property (
+ "active",
+ embolden_revealer,
+ "reveal-child",
+ SYNC_CREATE
+ );
+
Scratch.settings.bind (
"follow-system-style",
follow_system_switchmodelbutton,
@@ -284,6 +302,13 @@ public class Scratch.HeaderBar : Hdy.HeaderBar {
SettingsBindFlags.DEFAULT
);
+ Scratch.settings.bind (
+ "embolden-highcontrast",
+ embolden_switch,
+ "active",
+ SettingsBindFlags.DEFAULT
+ );
+
var gtk_settings = Gtk.Settings.get_default ();
switch (Scratch.settings.get_string ("style-scheme")) {
diff --git a/src/Widgets/SourceView.vala b/src/Widgets/SourceView.vala
index d85e048e2..fb81dfb83 100644
--- a/src/Widgets/SourceView.vala
+++ b/src/Widgets/SourceView.vala
@@ -270,7 +270,6 @@ namespace Scratch.Widgets {
space_drawer.enable_matrix = true;
update_draw_spaces ();
-
tab_width = (uint) Scratch.settings.get_int ("indent-width");
if (Scratch.settings.get_boolean ("line-wrap")) {
set_wrap_mode (Gtk.WrapMode.WORD);
@@ -278,16 +277,29 @@ namespace Scratch.Widgets {
set_wrap_mode (Gtk.WrapMode.NONE);
}
+ if (settings.get_boolean ("follow-system-style")) {
+ var system_prefers_dark = Granite.Settings.get_default ().prefers_color_scheme == Granite.Settings.ColorScheme.DARK;
+ if (system_prefers_dark) {
+ source_buffer.style_scheme = style_scheme_manager.get_scheme ("elementary-dark");
+ } else {
+ source_buffer.style_scheme = style_scheme_manager.get_scheme ("elementary-light");
+ }
+ } else {
+ var scheme = style_scheme_manager.get_scheme (Scratch.settings.get_string ("style-scheme"));
+ source_buffer.style_scheme = scheme ?? style_scheme_manager.get_scheme ("elementary-highcontrast-light");
+ }
+
if (Scratch.settings.get_boolean ("use-system-font")) {
font = ((Scratch.Application) GLib.Application.get_default ()).default_font;
} else {
font = Scratch.settings.get_string ("font");
}
+ var embolden = Scratch.settings.get_boolean ("embolden-highcontrast") && source_buffer.style_scheme.id == "elementary-highcontrast-light";
/* Convert font description to css equivalent and apply to the .view node */
var font_css = string.join (" ",
".view {",
- Scratch.Utils.pango_font_description_to_css (Pango.FontDescription.from_string (font)),
+ Scratch.Utils.pango_font_description_to_css (Pango.FontDescription.from_string (font), embolden),
"}"
);
@@ -297,18 +309,6 @@ namespace Scratch.Widgets {
critical (e.message);
}
- if (settings.get_boolean ("follow-system-style")) {
- var system_prefers_dark = Granite.Settings.get_default ().prefers_color_scheme == Granite.Settings.ColorScheme.DARK;
- if (system_prefers_dark) {
- source_buffer.style_scheme = style_scheme_manager.get_scheme ("elementary-dark");
- } else {
- source_buffer.style_scheme = style_scheme_manager.get_scheme ("elementary-light");
- }
- } else {
- var scheme = style_scheme_manager.get_scheme (Scratch.settings.get_string ("style-scheme"));
- source_buffer.style_scheme = scheme ?? style_scheme_manager.get_scheme ("elementary-highcontrast-light");
- }
-
git_diff_gutter_renderer.set_style_scheme (source_buffer.style_scheme);
style_changed (source_buffer.style_scheme);
}