annotate lib-src/mule/m2ps.c @ 94:1040fe1366ac xemacs-20-0f2

Import from CVS: tag xemacs-20-0f2
author cvs
date Mon, 13 Aug 2007 09:12:09 +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 /* m2ps Ver.2.2 -- Convert multilingual text to PostScript
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.8 written by K.Handa <handa@etl.go.jp> */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
22 /* 92.11.3 modified for Mule Ver.0.9.7
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
23 by T.Matsuzawa <mzw_t@hpujisa.yhp.co.jp>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
24 Support NONSPACING characters and send smaller bitmap. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
25 /* 92.11.6 modified for Mule Ver.0.9.7 by K.Shibata <shibata@sgi.co.jp>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
26 Modified for ANSI-C. */
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.14 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 Support composite character. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
34 /* 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
35 Bug in handling missing font fixed.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
36 Support Big5. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
37 /* 93.5.29 modified for Mule Ver.0.9.8 by Y.Niibe <gniibe@mri.co.jp>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
38 Include config.h in src directory */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
39 /* 93.6.4 modified for Mule Ver.0.9.8 by K.Shibata <shibata@sgi.co.jp>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
40 Modified for ANSI-C. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
41 /* 93.12.25 modified for Mule Ver.1.0 by K.Handa <handa@etl.go.jp>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
42 In textmode(), bug of right-to-left handling fixed */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
43 /* 94.3.8 modified for Mule Ver.1.1 by K.Handa <handa@etl.go.jp>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
44 Bug in find_encoding() fixed. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
45 /* See `mule/ChangeLog.Mule' for the recent change log */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
46
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
47 #include <stdio.h>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
48 #include <fcntl.h>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
49 #include <sys/types.h>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
50 #include <sys/file.h>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
51 #include "mulelib.h"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
52
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
53 static char *m2ps_version = "2.2";
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
54
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
55 #ifndef PSHeader
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
56 #define PSHeader "m2ps.ps"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
57 #endif
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
58
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
59 #ifndef DPI
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
60 #define DPI 300
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
61 #endif
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
62
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
63 #ifndef FontScale
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
64 #define FontScale 10
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
65 #endif
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
66
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
67 #ifndef LinePitch
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
68 #define LinePitch 14
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
69 #endif
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
71 /* Parameters for A4 paper */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
72 #define A4_MaxLine 56
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
73 #define A4_TopMargin 800
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
74
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
75 /* Parameters for US-LETTER paper */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
76 #define US_MaxLine 50
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
77 #define US_TopMargin 746
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
78
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
79 #ifndef USLETTER
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
80
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
81 #ifndef MaxLine
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
82 #define MaxLine A4_MaxLine
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
83 #endif
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
84
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
85 #ifndef TopMargin
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
86 #define TopMargin A4_TopMargin
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
87 #endif
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
88
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
89 #else /* US-LETTER */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
90
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
91 #ifndef MaxLine
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
92 #define MaxLine US_MaxLine
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
93 #endif
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
94
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
95 #ifndef TopMargin
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
96 #define TopMargin US_TopMargin
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
97 #endif
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
98
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
99 #endif /* US-LETTER */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
100
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
101 #ifndef LeftMargin
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
102 #define LeftMargin 30 /* To widen left margin, specify larger value. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
103 #endif
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
104
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
105 #ifndef ShortMemory
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
106 #define ShortMemory 0
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
107 #endif
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
108
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
109 char *psheader = PSHeader;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
110 int dpi = DPI;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
111 int fontscale = FontScale;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
112 int linepitch = LinePitch;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
113 int maxline = MaxLine;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
114 int topmargin = TopMargin;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
115 int leftmargin = LeftMargin;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
116 int shortmemory = ShortMemory;
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 /* Main staffs */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
120 /***************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
121
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
122 /* GLOBAL VARIABLES */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
123 int clm, row, current_lc;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
124
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
125 set_font(lc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
126 int lc;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
127 { /* 93.5.7, 94.11.29 by K.Handa -- Big change */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
128 if (FONT_LOADED (lc) == 0) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
129 if (bdf_load_font(lc))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
130 ps_newfont(lc);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
131 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
132 lc = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
133 } else if (FONT_LOADED (lc) < 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
134 lc = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
135 if (lc != current_lc) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
136 ps_setfont(lc);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
137 current_lc = lc;
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
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
141 renew_font(lc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
142 int lc;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
143 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
144 bzero(((font_extra *)font[lc & 0x7F].extra)->new, 256 * (sizeof (char)));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
145 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
146
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
147 /* Load specified glyph, then return the index to glyph. Note the index
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
148 is within the range of [0,255]. Return -1 if error. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
149 set_glyph1(lc, c)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
150 int lc, c;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
151 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
152 if (!DEFINED1(lc, c)) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
153 if (bdf_load_glyph(lc, c, &glyph)) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
154 ps_newglyph(c, &glyph);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
155 DEFINE1(lc, c);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
156 } else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
157 return -1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
158 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
159 return c;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
160 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
161
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
162 find_encoding(fontp, lc, c)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
163 font_struct *fontp;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
164 int lc, c;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
165 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
166 font_extra *ext = (font_extra *)fontp->extra;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
167 int i, min_count = ext->count[0], j = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
168
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
169 if (min_count > 0) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
170 min_count = 0x7FFF; /* 94.3.8 by K.Handa */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
171 for (i = 0; i < 256; i++) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
172 if (ext->count[i] <= min_count && !ext->new[i]) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
173 min_count = ext->count[i], j = i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
174 if (min_count == 0) break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
175 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
176 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
177 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
178 if (min_count > 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
179 UNDEFINE2(lc, ext->code[j]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
180
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
181 ext->count[j] = ext->new[j] = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
182 ext->code[j] = c;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
183 DEFINE2(lc, ext->code[j]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
184 return j;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
185 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
186
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
187 /* Load specified glyph, replacing previously loaded glyph if necessary,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
188 then return the index to glyph. Note the index is within the range
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
189 of [0,255]. Return -1 if error. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
190 set_glyph2(lc, c)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
191 int lc, c;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
192 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
193 int code;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
194 font_struct *fontp = &font[lc & 0x7F];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
195 font_extra *ext = (font_extra *)fontp->extra;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
196
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
197 if (!DEFINED2(lc, c)) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
198 if (bdf_load_glyph(lc, c, &glyph)) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
199 code = find_encoding(fontp, lc, c);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
200 ps_newglyph(code, &glyph);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
201 } else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
202 return -1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
203 } else {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
204 for (code = 0; code < 256; code++) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
205 if (ext->code[code] == c) break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
206 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
207 ext->new[code] = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
208 ext->count[code]++;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
209 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
210 return code;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
211 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
212
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
213 swap_buf(buf, from, to)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
214 unsigned char *buf;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
215 int from, to;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
216 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
217 int i, j;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
218 unsigned char buf2[1024], *p = buf2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
219
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
220 i = j = to;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
221 while (--i >= from) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
222 if (NONASCII_P(buf[i])) continue;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
223 bcopy(buf + i, p, j - i);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
224 p += j - i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
225 j = i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
226 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
227 bcopy(buf2, buf + from, to - from);
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 textmode()
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
231 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
232 register int i, j, k, c, lc;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
233 char buf[1024]; /* 92.11.6 by K.Shibata */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
234 unsigned char line[1024], *p;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
235 int cmp_flag = 0, len, r2l_chars;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
236
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
237 ps_bot(); ps_bop();
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
238 clm = row = 0; current_lc = -1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
239 /* set_font(0); */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
240 while ((len = get_line(line, 1024, stdin)) >= 0) { /* 93.6.4 by K.Shibata */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
241 /* We should process line by line to handle r2l direction. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
242 j = 0; r2l_chars = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
243
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
244 /* At first, re-order characters of r2l direction. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
245 while (j < len) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
246 p = line + j;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
247 if (*p <= 0x7F) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
248 lc = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
249 p++;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
250 } else {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
251 lc = *p++;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
252 if (lc == LCCMP) lc = *p++ - 0x20;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
253 if (lc >= LCPRV11) lc = *p++;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
254 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
255 while (NONASCII_P(*p)) p++;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
256 if (char_direction[lc]) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
257 if (!r2l_chars) k = j;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
258 r2l_chars++;
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 if (r2l_chars > 1)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
261 swap_buf(line, k, j);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
262 r2l_chars = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
263 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
264 j = p - line;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
265 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
266 if (r2l_chars > 1) swap_buf(line, k, j); /* 93.12.25 by K.Handa */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
267
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
268 /* Then output characters. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
269 for (j = 0; j < len;) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
270 c = line[j];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
271
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
272 if (c == LCCMP) { /* start of composite characters */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
273 cmp_flag = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
274 j++;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
275 continue;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
276 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
277 if (cmp_flag) { /* composed characters have special encoding */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
278 if (c == 0xA0) c = line[++j] & 0x7F;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
279 else if (c > 0xA0) c -= 0x20;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
280 else cmp_flag = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
281 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
282
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
283 if (c < 0x20 || c == 0x7F) { /* Control code */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
284 switch (c) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
285 case '\t':
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
286 i = 8 - (clm % 8);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
287 clm += i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
288 set_font(0);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
289 if (set_glyph1(0, ' ') >= 0) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
290 putchar('(');
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
291 while (i--) putchar(' ');
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
292 printf(") s ");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
293 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
294 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
295 case '\f':
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
296 ps_eop(), ps_bop();
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
297 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
298 default:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
299 if (c < ' ') control_char(c);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
300 else invalid_char(c);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
301 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
302 j++;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
303 } else if (c < 0x7F) { /* ASCII */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
304 set_font(0);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
305 i = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
306 do {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
307 if ((c = set_glyph1(0, c)) >= 0) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
308 if (c == '\\' || c == '(' || c == ')')
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
309 buf[i++] = '\\', buf[i++] = c;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
310 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
311 buf[i++] = c;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
312 clm++;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
313 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
314 c = line[++j];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
315 } while (!cmp_flag /* process composite character one by one */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
316 && 0x20 <= c && c < 0x7F);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
317 buf[i] = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
318 switch (cmp_flag) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
319 case 0: /* not composite character */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
320 printf("(%s) s ", buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
321 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
322 case 1: /* first of composite character */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
323 printf("(%s) cs1 ", buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
324 cmp_flag = 2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
325 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
326 default: /* case 2: rest of composite character*/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
327 if (font[0].relative_compose)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
328 printf("(%s) cs2 ", buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
329 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
330 printf("(%s) cs3 ", buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
331 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
332 } else if (c < LCINV) { /* Multilingual character */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
333 int cur_lc = c < LCPRV11 ? c : line[j + 1];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
334 CCL_PROGRAM *ccl = x_ccl_programs[cur_lc & 0x7F];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
335 unsigned char c1, c2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
336
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
337 set_font(cur_lc);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
338 i = 0, lc = cur_lc;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
339 while (1) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
340 if (lc >= LCPRV11) lc = line[j + 1];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
341 if (lc != cur_lc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
342 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
343 if (lc < LCJPOLD) c1 = 0, c2 = line[j + 1], j += 2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
344 else if (lc < LCPRV11) c1 = line[j + 1], c2 = line[j + 2], j += 3;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
345 else if (lc < LCPRV21EXT) c1 = 0, c2 = line[j + 2], j += 3;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
346 else c1 = line[j + 2], c2 = line[j + 3], j += 4;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
347 if (!ccl) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
348 c = c1 * 256 + c2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
349 } else {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
350 ccl->reg[0] = c1; ccl->reg[1] = c2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
351 ccl_driver (ccl, NULL, NULL, 0, 0);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
352 c = ccl->reg[0] * 256 + ccl->reg[1];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
353 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
354 if (current_lc != lc) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
355 /* Font is not found. Use ASCII to write the code. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
356 c &= 0x7F;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
357 if (c >= ' ' && c <= 126)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
358 c = set_glyph1(0, c & 0x7F);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
359 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
360 c = set_glyph1(0, ' ');
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
361 } else if (char_type[lc] < TYPE94N)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
362 c = set_glyph1(lc, c);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
363 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
364 c = set_glyph2(lc, c);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
365 if (c >= 0) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
366 if (c == '\\' || c == '(' || c == ')')
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
367 buf[i++] = '\\', buf[i++] = c;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
368 else if (c >= ' ' && c < 127)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
369 buf[i++] = c;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
370 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
371 sprintf(buf + i, "\\%03o", c), i += 4;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
372 clm += lc < 0x90 || (lc >= LCPRV11EXT && lc < LCPRV21EXT) ? 1 : 2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
373 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
374 if (cmp_flag) break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
375 lc = line[j];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
376 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
377 buf[i] = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
378 switch (cmp_flag) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
379 case 0:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
380 printf("(%s) s ", buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
381 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
382 case 1:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
383 printf("(%s) cs1 ", buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
384 cmp_flag = 2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
385 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
386 case 2:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
387 default:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
388 if (font[lc & 0x7F].relative_compose)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
389 printf("(%s) cs2 ", buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
390 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
391 printf("(%s) cs3 ", buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
392 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
393 renew_font(cur_lc);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
394 } else {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
395 invalid_char(c);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
396 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
397 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
398 printf("n\n");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
399 row++, clm = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
400 if (row >= maxline) ps_eop(), ps_bop();
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
401 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
402
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
403 ps_eop();
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
404 ps_eot();
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
405 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
406
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
407 control_char(c)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
408 int c;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
409 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
410 c += '@';
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
411 set_font(0);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
412 if ((set_glyph1(0, '^') >= 0) && (set_glyph1(0, c) >= 0)) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
413 printf("(^%c) s ", c);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
414 clm += 2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
415 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
416 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
417
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
418 invalid_char(c)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
419 int c;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
420 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
421 int i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
422
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
423 set_font(0);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
424 if (set_glyph1(0, '\\') >= 0) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
425 for (i = '0'; i <= '9'; i++) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
426 if (set_glyph1(0, i) < 0) break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
427 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
428 if (i > '9') {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
429 printf("(\\\\%03o) s ", c);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
430 clm += 4;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
431 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
432 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
433 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
434
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
435 main(argc, argv)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
436 int argc;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
437 char *argv[];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
438 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
439 register int i = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
440 char *bdf_path = NULL, *charsets = NULL;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
441
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
442 while (i < argc) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
443 if (!strcmp(argv[i], "-ps") && (i + 1) < argc) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
444 psheader = argv[i + 1];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
445 i += 2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
446 } else if (!strcmp(argv[i], "-fp") && (i + 1) < argc) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
447 bdf_path = argv[i + 1];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
448 i += 2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
449 } else if (!strcmp(argv[i], "-cs") && (i + 1) < argc) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
450 charsets = argv[i + 1];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
451 i += 2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
452 } else if (!strcmp(argv[i], "-dpi") && (i + 1) < argc) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
453 dpi = atoi(argv[i + 1]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
454 i += 2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
455 } else if (!strcmp(argv[i], "-fs") && (i + 1) < argc) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
456 fontscale = atoi(argv[i + 1]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
457 i += 2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
458 } else if (!strcmp(argv[i], "-lp") && (i + 1) < argc) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
459 linepitch = atoi(argv[i + 1]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
460 i += 2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
461 } else if (!strcmp(argv[i], "-ml") && (i + 1) < argc) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
462 maxline = atoi(argv[i + 1]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
463 i += 2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
464 } else if (!strcmp(argv[i], "-tm") && (i + 1) < argc) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
465 topmargin = atoi(argv[i + 1]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
466 i += 2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
467 } else if (!strcmp(argv[i], "-lm") && (i + 1) < argc) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
468 leftmargin = atoi(argv[i + 1]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
469 i += 2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
470 } else if (!strcmp(argv[i], "-sm")) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
471 shortmemory = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
472 i++;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
473 } else if (!strcmp(argv[i], "-bm")) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
474 shortmemory = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
475 i++;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
476 } else if (!strcmp(argv[i], "-a4") || !strcmp(argv[i], "-A4")) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
477 maxline = A4_MaxLine;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
478 topmargin = A4_TopMargin;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
479 i++;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
480 } else if (!strcmp(argv[i], "-us") || !strcmp(argv[i], "-US")) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
481 maxline = US_MaxLine;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
482 topmargin = US_TopMargin;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
483 i++;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
484 } else if (!strncmp(argv[i], "-ver", 4)) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
485 printf("m2ps Ver.%s\n", m2ps_version);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
486 exit(0);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
487 } else {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
488 fprintf(stderr, "%s: Invalid argument: %s\n", argv[0], argv[i]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
489 exit(1);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
490 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
491 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
492
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
493 mulelib_initialize(argc, argv, charsets, NULL);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
494 bdf_initialize(bdf_path, 0);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
495 textmode();
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
496 exit(0);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
497 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
498
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
499 /*********************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
500 /* PostScript staffs */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
501 /*********************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
502
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
503 ps_bot()
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
504 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
505 int c;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
506 FILE *fp;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
507
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
508 if ((fp = open_file(PATH_DATA, psheader)) == NULL)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
509 fatal1("PostScript header file not found.");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
510
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
511 while ((c = getc(fp)) != EOF) putchar(c);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
512 fclose(fp);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
513 printf("Mydict begin\n");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
514 printf("/DPI %d def\n", dpi);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
515 printf("/FontScale %d def\n", fontscale);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
516 printf("/LinePitch %d def\n", linepitch);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
517 printf("/TopMargin %d def\n", topmargin);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
518 printf("/LeftMargin %d def\n", leftmargin);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
519 printf("/ShortMemory %s def\n", (shortmemory ? "true" : "false"));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
520 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
521
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
522 ps_eot()
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
523 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
524 printf("end\n");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
525 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
526
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
527 /* Define new PS font for a leading char LC.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
528 No_cache flag is for the fonts be modified (replacing the glyphs, etc.)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
529 at execution time. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
530 ps_newfont(lc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
531 int lc;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
532 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
533 font_struct *fontp = &font[lc & 0x7F];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
534
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
535 printf("/F%02x /FF%02x %d [%d %d %d %d] %d %s nf\n",
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
536 lc, lc, ((font_extra *)fontp->extra)->fs,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
537 fontp->llx, fontp->lly - fontp->yoffset,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
538 fontp->urx, fontp->ury - fontp->yoffset,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
539 fontp->relative_compose,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
540 (fontp->bytes == 1 ? "true" : "false"));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
541 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
542
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
543 ps_setfont(lc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
544 int lc;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
545 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
546 printf("F%02x f\n", lc);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
547 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
548
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
549 ps_newglyph(encoding, glyph)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
550 int encoding;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
551 glyph_struct *glyph;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
552 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
553 char *bitmap = glyph->bitmap;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
554
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
555 if (*bitmap == '\0')
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
556 bitmap = "00";
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
557
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
558 printf("/C%d%s[ %d %d %d %d %d %d %d %d %d <%s> ] g\n",
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
559 encoding, (encoding < 10 ? "XX " : encoding < 100 ? "X " : " "),
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
560 glyph->dwidth,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
561 glyph->bbox, glyph->bboy,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
562 glyph->bbw + glyph->bbox, glyph->bbh + glyph->bboy,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
563 glyph->bbw, glyph->bbh,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
564 glyph->bbox, glyph->bbh + glyph->bboy,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
565 bitmap);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
566 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
567
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
568 ps_bop()
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
569 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
570 int lc;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
571
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
572 row = clm = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
573 printf("bp\n");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
574 if (shortmemory) {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
575 current_lc = -1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
576 for (lc = 0; lc < 256; lc++) { /* 93.5.7 by K.Handa */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
577 if (FONT_LOADED (lc) == 1) FONT_LOADED (lc) = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
578 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
579 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
580 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
581
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
582 ps_eop()
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
583 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
584 printf("ep\n");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
585 }