annotate src/w32bdf.c @ 24243:aa82f46ecc36

Fix key bindings for appt-add and appt-delete
author Edward M. Reingold <reingold@emr.cs.iit.edu>
date Mon, 01 Feb 1999 15:39:28 +0000
parents db9dfcd11c84
children 541ff963ba80
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
24141
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
1 /* Implementation of BDF font handling on the Microsoft W32 API.
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
2 Copyright (C) 1999 Free Software Foundation, Inc.
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
3
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
4 This file is part of GNU Emacs.
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
5
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
6 GNU Emacs is free software; you can redistribute it and/or modify
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
8 the Free Software Foundation; either version 2, or (at your option)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
9 any later version.
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
10
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
11 GNU Emacs is distributed in the hope that it will be useful,
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
14 GNU General Public License for more details.
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
15
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
17 along with GNU Emacs; see the file COPYING. If not, write to
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
19 Boston, MA 02111-1307, USA. */
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
20
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
21 /* Based heavily on code by H. Miyashita for Meadow (a descendant of
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
22 MULE for W32). */
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
23
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
24 #include <windows.h>
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
25 #include "config.h"
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
26 #include "lisp.h"
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
27 #include "charset.h"
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
28 #include "fontset.h"
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
29 #include "blockinput.h"
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
30 #include "w32gui.h"
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
31 #include "w32term.h"
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
32 #include "w32bdf.h"
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
33
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
34 #define min(a, b) ((a) < (b) ? (a) : (b))
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
35 #define max(a, b) ((a) > (b) ? (a) : (b))
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
36
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
37 void w32_free_bdf_font(bdffont *fontp);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
38 bdffont *w32_init_bdf_font(char *filename);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
39
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
40 static int
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
41 search_file_line(char *key, char *start, int len, char **val, char **next)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
42 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
43 int linelen;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
44 unsigned char *p, *q;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
45
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
46 p = memchr(start, '\n', len);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
47 if (!p) return -1;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
48 for (;start < p;start++)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
49 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
50 if ((*start != ' ') || (*start != '\t')) break;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
51 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
52 linelen = p - start + 1;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
53 *next = p + 1;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
54 if (strncmp(start, key, min(strlen(key), linelen)) == 0)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
55 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
56 *val = start + strlen(key);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
57 return 1;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
58 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
59
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
60 return 0;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
61 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
62
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
63 static int
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
64 proceed_file_line(char *key, char *start, int *len, char **val, char **next)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
65 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
66 int flag = 0;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
67
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
68 do {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
69 flag = search_file_line(key, start, *len, val, next);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
70 *len -= (int)(*next - start);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
71 start = *next;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
72 }while(flag == 0);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
73
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
74 if (flag == -1) return 0;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
75 return 1;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
76 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
77
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
78 static int
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
79 set_bdf_font_info(bdffont *fontp)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
80 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
81 unsigned char *start, *p, *q;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
82 int len, flag;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
83 int bbw, bbh, bbx, bby;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
84 int val1;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
85
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
86 len = fontp->size;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
87 start = fontp->font;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
88
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
89 fontp->yoffset = 0;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
90 fontp->relative_compose = 0;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
91 fontp->default_ascent = 0;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
92
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
93 flag = proceed_file_line("FONTBOUNDINGBOX", start, &len, &p, &q);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
94 if (!flag) return 0;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
95 bbw = strtol(p, &start, 10);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
96 p = start;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
97 bbh = strtol(p, &start, 10);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
98 p = start;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
99 bbx = strtol(p, &start, 10);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
100 p = start;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
101 bby = strtol(p, &start, 10);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
102
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
103 fontp->llx = bbx;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
104 fontp->lly = bby;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
105 fontp->urx = bbw + bbx;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
106 fontp->ury = bbh + bby;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
107 fontp->width = bbw;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
108 fontp->height = bbh;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
109 start = q;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
110 flag = proceed_file_line("STARTPROPERTIES", start, &len, &p, &q);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
111 if (!flag) return 1;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
112
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
113 do {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
114 start = q;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
115 if (search_file_line("PIXEL_SIZE", start, len, &p, &q) == 1)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
116 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
117 val1 = atoi(p);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
118 fontp->pixsz = val1;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
119 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
120 else if (search_file_line("FONT_ASCENT", start, len, &p, &q) == 1)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
121 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
122 val1 = atoi(p);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
123 fontp->ury = val1;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
124 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
125 else if (search_file_line("FONT_DESCENT", start, len, &p, &q) == 1)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
126 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
127 val1 = atoi(p);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
128 fontp->lly = -val1;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
129 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
130 else if (search_file_line("_MULE_BASELINE_OFFSET", start, len, &p, &q) == 1)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
131 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
132 val1 = atoi(p);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
133 fontp->yoffset = val1;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
134 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
135 else if (search_file_line("_MULE_RELATIVE_COMPOSE", start, len, &p, &q) == 1)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
136 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
137 val1 = atoi(p);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
138 fontp->relative_compose = val1;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
139 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
140 else if (search_file_line("_MULE_DEFAULT_ASCENT", start, len, &p, &q) == 1)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
141 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
142 val1 = atoi(p);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
143 fontp->default_ascent = val1;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
144 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
145 else
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
146 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
147 flag = search_file_line("ENDPROPERTIES", start, len, &p, &q);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
148 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
149 if (flag == -1) return 0;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
150 len -= (q - start);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
151 }while(flag == 0);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
152 start = q;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
153 flag = proceed_file_line("CHARS", start, &len, &p, &q);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
154 if (!flag) return 0;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
155 fontp->seeked = q;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
156
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
157 return 1;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
158 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
159
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
160 bdffont*
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
161 w32_init_bdf_font(char *filename)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
162 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
163 HANDLE hfile, hfilemap;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
164 bdffont *bdffontp;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
165 unsigned char *font;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
166 BY_HANDLE_FILE_INFORMATION fileinfo;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
167 int i;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
168
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
169 hfile = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL,
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
170 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
171 if (hfile == INVALID_HANDLE_VALUE) return NULL;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
172 if (!GetFileInformationByHandle(hfile, &fileinfo) ||
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
173 (fileinfo.nFileSizeHigh != 0) ||
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
174 (fileinfo.nFileSizeLow > BDF_FILE_SIZE_MAX))
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
175 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
176 CloseHandle(hfile);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
177 error("Fail to open BDF file.");
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
178 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
179 hfilemap = CreateFileMapping(hfile, NULL, PAGE_READONLY, 0, 0, NULL);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
180 if (hfilemap == INVALID_HANDLE_VALUE)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
181 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
182 CloseHandle(hfile);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
183 error("Can't map font.");
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
184 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
185
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
186 font = MapViewOfFile(hfilemap, FILE_MAP_READ, 0, 0, 0);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
187
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
188 if (!font)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
189 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
190 CloseHandle(hfile);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
191 CloseHandle(hfilemap);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
192 error("Can't view font.");
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
193 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
194
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
195 bdffontp = (bdffont *) xmalloc(sizeof(bdffont));
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
196
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
197 for(i = 0;i < BDF_FIRST_OFFSET_TABLE;i++)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
198 bdffontp->offset[i] = NULL;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
199 bdffontp->size = fileinfo.nFileSizeLow;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
200 bdffontp->font = font;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
201 bdffontp->hfile = hfile;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
202 bdffontp->hfilemap = hfilemap;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
203 bdffontp->filename = (char*) xmalloc(strlen(filename) + 1);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
204 strcpy(bdffontp->filename, filename);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
205
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
206 if (!set_bdf_font_info(bdffontp))
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
207 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
208 w32_free_bdf_font(bdffontp);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
209 error("Invalid BDF font!");
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
210 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
211 return bdffontp;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
212 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
213
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
214 void
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
215 w32_free_bdf_font(bdffont *fontp)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
216 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
217 int i;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
218
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
219 UnmapViewOfFile(fontp->hfilemap);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
220 CloseHandle(fontp->hfilemap);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
221 CloseHandle(fontp->hfile);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
222 xfree(fontp->filename);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
223 for(i = 0;i < BDF_FIRST_OFFSET_TABLE;i++)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
224 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
225 if (fontp->offset[i]) xfree(fontp->offset[i]);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
226 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
227 xfree(fontp);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
228 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
229
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
230 static unsigned char*
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
231 get_cached_char_offset(bdffont *fontp, int index)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
232 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
233 unsigned char **offset1;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
234 unsigned char *offset2;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
235 int i;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
236
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
237 if (index > 0xffff)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
238 return NULL;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
239
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
240 offset1 = fontp->offset[BDF_FIRST_OFFSET(index)];
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
241 if (!offset1)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
242 return NULL;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
243 offset2 = offset1[BDF_SECOND_OFFSET(index)];
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
244
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
245 if (offset2) return offset2;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
246
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
247 return NULL;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
248 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
249
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
250 static void
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
251 cache_char_offset(bdffont *fontp, int index, unsigned char *offset)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
252 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
253 unsigned char **offset1;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
254 int i;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
255
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
256 if (index > 0xffff)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
257 return;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
258
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
259 offset1 = fontp->offset[BDF_FIRST_OFFSET(index)];
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
260 if (!offset1)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
261 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
262 offset1 = fontp->offset[BDF_FIRST_OFFSET(index)] =
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
263 (unsigned char **) xmalloc(sizeof(unsigned char*) *
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
264 BDF_SECOND_OFFSET_TABLE);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
265 memset(offset1, 0, sizeof(unsigned char*) * BDF_SECOND_OFFSET_TABLE);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
266 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
267 offset1[BDF_SECOND_OFFSET(index)] = offset;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
268
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
269 return;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
270 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
271
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
272 static unsigned char*
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
273 seek_char_offset(bdffont *fontp, int index)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
274 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
275 int len, flag, font_index;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
276 unsigned char *start, *p, *q;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
277
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
278 if (!fontp->seeked) return NULL;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
279
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
280 start = fontp->seeked;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
281 len = fontp->size - (start - fontp->font);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
282
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
283 do {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
284 flag = proceed_file_line("ENCODING", start, &len, &p, &q);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
285 if (!flag)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
286 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
287 fontp->seeked = NULL;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
288 return NULL;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
289 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
290 font_index = atoi(p);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
291 cache_char_offset(fontp, font_index, q);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
292 start = q;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
293 } while (font_index != index);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
294 fontp->seeked = q;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
295
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
296 return q;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
297 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
298
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
299 #define GET_HEX_VAL(x) ((isdigit(x)) ? ((x) - '0') : \
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
300 (((x) >= 'A') && ((x) <= 'Z')) ? ((x) - 'A' + 10) : \
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
301 (((x) >= 'a') && ((x) <= 'z')) ? ((x) - 'a' + 10) : \
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
302 (-1))
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
303
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
304 int
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
305 w32_get_bdf_glyph(bdffont *fontp, int index, int size, glyph_struct *glyph)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
306 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
307 unsigned char *start, *p, *q, *bitmapp;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
308 unsigned char val1, val2;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
309 int i, j, len, flag;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
310
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
311 start = get_cached_char_offset(fontp, index);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
312 if (!start)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
313 start = seek_char_offset(fontp, index);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
314 if (!start)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
315 return 0;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
316
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
317 len = fontp->size - (start - fontp->font);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
318
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
319 flag = proceed_file_line("DWIDTH", start, &len, &p, &q);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
320 if (!flag)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
321 return 0;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
322 glyph->dwidth = atoi(p);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
323
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
324 start = q;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
325 flag = proceed_file_line("BBX", start, &len, &p, &q);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
326 if (!flag)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
327 return 0;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
328 glyph->bbw = strtol(p, &start, 10);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
329 p = start;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
330 glyph->bbh = strtol(p, &start, 10);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
331 p = start;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
332 glyph->bbox = strtol(p, &start, 10);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
333 p = start;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
334 glyph->bboy = strtol(p, &start, 10);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
335
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
336 if (size == 0) return 1;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
337
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
338 start = q;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
339 flag = proceed_file_line("BITMAP", start, &len, &p, &q);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
340 if (!flag)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
341 return 0;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
342
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
343 p = q;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
344 bitmapp = glyph->bitmap;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
345 for(i = 0;i < glyph->bbh;i++)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
346 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
347 q = memchr(p, '\n', len);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
348 if (!q) return 0;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
349 for(j = 0;((q > p) && (j < ((glyph->bbw + 7) / 8 )));j++)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
350 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
351 val1 = GET_HEX_VAL(*p);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
352 if (val1 == -1) return 0;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
353 p++;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
354 val2 = GET_HEX_VAL(*p);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
355 if (val2 == -1) return 0;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
356 p++;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
357 size--;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
358 if (size <= 0) return 0;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
359 /* NAND Operation. */
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
360 *bitmapp++ = (unsigned char)~((val1 << 4) | val2);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
361 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
362 /* CreateBitmap requires WORD alignment. */
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
363 if (j % 2)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
364 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
365 *bitmapp++ = 0xff;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
366 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
367 p = q + 1;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
368 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
369
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
370 return 1;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
371 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
372
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
373 int
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
374 w32_BDF_TextOut(bdffont *fontp, HDC hdc, int left,
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
375 int top, unsigned char *text, int dim, int bytelen,
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
376 int fixed_pitch_size)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
377 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
378 int bitmap_size, index, btop;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
379 unsigned char *textp;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
380 glyph_struct glyph;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
381 HDC hCompatDC = 0;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
382 HBITMAP hBMP;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
383 HBRUSH hFgBrush, hOrgBrush;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
384 HANDLE holdobj, horgobj = 0;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
385 UINT textalign;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
386 int flag = 0;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
387
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
388 bitmap_size = ((fontp->urx - fontp->llx) / 8 + 2) * (fontp->ury - fontp->lly)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
389 + 256;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
390
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
391 glyph.bitmap = (unsigned char*) alloca(sizeof(unsigned char) * bitmap_size);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
392
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
393 hCompatDC = CreateCompatibleDC(hdc);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
394
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
395 textalign = GetTextAlign(hdc);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
396
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
397 SaveDC(hdc);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
398
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
399 hFgBrush = CreateSolidBrush(GetTextColor(hdc));
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
400 hOrgBrush = SelectObject(hdc, hFgBrush);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
401 SetTextColor(hdc, RGB(0, 0, 0));
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
402 SetBkColor(hdc, RGB(0xff, 0xff, 0xff));
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
403
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
404 textp = text;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
405 while(bytelen > 0)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
406 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
407 if (dim == 1)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
408 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
409 index = *textp++;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
410 bytelen--;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
411 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
412 else
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
413 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
414 bytelen -= 2;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
415 if (bytelen < 0) break;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
416 index = MAKELENDSHORT(textp[1], textp[0]);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
417 textp += 2;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
418 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
419 if (!w32_get_bdf_glyph(fontp, index, bitmap_size, &glyph))
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
420 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
421 if (horgobj)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
422 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
423 SelectObject(hCompatDC, horgobj);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
424 DeleteObject(hBMP);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
425 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
426 DeleteDC(hCompatDC);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
427 return 0;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
428 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
429 hBMP = CreateBitmap(glyph.bbw, glyph.bbh, 1, 1, glyph.bitmap);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
430 if (textalign & TA_BASELINE)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
431 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
432 btop = top - (glyph.bbh + glyph.bboy);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
433 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
434 else if (textalign & TA_BOTTOM)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
435 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
436 btop = top - glyph.bbh;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
437 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
438 else
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
439 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
440 btop = top;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
441 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
442
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
443 if (horgobj)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
444 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
445 SelectObject(hCompatDC, hBMP);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
446 DeleteObject(holdobj);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
447 holdobj = hBMP;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
448 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
449 else
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
450 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
451 horgobj = SelectObject(hCompatDC, hBMP);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
452 holdobj = hBMP;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
453 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
454 #if 0
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
455 BitBlt(hdc, left, btop, glyph.bbw, glyph.bbh, hCompatDC, 0, 0, SRCCOPY);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
456 #else
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
457 BitBlt(hdc, left, btop, glyph.bbw, glyph.bbh, hCompatDC, 0, 0, 0xB8074A);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
458 #endif
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
459 if (fixed_pitch_size)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
460 left += fixed_pitch_size;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
461 else
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
462 left += glyph.dwidth;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
463 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
464 SelectObject(hCompatDC, horgobj);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
465 SelectObject(hdc, hOrgBrush);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
466 DeleteObject(hFgBrush);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
467 DeleteObject(hBMP);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
468 DeleteDC(hCompatDC);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
469 RestoreDC(hdc, -1);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
470
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
471 return 1;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
472 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
473
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
474 struct font_info *w32_load_bdf_font (struct frame *f, char *fontname,
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
475 int size, char* filename)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
476 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
477 struct w32_display_info *dpyinfo = FRAME_W32_DISPLAY_INFO (f);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
478 struct font_info *fontp;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
479 XFontStruct *font;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
480 bdffont* bdf_font;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
481
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
482 bdf_font = w32_init_bdf_font (filename);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
483
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
484 if (!bdf_font) return NULL;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
485
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
486 font = (XFontStruct *) xmalloc (sizeof (XFontStruct));
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
487
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
488 font->bdf = bdf_font;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
489 font->hfont = 0;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
490
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
491 /* Do we need to create the table? */
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
492 if (dpyinfo->font_table_size == 0)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
493 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
494 dpyinfo->font_table_size = 16;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
495 dpyinfo->font_table
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
496 = (struct font_info *) xmalloc (dpyinfo->font_table_size
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
497 * sizeof (struct font_info));
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
498 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
499 /* Do we need to grow the table? */
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
500 else if (dpyinfo->n_fonts
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
501 >= dpyinfo->font_table_size)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
502 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
503 dpyinfo->font_table_size *= 2;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
504 dpyinfo->font_table
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
505 = (struct font_info *) xrealloc (dpyinfo->font_table,
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
506 (dpyinfo->font_table_size
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
507 * sizeof (struct font_info)));
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
508 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
509
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
510 fontp = dpyinfo->font_table + dpyinfo->n_fonts;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
511
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
512 /* Now fill in the slots of *FONTP. */
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
513 BLOCK_INPUT;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
514 fontp->font = font;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
515 fontp->font_idx = dpyinfo->n_fonts;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
516 fontp->name = (char *) xmalloc (strlen (fontname) + 1);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
517 bcopy (fontname, fontp->name, strlen (fontname) + 1);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
518 fontp->full_name = fontp->name;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
519 fontp->size = FONT_WIDTH (font);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
520 fontp->height = FONT_HEIGHT (font);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
521
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
522 /* The slot `encoding' specifies how to map a character
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
523 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
524 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF, 0:0x2020..0x7F7F,
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
525 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF,
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
526 0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF, or
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
527 2:0xA020..0xFF7F). For the moment, we don't know which charset
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
528 uses this font. So, we set informatoin in fontp->encoding[1]
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
529 which is never used by any charset. If mapping can't be
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
530 decided, set FONT_ENCODING_NOT_DECIDED. */
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
531 fontp->encoding[1] = FONT_ENCODING_NOT_DECIDED;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
532 fontp->baseline_offset = bdf_font->yoffset;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
533 fontp->relative_compose = bdf_font->relative_compose;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
534 fontp->default_ascent = bdf_font->default_ascent;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
535
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
536 UNBLOCK_INPUT;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
537 dpyinfo->n_fonts++;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
538 return fontp;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
539 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
540
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
541 /* Check a file for an XFLD string describing it. */
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
542 int w32_BDF_to_x_font (char *file, char* xstr, int len)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
543 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
544 HANDLE hfile, hfilemap;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
545 BY_HANDLE_FILE_INFORMATION fileinfo;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
546 unsigned char *font, *start, *p, *q;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
547 int flag, size, retval = 0;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
548
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
549 hfile = CreateFile (file, GENERIC_READ, FILE_SHARE_READ, NULL,
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
550 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
551 if (hfile == INVALID_HANDLE_VALUE) return 0;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
552 if (!GetFileInformationByHandle(hfile, &fileinfo) ||
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
553 (fileinfo.nFileSizeHigh != 0) ||
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
554 (fileinfo.nFileSizeLow > BDF_FILE_SIZE_MAX))
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
555 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
556 CloseHandle (hfile);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
557 return 0;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
558 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
559 size = fileinfo.nFileSizeLow;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
560
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
561 hfilemap = CreateFileMapping (hfile, NULL, PAGE_READONLY, 0, 0, NULL);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
562 if (hfilemap == INVALID_HANDLE_VALUE)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
563 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
564 CloseHandle (hfile);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
565 return 0;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
566 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
567
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
568 font = MapViewOfFile (hfilemap, FILE_MAP_READ, 0, 0, 0);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
569 if (!font)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
570 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
571 CloseHandle (hfile);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
572 CloseHandle (hfilemap);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
573 return 0;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
574 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
575 start = font;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
576
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
577 flag = proceed_file_line ("FONT ", start, &size, &p, &q);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
578 if (flag)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
579 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
580 /* If font provides a description of itself, check it is a
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
581 full XLFD before accepting it. */
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
582 int count = 0;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
583 char *s;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
584
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
585 for (s = p; s < q; s++)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
586 if (*s == '\n')
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
587 break;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
588 else if (*s == '-')
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
589 count++;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
590 if (count == 14 && q - p - 1 <= len)
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
591 {
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
592 strncpy (xstr, p, q-p-1);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
593 xstr[q-p-1] = '\0';
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
594 /* Files may have DOS line ends (ie still ^M on end). */
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
595 if (iscntrl(xstr[q-p-2]))
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
596 xstr[q-p-2] = '\0';
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
597
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
598 retval = 1;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
599 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
600 }
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
601 CloseHandle (hfile);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
602 CloseHandle (hfilemap);
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
603 return retval;
db9dfcd11c84 Initial revision
Geoff Voelker <voelker@cs.washington.edu>
parents:
diff changeset
604 }