xref: /OK3568_Linux_fs/kernel/lib/fonts/fonts.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * `Soft' font definitions
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  *    Created 1995 by Geert Uytterhoeven
5*4882a593Smuzhiyun  *    Rewritten 1998 by Martin Mares <mj@ucw.cz>
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  *	2001 - Documented with DocBook
8*4882a593Smuzhiyun  *	- Brad Douglas <brad@neruo.com>
9*4882a593Smuzhiyun  *
10*4882a593Smuzhiyun  * This file is subject to the terms and conditions of the GNU General Public
11*4882a593Smuzhiyun  * License.  See the file COPYING in the main directory of this archive
12*4882a593Smuzhiyun  * for more details.
13*4882a593Smuzhiyun  */
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun #include <linux/module.h>
16*4882a593Smuzhiyun #include <linux/types.h>
17*4882a593Smuzhiyun #include <linux/string.h>
18*4882a593Smuzhiyun #if defined(__mc68000__)
19*4882a593Smuzhiyun #include <asm/setup.h>
20*4882a593Smuzhiyun #endif
21*4882a593Smuzhiyun #include <linux/font.h>
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun static const struct font_desc *fonts[] = {
24*4882a593Smuzhiyun #ifdef CONFIG_FONT_8x8
25*4882a593Smuzhiyun 	&font_vga_8x8,
26*4882a593Smuzhiyun #endif
27*4882a593Smuzhiyun #ifdef CONFIG_FONT_8x16
28*4882a593Smuzhiyun 	&font_vga_8x16,
29*4882a593Smuzhiyun #endif
30*4882a593Smuzhiyun #ifdef CONFIG_FONT_6x11
31*4882a593Smuzhiyun 	&font_vga_6x11,
32*4882a593Smuzhiyun #endif
33*4882a593Smuzhiyun #ifdef CONFIG_FONT_7x14
34*4882a593Smuzhiyun 	&font_7x14,
35*4882a593Smuzhiyun #endif
36*4882a593Smuzhiyun #ifdef CONFIG_FONT_SUN8x16
37*4882a593Smuzhiyun 	&font_sun_8x16,
38*4882a593Smuzhiyun #endif
39*4882a593Smuzhiyun #ifdef CONFIG_FONT_SUN12x22
40*4882a593Smuzhiyun 	&font_sun_12x22,
41*4882a593Smuzhiyun #endif
42*4882a593Smuzhiyun #ifdef CONFIG_FONT_10x18
43*4882a593Smuzhiyun 	&font_10x18,
44*4882a593Smuzhiyun #endif
45*4882a593Smuzhiyun #ifdef CONFIG_FONT_ACORN_8x8
46*4882a593Smuzhiyun 	&font_acorn_8x8,
47*4882a593Smuzhiyun #endif
48*4882a593Smuzhiyun #ifdef CONFIG_FONT_PEARL_8x8
49*4882a593Smuzhiyun 	&font_pearl_8x8,
50*4882a593Smuzhiyun #endif
51*4882a593Smuzhiyun #ifdef CONFIG_FONT_MINI_4x6
52*4882a593Smuzhiyun 	&font_mini_4x6,
53*4882a593Smuzhiyun #endif
54*4882a593Smuzhiyun #ifdef CONFIG_FONT_6x10
55*4882a593Smuzhiyun 	&font_6x10,
56*4882a593Smuzhiyun #endif
57*4882a593Smuzhiyun #ifdef CONFIG_FONT_TER16x32
58*4882a593Smuzhiyun 	&font_ter_16x32,
59*4882a593Smuzhiyun #endif
60*4882a593Smuzhiyun #ifdef CONFIG_FONT_6x8
61*4882a593Smuzhiyun 	&font_6x8,
62*4882a593Smuzhiyun #endif
63*4882a593Smuzhiyun };
64*4882a593Smuzhiyun 
65*4882a593Smuzhiyun #define num_fonts ARRAY_SIZE(fonts)
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun #ifdef NO_FONTS
68*4882a593Smuzhiyun #error No fonts configured.
69*4882a593Smuzhiyun #endif
70*4882a593Smuzhiyun 
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun /**
73*4882a593Smuzhiyun  *	find_font - find a font
74*4882a593Smuzhiyun  *	@name: string name of a font
75*4882a593Smuzhiyun  *
76*4882a593Smuzhiyun  *	Find a specified font with string name @name.
77*4882a593Smuzhiyun  *
78*4882a593Smuzhiyun  *	Returns %NULL if no font found, or a pointer to the
79*4882a593Smuzhiyun  *	specified font.
80*4882a593Smuzhiyun  *
81*4882a593Smuzhiyun  */
find_font(const char * name)82*4882a593Smuzhiyun const struct font_desc *find_font(const char *name)
83*4882a593Smuzhiyun {
84*4882a593Smuzhiyun 	unsigned int i;
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun 	BUILD_BUG_ON(!num_fonts);
87*4882a593Smuzhiyun 	for (i = 0; i < num_fonts; i++)
88*4882a593Smuzhiyun 		if (!strcmp(fonts[i]->name, name))
89*4882a593Smuzhiyun 			return fonts[i];
90*4882a593Smuzhiyun 	return NULL;
91*4882a593Smuzhiyun }
92*4882a593Smuzhiyun EXPORT_SYMBOL(find_font);
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun 
95*4882a593Smuzhiyun /**
96*4882a593Smuzhiyun  *	get_default_font - get default font
97*4882a593Smuzhiyun  *	@xres: screen size of X
98*4882a593Smuzhiyun  *	@yres: screen size of Y
99*4882a593Smuzhiyun  *      @font_w: bit array of supported widths (1 - 32)
100*4882a593Smuzhiyun  *      @font_h: bit array of supported heights (1 - 32)
101*4882a593Smuzhiyun  *
102*4882a593Smuzhiyun  *	Get the default font for a specified screen size.
103*4882a593Smuzhiyun  *	Dimensions are in pixels.
104*4882a593Smuzhiyun  *
105*4882a593Smuzhiyun  *	Returns %NULL if no font is found, or a pointer to the
106*4882a593Smuzhiyun  *	chosen font.
107*4882a593Smuzhiyun  *
108*4882a593Smuzhiyun  */
get_default_font(int xres,int yres,u32 font_w,u32 font_h)109*4882a593Smuzhiyun const struct font_desc *get_default_font(int xres, int yres, u32 font_w,
110*4882a593Smuzhiyun 					 u32 font_h)
111*4882a593Smuzhiyun {
112*4882a593Smuzhiyun 	int i, c, cc, res;
113*4882a593Smuzhiyun 	const struct font_desc *f, *g;
114*4882a593Smuzhiyun 
115*4882a593Smuzhiyun 	g = NULL;
116*4882a593Smuzhiyun 	cc = -10000;
117*4882a593Smuzhiyun 	for (i = 0; i < num_fonts; i++) {
118*4882a593Smuzhiyun 		f = fonts[i];
119*4882a593Smuzhiyun 		c = f->pref;
120*4882a593Smuzhiyun #if defined(__mc68000__)
121*4882a593Smuzhiyun #ifdef CONFIG_FONT_PEARL_8x8
122*4882a593Smuzhiyun 		if (MACH_IS_AMIGA && f->idx == PEARL8x8_IDX)
123*4882a593Smuzhiyun 			c = 100;
124*4882a593Smuzhiyun #endif
125*4882a593Smuzhiyun #ifdef CONFIG_FONT_6x11
126*4882a593Smuzhiyun 		if (MACH_IS_MAC && xres < 640 && f->idx == VGA6x11_IDX)
127*4882a593Smuzhiyun 			c = 100;
128*4882a593Smuzhiyun #endif
129*4882a593Smuzhiyun #endif
130*4882a593Smuzhiyun 		if ((yres < 400) == (f->height <= 8))
131*4882a593Smuzhiyun 			c += 1000;
132*4882a593Smuzhiyun 
133*4882a593Smuzhiyun 		/* prefer a bigger font for high resolution */
134*4882a593Smuzhiyun 		res = (xres / f->width) * (yres / f->height) / 1000;
135*4882a593Smuzhiyun 		if (res > 20)
136*4882a593Smuzhiyun 			c += 20 - res;
137*4882a593Smuzhiyun 
138*4882a593Smuzhiyun 		if ((font_w & (1 << (f->width - 1))) &&
139*4882a593Smuzhiyun 		    (font_h & (1 << (f->height - 1))))
140*4882a593Smuzhiyun 			c += 1000;
141*4882a593Smuzhiyun 
142*4882a593Smuzhiyun 		if (c > cc) {
143*4882a593Smuzhiyun 			cc = c;
144*4882a593Smuzhiyun 			g = f;
145*4882a593Smuzhiyun 		}
146*4882a593Smuzhiyun 	}
147*4882a593Smuzhiyun 	return g;
148*4882a593Smuzhiyun }
149*4882a593Smuzhiyun EXPORT_SYMBOL(get_default_font);
150*4882a593Smuzhiyun 
151*4882a593Smuzhiyun MODULE_AUTHOR("James Simmons <jsimmons@users.sf.net>");
152*4882a593Smuzhiyun MODULE_DESCRIPTION("Console Fonts");
153*4882a593Smuzhiyun MODULE_LICENSE("GPL");
154