blob: e7258d8c252b272b56222ca662ccb197f3bbdf23 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Geert Uytterhoevenee89bd62013-06-09 11:46:43 +02002 * `Soft' font definitions
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
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 Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/module.h>
16#include <linux/types.h>
17#include <linux/string.h>
Adrian Bunk7b892802008-02-06 01:36:29 -080018#if defined(__mc68000__)
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <asm/setup.h>
20#endif
21#include <linux/font.h>
22
Jan Beulich2f4516d2005-09-13 01:25:44 -070023static const struct font_desc *fonts[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#ifdef CONFIG_FONT_8x8
Takashi Iwaiaa1d19f2019-06-18 22:34:23 +020025 &font_vga_8x8,
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#endif
27#ifdef CONFIG_FONT_8x16
Takashi Iwaiaa1d19f2019-06-18 22:34:23 +020028 &font_vga_8x16,
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#endif
30#ifdef CONFIG_FONT_6x11
Takashi Iwaiaa1d19f2019-06-18 22:34:23 +020031 &font_vga_6x11,
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#endif
Jurriaan303b86d2005-06-21 17:17:06 -070033#ifdef CONFIG_FONT_7x14
Takashi Iwaiaa1d19f2019-06-18 22:34:23 +020034 &font_7x14,
Jurriaan303b86d2005-06-21 17:17:06 -070035#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#ifdef CONFIG_FONT_SUN8x16
Takashi Iwaiaa1d19f2019-06-18 22:34:23 +020037 &font_sun_8x16,
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#endif
39#ifdef CONFIG_FONT_SUN12x22
Takashi Iwaiaa1d19f2019-06-18 22:34:23 +020040 &font_sun_12x22,
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#endif
Jurriaan303b86d2005-06-21 17:17:06 -070042#ifdef CONFIG_FONT_10x18
Takashi Iwaiaa1d19f2019-06-18 22:34:23 +020043 &font_10x18,
Jurriaan303b86d2005-06-21 17:17:06 -070044#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#ifdef CONFIG_FONT_ACORN_8x8
Takashi Iwaiaa1d19f2019-06-18 22:34:23 +020046 &font_acorn_8x8,
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#endif
48#ifdef CONFIG_FONT_PEARL_8x8
Takashi Iwaiaa1d19f2019-06-18 22:34:23 +020049 &font_pearl_8x8,
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#endif
51#ifdef CONFIG_FONT_MINI_4x6
Takashi Iwaiaa1d19f2019-06-18 22:34:23 +020052 &font_mini_4x6,
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#endif
Maarten ter Huurne33ac9db2014-09-09 13:46:28 +020054#ifdef CONFIG_FONT_6x10
Takashi Iwaiaa1d19f2019-06-18 22:34:23 +020055 &font_6x10,
Maarten ter Huurne33ac9db2014-09-09 13:46:28 +020056#endif
Amanoel Dawodac8b6f12018-12-05 18:56:37 -050057#ifdef CONFIG_FONT_TER16x32
Takashi Iwaiaa1d19f2019-06-18 22:34:23 +020058 &font_ter_16x32,
Amanoel Dawodac8b6f12018-12-05 18:56:37 -050059#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070060};
61
Tobias Klauserd1ae4182006-03-27 01:17:39 -080062#define num_fonts ARRAY_SIZE(fonts)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
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 Beulich2f4516d2005-09-13 01:25:44 -070079const struct font_desc *find_font(const char *name)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080{
Takashi Iwaiaa1d19f2019-06-18 22:34:23 +020081 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Takashi Iwai73a649d2019-06-18 22:34:24 +020083 BUILD_BUG_ON(!num_fonts);
Takashi Iwaiaa1d19f2019-06-18 22:34:23 +020084 for (i = 0; i < num_fonts; i++)
85 if (!strcmp(fonts[i]->name, name))
86 return fonts[i];
87 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088}
Takashi Iwaiaa1d19f2019-06-18 22:34:23 +020089EXPORT_SYMBOL(find_font);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
91
92/**
93 * get_default_font - get default font
94 * @xres: screen size of X
95 * @yres: screen size of Y
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -070096 * @font_w: bit array of supported widths (1 - 32)
97 * @font_h: bit array of supported heights (1 - 32)
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 *
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. Daplas2d2699d2007-05-08 00:39:11 -0700106const struct font_desc *get_default_font(int xres, int yres, u32 font_w,
107 u32 font_h)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108{
Takashi Iwaidfd19a52019-06-18 22:34:25 +0200109 int i, c, cc, res;
Takashi Iwaiaa1d19f2019-06-18 22:34:23 +0200110 const struct font_desc *f, *g;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
Takashi Iwaiaa1d19f2019-06-18 22:34:23 +0200112 g = NULL;
113 cc = -10000;
114 for (i = 0; i < num_fonts; i++) {
115 f = fonts[i];
116 c = f->pref;
Adrian Bunk7b892802008-02-06 01:36:29 -0800117#if defined(__mc68000__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118#ifdef CONFIG_FONT_PEARL_8x8
Takashi Iwaiaa1d19f2019-06-18 22:34:23 +0200119 if (MACH_IS_AMIGA && f->idx == PEARL8x8_IDX)
120 c = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121#endif
122#ifdef CONFIG_FONT_6x11
Takashi Iwaiaa1d19f2019-06-18 22:34:23 +0200123 if (MACH_IS_MAC && xres < 640 && f->idx == VGA6x11_IDX)
124 c = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125#endif
126#endif
Takashi Iwaiaa1d19f2019-06-18 22:34:23 +0200127 if ((yres < 400) == (f->height <= 8))
128 c += 1000;
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -0700129
Takashi Iwaidfd19a52019-06-18 22:34:25 +0200130 /* 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 Iwaiaa1d19f2019-06-18 22:34:23 +0200135 if ((font_w & (1 << (f->width - 1))) &&
136 (font_h & (1 << (f->height - 1))))
137 c += 1000;
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -0700138
Takashi Iwaiaa1d19f2019-06-18 22:34:23 +0200139 if (c > cc) {
140 cc = c;
141 g = f;
142 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 }
Takashi Iwaiaa1d19f2019-06-18 22:34:23 +0200144 return g;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146EXPORT_SYMBOL(get_default_font);
147
148MODULE_AUTHOR("James Simmons <jsimmons@users.sf.net>");
149MODULE_DESCRIPTION("Console Fonts");
150MODULE_LICENSE("GPL");