| 1 |
/* |
| 2 |
* `Soft' font definitions |
| 3 |
* |
| 4 |
* Created 1995 by Geert Uytterhoeven |
| 5 |
* Rewritten 1998 by Martin Mares <[email protected]> |
| 6 |
* |
| 7 |
* 2001 - Documented with DocBook |
| 8 |
* - Brad Douglas <[email protected]> |
| 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 |
|
| 15 |
#include <linux/module.h> |
| 16 |
#include <linux/types.h> |
| 17 |
#include <linux/string.h> |
| 18 |
#if defined(__mc68000__) |
| 19 |
#include <asm/setup.h> |
| 20 |
#endif |
| 21 |
#include <linux/font.h> |
| 22 |
|
| 23 |
static const struct font_desc *fonts[] = { |
| 24 |
#ifdef CONFIG_FONT_8x8 |
| 25 |
&font_vga_8x8, |
| 26 |
#endif |
| 27 |
#ifdef CONFIG_FONT_8x16 |
| 28 |
&font_vga_8x16, |
| 29 |
#endif |
| 30 |
#ifdef CONFIG_FONT_6x11 |
| 31 |
&font_vga_6x11, |
| 32 |
#endif |
| 33 |
#ifdef CONFIG_FONT_7x14 |
| 34 |
&font_7x14, |
| 35 |
#endif |
| 36 |
#ifdef CONFIG_FONT_SUN8x16 |
| 37 |
&font_sun_8x16, |
| 38 |
#endif |
| 39 |
#ifdef CONFIG_FONT_SUN12x22 |
| 40 |
&font_sun_12x22, |
| 41 |
#endif |
| 42 |
#ifdef CONFIG_FONT_10x18 |
| 43 |
&font_10x18, |
| 44 |
#endif |
| 45 |
#ifdef CONFIG_FONT_ACORN_8x8 |
| 46 |
&font_acorn_8x8, |
| 47 |
#endif |
| 48 |
#ifdef CONFIG_FONT_PEARL_8x8 |
| 49 |
&font_pearl_8x8, |
| 50 |
#endif |
| 51 |
#ifdef CONFIG_FONT_MINI_4x6 |
| 52 |
&font_mini_4x6, |
| 53 |
#endif |
| 54 |
#ifdef CONFIG_FONT_6x10 |
| 55 |
&font_6x10, |
| 56 |
#endif |
| 57 |
#ifdef CONFIG_FONT_TER10x18 |
| 58 |
&font_ter_10x18, |
| 59 |
#endif |
| 60 |
#ifdef CONFIG_FONT_TER16x32 |
| 61 |
&font_ter_16x32, |
| 62 |
#endif |
| 63 |
#ifdef CONFIG_FONT_6x8 |
| 64 |
&font_6x8, |
| 65 |
#endif |
| 66 |
}; |
| 67 |
|
| 68 |
#define num_fonts ARRAY_SIZE(fonts) |
| 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 |
const struct font_desc *find_font(const char *name) |
| 86 |
{ |
| 87 |
unsigned int i; |
| 88 |
|
| 89 |
BUILD_BUG_ON(!num_fonts); |
| 90 |
for (i = 0; i < num_fonts; i++) |
| 91 |
if (!strcmp(fonts[i]->name, name)) |
| 92 |
return fonts[i]; |
| 93 |
return NULL; |
| 94 |
} |
| 95 |
EXPORT_SYMBOL(find_font); |
| 96 |
|
| 97 |
|
| 98 |
/** |
| 99 |
* get_default_font - get default font |
| 100 |
* @xres: screen size of X |
| 101 |
* @yres: screen size of Y |
| 102 |
* @font_w: bit array of supported widths (1 - FB_MAX_BLIT_WIDTH) |
| 103 |
* @font_h: bit array of supported heights (1 - FB_MAX_BLIT_HEIGHT) |
| 104 |
* |
| 105 |
* Get the default font for a specified screen size. |
| 106 |
* Dimensions are in pixels. |
| 107 |
* |
| 108 |
* font_w or font_h being NULL means all values are supported. |
| 109 |
* |
| 110 |
* Returns %NULL if no font is found, or a pointer to the |
| 111 |
* chosen font. |
| 112 |
* |
| 113 |
*/ |
| 114 |
const struct font_desc *get_default_font(int xres, int yres, |
| 115 |
unsigned long *font_w, |
| 116 |
unsigned long *font_h) |
| 117 |
{ |
| 118 |
int i, c, cc, res; |
| 119 |
const struct font_desc *f, *g; |
| 120 |
|
| 121 |
g = NULL; |
| 122 |
cc = -10000; |
| 123 |
for (i = 0; i < num_fonts; i++) { |
| 124 |
f = fonts[i]; |
| 125 |
c = f->pref; |
| 126 |
#if defined(__mc68000__) |
| 127 |
#ifdef CONFIG_FONT_PEARL_8x8 |
| 128 |
if (MACH_IS_AMIGA && f->idx == PEARL8x8_IDX) |
| 129 |
c = 100; |
| 130 |
#endif |
| 131 |
#ifdef CONFIG_FONT_6x11 |
| 132 |
if (MACH_IS_MAC && xres < 640 && f->idx == VGA6x11_IDX) |
| 133 |
c = 100; |
| 134 |
#endif |
| 135 |
#endif |
| 136 |
if ((yres < 400) == (f->height <= 8)) |
| 137 |
c += 1000; |
| 138 |
|
| 139 |
/* prefer a bigger font for high resolution */ |
| 140 |
res = (xres / f->width) * (yres / f->height) / 1000; |
| 141 |
if (res > 20) |
| 142 |
c += 20 - res; |
| 143 |
|
| 144 |
if ((!font_w || test_bit(f->width - 1, font_w)) && |
| 145 |
(!font_h || test_bit(f->height - 1, font_h))) |
| 146 |
c += 1000; |
| 147 |
|
| 148 |
if (c > cc) { |
| 149 |
cc = c; |
| 150 |
g = f; |
| 151 |
} |
| 152 |
} |
| 153 |
return g; |
| 154 |
} |
| 155 |
EXPORT_SYMBOL(get_default_font); |
| 156 |
|
| 157 |
MODULE_AUTHOR("James Simmons <[email protected]>"); |
| 158 |
MODULE_DESCRIPTION("Console Fonts"); |
| 159 |
MODULE_LICENSE("GPL"); |