Changeset 12407
- Timestamp:
- 06/12/12 07:55:14 (13 years ago)
- Location:
- issm/trunk-jpl/externalpackages/export_fig
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/externalpackages/export_fig/export_fig.m
r11803 r12407 16 16 % export_fig ... -<colorspace> 17 17 % export_fig ... -append 18 % export_fig ... -bookmark 18 19 % export_fig(..., handle) 19 20 % … … 120 121 % exists, the figure is to be appended as a new page, instead 121 122 % of being overwritten (default). 123 % -bookmark - option to indicate that a bookmark with the name of the 124 % figure is to be created in the output file (pdf only). 122 125 % handle - The handle of the figure or axes (can be an array of handles 123 126 % of several axes, but these must be in the same figure) to be … … 159 162 % 14/03/12: Fix bug in fixing the axes limits (thanks to Tobias Lamour for 160 163 % reporting it). 164 % 02/05/12: Incorporate patch of Petr Nechaev (many thanks), enabling 165 % bookmarking of figures in pdf files. 166 % 09/05/12: Incorporate patch of Arcelia Arrieta (many thanks), to keep 167 % tick marks fixed. 161 168 162 169 function [im alpha] = export_fig(varargin) … … 194 201 Hlims = findall(fig, 'Type', 'axes'); 195 202 if ~cls 196 % Record the old axes limit modes203 % Record the old axes limit and tick modes 197 204 Xlims = make_cell(get(Hlims, 'XLimMode')); 198 205 Ylims = make_cell(get(Hlims, 'YLimMode')); 199 206 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'); 207 Xtick = make_cell(get(Hlims, 'XTickMode')); 208 Ytick = make_cell(get(Hlims, 'YTickMode')); 209 Ztick = make_cell(get(Hlims, 'ZTickMode')); 210 end 211 % Set all axes limit and tick modes to manual, so the limits and ticks can't change 212 set(Hlims, 'XLimMode', 'manual', 'YLimMode', 'manual', 'ZLimMode', 'manual', 'XTickMode', 'manual', 'YTickMode', 'manual', 'ZTickMode', 'manual'); 203 213 % Set to print exactly what is there 204 214 set(fig, 'InvertHardcopy', 'off'); … … 403 413 eps_remove_background(tmp_nam); 404 414 end 415 % Add a bookmark to the PDF if desired 416 if options.bookmark 417 fig_nam = get(fig, 'Name'); 418 if isempty(fig_nam) 419 warning('export_fig:EmptyBookmark', 'Bookmark requested for figure with no name. Bookmark will be empty.'); 420 end 421 add_bookmark(tmp_nam, fig_nam); 422 end 405 423 % Generate a pdf 406 424 eps2pdf(tmp_nam, pdf_nam, 1, options.append, options.colourspace==2, options.quality); … … 435 453 % Reset the hardcopy mode 436 454 set(fig, 'InvertHardcopy', old_mode); 437 % Reset the axes limit modes455 % Reset the axes limit and tick modes 438 456 for a = 1:numel(Hlims) 439 set(Hlims(a), 'XLimMode', Xlims{a}, 'YLimMode', Ylims{a}, 'ZLimMode', Zlims{a} );457 set(Hlims(a), 'XLimMode', Xlims{a}, 'YLimMode', Ylims{a}, 'ZLimMode', Zlims{a}, 'XTickMode', Xtick{a}, 'YTickMode', Ytick{a}, 'ZTickMode', Ztick{a}); 440 458 end 441 459 end … … 462 480 'aa_factor', 3, ... 463 481 'magnify', 1, ... 482 'bookmark', false, ... 464 483 'quality', []); 465 484 native = false; % Set resolution to native of an image … … 504 523 case 'append' 505 524 options.append = true; 525 case 'bookmark' 526 options.bookmark = true; 506 527 case 'native' 507 528 native = true; … … 743 764 % Helper function 744 765 function A = make_cell(A) 745 if ~iscell(A) 746 A = {A}; 747 end 748 766 if ~iscell(A) 767 A = {A}; 768 end 769 return 770 771 function add_bookmark(fname, bookmark_text) 772 % Adds a bookmark to the temporary EPS file after %%EndPageSetup 773 % Read in the file 774 fh = fopen(fname, 'r'); 775 if fh == -1 776 error('File %s not found.', fname); 777 end 778 try 779 fstrm = fread(fh, '*char')'; 780 catch ex 781 fclose(fh); 782 rethrow(ex); 783 end 784 fclose(fh); 785 786 % Include standard pdfmark prolog to maximize compatibility 787 fstrm = strrep(fstrm, '%%BeginProlog', sprintf('%%%%BeginProlog\n/pdfmark where {pop} {userdict /pdfmark /cleartomark load put} ifelse')); 788 % Add page bookmark 789 fstrm = strrep(fstrm, '%%EndPageSetup', sprintf('%%%%EndPageSetup\n[ /Title (%s) /OUT pdfmark',bookmark_text)); 790 791 % Write out the updated file 792 fh = fopen(fname, 'w'); 793 if fh == -1 794 error('Unable to open %s for writing.', fname); 795 end 796 try 797 fwrite(fh, fstrm, 'char*1'); 798 catch ex 799 fclose(fh); 800 rethrow(ex); 801 end 802 fclose(fh); 803 return -
issm/trunk-jpl/externalpackages/export_fig/print2array.m
r11803 r12407 41 41 % 27/1/2012 Bug fix affecting painters rendering tall figures. Thanks to 42 42 % Ken Campbell for reporting it. 43 44 % 3/4/2012 Bug fix to median input. Thanks to Andy Matthews for reporting 45 % it. 43 46 44 47 function [A bcol] = print2array(fig, res, renderer) … … 119 122 end 120 123 end 121 bcol = median([reshape(A(:,[l r],:), [], size(A, 3)); reshape(A([t b],:,:), [], size(A, 3))], 1);124 bcol = uint8(median(single([reshape(A(:,[l r],:), [], size(A, 3)); reshape(A([t b],:,:), [], size(A, 3))]), 1)); 122 125 for c = 1:size(A, 3) 123 126 A(:,[1:l-1, r+1:end],c) = bcol(c); -
issm/trunk-jpl/externalpackages/export_fig/print2eps.m
r11803 r12407 45 45 % alias can lead to another font being swapped in. 46 46 47 % 10/4/2012 Make the font swapping case insensitive. 48 47 49 function print2eps(name, fig, varargin) 48 50 options = {'-depsc2'}; … … 57 59 end 58 60 % Find all the used fonts in the figure 59 fonts = get(findall(fig, '-property', 'FontName'), 'FontName'); 61 font_handles = findall(fig, '-property', 'FontName'); 62 fonts = get(font_handles, 'FontName'); 60 63 if ~iscell(fonts) 61 64 fonts = {fonts}; 62 65 end 63 fonts = unique(fonts);64 66 % Map supported font aliases onto the correct name 67 fontsl = lower(fonts); 65 68 for a = 1:numel(fonts) 66 f = lower(fonts{a});69 f = fontsl{a}; 67 70 f(f==' ') = []; 68 71 switch f 69 72 case {'times', 'timesnewroman', 'times-roman'} 70 fonts {a} = 'Times-Roman';73 fontsl{a} = 'times-roman'; 71 74 case {'arial', 'helvetica'} 72 fonts {a} = 'Helvetica';75 fontsl{a} = 'helvetica'; 73 76 case {'newcenturyschoolbook', 'newcenturyschlbk'} 74 fonts {a} = 'NewCenturySchlbk';77 fontsl{a} = 'newcenturyschlbk'; 75 78 otherwise 76 79 end 77 80 end 81 fontslu = unique(fontsl); 78 82 % Determine the font swap table 79 83 matlab_fonts = {'Helvetica', 'Times-Roman', 'Palatino', 'Bookman', 'Helvetica-Narrow', 'Symbol', ... 80 84 '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 matlab_fontsl = lower(matlab_fonts); 86 require_swap = find(~ismember(fontslu, matlab_fontsl)); 87 unused_fonts = find(~ismember(matlab_fontsl, fontslu)); 88 font_swap = cell(3, 0); 89 for 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, []); 95 end 85 96 % Swap the fonts 86 97 for a = 1:size(font_swap, 2) 87 set(f indall(fig, 'FontName', font_swap{2,a}), 'FontName', font_swap{1,a});98 set(font_swap{1,a}, 'FontName', font_swap{2,a}); 88 99 end 89 100 % Set paper size … … 114 125 % Reset the font names in the figure 115 126 for a = 1:size(font_swap, 2) 116 set(f indall(fig, 'FontName', font_swap{1,a}), 'FontName', font_swap{2,a});127 set(font_swap{1,a}, 'FontName', font_swap{3,a}); 117 128 end 118 129 % Replace the font names in the eps file 130 font_swap = font_swap(2:3,:); 119 131 try 120 132 swap_fonts(name, font_swap{:});
Note:
See TracChangeset
for help on using the changeset viewer.