File: appPaper.c

package info (click to toggle)
ted 2.6-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 7,928 kB
  • ctags: 8,734
  • sloc: ansic: 71,878; makefile: 2,363; sh: 159
file content (100 lines) | stat: -rw-r--r-- 2,681 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/************************************************************************/
/*  Paper sizes.							*/
/************************************************************************/

#   include	"config.h"

#   include	"appPaper.h"
#   include	<debugon.h>

typedef struct PaperSize
    {
    char *	psMnemonic;
    char *	psLabel;
    int		psWideTwips;
    int		psHighTwips;
    } PaperSize;

static PaperSize UtilPaperSizes[]=
{
    { "a4",		"A4: 210 x 297 mm",		11909,	16834,	},
    { "a5",		"A5: 149 x 210 mm",		8417,	11909,	},
    { "a6",		"A6: 105 x 149 mm",		5954,	8417,	},
    { "letter",		"Letter: 8 1/2 x 11 \"",	12240,	15840,	},
    { "legal",		"Legal: 8 1/2 x 14 \"",		12240,	20720,	},
    { "executive",	"Executive: 7 1/4 x 10 1/2 \"",	10440,	15120,	},
};

/************************************************************************/
/*  Get information on a certain paper size.				*/
/************************************************************************/

int appPaperGetInformation(	int		n,
				int *		pWidth,
				int *		pHeight,
				const char **	pLabel )
    {
    PaperSize *	ps;

    if  ( n < 0								||
	  n >= (int)( sizeof(UtilPaperSizes)/sizeof(PaperSize) )	)
	{ return -1;	}

    ps= UtilPaperSizes+ n;

    if  ( pWidth )
	{ *pWidth= ps->psWideTwips;	}
    if  ( pHeight )
	{ *pHeight= ps->psHighTwips;	}
    if  ( pLabel )
	{ *pLabel= ps->psLabel;		}

    return 0;
    }

/************************************************************************/
/*  Try to find a paper size by its size.				*/
/************************************************************************/
int appPaperGetBySize(		int		width,
				int		height )
    {
    unsigned	i;

    int		gw= width/200;
    int		gh= height/200;

    for ( i= 0; i < sizeof(UtilPaperSizes)/sizeof(PaperSize); i++ )
	{
	int		dw= UtilPaperSizes[i].psWideTwips- width;
	int		dh= UtilPaperSizes[i].psHighTwips- height;

	if  ( dw < gw && dw > -gw && dh < gh && dh > -gh )
	    { return i; }
	}

    return -1;
    }

/************************************************************************/
/*  Try to find a paper size by its mnemonic.				*/
/************************************************************************/
int appPaperGetByMnemonic(	const char *	mnemonic )
    {
    unsigned		i;

    for ( i= 0; i < sizeof(UtilPaperSizes)/sizeof(PaperSize); i++ )
	{
	if  ( ! strcmp( UtilPaperSizes[i].psMnemonic, mnemonic ) )
	    { return i; }
	}

    for ( i= 0; i < sizeof(UtilPaperSizes)/sizeof(PaperSize); i++ )
	{
	if  ( tolower( mnemonic[0] ) ==
			tolower( UtilPaperSizes[i].psMnemonic[0] )	&&
	      ! strcmp( UtilPaperSizes[i].psMnemonic+ 1, mnemonic+ 1 )	)
	    { return i; }
	}

    return -1;
    }