From cca66b9ec4e494c1d919bff0f71a820d8afab1fa Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:24:48 +0200 Subject: Adding upstream version 1.2.2. Signed-off-by: Daniel Baumann --- src/extension/internal/png-output.cpp | 106 ++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 src/extension/internal/png-output.cpp (limited to 'src/extension/internal/png-output.cpp') diff --git a/src/extension/internal/png-output.cpp b/src/extension/internal/png-output.cpp new file mode 100644 index 0000000..68841ef --- /dev/null +++ b/src/extension/internal/png-output.cpp @@ -0,0 +1,106 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * An internal raster export which passes the generated PNG output + * to an external file. In the future this module could host more of + * the PNG generation code that isn't needed for other raster export options. + * + * Authors: + * Martin Owens + * + * Copyright (C) 2021 Authors + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include "png-output.h" + +#include +#include +#include +#include +#include + +#include "clear-n_.h" + +namespace Inkscape { +namespace Extension { +namespace Internal { + +void PngOutput::export_raster(Inkscape::Extension::Output * /*module*/, + const SPDocument * /*doc*/, std::string const &png_file, gchar const *filename) +{ + // We want to move the png file to the new location + Glib::RefPtr input_fn = Gio::File::create_for_path(png_file); + Glib::RefPtr output_fn = Gio::File::create_for_path(filename); + try { + // This file must be copied because the permissions must be created + // based on it's target location and not the temp directory. + input_fn->copy(output_fn, Gio::FILE_COPY_OVERWRITE | Gio::FILE_COPY_TARGET_DEFAULT_PERMS); + } + catch (const Gio::Error& e) { + std::cerr << "Moving resource " << png_file + << " to " << filename + << " failed: " << e.what().raw() << std::endl; + } +} + +void PngOutput::init() +{ + // clang-format off + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Portable Network Graphic") "\n" + "" SP_MODULE_KEY_RASTER_PNG "\n" + "false" + "" + "" // First because it's the default option + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" // First because it's default (and broken) + "" + "" + "" + "" + "0.0" + "2" + "\n" + ".png\n" + "image/png\n" + "" N_("Portable Network Graphic (*.png)") "\n" + "" N_("Default raster graphic export") "\n" + "\n" + "", + new PngOutput()); + // clang-format on +} + +} // namespace Internal +} // namespace Extension +} // namespace Inkscape + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : -- cgit v1.2.3