source: libcaca/trunk/python/examples/figfont.py @ 4802

Last change on this file since 4802 was 4802, checked in by alxf, 2 years ago

Add support for python3 to python bindings.

  • Property svn:executable set to *
File size: 1.4 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3#
4# figfont       libcaca FIGfont test program
5# Copyright (c) 2010 Alex Foulon <alxf@lavabit.com>
6#
7# This file is a Python port of "examples/figfont.c"
8# which is:
9# Copyright (c) 2007-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
19import codecs
20import os
21import sys
22
23import caca
24from caca.canvas import Canvas, CanvasError
25
26def main():
27    """ Main function. """
28
29
30    if len(sys.argv) < 3:
31        sys.stderr.write("Usage: %s <figfont file> <word>\n" \
32                            % os.path.basename(sys.argv[0]))
33        sys.exit(2)
34
35    try:
36        cv = Canvas(0, 0)
37    except CanvasError as err:
38        sys.stderr.write("%s\n" % err)
39        sys.exit(2)
40
41    if cv.set_figfont(sys.argv[1]):
42        sys.stderr.write("Could not open font...\n")
43        sys.exit(2)
44
45    if sys.version_info[0:2] >= (3,0):
46        word = sys.argv[2]
47    else:
48        word = codecs.decode(sys.argv[2], "utf8")
49    for c in word:
50        cv.put_figchar(c)
51
52    sys.stderr.write(cv.export_to_memory("utf8"))
53
54if __name__ == "__main__":
55    main()
56
Note: See TracBrowser for help on using the repository browser.