~ubuntu-branches/ubuntu/quantal/enigmail/quantal-security

« back to all changes in this revision

Viewing changes to build/pypng/texttopng

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2013-09-13 16:02:15 UTC
  • mfrom: (0.12.16)
  • Revision ID: package-import@ubuntu.com-20130913160215-u3g8nmwa0pdwagwc
Tags: 2:1.5.2-0ubuntu0.12.10.1
* New upstream release v1.5.2 for Thunderbird 24

* Build enigmail using a stripped down Thunderbird 17 build system, as it's
  now quite difficult to build the way we were doing previously, with the
  latest Firefox build system
* Add debian/patches/no_libxpcom.patch - Don't link against libxpcom, as it
  doesn't exist anymore (but exists in the build system)
* Add debian/patches/use_sdk.patch - Use the SDK version of xpt.py and
  friends
* Drop debian/patches/ipc-pipe_rename.diff (not needed anymore)
* Drop debian/patches/makefile_depth.diff (not needed anymore)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# $URL: http://pypng.googlecode.com/svn/trunk/code/texttopng $
 
3
# $Rev: 132 $
 
4
# Script to renders text as a PNG image.
 
5
 
 
6
from array import array
 
7
import itertools
 
8
 
 
9
font = {
 
10
  32: '0000000000000000',
 
11
  33: '0010101010001000',
 
12
  34: '0028280000000000',
 
13
  35: '0000287c287c2800',
 
14
  36: '00103c5038147810',
 
15
  37: '0000644810244c00',
 
16
  38: '0020502054483400',
 
17
  39: '0010100000000000',
 
18
  40: '0008101010101008',
 
19
  41: '0020101010101020',
 
20
  42: '0010543838541000',
 
21
  43: '000010107c101000',
 
22
  44: '0000000000301020',
 
23
  45: '000000007c000000',
 
24
  46: '0000000000303000',
 
25
  47: '0000040810204000',
 
26
  48: '0038445454443800',
 
27
  49: '0008180808080800',
 
28
  50: '0038043840407c00',
 
29
  51: '003c041804043800',
 
30
  52: '00081828487c0800',
 
31
  53: '0078407804047800',
 
32
  54: '0038407844443800',
 
33
  55: '007c040810101000',
 
34
  56: '0038443844443800',
 
35
  57: '0038443c04040400',
 
36
  58: '0000303000303000',
 
37
  59: '0000303000301020',
 
38
  60: '0004081020100804',
 
39
  61: '0000007c007c0000',
 
40
  62: '0040201008102040',
 
41
  63: '0038440810001000',
 
42
  64: '00384c545c403800',
 
43
  65: '0038447c44444400',
 
44
  66: '0078447844447800',
 
45
  67: '0038444040443800',
 
46
  68: '0070484444487000',
 
47
  69: '007c407840407c00',
 
48
  70: '007c407840404000',
 
49
  71: '003844405c443c00',
 
50
  72: '0044447c44444400',
 
51
  73: '0038101010103800',
 
52
  74: '003c040404443800',
 
53
  75: '0044487048444400',
 
54
  76: '0040404040407c00',
 
55
  77: '006c545444444400',
 
56
  78: '004464544c444400',
 
57
  79: '0038444444443800',
 
58
  80: '0078447840404000',
 
59
  81: '0038444444443c02',
 
60
  82: '0078447844444400',
 
61
  83: '0038403804047800',
 
62
  84: '007c101010101000',
 
63
  85: '0044444444443c00',
 
64
  86: '0044444444281000',
 
65
  87: '0044445454543800',
 
66
  88: '0042241818244200',
 
67
  89: '0044443810101000',
 
68
  90: '007c081020407c00',
 
69
  91: '0038202020202038',
 
70
  92: '0000402010080400',
 
71
  93: '0038080808080838',
 
72
  94: '0010284400000000',
 
73
  95: '000000000000fe00',
 
74
  96: '0040200000000000',
 
75
  97: '000038043c443c00',
 
76
  98: '0040784444447800',
 
77
  99: '0000384040403800',
 
78
  100: '00043c4444443c00',
 
79
  101: '000038447c403c00',
 
80
  102: '0018203820202000',
 
81
  103: '00003c44443c0438',
 
82
  104: '0040784444444400',
 
83
  105: '0010003010101000',
 
84
  106: '0010003010101020',
 
85
  107: '0040404870484400',
 
86
  108: '0030101010101000',
 
87
  109: '0000385454444400',
 
88
  110: '0000784444444400',
 
89
  111: '0000384444443800',
 
90
  112: '0000784444784040',
 
91
  113: '00003c44443c0406',
 
92
  114: '00001c2020202000',
 
93
  115: '00003c4038047800',
 
94
  116: '0020203820201800',
 
95
  117: '0000444444443c00',
 
96
  118: '0000444444281000',
 
97
  119: '0000444454543800',
 
98
  120: '0000442810284400',
 
99
  121: '00004444443c0438',
 
100
  122: '00007c0810207c00',
 
101
  123: '0018202060202018',
 
102
  124: '0010101000101010',
 
103
  125: '003008080c080830',
 
104
  126: '0020540800000000',
 
105
}
 
106
 
 
107
def char(i):
 
108
    """Get image data for the character `i` (a one character string).
 
109
    Returned as a list of rows.  Each row is a tuple containing the
 
110
    packed pixels.
 
111
    """
 
112
 
 
113
    i = ord(i)
 
114
    if i not in font:
 
115
        return [(0,)]*8
 
116
    return map(lambda row: (ord(row),), font[i].decode('hex'))
 
117
 
 
118
def texttoraster(m):
 
119
    """Convert string *m* to a raster image (by rendering it using the
 
120
    font in *font*).  A triple of (*width*, *height*, *pixels*) is
 
121
    returned; *pixels* is in boxed row packed pixel format.
 
122
    """
 
123
 
 
124
    # Assumes monospaced font.
 
125
    x = 8*len(m)
 
126
    y = 8
 
127
    return x,y,itertools.imap(lambda row: itertools.chain(*row),
 
128
                              zip(*map(char, m)))
 
129
 
 
130
 
 
131
def render(message, out):
 
132
    import png
 
133
 
 
134
    x,y,pixels = texttoraster(message)
 
135
    w = png.Writer(x, y, greyscale=True, bitdepth=1)
 
136
    w.write_packed(out, pixels)
 
137
    out.flush()
 
138
 
 
139
def main(argv=None):
 
140
    import sys
 
141
 
 
142
    if argv is None:
 
143
        argv = sys.argv
 
144
    if len(argv) > 1:
 
145
        message = argv[1]
 
146
    else:
 
147
        message = sys.stdin.read()
 
148
    render(message, sys.stdout)
 
149
 
 
150
if __name__ == '__main__':
 
151
    main()