]> granicus.if.org Git - graphviz/commitdiff
partially migrate win viewport to use graph viewport data
authorellson <devnull@localhost>
Tue, 28 Dec 2004 19:02:22 +0000 (19:02 +0000)
committerellson <devnull@localhost>
Tue, 28 Dec 2004 19:02:22 +0000 (19:02 +0000)
cmd/dot/dot.c
lib/common/emit.c
lib/common/output.c
lib/common/renderprocs.h
lib/gvc/gvemit.c
lib/gvc/gvrender.c
tclpkg/tcldot/tcldot.c

index ba8405bc753706eadff765bbf477f3ddb715826b..69f3fbe1fc2c64ad9f981b15de01fb9815da175c 100644 (file)
@@ -56,7 +56,7 @@ static GVC_t *gvc;
 static void intr(int s)
 {
     if (gvc->g)
-       dotneato_write(gvc);
+       dotneato_write(gvc, gvc->g);
     dotneato_terminate(gvc);
     exit(1);
 }
@@ -174,7 +174,7 @@ int main(int argc, char **argv)
                agclose(prev);
            }
            gvlayout_layout(gvc, g);
-           dotneato_write(gvc);
+           dotneato_write(gvc, g);
            prev = g;
        }
     }
index 60aeb43568ec9d06b9d5ba706b4d2c16a00ef99a..2db7b5841e7ab8a7e37a3beb7ac0d1e09f0be385 100644 (file)
@@ -80,9 +80,8 @@ static int write_node_test(Agraph_t * g, Agnode_t * n)
 }
 
 
-void emit_reset(GVC_t * gvc)
+void emit_reset(GVC_t * gvc, graph_t * g)
 {
-    Agraph_t *g = gvc->g;
     Agnode_t *n;
 
     N_pages = 1;
@@ -653,18 +652,13 @@ void emit_edge(GVC_t * gvc, edge_t * e)
     gvrender_end_edge(gvc);
 }
 
