~openerp-groupes/openobject-server/6.0-fix-setup-windows

« back to all changes in this revision

Viewing changes to bin/reportlab/graphics/widgets/flags.py

  • Committer: pinky
  • Date: 2006-12-07 13:41:40 UTC
  • Revision ID: pinky-3f10ee12cea3c4c75cef44ab04ad33ef47432907
New trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#see license.txt for license details
 
2
#history http://www.reportlab.co.uk/cgi-bin/viewcvs.cgi/public/reportlab/trunk/reportlab/graphics/widgets/flags.py
 
3
# Flag Widgets - a collection of flags as widgets
 
4
# author: John Precedo (johnp@reportlab.com)
 
5
"""This file is a collection of flag graphics as widgets.
 
6
 
 
7
All flags are represented at the ratio of 1:2, even where the official ratio for the flag is something else
 
8
(such as 3:5 for the German national flag). The only exceptions are for where this would look _very_ wrong,
 
9
such as the Danish flag whose (ratio is 28:37), or the Swiss flag (which is square).
 
10
 
 
11
Unless otherwise stated, these flags are all the 'national flags' of the countries, rather than their
 
12
state flags, naval flags, ensigns or any other variants. (National flags are the flag flown by civilians
 
13
of a country and the ones usually used to represent a country abroad. State flags are the variants used by
 
14
the government and by diplomatic missions overseas).
 
15
 
 
16
To check on how close these are to the 'official' representations of flags, check the World Flag Database at
 
17
http://www.flags.ndirect.co.uk/
 
18
 
 
19
The flags this file contains are:
 
20
 
 
21
EU Members:
 
22
United Kingdom, Austria, Belgium, Denmark, Finland, France, Germany, Greece, Ireland, Italy, Luxembourg,
 
23
Holland (The Netherlands), Spain, Sweden
 
24
 
 
25
Others:
 
26
USA, Czech Republic, European Union, Switzerland, Turkey, Brazil
 
27
 
 
28
(Brazilian flag contributed by Publio da Costa Melo [publio@planetarium.com.br]).
 
29
"""
 
30
__version__=''' $Id$ '''
 
31
 
 
32
from reportlab.lib import colors
 
33
from reportlab.lib.validators import *
 
34
from reportlab.lib.attrmap import *
 
35
from reportlab.graphics.shapes import Line, Rect, Polygon, Drawing, Group, String, Circle, Wedge
 
36
from reportlab.graphics.widgetbase import Widget
 
37
from reportlab.graphics import renderPDF
 
38
from signsandsymbols import _Symbol
 
39
import copy
 
40
from math import sin, cos, pi
 
41
 
 
42
validFlag=OneOf(None,
 
43
                'UK',
 
44
                'USA',
 
45
                'Afghanistan',
 
46
                'Austria',
 
47
                'Belgium',
 
48
                'China',
 
49
                'Cuba',
 
50
                'Denmark',
 
51
                'Finland',
 
52
                'France',
 
53
                'Germany',
 
54
                'Greece',
 
55
                'Ireland',
 
56
                'Italy',
 
57
                'Japan',
 
58
                'Luxembourg',
 
59
                'Holland',
 
60
                'Palestine',
 
61
                'Portugal',
 
62
                'Russia',
 
63
                'Spain',
 
64
                'Sweden',
 
65
                'Norway',
 
66
                'CzechRepublic',
 
67
                'Turkey',
 
68
                'Switzerland',
 
69
                'EU',
 
70
                'Brazil'
 
71
                )
 
72
 
 
73
_size = 100.
 
74
 
 
75
class Star(_Symbol):
 
76
    """This draws a 5-pointed star.
 
77
 
 
78
        possible attributes:
 
79
        'x', 'y', 'size', 'fillColor', 'strokeColor'
 
80
 
 
81
        """
 
82
    _attrMap = AttrMap(BASE=_Symbol,
 
83
            angle = AttrMapValue(isNumber, desc='angle in degrees'),
 
84
            )
 
85
    _size = 100.
 
86
 
 
87
    def __init__(self):
 
88
        _Symbol.__init__(self)
 
89
        self.size = 100
 
90
        self.fillColor = colors.yellow
 
91
        self.strokeColor = None
 
92
        self.angle = 0
 
93
 
 
94
    def demo(self):
 
95
        D = Drawing(200, 100)
 
96
        et = Star()
 
97
        et.x=50
 
98
        et.y=0
 
99
        D.add(et)
 
100
        labelFontSize = 10
 
101
        D.add(String(et.x+(et.size/2.0),(et.y-(1.2*labelFontSize)),
 
102
                            et.__class__.__name__, fillColor=colors.black, textAnchor='middle',
 
103
                            fontSize=labelFontSize))
 
104
        return D
 
105
 
 
106
    def draw(self):
 
107
        s = float(self.size)  #abbreviate as we will use this a lot
 
108
        g = Group()
 
109
 
 
110
        # new algorithm from markers.StarFive
 
111
        R = float(self.size)/2
 
112
        r = R*sin(18*(pi/180.0))/cos(36*(pi/180.0))
 
113
        P = []
 
114
        angle = 90
 
115
        for i in xrange(5):
 
116
            for radius in R, r:
 
117
                theta = angle*(pi/180.0)
 
118
                P.append(radius*cos(theta))
 
119
                P.append(radius*sin(theta))
 
120
                angle = angle + 36
 
