1 /* Copyright (C) 2001-2012 Artifex Software, Inc.
2 All Rights Reserved.
3
4 This software is provided AS-IS with no warranty, either express or
5 implied.
6
7 This software is distributed under license and may not be copied,
8 modified or distributed except as expressly authorized under the terms
9 of the license contained in the file LICENSE in this distribution.
10
11 Refer to licensing information at http://www.artifex.com or contact
12 Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134, San Rafael,
13 CA 94903, U.S.A., +1(415)492-9861, for further information.
14 */
15
16
17 /* $Id:$ */
18 /* MS Windows implementation of gp_defaultpapersize */
19
20 #include <windows.h>
21 #include <string.h>
22 #include "gx.h"
23 #include "gp.h"
24
25 /* For compilation on Windows NT */
26 #ifndef LOCALE_IPAPERSIZE
27 # define LOCALE_IPAPERSIZE 0x100A
28 #endif
29
30 /* ------ Default paper size ------ */
31
32 /* Get the default paper size. See gp_paper.h for details. */
33 int
gp_defaultpapersize(char * ptr,int * plen)34 gp_defaultpapersize(char *ptr, int *plen)
35 {
36 char buf[6];
37 char *paper = NULL;
38
39 /* Determine the default paper size using the Windows locale.
40 * LOCALE_IPAPERSIZE is only supported on Windows 2000 or later.
41 */
42 if (GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_IPAPERSIZE,
43 buf, sizeof(buf))) {
44 int val = atoi(buf);
45 if (val == 1)
46 paper = "letter";
47 else if (val == 5)
48 paper = "legal";
49 else if (val == 8)
50 paper = "a3";
51 else if (val == 9)
52 paper = "a4";
53 }
54
55 /* Fall back to the default paper size method described in
56 * http://msdn.microsoft.com/en-us/library/ms801585.aspx
57 */
58 if ((paper == 0) &&
59 GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_ICOUNTRY,
60 buf, sizeof(buf))) {
61 int country = atoi(buf);
62 if ((country == CTRY_UNITED_STATES) ||
63 (country == CTRY_CANADA) ||
64 ((country >= 50) && (country < 60) && (country != CTRY_BRAZIL)) ||
65 ((country >= 500) && (country < 600)) ) {
66 /* Imperial measurement system */
67 paper = "letter";
68 }
69 else {
70 /* Metric measurement system */
71 paper = "a4";
72 }
73 }
74
75 if (paper) {
76 int len = strlen(paper);
77
78 if (len < *plen) {
79 /* string fits */
80 strcpy(ptr, paper);
81 *plen = len + 1;
82 return 0;
83 }
84 /* string doesn't fit */
85 *plen = len + 1;
86 return -1;
87 }
88
89 /* No default paper size */
90
91 if (*plen > 0)
92 *ptr = 0;
93 *plen = 1;
94 return 1;
95 }
96