Skip to content

Commit

Permalink
Scale ImageViews depending on display scale.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kasper Peeters committed Jun 14, 2024
1 parent 8e6541c commit d9b0d24
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
5 changes: 5 additions & 0 deletions frontend/common/TeXEngine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions frontend/common/TeXEngine.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> latex_packages;
Expand Down
4 changes: 2 additions & 2 deletions frontend/gtkmm/ImageView.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
24 changes: 12 additions & 12 deletions frontend/gtkmm/NotebookWindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<Gtk::Image>(
get_icon(install_prefix()+"/share/cadabra2/cdb-icons/cdb-cancel.svg")));
tool_run.add(*Gtk::make_managed<Gtk::Image>(
Expand All @@ -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<Gtk::Image>(
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");
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 );
Expand All @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion frontend/gtkmm/TeXView.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d9b0d24

Please sign in to comment.