]> granicus.if.org Git - graphviz/commitdiff
font / selection / few memory leaks fix
authorarif <devnull@localhost>
Mon, 3 Nov 2008 20:40:08 +0000 (20:40 +0000)
committerarif <devnull@localhost>
Mon, 3 Nov 2008 20:40:08 +0000 (20:40 +0000)
cmd/smyrna/draw.c
cmd/smyrna/draw.h
cmd/smyrna/glexpose.c
cmd/smyrna/gltemplate.c
cmd/smyrna/selection.c
cmd/smyrna/viewport.c
lib/glcomp/glTexFontTGA.c
lib/glcomp/glpangofont.c

index ae7de9592dcc9cac8c13c1becb8487f829178b2a..6bf6406ac794eca855514c61caea173936444418 100755 (executable)
@@ -439,8 +439,9 @@ static void SetStyle(xdot_op * op, int param)
 
 static void SetFont(xdot_op * op, int param)
 {
-//      view->FontName=ABSet(op->u.font.name);
-    view->FontSize = (int) op->u.font.size;
+       //activate the right font
+       view->fontset->activefont=add_font(view->fontset,op->u.font.name);//load or set active font
+       view->FontSize = (int) op->u.font.size;
 }
 
 static void InsertImage(xdot_op * op, int param)
@@ -465,8 +466,7 @@ static void EmbedText(xdot_op * op, int param)
     if (param == 1)            //selected
        fontColor(view->fontset->fonts[view->fontset->activefont],view->selectedNodeColor.R, view->selectedNodeColor.G,
                  view->selectedNodeColor.B);
-
-    fontDrawString(view->fontset->fonts[view->fontset->activefont],(int) (x - dx), op->u.text.y - (int) dy,
+       fontDrawString(view->fontset->fonts[view->fontset->activefont],(int) (x - dx), op->u.text.y - (int) dy,
                   op->u.text.text, op->u.text.width);
 }
 
@@ -627,22 +627,26 @@ static void drawXdot(xdot * xDot, int param, void *p)
     sdot_op *ops = (sdot_op *) (xDot->ops);
     sdot_op *op;
 
-    for (id = 0; id < xDot->cnt; id++) {
-       op = ops + id;
-       op->obj = p;
-       op->op.drawfunc(&(op->op), param);
+    for (id = 0; id < xDot->cnt; id++)
+       {
+               op = ops + id;
+               op->obj = p;
+               op->op.drawfunc(&(op->op), param);
     }
     if (OD_Preselected(p) == 1)
-       select_object(view->g[view->activeGraph], p);
+               select_object(view->g[view->activeGraph], p);
     OD_Preselected(p) = 0;
 }
 
+
+
 static void drawXdotwithattr(void *p, char *attr, int param)
 {
     xdot *xDot;
-    if ((xDot = parseXDotF(agget(p, attr), OpFns, sizeof(sdot_op)))) {
-       drawXdot(xDot, param, p);
-       freeXDot(xDot);
+    if ((xDot = parseXDotF(agget(p, attr), OpFns, sizeof(sdot_op))))
+       {
+               drawXdot(xDot, param, p);
+               freeXDot(xDot);
     }
 }
 
@@ -656,6 +660,8 @@ static void drawXdotwithattrs(void *e, int param)
     drawXdotwithattr(e, "_tldraw_", param);
 }
 
