Changeset 21671
- Timestamp:
- 04/12/17 16:35:34 (8 years ago)
- Location:
- issm/trunk-jpl/externalpackages/export_fig
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/externalpackages/export_fig/eps2pdf.m
r21315 r21671 56 56 % 04/10/15: Suggest a workaround for issue #41 (missing font path; thanks Mariia Fedotenkova) 57 57 % 22/02/16: Bug fix from latest release of this file (workaround for issue #41) 58 % 20/03/17: Added informational message in case of GS croak (issue #186) 58 59 59 60 % Intialise the options string for ghostscript … … 159 160 fprintf(2, ' or maybe the%s option(s) are not accepted by your GS version\n', gs_options); 160 161 end 162 fprintf(2, ' or maybe you have another gs executable in your system''s path\n'); 161 163 fprintf(2, 'Ghostscript options: %s\n\n', orig_options); 162 164 error(message); -
issm/trunk-jpl/externalpackages/export_fig/export_fig.m
r21315 r21671 25 25 % export_fig ... -update 26 26 % export_fig ... -nofontswap 27 % export_fig ... -linecaps 27 28 % export_fig(..., handle) 28 29 % … … 43 44 % - Vector formats: pdf, eps 44 45 % - Bitmap formats: png, tiff, jpg, bmp, export to workspace 46 % - Rounded line-caps (optional; pdf & eps only) 45 47 % 46 48 % This function is especially suited to exporting figures for use in … … 153 155 % done in vector formats (only): 11 standard Matlab fonts are 154 156 % replaced by the original figure fonts. This option prevents this. 157 % -linecaps - option to create rounded line-caps (vector formats only). 155 158 % handle - The handle of the figure, axes or uipanels (can be an array of 156 159 % handles, but the objects must be in the same figure) to be … … 241 244 % 17/05/16: Fixed case of image YData containing more than 2 elements (issue #151) 242 245 % 08/08/16: Enabled exporting transparency to TIF, in addition to PNG/PDF (issue #168) 246 % 11/12/16: Added alert in case of error creating output PDF/EPS file (issue #179) 247 % 13/12/16: Minor fix to the commit for issue #179 from 2 days ago 248 % 22/03/17: Fixed issue #187: only set manual ticks when no exponent is present 249 % 09/04/17: Added -linecaps option (idea by Baron Finer, issue #192) 243 250 %} 244 251 … … 271 278 else 272 279 % Check we have a figure 273 if ~isequal(get(fig, 'Type'), 'figure') ;280 if ~isequal(get(fig, 'Type'), 'figure') 274 281 error('Handle must be that of a figure, axes or uipanel'); 275 282 end … … 583 590 if hasTransparency || hasPatches 584 591 % This is *MUCH* slower, but more accurate for patches and transparent annotations (issue #39) 585 renderer = '-painters'; 592 renderer = '-painters'; %ISSM fix 586 593 else 587 594 renderer = '-painters'; … … 655 662 eps2pdf(tmp_nam, pdf_nam_tmp, 1, options.append, options.colourspace==2, options.quality, options.gs_options); 656 663 % Ghostscript croaks on % chars in the output PDF file, so use tempname and then rename the file 657 try movefile(pdf_nam_tmp, pdf_nam, 'f'); catch, end 664 try 665 % Rename the file (except if it is already the same) 666 % Abbie K's comment on the commit for issue #179 (#commitcomment-20173476) 667 if ~isequal(pdf_nam_tmp, pdf_nam) 668 movefile(pdf_nam_tmp, pdf_nam, 'f'); 669 end 670 catch 671 % Alert in case of error creating output PDF/EPS file (issue #179) 672 if exist(pdf_nam_tmp, 'file') 673 error(['Could not create ' pdf_nam ' - perhaps the folder does not exist, or you do not have write permissions']); 674 else 675 error('Could not generate the intermediary EPS file.'); 676 end 677 end 658 678 catch ex 659 679 % Delete the eps … … 663 683 % Delete the eps 664 684 delete(tmp_nam); 665 if options.eps 685 if options.eps || options.linecaps 666 686 try 667 687 % Generate an eps from the pdf … … 669 689 eps_nam_tmp = strrep(pdf_nam_tmp,'.pdf','.eps'); 670 690 pdf2eps(pdf_nam, eps_nam_tmp); 671 movefile(eps_nam_tmp, [options.name '.eps'], 'f'); 691 692 % Issue #192: enable rounded line-caps 693 if options.linecaps 694 fstrm = read_write_entire_textfile(eps_nam_tmp); 695 fstrm = regexprep(fstrm, '[02] J', '1 J'); 696 read_write_entire_textfile(eps_nam_tmp, fstrm); 697 if options.pdf 698 eps2pdf(eps_nam_tmp, pdf_nam, 1, options.append, options.colourspace==2, options.quality, options.gs_options); 699 end 700 end 701 702 if options.eps 703 movefile(eps_nam_tmp, [options.name '.eps'], 'f'); 704 else % if options.pdf 705 try delete(eps_nam_tmp); catch, end 706 end 672 707 catch ex 673 708 if ~options.pdf … … 856 891 'update', false, ... 857 892 'fontswap', true, ... 893 'linecaps', false, ... 858 894 'gs_options', {{}}); 859 895 end … … 946 982 case 'nofontswap' 947 983 options.fontswap = false; 984 case 'linecaps' 985 options.linecaps = true; 948 986 otherwise 949 987 try … … 1161 1199 1162 1200 function A = rgb2grey(A) 1163 A = cast(reshape(reshape(single(A), [], 3) * single([0.299; 0.587; 0.114]), size(A, 1), size(A, 2)), class(A)); % #ok<ZEROLIKE>1201 A = cast(reshape(reshape(single(A), [], 3) * single([0.299; 0.587; 0.114]), size(A, 1), size(A, 2)), class(A)); % #ok<ZEROLIKE> 1164 1202 end 1165 1203 … … 1257 1295 M = {M}; 1258 1296 end 1259 M = cellfun(@(c) strcmp(c, 'linear'), M); 1260 set(Hlims(M), [ax 'TickMode'], 'manual'); 1261 %set(Hlims(M), [ax 'TickLabelMode'], 'manual'); % this hides exponent label in HG2! 1297 %idx = cellfun(@(c) strcmp(c, 'linear'), M); 1298 idx = find(strcmp(M,'linear')); 1299 %set(Hlims(idx), [ax 'TickMode'], 'manual'); % issue #187 1300 %set(Hlims(idx), [ax 'TickLabelMode'], 'manual'); % this hides exponent label in HG2! 1301 for idx2 = 1 : numel(idx) 1302 try 1303 % Fix for issue #187 - only set manual ticks when no exponent is present 1304 hAxes = Hlims(idx(idx2)); 1305 props = {[ax 'TickMode'],'manual', [ax 'TickLabelMode'],'manual'}; 1306 if isempty(strtrim(hAxes.([ax 'Ruler']).SecondaryLabel.String)) 1307 set(hAxes, props{:}); % no exponent, so update moth ticks and tick labels to manual 1308 end 1309 catch % probably HG1 1310 set(hAxes, props{:}); % revert back to old behavior 1311 end 1312 end 1262 1313 end 1263 1314 -
issm/trunk-jpl/externalpackages/export_fig/pdftops.m
r21315 r21671 33 33 34 34 % Call pdftops 35 [varargout{1:nargout}] = system( sprintf('"%s" %s', xpdf_path, cmd));35 [varargout{1:nargout}] = system([xpdf_command(xpdf_path()) cmd]); 36 36 end 37 37 … … 138 138 function good = check_xpdf_path(path_) 139 139 % Check the path is valid 140 [good, message] = system( sprintf('"%s" -h', path_)); %#ok<ASGLU>140 [good, message] = system([xpdf_command(path_) '-h']); %#ok<ASGLU> 141 141 % system returns good = 1 even when the command runs 142 142 % Look for something distinct in the help text … … 149 149 end 150 150 end 151 152 function cmd = xpdf_command(path_) 153 % Initialize any required system calls before calling ghostscript 154 % TODO: in Unix/Mac, find a way to determine whether to use "export" (bash) or "setenv" (csh/tcsh) 155 shell_cmd = ''; 156 if isunix 157 % Avoids an error on Linux with outdated MATLAB lib files 158 % R20XXa/bin/glnxa64/libtiff.so.X 159 % R20XXa/sys/os/glnxa64/libstdc++.so.X 160 shell_cmd = 'export LD_LIBRARY_PATH=""; '; 161 end 162 if ismac 163 shell_cmd = 'export DYLD_LIBRARY_PATH=""; '; 164 end 165 % Construct the command string 166 cmd = sprintf('%s"%s" ', shell_cmd, path_); 167 end -
issm/trunk-jpl/externalpackages/export_fig/print2array.m
r21315 r21671 50 50 % 28/05/15: Fixed issue #69: patches with LineWidth==0.75 appear wide (internal bug in Matlab's print() func) 51 51 % 07/07/15: Fixed issue #83: use numeric handles in HG1 52 % 11/12/16: Fixed cropping issue reported by Harry D. 52 53 %} 53 54 … … 102 103 end 103 104 if nargin > 2 && strcmp(renderer, '-painters') 104 % Print to eps file 105 if isTempDirOk 106 tmp_eps = [tempname '.eps']; 107 else 108 tmp_eps = fullfile(fpath,[fname '.eps']); 109 end 110 print2eps(tmp_eps, fig, 0, renderer, '-loose'); 105 % First try to print directly to tif file 111 106 try 112 % Initialize the command to export to tiff using ghostscript 113 cmd_str = ['-dEPSCrop -q -dNOPAUSE -dBATCH ' res_str ' -sDEVICE=tiff24nc']; 114 % Set the font path 115 fp = font_path(); 116 if ~isempty(fp) 117 cmd_str = [cmd_str ' -sFONTPATH="' fp '"']; 118 end 119 % Add the filenames 120 cmd_str = [cmd_str ' -sOutputFile="' tmp_nam '" "' tmp_eps '"' gs_options]; 121 % Execute the ghostscript command 122 ghostscript(cmd_str); 123 catch me 107 % Print the file into a temporary TIF file and read it into array A 108 [A, err, ex] = read_tif_img(fig, res_str, renderer, tmp_nam); 109 if err, rethrow(ex); end 110 catch % error - try to print to EPS and then using Ghostscript to TIF 111 % Print to eps file 112 if isTempDirOk 113 tmp_eps = [tempname '.eps']; 114 else 115 tmp_eps = fullfile(fpath,[fname '.eps']); 116 end 117 print2eps(tmp_eps, fig, 0, renderer, '-loose'); 118 try 119 % Initialize the command to export to tiff using ghostscript 120 cmd_str = ['-dEPSCrop -q -dNOPAUSE -dBATCH ' res_str ' -sDEVICE=tiff24nc']; 121 % Set the font path 122 fp = font_path(); 123 if ~isempty(fp) 124 cmd_str = [cmd_str ' -sFONTPATH="' fp '"']; 125 end 126 % Add the filenames 127 cmd_str = [cmd_str ' -sOutputFile="' tmp_nam '" "' tmp_eps '"' gs_options]; 128 % Execute the ghostscript command 129 ghostscript(cmd_str); 130 catch me 131 % Delete the intermediate file 132 delete(tmp_eps); 133 rethrow(me); 134 end 124 135 % Delete the intermediate file 125 136 delete(tmp_eps); 126 rethrow(me); 127 end 128 % Delete the intermediate file 129 delete(tmp_eps); 130 % Read in the generated bitmap 131 A = imread(tmp_nam); 132 % Delete the temporary bitmap file 133 delete(tmp_nam); 137 % Read in the generated bitmap 138 A = imread(tmp_nam); 139 % Delete the temporary bitmap file 140 delete(tmp_nam); 141 end 134 142 % Set border pixels to the correct colour 135 143 if isequal(bcol, 'none') … … 168 176 renderer = '-opengl'; 169 177 end 170 err = false; 171 % Set paper size 172 old_pos_mode = get(fig, 'PaperPositionMode'); 173 old_orientation = get(fig, 'PaperOrientation'); 174 set(fig, 'PaperPositionMode', 'auto', 'PaperOrientation', 'portrait'); 175 try 176 % Workaround for issue #69: patches with LineWidth==0.75 appear wide (internal bug in Matlab's print() function) 177 fp = []; % in case we get an error below 178 fp = findall(fig, 'Type','patch', 'LineWidth',0.75); 179 set(fp, 'LineWidth',0.5); 180 % Fix issue #83: use numeric handles in HG1 181 if ~using_hg2(fig), fig = double(fig); end 182 % Print to tiff file 183 print(fig, renderer, res_str, '-dtiff', tmp_nam); 184 % Read in the printed file 185 A = imread(tmp_nam); 186 % Delete the temporary file 187 delete(tmp_nam); 188 catch ex 189 err = true; 190 end 191 set(fp, 'LineWidth',0.75); % restore original figure appearance 192 % Reset paper size 193 set(fig, 'PaperPositionMode', old_pos_mode, 'PaperOrientation', old_orientation); 178 % Print the file into a temporary TIF file and read it into array A 179 [A, err, ex] = read_tif_img(fig, res_str, renderer, tmp_nam); 194 180 % Throw any error that occurred 195 181 if err … … 220 206 end 221 207 208 % Function to create a TIF image of the figure and read it into an array 209 function [A, err, ex] = read_tif_img(fig, res_str, renderer, tmp_nam) 210 err = false; 211 ex = []; 212 % Temporarily set the paper size 213 old_pos_mode = get(fig, 'PaperPositionMode'); 214 old_orientation = get(fig, 'PaperOrientation'); 215 set(fig, 'PaperPositionMode','auto', 'PaperOrientation','portrait'); 216 try 217 % Workaround for issue #69: patches with LineWidth==0.75 appear wide (internal bug in Matlab's print() function) 218 fp = []; % in case we get an error below 219 fp = findall(fig, 'Type','patch', 'LineWidth',0.75); 220 set(fp, 'LineWidth',0.5); 221 % Fix issue #83: use numeric handles in HG1 222 if ~using_hg2(fig), fig = double(fig); end 223 % Print to tiff file 224 print(fig, renderer, res_str, '-dtiff', tmp_nam); 225 % Read in the printed file 226 A = imread(tmp_nam); 227 % Delete the temporary file 228 delete(tmp_nam); 229 catch ex 230 err = true; 231 end 232 set(fp, 'LineWidth',0.75); % restore original figure appearance 233 % Reset the paper size 234 set(fig, 'PaperPositionMode',old_pos_mode, 'PaperOrientation',old_orientation); 235 end 236 222 237 % Function to return (and create, where necessary) the font path 223 238 function fp = font_path() -
issm/trunk-jpl/externalpackages/export_fig/print2eps.m
r21315 r21671 27 27 % fontswap - Whether to swap non-default fonts in figure. Default: true 28 28 % renderer - Renderer used to generate bounding-box. Default: 'opengl' 29 % (available only via the struct alternative) 29 30 % crop_amounts - 4-element vector of crop amounts: [top,right,bottom,left] 30 31 % (available only via the struct alternative)
Note:
See TracChangeset
for help on using the changeset viewer.