Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions data/io.elementary.code.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@
<summary>Remember the last focused document.</summary>
<description>Restore the focused document from a previous session when opening Code.</description>
</key>
<key name="embolden-highcontrast" type="b">
<default>true</default>
<summary>Embolden the high contrast theme</summary>
<description>Always use bold font when using the high contrast style scheme</description>
</key>
<key name="active-project-path" type="s">
<default>''</default>
<summary>The active project path.</summary>
Expand Down
4 changes: 2 additions & 2 deletions src/Utils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down
27 changes: 26 additions & 1 deletion src/Widgets/HeaderBar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -277,13 +288,27 @@ 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,
"active",
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")) {
Expand Down
28 changes: 14 additions & 14 deletions src/Widgets/SourceView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -270,24 +270,36 @@ 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);
} else {
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),
"}"
);

Expand All @@ -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);
}
Expand Down
Loading