| 3112 | |
| 3113 | #if defined(HAVE_QT) && !defined(PREFER_LIBPNG_FOR_SAVE) |
| 3114 | void |
| 3115 | LayoutViewBase::save_image (const std::string &fn, unsigned int width, unsigned int height) |
| 3116 | { |
| 3117 | tl::SelfTimer timer (tl::verbosity () >= 11, tl::to_string (tr ("Save image"))); |
| 3118 | |
| 3119 | QImageWriter writer (tl::to_qstring (fn), QByteArray ("PNG")); |
| 3120 | |
| 3121 | lay::Viewport vp (width, height, mp_canvas->viewport ().target_box ()); |
| 3122 | std::vector<std::pair<std::string, std::string> > texts = png_texts (this, vp.box ()); |
| 3123 | for (auto i = texts.begin (); i != texts.end (); ++i) { |
| 3124 | writer.setText (tl::to_qstring (i->first), tl::to_qstring (i->second)); |
| 3125 | } |
| 3126 | |
| 3127 | refresh (); |
| 3128 | |
| 3129 | if (! writer.write (mp_canvas->image (width, height).to_image ())) { |
| 3130 | throw tl::Exception (tl::to_string (tr ("Unable to write screenshot to file: %s (%s)")), fn, tl::to_string (writer.errorString ())); |
| 3131 | } |
| 3132 | |
| 3133 | tl::log << "Saved image to " << fn; |
| 3134 | } |
| 3135 | #elif defined(HAVE_PNG) |
| 3136 | void |
| 3137 | LayoutViewBase::save_image (const std::string &fn, unsigned int width, unsigned int height) |