オープンソース・ソフトウェアの開発とダウンロード

CVS リポジトリの参照

Contents of /neotype/neotype/scmprims.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Wed Jan 15 09:20:10 2003 UTC (21 years, 4 months ago) by torus
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +0 -0 lines
File MIME type: text/x-csrc
(none)

1 // Guile 関数の定義。
2 // $Id: scmprims.c,v 1.2 2002/07/30 12:45:04 toru Exp $
3
4 #include <guile/gh.h>
5 #include <stdio.h>
6
7 #include "util.h"
8 #include "pdf.h"
9 #include "parse.h"
10 #include "scmprims.h"
11
12 void
13 nt_scm_register_procs ()
14 {
15
16 gh_new_procedure ("nt-set-text-pos", nt_scm_set_text_pos, 2, 0, 0);
17 gh_new_procedure ("nt-font", nt_scm_font, 3, 0, 0);
18 gh_new_procedure ("nt-rotate", nt_scm_rotate, 1, 0, 0);
19 gh_new_procedure ("nt-translate", nt_scm_translate, 2, 0, 0);
20 gh_new_procedure ("nt-show", nt_scm_show, 1, 0, 0);
21 gh_new_procedure ("nt-moveto", nt_scm_moveto, 2, 0, 0);
22 gh_new_procedure ("nt-lineto", nt_scm_lineto, 2, 0, 0);
23 gh_new_procedure ("nt-stroke", nt_scm_stroke, 0, 0, 0);
24
25 gh_new_procedure ("nt-begin-page", nt_scm_begin_page, 2, 0, 0);
26 gh_new_procedure ("nt-end-page", nt_scm_end_page, 0, 0, 0);
27 gh_new_procedure ("nt-save", nt_scm_save, 0, 0, 0);
28 gh_new_procedure ("nt-restore", nt_scm_restore, 0, 0, 0);
29
30 gh_new_procedure ("nt-current-position", nt_scm_current_position, 0, 0, 0);
31 gh_new_procedure ("nt-current-angle", nt_scm_current_angle, 0, 0, 0);
32 gh_new_procedure ("nt-text-width", nt_scm_text_width, 4, 0, 0);
33
34 gh_new_procedure ("nt-split-string", nt_scm_split_string, 1, 0, 0);
35
36 gh_new_procedure ("nt-open", nt_scm_open, 1, 0, 0);
37 gh_new_procedure ("nt-close", nt_scm_close, 0, 0, 0);
38 gh_new_procedure ("nt-include", nt_scm_include, 1, 0, 0);
39
40 gh_new_procedure ("nt-parse-string", nt_scm_parse_string, 1, 0, 0);
41 }
42
43
44 SCM
45 nt_scm_open (SCM s_file)
46 {
47 char *file;
48 int len;
49
50 file = gh_scm2newstr (s_file, &len);
51 nt_pdf_open (file);
52 free (file);
53
54 return s_file;
55 }
56
57 SCM
58 nt_scm_close ()
59 {
60 nt_pdf_close ();
61
62 return SCM_EOL;
63 }
64
65 SCM
66 nt_scm_include (SCM s_file)
67 {
68 int d;
69 char *file;
70 FILE *fp;
71
72 file = gh_scm2newstr (s_file, &d);
73 fp = fopen (file, "r");
74
75 if (! fp) {
76 fprintf (stderr, "%s: open failed.", file);
77 } else {
78 nt_prs_loop (fp);
79 }
80
81 free (file);
82 return SCM_EOL;
83 }
84
85 SCM
86 nt_scm_parse_string (SCM s_str)
87 {
88 int d;
89 char *str;
90
91 str = gh_scm2newstr (s_str, &d);
92 nt_prs_loop_with_string_literal (str);
93
94 free (str);
95 return SCM_EOL;
96 }
97
98 SCM
99 nt_scm_set_text_pos (SCM s_x, SCM s_y)
100 {
101 float x, y;
102
103 x = (float) gh_scm2double (s_x);
104 y = (float) gh_scm2double (s_y);
105
106 nt_pdf_set_text_pos (x, y);
107
108 return SCM_EOL;
109 }
110
111 SCM
112 nt_scm_font (SCM s_font_name, SCM s_encoding, SCM s_size)
113 {
114 char *font_name, *encoding;
115 double size;
116 int d;
117
118 font_name = gh_scm2newstr (s_font_name, &d);
119 encoding = gh_scm2newstr (s_encoding, &d);
120 size = gh_scm2double (s_size);
121
122 nt_pdf_font (font_name, encoding, size);
123
124 free (font_name);
125 free (encoding);
126
127 return SCM_EOL;
128 }
129
130 SCM
131 nt_scm_translate (SCM s_x, SCM s_y)
132 {
133 float x, y;
134
135 x = gh_scm2double (s_x);
136 y = gh_scm2double (s_y);
137
138 nt_pdf_translate (x, y);
139
140 return SCM_EOL;
141 }
142
143 SCM
144 nt_scm_rotate (SCM s_angle)
145 {
146 float angle = (float) gh_scm2double (s_angle);
147
148 nt_pdf_rotate (angle);
149
150 return SCM_EOL;
151 }
152
153 SCM
154 nt_scm_show (SCM s_string)
155 {
156 char *str;
157 int len;
158 SCM s_len;
159
160 str = gh_scm2newstr (s_string, &len);
161 nt_pdf_show (str);
162
163 free (str);
164
165 s_len = gh_int2scm (len);
166 return s_len;
167 }
168
169 SCM
170 nt_scm_moveto (SCM s_x, SCM s_y)
171 {
172 float x, y;
173
174 x = (float) gh_scm2double (s_x);
175 y = (float) gh_scm2double (s_y);
176
177 nt_pdf_moveto (x, y);
178
179 return SCM_EOL;
180 }
181
182 SCM
183 nt_scm_lineto (SCM s_x, SCM s_y)
184 {
185 float x, y;
186
187 x = (float) gh_scm2double (s_x);
188 y = (float) gh_scm2double (s_y);
189
190 nt_pdf_lineto (x, y);
191
192 return SCM_EOL;
193 }
194
195 SCM
196 nt_scm_stroke ()
197 {
198 nt_pdf_stroke ();
199 return SCM_EOL;
200 }
201
202
203 SCM
204 nt_scm_begin_page (SCM s_width, SCM s_height)
205 {
206 float w, h;
207
208 w = (float) gh_scm2double (s_width);
209 h = (float) gh_scm2double (s_height);
210
211 nt_pdf_begin_page (w, h);
212
213 return SCM_EOL;
214 }
215
216 SCM
217 nt_scm_end_page ()
218 {
219 nt_pdf_end_page ();
220 return SCM_EOL;
221 }
222
223 SCM
224 nt_scm_save ()
225 {
226 nt_pdf_save ();
227
228 return SCM_EOL;
229 }
230
231 SCM
232 nt_scm_restore ()
233 {
234 nt_pdf_restore ();
235
236 return SCM_EOL;
237 }
238
239
240 SCM
241 nt_scm_current_position ()
242 {
243 return SCM_EOL;
244 }
245
246 SCM
247 nt_scm_current_angle ()
248 {
249 return SCM_EOL;
250 }
251
252 SCM
253 nt_scm_text_width (SCM s_string, SCM s_font, SCM s_encoding, SCM s_size)
254 {
255 char *str, *font, *encoding;
256 double size, width;
257 int len;
258
259 SCM_ASSERT(SCM_STRINGP (s_string), s_string, SCM_ARG1, "nt-text-width");
260 SCM_ASSERT(SCM_STRINGP (s_font), s_font, SCM_ARG2, "nt-text-width");
261 SCM_ASSERT(SCM_STRINGP (s_encoding), s_encoding, SCM_ARG3, "nt-text-width");
262
263 str = gh_scm2newstr (s_string, &len);
264 font = gh_scm2newstr (s_font, &len);
265 encoding = gh_scm2newstr (s_encoding, &len);
266 size = gh_scm2double (s_size);
267
268 // debug_printf ("nt_scm_text_width: %s %s %s %f", str, font, encoding, size);
269
270 width = nt_pdf_text_width (str, font, encoding, size);
271
272 free (encoding);
273 free (font);
274 free (str);
275
276 return gh_double2scm (width);
277 }
278
279 SCM
280 nt_scm_split_string (SCM s_string)
281 {
282 char *str, *p;
283 int len, c_len;
284 char type_tag [10];
285 char quote_code [100];
286 char c [3];
287 int first = 1;
288 SCM s_dest, s_c, s_type_tag;
289
290 str = gh_scm2newstr (s_string, &len);
291
292 for (p = str; *p; p ++) {
293 if (isascii (*p)) {
294 strcpy (type_tag, "ascii");
295 c [0] = *p;
296 c [1] = '\0';
297 c_len = 1;
298 } else {
299 strcpy (type_tag, "jeuc");
300 c [0] = *p;
301 c [1] = *(++ p);
302 c [2] = '\0';
303 c_len = 2;
304 }
305
306 s_c = gh_str2scm (c, c_len);
307
308 sprintf (quote_code, "'%s", type_tag);
309 s_type_tag = gh_eval_str (quote_code);
310 // s_type_tag = gh_symbol2scm (type_tag);
311
312 // gh_display (s_type_tag);
313
314 if (first) {
315 s_dest = SCM_LIST1 (SCM_LIST2 (s_c, s_type_tag));
316 } else {
317 s_dest = gh_append2 (s_dest, SCM_LIST1 (SCM_LIST2 (s_c, s_type_tag)));
318 }
319
320 first = 0;
321 }
322
323 return s_dest;
324 }
325
326 // Local Variables:
327 // buffer-file-coding-system: euc-jp-unix
328 // End:

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26