Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

86 рядки
2.3 KiB

  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # font libcaca font test program
  5. # Copyright (c) 2010 Alex Foulon <alxf@lavabit.com>
  6. #
  7. # This file is a Python port of "examples/font.c"
  8. # which is:
  9. # Copyright (c) 2006-2010 Sam Hocevar <sam@hocevar.net>
  10. # All Rights Reserverd
  11. #
  12. # This library is free software. It comes without any warranty, to
  13. # the extent permitted by applicable law. You can redistribute it
  14. # and/or modify it under the terms of the Do What the Fuck You Want
  15. # to Public License, Version 2, as published by Sam Hocevar. See
  16. # http://www.wtfpl.net/ for more details.
  17. #
  18. import ctypes
  19. import sys
  20. import caca
  21. from caca.canvas import Canvas, CanvasError
  22. from caca.display import Display, DisplayError, Event
  23. from caca.dither import Dither, DitherError
  24. from caca.font import Font, FontError
  25. def main():
  26. """ Main function. """
  27. try:
  28. cv = Canvas(8, 2)
  29. except CanvasError as err:
  30. sys.stderr.write("%s\n" % err)
  31. sys.exit(127)
  32. cv.set_color_ansi(caca.COLOR_WHITE, caca.COLOR_BLACK)
  33. cv.put_str(0, 0, "ABcde")
  34. cv.set_color_ansi(caca.COLOR_LIGHTRED, caca.COLOR_BLACK)
  35. cv.put_str(5, 0, "\\o/")
  36. cv.set_color_ansi(caca.COLOR_WHITE, caca.COLOR_BLUE)
  37. cv.put_str(0, 1, "&$âøÿØ?!")
  38. fonts = caca.get_font_list()
  39. if not fonts:
  40. sys.stderr.write("libcaca was compiled without any fonts\n")
  41. sys.exit(127)
  42. try:
  43. f = Font(fonts[0])
  44. except FontError as err:
  45. sys.stderr.write("%s\n" % err)
  46. sys.exit(127)
  47. w = cv.get_width() * f.get_width()
  48. h = cv.get_height() * f.get_height()
  49. buf = ctypes.c_buffer(4 * w * h)
  50. cv.render(f, buf, w, h, 4 * w)
  51. cv.set_size(80, 32)
  52. try:
  53. dp = Display(cv)
  54. except DisplayError as err:
  55. sys.stderr.write("%s\n" % err)
  56. sys.exit(127)
  57. try:
  58. if sys.byteorder == 'big':
  59. dit = Dither(32, w, h, 4 * w, 0xff0000, 0xff00, 0xff, 0xff000000)
  60. else:
  61. dit = Dither(32, w, h, 4 * w, 0xff00, 0xff0000, 0xff000000, 0xff)
  62. dit.bitmap(cv, 0, 0, cv.get_width(), cv.get_height(), buf)
  63. except DitherError as err:
  64. sys.stderr.write("%s\n" % err)
  65. sys.exit(127)
  66. else:
  67. dp.refresh()
  68. dp.get_event(caca.EVENT_KEY_PRESS, Event(), -1)
  69. if __name__ == "__main__":
  70. main()