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