aboutsummaryrefslogtreecommitdiffstats
path: root/fbtruetype/fbtruetype.c
blob: 1fd8ac35728b84c521bad9c815c0f90e3a84d55c (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
 *	fbmngplay - fb console MNG player.
 *	(c) 2001-2002 by Stefan Reinauer, <stepan@suse.de>
 *  
 *	This program is based on mngplay, written and (C) by
 *	Ralph Giles <giles@ashlu.bc.ca>
 *
 *	This program my be redistributed under the terms of the
 *	GNU General Public Licence, version 2, or at your preference,
 *	any later version.
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <getopt.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <linux/fb.h>
#include <signal.h>


#include "fbtruetype.h"
#include "messages.h"
#include "console.h"

volatile int run = 1;
int verbose = 0;
int buffered = 0;
int waitsignal = 0;
int delta = 16;
int sconly = 0;

unsigned int fbbytes, fbx, fby;
unsigned int fbypos = 100, fbxpos = 100;
unsigned int fblinelen, alpha = 100;
unsigned char *framebuffer, *font = DEFAULT_FONTNAME;
unsigned int fgcolor = 0xff0000;
unsigned int fontsize = 36;
int strict_font = 0;
int rendertext(char *text, char *fontname, unsigned int size,
	       unsigned int forecol);

int main(int argc, char *argv[])
{
	int fbdev, c, option_index;
	unsigned int alpha;
	struct fb_var_screeninfo var;
	struct fb_fix_screeninfo fix;

	/* Check which console we're running on */
	init_consoles();

	alpha = 100;
	while (1) {
		static struct option long_options[] = {
			{"help", 0, 0, 'h'},
			{"verbose", 0, 0, 'v'},
			{"alpha", 1, 0, 'a'},
			{"version", 0, 0, 'V'},
			{"start-console", 0, 0, 'S'},
			{"size", 1, 0, 's'},
			{"console", 1, 0, 'c'},
			{"font", 1, 0, 'f'},
			{"textcolor", 1, 0, 't'},
			{0, 0, 0, 0}
		};

		c = getopt_long(argc, argv, "a:x:y:h?vVSc:f:t:s:",
				long_options, &option_index);

		if (c == -1)
			break;

		switch (c) {
		case 'a':
			alpha = atoi(optarg);
			if (alpha > 100)
				alpha = 100;
			break;
		case 'x':
			fbxpos = atoi(optarg);
			break;
		case 'y':
			fbypos = atoi(optarg);
			break;
		case '?':
		case 'h':
			usage(argv[0]);
			exit(0);
		case 'v':
			verbose = 1;
			break;
		case 'V':
			version();
			exit(0);
		case 'c':
			start_console = atoi(optarg) - 1;
		case 'S':
			sconly = 1;
			break;
		case 'f':
			strict_font = 1;
			font = strdup(optarg);
			break;
		case 't':
			fgcolor = strtol(optarg, NULL, 16);
			break;
		case 's':
			fontsize = strtol(optarg, NULL, 10);
			break;

		default:
			break;
		}
	}
	if (optind >= argc) {
		printf("No text\n");
		exit(0);
	}

	/* Initialize framebuffer */
	fbdev = open("/dev/fb0", O_RDWR);
	if (fbdev < 0) {
		fprintf(stderr, "error while opening framebuffer.\n");
		exit(fbdev);
	}

	ioctl(fbdev, FBIOGET_VSCREENINFO, &var);
	fbbytes = var.bits_per_pixel >> 3;
	fbx = var.xres;
	fby = var.yres;
	ioctl(fbdev, FBIOGET_FSCREENINFO, &fix);
	fblinelen = fix.line_length;

	framebuffer = mmap(NULL, fblinelen * fby,
			   PROT_WRITE | PROT_READ, MAP_SHARED, fbdev, 0);

	rendertext(argv[optind], font, fontsize, fgcolor);
	return 0;
}