您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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://sam.zoy.org/wtfpl/COPYING 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, 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, 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, err:
  55. sys.stderr.write("%s\n" % err)
  56. sys.exit(127)
  57. if sys.byteorder == 'big':
  58. dit = Dither(32, w, h, 4 * w, 0xff0000, 0xff00, 0xff, 0xff000000)
  59. else:
  60. dit = Dither(32, w, h, 4 * w, 0xff00, 0xff0000, 0xff000000, 0xff)
  61. dit.bitmap(cv, 0, 0, cv.get_width(), cv.get_height(), buf)
  62. dp.refresh()
  63. dp.get_event(caca.EVENT_KEY_PRESS, Event(), -1)
  64. if __name__ == "__main__":
  65. main()