Mark de Wever wrote:
Hi,

I've been working on creating a plplot widget in gtkmm [1], this widget
uses the extcairo driver. In order to get this widget working I've been
making several modifications to the plplot sources.

I created a new patch in response to the discussion regarding the offset usage. I hope the other questions in my initial mail will be answered as well and some feedback about the patch in general.

I haven't been able to get PLESC_RESIZE to work as wanted so disabled it for now.

PLESC_INITFIT calls plbop() which causes the initial drawing to work as wanted. Since the offsets in the geometry aren't meant to be used as offset in the widget, the x1 and y1 of the clipping rectangle should both be 0.0 when used in PLESC_INITFIT. I added a warning if that pre-condition is not true.

Regards,
Mark de Wever
diff --git a/drivers/cairo.c b/drivers/cairo.c
index e6a6a42..c8c91ca 100644
--- a/drivers/cairo.c
+++ b/drivers/cairo.c
@@ -2342,6 +2342,42 @@ void plD_eop_extcairo(PLStream *pls)
   an external Cairo context to use for rendering.
   ---------------------------------------------------------------------*/
 
+static void init_context(PLStream *pls,  void *ptr, PLCairo *aStream
+               , const int fit_to_clip)
+{
+      aStream->cairoContext = (cairo_t *)ptr;
+
+      /* Set graphics aliasing */
+      cairo_set_antialias(aStream->cairoContext, 
aStream->graphics_anti_aliasing);
+
+         if(fit_to_clip) {
+                 /* Adjust the size to the size of the clip_rect */
+                 double x1, y1, x2, y2;
+                 cairo_clip_extents(aStream->cairoContext, &x1, &y1, &x2, &y2);
+
+                 if(x1 != 0.0 || y1 != 0.0)
+                    plwarn("The lower right corner of the clipping rectangle 
should be at 0.0, 0.0.\n");
+
+                 pls->xlength = x2;
+                 pls->ylength = y2;
+
+                 PLFLT downscale = 0.0;
+                 if (pls->xlength > pls->ylength)
+                         downscale = (double)pls->xlength/(double)(PIXELS_X-1);
+                 else
+                         downscale = (double)pls->ylength/(double)PIXELS_Y;
+                 plP_setphy((PLINT) 0, (PLINT) (pls->xlength / downscale), 
(PLINT) 0, (PLINT) (pls->ylength / downscale));
+                 plP_setpxl(DPI/25.4/downscale, DPI/25.4/downscale);
+                 aStream->downscale = downscale;
+
+                 // Set up the rotation
+                 plsdiori(pls->diorot);
+         }
+
+      /* Invert the surface so that the graphs are drawn right side up. */
+      rotate_cairo_surface(pls, 1.0, 0.0, 0.0, -1.0, 0.0, pls->ylength);
+}
+
 void plD_esc_extcairo(PLStream *pls, PLINT op, void *ptr)
 {
   PLCairo *aStream;
@@ -2350,18 +2386,25 @@ void plD_esc_extcairo(PLStream *pls, PLINT op, void 
*ptr)
 
   switch(op)
     {
-    case PLESC_DEVINIT: /* Set external context */
-      aStream->cairoContext = (cairo_t *)ptr;
-      /* Set graphics aliasing */
-      cairo_set_antialias(aStream->cairoContext, 
aStream->graphics_anti_aliasing);
+    case PLESC_DEVINIT_FIT: /* Set external context */
+               init_context(pls, ptr, aStream, 1);
+               plbop();
+               break;
 
-      /* Invert the surface so that the graphs are drawn right side up. */
-      rotate_cairo_surface(pls, 1.0, 0.0, 0.0, -1.0, 0.0, pls->ylength);
-
-      /* Should adjust plot size to fit in the given cairo context?
-         Cairo does not provide a way to query the dimensions of a context? */
+    case PLESC_DEVINIT: /* Set external context */
+               init_context(pls, ptr, aStream, 0);
+               break;
+/*
+    case PLESC_RESIZE:
+               init_context(pls, ptr, aStream, 1);
+               plRemakePlot(pls);
+               break;
+*/
+    case PLESC_REDRAW:
+               init_context(pls, ptr, aStream, 0);
+               plRemakePlot(pls);
+               break;
 
-      break;
     default: /* Fall back on default Cairo actions */
       plD_esc_cairo(pls, op, ptr);
       break;
diff --git a/include/plplot.h b/include/plplot.h
index dc99a7c..2aa796c 100644
--- a/include/plplot.h
+++ b/include/plplot.h
@@ -236,6 +236,7 @@ typedef void* PLPointer;
 #define PLESC_START_RASTERIZE   32      /* start rasterized rendering */
 #define PLESC_END_RASTERIZE     33      /* end rasterized rendering */
 #define PLESC_ARC               34      /* render an arc */
+#define PLESC_DEVINIT_FIT       35
 
 /* Alternative unicode text handling control characters */
 #define PLTEXT_FONTCHANGE       0       /* font change in the text stream */
diff --git a/include/plplotP.h b/include/plplotP.h
index 6dcf9b2..9631931 100644
--- a/include/plplotP.h
+++ b/include/plplotP.h
@@ -284,7 +284,7 @@ extern PLDLLIMPEXP_DATA(PLStream *)plsc;
 /* Some constants */
 
 #define PL_MAXPOLY     256     /* Max segments in polyline or polygon */
-#define PL_NSTREAMS    100     /* Max number of concurrent streams. */
+#define PL_NSTREAMS    10000   /* Max number of concurrent streams. */
 #define PL_RGB_COLOR   -1      /* A hack */
 
 #define TEXT_MODE      0
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Plplot-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/plplot-devel

Reply via email to