Changeset 11803
- Timestamp:
- 03/28/12 13:43:15 (13 years ago)
- Location:
- issm/trunk-jpl/externalpackages/export_fig
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/externalpackages/export_fig/eps2pdf.m
r7182 r11803 33 33 % gives lossless output. Default: ghostscript prepress default. 34 34 35 % Copyright (C) Oliver Woodford 2009-201 035 % Copyright (C) Oliver Woodford 2009-2011 36 36 37 37 % Suggestion of appending pdf files provided by Matt C at: … … 43 43 % which was fixed for lossless compression settings. 44 44 45 % 9/12/2011 Pass font path to ghostscript. 46 45 47 function eps2pdf(source, dest, crop, append, gray, quality) 46 48 % Intialise the options string for ghostscript … … 49 51 if nargin < 3 || crop 50 52 options = [options ' -dEPSCrop']; 53 end 54 % Set the font path 55 fp = font_path(); 56 if ~isempty(fp) 57 options = [options ' -sFONTPATH="' fp '"']; 51 58 end 52 59 % Set the grayscale option … … 103 110 return 104 111 112 % Function to return (and create, where necessary) the font path 113 function fp = font_path() 114 fp = user_string('gs_font_path'); 115 if ~isempty(fp) 116 return 117 end 118 % Create the path 119 % Start with the default path 120 fp = getenv('GS_FONTPATH'); 121 % Add on the typical directories for a given OS 122 if ispc 123 if ~isempty(fp) 124 fp = [fp ';']; 125 end 126 fp = [fp getenv('WINDIR') filesep 'Fonts']; 127 else 128 if ~isempty(fp) 129 fp = [fp ':']; 130 end 131 fp = [fp '/usr/share/fonts:/usr/local/share/fonts:/usr/share/fonts/X11:/usr/local/share/fonts/X11:/usr/share/fonts/truetype:/usr/local/share/fonts/truetype']; 132 end 133 user_string('gs_font_path', fp); 134 return -
issm/trunk-jpl/externalpackages/export_fig/export_fig.m
r10635 r11803 134 134 % See also PRINT, SAVEAS. 135 135 136 % Copyright (C) Oliver Woodford 2008-201 1136 % Copyright (C) Oliver Woodford 2008-2012 137 137 138 138 % The idea of using ghostscript is inspired by Peder Axensten's SAVEFIG … … 156 156 % isolated from gui objects. 157 157 158 % 23/02/12: Ensure that axes limits don't change during printing 159 % 14/03/12: Fix bug in fixing the axes limits (thanks to Tobias Lamour for 160 % reporting it). 161 158 162 function [im alpha] = export_fig(varargin) 163 % Make sure the figure is rendered correctly _now_ so that properties like 164 % axes limits are up-to-date. 165 drawnow; 159 166 % Parse the input arguments 160 167 [fig options] = parse_args(nargout, varargin{:}); … … 184 191 end 185 192 end 193 % MATLAB "feature": axes limits can change when printing 194 Hlims = findall(fig, 'Type', 'axes'); 195 if ~cls 196 % Record the old axes limit modes 197 Xlims = make_cell(get(Hlims, 'XLimMode')); 198 Ylims = make_cell(get(Hlims, 'YLimMode')); 199 Zlims = make_cell(get(Hlims, 'ZLimMode')); 200 end 201 % Set all axes limit modes to manual, so the limits can't change 202 set(Hlims, 'XLimMode', 'manual', 'YLimMode', 'manual', 'ZLimMode', 'manual'); 186 203 % Set to print exactly what is there 187 204 set(fig, 'InvertHardcopy', 'off'); … … 418 435 % Reset the hardcopy mode 419 436 set(fig, 'InvertHardcopy', old_mode); 437 % Reset the axes limit modes 438 for a = 1:numel(Hlims) 439 set(Hlims(a), 'XLimMode', Xlims{a}, 'YLimMode', Ylims{a}, 'ZLimMode', Zlims{a}); 440 end 420 441 end 421 442 return … … 719 740 b = options.png || options.tif || options.jpg || options.bmp || options.im || options.alpha; 720 741 return 742 743 % Helper function 744 function A = make_cell(A) 745 if ~iscell(A) 746 A = {A}; 747 end 748 -
issm/trunk-jpl/externalpackages/export_fig/isolate_axes.m
r10635 r11803 18 18 % fh - The handle of the created figure. 19 19 20 % Copyright (C) Oliver Woodford 2011 20 % Copyright (C) Oliver Woodford 2011-2012 21 21 22 22 % Thank you to Rosella Blatt for reporting a bug to do with axes in GUIs 23 % 16/3/2012 Moved copyfig to its own function. Thanks to Bob Fratantonio 24 % for pointing out that the function is also used in export_fig.m. 23 25 24 26 function fh = isolate_axes(ah, vis) … … 107 109 end 108 110 return 109 110 function fh = copyfig(fh)111 % Is there a legend?112 if isempty(findobj(fh, 'Type', 'axes', 'Tag', 'legend'))113 % Safe to copy using copyobj114 fh = copyobj(fh, 0);115 else116 % copyobj will change the figure, so save and then load it instead117 tmp_nam = [tempname '.fig'];118 hgsave(fh, tmp_nam);119 fh = hgload(tmp_nam);120 delete(tmp_nam);121 end122 return -
issm/trunk-jpl/externalpackages/export_fig/license.txt
r10635 r11803 1 Copyright (c) 201 1, Oliver Woodford1 Copyright (c) 2012, Oliver Woodford 2 2 All rights reserved. 3 3 -
issm/trunk-jpl/externalpackages/export_fig/print2array.m
r10635 r11803 37 37 % Thanks to Phil Trinh and Meelis Lootus for reporting the issues. 38 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 39 44 function [A bcol] = print2array(fig, res, renderer) 40 45 % Generate default input arguments, if needed … … 66 71 print2eps(tmp_eps, fig, renderer, '-loose'); 67 72 try 68 % Export to tiff using ghostscript 69 ghostscript(['-dEPSCrop -q -dNOPAUSE -dBATCH ' res_str ' -sDEVICE=tiff24nc -sOutputFile="' tmp_nam '" "' tmp_eps '"']); 73 % Initialize the command to export to tiff using ghostscript 74 cmd_str = ['-dEPSCrop -q -dNOPAUSE -dBATCH ' res_str ' -sDEVICE=tiff24nc']; 75 % Set the font path 76 fp = font_path(); 77 if ~isempty(fp) 78 cmd_str = [cmd_str ' -sFONTPATH="' fp '"']; 79 end 80 % Add the filenames 81 cmd_str = [cmd_str ' -sOutputFile="' tmp_nam '" "' tmp_eps '"']; 82 % Execute the ghostscript command 83 ghostscript(cmd_str); 70 84 catch 71 85 % Delete the intermediate file … … 105 119 end 106 120 end 107 bcol = median([reshape(A(:,[l r],:), [], size(A, 3)); reshape(A( :,[t b],:), [], size(A, 3))], 1);121 bcol = median([reshape(A(:,[l r],:), [], size(A, 3)); reshape(A([t b],:,:), [], size(A, 3))], 1); 108 122 for c = 1:size(A, 3) 109 123 A(:,[1:l-1, r+1:end],c) = bcol(c); … … 156 170 end 157 171 return 172 173 % Function to return (and create, where necessary) the font path 174 function fp = font_path() 175 fp = user_string('gs_font_path'); 176 if ~isempty(fp) 177 return 178 end 179 % Create the path 180 % Start with the default path 181 fp = getenv('GS_FONTPATH'); 182 % Add on the typical directories for a given OS 183 if ispc 184 if ~isempty(fp) 185 fp = [fp ';']; 186 end 187 fp = [fp getenv('WINDIR') filesep 'Fonts']; 188 else 189 if ~isempty(fp) 190 fp = [fp ':']; 191 end 192 fp = [fp '/usr/share/fonts:/usr/local/share/fonts:/usr/share/fonts/X11:/usr/local/share/fonts/X11:/usr/share/fonts/truetype:/usr/local/share/fonts/truetype']; 193 end 194 user_string('gs_font_path', fp); 195 return -
issm/trunk-jpl/externalpackages/export_fig/print2eps.m
r10635 r11803 6 6 % print2eps(filename, fig_handle, options) 7 7 % 8 % This function saves a figure as an eps file, and improves the line style, 9 % making dashed lines more like those on screen and giving grid lines their 10 % own dotted style. 8 % This function saves a figure as an eps file, with two improvements over 9 % MATLAB's print command. First, it improves the line style, making dashed 10 % lines more like those on screen and giving grid lines their own dotted 11 % style. Secondly, it substitutes original font names back into the eps 12 % file, where these have been changed by MATLAB, for up to 11 different 13 % fonts. 11 14 % 12 15 %IN: … … 18 21 % options - Additional parameter strings to be passed to print. 19 22 20 % Copyright (C) Oliver Woodford 2008-201 123 % Copyright (C) Oliver Woodford 2008-2012 21 24 22 25 % The idea of editing the EPS file to change line styles comes from Jiro … … 28 31 % Thanks to Mathieu Morlighem for reporting the issue and obtaining a fix 29 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. 30 46 31 47 function print2eps(name, fig, varargin) … … 39 55 if numel(name) < 5 || ~strcmpi(name(end-3:end), '.eps') 40 56 name = [name '.eps']; % Add the missing extension 57 end 58 % Find all the used fonts in the figure 59 fonts = get(findall(fig, '-property', 'FontName'), 'FontName'); 60 if ~iscell(fonts) 61 fonts = {fonts}; 62 end 63 fonts = unique(fonts); 64 % Map supported font aliases onto the correct name 65 for a = 1:numel(fonts) 66 f = lower(fonts{a}); 67 f(f==' ') = []; 68 switch f 69 case {'times', 'timesnewroman', 'times-roman'} 70 fonts{a} = 'Times-Roman'; 71 case {'arial', 'helvetica'} 72 fonts{a} = 'Helvetica'; 73 case {'newcenturyschoolbook', 'newcenturyschlbk'} 74 fonts{a} = 'NewCenturySchlbk'; 75 otherwise 76 end 77 end 78 % Determine the font swap table 79 matlab_fonts = {'Helvetica', 'Times-Roman', 'Palatino', 'Bookman', 'Helvetica-Narrow', 'Symbol', ... 80 'AvantGarde', 'NewCenturySchlbk', 'Courier', 'ZapfChancery', 'ZapfDingbats'}; 81 require_swap = find(~ismember(fonts, matlab_fonts)); 82 unused_fonts = find(~ismember(matlab_fonts, fonts)); 83 font_swap = min(numel(require_swap), numel(unused_fonts)); 84 font_swap = [reshape(matlab_fonts(unused_fonts(1:font_swap)), 1, font_swap); reshape(fonts(require_swap(1:font_swap)), 1, font_swap)]; 85 % Swap the fonts 86 for a = 1:size(font_swap, 2) 87 set(findall(fig, 'FontName', font_swap{2,a}), 'FontName', font_swap{1,a}); 41 88 end 42 89 % Set paper size … … 63 110 % Reset paper size 64 111 set(fig, 'PaperPositionMode', old_mode); 112 % Correct the fonts 113 if ~isempty(font_swap) 114 % Reset the font names in the figure 115 for a = 1:size(font_swap, 2) 116 set(findall(fig, 'FontName', font_swap{1,a}), 'FontName', font_swap{2,a}); 117 end 118 % Replace the font names in the eps file 119 try 120 swap_fonts(name, font_swap{:}); 121 catch 122 warning('swap_fonts() failed. This is usually because the figure contains a large number of patch objects. Consider exporting to a bitmap format in this case.'); 123 return 124 end 125 end 65 126 % Fix the line styles 66 127 try … … 70 131 end 71 132 return 133 134 function swap_fonts(fname, varargin) 135 % Read in the file 136 fh = fopen(fname, 'r'); 137 if fh == -1 138 error('File %s not found.', fname); 139 end 140 try 141 fstrm = fread(fh, '*char')'; 142 catch ex 143 fclose(fh); 144 rethrow(ex); 145 end 146 fclose(fh); 147 148 % Replace the font names 149 for a = 1:2:numel(varargin) 150 fstrm = regexprep(fstrm, [varargin{a} '-?[a-zA-Z]*\>'], varargin{a+1}(~isspace(varargin{a+1}))); 151 end 152 153 % Write out the updated file 154 fh = fopen(fname, 'w'); 155 if fh == -1 156 error('Unable to open %s for writing.', fname2); 157 end 158 try 159 fwrite(fh, fstrm, 'char*1'); 160 catch ex 161 fclose(fh); 162 rethrow(ex); 163 end 164 fclose(fh); 165 return
Note:
See TracChangeset
for help on using the changeset viewer.