1 /**
2 ** BCC2GRX - Interfacing Borland based graphics programs to LIBGRX
3 ** Copyright (C) 1993-97 by Hartmut Schirmer
4 **
5 **
6 ** Contact : Hartmut Schirmer
7 ** Feldstrasse 118
8 ** D-24105 Kiel
9 ** Germany
10 **
11 ** e-mail : hsc@techfak.uni-kiel.de
12 **
13 ** This file is part of the GRX graphics library.
14 **
15 ** The GRX graphics library is free software; you can redistribute it
16 ** and/or modify it under some conditions; see the "copying.grx" file
17 ** for details.
18 **
19 ** This library is distributed in the hope that it will be useful,
20 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 **
23 **/
24
25 #include "text.h"
26
27
28 /* -------------------------------------------------------------- */
29
__gr_text_registerfont(int start,int stop,void * font)30 int __gr_text_registerfont( int start, int stop, void *font)
31 {
32 int i;
33 char *Header;
34 char *name;
35
36 __gr_text_init();
37 Header = (char *)font + PreSkip;
38 if ( memcmp( font, "PK\x8\x8",4)!=0 || *Header != '+')
39 return grInvalidFont;
40
41 name = (char *) font;
42 while (*name != '\x1a') {
43 if ( name-(char *)font > 128)
44 return grInvalidFont;
45 ++name;
46 }
47 name += 3;
48
49 for (i=1; i <= BOLD_FONT; ++i)
50 if (memcmp( name, StdFonts[i], 4) == 0)
51 break;
52 if (i > BOLD_FONT) {
53 i = start;
54 while ( i <= stop && Fonts[i] != NULL)
55 ++i;
56 if (i > stop)
57 return grNoFontMem;
58 }
59 Fonts[i] = font;
60 return i;
61 }
62
__gr_text_installfont(int start,int stop,const char * name)63 int __gr_text_installfont( int start, int stop, const char *name)
64 {
65 FILE *ff;
66 long size;
67 void *font;
68 int res;
69 char *temp = alloca(strlen(name)+1+4);
70 char *temp1;
71
72 #ifdef __linux__
73 # define CHG_CHAR '\\'
74 # define NEW_CHAR '/'
75 #else
76 # define CHG_CHAR '/'
77 # define NEW_CHAR '\\'
78 #endif
79
80 if (temp != NULL) {
81 int have_ext = FALSE;
82 strcpy(temp, name);
83 temp1 = temp;
84 while (*temp != '\0') {
85 if (*temp == CHG_CHAR) *temp = NEW_CHAR;
86 else *temp = (tolower)(*temp);
87 if (*temp == NEW_CHAR) have_ext = FALSE;
88 else have_ext |= *temp == '.';
89 ++temp;
90 }
91 if (!have_ext)
92 strcat(temp1, ".chr");
93 ff = fopen(temp1, "rb");
94 }
95 else
96 ff = NULL;
97
98 if (ff == NULL)
99 return grFileNotFound;
100 fseek( ff, 0, SEEK_END);
101 size = ftell(ff);
102 fseek( ff, 0, SEEK_SET);
103 font = malloc( (size_t) size);
104 if (font == NULL) {
105 fclose( ff);
106 return grNoFontMem;
107 }
108 fread( font, (size_t) size, 1, ff);
109 fclose( ff);
110 res = __gr_text_registerfont(start, stop, font);
111 if (res < 0)
112 free( font);
113 return res;
114 }
115
116