Changeset 12407


Ignore:
Timestamp:
06/12/12 07:55:14 (13 years ago)
Author:
Mathieu Morlighem
Message:

updated export_fig to newest version

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  
    1616%   export_fig ... -<colorspace>
    1717%   export_fig ... -append
     18%   export_fig ... -bookmark
    1819%   export_fig(..., handle)
    1920%
     
    120121%             exists, the figure is to be appended as a new page, instead
    121122%             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).
    122125%   handle - The handle of the figure or axes (can be an array of handles
    123126%            of several axes, but these must be in the same figure) to be
     
    159162% 14/03/12: Fix bug in fixing the axes limits (thanks to Tobias Lamour for
    160163%           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.
    161168
    162169function [im alpha] = export_fig(varargin)
     
    194201Hlims = findall(fig, 'Type', 'axes');
    195202if ~cls
    196     % Record the old axes limit modes
     203    % Record the old axes limit and tick modes
    197204    Xlims = make_cell(get(Hlims, 'XLimMode'));
    198205    Ylims = make_cell(get(Hlims, 'YLimMode'));
    199206    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'));
     210end
     211% Set all axes limit and tick modes to manual, so the limits and ticks can't change
     212set(Hlims, 'XLimMode', 'manual', 'YLimMode', 'manual', 'ZLimMode', 'manual', 'XTickMode', 'manual', 'YTickMode', 'manual', 'ZTickMode', 'manual');
    203213% Set to print exactly what is there
    204214set(fig, 'InvertHardcopy', 'off');
     
    403413            eps_remove_background(tmp_nam);
    404414        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
    405423        % Generate a pdf
    406424        eps2pdf(tmp_nam, pdf_nam, 1, options.append, options.colourspace==2, options.quality);
     
    435453    % Reset the hardcopy mode
    436454    set(fig, 'InvertHardcopy', old_mode);
    437     % Reset the axes limit modes
     455    % Reset the axes limit and tick modes
    438456    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});
    440458    end
    441459end
     
    462480                 'aa_factor', 3, ...
    463481                 'magnify', 1, ...
     482                 'bookmark', false, ...
    464483                 'quality', []);
    465484native = false; % Set resolution to native of an image
     
    504523                case 'append'
    505524                    options.append = true;
     525                case 'bookmark'
     526                    options.bookmark = true;
    506527                case 'native'
    507528                    native = true;
     
    743764% Helper function
    744765function A = make_cell(A)
    745  if ~iscell(A)
    746      A = {A};
    747  end
    748  
     766if ~iscell(A)
     767    A = {A};
     768end
     769return
     770
     771function add_bookmark(fname, bookmark_text)
     772% Adds a bookmark to the temporary EPS file after %%EndPageSetup
     773% Read in the file
     774fh = fopen(fname, 'r');
     775if fh == -1
     776    error('File %s not found.', fname);
     777end
     778try
     779    fstrm = fread(fh, '*char')';
     780catch ex
     781    fclose(fh);
     782    rethrow(ex);
     783end
     784fclose(fh);
     785
     786% Include standard pdfmark prolog to maximize compatibility
     787fstrm = strrep(fstrm, '%%BeginProlog', sprintf('%%%%BeginProlog\n/pdfmark where {pop} {userdict /pdfmark /cleartomark load put} ifelse'));
     788% Add page bookmark
     789fstrm = strrep(fstrm, '%%EndPageSetup', sprintf('%%%%EndPageSetup\n[ /Title (%s) /OUT pdfmark',bookmark_text));
     790
     791% Write out the updated file
     792fh = fopen(fname, 'w');
     793if fh == -1
     794    error('Unable to open %s for writing.', fname);
     795end
     796try
     797    fwrite(fh, fstrm, 'char*1');
     798catch ex
     799    fclose(fh);
     800    rethrow(ex);
     801end
     802fclose(fh);
     803return
  • issm/trunk-jpl/externalpackages/export_fig/print2array.m

    r11803 r12407  
    4141% 27/1/2012 Bug fix affecting painters rendering tall figures. Thanks to
    4242% Ken Campbell for reporting it.
     43
     44% 3/4/2012 Bug fix to median input. Thanks to Andy Matthews for reporting
     45% it.
    4346
    4447function [A bcol] = print2array(fig, res, renderer)
     
    119122            end
    120123        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));
    122125        for c = 1:size(A, 3)
    123126            A(:,[1:l-1, r+1:end],c) = bcol(c);
  • issm/trunk-jpl/externalpackages/export_fig/print2eps.m

    r11803 r12407  
    4545% alias can lead to another font being swapped in.
    4646
     47% 10/4/2012 Make the font swapping case insensitive.
     48
    4749function print2eps(name, fig, varargin)
    4850options = {'-depsc2'};
     
    5759end
    5860% Find all the used fonts in the figure
    59 fonts = get(findall(fig, '-property', 'FontName'), 'FontName');
     61font_handles = findall(fig, '-property', 'FontName');
     62fonts = get(font_handles, 'FontName');
    6063if ~iscell(fonts)
    6164    fonts = {fonts};
    6265end
    63 fonts = unique(fonts);
    6466% Map supported font aliases onto the correct name
     67fontsl = lower(fonts);
    6568for a = 1:numel(fonts)
    66     f = lower(fonts{a});
     69    f = fontsl{a};
    6770    f(f==' ') = [];
    6871    switch f
    6972        case {'times', 'timesnewroman', 'times-roman'}
    70             fonts{a} = 'Times-Roman';
     73            fontsl{a} = 'times-roman';
    7174        case {'arial', 'helvetica'}
    72             fonts{a} = 'Helvetica';
     75            fontsl{a} = 'helvetica';
    7376        case {'newcenturyschoolbook', 'newcenturyschlbk'}
    74             fonts{a} = 'NewCenturySchlbk';
     77            fontsl{a} = 'newcenturyschlbk';
    7578        otherwise
    7679    end
    7780end
     81fontslu = unique(fontsl);
    7882% Determine the font swap table
    7983matlab_fonts = {'Helvetica', 'Times-Roman', 'Palatino', 'Bookman', 'Helvetica-Narrow', 'Symbol', ...
    8084                '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)];
     85matlab_fontsl = lower(matlab_fonts);
     86require_swap = find(~ismember(fontslu, matlab_fontsl));
     87unused_fonts = find(~ismember(matlab_fontsl, fontslu));
     88font_swap = cell(3, 0);
     89for 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, []);
     95end
    8596% Swap the fonts
    8697for a = 1:size(font_swap, 2)
    87     set(findall(fig, 'FontName', font_swap{2,a}), 'FontName', font_swap{1,a});
     98    set(font_swap{1,a}, 'FontName', font_swap{2,a});
    8899end
    89100% Set paper size
     
    114125    % Reset the font names in the figure
    115126    for a = 1:size(font_swap, 2)
    116         set(findall(fig, 'FontName', font_swap{1,a}), 'FontName', font_swap{2,a});
     127        set(font_swap{1,a}, 'FontName', font_swap{3,a});
    117128    end
    118129    % Replace the font names in the eps file
     130    font_swap = font_swap(2:3,:);
    119131    try
    120132        swap_fonts(name, font_swap{:});
Note: See TracChangeset for help on using the changeset viewer.