fonts.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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_TER16x32
  56. &font_ter_16x32,
  57. #endif
  58. #ifdef CONFIG_FONT_6x8
  59. &font_6x8,
  60. #endif
  61. };
  62. #define num_fonts ARRAY_SIZE(fonts)
  63. #ifdef NO_FONTS
  64. #error No fonts configured.
  65. #endif
  66. /**
  67. * find_font - find a font
  68. * @name: string name of a font
  69. *
  70. * Find a specified font with string name @name.
  71. *
  72. * Returns %NULL if no font found, or a pointer to the
  73. * specified font.
  74. *
  75. */
  76. const struct font_desc *find_font(const char *name)
  77. {
  78. unsigned int i;
  79. BUILD_BUG_ON(!num_fonts);
  80. for (i = 0; i < num_fonts; i++)
  81. if (!strcmp(fonts[i]->name, name))
  82. return fonts[i];
  83. return NULL;
  84. }
  85. EXPORT_SYMBOL(find_font);
  86. /**
  87. * get_default_font - get default font
  88. * @xres: screen size of X
  89. * @yres: screen size of Y
  90. * @font_w: bit array of supported widths (1 - 32)
  91. * @font_h: bit array of supported heights (1 - 32)
  92. *
  93. * Get the default font for a specified screen size.
  94. * Dimensions are in pixels.
  95. *
  96. * Returns %NULL if no font is found, or a pointer to the
  97. * chosen font.
  98. *
  99. */
  100. const struct font_desc *get_default_font(int xres, int yres, u32 font_w,
  101. u32 font_h)
  102. {
  103. int i, c, cc, res;
  104. const struct font_desc *f, *g;
  105. g = NULL;
  106. cc = -10000;
  107. for (i = 0; i < num_fonts; i++) {
  108. f = fonts[i];
  109. c = f->pref;
  110. #if defined(__mc68000__)
  111. #ifdef CONFIG_FONT_PEARL_8x8
  112. if (MACH_IS_AMIGA && f->idx == PEARL8x8_IDX)
  113. c = 100;
  114. #endif
  115. #ifdef CONFIG_FONT_6x11
  116. if (MACH_IS_MAC && xres < 640 && f->idx == VGA6x11_IDX)
  117. c = 100;
  118. #endif
  119. #endif
  120. if ((yres < 400) == (f->height <= 8))
  121. c += 1000;
  122. /* prefer a bigger font for high resolution */
  123. res = (xres / f->width) * (yres / f->height) / 1000;
  124. if (res > 20)
  125. c += 20 - res;
  126. if ((font_w & (1 << (f->width - 1))) &&
  127. (font_h & (1 << (f->height - 1))))
  128. c += 1000;
  129. if (c > cc) {
  130. cc = c;
  131. g = f;
  132. }
  133. }
  134. return g;
  135. }
  136. EXPORT_SYMBOL(get_default_font);
  137. MODULE_AUTHOR("James Simmons <jsimmons@users.sf.net>");
  138. MODULE_DESCRIPTION("Console Fonts");
  139. MODULE_LICENSE("GPL");