summaryrefslogtreecommitdiff
path: root/print/tex-xdvik/files/patch-texk-xdvik-dvi-init.c
blob: 75b97b2557538420e2a4a44b27f85f3e80c3b45c (plain) (blame)
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
--- dvi-init.c.orig	2013-04-05 09:14:54.000000000 +0900
+++ dvi-init.c	2013-05-06 05:13:12.000000000 +0900
@@ -53,6 +53,9 @@
 #include "statusline.h"
 #include "events.h"
 #include "font-open.h"
+#ifdef HAVE_LIBPAPER
+#include <paper.h>
+#endif
 
 #if FREETYPE
 # include FT_SIZES_H
@@ -865,9 +868,14 @@
     char temp[21];
     const char **p;
     char *q;
+#ifdef HAVE_LIBPAPER
+    const struct paper *pp;
+    int landscape = 0;
+#else
     const char **paper_types = get_paper_types();
     size_t paper_types_size = get_paper_types_size();
-    
+#endif
+
     if (*arg == '+') {
 	++arg;
 	ignore_papersize_specials = True;
@@ -884,6 +892,55 @@
 	    break;
     }
     arg = temp;
+#ifdef HAVE_LIBPAPER
+    paperinit();
+    if (strcmp(temp, "libpaper") == 0) {
+	const char *name;
+
+	name = systempapername();
+	if (name == NULL)
+		name = defaultpapername();
+
+	strncpy(temp, name, sizeof(temp));
+	temp[sizeof(temp) - 1] = '\0';
+    }
+    if (strcmp(temp, "letter") != 0 ||
+	strcmp(temp, "ledgar") != 0) {
+	if (temp[strlen(temp) - 1] == 'r') {
+		temp[strlen(temp) - 1] = '\0';
+		landscape = 1;
+	}
+    }
+    for (pp = paperfirst(); pp; pp = papernext(pp)) {
+	if (strcmp(temp, papername(pp)) == 0) {
+		double w, h;
+		char wstr[256];
+		char hstr[256];
+		
+		if (landscape == 0) {
+			w = paperpswidth(pp);
+			h = paperpsheight(pp);
+		} else {
+			h = paperpswidth(pp);
+			w = paperpsheight(pp);
+		}
+		w = w / 72.0 * 10 * 2.54;
+		h = h / 72.0 * 10 * 2.54;
+		snprintf(wstr, sizeof(wstr), "%f mm", w);
+		snprintf(hstr, sizeof(hstr), "%f mm", h);
+		wstr[sizeof(wstr) - 1] = '\0';
+		hstr[sizeof(hstr) - 1] = '\0';
+		m_paper_unshrunk_w = atopix(wstr, False);
+		m_paper_unshrunk_h = atopix(hstr, False);
+    		globals.grid_paper_unit = atopixunit("mm");
+
+		break;
+	}
+    }
+    paperdone();
+    if (pp == NULL)
+	return (False);
+#else
     /* perform substitutions */
     for (p = paper_types; p < paper_types + paper_types_size; p += 2) {
 	if (strcmp(temp, *p) == 0) {
@@ -898,6 +955,7 @@
     m_paper_unshrunk_h = atopix(arg1 + 1, False);
 
     globals.grid_paper_unit = atopixunit(arg);
+#endif
     
     return (m_paper_unshrunk_w != 0 && m_paper_unshrunk_h != 0);
 }