From d9b0d24dc724720e37ab4a8d10cbb9258e7539cb Mon Sep 17 00:00:00 2001 From: Kasper Peeters Date: Fri, 14 Jun 2024 18:48:35 +0100 Subject: [PATCH] Scale ImageViews depending on display scale. --- frontend/common/TeXEngine.cc | 5 +++++ frontend/common/TeXEngine.hh | 1 + frontend/gtkmm/ImageView.cc | 4 ++-- frontend/gtkmm/NotebookWindow.cc | 24 ++++++++++++------------ frontend/gtkmm/TeXView.cc | 2 +- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/frontend/common/TeXEngine.cc b/frontend/common/TeXEngine.cc index 68e01b87a1..6911f7e7fc 100644 --- a/frontend/common/TeXEngine.cc +++ b/frontend/common/TeXEngine.cc @@ -257,6 +257,11 @@ double TeXEngine::get_scale() const return total_scale_; } +double TeXEngine::get_device_scale() const + { + return device_scale_; + } + TeXEngine::TeXRequest::TeXRequest() : needs_generating(true) { diff --git a/frontend/common/TeXEngine.hh b/frontend/common/TeXEngine.hh index a40cd37d71..c5d3f01bd8 100644 --- a/frontend/common/TeXEngine.hh +++ b/frontend/common/TeXEngine.hh @@ -64,6 +64,7 @@ namespace cadabra { // bitmaps at the width times this size. void set_scale(double total_scale, double device_scale); double get_scale() const; + double get_device_scale() const; void set_font_size(int font_size); int get_font_size() const; std::vector latex_packages; diff --git a/frontend/gtkmm/ImageView.cc b/frontend/gtkmm/ImageView.cc index f1c2d9d89c..1f7355ee19 100644 --- a/frontend/gtkmm/ImageView.cc +++ b/frontend/gtkmm/ImageView.cc @@ -72,7 +72,7 @@ void ImageView::set_image_from_base64(const std::string& b64) std::string dec=Glib::Base64::decode(b64); str->add_data(dec.c_str(), dec.size()); - pixbuf = Gdk::Pixbuf::create_from_stream_at_scale(str, 400, -1, true); + pixbuf = Gdk::Pixbuf::create_from_stream_at_scale(str, 400*scale, -1, true); if(!pixbuf) std::cerr << "cadabra-client: unable to create image from data" << std::endl; else { @@ -86,7 +86,7 @@ void ImageView::set_image_from_svg(const std::string& svg) auto str = Gio::MemoryInputStream::create(); std::string dec=Glib::Base64::decode(svg); str->add_data(dec.c_str(), dec.size()); - pixbuf = Gdk::Pixbuf::create_from_stream_at_scale(str, 400, -1, true); + pixbuf = Gdk::Pixbuf::create_from_stream_at_scale(str, 400*scale, -1, true); if(!pixbuf) std::cerr << "cadabra-client: unable to create image from svg data" << std::endl; else { diff --git a/frontend/gtkmm/NotebookWindow.cc b/frontend/gtkmm/NotebookWindow.cc index de51a561b8..e8833f2282 100644 --- a/frontend/gtkmm/NotebookWindow.cc +++ b/frontend/gtkmm/NotebookWindow.cc @@ -606,7 +606,7 @@ NotebookWindow::NotebookWindow(Cadabra *c, bool ro) // Setup the toolbar and buttons in it. if(!read_only) { - toolbar.set_size_request(-1, 70/scale); + toolbar.set_size_request(-1, 70/display_scale); tool_stop.add(*Gtk::make_managed( get_icon(install_prefix()+"/share/cadabra2/cdb-icons/cdb-cancel.svg"))); tool_run.add(*Gtk::make_managed( @@ -619,12 +619,12 @@ NotebookWindow::NotebookWindow(Cadabra *c, bool ro) get_icon(install_prefix()+"/share/cadabra2/cdb-icons/cdb-save.svg"))); tool_save_as.add(*Gtk::make_managed( get_icon(install_prefix()+"/share/cadabra2/cdb-icons/cdb-save-as.svg"))); - tool_stop.set_size_request(70/scale, 70/scale); - tool_run.set_size_request(70/scale, 70/scale); - tool_restart.set_size_request(70/scale, 70/scale); - tool_open.set_size_request(70/scale, 70/scale); - tool_save.set_size_request(70/scale, 70/scale); - tool_save_as.set_size_request(70/scale, 70/scale); + tool_stop.set_size_request(70/display_scale, 70/display_scale); + tool_run.set_size_request(70/display_scale, 70/display_scale); + tool_restart.set_size_request(70/display_scale, 70/display_scale); + tool_open.set_size_request(70/display_scale, 70/display_scale); + tool_save.set_size_request(70/display_scale, 70/display_scale); + tool_save_as.set_size_request(70/display_scale, 70/display_scale); tool_run.set_tooltip_text("Execute all cells"); tool_stop.set_tooltip_text("Stop execution"); tool_restart.set_tooltip_text("Restart kernel"); @@ -641,8 +641,8 @@ NotebookWindow::NotebookWindow(Cadabra *c, bool ro) toolbar.pack_start(tool_restart, Gtk::PACK_SHRINK); toolbar.pack_start(top_label); toolbar.pack_end(kernel_spinner, Gtk::PACK_SHRINK); - kernel_spinner.set_size_request(50/scale, 50/scale); - kernel_spinner.set_margin_end(10/scale); + kernel_spinner.set_size_request(50/display_scale, 50/display_scale); + kernel_spinner.set_margin_end(10/display_scale); } // Normally we would use 'set_action_name' to associate the @@ -675,7 +675,7 @@ NotebookWindow::NotebookWindow(Cadabra *c, bool ro) // Status bar kernel_label.set_text("Server: not connected"); - statusbarbox.set_size_request(-1,50/scale); + statusbarbox.set_size_request(-1,50/display_scale); statusbarbox.set_homogeneous(false); statusbarbox.pack_start(status_label, false, false, 0); statusbarbox.pack_start(kernel_label, false, false, 0); @@ -1260,7 +1260,7 @@ void NotebookWindow::add_cell(const DTree& tr, DTree::iterator it, bool visible) } case DataCell::CellType::image_png: { // FIXME: horribly memory inefficient - ImageView *iv=new ImageView(display_scale); + ImageView *iv=new ImageView(scale/display_scale); iv->set_image_from_base64(it->textbuf); newcell.imagebox = manage( iv ); @@ -1269,7 +1269,7 @@ void NotebookWindow::add_cell(const DTree& tr, DTree::iterator it, bool visible) } case DataCell::CellType::image_svg: { // FIXME: horribly memory inefficient - ImageView *iv=new ImageView(display_scale); + ImageView *iv=new ImageView(scale/display_scale); iv->set_image_from_svg(it->textbuf); newcell.imagebox = manage( iv ); diff --git a/frontend/gtkmm/TeXView.cc b/frontend/gtkmm/TeXView.cc index d6dc7bbccf..98670ac567 100644 --- a/frontend/gtkmm/TeXView.cc +++ b/frontend/gtkmm/TeXView.cc @@ -64,7 +64,7 @@ float TeXView::text_size() const // FIXME: we used to multiply with engine.get_scale() but that seems // wrong. - float ret = 28.0f/12.0f*engine.get_font_size()/1.7f; + float ret = 28.0f/12.0f*engine.get_font_size()*engine.get_scale()/engine.get_device_scale()/1.7f; // std::cerr << "engine.font_size = " << engine.get_font_size() << ", .scale = " << engine.get_scale() // << ", text_size = " << ret << std::endl; return ret;