121
        # star specific bits
 
122
        star = Polygon(P,
 
123
                    fillColor = self.fillColor,
 
124
                    strokeColor = self.strokeColor,
 
125
                    strokeWidth=s/50)
 
126
        g.rotate(self.angle)
 
127
        g.shift(self.x+self.dx,self.y+self.dy)
 
128
        g.add(star)
 
129
 
 
130
        return g
 
131
 
 
132
class Flag(_Symbol):
 
133
    """This is a generic flag class that all the flags in this file use as a basis.
 
134
 
 
135
        This class basically provides edges and a tidy-up routine to hide any bits of
 
136
        line that overlap the 'outside' of the flag
 
137
 
 
138
        possible attributes:
 
139
        'x', 'y', 'size', 'fillColor'
 
140
    """
 
141
 
 
142
    _attrMap = AttrMap(BASE=_Symbol,
 
143
            fillColor = AttrMapValue(isColor, desc='Background color'),
 
144
            border = AttrMapValue(isBoolean, 'Whether a background is drawn'),
 
145
            kind = AttrMapValue(validFlag, desc='Which flag'),
 
146
            )
 
147
 
 
148
    _cache = {}
 
149
 
 
150
    def __init__(self,**kw):
 
151
        _Symbol.__init__(self)
 
152
        self.kind = None
 
153
        self.size = 100
 
154
        self.fillColor = colors.white
 
155
        self.border=1
 
156
        self.setProperties(kw)
 
157
 
 
158
    def availableFlagNames(self):
 
159
        '''return a list of the things we can display'''
 
160
        return filter(lambda x: x is not None, self._attrMap['kind'].validate._enum)
 
161
 
 
162
    def _Flag_None(self):
 
163
        s = _size  # abbreviate as we will use this a lot
 
164
        g = Group()
 
165
        g.add(Rect(0, 0, s*2, s, fillColor = colors.purple, strokeColor = colors.black, strokeWidth=0))
 
166
        return g
 
167
 
 
168
    def _borderDraw(self,f):
 
169
        s = self.size  # abbreviate as we will use this a lot
 
170
        g = Group()
 
171
        g.add(f)
 
172
        x, y, sW = self.x+self.dx, self.y+self.dy, self.strokeWidth/2.
 
173
        g.insert(0,Rect(-sW, -sW, width=getattr(self,'_width',2*s)+3*sW, height=getattr(self,'_height',s)+2*sW,
 
174
                fillColor = None, strokeColor = self.strokeColor, strokeWidth=sW*2))
 
175
        g.shift(x,y)
 
176
        g.scale(s/_size, s/_size)
 
177
        return g
 
178
 
 
179
    def draw(self):
 
180
        kind = self.kind or 'None'
 
181
        f = self._cache.get(kind)
 
182
        if not f:
 
183
            f = getattr(self,'_Flag_'+kind)()
 
184
            self._cache[kind] = f._explode()
 
185
        return self._borderDraw(f)
 
186
 
 
187
    def clone(self):
 
188
        return copy.copy(self)
 
189
 
 
190
    def demo(self):
 
191
        D = Drawing(200, 100)
 
192
        name = self.availableFlagNames()
 
193
        import time
 
194
        name = name[int(time.time()) % len(name)]
 
195
        fx = Flag()
 
196
        fx.kind = name
 
197
        fx.x = 0
 
198
        fx.y = 0
 
199
        D.add(fx)
 
200
        labelFontSize = 10
 
201
        D.add(String(fx.x+(fx.size/2),(fx.y-(1.2*labelFontSize)),
 
202
                            name, fillColor=colors.black, textAnchor='middle',
 
203
                            fontSize=labelFontSize))
 
204
        labelFontSize = int(fx.size/4)
 
205
        D.add(String(fx.x+(fx.size),(fx.y+((fx.size/2))),
 
206
                            "SAMPLE", fillColor=colors.gold, textAnchor='middle',
 
207
                            fontSize=labelFontSize, fontName="Helvetica-Bold"))
 
208
        return D
 
209
 
 
210
    def _Flag_UK(self):
 
211
        s = _size
 
212
        g = Group()
 
213
        w = s*2
 
214
        g.add(Rect(0, 0, w, s, fillColor = colors.navy, strokeColor = colors.black, strokeWidth=0))
 
215
        g.add(Polygon([0,0, s*.225,0, w,s*(1-.1125), w,s, w-s*.225,s, 0, s*.1125], fillColor = colors.mintcream, strokeColor=None, strokeWidth=0))
 
216
        g.add(Polygon([0,s*(1-.1125), 0, s, s*.225,s, w, s*.1125, w,0, w-s*.225,0], fillColor = colors.mintcream, strokeColor=None, strokeWidth=0))
 
217
        g.add(Polygon([0, s-(s/15), (s-((s/10)*4)), (s*0.65), (s-(s/10)*3), (s*0.65), 0, s], fillColor = colors.red, strokeColor = None, strokeWidth=0))
 
218
        g.add(Polygon([0, 0, (s-((s/10)*3)), (s*0.35), (s-((s/10)*2)), (s*0.35), (s/10), 0], fillColor = colors.red, strokeColor = None, strokeWidth=0))
 
219
        g.add(Polygon([w, s, (s+((s/10)*3)), (s*0.65), (s+((s/10)*2)), (s*0.65), w-(s/10), s], fillColor = colors.red, strokeColor = None, strokeWidth=0))
 
