File: figfont.py

package info (click to toggle)
libcaca 0.99.beta20-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,540 kB
  • sloc: ansic: 25,091; php: 2,763; python: 2,637; cs: 1,213; cpp: 1,127; java: 916; objc: 836; makefile: 545; perl: 505; sh: 472; asm: 297; ruby: 215; xml: 33
file content (56 lines) | stat: -rwxr-xr-x 1,421 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# figfont       libcaca FIGfont test program
# Copyright (c) 2010 Alex Foulon <alxf@lavabit.com>
#
# This file is a Python port of "examples/figfont.c"
# which is:
# Copyright (c) 2007-2010 Sam Hocevar <sam@hocevar.net>
#               All Rights Reserverd
#
# This library is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What the Fuck You Want
# to Public License, Version 2, as published by Sam Hocevar. See
# http://www.wtfpl.net/ for more details.
#

import codecs
import os
import sys

import caca
from caca.canvas import Canvas, CanvasError

def main():
    """ Main function. """


    if len(sys.argv) < 3:
        sys.stderr.write("Usage: %s <figfont file> <word>\n" \
                            % os.path.basename(sys.argv[0]))
        sys.exit(2)

    try:
        cv = Canvas(0, 0)
    except CanvasError as err:
        sys.stderr.write("%s\n" % err)
        sys.exit(2)

    if cv.set_figfont(sys.argv[1]):
        sys.stderr.write("Could not open font...\n")
        sys.exit(2)

    if sys.version_info[0:2] >= (3,0):
        word = sys.argv[2]
    else:
        word = codecs.decode(sys.argv[2], "utf8")
    for c in word:
        cv.put_figchar(c)

    sys.stderr.write(cv.export_to_memory("utf8"))

if __name__ == "__main__":
    main()