@@ -686,6 +686,16 @@ def draw_gouraud_triangle(self, gc, points, colors, trans):
686686 operator = 'arithmetic' ,
687687 k2 = "1" , k3 = "1" )
688688 writer .end ('filter' )
689+ # feColorMatrix filter to correct opacity
690+ writer .start (
691+ 'filter' ,
692+ id = 'colorMat' )
693+ writer .element (
694+ 'feColorMatrix' ,
695+ attrib = {'type' : 'matrix' },
696+ values = '1 0 0 0 0 \n 0 1 0 0 0 \n 0 0 1 0 0' +
697+ ' \n 1 1 1 1 0 \n 0 0 0 0 1 ' )
698+ writer .end ('filter' )
689699
690700 avg_color = np .sum (colors [:, :], axis = 0 ) / 3.0
691701 # Just skip fully-transparent triangles
@@ -719,41 +729,64 @@ def draw_gouraud_triangle(self, gc, points, colors, trans):
719729 writer .start (
720730 'linearGradient' ,
721731 id = "GR%x_%d" % (self ._n_gradients , i ),
732+ gradientUnits = "userSpaceOnUse" ,
722733 x1 = short_float_fmt (x1 ), y1 = short_float_fmt (y1 ),
723734 x2 = short_float_fmt (xb ), y2 = short_float_fmt (yb ))
724735 writer .element (
725736 'stop' ,
726- offset = '0 ' ,
727- style = generate_css ({'stop-color' : rgb2hex (c ),
737+ offset = '1 ' ,
738+ style = generate_css ({'stop-color' : rgb2hex (avg_color ),
728739 'stop-opacity' : short_float_fmt (c [- 1 ])}))
729740 writer .element (
730741 'stop' ,
731- offset = '1 ' ,
742+ offset = '0 ' ,
732743 style = generate_css ({'stop-color' : rgb2hex (c ),
733744 'stop-opacity' : "0" }))
745+
734746 writer .end ('linearGradient' )
735747
736- writer .element (
737- 'polygon' ,
738- id = 'GT%x' % self ._n_gradients ,
739- points = " " .join ([short_float_fmt (x )
740- for x in (x1 , y1 , x2 , y2 , x3 , y3 )]))
741748 writer .end ('defs' )
742749
743- avg_color = np .sum (colors [:, :], axis = 0 ) / 3.0
744- href = '#GT%x' % self ._n_gradients
750+ # triangle formation using "path"
751+ dpath = "M " + short_float_fmt (x1 )+ ',' + short_float_fmt (y1 )
752+ dpath += " L " + short_float_fmt (x2 ) + ',' + short_float_fmt (y2 )
753+ dpath += " " + short_float_fmt (x3 ) + ',' + short_float_fmt (y3 ) + " Z"
754+
745755 writer .element (
746- 'use ' ,
747- attrib = {'xlink:href ' : href ,
756+ 'path ' ,
757+ attrib = {'d ' : dpath ,
748758 'fill' : rgb2hex (avg_color ),
749- 'fill-opacity' : short_float_fmt (avg_color [- 1 ])})
750- for i in range (3 ):
751- writer .element (
752- 'use' ,
753- attrib = {'xlink:href' : href ,
754- 'fill' : 'url(#GR%x_%d)' % (self ._n_gradients , i ),
755- 'fill-opacity' : '1' ,
756- 'filter' : 'url(#colorAdd)' })
759+ 'fill-opacity' : '1' ,
760+ 'shape-rendering' : "crispEdges" })
761+
762+ writer .start (
763+ 'g' ,
764+ attrib = {'stroke' : "none" ,
765+ 'stroke-width' : "0" ,
766+ 'shape-rendering' : "crispEdges" ,
767+ 'filter' : "url(#colorMat)" })
768+
769+ writer .element (
770+ 'path' ,
771+ attrib = {'d' : dpath ,
772+ 'fill' : 'url(#GR%x_0)' % self ._n_gradients ,
773+ 'shape-rendering' : "crispEdges" })
774+
775+ writer .element (
776+ 'path' ,
777+ attrib = {'d' : dpath ,
778+ 'fill' : 'url(#GR%x_1)' % self ._n_gradients ,
779+ 'filter' : 'url(#colorAdd)' ,
780+ 'shape-rendering' : "crispEdges" })
781+
782+ writer .element (
783+ 'path' ,
784+ attrib = {'d' : dpath ,
785+ 'fill' : 'url(#GR%x_2)' % self ._n_gradients ,
786+ 'filter' : 'url(#colorAdd)' ,
787+ 'shape-rendering' : "crispEdges" })
788+
789+ writer .end ('g' )
757790
758791 self ._n_gradients += 1
759792
0 commit comments