| 3160 | |
| 3161 | #if defined(HAVE_QT) && !defined(PREFER_LIBPNG_FOR_SAVE) |
| 3162 | void |
| 3163 | LayoutViewBase::save_image_with_options (const std::string &fn, |
| 3164 | unsigned int width, unsigned int height, int linewidth, int oversampling, double resolution, double font_resolution, |
| 3165 | tl::Color background, tl::Color foreground, tl::Color active, const db::DBox &target_box, bool monochrome) |
| 3166 | { |
| 3167 | tl::SelfTimer timer (tl::verbosity () >= 11, tl::to_string (tr ("Save image"))); |
| 3168 | |
| 3169 | QImageWriter writer (tl::to_qstring (fn), QByteArray ("PNG")); |
| 3170 | |
| 3171 | lay::Viewport vp (width, height, mp_canvas->viewport ().target_box ()); |
| 3172 | std::vector<std::pair<std::string, std::string> > texts = png_texts (this, vp.box ()); |
| 3173 | for (auto i = texts.begin (); i != texts.end (); ++i) { |
| 3174 | writer.setText (tl::to_qstring (i->first), tl::to_qstring (i->second)); |
| 3175 | } |
| 3176 | |
| 3177 | refresh (); |
| 3178 | |
| 3179 | if (monochrome) { |
| 3180 | if (! writer.write (mp_canvas->image_with_options_mono (width, height, linewidth, background, foreground, active, target_box).to_image ())) { |
| 3181 | throw tl::Exception (tl::to_string (tr ("Unable to write screenshot to file: %s (%s)")), fn, tl::to_string (writer.errorString ())); |
| 3182 | } |
| 3183 | } else { |
| 3184 | if (! writer.write (mp_canvas->image_with_options (width, height, linewidth, oversampling, resolution, font_resolution, background, foreground, active, target_box).to_image ())) { |
| 3185 | throw tl::Exception (tl::to_string (tr ("Unable to write screenshot to file: %s (%s)")), fn, tl::to_string (writer.errorString ())); |
| 3186 | } |
| 3187 | } |
| 3188 | |
| 3189 | tl::log << "Saved image to " << fn; |
| 3190 | } |
| 3191 | #elif defined(HAVE_PNG) |
| 3192 | void |
| 3193 | LayoutViewBase::save_image_with_options (const std::string &fn, |
no test coverage detected