flags.py 30 KB

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