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