2009-07-20 Joe Auricchio <jauricchio@gmail.com>
[grub2/phcoder.git] / include / grub / font.h
blob8a5f3ac7dce87f7264f3835052e94e52b22b4039
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2003,2007,2008,2009 Free Software Foundation, Inc.
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef GRUB_FONT_HEADER
20 #define GRUB_FONT_HEADER 1
22 #include <grub/types.h>
23 #include <grub/video.h>
25 /* Forward declaration of opaque structure grub_font.
26 Users only pass struct grub_font pointers to the font module functions,
27 and do not have knowledge of the structure contents. */
28 struct grub_font;
30 /* Font type used to access font functions. */
31 typedef struct grub_font *grub_font_t;
33 struct grub_font_node
35 struct grub_font_node *next;
36 grub_font_t value;
39 /* Global font registry. */
40 extern struct grub_font_node *grub_font_list;
42 struct grub_font_glyph
44 /* Reference to the font this glyph belongs to. */
45 grub_font_t font;
47 /* Glyph bitmap width in pixels. */
48 grub_uint16_t width;
50 /* Glyph bitmap height in pixels. */
51 grub_uint16_t height;
53 /* Glyph bitmap x offset in pixels. Add to screen coordinate. */
54 grub_int16_t offset_x;
56 /* Glyph bitmap y offset in pixels. Subtract from screen coordinate. */
57 grub_int16_t offset_y;
59 /* Number of pixels to advance to start the next character. */
60 grub_uint16_t device_width;
62 /* Row-major order, packed bits (no padding; rows can break within a byte).
63 The length of the array is (width * height + 7) / 8. Within a
64 byte, the most significant bit is the first (leftmost/uppermost) pixel.
65 Pixels are coded as bits, value 1 meaning of opaque pixel and 0 is
66 transparent. If the length of the array does not fit byte boundary, it
67 will be padded with 0 bits to make it fit. */
68 grub_uint8_t bitmap[0];
71 /* Initialize the font loader.
72 Must be called before any fonts are loaded or used. */
73 void grub_font_loader_init (void);
75 /* Load a font and add it to the beginning of the global font list.
76 Returns: 0 upon success; nonzero upon failure. */
77 int grub_font_load (const char *filename);
79 /* Get the font that has the specified name. Font names are in the form
80 "Family Name Bold Italic 14", where Bold and Italic are optional.
81 If no font matches the name specified, the most recently loaded font
82 is returned as a fallback. */
83 grub_font_t grub_font_get (const char *font_name);
85 const char *grub_font_get_name (grub_font_t font);
87 int grub_font_get_max_char_width (grub_font_t font);
89 int grub_font_get_max_char_height (grub_font_t font);
91 int grub_font_get_ascent (grub_font_t font);
93 int grub_font_get_descent (grub_font_t font);
95 int grub_font_get_leading (grub_font_t font);
97 int grub_font_get_height (grub_font_t font);
99 int grub_font_get_string_width (grub_font_t font, const char *str);
101 struct grub_font_glyph *grub_font_get_glyph (grub_font_t font,
102 grub_uint32_t code);
104 struct grub_font_glyph *grub_font_get_glyph_with_fallback (grub_font_t font,
105 grub_uint32_t code);
107 grub_err_t grub_font_draw_glyph (struct grub_font_glyph *glyph,
108 grub_video_color_t color,
109 int left_x, int baseline_y);
111 grub_err_t grub_font_draw_string (const char *str, grub_font_t font,
112 grub_video_color_t color,
113 int left_x, int baseline_y);
115 #endif /* ! GRUB_FONT_HEADER */