-void emit_graph(GVC_t * gvc, graph_t * g, int flags)
+void emit_init(GVC_t * gvc, graph_t * g)
 {
-    point curpage;
-    graph_t *sg;
-    node_t *n;
-    edge_t *e;
-    int c;
-    char *str, *colors;
-    double X, Y, Z, x, y;
-    char *s, *url = NULL, *tooltip = NULL, *target = NULL;
+    char *str;
+    double X = 400.0, Y = 400.0, Z = 0.0, x = 0.0, y = 0.0;
+
+/* FIXME - init viewport to graph dimensions */
 
-    X = Y = Z = x = y = 0.0;
     if ((str = agget(g, "viewport")))
        sscanf(str, "%lf,%lf,%lf,%lf,%lf", &X, &Y, &Z, &x, &y);
     gvc->size.x = ROUND(X);
@@ -675,8 +669,26 @@ void emit_graph(GVC_t * gvc, graph_t * g, int flags)
 
     G_peripheries = agfindattr(g, "peripheries");
     setup_graph(gvc, g);
-    if (Page == 0)
-       gvrender_begin_job(gvc, Lib, Pages);
+    gvrender_begin_job(gvc, Lib, Pages);
+}
+
+void emit_deinit(GVC_t * gvc, graph_t * g)
+{
+}
+
+void emit_graph(GVC_t * gvc, graph_t * g, int flags)
+{
+    point curpage;
+    graph_t *sg;
+    node_t *n;
+    edge_t *e;
+    int c;
+    char *str, *colors;
+    char *s, *url = NULL, *tooltip = NULL, *target = NULL;
+
+    /* FIXME - I don't understand why I need this again */
+    setup_graph(gvc, g);
+
     gvrender_begin_graph(gvc, g, PB, PFC);
     if (flags & EMIT_COLORS) {
        gvrender_set_fillcolor(gvc, DEFAULT_FILL);
index b92b682c250974c842b08c04eb89240cdfd3bb67..c8e6e5e3236121d02696c98efeedba7f49ef778d 100644 (file)
@@ -122,6 +122,9 @@ void dotneato_write_one(GVC_t * gvc, graph_t * g)
 {
     int flags;
 
+    gvc->g = g;
+    dotneato_set_margins(gvc, g);
+    emit_init(gvc, g);
     if (NOT(gvrender_features(gvc) & GVRENDER_DOES_MULTIGRAPH_OUTPUT_FILES)
 #ifndef DISABLE_CODEGENS
 /* FIXME - bad hack until feaures supported in codegens */
@@ -131,8 +134,7 @@ void dotneato_write_one(GVC_t * gvc, graph_t * g)
 #endif
 #endif
        )
-       emit_reset(gvc);
-    dotneato_set_margins(gvc, g);
+       emit_reset(gvc, g);
     switch (gvc->job->output_lang) {
     case GVRENDER_PLUGIN:
        flags = chkOrder(g);
@@ -211,11 +213,11 @@ void dotneato_write_one(GVC_t * gvc, graph_t * g)
 
     }
     fflush(gvc->job->output_file);
+    emit_deinit(gvc, g);
 }
 
-void dotneato_write(GVC_t * gvc)
+void dotneato_write(GVC_t * gvc, graph_t * g)
 {
-    graph_t *g = gvc->g;
     gvrender_job_t *job;
 
     for (job = gvrender_first_job(gvc); job; job = gvrender_next_job(gvc)) {
index 2effe7dbe4cbe8e7cb6f4506dd7d2c286f9a1691..8f3aa2cba7469ac9374054491a9b1e86c8d951b8 100644 (file)
@@ -68,13 +68,15 @@ extern "C" {
     extern void dotneato_set_margins(GVC_t * gvc, Agraph_t *);
     extern void dotneato_eof(GVC_t * gvc);
     extern void dotneato_terminate(GVC_t * gvc);
-    extern void dotneato_write(GVC_t * gvc);
-    extern void dotneato_write_one(GVC_t * gvc, graph_t * g);
+    extern void dotneato_write(GVC_t * gvc, graph_t *g);
+    extern void dotneato_write_one(GVC_t * gvc, graph_t *g);
     extern int edge_in_CB(Agedge_t *);
     extern int edge_in_layer(Agraph_t *, Agedge_t *);
     extern double elapsed_sec(void);
     extern void enqueue(queue *, Agnode_t *);
     extern void enqueue_neighbors(queue *, Agnode_t *, int);
+    extern void emit_init(GVC_t * gvc, graph_t * g);
+    extern void emit_deinit(GVC_t * gvc, graph_t * g);
     extern void emit_attachment(GVC_t * gvc, textlabel_t *, splines *);
     extern void emit_clusters(GVC_t * gvc, Agraph_t * g, int flags);
     extern void emit_eof(GVC_t * gvc);
@@ -84,7 +86,7 @@ extern "C" {
     extern void emit_label(GVC_t * gvc, textlabel_t *, void *obj);
     extern int emit_once(char *message);
     extern void emit_once_reset();
-    extern void emit_reset(GVC_t * gvc);
+    extern void emit_reset(GVC_t * gvc, graph_t * g);
     extern void endpath(path *, Agedge_t *, int, pathend_t *, boolean);
     extern void epsf_init(node_t * n);
     extern void epsf_free(node_t * n);
index 1fef649b1404b9b557bd4dcca9c1fd2a5c2dc67d..b4162d84a727b04902810b68c19f1ff956d270f2 100644 (file)
@@ -52,8 +52,11 @@ typedef struct win {
 
     unsigned int width, height;
 
-    cairo_t *cr;
     GVC_t *gvc;
+    graph_t *g;
+    int flags;
+
+    cairo_t *cr;
 
     double tx, ty, zoom, oldx, oldy;
     int needs_refresh, fit_mode, click, active;
@@ -177,8 +180,6 @@ static void win_init(win_t * win, int argb, const char *geometry,
        int x, y;
        XParseGeometry(geometry, &x, &y, &win->width, &win->height);
     } else {
-/* FIXME - gvc->size is 0,0 at this time.  need to set viewport and transform earlier */
-//     svg_cairo_get_size(win->svgc, &win->width, &win->height);
         win->width = win->gvc->size.x;
         win->height = win->gvc->size.y;
     }
@@ -232,7 +233,7 @@ static void win_init(win_t * win, int argb, const char *geometry,
        else
            key_binding[i].keycode = XKeysymToKeycode(dpy, keysym);
     }
-    win->cr = cairo_create();
+//    win->cr = cairo_create();
     surface = cairo_xlib_surface_create(dpy, win->pix, win->visual,
                                        CAIRO_FORMAT_ARGB32, win->cmap);
     cairo_set_target_surface(win->cr, surface);
@@ -264,8 +265,8 @@ static void win_init(win_t * win, int argb, const char *geometry,
 
 static void win_deinit(win_t * win)
 {
-    cairo_destroy(win->cr);
-    win->cr = NULL;
+//    cairo_destroy(win->cr);
+//    win->cr = NULL;
     XFreeGC(win->dpy, win->gc);
     XDestroyWindow(win->dpy, win->win);
 }
@@ -278,9 +279,7 @@ static void win_refresh(win_t * win)
     cairo_translate(win->cr, win->tx, win->ty);
     cairo_scale(win->cr, win->zoom, win->zoom);
 
-//    svg_cairo_render(win->svgc, win->cr);
-// FIXME:  flags = chkOrder(g) | gvc->render_features->flags;
-    emit_graph(win->gvc, win->gvc->g, win->gvc->render_features->flags);
+    emit_graph(win->gvc, win->g, win->flags);
 
     cairo_restore(win->cr);
     XCopyArea(win->dpy, win->pix, win->win, win->gc,
@@ -552,7 +551,6 @@ static int toggle_fit_cb(win_t * win)
     win->fit_mode = !win->fit_mode;
     if (win->fit_mode) {
        int dflt_width, dflt_height;
-//     svg_cairo_get_size(win->svgc, &dflt_width, &dflt_height);
        dflt_width = win->gvc->size.x;
        dflt_height = win->gvc->size.y;
        win->zoom =
@@ -566,7 +564,6 @@ static int toggle_fit_cb(win_t * win)
 }
 #endif /* X_DISPLAY_MISSING */
 
-
 void gvemit_graph(GVC_t * gvc, graph_t * g, int flags)
 {
    if (flags & GVRENDER_X11_EVENTS) {
@@ -574,9 +571,14 @@ void gvemit_graph(GVC_t * gvc, graph_t * g, int flags)
        win_t win;
        const char *display=NULL;
        int argb=0;
-       const char *geometry="200x200";
+       const char *geometry=NULL;
 
        win.gvc = gvc;
+       win.g = g;
+       win.flags = flags;
+
+       gvc->surface = win.cr = cairo_create();;
+       gvc->external_surface = TRUE;
 
        win.dpy = XOpenDisplay(display);
        if (win.dpy == NULL) {
@@ -589,6 +591,7 @@ void gvemit_graph(GVC_t * gvc, graph_t * g, int flags)
 
        win_handle_events(&win);
 
+       cairo_destroy(win.cr);
        win_deinit(&win);
 
        XCloseDisplay(win.dpy);
index db76c8b801db873a9d08f7d265e38c3ebe2bbbe3..9dcaf668561909db7af8d32f9af8849b8b3fd05c 100644 (file)
@@ -134,7 +134,7 @@ void gvrender_begin_job(GVC_t * gvc, char **lib, point pages)
     else {
        codegen_t *cg = gvc->codegen;
 
-       if (cg && cg->begin_job)
+       if (cg && cg->begin_job && gvc->page_number == 0)
            cg->begin_job(gvc->job->output_file, gvc->g, lib, gvc->user,
                          gvc->info, pages);
     }
index dbec842b017c050002ea920e212515266ecafd54..6af266cb95bbd6f019c24c3359c503db07d8c8c0 100644 (file)
@@ -1267,7 +1267,7 @@ static int graphcmd(ClientData clientData, Tcl_Interp * interp,
        return TCL_OK;
 
     } else if ((c == 'w') && (strncmp(argv[1], "write", length) == 0)) {
-       gvc->g = g = g->root;
+       g = g->root;
        if (argc < 3) {
            Tcl_AppendResult(interp, "wrong # args: should be \"",
                             argv[0],
@@ -1299,7 +1299,7 @@ static int graphcmd(ClientData clientData, Tcl_Interp * interp,
            tcldot_layout(g, (argc > 4) ? argv[4] : (char *) NULL);
        }
 
-       emit_reset(gvc);        /* reset page numbers in postscript */
+       emit_reset(gvc, g);     /* reset page numbers in postscript */
        dotneato_write_one(gvc, g);
        gvrender_delete_jobs(gvc);
        return TCL_OK;