Initial revision
[ssr] / StraySrc / Libraries / Steel / c / font
1 /************************************************************************/
2 /* © Acorn Computers Ltd, 1992. */
3 /* */
4 /* This file forms part of an unsupported source release of RISC_OSLib. */
5 /* */
6 /* It may be freely used to create executable images for saleable */
7 /* products but cannot be sold in source form or as an object library */
8 /* without the prior written consent of Acorn Computers Ltd. */
9 /* */
10 /* If this file is re-distributed (even if modified) it should retain */
11 /* this copyright notice. */
12 /* */
13 /************************************************************************/
14
15 /*
16 * Title : c.font
17 * Purpose: access to RISC OS font facilities
18 * History: IDJ: 06-Feb-92: prepared for source release
19 */
20
21 #ifndef __stddef_h
22 #include <stddef.h>
23 #endif
24 #include "h.os"
25 #include "h.trace"
26 #include "h.font"
27
28
29 /* F O N T S W I 's */
30 #define CacheAddr 0x40080
31 #define FindFont 0x40081
32 #define LoseFont 0x40082
33 #define ReadDefn 0x40083
34 #define ReadInfo 0x40084
35 #define StringWidth 0x40085
36 #define Paint 0x40086
37 #define Caret 0x40087
38 #define ConverttoOS 0x40088
39 #define Converttopoints 0x40089
40 #define SetFont 0x4008A
41 #define CurrentFont 0x4008B
42 #define FutureFont 0x4008C
43 #define FindCaret 0x4008D
44 #define CharBBox 0x4008E
45 #define ReadScaleFactor 0x4008F
46 #define SetScaleFactor 0x40090
47 #define ListFonts 0x40091
48 #define SetFontColours 0x40092
49 #define SetPalette 0x40093
50 #define ReadThresholds 0x40094
51 #define SetThresholds 0x40095
52 #define FindCaretJ 0x40096
53 #define StringBBox 0x40097
54 #define ReadColourTable 0x40098
55 #define MakeBitmap 0x40099
56 #define UnCacheFile 0x4009A
57 #define SetFontMax 0x4009B
58 #define ReadFontMax 0x4009C
59 #define ReadFontPrefix 0x4009D
60 #define SwitchOutputToBuffer 0x4009E
61 #define ReadFontMetrics 0x4009F
62
63 #pragma no_check_stack
64
65 os_error *font_cacheaddress(int *version, int *cacheused, int *cachesize)
66 {
67 os_regset r;
68 os_error *e;
69
70 r.r[0] = 0;
71 e = os_swix(CacheAddr, &r);
72
73 if (!e)
74 {
75 *version = r.r[0];
76 *cacheused = r.r[1];
77 *cachesize = r.r[2];
78 }
79
80 return e;
81 }
82
83
84 os_error *font_find(char *name, int xsize, int ysize, int xres, int yres, font *fontadd)
85 {
86 os_regset r;
87 os_error *e;
88
89 r.r[1] = (int)name;
90 r.r[2] = xsize;
91 r.r[3] = ysize;
92 r.r[4] = xres;
93 r.r[5] = yres;
94
95 e = os_swix(FindFont, &r);
96
97 *fontadd = (font) r.r[0];
98
99 return e;
100 }
101
102
103 os_error *font_lose(font f)
104 {
105 os_regset r;
106 os_error *e;
107
108 r.r[0] = f;
109 e = os_swix(LoseFont, &r);
110 return e;
111 }
112
113
114 os_error * font_readdef(font f, font_def *d)
115 {
116 os_regset r;
117 os_error *e;
118
119 r.r[0] = (int)f;
120 r.r[1] = (int)&d->name;
121
122 e = os_swix(ReadDefn, &r);
123
124 d->xsize = r.r[2];
125 d->ysize = r.r[3];
126 d->xres = r.r[4];
127 d->yres = r.r[5];
128 d->usage = r.r[6];
129 d->age = r.r[7];
130
131 return(e);
132 }
133
134
135 os_error *font_readinfo(font f, font_info *i)
136 {
137 os_regset r;
138 os_error *e;
139
140 r.r[0] = f;
141
142 e = os_swix(ReadInfo, &r);
143
144 i->minx = r.r[1];
145 i->miny = r.r[2];
146 i->maxx = r.r[3];
147 i->maxy = r.r[4];
148
149 return e;
150 }
151
152
153 os_error *font_strwidth(font_string *fs)
154 {
155 os_regset r;
156 os_error *e;
157
158 r.r[1] = (int)fs->s;
159 r.r[2] = fs->x;
160 r.r[3] = fs->y;
161 r.r[4] = fs->split;
162 r.r[5] = fs->term;
163
164 e = os_swix(StringWidth, &r);
165
166 fs->x = r.r[2];
167 fs->y = r.r[3];
168 fs->split = r.r[4];
169 fs->term = r.r[5];
170
171 return e;
172 }
173
174
175 os_error *font_paint(char *s, int options, int x, int y)
176 {
177 os_regset r;
178 os_error *e;
179
180 r.r[1] = (int)s;
181 r.r[2] = options;
182 r.r[3] = x;
183 r.r[4] = y;
184
185 e = os_swix(Paint, &r);
186
187 return e;
188 }
189
190
191 os_error *font_caret(int colour, int height, int flags, int x, int y)
192 {
193 os_regset r;
194 os_error *e;
195
196 r.r[0] = colour;
197 r.r[1] = height;
198 r.r[2] = flags;
199 r.r[3] = x;
200 r.r[4] = y;
201
202 e = os_swix(Caret, &r);
203
204 return e;
205 }
206
207
208 os_error *font_converttoos(int x_inch, int y_inch, int *x_os, int *y_os)
209 {
210 os_regset r;
211 os_error *e;
212
213 r.r[1] = x_inch;
214 r.r[2] = y_inch;
215
216 e = os_swix(ConverttoOS, &r);
217
218 *x_os = r.r[1];
219 *y_os = r.r[2];
220
221 return e;
222 }
223
224
225 os_error *font_converttopoints(int x_os, int y_os, int *x_inch, int *y_inch)
226 {
227 os_regset r;
228 os_error *e;
229
230 r.r[1] = x_os;
231 r.r[2] = y_os;
232
233 e = os_swix(Converttopoints, &r);
234
235 *x_inch = r.r[1];
236 *y_inch = r.r[2];
237
238 return e;
239 }
240
241
242 os_error *font_setfont(font f)
243 {
244 os_regset r;
245 os_error *e;
246
247 r.r[0] = f;
248
249 e = os_swix(SetFont, &r);
250
251 return(e);
252 }
253
254
255 os_error *font_current(font_state *f)
256 {
257 os_regset r;
258 os_error *e;
259
260 e = os_swix(CurrentFont, &r);
261
262 f->f = r.r[0];
263 f->back_colour = r.r[1];
264 f->fore_colour = r.r[2];
265 f->offset = r.r[3];
266
267 return(e);
268 }
269
270
271 os_error *font_future(font_state *f)
272 {
273 os_regset r;
274 os_error *e;
275
276 e = os_swix(FutureFont, &r);
277
278 f->f = r.r[0];
279 f->back_colour = r.r[1];
280 f->fore_colour = r.r[2];
281 f->offset = r.r[3];
282
283 return(e);
284 }
285
286
287 os_error *font_findcaret(font_string *fs)
288 {
289 os_regset r;
290 os_error *e;
291
292 r.r[1] = (int)fs->s;
293 r.r[2] = fs->x;
294 r.r[3] = fs->y;
295
296 e = os_swix(FindCaret, &r);
297
298 fs->x = r.r[2];
299 fs->y = r.r[3];
300 fs->split = r.r[4];
301 fs->term = r.r[5];
302
303 return e;
304 }
305
306
307 os_error *font_charbbox(font f, char ch, int options, font_info *i)
308 {
309 os_regset r;
310 os_error *e;
311
312 r.r[0] = f;
313 r.r[1] = ch;
314 r.r[2] = options;
315
316 e = os_swix(CharBBox, &r);
317
318 i->minx = r.r[1];
319 i->miny = r.r[2];
320 i->maxx = r.r[3];
321 i->maxy = r.r[4];
322
323 return e;
324 }
325
326
327 os_error *font_readscalefactor(int *x, int *y)
328 {
329 os_regset r;
330 os_error *e;
331
332 e = os_swix(ReadScaleFactor, &r);
333
334 *x = r.r[1];
335 *y = r.r[2];
336
337 return e;
338 }
339
340
341 os_error *font_setscalefactor(int x, int y)
342 {
343 os_regset r;
344 os_error *e;
345
346 r.r[1] = x;
347 r.r[2] = y;
348
349 e = os_swix(SetScaleFactor, &r);
350
351 return e;
352 }
353
354
355 os_error *font_list(char *a, int *count)
356 {
357 os_regset r;
358 os_error *e;
359 int i;
360
361 r.r[1] = (int)a;
362 r.r[2] = *count;
363 r.r[3] = -1;
364
365 e = os_swix(ListFonts, &r);
366
367 if (!e)
368 {
369
370 *count = r.r[2];
371 i = 0;
372
373 while (a[i] >= 32 && i <= 99)
374
375 ++i;
376
377 a[i] = 0;
378
379 }
380 else /* error return: probably some filing system error */
381 *count = -1; /* signal end of list */
382
383 return e;
384
385 }
386
387
388 os_error *font_setcolour(font f, int background, int foreground, int offset)
389 {
390 os_regset r;
391 os_error *e;
392
393 r.r[0] = f;
394 r.r[1] = background;
395 r.r[2] = foreground;
396 r.r[3] = offset;
397
398 e = os_swix(SetFontColours, &r);
399
400 return e;
401 }
402
403
404 os_error *font_setpalette(int background, int foreground, int offset,
405 int physical_back, int physical_fore)
406
407 {
408 os_regset r;
409 os_error *e;
410
411 r.r[1] = background;
412 r.r[2] = foreground;
413 r.r[3] = offset;
414 r.r[4] = physical_back;
415 r.r[5] = physical_fore;
416
417 e = os_swix(SetPalette, &r);
418
419 return e;
420 }
421
422
423 os_error *font_readthresholds(font_threshold *th)
424 {
425 os_regset r;
426 os_error *e;
427
428 r.r[1] = (int)th;
429
430 e = os_swix(ReadThresholds, &r);
431
432 return e;
433 }
434
435
436 os_error *font_setthresholds(font_threshold *th)
437 {
438 os_regset r;
439 os_error *e;
440
441 r.r[1] = (int)th;
442
443 e = os_swix(SetThresholds, &r);
444
445 return e;
446 }
447
448
449 os_error *font_findcaretj(font_string *fs, int offset_x, int offset_y)
450 {
451 os_regset r;
452 os_error *e;
453
454 r.r[1] = (int)fs->s;
455 r.r[2] = fs->x;
456 r.r[3] = fs->y;
457 r.r[4] = offset_x;
458 r.r[5] = offset_y;
459
460 e = os_swix(FindCaretJ, &r);
461
462 fs->x = r.r[2];
463 fs->y = r.r[3];
464 fs->split = r.r[4];
465 fs->term = r.r[5];
466
467 return e;
468 }
469
470
471 os_error *font_stringbbox(char *s, font_info *fi)
472 {
473 os_regset r;
474 os_error *e;
475
476 r.r[1] = (int)s;
477
478 e = os_swix(StringBBox, &r);
479
480 fi->minx = r.r[1];
481 fi->miny = r.r[2];
482 fi->maxx = r.r[3];
483 fi->maxy = r.r[4];
484
485 return e;
486 }
487
488 /*-----------------------------------------------------------------*/
489 /*Routines for conversion of fonts to Draw module path objects. See
490 the documentation of SWI Font_SwitchOutputToBuffer.*/
491
492 os_error *font_output_to_null (BOOL add_hints, BOOL output_skeleton,
493 font_action_on_bitmap action_on_bitmap)
494
495 {
496 os_regset reg_set;
497 os_error *error;
498
499 tracef0 ("font_output_to_null\n");
500
501 reg_set.r[0] =
502 1 /*no output*/ +
503 (add_hints? 1 << 1: 0) +
504 (output_skeleton? 1 << 2: 0) +
505 ( action_on_bitmap == font_ERROR?
506 1 << 4:
507 action_on_bitmap == font_CONVERT?
508 1 << 3:
509 0
510 );
511 reg_set.r[1] = 8;
512
513 if ((error = os_swix (SwitchOutputToBuffer, &reg_set)) != NULL)
514 return error;
515
516 return NULL;
517 }
518
519
520 os_error *font_output_size (size_t *size_ptr)
521 {
522 os_regset reg_set;
523 os_error *error;
524
525 tracef0 ("font_output_size\n");
526
527 reg_set.r [0] = 0;
528 reg_set.r [1] = -1;
529
530 if ((error = os_swix (SwitchOutputToBuffer, &reg_set)) != NULL)
531 return error;
532
533 *size_ptr = reg_set.r [1];
534 tracef1 ("font_output_size: made %d bytes of path\n", *size_ptr);
535 return NULL;
536 }
537
538
539 os_error *font_output_to_buffer(drawmod_buffer *buff_ptr, BOOL add_hints,
540 BOOL output_skeleton,
541 font_action_on_bitmap action_on_bitmap)
542
543 {
544 os_regset reg_set;
545 os_error *error;
546
547 tracef0 ("font_output_to_buffer\n");
548
549 reg_set.r[0] =
550 (add_hints? 1 << 1: 0) +
551 (output_skeleton? 1 << 2: 0) +
552 ( action_on_bitmap == font_ERROR?
553 1 << 4:
554 action_on_bitmap == font_CONVERT?
555 1 << 3:
556 0
557 );
558 reg_set.r[1] = (int) buff_ptr;
559
560 tracef1 ("font_output_to_buffer: path going to 0x%p\n", buff_ptr);
561 if ((error = os_swix (SwitchOutputToBuffer, &reg_set)) != NULL)
562 return error;
563
564 return NULL;
565 }
566
567
568 os_error *font_output_to_screen (void)
569 {
570 os_regset reg_set;
571 os_error *error;
572
573 tracef0 ("font_output_to_screen\n");
574
575 reg_set.r [0] = 0;
576 reg_set.r [1] = 0;
577
578 if ((error = os_swix (SwitchOutputToBuffer, &reg_set)) != NULL)
579 return error;
580
581 return NULL;
582 }
583
584 #pragma check_stack