Load default font during init

master
Melroy van den Berg 2021-08-26 17:37:28 +02:00
parent d39ebb51cd
commit f63f01614f
No known key found for this signature in database
GPG Key ID: 71D11FF23454B9D7
2 changed files with 20 additions and 15 deletions

View File

@ -73,6 +73,8 @@ MainWindow::MainWindow(const std::string &timeout)
// Add custom CSS Provider to draw textview
auto style = m_draw_main.get_style_context();
style->add_provider(m_mainDrawCSSProvider, GTK_STYLE_PROVIDER_PRIORITY_USER);
// Load the default font family and font size
updateMainCSS();
// Browser text main drawing area
m_scrolledWindowMain.add(m_draw_main);
@ -1738,6 +1740,18 @@ std::string MainWindow::getIconImageFromTheme(const std::string &iconName, const
}
}
/**
* Update the CSS provider data on the main draw text view
*/
void MainWindow::updateMainCSS()
{
m_mainDrawCSSProvider->load_from_data("textview { "
"font-family: \"" + m_fontFamily + "\";"
"font-size: " + std::to_string(m_fontSize) + "pt;"
"letter-spacing: " + std::to_string(m_fontSpacing) + "px;"
"}");
}
void MainWindow::editor_changed_text()
{
// Retrieve text from text editor
@ -1799,21 +1813,21 @@ void MainWindow::insert_emoji()
void MainWindow::on_zoom_out()
{
m_fontSize -= 2;
update_main_css_provider();
updateMainCSS();
m_zoomRestoreButton.set_sensitive(m_fontSize != DEFAULT_FONT_SIZE);
}
void MainWindow::on_zoom_restore()
{
m_fontSize = DEFAULT_FONT_SIZE; // reset
update_main_css_provider();
updateMainCSS();
m_zoomRestoreButton.set_sensitive(false);
}
void MainWindow::on_zoom_in()
{
m_fontSize += 2;
update_main_css_provider();
updateMainCSS();
m_zoomRestoreButton.set_sensitive(m_fontSize != DEFAULT_FONT_SIZE);
}
@ -1822,13 +1836,13 @@ void MainWindow::on_font_set()
Pango::FontDescription fontDesc = Pango::FontDescription(m_fontButton.get_font_name());
m_fontFamily = fontDesc.get_family();
m_fontSize = (fontDesc.get_size_is_absolute()) ? fontDesc.get_size() : fontDesc.get_size() / PANGO_SCALE;
update_main_css_provider();
updateMainCSS();
}
void MainWindow::on_spacing_changed()
{
m_fontSpacing = m_spacingSpinButton.get_value_as_int(); // Letter spacing
update_main_css_provider();
updateMainCSS();
}
void MainWindow::on_margins_changed()
@ -1841,12 +1855,3 @@ void MainWindow::on_indent_changed()
{
this->m_draw_main.set_indent(m_indentSpinButton.get_value_as_int());
}
void MainWindow::update_main_css_provider()
{
m_mainDrawCSSProvider->load_from_data("textview { "
"font-family: \"" + m_fontFamily + "\";"
"font-size: " + std::to_string(m_fontSize) + "pt;"
"letter-spacing: " + std::to_string(m_fontSpacing) + "px;"
"}");
}

View File

@ -89,7 +89,6 @@ protected:
void on_spacing_changed();
void on_margins_changed();
void on_indent_changed();
void update_main_css_provider();
Glib::RefPtr<Gtk::AccelGroup> m_accelGroup; /*!< Accelerator group, used for keyboard shortcut bindings */
Glib::RefPtr<Gio::Settings> m_settings; /*!< Settings to store our preferences, even during restarts */
@ -255,6 +254,7 @@ private:
void fetchFromIPFS(bool isParseContent);
void openFromDisk(bool isParseContent);
std::string getIconImageFromTheme(const std::string &iconName, const std::string &typeofIcon);
void updateMainCSS();
};
#endif