Skip to content

Commit 2ce3771

Browse files
authored
Merge pull request #188 from toolstack/fix-mono-zooming
Fix mono zooming
2 parents 1aef28a + e671977 commit 2ce3771

4 files changed

Lines changed: 54 additions & 16 deletions

File tree

data/app.metainfo.xml.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
<li>Fixed deleting notebooks when duplicates in the trash already exist</li>
3838
<li>Fixed zero size trash items not displaying</li>
3939
<li>Fixed crash when opening notes from the command line (or Gnome Search)</li>
40+
<li>Fixed zooming of monospace fonts</li>
4041
<li>Removed selection of the text in the rename box automatically</li>
4142
<li>Moved to Gnome 47 runtime (thanks @drpetrikov)</li>
4243
<li>Moved to newer Gnome widgets (thanks @turlegarden)</li>

src/application.vala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ Sunniva Løvstad
194194
<li>Fixed deleting notebooks when duplicates in the trash already exist</li>
195195
<li>Fixed zero size trash items not displaying</li>
196196
<li>Fixed crash when opening notes from the command line (or Gnome Search)</li>
197+
<li>Fixed zooming of monospace fonts</li>
197198
<li>Removed selection of the text in the rename box automatically</li>
198199
<li>Moved to Gnome 47 runtime (thanks @drpetrikov)</li>
199200
<li>Moved to newer Gnome widgets (thanks @turlegarden)</li>

src/ui/edit_view/edit_view.vala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,14 @@ public class Folio.EditView : Gtk.Box {
164164
scrolled_window.get_vscrollbar ().margin_top = 48;
165165

166166
settings.bind ("toolbar-enabled", this, "toolbar-enabled", SettingsBindFlags.DEFAULT);
167-
settings.bind ("note-font-monospace", markdown_view, "font-monospace", SettingsBindFlags.DEFAULT);
168167
settings.bind ("url-detection-level", markdown_view, "url-detection-level", SettingsBindFlags.DEFAULT);
169168
settings.changed["note-font"].connect(() => set_note_font (settings.get_string ("note-font"), settings.get_string ("line-spacing")));
170169
settings.changed["line-spacing"].connect(() => set_note_font (settings.get_string ("note-font"), settings.get_string ("line-spacing")));
171170
settings.changed["note-max-width"].connect(() => set_max_width (settings.get_int ("note-max-width")));
172171

173172
var window_state = new Settings (@"$(Config.APP_ID).WindowState");
173+
var prefs_scale = window_state.get_int ("text-scale");
174+
scale = prefs_scale;
174175
window_state.bind ("text-scale", this, "scale", SettingsBindFlags.DEFAULT);
175176

176177
notify["toolbar-enabled"].connect (update_toolbar_visibility);
@@ -400,6 +401,7 @@ public class Folio.EditView : Gtk.Box {
400401
public void set_font_scale () {
401402
font_scale_provider.load_from_string (@"textview{font-size:$(scale / 100f)em;}");
402403
markdown_view.get_style_context ().add_provider (font_scale_provider, -1);
404+
markdown_view.scale = scale;
403405
}
404406

405407
private void set_note_font (string font, string line_spacing) {

src/ui/widgets/markdown/markdown_view.vala

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ public class GtkMarkdown.View : GtkSource.View {
88
public string font_monospace { get; set; default = "Monospace 10"; }
99
public int url_detection_level { get; set; default = 0; }
1010

11+
private int base_font_monospace_size { get; set; default = 10; }
12+
13+
public int scale { get; set; default = 100; }
14+
1115
public Gdk.RGBA h6_color {
1216
get {
1317
var rgba = get_color ();
@@ -439,24 +443,32 @@ public class GtkMarkdown.View : GtkSource.View {
439443
}
440444
}
441445

446+
var settings = new Settings (Config.APP_ID);
447+
var prefs_font_monospace = settings.get_string ("note-font-monospace");
448+
if (prefs_font_monospace != font_monospace) {
449+
font_monospace = prefs_font_monospace;
450+
}
451+
452+
settings.changed["note-font-monospace"].connect(() => change_font ());
453+
454+
var window_state = new Settings (@"$(Config.APP_ID).WindowState");
455+
var prefs_scale = window_state.get_int ("text-scale");
456+
457+
scale = prefs_scale;
458+
442459
notify["dark"].connect ((s, p) => update_color_scheme ());
443460
notify["theme-color"].connect ((s, p) => update_color_scheme ());
444461
notify["font-monospace"].connect ((s, p) => update_font ());
445462
notify["url-detection-level"].connect ((s, p) => update_url_detection ());
446463

447464
var font_desc = Pango.FontDescription.from_string (font_monospace);
448-
var font_size = font_desc.get_size ();
449-
if (!font_desc.get_size_is_absolute ()) {
450-
font_size = font_size / Pango.SCALE;
451-
}
452-
if (font_size < 3) {
453-
font_desc.set_size (10 * Pango.SCALE);
454-
font_monospace = font_desc.to_string ();
455-
}
465+
base_font_monospace_size = font_desc.get_size ();
456466

457467
update_color_scheme ();
458468
update_font ();
459469

470+
notify["scale"].connect(update_scale);
471+
460472
{
461473
var gutter = get_gutter (Gtk.TextWindowType.LEFT);
462474
renderer = new GtkSource.GutterRendererText ();
@@ -608,17 +620,39 @@ public class GtkMarkdown.View : GtkSource.View {
608620
}
609621
}
610622

611-
private void update_font () {
612-
var font_desc = Pango.FontDescription.from_string (font_monospace);
613-
var font_size = font_desc.get_size ();
623+
private int calculate_scaled_font_size (Pango.FontDescription font_desc) {
624+
var font_size = base_font_monospace_size;
625+
614626
if (!font_desc.get_size_is_absolute ()) {
615-
font_size = font_size / Pango.SCALE;
627+
font_size = ((font_size / Pango.SCALE) * scale ) / 100;
616628
}
617-
if (font_size < 3) {
618-
font_desc.set_size (10 * Pango.SCALE);
619-
font_monospace = font_desc.to_string ();
629+
630+
if (font_size < 4) { font_size = 4; }
631+
632+
return font_size;
633+
}
634+
635+
private void update_scale () {
636+
var font_desc = Pango.FontDescription.from_string (font_monospace);
637+
var font_size = calculate_scaled_font_size (font_desc);
638+
639+
font_desc.set_size (font_size * Pango.SCALE);
640+
font_monospace = font_desc.to_string ();
641+
}
642+
643+
private void change_font () {
644+
var settings = new Settings (Config.APP_ID);
645+
var prefs_font_monospace = settings.get_string ("note-font-monospace");
646+
if (prefs_font_monospace != font_monospace) {
647+
font_monospace = prefs_font_monospace;
620648
}
621649

650+
update_font ();
651+
}
652+
653+
private void update_font () {
654+
update_scale ();
655+
622656
text_tag_around = get_or_create_tag ("markdown-code-block-around");
623657
text_tag_around.font = font_monospace;
624658

0 commit comments

Comments
 (0)