220
        g.add(Polygon([w, (s/15), (s+((s/10)*4)), (s*0.35), (s+((s/10)*3)), (s*0.35), w, 0], fillColor = colors.red, strokeColor = None, strokeWidth=0))
 
221
        g.add(Rect(((s*0.42)*2), 0, width=(0.16*s)*2, height=s, fillColor = colors.mintcream, strokeColor = None, strokeWidth=0))
 
222
        g.add(Rect(0, (s*0.35), width=w, height=s*0.3, fillColor = colors.mintcream, strokeColor = None, strokeWidth=0))
 
223
        g.add(Rect(((s*0.45)*2), 0, width=(0.1*s)*2, height=s, fillColor = colors.red, strokeColor = None, strokeWidth=0))
 
224
        g.add(Rect(0, (s*0.4), width=w, height=s*0.2, fillColor = colors.red, strokeColor = None, strokeWidth=0))
 
225
        return g
 
226
 
 
227
    def _Flag_USA(self):
 
228
        s = _size  # abbreviate as we will use this a lot
 
229
        g = Group()
 
230
 
 
231
        box = Rect(0, 0, s*2, s, fillColor = colors.mintcream, strokeColor = colors.black, strokeWidth=0)
 
232
        g.add(box)
 
233
 
 
234
        for stripecounter in range (13,0, -1):
 
235
            stripeheight = s/13.0
 
236
            if not (stripecounter%2 == 0):
 
237
                stripecolor = colors.red
 
238
            else:
 
239
                stripecolor = colors.mintcream
 
240
            redorwhiteline = Rect(0, (s-(stripeheight*stripecounter)), width=s*2, height=stripeheight,
 
241
                fillColor = stripecolor, strokeColor = None, strokeWidth=20)
 
242
            g.add(redorwhiteline)
 
243
 
 
244
        bluebox = Rect(0, (s-(stripeheight*7)), width=0.8*s, height=stripeheight*7,
 
245
            fillColor = colors.darkblue, strokeColor = None, strokeWidth=0)
 
246
        g.add(bluebox)
 
247
 
 
248
        lss = s*0.045
 
249
        lss2 = lss/2
 
250
        s9 = s/9
 
251
        s7 = s/7
 
252
        for starxcounter in range(5):
 
253
            for starycounter in range(4):
 
254
                ls = Star()
 
255
                ls.size = lss
 
256
                ls.x = 0-s/22+lss/2+s7+starxcounter*s7
 
257
                ls.fillColor = colors.mintcream
 
258
                ls.y = s-(starycounter+1)*s9+lss2
 
259
                g.add(ls)
 
260
 
 
261
        for starxcounter in range(6):
 
262
            for starycounter in range(5):
 
263
                ls = Star()
 
264
                ls.size = lss
 
265
                ls.x = 0-(s/22)+lss/2+s/14+starxcounter*s7
 
266
                ls.fillColor = colors.mintcream
 
267
                ls.y = s-(starycounter+1)*s9+(s/18)+lss2
 
268
                g.add(ls)
 
269
        return g
 
270
 
 
271
    def _Flag_Afghanistan(self):
 
272
        s = _size
 
273
        g = Group()
 
274
 
 
275
        box = Rect(0, 0, s*2, s,
 
276
            fillColor = colors.mintcream, strokeColor = colors.black, strokeWidth=0)
 
277
        g.add(box)
 
278
 
 
279
        greenbox = Rect(0, ((s/3.0)*2.0), width=s*2.0, height=s/3.0,
 
280
                fillColor = colors.limegreen, strokeColor = None, strokeWidth=0)
 
281
        g.add(greenbox)
 
282
 
 
283
        blackbox = Rect(0, 0, width=s*2.0, height=s/3.0,
 
284
                fillColor = colors.black, strokeColor = None, strokeWidth=0)
 
285
        g.add(blackbox)
 
286
        return g
 
287
 
 
288
    def _Flag_Austria(self):
 
289
        s = _size  # abbreviate as we will use this a lot
 
290
        g = Group()
 
291
 
 
292
        box = Rect(0, 0, s*2, s, fillColor = colors.mintcream,
 
293
            strokeColor = colors.black, strokeWidth=0)
 
294
        g.add(box)
 
295
 
 
296
 
 
297
        redbox1 = Rect(0, 0, width=s*2.0, height=s/3.0,
 
298
            fillColor = colors.red, strokeColor = None, strokeWidth=0)
 
299
        g.add(redbox1)
 
300
 
 
301
        redbox2 = Rect(0, ((s/3.0)*2.0), width=s*2.0, height=s/3.0,
 
302
            fillColor = colors.red, strokeColor = None, strokeWidth=0)
 
303
        g.add(redbox2)
 
304
        return g
 
305
 
 
306
    def _Flag_Belgium(self):
 
307
        s = _size
 
308
        g = Group()
 
309
 
 
310
        box = Rect(0, 0, s*2, s,
 
311
            fillColor = colors.black, strokeColor = colors.black, strokeWidth=0)
 
312
        g.add(box)
 
313
 
 
314
 
 
315
        box1 = Rect(0, 0, width=(s/3.0)*2.0, height=s,
 
316
            fillColor = colors.black, strokeColor = None, strokeWidth=0)
 
317
        g.add(box1)
 
