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 #include "allocate.h"
27
28 #include <ctype.h>
StrLwrCpy(char * d,const char * s,int n)29 static void StrLwrCpy(char *d, const char *s, int n)
30 {
31 while (n-- > 0) {
32 *(d++) = tolower(*s);
33 ++s;
34 }
35 *d = '\0';
36 }
37
_installgrxfont(int start,int stop,const char * name)38 static int _installgrxfont(int start, int stop, const char *name)
39 {
40 __gr_text_init();
41 while (start < stop && Fonts[start] != NULL) ++start;
42 if (start >= stop)
43 return grNoFontMem;
44 #ifdef GRX_VERSION
45 if ( name[0] == '@' && name[1] == ':')
46 name += 2;
47 #endif
48 Fonts[start] = (void *) GrLoadFont((char *) name);
49 if (Fonts[start] == NULL)
50 return grFontNotFound;
51 return start;
52 }
53
_installuserfont(int len,const char * name)54 static int _installuserfont(int len, const char *name)
55 {
56 int res;
57 char *loc_name = ALLOC(len+5);
58
59 if ( !loc_name )
60 return grNoFontMem;
61
62 StrLwrCpy(loc_name, name, len);
63 if (strstr(loc_name, ".fnt") != NULL)
64 res = _installgrxfont( FirstGrxFont, LastGrxFont, name);
65 else
66 res = __gr_text_installfont( FirstUserFont, LastUserFont, loc_name);
67
68 FREE(loc_name);
69 return res;
70 }
71
installuserfont(const char * name)72 int installuserfont(const char *name)
73 {
74 return _installuserfont(strlen(name), name);
75 }
76