font.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (c) 2008-2010 Travis Geiselbrecht
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining
  5. * a copy of this software and associated documentation files
  6. * (the "Software"), to deal in the Software without restriction,
  7. * including without limitation the rights to use, copy, modify, merge,
  8. * publish, distribute, sublicense, and/or sell copies of the Software,
  9. * and to permit persons to whom the Software is furnished to do so,
  10. * subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be
  13. * included in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  18. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  19. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  20. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  21. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. /**
  24. * @file
  25. * @brief Font display
  26. *
  27. * This file contains functions to render fonts onto the graphics drawing
  28. * surface.
  29. *
  30. * @ingroup graphics
  31. */
  32. #include <debug.h>
  33. #include <lib/gfx.h>
  34. #include <lib/font.h>
  35. #include "font.h"
  36. /**
  37. * @brief Draw one character from the built-in font
  38. *
  39. * @ingroup graphics
  40. */
  41. void font_draw_char(gfx_surface *surface, unsigned char c, int x, int y, uint32_t color)
  42. {
  43. uint i,j;
  44. uint line;
  45. // draw this char into a buffer
  46. for (i = 0; i < FONT_Y; i++) {
  47. line = FONT[c * FONT_Y + i];
  48. for (j = 0; j < FONT_X; j++) {
  49. if (line & 0x1)
  50. gfx_putpixel(surface, x + j, y + i, color);
  51. line = line >> 1;
  52. }
  53. }
  54. gfx_flush_rows(surface, y, y + FONT_Y);
  55. }