318
 
 
319
        box2 = Rect(((s/3.0)*2.0), 0, width=(s/3.0)*2.0, height=s,
 
320
            fillColor = colors.gold, strokeColor = None, strokeWidth=0)
 
321
        g.add(box2)
 
322
 
 
323
        box3 = Rect(((s/3.0)*4.0), 0, width=(s/3.0)*2.0, height=s,
 
324
            fillColor = colors.red, strokeColor = None, strokeWidth=0)
 
325
        g.add(box3)
 
326
        return g
 
327
 
 
328
    def _Flag_China(self):
 
329
        s = _size
 
330
        g = Group()
 
331
        self._width = w = s*1.5
 
332
        g.add(Rect(0, 0, w, s, fillColor=colors.red, strokeColor=None, strokeWidth=0))
 
333
 
 
334
        def addStar(x,y,size,angle,g=g,w=s/20,x0=0,y0=s/2):
 
335
            s = Star()
 
336
            s.fillColor=colors.yellow
 
337
            s.angle = angle
 
338
            s.size = size*w*2
 
339
            s.x = x*w+x0
 
340
            s.y = y*w+y0
 
341
            g.add(s)
 
342
 
 
343
        addStar(5,5,3, 0)
 
344
        addStar(10,1,1,36.86989765)
 
345
        addStar(12,3,1,8.213210702)
 
346
        addStar(12,6,1,16.60154960)
 
347
        addStar(10,8,1,53.13010235)
 
348
        return g
 
349
 
 
350
    def _Flag_Cuba(self):
 
351
        s = _size
 
352
        g = Group()
 
353
 
 
354
        for i in range(5):
 
355
            stripe = Rect(0, i*s/5, width=s*2, height=s/5,
 
356
                fillColor = [colors.darkblue, colors.mintcream][i%2],
 
357
                strokeColor = None,
 
358
                strokeWidth=0)
 
359
            g.add(stripe)
 
360
 
 
361
        redwedge = Polygon(points = [ 0, 0, 4*s/5, (s/2), 0, s],
 
362
                    fillColor = colors.red, strokeColor = None, strokeWidth=0)
 
363
        g.add(redwedge)
 
364
 
 
365
        star = Star()
 
366
        star.x = 2.5*s/10
 
367
        star.y = s/2
 
368
        star.size = 3*s/10
 
369
        star.fillColor = colors.white
 
370
        g.add(star)
 
371
 
 
372
        box = Rect(0, 0, s*2, s,
 
373
            fillColor = None,
 
374
            strokeColor = colors.black,
 
375
            strokeWidth=0)
 
376
        g.add(box)
 
377
 
 
378
        return g
 
379
 
 
380
    def _Flag_Denmark(self):
 
381
        s = _size
 
382
        g = Group()
 
383
        self._width = w = s*1.4
 
384
 
 
385
        box = Rect(0, 0, w, s,
 
386
            fillColor = colors.red, strokeColor = colors.black, strokeWidth=0)
 
387
        g.add(box)
 
388
 
 
389
        whitebox1 = Rect(((s/5)*2), 0, width=s/6, height=s,
 
390
            fillColor = colors.mintcream, strokeColor = None, strokeWidth=0)
 
391
        g.add(whitebox1)
 
392
 
 
393
        whitebox2 = Rect(0, ((s/2)-(s/12)), width=w, height=s/6,
 
394
            fillColor = colors.mintcream, strokeColor = None, strokeWidth=0)
 
395
        g.add(whitebox2)
 
396
        return g
 
397
 
 
398
    def _Flag_Finland(self):
 
399
        s = _size
 
400
        g = Group()
 
401
 
 
402
        # crossbox specific bits
 
403
        box = Rect(0, 0, s*2, s,
 
404
            fillColor = colors.ghostwhite, strokeColor = colors.black, strokeWidth=0)
 
405
        g.add(box)
 
406
 
 
407
        blueline1 = Rect((s*0.6), 0, width=0.3*s, height=s,
 
408
            fillColor = colors.darkblue, strokeColor = None, strokeWidth=0)
 
409
        g.add(blueline1)
 
410
 
 
411
        blueline2 = Rect(0, (s*0.4), width=s*2, height=s*0.3,
 
412
            fillColor = colors.darkblue, strokeColor = None, strokeWidth=0)
 
413
        g.add(blueline2)
 
414
        return g
 
415
 
 
416
    def _Flag_France(self):
 
417
        s = _size
 
418
        g = Group()
 
419
 
 
420
        box = Rect(0, 0, s*2, s, fillColor = colors.navy, strokeColor = colors.black, strokeWidth=0)
 
421
        g.add(box)
 
422
 
 
423
        bluebox = Rect(0, 0, width=((s/3.0)*2.0), height=s,
 
424
            fillColor = colors.blue, strokeColor = None, strokeWidth=0)
 
425
        g.add(bluebox)
 
426
 
 
427
        whitebox = Rect(((s/3.0)*2.0), 0, width=((s/3.0)*2.0), height=s,
 
428
            fillColor = colors.mintcream, strokeColor = None, strokeWidth=0)
 
429
        g.add(whitebox)
 
430
 
 
431
        redbox = Rect(((s/3.0)*4.0), 0, width=((s/3.0)*2.0), height=s,
 
432
            fillColor = colors.red,
 
433
            strokeColor = None,
 
434
            strokeWidth=0)
 
435
        g.add(redbox)
 
436
        return g
 
