font.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2003,2007,2008,2009 Free Software Foundation, Inc.
  4. *
  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.
  9. *
  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.
  14. *
  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/>.
  17. */
  18. #ifndef GRUB_FONT_HEADER
  19. #define GRUB_FONT_HEADER 1
  20. #include <grub/types.h>
  21. #include <grub/video.h>
  22. #include <grub/file.h>
  23. /* Forward declaration of opaque structure grub_font.
  24. Users only pass struct grub_font pointers to the font module functions,
  25. and do not have knowledge of the structure contents. */
  26. struct grub_font;
  27. /* Font type used to access font functions. */
  28. typedef struct grub_font *grub_font_t;
  29. struct grub_font_node
  30. {
  31. struct grub_font_node *next;
  32. grub_font_t value;
  33. };
  34. /* Global font registry. */
  35. extern struct grub_font_node *grub_font_list;
  36. struct grub_font_glyph
  37. {
  38. /* Reference to the font this glyph belongs to. */
  39. grub_font_t font;
  40. /* Glyph bitmap width in pixels. */
  41. grub_uint16_t width;
  42. /* Glyph bitmap height in pixels. */
  43. grub_uint16_t height;
  44. /* Glyph bitmap x offset in pixels. Add to screen coordinate. */
  45. grub_int16_t offset_x;
  46. /* Glyph bitmap y offset in pixels. Subtract from screen coordinate. */
  47. grub_int16_t offset_y;
  48. /* Number of pixels to advance to start the next character. */
  49. grub_uint16_t device_width;
  50. /* Row-major order, packed bits (no padding; rows can break within a byte).
  51. The length of the array is (width * height + 7) / 8. Within a
  52. byte, the most significant bit is the first (leftmost/uppermost) pixel.
  53. Pixels are coded as bits, value 1 meaning of opaque pixel and 0 is
  54. transparent. If the length of the array does not fit byte boundary, it
  55. will be padded with 0 bits to make it fit. */
  56. grub_uint8_t bitmap[0];
  57. };
  58. /* Initialize the font loader.
  59. Must be called before any fonts are loaded or used. */
  60. void grub_font_loader_init (void);
  61. /* Load a font and add it to the beginning of the global font list.
  62. Returns: 0 upon success; nonzero upon failure. */
  63. int grub_font_load (const char *filename);
  64. /* Get the font that has the specified name. Font names are in the form
  65. "Family Name Bold Italic 14", where Bold and Italic are optional.
  66. If no font matches the name specified, the most recently loaded font
  67. is returned as a fallback. */
  68. grub_font_t grub_font_get (const char *font_name);
  69. const char *grub_font_get_name (grub_font_t font);
  70. int grub_font_get_max_char_width (grub_font_t font);
  71. int grub_font_get_max_char_height (grub_font_t font);
  72. int grub_font_get_ascent (grub_font_t font);
  73. int grub_font_get_descent (grub_font_t font);
  74. int grub_font_get_leading (grub_font_t font);
  75. int grub_font_get_height (grub_font_t font);
  76. int grub_font_get_code_width (grub_font_t font, const char *str,
  77. const char **end);
  78. int grub_font_get_string_width (grub_font_t font, const char *str);
  79. struct grub_font_glyph *grub_font_get_glyph (grub_font_t font,
  80. grub_uint32_t code);
  81. struct grub_font_glyph *grub_font_get_glyph_with_fallback (grub_font_t font,
  82. grub_uint32_t code);
  83. grub_err_t grub_font_draw_glyph (struct grub_font_glyph *glyph,
  84. grub_video_color_t color,
  85. int left_x, int baseline_y);
  86. grub_err_t grub_font_draw_string (const char *str, grub_font_t font,
  87. grub_video_color_t color,
  88. int left_x, int baseline_y);
  89. #endif /* ! GRUB_FONT_HEADER */