From 14588c1fc48ce1d67983a266e70c4894553bfae7 Mon Sep 17 00:00:00 2001 From: Melroy van den Berg Date: Thu, 3 Mar 2022 23:46:17 +0100 Subject: [PATCH] Use double for letter spacing --- src/mainwindow.cc | 18 ++++++++++++------ src/mainwindow.h | 2 +- src/schema/org.libreweb.browser.gschema.xml | 4 ++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/mainwindow.cc b/src/mainwindow.cc index 4240ec7..b401ea5 100644 --- a/src/mainwindow.cc +++ b/src/mainwindow.cc @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -32,7 +33,7 @@ MainWindow::MainWindow(const std::string& timeout) m_settings(), m_brightnessAdjustment(Gtk::Adjustment::create(1.0, 0.0, 1.0, 0.05, 0.1)), m_maxContentWidthAdjustment(Gtk::Adjustment::create(700, 0, 99999, 10, 20)), - m_spacingAdjustment(Gtk::Adjustment::create(0, -10, 10, 1, 2)), + m_spacingAdjustment(Gtk::Adjustment::create(0.0, -50.0, 50.0, 0.2, 0.1)), m_marginsAdjustment(Gtk::Adjustment::create(10, 0, 1000, 10, 20)), m_indentAdjustment(Gtk::Adjustment::create(0, 0, 1000, 5, 10)), m_drawCSSProvider(Gtk::CssProvider::create()), @@ -110,7 +111,7 @@ MainWindow::MainWindow(const std::string& timeout) positionDividerDraw_(-1), contentMargin_(20), contentMaxWidth_(700), - fontSpacing_(0), + fontSpacing_(0.0), indent_(0), wrapMode_(Gtk::WRAP_WORD_CHAR), brightnessScale_(1.0), @@ -378,7 +379,7 @@ void MainWindow::loadStoredSettings() m_fontButton.set_font_name(fontFamily_ + " " + std::to_string(currentFontSize_)); contentMaxWidth_ = m_settings->get_int("max-content-width"); - fontSpacing_ = m_settings->get_int("spacing"); + fontSpacing_ = m_settings->get_double("spacing"); contentMargin_ = m_settings->get_int("margins"); indent_ = m_settings->get_int("indent"); wrapMode_ = static_cast(m_settings->get_enum("wrap-mode")); @@ -841,6 +842,7 @@ void MainWindow::initSettingsPopover() m_wrapWordChar.set_tooltip_text("Word wrapping (+ character)"); m_maxContentWidthSpinButton.set_adjustment(m_maxContentWidthAdjustment); m_spacingSpinButton.set_adjustment(m_spacingAdjustment); + m_spacingSpinButton.set_digits(1); m_marginsSpinButton.set_adjustment(m_marginsAdjustment); m_indentSpinButton.set_adjustment(m_indentAdjustment); m_fontLabel.set_xalign(1); @@ -1091,7 +1093,7 @@ bool MainWindow::delete_window(GdkEventAny* any_event __attribute__((unused))) m_settings->set_string("font-family", fontFamily_); m_settings->set_int("font-size", currentFontSize_); m_settings->set_int("max-content-width", contentMaxWidth_); - m_settings->set_int("spacing", fontSpacing_); + m_settings->set_double("spacing", fontSpacing_); m_settings->set_int("margins", contentMargin_); m_settings->set_int("indent", indent_); m_settings->set_enum("wrap-mode", wrapMode_); @@ -2155,6 +2157,10 @@ void MainWindow::updateCSS() colorCss = "color: rgba(" + colorStr + ", " + colorStr + ", " + colorStr + ", " + darknessStr + ");"; } + std::stringstream streamFontSpacing; + streamFontSpacing << std::fixed << std::setprecision(1) << fontSpacing_; + std::string letterSpacing = streamFontSpacing.str(); + try { m_drawCSSProvider->load_from_data("textview { " @@ -2166,7 +2172,7 @@ void MainWindow::updateCSS() darknessStr + ");" "letter-spacing: " + - std::to_string(fontSpacing_) + "px; }"); + letterSpacing + "px; }"); } catch (const Gtk::CssProviderError& error) { @@ -2288,7 +2294,7 @@ void MainWindow::on_max_content_width_changed() void MainWindow::on_spacing_changed() { - fontSpacing_ = m_spacingSpinButton.get_value_as_int(); // Letter-spacing + fontSpacing_ = m_spacingSpinButton.get_value(); // Letter-spacing updateCSS(); } diff --git a/src/mainwindow.h b/src/mainwindow.h index 91832a6..1fe9ef6 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -308,7 +308,7 @@ private: int positionDividerDraw_; int contentMargin_; int contentMaxWidth_; - int fontSpacing_; + double fontSpacing_; int indent_; Gtk::WrapMode wrapMode_; double brightnessScale_; diff --git a/src/schema/org.libreweb.browser.gschema.xml b/src/schema/org.libreweb.browser.gschema.xml index 80b2876..cc8369a 100644 --- a/src/schema/org.libreweb.browser.gschema.xml +++ b/src/schema/org.libreweb.browser.gschema.xml @@ -43,8 +43,8 @@ 700 Max document content width - - 0 + + 0.0 Font spacing