From d82f7c5b1e00aa9af4a5ae03b92b064dfb4a86fa Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Mon, 20 Mar 2023 15:52:15 +0200 Subject: [PATCH] Add command-line flag (etc.) for setting PNG antialias level when exporting --- src/actions/actions-output.cpp | 13 ++++++++++++- src/inkscape-application.cpp | 15 ++++++++++++++- src/io/file-export-cmd.cpp | 23 ++++++++++++++++++++--- src/io/file-export-cmd.h | 1 + 4 files changed, 47 insertions(+), 5 deletions(-) diff --git a/src/actions/actions-output.cpp b/src/actions/actions-output.cpp index 7ee320f546..ec3ccf23c8 100644 --- a/src/actions/actions-output.cpp +++ b/src/actions/actions-output.cpp @@ -216,6 +216,14 @@ export_png_use_dithering(const Glib::VariantBase& value, InkscapeApplication *a // std::cout << s.get() << std::endl; } +void +export_png_antialias(const Glib::VariantBase& value, InkscapeApplication *app) +{ + Glib::Variant i = Glib::VariantBase::cast_dynamic >(value); + app->file_export()->export_png_antialias = i.get(); + // std::cout << s.get() << std::endl; +} + void export_do(InkscapeApplication *app) { @@ -261,6 +269,7 @@ std::vector> raw_data_output = {"app.export-background-opacity", N_("Export Background Opacity"), "Export", N_("Include background opacity in exported file") }, {"app.export-png-color-mode", N_("Export PNG Color Mode"), "Export", N_("Set color mode for PNG export") }, {"app.export-png-use-dithering", N_("Export PNG Dithering"), "Export", N_("Set dithering for PNG export") }, + {"app.export-png-antialias", N_("Export PNG Antialias"), "Export", N_("Set antialias for PNG export") }, {"app.export-do", N_("Do Export"), "Export", N_("Do export") } // clang-format on @@ -295,7 +304,8 @@ std::vector> hint_data_output = {"app.export-background", N_("Enter string for background color, e.g. #ff007f or rgb(255, 0, 128)") }, {"app.export-background-opacity", N_("Enter number for background opacity, either between 0.0 and 1.0, or 1 up to 255") }, {"app.export-png-color-mode", N_("Enter string for PNG Color Mode, one of Gray_1/Gray_2/Gray_4/Gray_8/Gray_16/RGB_8/RGB_16/GrayAlpha_8/GrayAlpha_16/RGBA_8/RGBA_16")}, - {"app.export-png-use-dithering", N_("Enter 1/0 for Yes/No to use dithering") } + {"app.export-png-use-dithering", N_("Enter 1/0 for Yes/No to use dithering") }, + {"app.export-png-antialias", N_("Enter integer for PNG antialias mode")} // clang-format on }; @@ -342,6 +352,7 @@ add_actions_output(InkscapeApplication* app) gapp->add_action_with_parameter( "export-background-opacity",Double, sigc::bind(sigc::ptr_fun(&export_background_opacity), app)); gapp->add_action_with_parameter( "export-png-color-mode", String, sigc::bind(sigc::ptr_fun(&export_png_color_mode), app)); gapp->add_action_with_parameter( "export-png-use-dithering", Bool, sigc::bind(sigc::ptr_fun(&export_png_use_dithering), app)); + gapp->add_action_with_parameter( "export-png-antialias", Int, sigc::bind(sigc::ptr_fun(&export_png_antialias), app)); // Extra gapp->add_action( "export-do", sigc::bind(sigc::ptr_fun(&export_do), app)); diff --git a/src/inkscape-application.cpp b/src/inkscape-application.cpp index 6a9347c949..e155e23145 100644 --- a/src/inkscape-application.cpp +++ b/src/inkscape-application.cpp @@ -772,6 +772,7 @@ InkscapeApplication::InkscapeApplication() gapp->add_main_option_entry(T::OPTION_TYPE_STRING, "export-background-opacity", 'y', N_("Background opacity for exported bitmaps (0.0 to 1.0, or 1 to 255)"), N_("VALUE")); // Bxx gapp->add_main_option_entry(T::OPTION_TYPE_STRING, "export-png-color-mode", '\0', N_("Color mode (bit depth and color type) for exported bitmaps (Gray_1/Gray_2/Gray_4/Gray_8/Gray_16/RGB_8/RGB_16/GrayAlpha_8/GrayAlpha_16/RGBA_8/RGBA_16)"), N_("COLOR-MODE")); // Bxx gapp->add_main_option_entry(T::OPTION_TYPE_STRING, "export-png-use-dithering", '\0', N_("Force dithering or disables it"), "false|true"); // Bxx + gapp->add_main_option_entry(T::OPTION_TYPE_INT, "export-png-antialias", '\0', N_("Set PNG antialiasing level"), N_("LEVEL")); // xxP // Query - Geometry _start_main_option_section(_("Query object/document geometry")); @@ -1791,7 +1792,19 @@ InkscapeApplication::on_handle_local_options(const Glib::RefPtrgetBool("/options/dithering/value", true); + } else { + _file_export.export_png_use_dithering = prefs->getBool("/options/dithering/value", true); + } + + if (options->contains("export-png-antialias")) { + Glib::ustring val; + options->lookup_value("export-png-antialias", val); + _file.export_png_antialias = Glib::Ascii::strtod(val); + } else { + // Default to 2 (default value for sp_export_png_file) + _file_export.export_png_antialias = 2; + } + if (use_active_window) { _gio_application->register_application(); if (!_gio_application->get_default()->is_remote()) { diff --git a/src/io/file-export-cmd.cpp b/src/io/file-export-cmd.cpp index 113985c024..c3bb3f4282 100644 --- a/src/io/file-export-cmd.cpp +++ b/src/io/file-export-cmd.cpp @@ -72,6 +72,7 @@ InkFileExportCmd::InkFileExportCmd() , export_id_only(false) , export_background_opacity(-1) // default is unset != actively set to 0 , export_plain_svg(false) + , export_png_antialias(2) // default from sp_export_png_file { } @@ -772,9 +773,25 @@ InkFileExportCmd::do_export_png_now(SPDocument *doc, std::string const &filename << width << " x " << height << " pixels (" << dpi << " dpi)" << std::endl; #endif - if( sp_export_png_file(doc, filename_out.c_str(), area, width, height, xdpi, ydpi, - bgcolor, nullptr, nullptr, true, export_id_only ? items : std::vector(), - false, color_type, bit_depth) == 1 ) { + if( sp_export_png_file( + doc, + filename_out.c_str(), + area, + width, + height, + xdpi, + ydpi, + bgcolor, + nullptr, // status callback + nullptr, // status callback data + true, // force overwrite + export_id_only ? items : std::vector(), + false, // interlace + color_type, + bit_depth, + 6, // zlib level + export_png_antialias, + ) == 1 ) { } else { std::cerr << "InkFileExport::do_export_png: Failed to export to " << filename_out << std::endl; } diff --git a/src/io/file-export-cmd.h b/src/io/file-export-cmd.h index d0acbe91ec..40d5246db0 100644 --- a/src/io/file-export-cmd.h +++ b/src/io/file-export-cmd.h @@ -78,6 +78,7 @@ public: Glib::ustring export_png_color_mode; bool export_plain_svg; bool export_png_use_dithering; + int export_png_antialias; }; #endif // INK_FILE_EXPORT_CMD_H -- GitLab