aboutsummaryrefslogtreecommitdiff
path: root/libdraw/getsubfont.c
blob: 78fea90107f4eb49372f01973fbf8991dd97207b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "lib9.h"
#include "kernel.h"
#include "draw.h"


#ifdef ANDROID
#include <android/log.h>

#define  LOG_TAG    "inferno RSF"
#define  LOGI(...)  __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
#define  LOGW(...)  __android_log_print(ANDROID_LOG_WARN,LOG_TAG,__VA_ARGS__)
#define  LOGE(...)  __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
#else
#define  LOGI(...)  printf(__VA_ARGS__)
#define  LOGW(...)  
#define  LOGE(...)  
#endif


extern Subfont*
readsubfont_ft(Display*d, char *name, int fnt_size, int dolock);


/*
 * Default version: treat as file name
 */

Subfont*
_getsubfont(Display *d, char *name, int font_size)
{
	int fd;
	Subfont *f;

	if( is_subfont_ft(name) )
	{
		if(d->local == 0)
			unlockdisplay(d);
LOGI("pre rsf_ft (%s)", name);
		f = readsubfont_ft(d, name, font_size, d->local == 0);
		if(d->local == 0)
			lockdisplay(d);
		if(f == 0)
			_drawprint(2, "getsubfont: can't read %s: %r\n", name);
		return f;
	}

	fd = libopen(name, OREAD);
		
	if(fd < 0){
		_drawprint(2, "getsubfont: can't open %s: %r\n", name);
		return 0;
	}
	/*
	 * unlock display so i/o happens with display released, unless
	 * user is doing his own locking, in which case this could break things.
	 * _getsubfont is called only from string.c and stringwidth.c,
	 * which are known to be safe to have this done.
	 */
	if(d->local == 0)
		unlockdisplay(d);
	f = readsubfont(d, name, fd, d->local == 0);
	if(d->local == 0)
		lockdisplay(d);
	if(f == 0)
		_drawprint(2, "getsubfont: can't read %s: %r\n", name);
	libclose(fd);
	return f;
}