Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Geert Uytterhoeven | ee89bd6 | 2013-06-09 11:46:43 +0200 | [diff] [blame] | 2 | * `Soft' font definitions |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Jan Beulich | 2f4516d | 2005-09-13 01:25:44 -0700 | [diff] [blame] | 23 | static const struct font_desc *fonts[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #ifdef CONFIG_FONT_8x8 |
Takashi Iwai | aa1d19f | 2019-06-18 22:34:23 +0200 | [diff] [blame] | 25 | &font_vga_8x8, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #endif |
| 27 | #ifdef CONFIG_FONT_8x16 |
Takashi Iwai | aa1d19f | 2019-06-18 22:34:23 +0200 | [diff] [blame] | 28 | &font_vga_8x16, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #endif |
| 30 | #ifdef CONFIG_FONT_6x11 |
Takashi Iwai | aa1d19f | 2019-06-18 22:34:23 +0200 | [diff] [blame] | 31 | &font_vga_6x11, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #endif |
Jurriaan | 303b86d | 2005-06-21 17:17:06 -0700 | [diff] [blame] | 33 | #ifdef CONFIG_FONT_7x14 |
Takashi Iwai | aa1d19f | 2019-06-18 22:34:23 +0200 | [diff] [blame] | 34 | &font_7x14, |
Jurriaan | 303b86d | 2005-06-21 17:17:06 -0700 | [diff] [blame] | 35 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #ifdef CONFIG_FONT_SUN8x16 |
Takashi Iwai | aa1d19f | 2019-06-18 22:34:23 +0200 | [diff] [blame] | 37 | &font_sun_8x16, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #endif |
| 39 | #ifdef CONFIG_FONT_SUN12x22 |
Takashi Iwai | aa1d19f | 2019-06-18 22:34:23 +0200 | [diff] [blame] | 40 | &font_sun_12x22, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #endif |
Jurriaan | 303b86d | 2005-06-21 17:17:06 -0700 | [diff] [blame] | 42 | #ifdef CONFIG_FONT_10x18 |
Takashi Iwai | aa1d19f | 2019-06-18 22:34:23 +0200 | [diff] [blame] | 43 | &font_10x18, |
Jurriaan | 303b86d | 2005-06-21 17:17:06 -0700 | [diff] [blame] | 44 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #ifdef CONFIG_FONT_ACORN_8x8 |
Takashi Iwai | aa1d19f | 2019-06-18 22:34:23 +0200 | [diff] [blame] | 46 | &font_acorn_8x8, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #endif |
| 48 | #ifdef CONFIG_FONT_PEARL_8x8 |
Takashi Iwai | aa1d19f | 2019-06-18 22:34:23 +0200 | [diff] [blame] | 49 | &font_pearl_8x8, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #endif |
| 51 | #ifdef CONFIG_FONT_MINI_4x6 |
Takashi Iwai | aa1d19f | 2019-06-18 22:34:23 +0200 | [diff] [blame] | 52 | &font_mini_4x6, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #endif |
Maarten ter Huurne | 33ac9db | 2014-09-09 13:46:28 +0200 | [diff] [blame] | 54 | #ifdef CONFIG_FONT_6x10 |
Takashi Iwai | aa1d19f | 2019-06-18 22:34:23 +0200 | [diff] [blame] | 55 | &font_6x10, |
Maarten ter Huurne | 33ac9db | 2014-09-09 13:46:28 +0200 | [diff] [blame] | 56 | #endif |
Amanoel Dawod | ac8b6f1 | 2018-12-05 18:56:37 -0500 | [diff] [blame] | 57 | #ifdef CONFIG_FONT_TER16x32 |
Takashi Iwai | aa1d19f | 2019-06-18 22:34:23 +0200 | [diff] [blame] | 58 | &font_ter_16x32, |
Amanoel Dawod | ac8b6f1 | 2018-12-05 18:56:37 -0500 | [diff] [blame] | 59 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | }; |
| 61 | |
Tobias Klauser | d1ae418 | 2006-03-27 01:17:39 -0800 | [diff] [blame] | 62 | #define num_fonts ARRAY_SIZE(fonts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
| 64 | #ifdef NO_FONTS |
| 65 | #error No fonts configured. |
| 66 | #endif |
| 67 | |
| 68 | |
| 69 | /** |
| 70 | * find_font - find a font |
| 71 | * @name: string name of a font |
| 72 | * |
| 73 | * Find a specified font with string name @name. |
| 74 | * |
| 75 | * Returns %NULL if no font found, or a pointer to the |
| 76 | * specified font. |
| 77 | * |
| 78 | */ |
Jan Beulich | 2f4516d | 2005-09-13 01:25:44 -0700 | [diff] [blame] | 79 | const struct font_desc *find_font(const char *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | { |
Takashi Iwai | aa1d19f | 2019-06-18 22:34:23 +0200 | [diff] [blame] | 81 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
Takashi Iwai | 73a649d | 2019-06-18 22:34:24 +0200 | [diff] [blame] | 83 | BUILD_BUG_ON(!num_fonts); |
Takashi Iwai | aa1d19f | 2019-06-18 22:34:23 +0200 | [diff] [blame] | 84 | for (i = 0; i < num_fonts; i++) |
| 85 | if (!strcmp(fonts[i]->name, name)) |
| 86 | return fonts[i]; |
| 87 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | } |
Takashi Iwai | aa1d19f | 2019-06-18 22:34:23 +0200 | [diff] [blame] | 89 | EXPORT_SYMBOL(find_font); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
| 91 | |
| 92 | /** |
| 93 | * get_default_font - get default font |
| 94 | * @xres: screen size of X |
| 95 | * @yres: screen size of Y |
Antonino A. Daplas | 2d2699d | 2007-05-08 00:39:11 -0700 | [diff] [blame] | 96 | * @font_w: bit array of supported widths (1 - 32) |
| 97 | * @font_h: bit array of supported heights (1 - 32) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | * |
| 99 | * Get the default font for a specified screen size. |
| 100 | * Dimensions are in pixels. |
| 101 | * |
| 102 | * Returns %NULL if no font is found, or a pointer to the |
| 103 | * chosen font. |
| 104 | * |
| 105 | */ |
Antonino A. Daplas | 2d2699d | 2007-05-08 00:39:11 -0700 | [diff] [blame] | 106 | const struct font_desc *get_default_font(int xres, int yres, u32 font_w, |
| 107 | u32 font_h) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | { |
Takashi Iwai | dfd19a5 | 2019-06-18 22:34:25 +0200 | [diff] [blame] | 109 | int i, c, cc, res; |
Takashi Iwai | aa1d19f | 2019-06-18 22:34:23 +0200 | [diff] [blame] | 110 | const struct font_desc *f, *g; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
Takashi Iwai | aa1d19f | 2019-06-18 22:34:23 +0200 | [diff] [blame] | 112 | g = NULL; |
| 113 | cc = -10000; |
| 114 | for (i = 0; i < num_fonts; i++) { |
| 115 | f = fonts[i]; |
| 116 | c = f->pref; |
Adrian Bunk | 7b89280 | 2008-02-06 01:36:29 -0800 | [diff] [blame] | 117 | #if defined(__mc68000__) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | #ifdef CONFIG_FONT_PEARL_8x8 |
Takashi Iwai | aa1d19f | 2019-06-18 22:34:23 +0200 | [diff] [blame] | 119 | if (MACH_IS_AMIGA && f->idx == PEARL8x8_IDX) |
| 120 | c = 100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | #endif |
| 122 | #ifdef CONFIG_FONT_6x11 |
Takashi Iwai | aa1d19f | 2019-06-18 22:34:23 +0200 | [diff] [blame] | 123 | if (MACH_IS_MAC && xres < 640 && f->idx == VGA6x11_IDX) |
| 124 | c = 100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | #endif |
| 126 | #endif |
Takashi Iwai | aa1d19f | 2019-06-18 22:34:23 +0200 | [diff] [blame] | 127 | if ((yres < 400) == (f->height <= 8)) |
| 128 | c += 1000; |
Antonino A. Daplas | 2d2699d | 2007-05-08 00:39:11 -0700 | [diff] [blame] | 129 | |
Takashi Iwai | dfd19a5 | 2019-06-18 22:34:25 +0200 | [diff] [blame] | 130 | /* prefer a bigger font for high resolution */ |
| 131 | res = (xres / f->width) * (yres / f->height) / 1000; |
| 132 | if (res > 20) |
| 133 | c += 20 - res; |
| 134 | |
Takashi Iwai | aa1d19f | 2019-06-18 22:34:23 +0200 | [diff] [blame] | 135 | if ((font_w & (1 << (f->width - 1))) && |
| 136 | (font_h & (1 << (f->height - 1)))) |
| 137 | c += 1000; |
Antonino A. Daplas | 2d2699d | 2007-05-08 00:39:11 -0700 | [diff] [blame] | 138 | |
Takashi Iwai | aa1d19f | 2019-06-18 22:34:23 +0200 | [diff] [blame] | 139 | if (c > cc) { |
| 140 | cc = c; |
| 141 | g = f; |
| 142 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | } |
Takashi Iwai | aa1d19f | 2019-06-18 22:34:23 +0200 | [diff] [blame] | 144 | return g; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | EXPORT_SYMBOL(get_default_font); |
| 147 | |
| 148 | MODULE_AUTHOR("James Simmons <jsimmons@users.sf.net>"); |
| 149 | MODULE_DESCRIPTION("Console Fonts"); |
| 150 | MODULE_LICENSE("GPL"); |