/src/barebox/lib/fonts/fonts.c
Line | Count | Source |
1 | | /* |
2 | | * `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 | | |
15 | | #include <module.h> |
16 | | #include <linux/kernel.h> |
17 | | #include <linux/types.h> |
18 | | #include <linux/string.h> |
19 | | #include <linux/font.h> |
20 | | |
21 | | static char *font_names; |
22 | | |
23 | | static LIST_HEAD(fonts_list); |
24 | | |
25 | | int font_register(struct font_desc *font) |
26 | 78 | { |
27 | 78 | if (font_names) |
28 | 0 | return -EBUSY; |
29 | | |
30 | 78 | list_add_tail(&font->list, &fonts_list); |
31 | | |
32 | 78 | return 0; |
33 | 78 | } |
34 | | int find_font_index(const struct font_desc *font, int ch) |
35 | 0 | { |
36 | 0 | int index; |
37 | 0 | if (font->index == NULL) { |
38 | 0 | index = DIV_ROUND_UP(font->width, 8); |
39 | 0 | index *= font->height; |
40 | 0 | index *= (unsigned char)ch; |
41 | 0 | } else { |
42 | | /* |
43 | | * FIXME: use binary search instead! |
44 | | */ |
45 | 0 | index = font->num_chars - 1; |
46 | |
|
47 | 0 | while (index && font->index[index].wc != ch) |
48 | 0 | index--; |
49 | | |
50 | | /* return 0 if not found. */ |
51 | 0 | index = font->index->index; |
52 | 0 | } |
53 | |
|
54 | 0 | return index; |
55 | 0 | } |
56 | | |
57 | | const struct font_desc *find_font_enum(int n) |
58 | 0 | { |
59 | 0 | struct font_desc *f; |
60 | 0 | int i = 0; |
61 | |
|
62 | 0 | list_for_each_entry(f, &fonts_list, list) { |
63 | 0 | if (i == n) |
64 | 0 | return f; |
65 | 0 | i++; |
66 | 0 | } |
67 | | |
68 | 0 | return NULL; |
69 | 0 | } |
70 | | |
71 | | struct param_d *add_param_font(struct device *dev, |
72 | | int (*set)(struct param_d *p, void *priv), |
73 | | int (*get)(struct param_d *p, void *priv), |
74 | | int *value, void *priv) |
75 | 0 | { |
76 | 0 | struct font_desc *f; |
77 | 0 | int num_fonts = 0; |
78 | |
|
79 | 0 | list_for_each_entry(f, &fonts_list, list) |
80 | 0 | num_fonts++; |
81 | |
|
82 | 0 | if (!font_names) { |
83 | 0 | int i = 0; |
84 | |
|
85 | 0 | font_names = xmalloc(sizeof(char *) * num_fonts); |
86 | |
|
87 | 0 | list_for_each_entry(f, &fonts_list, list) { |
88 | 0 | ((const char **)font_names)[i] = f->name; |
89 | 0 | i++; |
90 | 0 | } |
91 | 0 | } |
92 | |
|
93 | 0 | return dev_add_param_enum(dev, "font", |
94 | 0 | set, get, value, |
95 | 0 | (const char **)font_names, num_fonts, priv); |
96 | 0 | } |
97 | | |
98 | | MODULE_AUTHOR("James Simmons <jsimmons@users.sf.net>"); |
99 | | MODULE_DESCRIPTION("Console Fonts"); |
100 | | MODULE_LICENSE("GPL"); |