File: text_ex.py

package info (click to toggle)
python-enable 4.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 7,280 kB
  • ctags: 13,899
  • sloc: cpp: 48,447; python: 28,502; ansic: 9,004; makefile: 315; sh: 44
file content (85 lines) | stat: -rw-r--r-- 1,713 bytes parent folder | download | duplicates (2)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
from __future__ import with_statement

import time
from kiva.fonttools import Font
from kiva.constants import MODERN
from kiva.agg import AffineMatrix, GraphicsContextArray

gc = GraphicsContextArray((200,200))

font = Font(family=MODERN)
#print font.size
font.size=8
gc.set_font(font)


t1 = time.clock()

# consecutive printing of text.
with gc:
    gc.set_antialias(False)
    gc.set_fill_color((0,1,0))
    gc.translate_ctm(50,50)
    gc.rotate_ctm(3.1416/4)
    gc.show_text("hello")
    gc.translate_ctm(-50,-50)
    gc.set_text_matrix(AffineMatrix())
    gc.set_fill_color((0,1,1))
    gc.show_text("hello")

t2 = time.clock()
print 'aliased:', t2 - t1
gc.save("text_aliased.bmp")

gc = GraphicsContextArray((200,200))

font = Font(family=MODERN)
#print font.size
font.size=8
gc.set_font(font)

t1 = time.clock()

with gc:
    gc.set_antialias(True)
    gc.set_fill_color((0,1,0))
    gc.translate_ctm(50,50)
    gc.rotate_ctm(3.1416/4)
    gc.show_text("hello")
    gc.translate_ctm(-50,-50)
    gc.set_text_matrix(AffineMatrix())
    gc.set_fill_color((0,1,1))
    gc.show_text("hello")

t2 = time.clock()
print 'antialiased:', t2 - t1
gc.save("text_antialiased.bmp")

"""
with gc:
    gc.set_fill_color((0,1,0))
    gc.rotate_ctm(-45)
    gc.show_text_at_point("hello")
    gc.set_fill_color((0,1,1))
    gc.show_text("hello")

with gc:
    gc.translate_ctm(80,-3)
    gc.show_text("hello")

with gc:
    gc.set_fill_color((0,1,0))
    gc.translate_ctm(50,50)
    gc.show_text("hello")

with gc:
    gc.set_fill_color((0,1,0))
    gc.translate_ctm(50,50)
    gc.rotate_ctm(3.1416/4)
    gc.show_text("hello")
    gc.set_fill_color((1,0,0))
    gc.show_text("hello")
"""


gc.save("text_antiliased.bmp")