]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - lib/fonts/fonts.c
fonts: Prefer a bigger font for high resolution screens
[mirror_ubuntu-bionic-kernel.git] / lib / fonts / fonts.c
CommitLineData
1da177e4 1/*
ee89bd6b 2 * `Soft' font definitions
1da177e4
LT
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
1da177e4
LT
15#include <linux/module.h>
16#include <linux/types.h>
17#include <linux/string.h>
7b892806 18#if defined(__mc68000__)
1da177e4
LT
19#include <asm/setup.h>
20#endif
21#include <linux/font.h>
22
23#define NO_FONTS
24
2f4516db 25static const struct font_desc *fonts[] = {
1da177e4
LT
26#ifdef CONFIG_FONT_8x8
27#undef NO_FONTS
c49ea985 28 &font_vga_8x8,
1da177e4
LT
29#endif
30#ifdef CONFIG_FONT_8x16
31#undef NO_FONTS
c49ea985 32 &font_vga_8x16,
1da177e4
LT
33#endif
34#ifdef CONFIG_FONT_6x11
35#undef NO_FONTS
c49ea985 36 &font_vga_6x11,
1da177e4 37#endif
303b86d9
J
38#ifdef CONFIG_FONT_7x14
39#undef NO_FONTS
c49ea985 40 &font_7x14,
303b86d9 41#endif
1da177e4
LT
42#ifdef CONFIG_FONT_SUN8x16
43#undef NO_FONTS
c49ea985 44 &font_sun_8x16,
1da177e4
LT
45#endif
46#ifdef CONFIG_FONT_SUN12x22
47#undef NO_FONTS
c49ea985 48 &font_sun_12x22,
1da177e4 49#endif
303b86d9
J
50#ifdef CONFIG_FONT_10x18
51#undef NO_FONTS
c49ea985 52 &font_10x18,
303b86d9 53#endif
1da177e4
LT
54#ifdef CONFIG_FONT_ACORN_8x8
55#undef NO_FONTS
c49ea985 56 &font_acorn_8x8,
1da177e4
LT
57#endif
58#ifdef CONFIG_FONT_PEARL_8x8
59#undef NO_FONTS
c49ea985 60 &font_pearl_8x8,
1da177e4
LT
61#endif
62#ifdef CONFIG_FONT_MINI_4x6
63#undef NO_FONTS
c49ea985 64 &font_mini_4x6,
1da177e4 65#endif
33ac9dba
MH
66#ifdef CONFIG_FONT_6x10
67#undef NO_FONTS
c49ea985 68 &font_6x10,
33ac9dba 69#endif
2680bb61
AD
70#ifdef CONFIG_FONT_TER16x32
71#undef NO_FONTS
c49ea985 72 &font_ter_16x32,
2680bb61 73#endif
1da177e4
LT
74};
75
d1ae418e 76#define num_fonts ARRAY_SIZE(fonts)
1da177e4
LT
77
78#ifdef NO_FONTS
79#error No fonts configured.
80#endif
81
82
83/**
84 * find_font - find a font
85 * @name: string name of a font
86 *
87 * Find a specified font with string name @name.
88 *
89 * Returns %NULL if no font found, or a pointer to the
90 * specified font.
91 *
92 */
2f4516db 93const struct font_desc *find_font(const char *name)
1da177e4 94{
c49ea985 95 unsigned int i;
1da177e4 96
c49ea985
TI
97 for (i = 0; i < num_fonts; i++)
98 if (!strcmp(fonts[i]->name, name))
99 return fonts[i];
100 return NULL;
1da177e4 101}
c49ea985 102EXPORT_SYMBOL(find_font);
1da177e4
LT
103
104
105/**
106 * get_default_font - get default font
107 * @xres: screen size of X
108 * @yres: screen size of Y
2d2699d9
AD
109 * @font_w: bit array of supported widths (1 - 32)
110 * @font_h: bit array of supported heights (1 - 32)
1da177e4
LT
111 *
112 * Get the default font for a specified screen size.
113 * Dimensions are in pixels.
114 *
115 * Returns %NULL if no font is found, or a pointer to the
116 * chosen font.
117 *
118 */
2d2699d9
AD
119const struct font_desc *get_default_font(int xres, int yres, u32 font_w,
120 u32 font_h)
1da177e4 121{
c422b6cb 122 int i, c, cc, res;
c49ea985
TI
123 const struct font_desc *f, *g;
124
125 g = NULL;
126 cc = -10000;
127 for (i = 0; i < num_fonts; i++) {
128 f = fonts[i];
129 c = f->pref;
7b892806 130#if defined(__mc68000__)
1da177e4 131#ifdef CONFIG_FONT_PEARL_8x8
c49ea985
TI
132 if (MACH_IS_AMIGA && f->idx == PEARL8x8_IDX)
133 c = 100;
1da177e4
LT
134#endif
135#ifdef CONFIG_FONT_6x11
c49ea985
TI
136 if (MACH_IS_MAC && xres < 640 && f->idx == VGA6x11_IDX)
137 c = 100;
1da177e4
LT
138#endif
139#endif
c49ea985
TI
140 if ((yres < 400) == (f->height <= 8))
141 c += 1000;
2d2699d9 142
c422b6cb
TI
143 /* prefer a bigger font for high resolution */
144 res = (xres / f->width) * (yres / f->height) / 1000;
145 if (res > 20)
146 c += 20 - res;
147
c49ea985
TI
148 if ((font_w & (1 << (f->width - 1))) &&
149 (font_h & (1 << (f->height - 1))))
150 c += 1000;
2d2699d9 151
c49ea985
TI
152 if (c > cc) {
153 cc = c;
154 g = f;
155 }
1da177e4 156 }
c49ea985 157 return g;
1da177e4 158}
1da177e4
LT
159EXPORT_SYMBOL(get_default_font);
160
161MODULE_AUTHOR("James Simmons <jsimmons@users.sf.net>");
162MODULE_DESCRIPTION("Console Fonts");
163MODULE_LICENSE("GPL");