Changeset 14174
- Timestamp:
- 12/17/12 14:41:41 (12 years ago)
- Location:
- issm/trunk-jpl/externalpackages/export_fig
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/externalpackages/export_fig/export_fig.m
r12407 r14174 123 123 % -bookmark - option to indicate that a bookmark with the name of the 124 124 % figure is to be created in the output file (pdf only). 125 % handle - The handle of the figure or axes (can be an array of handles126 % of several axes, but thesemust be in the same figure) to be125 % handle - The handle of the figure, axes or uipanels (can be an array of 126 % handles, but the objects must be in the same figure) to be 127 127 % saved. Default: gcf. 128 128 % … … 166 166 % 09/05/12: Incorporate patch of Arcelia Arrieta (many thanks), to keep 167 167 % tick marks fixed. 168 169 function [im alpha] = export_fig(varargin) 168 % 12/12/12: Add support for isolating uipanels. Thanks to michael for 169 % suggesting it. 170 171 function [im, alpha] = export_fig(varargin) 170 172 % Make sure the figure is rendered correctly _now_ so that properties like 171 173 % axes limits are up-to-date. 172 174 drawnow; 173 175 % Parse the input arguments 174 [fig options] = parse_args(nargout, varargin{:});176 [fig, options] = parse_args(nargout, varargin{:}); 175 177 % Isolate the subplot, if it is one 176 cls = strcmp(get(fig(1), 'Type'), 'axes');178 cls = all(ismember(get(fig, 'Type'), {'axes', 'uipanel'})); 177 179 if cls 178 180 % Given handles of one or more axes, so isolate them from the rest 179 181 fig = isolate_axes(fig); 180 182 else 183 % Check we have a figure 184 if ~isequal(get(fig, 'Type'), 'figure'); 185 error('Handle must be that of a figure, axes or uipanel'); 186 end 187 % Get the old InvertHardcopy mode 181 188 old_mode = get(fig, 'InvertHardcopy'); 182 189 end … … 198 205 end 199 206 end 200 % MATLAB "feature": axes limits can change when printing207 % MATLAB "feature": axes limits and tick marks can change when printing 201 208 Hlims = findall(fig, 'Type', 'axes'); 202 209 if ~cls … … 282 289 % Crop the background 283 290 if options.crop 284 [alpha v] = crop_background(alpha, 0);291 [alpha, v] = crop_background(alpha, 0); 285 292 A = A(v(1):v(2),v(3):v(4),:); 286 293 end … … 289 296 res = options.magnify * get(0, 'ScreenPixelsPerInch') / 25.4e-3; 290 297 % Save the png 291 imwrite(A, [options.name '.png'], 'Alpha', alpha, 'ResolutionUnit', 'meter', 'XResolution', res, 'YResolution', res);298 imwrite(A, [options.name '.png'], 'Alpha', double(alpha), 'ResolutionUnit', 'meter', 'XResolution', res, 'YResolution', res); 292 299 % Clear the png bit 293 300 options.png = false; … … 325 332 tcol = 255; 326 333 else 327 [A tcol] = print2array(fig, magnify, renderer);334 [A, tcol] = print2array(fig, magnify, renderer); 328 335 end 329 336 % Crop the background … … 460 467 return 461 468 462 function [fig options] = parse_args(nout, varargin)469 function [fig, options] = parse_args(nout, varargin) 463 470 % Parse the input arguments 464 471 % Set the defaults … … 542 549 end 543 550 else 544 [p options.nameext] = fileparts(varargin{a});551 [p, options.name, ext] = fileparts(varargin{a}); 545 552 if ~isempty(p) 546 553 options.name = [p filesep options.name]; … … 577 584 578 585 % Check whether transparent background is wanted (old way) 579 if isequal(get( fig, 'Color'), 'none')586 if isequal(get(ancestor(fig, 'figure'), 'Color'), 'none') 580 587 options.transparent = true; 581 588 end … … 667 674 return 668 675 669 function [A v] = crop_background(A, bcol)676 function [A, v] = crop_background(A, bcol) 670 677 % Map the foreground pixels 671 [h wc] = size(A);678 [h, w, c] = size(A); 672 679 if isscalar(bcol) && c > 1 673 680 bcol = bcol(ones(1, c)); -
issm/trunk-jpl/externalpackages/export_fig/ghostscript.m
r10635 r14174 1 function varargout = ghostscript(cmd)2 1 %GHOSTSCRIPT Calls a local GhostScript executable with the input command 3 2 % … … 25 24 % Thanks to Jonas Dorn for the fix for the title of the uigetdir window on 26 25 % Mac OS. 27 28 26 % Thanks to Nathan Childress for the fix to the default location on 64-bit 29 27 % Windows systems. 30 31 28 % 27/4/11 - Find 64-bit Ghostscript on Windows. Thanks to Paul Durack and 32 29 % Shaun Kline for pointing out the issue 33 34 30 % 4/5/11 - Thanks to David Chorlian for pointing out an alternative 35 31 % location for gs on linux. 32 % 12/12/12 - Add extra executable name on Windows. Thanks to Ratish 33 % Punnoose for highlighting the issue. 36 34 35 function varargout = ghostscript(cmd) 37 36 % Call ghostscript 38 37 [varargout{1:nargout}] = system(sprintf('"%s" %s', gs_path, cmd)); 39 38 return 40 39 41 function path = gs_path40 function path_ = gs_path 42 41 % Return a valid path 43 42 % Start with the currently set path 44 path = user_string('ghostscript');43 path_ = user_string('ghostscript'); 45 44 % Check the path works 46 if check_gs_path(path )45 if check_gs_path(path_) 47 46 return 48 47 end 49 48 % Check whether the binary is on the path 50 49 if ispc 51 bin = {'gswin32c.exe', 'gswin64c.exe' };50 bin = {'gswin32c.exe', 'gswin64c.exe', 'gs'}; 52 51 else 53 52 bin = {'gs'}; 54 53 end 55 54 for a = 1:numel(bin) 56 path = bin{a};57 if check_store_gs_path(path )55 path_ = bin{a}; 56 if check_store_gs_path(path_) 58 57 return 59 58 end … … 76 75 path2 = [default_location dir_list(a).name executable{b}]; 77 76 if exist(path2, 'file') == 2 78 path = path2;77 path_ = path2; 79 78 ver_num = ver_num2; 80 79 end … … 82 81 end 83 82 end 84 if check_store_gs_path(path )83 if check_store_gs_path(path_) 85 84 return 86 85 end … … 88 87 bin = {'/usr/bin/gs', '/usr/local/bin/gs'}; 89 88 for a = 1:numel(bin) 90 path = bin{a};91 if check_store_gs_path(path )89 path_ = bin{a}; 90 if check_store_gs_path(path_) 92 91 return 93 92 end … … 110 109 for a = 1:numel(bin_dir) 111 110 for b = 1:numel(bin) 112 path = [base bin_dir{a} bin{b}];113 if exist(path , 'file') == 2114 if check_store_gs_path(path )111 path_ = [base bin_dir{a} bin{b}]; 112 if exist(path_, 'file') == 2 113 if check_store_gs_path(path_) 115 114 return 116 115 end … … 121 120 error('Ghostscript not found. Have you installed it from www.ghostscript.com?'); 122 121 123 function good = check_store_gs_path(path )122 function good = check_store_gs_path(path_) 124 123 % Check the path is valid 125 good = check_gs_path(path );124 good = check_gs_path(path_); 126 125 if ~good 127 126 return 128 127 end 129 128 % Update the current default path to the path found 130 if ~user_string('ghostscript', path )129 if ~user_string('ghostscript', path_) 131 130 warning('Path to ghostscript installation could not be saved. Enter it manually in ghostscript.txt.'); 132 131 return … … 134 133 return 135 134 136 function good = check_gs_path(path )135 function good = check_gs_path(path_) 137 136 % Check the path is valid 138 [good message] = system(sprintf('"%s" -h', path));137 [good, message] = system(sprintf('"%s" -h', path_)); 139 138 good = good == 0; 140 139 return -
issm/trunk-jpl/externalpackages/export_fig/isolate_axes.m
r11803 r14174 5 5 % fh = isolate_axes(ah, vis) 6 6 % 7 % This function will create a new figure containing the axes specified, and8 % also their associated legends and colorbars. The axes specified must all9 % be in the same figure, but they will generally only be a subset of the10 % a xes in the figure.7 % This function will create a new figure containing the axes/uipanels 8 % specified, and also their associated legends and colorbars. The objects 9 % specified must all be in the same figure, but they will generally only be 10 % a subset of the objects in the figure. 11 11 % 12 12 % IN: 13 % ah - An array of axes handles, which must come from the same figure. 13 % ah - An array of axes and uipanel handles, which must come from the 14 % same figure. 14 15 % vis - A boolean indicating whether the new figure should be visible. 15 16 % Default: false. … … 23 24 % 16/3/2012 Moved copyfig to its own function. Thanks to Bob Fratantonio 24 25 % for pointing out that the function is also used in export_fig.m. 26 % 12/12/12 - Add support for isolating uipanels. Thanks to michael for 27 % suggesting it. 25 28 26 29 function fh = isolate_axes(ah, vis) … … 29 32 error('ah must be an array of handles'); 30 33 end 31 % Check that the handles are all for axes , and are all in the same figure34 % Check that the handles are all for axes or uipanels, and are all in the same figure 32 35 fh = ancestor(ah(1), 'figure'); 33 36 nAx = numel(ah); 34 37 for a = 1:nAx 35 if ~ strcmp(get(ah(a), 'Type'), 'axes')36 error('All handles must be axes handles.');38 if ~ismember(get(ah(a), 'Type'), {'axes', 'uipanel'}) 39 error('All handles must be axes or uipanel handles.'); 37 40 end 38 41 if ~isequal(ancestor(ah(a), 'figure'), fh) … … 40 43 end 41 44 end 42 % Tag the axes so we can find them in the copy45 % Tag the objects so we can find them in the copy 43 46 old_tag = get(ah, 'Tag'); 44 47 if nAx == 1 … … 51 54 set(fh, 'Visible', 'off'); 52 55 end 53 % Reset the axestags56 % Reset the object tags 54 57 for a = 1:nAx 55 58 set(ah(a), 'Tag', old_tag{a}); … … 59 62 if numel(ah) ~= nAx 60 63 close(fh); 61 error('Incorrect number of axes found.');64 error('Incorrect number of objects found.'); 62 65 end 63 66 % Set the axes tags to what they should be … … 87 90 % Get all the objects in the figure 88 91 axs = findall(fh); 89 % Delete everything except for the input axes and associated items92 % Delete everything except for the input objects and associated items 90 93 delete(axs(~ismember(axs, [ah; allchildren(ah); allancestors(ah)]))); 91 94 return -
issm/trunk-jpl/externalpackages/export_fig/pdftops.m
r10635 r14174 33 33 return 34 34 35 function path = xpdf_path35 function path_ = xpdf_path 36 36 % Return a valid path 37 37 % Start with the currently set path 38 path = user_string('pdftops');38 path_ = user_string('pdftops'); 39 39 % Check the path works 40 if check_xpdf_path(path )40 if check_xpdf_path(path_) 41 41 return 42 42 end … … 48 48 end 49 49 if check_store_xpdf_path(bin) 50 path = bin;50 path_ = bin; 51 51 return 52 52 end 53 53 % Search the obvious places 54 54 if ispc 55 path = 'C:\Program Files\xpdf\pdftops.exe';55 path_ = 'C:\Program Files\xpdf\pdftops.exe'; 56 56 else 57 path = '/usr/local/bin/pdftops';57 path_ = '/usr/local/bin/pdftops'; 58 58 end 59 if check_store_xpdf_path(path )59 if check_store_xpdf_path(path_) 60 60 return 61 61 end … … 75 75 bin_dir = {'', ['bin' filesep], ['lib' filesep]}; 76 76 for a = 1:numel(bin_dir) 77 path = [base bin_dir{a} bin];78 if exist(path , 'file') == 277 path_ = [base bin_dir{a} bin]; 78 if exist(path_, 'file') == 2 79 79 break; 80 80 end 81 81 end 82 if check_store_xpdf_path(path )82 if check_store_xpdf_path(path_) 83 83 return 84 84 end … … 86 86 error('pdftops executable not found.'); 87 87 88 function good = check_store_xpdf_path(path )88 function good = check_store_xpdf_path(path_) 89 89 % Check the path is valid 90 good = check_xpdf_path(path );90 good = check_xpdf_path(path_); 91 91 if ~good 92 92 return 93 93 end 94 94 % Update the current default path to the path found 95 if ~user_string('pdftops', path )95 if ~user_string('pdftops', path_) 96 96 warning('Path to pdftops executable could not be saved. Enter it manually in pdftops.txt.'); 97 97 return … … 99 99 return 100 100 101 function good = check_xpdf_path(path )101 function good = check_xpdf_path(path_) 102 102 % Check the path is valid 103 [good message] = system(sprintf('"%s" -h', path ));103 [good message] = system(sprintf('"%s" -h', path_)); 104 104 % system returns good = 1 even when the command runs 105 105 % Look for something distinct in the help text -
issm/trunk-jpl/externalpackages/export_fig/print2array.m
r12407 r14174 25 25 % bcol - 1x3 uint8 vector of the background color 26 26 27 % Copyright (C) Oliver Woodford 2008-201 127 % Copyright (C) Oliver Woodford 2008-2012 28 28 29 % 5/9/2011 Set EraseModes to normal when using opengl or zbuffer renderers. 30 % Thanks to Pawel Kocieniewski for reporting the issue. 29 % 05/09/11: Set EraseModes to normal when using opengl or zbuffer 30 % renderers. Thanks to Pawel Kocieniewski for reporting the 31 % issue. 32 % 21/09/11: Bug fix: unit8 -> uint8! Thanks to Tobias Lamour for reporting 33 % the issue. 34 % 14/11/11: Bug fix: stop using hardcopy(), as it interfered with figure 35 % size and erasemode settings. Makes it a bit slower, but more 36 % reliable. Thanks to Phil Trinh and Meelis Lootus for reporting 37 % the issues. 38 % 09/12/11: Pass font path to ghostscript. 39 % 27/01/12: Bug fix affecting painters rendering tall figures. Thanks to 40 % Ken Campbell for reporting it. 41 % 03/04/12: Bug fix to median input. Thanks to Andy Matthews for reporting 42 % it. 43 % 26/10/12: Set PaperOrientation to portrait. Thanks to Michael Watts for 44 % reporting the issue. 31 45 32 % 21/9/2011 Bug fix: unit8 -> uint8! 33 % Thanks to Tobias Lamour for reporting the issue. 34 35 % 14/11/2011 Bug fix: stop using hardcopy(), as it interfered with figure 36 % size and erasemode settings. Makes it a bit slower, but more reliable. 37 % Thanks to Phil Trinh and Meelis Lootus for reporting the issues. 38 39 % 9/12/2011 Pass font path to ghostscript. 40 41 % 27/1/2012 Bug fix affecting painters rendering tall figures. Thanks to 42 % Ken Campbell for reporting it. 43 44 % 3/4/2012 Bug fix to median input. Thanks to Andy Matthews for reporting 45 % it. 46 47 function [A bcol] = print2array(fig, res, renderer) 46 function [A, bcol] = print2array(fig, res, renderer) 48 47 % Generate default input arguments, if needed 49 48 if nargin < 2 … … 85 84 % Execute the ghostscript command 86 85 ghostscript(cmd_str); 87 catch 86 catch me 88 87 % Delete the intermediate file 89 88 delete(tmp_eps); 90 rethrow( lasterror);89 rethrow(me); 91 90 end 92 91 % Delete the intermediate file … … 134 133 err = false; 135 134 % Set paper size 136 old_mode = get(fig, 'PaperPositionMode'); 137 set(fig, 'PaperPositionMode', 'auto'); 135 old_pos_mode = get(fig, 'PaperPositionMode'); 136 old_orientation = get(fig, 'PaperOrientation'); 137 set(fig, 'PaperPositionMode', 'auto', 'PaperOrientation', 'portrait'); 138 138 try 139 139 % Print to tiff file … … 147 147 end 148 148 % Reset paper size 149 set(fig, 'PaperPositionMode', old_ mode);149 set(fig, 'PaperPositionMode', old_pos_mode, 'PaperOrientation', old_orientation); 150 150 % Throw any error that occurred 151 151 if err -
issm/trunk-jpl/externalpackages/export_fig/print2eps.m
r12407 r14174 28 28 % fex id: 5743, but the implementation is mine :) 29 29 30 % 14/11/2011 Fix a MATLAB bug rendering black or white text incorrectly. 31 % Thanks to Mathieu Morlighem for reporting the issue and obtaining a fix 32 % from TMW. 33 34 % 8/12/2011 Added ability to correct fonts. Several people have requested 35 % this at one time or another, and also pointed me to printeps (fex id: 36 % 7501), so thank you to them. My implementation (which was not inspired by 37 % printeps - I'd already had the idea for my approach) goes 38 % slightly further in that it allows multiple fonts to be swapped. 39 40 % 14/12/2011 Fix bug affecting font names containing spaces. Many thanks to 41 % David Szwer for reporting the issue. 42 43 % 25/1/2012 Add a font not to be swapped. Thanks to Anna Rafferty and Adam 44 % Jackson for reporting the issue. Also fix a bug whereby using a font 45 % alias can lead to another font being swapped in. 46 47 % 10/4/2012 Make the font swapping case insensitive. 30 % 14/11/2011: Fix a MATLAB bug rendering black or white text incorrectly. 31 % Thanks to Mathieu Morlighem for reporting the issue and 32 % obtaining a fix from TMW. 33 % 08/12/11: Added ability to correct fonts. Several people have requested 34 % this at one time or another, and also pointed me to printeps 35 % (fex id: 7501), so thank you to them. My implementation (which 36 % was not inspired by printeps - I'd already had the idea for my 37 % approach) goes slightly further in that it allows multiple 38 % fonts to be swapped. 39 % 14/12/11: Fix bug affecting font names containing spaces. Thanks to David 40 % Szwer for reporting the issue. 41 % 25/01/12: Add a font not to be swapped. Thanks to Anna Rafferty and Adam 42 % Jackson for reporting the issue. Also fix a bug whereby using a 43 % font alias can lead to another font being swapped in. 44 % 10/04/12: Make the font swapping case insensitive. 45 % 26/10/12: Set PaperOrientation to portrait. Thanks to Michael Watts for 46 % reporting the issue. 47 % 26/10/12: Fix issue to do with swapping fonts changing other fonts and 48 % sizes we don't want, due to listeners. Thanks to Malcolm Hudson 49 % for reporting the issue. 48 50 49 51 function print2eps(name, fig, varargin) … … 59 61 end 60 62 % Find all the used fonts in the figure 61 font_handles = find all(fig, '-property', 'FontName');63 font_handles = findobj(fig, '-property', 'FontName'); 62 64 fonts = get(font_handles, 'FontName'); 63 65 if ~iscell(fonts) … … 86 88 require_swap = find(~ismember(fontslu, matlab_fontsl)); 87 89 unused_fonts = find(~ismember(matlab_fontsl, fontslu)); 88 font_swap = cell(3, 0);89 fo r a = 1:min(numel(require_swap), numel(unused_fonts))90 ind = find(strcmp(fontslu{require_swap(a)}, fontsl)); 91 n = numel(ind);92 font_swap (1,end+1:end+n) = reshape(mat2cell(font_handles(ind), ones(n, 1)), 1, []);93 font_swap (2,end-n+1:end) = matlab_fonts(unused_fonts(a));94 font _swap(3,end-n+1:end) = reshape(fonts(ind), 1, []);90 font_swap = cell(3, min(numel(require_swap), numel(unused_fonts))); 91 fonts_new = fonts; 92 for a = 1:size(font_swap, 2) 93 font_swap{1,a} = find(strcmp(fontslu{require_swap(a)}, fontsl)); 94 font_swap{2,a} = matlab_fonts{unused_fonts(a)}; 95 font_swap{3,a} = fonts{font_swap{1,end}(1)}; 96 fonts_new(font_swap{1,a}) = {font_swap{2,a}}; 95 97 end 96 98 % Swap the fonts 97 for a = 1:size(font_swap, 2) 98 set(font_swap{1,a}, 'FontName', font_swap{2,a}); 99 if ~isempty(font_swap) 100 fonts_size = get(font_handles, 'FontSize'); 101 if iscell(fonts_size) 102 fonts_size = cell2mat(fonts_size); 103 end 104 M = false(size(font_handles)); 105 % Loop because some changes may not stick first time, due to listeners 106 c = 0; 107 update = zeros(1000, 1); 108 for b = 1:10 % Limit number of loops to avoid infinite loop case 109 for a = 1:numel(M) 110 M(a) = ~isequal(get(font_handles(a), 'FontName'), fonts_new{a}) || ~isequal(get(font_handles(a), 'FontSize'), fonts_size(a)); 111 if M(a) 112 set(font_handles(a), 'FontName', fonts_new{a}, 'FontSize', fonts_size(a)); 113 c = c + 1; 114 update(c) = a; 115 end 116 end 117 if ~any(M) 118 break; 119 end 120 end 121 % Compute the order to revert fonts later, without the need of a loop 122 [update, M] = unique(update(1:c)); 123 [M, M] = sort(M); 124 update = reshape(update(M), 1, []); 99 125 end 100 126 % Set paper size 101 old_mode = get(fig, 'PaperPositionMode'); 102 set(fig, 'PaperPositionMode', 'auto'); 127 old_pos_mode = get(fig, 'PaperPositionMode'); 128 old_orientation = get(fig, 'PaperOrientation'); 129 set(fig, 'PaperPositionMode', 'auto', 'PaperOrientation', 'portrait'); 103 130 % MATLAB bug fix - black and white text can come out inverted sometimes 104 131 % Find the white and black text … … 120 147 set(white_text_handles, 'Color', [1 1 1]); 121 148 % Reset paper size 122 set(fig, 'PaperPositionMode', old_ mode);149 set(fig, 'PaperPositionMode', old_pos_mode, 'PaperOrientation', old_orientation); 123 150 % Correct the fonts 124 151 if ~isempty(font_swap) 125 152 % Reset the font names in the figure 126 for a = 1:size(font_swap, 2)127 set(font_ swap{1,a}, 'FontName', font_swap{3,a});153 for a = update 154 set(font_handles(a), 'FontName', fonts{a}, 'FontSize', fonts_size(a)); 128 155 end 129 156 % Replace the font names in the eps file
Note:
See TracChangeset
for help on using the changeset viewer.