437
 
 
438
    def _Flag_Germany(self):
 
439
        s = _size
 
440
        g = Group()
 
441
 
 
442
        box = Rect(0, 0, s*2, s,
 
443
                fillColor = colors.gold, strokeColor = colors.black, strokeWidth=0)
 
444
        g.add(box)
 
445
 
 
446
        blackbox1 = Rect(0, ((s/3.0)*2.0), width=s*2.0, height=s/3.0,
 
447
            fillColor = colors.black, strokeColor = None, strokeWidth=0)
 
448
        g.add(blackbox1)
 
449
 
 
450
        redbox1 = Rect(0, (s/3.0), width=s*2.0, height=s/3.0,
 
451
            fillColor = colors.orangered, strokeColor = None, strokeWidth=0)
 
452
        g.add(redbox1)
 
453
        return g
 
454
 
 
455
    def _Flag_Greece(self):
 
456
        s = _size
 
457
        g = Group()
 
458
 
 
459
        box = Rect(0, 0, s*2, s, fillColor = colors.gold,
 
460
                        strokeColor = colors.black, strokeWidth=0)
 
461
        g.add(box)
 
462
 
 
463
        for stripecounter in range (9,0, -1):
 
464
            stripeheight = s/9.0
 
465
            if not (stripecounter%2 == 0):
 
466
                stripecolor = colors.deepskyblue
 
467
            else:
 
468
                stripecolor = colors.mintcream
 
469
 
 
470
            blueorwhiteline = Rect(0, (s-(stripeheight*stripecounter)), width=s*2, height=stripeheight,
 
471
                fillColor = stripecolor, strokeColor = None, strokeWidth=20)
 
472
            g.add(blueorwhiteline)
 
473
 
 
474
        bluebox1 = Rect(0, ((s)-stripeheight*5), width=(stripeheight*5), height=stripeheight*5,
 
475
            fillColor = colors.deepskyblue, strokeColor = None, strokeWidth=0)
 
476
        g.add(bluebox1)
 
477
 
 
478
        whiteline1 = Rect(0, ((s)-stripeheight*3), width=stripeheight*5, height=stripeheight,
 
479
            fillColor = colors.mintcream, strokeColor = None, strokeWidth=0)
 
480
        g.add(whiteline1)
 
481
 
 
482
        whiteline2 = Rect((stripeheight*2), ((s)-stripeheight*5), width=stripeheight, height=stripeheight*5,
 
483
            fillColor = colors.mintcream, strokeColor = None, strokeWidth=0)
 
484
        g.add(whiteline2)
 
485
 
 
486
        return g
 
487
 
 
488
    def _Flag_Ireland(self):
 
489
        s = _size
 
490
        g = Group()
 
491
 
 
492
        box = Rect(0, 0, s*2, s,
 
493
            fillColor = colors.forestgreen, strokeColor = colors.black, strokeWidth=0)
 
494
        g.add(box)
 
495
 
 
496
        whitebox = Rect(((s*2.0)/3.0), 0, width=(2.0*(s*2.0)/3.0), height=s,
 
497
                fillColor = colors.mintcream, strokeColor = None, strokeWidth=0)
 
498
        g.add(whitebox)
 
499
 
 
500
        orangebox = Rect(((2.0*(s*2.0)/3.0)), 0, width=(s*2.0)/3.0, height=s,
 
501
            fillColor = colors.darkorange, strokeColor = None, strokeWidth=0)
 
502
        g.add(orangebox)
 
503
        return g
 
504
 
 
505
    def _Flag_Italy(self):
 
506
        s = _size
 
507
        g = Group()
 
508
        g.add(Rect(0,0,s*2,s,fillColor=colors.forestgreen,strokeColor=None, strokeWidth=0))
 
509
        g.add(Rect((2*s)/3, 0, width=(s*4)/3, height=s, fillColor = colors.mintcream, strokeColor = None, strokeWidth=0))
 
510
        g.add(Rect((4*s)/3, 0, width=(s*2)/3, height=s, fillColor = colors.red, strokeColor = None, strokeWidth=0))
 
511
        return g
 
512
 
 
513
    def _Flag_Japan(self):
 
514
        s = _size
 
515
        g = Group()
 
516
        w = self._width = s*1.5
 
517
        g.add(Rect(0,0,w,s,fillColor=colors.mintcream,strokeColor=None, strokeWidth=0))
 
518
        g.add(Circle(cx=w/2,cy=s/2,r=0.3*w,fillColor=colors.red,strokeColor=None, strokeWidth=0))
 
519
        return g
 
520
 
 
521
    def _Flag_Luxembourg(self):
 
522
        s = _size
 
523
        g = Group()
 
524
 
 
525
        box = Rect(0, 0, s*2, s,
 
526
            fillColor = colors.mintcream, strokeColor = colors.black, strokeWidth=0)
 
527
        g.add(box)
 
528
 
 
529
        redbox = Rect(0, ((s/3.0)*2.0), width=s*2.0, height=s/3.0,
 
530
                fillColor = colors.red, strokeColor = None, strokeWidth=0)
 
531
        g.add(redbox)
 
532
 
 
533
        bluebox = Rect(0, 0, width=s*2.0, height=s/3.0,
 
534
                fillColor = colors.dodgerblue, strokeColor = None, strokeWidth=0)
 
535
        g.add(bluebox)
 
536
        return g
 
