"Fossies" - the Fresh Open Source Software Archive

Member "reportlab-3.5.23/src/reportlab/graphics/widgets/flags.py" (6 Nov 2017, 30285 Bytes) of package /linux/privat/reportlab-3.5.23.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "flags.py" see the Fossies "Dox" file reference documentation.

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