fonts.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. #include <linux/module.h>
  15. #include <linux/types.h>
  16. #include <linux/string.h>
  17. #if defined(__mc68000__)
  18. #include <asm/setup.h>
  19. #endif
  20. #include <linux/font.h>
  21. static const struct font_desc *fonts[] = {
  22. #ifdef CONFIG_FONT_8x8
  23. &font_vga_8x8,
  24. #endif
  25. #ifdef CONFIG_FONT_8x16
  26. &font_vga_8x16,
  27. #endif
  28. #ifdef CONFIG_FONT_6x11
  29. &font_vga_6x11,
  30. #endif
  31. #ifdef CONFIG_FONT_7x14
  32. &font_7x14,
  33. #endif
  34. #ifdef CONFIG_FONT_SUN8x16
  35. &font_sun_8x16,
  36. #endif
  37. #ifdef CONFIG_FONT_SUN12x22
  38. &font_sun_12x22,
  39. #endif
  40. #ifdef CONFIG_FONT_10x18
  41. &font_10x18,
  42. #endif
  43. #ifdef CONFIG_FONT_ACORN_8x8
  44. &font_acorn_8x8,
  45. #endif
  46. #ifdef CONFIG_FONT_PEARL_8x8
  47. &font_pearl_8x8,
  48. #endif
  49. #ifdef CONFIG_FONT_MINI_4x6
  50. &font_mini_4x6,
  51. #endif
  52. #ifdef CONFIG_FONT_6x10
  53. &font_6x10,
  54. #endif
  55. #ifdef CONFIG_FONT_TER10x18
  56. &font_ter_10x18,
  57. #endif
  58. #ifdef CONFIG_FONT_TER16x32
  59. &font_ter_16x32,
  60. #endif
  61. #ifdef CONFIG_FONT_6x8
  62. &font_6x8,
  63. #endif
  64. };
  65. #define num_fonts ARRAY_SIZE(fonts)
  66. #ifdef NO_FONTS
  67. #error No fonts configured.
  68. #endif
  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. */
  79. const struct font_desc *find_font(const char *name)
  80. {
  81. unsigned int i;
  82. BUILD_BUG_ON(!num_fonts);
  83. for (i = 0; i < num_fonts; i++)
  84. if (!strcmp(fonts[i]->name, name))
  85. return fonts[i];
  86. return NULL;
  87. }
  88. EXPORT_SYMBOL(find_font);
  89. /**
  90. * get_default_font - get default font
  91. * @xres: screen size of X
  92. * @yres: screen size of Y
  93. * @font_w: bit array of supported widths (1 - FB_MAX_BLIT_WIDTH)
  94. * @font_h: bit array of supported heights (1 - FB_MAX_BLIT_HEIGHT)
  95. *
  96. * Get the default font for a specified screen size.
  97. * Dimensions are in pixels.
  98. *
  99. * font_w or font_h being NULL means all values are supported.
  100. *
  101. * Returns %NULL if no font is found, or a pointer to the
  102. * chosen font.
  103. *
  104. */
  105. const struct font_desc *get_default_font(int xres, int yres,
  106. unsigned long *font_w,
  107. unsigned long *font_h)
  108. {
  109. int i, c, cc, res;
  110. const struct font_desc *f, *g;
  111. g = NULL;
  112. cc = -10000;
  113. for (i = 0; i < num_fonts; i++) {
  114. f = fonts[i];
  115. c = f->pref;
  116. #if defined(__mc68000__)
  117. #ifdef CONFIG_FONT_PEARL_8x8
  118. if (MACH_IS_AMIGA && f->idx == PEARL8x8_IDX)
  119. c = 100;
  120. #endif
  121. #ifdef CONFIG_FONT_6x11
  122. if (MACH_IS_MAC && xres < 640 && f->idx == VGA6x11_IDX)
  123. c = 100;
  124. #endif
  125. #endif
  126. if ((yres < 400) == (f->height <= 8))
  127. c += 1000;
  128. /* prefer a bigger font for high resolution */
  129. res = (xres / f->width) * (yres / f->height) / 1000;
  130. if (res > 20)
  131. c += 20 - res;
  132. if ((!font_w || test_bit(f->width - 1, font_w)) &&
  133. (!font_h || test_bit(f->height - 1, font_h)))
  134. c += 1000;
  135. if (c > cc) {
  136. cc = c;
  137. g = f;
  138. }
  139. }
  140. return g;
  141. }
  142. EXPORT_SYMBOL(get_default_font);
  143. MODULE_AUTHOR("James Simmons <jsimmons@users.sf.net>");
  144. MODULE_DESCRIPTION("Console Fonts");
  145. MODULE_LICENSE("GPL");