537
 
 
538
    def _Flag_Holland(self):
 
539
        s = _size
 
540
        g = Group()
 
541
 
 
542
        box = Rect(0, 0, s*2, s,
 
543
            fillColor = colors.mintcream, strokeColor = colors.black, strokeWidth=0)
 
544
        g.add(box)
 
545
 
 
546
        redbox = Rect(0, ((s/3.0)*2.0), width=s*2.0, height=s/3.0,
 
547
                fillColor = colors.red, strokeColor = None, strokeWidth=0)
 
548
        g.add(redbox)
 
549
 
 
550
        bluebox = Rect(0, 0, width=s*2.0, height=s/3.0,
 
551
                fillColor = colors.darkblue, strokeColor = None, strokeWidth=0)
 
552
        g.add(bluebox)
 
553
        return g
 
554
 
 
555
    def _Flag_Portugal(self):
 
556
        return Group()
 
557
 
 
558
    def _Flag_Russia(self):
 
559
        s = _size
 
560
        g = Group()
 
561
        w = self._width = s*1.5
 
562
        t = s/3
 
563
        g.add(Rect(0, 0, width=w, height=t, fillColor = colors.red, strokeColor = None, strokeWidth=0))
 
564
        g.add(Rect(0, t, width=w, height=t, fillColor = colors.blue, strokeColor = None, strokeWidth=0))
 
565
        g.add(Rect(0, 2*t, width=w, height=t, fillColor = colors.mintcream, strokeColor = None, strokeWidth=0))
 
566
        return g
 
567
 
 
568
    def _Flag_Spain(self):
 
569
        s = _size
 
570
        g = Group()
 
571
        w = self._width = s*1.5
 
572
        g.add(Rect(0, 0, width=w, height=s, fillColor = colors.red, strokeColor = None, strokeWidth=0))
 
573
        g.add(Rect(0, (s/4), width=w, height=s/2, fillColor = colors.yellow, strokeColor = None, strokeWidth=0))
 
574
        return g
 
575
 
 
576
    def _Flag_Sweden(self):
 
577
        s = _size
 
578
        g = Group()
 
579
        self._width = s*1.4
 
580
        box = Rect(0, 0, self._width, s,
 
581
            fillColor = colors.dodgerblue, strokeColor = colors.black, strokeWidth=0)
 
582
        g.add(box)
 
583
 
 
584
        box1 = Rect(((s/5)*2), 0, width=s/6, height=s,
 
585
                fillColor = colors.gold, strokeColor = None, strokeWidth=0)
 
586
        g.add(box1)
 
587
 
 
588
        box2 = Rect(0, ((s/2)-(s/12)), width=self._width, height=s/6,
 
589
            fillColor = colors.gold,
 
590
            strokeColor = None,
 
591
            strokeWidth=0)
 
592
        g.add(box2)
 
593
        return g
 
594
 
 
595
    def _Flag_Norway(self):
 
596
        s = _size
 
597
        g = Group()
 
598
        self._width = s*1.4
 
599
 
 
600
        box = Rect(0, 0, self._width, s,
 
601
                fillColor = colors.red, strokeColor = colors.black, strokeWidth=0)
 
602
        g.add(box)
 
603
 
 
604
        box = Rect(0, 0, self._width, s,
 
605
                fillColor = colors.red, strokeColor = colors.black, strokeWidth=0)
 
606
        g.add(box)
 
607
 
 
608
        whiteline1 = Rect(((s*0.2)*2), 0, width=s*0.2, height=s,
 
609
                fillColor = colors.ghostwhite, strokeColor = None, strokeWidth=0)
 
610
        g.add(whiteline1)
 
611
 
 
612
        whiteline2 = Rect(0, (s*0.4), width=self._width, height=s*0.2,
 
613
                fillColor = colors.ghostwhite, strokeColor = None, strokeWidth=0)
 
614
        g.add(whiteline2)
 
615
 
 
616
        blueline1 = Rect(((s*0.225)*2), 0, width=0.1*s, height=s,
 
617
                fillColor = colors.darkblue, strokeColor = None, strokeWidth=0)
 
618
        g.add(blueline1)
 
619
 
 
620
        blueline2 = Rect(0, (s*0.45), width=self._width, height=s*0.1,
 
621
                fillColor = colors.darkblue, strokeColor = None, strokeWidth=0)
 
622
        g.add(blueline2)
 
623
        return g
 
624
 
 
625
    def _Flag_CzechRepublic(self):
 
626
        s = _size
 
627
        g = Group()
 
628
        box = Rect(0, 0, s*2, s,
 
629
            fillColor = colors.mintcream,
 
630
                        strokeColor = colors.black,
 
631
            strokeWidth=0)
 
632
        g.add(box)
 
633
 
 
634
        redbox = Rect(0, 0, width=s*2, height=s/2,
 
635
            fillColor = colors.red,
 
636
            strokeColor = None,
 
637
            strokeWidth=0)
 
638
        g.add(redbox)
 
639
 
 
640
        bluewedge = Polygon(points = [ 0, 0, s, (s/2), 0, s],
 
641
                    fillColor = colors.darkblue, strokeColor = None, strokeWidth=0)
 
642
        g.add(bluewedge)
 
643
        return g
 
644
 
 
645
    def _Flag_Palestine(self):
 
646
        s = _size
 
647
        g = Group()
 
