Home > atmlab > graphs > fit_to_paper.m

fit_to_paper

PURPOSE ^

FIT_TO_PAPER Resizes a figure to fill the paper.

SYNOPSIS ^

function fit_to_paper(psize,vborder,hborder)

DESCRIPTION ^

 FIT_TO_PAPER   Resizes a figure to fill the paper.

    The function sets the size of the current figure to match the size of
    the given paper format, considering the specified borders. The figure
    is centered on the paper.

    For landscape papers, the figure is prepared for printing by the call:
       orient('landscape');

 FORMAT   fit_to_paper(psize[,hborder,vborder])
        
 IN    psize     The paper size as a string. Valid options are:
                    a4 or a4p
                    a4l
                    a5 or a5p
                    a5l
                 where p and l stand for portrait and landscape, respectively.
 OPT   hborder   Horisontal border. Unit is [mm]. This border width is 
                 applied on both sides of the figure. Default is 15 mm.
       vborder   Vertical border. Unit is [mm]. This border height is 
                 applied both above and below the figure. Default is 25 mm.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

fit_to_paper.m

SOURCE CODE ^

0001 % FIT_TO_PAPER   Resizes a figure to fill the paper.
0002 %
0003 %    The function sets the size of the current figure to match the size of
0004 %    the given paper format, considering the specified borders. The figure
0005 %    is centered on the paper.
0006 %
0007 %    For landscape papers, the figure is prepared for printing by the call:
0008 %       orient('landscape');
0009 %
0010 % FORMAT   fit_to_paper(psize[,hborder,vborder])
0011 %
0012 % IN    psize     The paper size as a string. Valid options are:
0013 %                    a4 or a4p
0014 %                    a4l
0015 %                    a5 or a5p
0016 %                    a5l
0017 %                 where p and l stand for portrait and landscape, respectively.
0018 % OPT   hborder   Horisontal border. Unit is [mm]. This border width is
0019 %                 applied on both sides of the figure. Default is 15 mm.
0020 %       vborder   Vertical border. Unit is [mm]. This border height is
0021 %                 applied both above and below the figure. Default is 25 mm.
0022 
0023 % 2002-12-11   Created by Patrick Eriksson.
0024 
0025 
0026 function fit_to_paper(psize,vborder,hborder)
0027 
0028 
0029 %=== Basic check of input
0030 %
0031 rqre_nargin( 1, nargin );
0032 
0033 
0034 %=== Default values
0035 %
0036 if nargin < 2
0037   vborder = 25;   % mm
0038 end
0039 if nargin < 3
0040   hborder = 15;   % mm
0041 end
0042 
0043 
0044 %=== Get paper size (in mm)
0045 %
0046 do_orient = 0;   % True for landscape
0047 %
0048 if strcmp( psize, 'a4' )  |  strcmp( psize, 'a4p' )
0049   width  = 210;
0050   height = 297;
0051 
0052 elseif strcmp( psize, 'a4l' )
0053   width     = 297;
0054   height    = 210;
0055   do_orient = 1;
0056 
0057 elseif strcmp( psize, 'a5' )  |  strcmp( psize, 'a5p' )
0058   width  = 148;
0059   height = 210;
0060 
0061 elseif strcmp( psize, 'a5l' )
0062   width     = 210;
0063   height    = 148;
0064   do_orient = 1;
0065 
0066 else
0067   error( sprintf( 'Invalid paper type (%s).', psize ) );
0068 end
0069 
0070 
0071 %=== Store present units
0072 %
0073 h = gcf;
0074 %
0075 unit1 = get( h, 'Unit' );
0076 unit2 = get( h, 'PaperUnit' );
0077 
0078 
0079 %=== Set unit cm
0080 %
0081 set( h, 'Unit', 'ce' );
0082 set( h, 'PaperUnit', 'ce' );
0083 
0084 
0085 %=== Scale set lengths
0086 %
0087 width   = width / 10;
0088 height  = height / 10;
0089 hborder = hborder / 10;
0090 vborder = vborder / 10;
0091 
0092 
0093 %=== Set positions
0094 %
0095 set( h, 'Position', [hborder vborder width-2*hborder height-2*vborder] );
0096 set( h, 'PaperPosition', [hborder vborder width-2*hborder height-2*vborder] );
0097 
0098 
0099 %=== Re-set units
0100 set( h, 'Unit', unit1 );
0101 set( h, 'PaperUnit', unit2 );
0102 
0103 
0104 %=== Landscape?
0105 if do_orient
0106   orient('landscape');
0107 end

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005