annotate lib-src/mule/bdf.c @ 123:c77884c6318d

Added tag r20-1b14 for changeset d2f30a177268
author cvs
date Mon, 13 Aug 2007 09:26:04 +0200
parents 131b0175ea99
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1 /* bdfstaff Ver.2.2 -- BDF utilities
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2 Copyright (C) 1992 Free Software Foundation, Inc. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4 /* This file is part of Mule (MULtilingual Enhancement of GNU Emacs).
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
5
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
6 Mule is free software distributed in the form of patches to GNU Emacs.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
7 You can redistribute it and/or modify
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
8 it under the terms of the GNU General Public License as published by
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
9 the Free Software Foundation; either version 1, or (at your option)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
10 any later version.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
11
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
12 Mule is distributed in the hope that it will be useful,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
15 GNU General Public License for more details.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
16
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
18 along with GNU Emacs; see the file COPYING. If not, write to
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
20
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
21 /* 92.10.14 written by K.Handa <handa@etl.go.jp> */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
22 /* 92.10.21 modified for Mule 0.9.6 with DOS support
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
23 by M.Higashida <manabu@sigmath.osaka-u.ac.jp> */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
24 /* 92.11.3 modified for Mule Ver.0.9.7
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
25 by T.Matsuzawa <mzw_t@hpujisa.yhp.co.jp>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
26 Support NONSPACING characters and send smaller bitmap. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
27 /* 92.11.10 modified for Mule Ver.0.9.7
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
28 by K.Sakaeda <saka@tomorose.trad.pfu.fujitsu.co.jp>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
29 Modified for SystemV. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
30 /* 92.11.24 modified for Mule Ver.0.9.7 by K.Handa <handa@etl.go.jp>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
31 Modified to reduce memory. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
32 /* 92.12.15 modified for Mule Ver.0.9.7 by K.Handa <handa@etl.go.jp>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
33 Look FONTPROPERTIES. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
34 /* 93.1.13 modified for Mule Ver.0.9.7.1
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
35 by T.Furuhata <furuhata@fujita3.iis.u-tokyo.ac.jp>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
36 Modified for AIX. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
37 /* 93.2.10 modified for Mule Ver.0.9.7.1 by K.Handa <handa@etl.go.jp>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
38 In bdf_fopen(), declaration of 'path' is changed. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
39 /* 93.3.15 modified for Mule Ver.0.9.7.1 by K.Handa <handa@etl.go.jp>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
40 For AIX, now we don't need "#pragma alloca". */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
41 /* 93.5.7 modified for Mule Ver.0.9.8 by K.Handa <handa@etl.go.jp>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
42 In bdf_load_font(), bug fixed in handling private char-set. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
43 /* 93.5.7 modified for Mule Ver.0.9.8 by K.Handa <handa@etl.go.jp>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
44 In bdf_load_font(), use value of PIXEL_SIZE instead of BBH.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
45 Support right-to-left character.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
46 Support Big5. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
47 /* 93.7.19 modified for Mule Ver.0.9.8 by K.Handa <handa@etl.go.jp>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
48 Stop including "codeconv.h". */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
49 /* 94.3.9 modified for Mule Ver.1.1 by Y.Niibe <gniibe@oz.etl.go.jp>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
50 In bdf_load_font(), fontp->extra->fs should not be set in emacs. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
51
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
52 #include <stdio.h>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
53 #include <sys/param.h>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
54 #include <sys/types.h>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
55 #include <fcntl.h>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
56 #include <sys/file.h>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
57 #include "mulelib.h"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
58 #ifdef USG
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
59 #include <string.h>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
60 #else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
61 #include <strings.h>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
62 #endif
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
63
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
64 static int in_emacs;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
65
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
66 char *bdf_path;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
67
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
68 font_struct *font;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
69 glyph_struct glyph;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
70 static char *line, *dummy;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
71 #ifndef LINE_BUF_SIZE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
72 #define LINE_BUF_SIZE 256
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
73 #endif
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
74
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
75 bdf_reset_font(fontp)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
76 font_struct *fontp;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
77 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
78 int size1, size2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
79 font_extra *ext;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
80
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
81 if (fontp->bytes == 1) size1 = size2 = 256;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
82 else size1 = 0x10000, size2 = size1 / 32;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
83
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
84 if (fontp->offset == NULL) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
85 fontp->offset = (long *)malloc((sizeof (long)) * size1);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
86 bzero(fontp->offset, (sizeof (long)) * size1);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
87 if (in_emacs) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
88 fontp->extra = (char **)malloc((sizeof (char *)) * size1);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
89 bzero(fontp->extra, (sizeof (char *)) * size1);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
90 } else {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
91 fontp->extra = (char **)malloc(sizeof *ext);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
92 ext = (font_extra *)(fontp->extra);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
93 ext->defined = (unsigned int *)malloc((sizeof (int)) * size2);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
94 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
95 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
96 if (!in_emacs) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
97 bzero(ext->defined, (sizeof (int)) * size2);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
98 bzero(ext->code, (sizeof (int)) * 256);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
99 bzero(ext->count, (sizeof (int)) * 256);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
100 bzero(ext->new, (sizeof (char)) * 256);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
101 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
102 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
103
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
104 bdf_init_font()
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
105 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
106 int i, lc;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
107
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
108 font = (font_struct *)malloc((sizeof (font_struct)) * 128);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
109 for (i = 0; i < 128; i++) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
110 font[i].fp = NULL;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
111 font[i].loaded = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
112 font[i].offset = NULL;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
113 font[i].bytes = char_type[i == 0 ? i : i + 128] < TYPE94N ? 1 : 2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
114 font[i].filename = font_name[i];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
115 font[i].encoding = font_encoding[i];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
116 lc = (i == 0) ? i : i | 0x80;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
117 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
118 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
119
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
120 bdf_init_glyph(glyphp)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
121 glyph_struct *glyphp;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
122 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
123 glyphp->bitmap_size = 100;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
124 glyphp->bitmap = (char *)malloc(glyph.bitmap_size * (sizeof (char)));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
125 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
126
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
127 bdf_initialize(bp, _emacs)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
128 char *bp;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
129 int _emacs;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
130 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
131 in_emacs = _emacs;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
132 line = (char *)malloc(LINE_BUF_SIZE);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
133 dummy = (char *)malloc(LINE_BUF_SIZE);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
134 bdf_path = (bp != NULL ? bp : getenv("BDFPATH"));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
135 if (bdf_path == NULL) bdf_path = BDF_PATH;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
136 bdf_init_font();
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
137 bdf_init_glyph(&glyph);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
138 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
139
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
140 bdf_proceed_line(fp, str)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
141 FILE *fp;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
142 char *str;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
143 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
144 int len = strlen(str);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
145 do {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
146 if (fgets(line, LINE_BUF_SIZE, fp) == NULL)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
147 return 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
148 } while (strncmp(line, str, len));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
149 return 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
150 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
151
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
152 bdf_proceed_line2(fp, str, stop)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
153 FILE *fp;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
154 char *str, *stop;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
155 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
156 int len1 = strlen(str), len2 = strlen(stop);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
157 do {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
158 if (fgets(line, LINE_BUF_SIZE, fp) == NULL
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
159 || !strncmp(line, stop, len2))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
160 return 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
161 } while (strncmp(line, str, len1));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
162 return 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
163 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
164
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
165 bdf_load_font(lc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
166 int lc;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
167 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
168 font_struct *fontp = &font[lc & 0x7F];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
169 int i, j, bbw, bbh, bbox, bboy;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
170 unsigned int idx;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
171
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
172 if (fontp->filename == NULL
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
173 || (fontp->fp = open_file(bdf_path, fontp->filename)) == NULL) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
174 if (lc == 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
175 fatal1("Font for ASCII not found.\n");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
176 warning2("Font(%d:%s) not found. Substituted by ASCII font.\n",
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
177 lc, fontp->filename);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
178 *fontp = font[0];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
179 fontp->loaded = -1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
180 return 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
181 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
182
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
183 bdf_reset_font(fontp);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
184
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
185 bdf_proceed_line(fontp->fp, "FONTBOUNDINGBOX ");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
186 sscanf(line, "%s %d %d %d %d", dummy, &bbw, &bbh, &bbox, &bboy);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
187 fontp->llx = bbox, fontp->lly = bboy;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
188 fontp->urx = bbw + bbox, fontp->ury = bbh + bboy;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
189 fontp->yoffset = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
190 fontp->relative_compose = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
191 if (!in_emacs)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
192 ((font_extra *)fontp->extra)->fs = bbh;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
193 if (bdf_proceed_line2(fontp->fp, "STARTPROPERTIES ", "CHARS ")) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
194 do {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
195 /* If there are properties of PIXEL_SIZE, FONT_ASCENT, FONT_DESCENT,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
196 we believe them rather than FONTBOUNDINGBOX.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
197 In addition, we also look private properties _MULE_BASELINE_OFFSET
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
198 and _MULE_RELATIVE_COMPOSE. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
199 if (fgets(line, LINE_BUF_SIZE, fontp->fp) == NULL)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
200 return 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
201 if (!strncmp(line, "PIXEL_SIZE ", 11)) { /* 93.5.7 by K.Handa */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
202 if (!in_emacs) { /* 94.3.9 by Y.Niibe */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
203 sscanf(line, "%s %d", dummy, &i);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
204 ((font_extra *)fontp->extra)->fs = i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
205 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
206 } else if (!strncmp(line, "FONT_ASCENT ", 12)) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
207 sscanf(line, "%s %d", dummy, &fontp->ury);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
208 } else if (!strncmp(line, "FONT_DESCENT ", 13)) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
209 sscanf(line, "%s %d", dummy, &i);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
210 fontp->lly = - i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
211 } else if (!strncmp(line, "_MULE_BASELINE_OFFSET ", 22)) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
212 sscanf(line, "%s %d", dummy, &i);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
213 fontp->yoffset = - i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
214 } else if (!strncmp(line, "_MULE_RELATIVE_COMPOSE ", 23)) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
215 sscanf(line, "%s %d", dummy, &fontp->relative_compose);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
216 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
217 } while (strncmp(line, "ENDPROPERTIES", 13));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
218 bdf_proceed_line(fontp->fp, "CHARS ");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
219 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
220 sscanf(line, "%s %d", dummy, &(fontp->chars));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
221 fontp->last_offset = ftell(fontp->fp);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
222 fontp->loaded = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
223 if (fontp->bytes == 2) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
224 fontp->yoffset
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
225 = (((fontp->ury + fontp->lly) - (font[0].ury + font[0].lly - font[0].yoffset * 2)) / 2)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
226 * ((font_extra *)font[0].extra)->fs / ((font_extra *)fontp->extra)->fs;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
227 printf("%%yoffset of %d(%d) is %d\n", lc, ((font_extra *)font[0].extra)->fs, fontp->yoffset);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
228
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
229 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
230 return 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
231 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
232
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
233 bdf_load_glyph(lc, idx, glyph)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
234 int lc, idx;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
235 glyph_struct *glyph;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
236 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
237 font_struct *fontp = &font[lc & 0x7F];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
238 int i, j;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
239 int width, size;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
240 int h0, h1, k;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
241
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
242 if (fontp->fp == NULL) goto glyph_not_found;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
243
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
244 if (fontp->offset[idx]) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
245 fseek(fontp->fp, fontp->offset[idx], 0);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
246 } else {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
247 fseek(fontp->fp, fontp->last_offset, 0);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
248 i = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
249 while (fontp->chars-- > 0) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
250 bdf_proceed_line(fontp->fp, "ENCODING ");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
251 sscanf(line, "%s %d", dummy, &i);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
252 fontp->offset[i] = fontp->last_offset = ftell(fontp->fp);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
253 if (i == idx) break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
254 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
255 if (i != idx) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
256 if (fontp->offset[idx & 0x7F7F]) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
257 fontp->offset[idx] = fontp->offset[idx & 0x7F7F];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
258 fseek(fontp->fp, fontp->offset[idx], 0);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
259 } else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
260 goto glyph_not_found;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
261 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
262 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
263
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
264 bdf_proceed_line(fontp->fp, "DWIDTH ");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
265 sscanf(line, "%s %d", dummy, &(glyph->dwidth));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
266 bdf_proceed_line(fontp->fp, "BBX ");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
267 sscanf(line, "%s %d %d %d %d",
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
268 dummy, &(glyph->bbw), &(glyph->bbh), &(glyph->bbox), &(glyph->bboy));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
269 bdf_proceed_line(fontp->fp, "BITMAP");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
270 width = ((glyph->bbw + 7) / 8) * 2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
271 size = width * glyph->bbh + 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
272 if (glyph->bitmap_size < size)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
273 glyph->bitmap_size = size, glyph->bitmap = (char *)realloc(glyph->bitmap, size);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
274
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
275 h0 = h1 = -1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
276 j = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
277 for ( i = 0; i < glyph->bbh; i++ ) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
278 if (!fgets(line, LINE_BUF_SIZE, fontp->fp)) goto glyph_not_found;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
279 line[width] = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
280 for ( k = 0; k < width; k++ ) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
281 if ( line[k] != '0' ) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
282 if ( h0 < 0 ) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
283 h0 = i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
284 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
285 if ( h1 < i ) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
286 h1 = i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
287 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
288 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
289 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
290 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
291 if ( h0 < 0 ) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
292 continue;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
293 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
294 sprintf(glyph->bitmap + j, "%s", line);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
295 j += width;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
296 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
297 glyph->bitmap[j] = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
298 if ( h0 < 0 && h1 < 0 ) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
299 h0 = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
300 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
301 glyph->bboy += ( glyph->bbh - h1 - 1) - fontp->yoffset;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
302 glyph->bbh = ( h1 - h0 + 1 );
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
303 glyph->bitmap_size = width * glyph->bbh + 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
304 glyph->bitmap = (char *)realloc(glyph->bitmap, size );
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
305 glyph->bitmap[glyph->bitmap_size - 1] = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
306 return 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
307
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
308 glyph_not_found:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
309 warning3("Glyph of char(%d) for font(%d:%s) not found.\n",
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
310 idx, lc, fontp->filename);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
311 return 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
312 }