648
        box = Rect(0, s/3, s*2, s/3,
 
649
            fillColor = colors.mintcream,
 
650
                        strokeColor = None,
 
651
            strokeWidth=0)
 
652
        g.add(box)
 
653
 
 
654
        greenbox = Rect(0, 0, width=s*2, height=s/3,
 
655
            fillColor = colors.limegreen,
 
656
            strokeColor = None,
 
657
            strokeWidth=0)
 
658
        g.add(greenbox)
 
659
 
 
660
        blackbox = Rect(0, 2*s/3, width=s*2, height=s/3,
 
661
            fillColor = colors.black,
 
662
            strokeColor = None,
 
663
            strokeWidth=0)
 
664
        g.add(blackbox)
 
665
 
 
666
        redwedge = Polygon(points = [ 0, 0, 2*s/3, (s/2), 0, s],
 
667
                    fillColor = colors.red, strokeColor = None, strokeWidth=0)
 
668
        g.add(redwedge)
 
669
        return g
 
670
 
 
671
    def _Flag_Turkey(self):
 
672
        s = _size
 
673
        g = Group()
 
674
 
 
675
        box = Rect(0, 0, s*2, s,
 
676
            fillColor = colors.red,
 
677
                        strokeColor = colors.black,
 
678
            strokeWidth=0)
 
679
        g.add(box)
 
680
 
 
681
        whitecircle = Circle(cx=((s*0.35)*2), cy=s/2, r=s*0.3,
 
682
            fillColor = colors.mintcream,
 
683
            strokeColor = None,
 
684
            strokeWidth=0)
 
685
        g.add(whitecircle)
 
686
 
 
687
        redcircle = Circle(cx=((s*0.39)*2), cy=s/2, r=s*0.24,
 
688
            fillColor = colors.red,
 
689
            strokeColor = None,
 
690
            strokeWidth=0)
 
691
        g.add(redcircle)
 
692
 
 
693
        ws = Star()
 
694
        ws.angle = 15
 
695
        ws.size = s/5
 
696
        ws.x = (s*0.5)*2+ws.size/2
 
697
        ws.y = (s*0.5)
 
698
        ws.fillColor = colors.mintcream
 
699
        ws.strokeColor = None
 
700
        g.add(ws)
 
701
        return g
 
702
 
 
703
    def _Flag_Switzerland(self):
 
704
        s = _size
 
705
        g = Group()
 
706
        self._width = s
 
707
 
 
708
        g.add(Rect(0, 0, s, s, fillColor = colors.red, strokeColor = colors.black, strokeWidth=0))
 
709
        g.add(Line((s/2), (s/5.5), (s/2), (s-(s/5.5)),
 
710
            fillColor = colors.mintcream, strokeColor = colors.mintcream, strokeWidth=(s/5)))
 
711
        g.add(Line((s/5.5), (s/2), (s-(s/5.5)), (s/2),
 
712
            fillColor = colors.mintcream, strokeColor = colors.mintcream, strokeWidth=s/5))
 
713
        return g
 
714
 
 
715
    def _Flag_EU(self):
 
716
        s = _size
 
717
        g = Group()
 
718
        w = self._width = 1.5*s
 
719
 
 
720
        g.add(Rect(0, 0, w, s, fillColor = colors.darkblue, strokeColor = None, strokeWidth=0))
 
721
        centerx=w/2
 
722
        centery=s/2
 
723
        radius=s/3
 
724
        yradius = radius
 
725
        xradius = radius
 
726
        nStars = 12
 
727
        delta = 2*pi/nStars
 
728
        for i in range(nStars):
 
729
            rad = i*delta
 
730
            gs = Star()
 
731
            gs.x=cos(rad)*radius+centerx
 
732
            gs.y=sin(rad)*radius+centery
 
733
            gs.size=s/10
 
734
            gs.fillColor=colors.gold
 
735
            g.add(gs)
 
736
        return g
 
737
 
 
738
    def _Flag_Brazil(self):
 
739
        s = _size  # abbreviate as we will use this a lot
 
740
        g = Group()
 
741
 
 
742
        m = s/14
 
743
        self._width = w = (m * 20)
 
744
 
 
745
        def addStar(x,y,size, g=g, w=w, s=s, m=m):
 
746
            st = Star()
 
747
            st.fillColor=colors.mintcream
 
748
            st.size = size*m
 
749
            st.x = (w/2) + (x * (0.35 * m))
 
750
            st.y = (s/2) + (y * (0.35 * m))
 
751
            g.add(st)
 
752
 
 
753
        g.add(Rect(0, 0, w, s, fillColor = colors.green, strokeColor = None, strokeWidth=0))
 
754
        g.add(Polygon(points = [ 1.7*m, (s/2), (w/2), s-(1.7*m), w-(1.7*m),(s/2),(w/2), 1.7*m],
 
755
                      fillColor = colors.yellow, strokeColor = None, strokeWidth=0))
 
756
        g.add(Circle(cx=w/2, cy=s/2, r=3.5*m,
 
757
                     fillColor=colors.blue,strokeColor=None, strokeWidth=0))
 
758
        g.add(Wedge((w/2)-(2*m), 0, 8.5*m, 50, 98.1, 8.5*m,
 
759
                    fillColor=colors.mintcream,strokeColor=None, strokeWidth=0))
 
760
        g.add(Wedge((w/2), (s/2), 3.501*m, 156, 352, 3.501*m,
 
761
                    fillColor=colors.mintcream,strokeColor=None, strokeWidth=0))
 
