Home > voicebox > fig2emf.m

fig2emf

PURPOSE ^

FIG2EMF save a figure in windows metafile format (H,S,P)

SYNOPSIS ^

function fig2emf(h,s,p,f)

DESCRIPTION ^

FIG2EMF save a figure in windows metafile format (H,S,P)
 Usage:  (1) fig2emf      % save current figure in current folder
         (2) emf=1;                        % set emf=1 to print
             figsize=[500 300];            % default size
             figdir='../figs/<m>-<n>';     % default destination
             ...
             plot (...);
             figbolden(figsize);
             if emf, fig2emf(figdir), end

 Inputs: h   figure handle [use [] or omit for the current figure]
         s   optional file name which can include <m> for the top level
                 mfile name and <n> for figure number [if empty or missing: '<m>_<n>']
                 '.' suppresses the save, if s ends in '/' or '\', then '<m>_<n>' is appended
         p   call figbolden(p) before printing the figure (use p=0 for figbolden default)
         f   output format [default 'meta']
             jpeg, png, tiff, tiffn, meta, bmpmono, bmp, bmp16m, bmp256,
             hdf, pbm, pbmraw, pcxmono, pcx24b, pcx256, pcx16, pgm,
             pgmraw, ppm, ppmraw; pdf, eps, epsc, eps2, epsc2, meta, svg, ps, psc, ps2, psc2 

 Bugs:
    (1) MATLAB does not print the figure correctly when running under
        remote desktop; it seems to pick up the screen resolution incorrectly.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function fig2emf(h,s,p,f)
0002 %FIG2EMF save a figure in windows metafile format (H,S,P)
0003 % Usage:  (1) fig2emf      % save current figure in current folder
0004 %         (2) emf=1;                        % set emf=1 to print
0005 %             figsize=[500 300];            % default size
0006 %             figdir='../figs/<m>-<n>';     % default destination
0007 %             ...
0008 %             plot (...);
0009 %             figbolden(figsize);
0010 %             if emf, fig2emf(figdir), end
0011 %
0012 % Inputs: h   figure handle [use [] or omit for the current figure]
0013 %         s   optional file name which can include <m> for the top level
0014 %                 mfile name and <n> for figure number [if empty or missing: '<m>_<n>']
0015 %                 '.' suppresses the save, if s ends in '/' or '\', then '<m>_<n>' is appended
0016 %         p   call figbolden(p) before printing the figure (use p=0 for figbolden default)
0017 %         f   output format [default 'meta']
0018 %             jpeg, png, tiff, tiffn, meta, bmpmono, bmp, bmp16m, bmp256,
0019 %             hdf, pbm, pbmraw, pcxmono, pcx24b, pcx256, pcx16, pgm,
0020 %             pgmraw, ppm, ppmraw; pdf, eps, epsc, eps2, epsc2, meta, svg, ps, psc, ps2, psc2
0021 %
0022 % Bugs:
0023 %    (1) MATLAB does not print the figure correctly when running under
0024 %        remote desktop; it seems to pick up the screen resolution incorrectly.
0025 
0026 %      Copyright (C) Mike Brookes 2012
0027 %      Version: $Id: fig2emf.m 7761 2016-04-12 07:51:22Z dmb $
0028 %
0029 %   VOICEBOX is a MATLAB toolbox for speech processing.
0030 %   Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html
0031 %
0032 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0033 %   This program is free software; you can redistribute it and/or modify
0034 %   it under the terms of the GNU General Public License as published by
0035 %   the Free Software Foundation; either version 2 of the License, or
0036 %   (at your option) any later version.
0037 %
0038 %   This program is distributed in the hope that it will be useful,
0039 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0040 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0041 %   GNU General Public License for more details.
0042 %
0043 %   You can obtain a copy of the GNU General Public License from
0044 %   http://www.gnu.org/copyleft/gpl.html or by writing to
0045 %   Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA.
0046 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0047 switch nargin
0048     case 0
0049         h=[];
0050         s='';
0051         p=[];
0052     case 1
0053         if ischar(h) || ~numel(h)   % fig2emf(s)
0054             s=h;
0055             h=[];
0056         else                        % fig2emf(h)
0057             s='';
0058         end
0059         p=[];
0060     case 2
0061         if ischar(h) || ~numel(h)   % fig2emf(s,p)
0062             p=s;
0063             s=h;
0064             h=[];
0065         else                        % fig2emf(h,s)
0066             p=[];
0067         end
0068     case 3
0069         if ischar(h) || ~numel(h)   % fig2emf(s,p,f)
0070             f=p;
0071             p=s;
0072             s=h;
0073             h=[];
0074         else                        % fig2emf(h,s,p)
0075             f='meta';
0076         end
0077 end
0078 if ~numel(h)
0079     h=gcf;
0080 else
0081     figure(h);
0082 end
0083 if ~numel(s)
0084     s='<m>_<n>';
0085 elseif s(end)=='/' || s(end)=='\'
0086     s=[s '<m>_<n>'];
0087 end
0088 [st,sti]=dbstack;
0089 if numel(st)>1
0090     mfn=st(end).name;  % ancestor mfile name
0091 else
0092     mfn='Figure';
0093 end
0094 if isreal(h)
0095     fn=num2str(round(h)); % get figure number
0096 else
0097     fn=num2str(get(h,'number'));  % in new versions of matlab use this method
0098 end
0099 ix=strfind(s,'<m>');
0100 while numel(ix)>0
0101     s=[s(1:ix-1) mfn s(ix+3:end)];
0102     ix=strfind(s,'<m>');
0103 end
0104 ix=strfind(s,'<n>');
0105 while numel(ix)>0
0106     s=[s(1:ix-1) fn s(ix+3:end)];
0107     ix=strfind(s,'<n>');
0108 end
0109 if numel(p)>0
0110     if numel(p)==1 && p==0
0111         figbolden;
0112     else
0113         figbolden(p)
0114     end
0115 end
0116 set(gcf,'paperpositionmode','auto');  % preserve screen shape
0117 if ~strcmp(s,'.')
0118     %     eval(['print -dmeta ' s]); % previous version
0119     if nargin<3
0120         f='meta';
0121     end
0122     print(['-d' f],s);
0123 end

Generated on Tue 10-Oct-2017 08:30:10 by m2html © 2003