[reportlab-users] diagonal ShadedRect and Clipping ?

Dirk Datzert reportlab-users@reportlab.com
Sun, 11 Aug 2002 20:06:12 +0200


Dies ist eine mehrteilige Nachricht im MIME-Format.
--------------104413D2746D6298DA6B0CBF
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi Robin,

based on ShadedPolygon and did the orientation-mode 'diagonalup' and
'diagonaldown' for ShadedRect.

I don't know if it will be made much sense for you to integrate this
really into grids.py since ShadedPolygon is experimental. And second it
is double depended class ShadedRect is used in ShadedPolygon and
ShadedPolygon is used in ShadedRect :-)) ???

Regards,
Dirk
--------------104413D2746D6298DA6B0CBF
Content-Type: text/plain; charset=us-ascii;
 name="grids.py.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="grids.py.diff"

@@ -334,7 +332,7 @@
         y = AttrMapValue(isNumber, desc="The grid's lower-left y position."),
         width = AttrMapValue(isNumber, desc="The grid's width."),
         height = AttrMapValue(isNumber, desc="The grid's height."),
-        orientation = AttrMapValue(OneOf(('vertical', 'horizontal')), desc='Determines if stripes are vertical or horizontal.'),
+        orientation = AttrMapValue(OneOf(('vertical', 'horizontal', 'diagonalup', 'diagonaldown')), desc='Determines if stripes are vertical or horizontal.'),
         numShades = AttrMapValue(isNumber, desc='The number of interpolating colors.'),
         fillColorStart = AttrMapValue(isColorOrNone, desc='Start value of the color shade.'),
         fillColorEnd = AttrMapValue(isColorOrNone, desc='End value of the color shade.'),
@@ -384,6 +381,27 @@
         return x, y, width, height, fillColorStart, fillColorEnd
 
     def draw(self):
+        # check orientation diagonal !
+        if self.orientation[:8] == 'diagonal':
+            from math import sqrt, acos, pi
+
+            sp = ShadedPolygon()
+
+            for k in 'fillColorStart', 'fillColorEnd', 'strokeColor', 'strokeWidth', 'numShades', 'cylinderMode':
+                setattr(sp,k,getattr(self,k))
+
+            w,h = self.width,self.height
+            d = sqrt(w**2+h**2)
+
+            sp.angle = acos(w/d)/pi*180
+
+            if self.orientation[-4:] == 'down':
+                sp.angle = -sp.angle
+
+            sp.points = [self.x,self.y,self.x+self.width,self.y,self.x+self.width,self.y+self.height,self.x,self.y+self.height]
+
+            return sp.draw()
+
         # general widget bits
         group = Group()
         x, y, w, h, fillColorStart, fillColorEnd = self._flipRectCorners()

--------------104413D2746D6298DA6B0CBF--