762
        g.add(Wedge((w/2)-(2*m), 0, 8*m, 48.1, 100, 8*m,
 
763
                    fillColor=colors.blue,strokeColor=None, strokeWidth=0))
 
764
        g.add(Rect(0, 0, w, (s/4) + 1.7*m,
 
765
                   fillColor = colors.green, strokeColor = None, strokeWidth=0))
 
766
        g.add(Polygon(points = [ 1.7*m,(s/2), (w/2),s/2 - 2*m,  w-(1.7*m),(s/2) , (w/2),1.7*m],
 
767
                      fillColor = colors.yellow, strokeColor = None, strokeWidth=0))
 
768
        g.add(Wedge(w/2, s/2, 3.502*m, 166, 342.1, 3.502*m,
 
769
                    fillColor=colors.blue,strokeColor=None, strokeWidth=0))
 
770
 
 
771
        addStar(3.2,3.5,0.3)
 
772
        addStar(-8.5,1.5,0.3)
 
773
        addStar(-7.5,-3,0.3)
 
774
        addStar(-4,-5.5,0.3)
 
775
        addStar(0,-4.5,0.3)
 
776
        addStar(7,-3.5,0.3)
 
777
        addStar(-3.5,-0.5,0.25)
 
778
        addStar(0,-1.5,0.25)
 
779
        addStar(1,-2.5,0.25)
 
780
        addStar(3,-7,0.25)
 
781
        addStar(5,-6.5,0.25)
 
782
        addStar(6.5,-5,0.25)
 
783
        addStar(7,-4.5,0.25)
 
784
        addStar(-5.5,-3.2,0.25)
 
785
        addStar(-6,-4.2,0.25)
 
786
        addStar(-1,-2.75,0.2)
 
787
        addStar(2,-5.5,0.2)
 
788
        addStar(4,-5.5,0.2)
 
789
        addStar(5,-7.5,0.2)
 
790
        addStar(5,-5.5,0.2)
 
791
        addStar(6,-5.5,0.2)
 
792
        addStar(-8.8,-3.2,0.2)
 
793
        addStar(2.5,0.5,0.2)
 
794
        addStar(-0.2,-3.2,0.14)
 
795
        addStar(-7.2,-2,0.14)
 
796
        addStar(0,-8,0.1)
 
797
 
 
798
        sTmp = "ORDEM E PROGRESSO"
 
799
        nTmp = len(sTmp)
 
800
        delta = 0.850848010347/nTmp
 
801
        radius = 7.9 *m
 
802
        centerx = (w/2)-(2*m)
 
803
        centery = 0
 
804
        for i in range(nTmp):
 
805
            rad = 2*pi - i*delta -4.60766922527
 
806
            x=cos(rad)*radius+centerx
 
807
            y=sin(rad)*radius+centery
 
808
            if i == 6:
 
809
                z = 0.35*m
 
810
            else:
 
811
                z= 0.45*m
 
812
            g2 = Group(String(x, y, sTmp[i], fontName='Helvetica-Bold',
 
813
                fontSize = z,strokeColor=None,fillColor=colors.green))
 
814
            g2.rotate(rad)
 
815
            g.add(g2)
 
816
        return g
 
817
 
 
818
def makeFlag(name):
 
819
    flag = Flag()
 
820
    flag.kind = name
 
821
    return flag
 
822
 
 
823
def test():
 
824
    """This function produces three pdf files with examples of all the signs and symbols from this file.
 
825
    """
 
826
# page 1
 
827
 
 
828
    labelFontSize = 10
 
829
 
 
830
    X = (20,245)
 
831
 
 
832
    flags = [
 
833
            'UK',
 
834
            'USA',
 
835
            'Afghanistan',
 
836
            'Austria',
 
837
            'Belgium',
 
838
            'Denmark',
 
839
            'Cuba',
 
840
            'Finland',
 
841
            'France',
 
842
            'Germany',
 
843
            'Greece',
 
844
            'Ireland',
 
845
            'Italy',
 
846
            'Luxembourg',
 
847
            'Holland',
 
848
            'Palestine',
 
849
            'Portugal',
 
850
            'Spain',
 
851
            'Sweden',
 
852
            'Norway',
 
853
            'CzechRepublic',
 
854
            'Turkey',
 
855
            'Switzerland',
 
856
            'EU',
 
857
            'Brazil',
 
858
            ]
 
859
    y = Y0 = 530
 
860
    f = 0
 
861
    D = None
 
862
    for name in flags:
 
863
        if not D: D = Drawing(450,650)
 
864
        flag = makeFlag(name)
 
865
        i = flags.index(name)
 
866
        flag.x = X[i%2]
 
867
        flag.y = y
 
868
        D.add(flag)
 
869
        D.add(String(flag.x+(flag.size/2),(flag.y-(1.2*labelFontSize)),
 
870
                name, fillColor=colors.black, textAnchor='middle', fontSize=labelFontSize))
 
871
        if i%2: y = y - 125
 
872
        if (i%2 and y<0) or name==flags[-1]:
 
873
            renderPDF.drawToFile(D, 'flags%02d.pdf'%f, 'flags.py - Page #%d'%(f+1))
 
874
            y = Y0
 
875
            f = f+1
 
876
            D = None
 
877
 
 
878
if __name__=='__main__':
 
879
    test()