Mercurial > octave
changeset 32283:d668c52cf2e6
print.m: Optionally don't append file extension to file name (bug #64510).
* scripts/plot/util/private/__print_parse_opts__.m: Add flag
"-no-append-file-extension" to skip adding a file extension that would match
the selected file format.
* scripts/plot/util/print.m: Add documentation for new flag. Add test.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Sun, 27 Aug 2023 16:29:40 +0200 |
parents | d607947a6f2a |
children | 265930c2158b |
files | scripts/plot/util/print.m scripts/plot/util/private/__print_parse_opts__.m |
diffstat | 2 files changed, 31 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/plot/util/print.m Mon Aug 28 11:47:15 2023 +0200 +++ b/scripts/plot/util/print.m Sun Aug 27 16:29:40 2023 +0200 @@ -427,6 +427,10 @@ ## respectively. Allowed values for @var{N} are 1, 2, or 4. ## @end table ## +## @item -no-append-file-extension +## With this option, @var{filename} is used verbatim. That means no file +## extension matching the file format is appended automatically. +## ## @seealso{saveas, getframe, savefig, hgsave, orient, figure} ## @end deftypefn @@ -823,6 +827,23 @@ endfunction +## Print to file with and without file extension +%!test +%! hf = figure ("visible", "off"); +%! unwind_protect +%! x = 0:0.1:1; +%! hax = axes (hf); +%! plot (hax, x, x); +%! tmp_name = tempname (); +%! print (hf, tmp_name, "-dpng"); +%! assert (isfile ([tmp_name ".png"])); +%! unlink ([tmp_name ".png"]); +%! print (hf, tmp_name, "-dpng", "-no-append-file-extension"); +%! assert (isfile (tmp_name)); +%! unlink (tmp_name); +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect %!error <a graphics handle> %! hf = figure ("visible", "off");
--- a/scripts/plot/util/private/__print_parse_opts__.m Mon Aug 28 11:47:15 2023 +0200 +++ b/scripts/plot/util/private/__print_parse_opts__.m Sun Aug 27 16:29:40 2023 +0200 @@ -61,6 +61,7 @@ arg_st.lpr_binary = __quote_path__ (__find_binary__ ("lpr")); arg_st.polymerge = 1; arg_st.name = ""; + arg_st.append_file_extension = true; arg_st.orientation = ""; arg_st.pstoedit_binary = __quote_path__ (__find_binary__ ("pstoedit")); arg_st.preview = ""; @@ -148,6 +149,8 @@ elseif (any (strcmp (arg, {"-interchange", "-metafile", "-pict", "-tiff"}))) arg_st.preview = arg(2:end); + elseif (strcmp (arg, "-no-append-file-extension")) + arg_st.append_file_extension = false; elseif (strncmp (arg, "-debug", 6)) arg_st.debug = true; arg_st.ghostscript.debug = true; @@ -233,7 +236,7 @@ if (isempty (arg_st.devopt)) if (arg_st.rgb_output) arg_st.devopt = "png"; - elseif (dot == 0) + elseif (dot == 0 || ! arg_st.append_file_extension) arg_st.devopt = "psc"; else arg_st.devopt = lower (arg_st.name(dot+1:end)); @@ -355,7 +358,8 @@ default_suffix = suffixes{match}; endif - if (dot == 0 && ! isempty (arg_st.name) && ! isempty (default_suffix)) + if (arg_st.append_file_extension && dot == 0 && ! isempty (arg_st.name) ... + && ! isempty (default_suffix)) arg_st.name = [arg_st.name "." default_suffix]; endif @@ -809,10 +813,10 @@ aliases.tiffn = "tiff24nc"; if (do_eps) - aliases.eps = "ps2write"; - aliases.eps2 = "ps2write"; - aliases.epsc = "ps2write"; - aliases.epsc2 = "ps2write"; + aliases.eps = "eps2write"; + aliases.eps2 = "eps2write"; + aliases.epsc = "eps2write"; + aliases.epsc2 = "eps2write"; endif endfunction