+
+
 void drawGraph(Agraph_t * g)
 {
     Agnode_t *v;
@@ -663,44 +669,113 @@ void drawGraph(Agraph_t * g)
     Agraph_t *s;
     int param = 0;
 
-    for (s = agfstsubg(g); s; s = agnxtsubg(s)) {
-       OD_SelFlag(s) = 0;
-       if (OD_Selected(s) == 1)
-           param = 1;
-       else
-           param = 0;
-       drawXdotwithattrs(s, param);
+    for (s = agfstsubg(g); s; s = agnxtsubg(s))
+       {
+               OD_SelFlag(s) = 0;
+               if (OD_Selected(s) == 1)
+                       param = 1;
+               else
+                   param = 0;
+               drawXdotwithattrs(s, param);
     }
 
-    for (v = agfstnode(g); v; v = agnxtnode(g, v)) {
-       if (OD_Selected(v) == 1)
-           param = 1;
-       else
-           param = 0;
-       OD_SelFlag(v) = 0;
-       drawXdotwithattr(v, "_draw_", param);
-       drawXdotwithattr(v, "_ldraw_", param);
-       for (e = agfstout(g, v); e; e = agnxtout(g, e)) {
-           OD_SelFlag(e) = 0;
-           if (OD_Selected(e) == 1)
-               param = 1;
-           else
-               param = 0;
-
-           drawXdotwithattrs(e, param);
+    for (v = agfstnode(g); v; v = agnxtnode(g, v)) 
+       {
+               if (OD_Selected(v) == 1)
+                       param = 1;
+               else
+                       param = 0;
+               OD_SelFlag(v) = 0;
+               drawXdotwithattr(v, "_draw_", param); //draw primitives
+               drawXdotwithattr(v, "_ldraw_", param);//label drawing
+               for (e = agfstout(g, v); e; e = agnxtout(g, e)) 
+               {
+                       OD_SelFlag(e) = 0;
+                       if (OD_Selected(e) == 1)
+                               param = 1;
+                       else
+                               param = 0;
+                   drawXdotwithattrs(e, param);
+               }
+    }
+    if ((view->Selection.Active > 0) && (!view->SignalBlock)) 
+       {
+               view->Selection.Active = 0;
+               drawGraph(g);
+               view->SignalBlock = 1;
+               glexpose();
+               view->SignalBlock = 0;
+    }
 
-       }
+}
+
+
+/*
+       this function is used to cache fonts in view->fontset
+*/
+
+static void scanXdot(xdot * xDot, void *p)
+{
+    int id;
+    sdot_op *ops = (sdot_op *) (xDot->ops);
+    sdot_op *op;
+
+    for (id = 0; id < xDot->cnt; id++)
+       {
+               op = ops + id;
+               op->obj = p;
+               if (op->op.kind==xd_font)
+               {
+                       add_font(view->fontset,op->op.u.font.name);//load or set active font
+               }
     }
-    if ((view->Selection.Active > 0) && (!view->SignalBlock)) {
-       view->Selection.Active = 0;
-       drawGraph(g);
-       view->SignalBlock = 1;
-       glexpose();
-       view->SignalBlock = 0;
+
+}
+
+
+static void scanXdotwithattr(void *p, char *attr)
+{
+    xdot *xDot;
+    if ((xDot = parseXDotF(agget(p, attr), OpFns, sizeof(sdot_op))))
+       {
+               scanXdot(xDot, p);
+               freeXDot(xDot);
     }
+}
 
+static void scanXdotwithattrs(void *e)
+{
+    scanXdotwithattr(e, "_draw_");
+    scanXdotwithattr(e, "_ldraw_");
+    scanXdotwithattr(e, "_hdraw_");
+    scanXdotwithattr(e, "_tdraw_");
+    scanXdotwithattr(e, "_hldraw_");
+    scanXdotwithattr(e, "_tldraw_");
 }
 
+
+
+/*
+       iterate in nodes and edges to cache fonts, run this once or whenever a new font is added to the graph
+*/
+
+
+void scanGraph(Agraph_t * g)
+{
+    Agnode_t *v;
+    Agedge_t *e;
+    Agraph_t *s;
+    for (v = agfstnode(g); v; v = agnxtnode(g, v)) 
+       {
+               scanXdotwithattr(v, "_draw_"); 
+               scanXdotwithattr(v, "_ldraw_");
+               for (e = agfstout(g, v); e; e = agnxtout(g, e)) 
+               {
+             scanXdotwithattrs(e);
+               }
+    }
+
+}
 int randomize_color(RGBColor * c, int brightness)
 {
     float R, B, G;
index b0e4e0425f346879e5834fe0875298b97b7c0de3..41b93c5e4c2fed7aeb3d8054332167a99288f29a 100755 (executable)
@@ -26,6 +26,7 @@
 typedef struct {
     xdot_op op;
     void *obj;
+       void *font;             //pointer to font in view->fontset
     int size;
 } sdot_op;
 
index 2cba67e71b92b0ad82b8414488bc4f81ed24f537..2b28ab47b1fa4c90b08a162f90f13ccf24db7674 100644 (file)
@@ -91,7 +91,7 @@ int glexpose_main(ViewInfo * view)
     draw_selection_box(view);
     drawBorders(view);
        drawRotatingTools();
-       drawtestpoly();
+//     drawtestpoly();
        /*DEBUG*/
 /*     if (view->mouse.mouse_mode == MM_PAN)
        {
index 2394231cbd6d7c774eae3538c8a61db909fd969e..1cc54fe7bd89172e85364ebaec8ca48f75ed2338 100755 (executable)
@@ -138,7 +138,7 @@ static void realize(GtkWidget * widget, gpointer data)
 #endif
 //    g_print("loading font....%i\n", fontLoad(smyrna_font));
 
-       add_font(view->fontset,"Vladimir script bold 16");//wired default font
+       add_font(view->fontset,"Times 16");//wired in default font
        /*** OpenGL BEGIN ***/
     if (!gdk_gl_drawable_gl_begin(gldrawable, glcontext))
        return;
@@ -323,6 +323,7 @@ static gboolean button_release_event(GtkWidget * widget,
            view->Selection.Active = 1;
            expose_event(view->drawing_area, NULL, NULL);
        }
+
        if (view->mouse.mouse_mode == MM_MOVE) {
            if (GD_TopView(view->g[view->activeGraph]) == 0)
                move_nodes(view->g[view->activeGraph]);
index 8b3f2e1c3aeda86b1a16af301d74b39542483666..3ed973b81bb7933c5774f555cd8914a116b19ce2 100755 (executable)
@@ -629,10 +629,14 @@ int lineintersects(float X1, float X2, float Y1, float Y2)
     float x, y, m, iter;
     float RX, RY, RW, RH;
     int intersects, in;
+       if (view->mouse.mouse_mode == MM_SINGLE_SELECT)
+       {
+           RW = 10;
+           RH = 10;
+       }
+
     RX = view->Selection.X;
     RY = view->Selection.Y;
-    RW = view->Selection.W;
-    RH = view->Selection.H;
     if ((is_point_in_rectangle(X1, Y1, RX, RY, RW, RH))
        && (is_point_in_rectangle(X2, Y2, RX, RY, RW, RH)))
        return 1;
index fbfb9bec4c586669c292ad6300ff6e293c0a8142..7ee966ecce7063ce2f76373c63442fb17c0d489d 100755 (executable)
@@ -34,6 +34,7 @@
 
   /* Forward declarations */
 static int init_object_custom_data(Agraph_t * graph, void *obj);
+static void refresh_borders(Agraph_t* g);
 
 #define countof( array ) ( sizeof( array )/sizeof( array[0] ) )
 
@@ -57,8 +58,9 @@ void clear_viewport(ViewInfo * view)
 {
     int ind = 0;
     /*free topview if there is one */
-    if (view->graphCount) {
-       cleartopview(view->Topview);
+       if (GD_TopView(view->g[view->activeGraph]))
+               cleartopview(view->Topview);
+       if (view->graphCount) {
        /*all cgraph graphs should be freed */
        for (ind = 0; ind < view->graphCount; ind++) {
            agclose(view->g[ind]);
@@ -667,7 +669,7 @@ static char* create_xdot_for_graph(Agraph_t * graph, int keeppos)
     } 
 
 #ifdef _WIN32
-    path = "\"C:/Program Files/Graphviz2.15/bin/dot.exe\" ";
+    path = "\"C:/Program Files/Graphviz 2.20/bin/dot.exe\" ";
 #else
     path = "dot ";
 #endif
@@ -680,7 +682,7 @@ static char* create_xdot_for_graph(Agraph_t * graph, int keeppos)
        else cmd = RALLOC (buflen, cmd, char);
     }
     sprintf (cmd, FMT, path, fix, alg, dotfile, xdotfile);
-    r = system (cmd);
+       r = system (cmd);
     unlink (dotfile);
     free (dotfile);
 
@@ -689,7 +691,11 @@ static char* create_xdot_for_graph(Agraph_t * graph, int keeppos)
        free (xdotfile);
        return 0;
     }
-    else return xdotfile;
+    else
+       {
+               return xdotfile;
+
+       }
 }
 
 /*
@@ -709,6 +715,7 @@ layoutGraph (Agraph_t *oldg, int keeppos, int closeold)
     if (closeold)
        agclose (oldg);
     newg = agread(input_file, NIL(Agdisc_t *));
+       refresh_borders(newg);
     g_print ("xdot is being loaded\n");
     fclose (input_file);
     unlink (infile);  // Remove temp file
@@ -723,26 +730,32 @@ static Agraph_t *loadGraph(char *filename)
 {
     Agraph_t *g;
     FILE *input_file;
-    if (!(input_file = fopen(filename, "r"))) {
-       g_print("Cannot open %s\n", filename);
-       return 0;
+       char* bf;
+       char buf[512];
+    if (!(input_file = fopen(filename, "r")))
+       {
+               g_print("Cannot open %s\n", filename);
+               return 0;
     }
-    if (!(g = agread(input_file, NIL(Agdisc_t *)))) {
-       g_print("Cannot read graph in  %s\n", filename);
-       fclose (input_file);
-       return 0;
+    if (!(g = agread(input_file, NIL(Agdisc_t *)))) 
+       {
+               g_print("Cannot read graph in  %s\n", filename);
+               fclose (input_file);
+               return 0;
     }
 
        /* If no position info, run layout with -Txdot
          */
-    if (!agattr(g, AGNODE, "pos", NULL)) {
-       g = layoutGraph (g, 0, 1);
-       if (!g) return 0;
+    if (!agattr(g, AGNODE, "pos", NULL)) 
+       {
+               g = layoutGraph (g, 0, 1);
+               if (!g) return 0;
     }
        /* If position info but not xdot, set Topview mode
          */
-    else if (!agattr(g, AGRAPH, "xdotversion", 0)) {
-       agattr(g, AGRAPH, "TopView", "1");
+    else if (!agattr(g, AGRAPH, "xdotversion", 0)) 
+       {
+               agattr(g, AGRAPH, "TopView", "1");
     }
 
     attach_object_custom_data_to_graph(g);
@@ -768,10 +781,26 @@ static Agraph_t *loadGraph(char *filename)
        }
     }
 #endif
-       if(strcasecmp(agget(g, "TopView"),"1")==0)
-               preparetopview(g, view->Topview);
+       bf=agget(g, "TopView");
+
+       if (bf)
+       {
+               if(strcasecmp(agget(g, "TopView"),"1")==0)
+                       preparetopview(g, view->Topview);
+       }
+       else    //set graph borders
+       {
+               refresh_borders(g);
+               scanGraph(g);   //calling font caching routines once....
+       }
     return g;
 }
+static void refresh_borders(Agraph_t* g)
+{
+               sscanf(agget(g,"bb"),"%f,%f,%f,%f",&(view->bdxLeft),&(view->bdyBottom),&(view->bdxRight),&(view->bdyTop));      
+}
+
+
 
 /* add_graph_to_viewport_from_file:
  * returns 1 if successfull else 0
index 709113488b45759941225d6c567cb26499b6128e..62212b85880e8eeca7cc9f6c2ab977e4fcfeeb73 100755 (executable)
@@ -306,7 +306,6 @@ unsigned char *load_png_font(char* file_name,int *imageWidth,int *imageHeight)
 
        for (i=0; i < info_ptr->height; i++)
    {
-          printf ("Column:%i\n",i);
           for (ii=0;ii < png_get_rowbytes(png_ptr, info_ptr); ii=ii+pixeloffset)       
                {
                        imageData[c]=row_pointers[info_ptr->height-i-1][ii];
@@ -325,17 +324,13 @@ unsigned char *load_png_font(char* file_name,int *imageWidth,int *imageHeight)
                                b1=row_pointers[info_ptr->height-i-1][ii+1];
                                b2=row_pointers[info_ptr->height-i-1][ii+2];
                                b3=row_pointers[info_ptr->height-i-1][ii+3];
-                                       printf ("(%i,%i,%i,%i)",b0,b1,b2,b3);
 
                        }
 
 
                        c++;
                }
-          printf ("\n");
    }
-       printf ("embedded bytes:%i\n",c);
-
        //cleaning libpng mess
        png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
        png_free(png_ptr, row_pointers);
index d4cd7abc8457a448b2b23f898684f4f5437930ff..98ffdf2d06fce449f47679e9b7d0f01c5e1dc499 100644 (file)
@@ -45,7 +45,7 @@ PangoLayout *  get_pango_layout (cairo_t      *cr,
 
        desc = pango_font_description_from_string(fontdescription);
 //     pango_font_description_set_family(desc, "CENTAUR.TTF");
-    //pango_font_description_set_size (desc, DEFAULT_FONT_SIZE * PANGO_SCALE/2.0);
+    pango_font_description_set_size (desc, DEFAULT_FONT_SIZE * PANGO_SCALE/2.0);
 //     pango_font_description_set_style    (desc,PANGO_STYLE_ITALIC);
 
     if (! pango_parse_markup (markup_text, -1, '\0', &attr_list, &text, NULL, NULL))