@@ -808,16 +808,31 @@ RendererAgg::draw_text(const Py::Tuple& args) {
808808
809809 int x = Py::Int ( args[1 ] );
810810 int y = Py::Int ( args[2 ] );
811- Py::SeqBase<Py::Object> rgba = Py::SeqBase<Py::Object>( args[3 ] );
812-
813- double r = Py::Float ( rgba[0 ] );
814- double g = Py::Float ( rgba[1 ] );
815- double b = Py::Float ( rgba[2 ] );
816- double a = Py::Float ( rgba[3 ] );
817-
818-
811+ Py::Object gc = args[3 ];
812+
813+ Py::Object o ( gc.getAttr ( " _cliprect" ) );
814+
815+ bool useClip = o.ptr ()!=Py_None;
816+ double l = 0 ;
817+ double b = 0 ;
818+ double r = width;
819+ double t = height;
820+ if (useClip) {
821+ Py::SeqBase<Py::Object> rect ( o );
822+
823+ l = Py::Float (rect[0 ]) ;
824+ b = Py::Float (rect[1 ]) ;
825+ double w = Py::Float (rect[2 ]) ;
826+ double h = Py::Float (rect[3 ]) ;
827+ r = l+w;
828+ t = b+h;
829+ // std::cout << b << " " << h << " " << " " << t << std::endl;
830+ }
831+
832+ agg::rgba color = get_color (gc);
819833 pixfmt::color_type p;
820- p.r = int (255 *r); p.b = int (255 *b); p.g = int (255 *g); p.a = int (255 *a);
834+ p.r = int (255 *color.r ); p.b = int (255 *color.b );
835+ p.g = int (255 *color.g ); p.a = int (255 *color.a );
821836
822837 // y = y-font->image.height;
823838 unsigned thisx, thisy;
@@ -826,8 +841,8 @@ RendererAgg::draw_text(const Py::Tuple& args) {
826841 for (size_t j=0 ; j<font->image .height ; ++j) {
827842 thisx = i+x+font->image .offsetx ;
828843 thisy = j+y+font->image .offsety ;
829- if (thisx<0 || thisx>=width ) continue ;
830- if (thisy<0 || thisy>=height) continue ;
844+ if (thisx<l || thisx>=r ) continue ;
845+ if (thisy<height-t || thisy>=height-b ) continue ;
831846 pixFmt->blend_pixel
832847 (thisx, thisy, p, font->image .buffer [i + j*font->image .width ]);
833848 }
0 commit comments