~ubuntu-branches/ubuntu/wily/python-imaging/wily

« back to all changes in this revision

Viewing changes to .pc/git-updates.diff/PIL/ImageDraw2.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-01-31 20:49:20 UTC
  • mfrom: (27.1.1 raring-proposed)
  • Revision ID: package-import@ubuntu.com-20130131204920-b5zshy6vgfvdionl
Tags: 1.1.7+1.7.8-1ubuntu1
Rewrite build dependencies to allow cross builds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# The Python Imaging Library
 
3
# $Id$
 
4
#
 
5
# WCK-style drawing interface operations
 
6
#
 
7
# History:
 
8
# 2003-12-07 fl   created
 
9
# 2005-05-15 fl   updated; added to PIL as ImageDraw2
 
10
# 2005-05-15 fl   added text support
 
11
# 2005-05-20 fl   added arc/chord/pieslice support
 
12
#
 
13
# Copyright (c) 2003-2005 by Secret Labs AB
 
14
# Copyright (c) 2003-2005 by Fredrik Lundh
 
15
#
 
16
# See the README file for information on usage and redistribution.
 
17
#
 
18
 
 
19
import Image, ImageColor, ImageDraw, ImageFont, ImagePath
 
20
 
 
21
class Pen:
 
22
    def __init__(self, color, width=1, opacity=255):
 
23
        self.color = ImageColor.getrgb(color)
 
24
        self.width = width
 
25
 
 
26
class Brush:
 
27
    def __init__(self, color, opacity=255):
 
28
        self.color = ImageColor.getrgb(color)
 
29
 
 
30
class Font:
 
31
    def __init__(self, color, file, size=12):
 
32
        # FIXME: add support for bitmap fonts
 
33
        self.color = ImageColor.getrgb(color)
 
34
        self.font = ImageFont.truetype(file, size)
 
35
 
 
36
class Draw:
 
37
 
 
38
    def __init__(self, image, size=None, color=None):
 
39
        if not hasattr(image, "im"):
 
40
            image = Image.new(image, size, color)
 
41
        self.draw = ImageDraw.Draw(image)
 
42
        self.image = image
 
43
        self.transform = None
 
44
 
 
45
    def flush(self):
 
46
        return self.image
 
47
 
 
48
    def render(self, op, xy, pen, brush=None):
 
49
        # handle color arguments
 
50
        outline = fill = None; width = 1
 
51
        if isinstance(pen, Pen):
 
52
            outline = pen.color
 
53
            width = pen.width
 
54
        elif isinstance(brush, Pen):
 
55
            outline = brush.color
 
56
            width = brush.width
 
57
        if isinstance(brush, Brush):
 
58
            fill = brush.color
 
59
        elif isinstance(pen, Brush):
 
60
            fill = pen.color
 
61
        # handle transformation
 
62
        if self.transform:
 
63
            xy = ImagePath.Path(xy)
 
64
            xy.transform(self.transform)
 
65
        # render the item
 
66
        if op == "line":
 
67
            self.draw.line(xy, fill=outline, width=width)
 
68
        else:
 
69
            getattr(self.draw, op)(xy, fill=fill, outline=outline)
 
70
 
 
71
    def settransform(self, (xoffset, yoffset)):
 
72
        self.transform = (1, 0, xoffset, 0, 1, yoffset)
 
73
 
 
74
    def arc(self, xy, start, end, *options):
 
75
        self.render("arc", xy, start, end, *options)
 
76
 
 
77
    def chord(self, xy, start, end, *options):
 
78
        self.render("chord", xy, start, end, *options)
 
79
 
 
80
    def ellipse(self, xy, *options):
 
81
        self.render("ellipse", xy, *options)
 
82
 
 
83
    def line(self, xy, *options):
 
84
        self.render("line", xy, *options)
 
85
 
 
86
    def pieslice(self, xy, start, end, *options):
 
87
        self.render("pieslice", xy, start, end, *options)
 
88
 
 
89
    def polygon(self, xy, *options):
 
90
        self.render("polygon", xy, *options)
 
91
 
 
92
    def rectangle(self, xy, *options):
 
93
        self.render("rectangle", xy, *options)
 
94
 
 
95
    def symbol(self, xy, symbol, *options):
 
96
        raise NotImplementedError("not in this version")
 
97
 
 
98
    def text(self, xy, text, font):
 
99
        if self.transform:
 
100
            xy = ImagePath.Path(xy)
 
101
            xy.transform(self.transform)
 
102
        self.draw.text(xy, text, font=font.font, fill=font.color)
 
103
 
 
104
    def textsize(self, text, font):
 
105
        return self.draw.textsize(text, font=font.font)