From 75a1178a4432a502919596a0f62ad4e2f03410a5 Mon Sep 17 00:00:00 2001 From: Phil Hart Date: Thu, 17 Apr 2025 07:07:44 +0000 Subject: [PATCH] Where the user specifies --export-dpi in a command line along with one or both of --export-width or --export-height, set this value into the pHYs chunk of the PNG file. --- src/io/file-export-cmd.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/io/file-export-cmd.cpp b/src/io/file-export-cmd.cpp index 04e6928d2d..d9e6264b77 100644 --- a/src/io/file-export-cmd.cpp +++ b/src/io/file-export-cmd.cpp @@ -705,18 +705,22 @@ InkFileExportCmd::do_export_png_now(SPDocument *doc, std::string const &filename double ydpi = dpi; if (export_height != 0) { + // Comment: This block may not always work as intended (philhart) height = export_height; if ((height < 1) || (height > PNG_UINT_31_MAX)) { std::cerr << "InkFileExport::do_export_png: " << "Export height " << height << " out of range (1 to " << PNG_UINT_31_MAX << ")" << std::endl; return; } + // Comment: the "if" statement treats "height" as pixels, but the line below treats it as inches (philhart) ydpi = Inkscape::Util::Quantity::convert(height, "in", "px") / area.height(); xdpi = ydpi; dpi = ydpi; + // Comment: "dpi" may be meaningless here (philhart) } if (export_width != 0) { + // Comment: Same comments as for the block above (philhart) width = export_width; if ((width < 1) || (width > PNG_UINT_31_MAX)) { std::cerr << "InkFileExport::do_export_png: " @@ -728,6 +732,25 @@ InkFileExportCmd::do_export_png_now(SPDocument *doc, std::string const &filename dpi = xdpi; } + /* + Blame start: philhart + */ + + /* + If the user invokes inkscape via a command line, AND specifies --export-dpi AND + one or both of --export-height or --export-width, then use the DPI supplied by the user. + Comment: the man page is silent about the units for both --export-height and --export-width + */ + + if ((export_width != 0 || export_height != 0) && export_dpi > 0 ) { + xdpi = export_dpi; + ydpi = export_dpi; // Both because of the call later to sp_export_png_file + } + + /* + Blame end: philhart + */ + if (width == 0) { width = (unsigned long int) (Inkscape::Util::Quantity::convert(area.width(), "px", "in") * dpi + 0.5); } -- GitLab