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)
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);
}
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);
}
}
drawXdotwithattr(e, "_tldraw_", param);
}
+
+
void drawGraph(Agraph_t * g)
{
Agnode_t *v;
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;
typedef struct {
xdot_op op;
void *obj;
+ void *font; //pointer to font in view->fontset
int size;
} sdot_op;
draw_selection_box(view);
drawBorders(view);
drawRotatingTools();
- drawtestpoly();
+// drawtestpoly();
/*DEBUG*/
/* if (view->mouse.mouse_mode == MM_PAN)
{
#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;
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]);
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;
/* 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] ) )
{
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]);
}
#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
else cmd = RALLOC (buflen, cmd, char);
}
sprintf (cmd, FMT, path, fix, alg, dotfile, xdotfile);
- r = system (cmd);
+ r = system (cmd);
unlink (dotfile);
free (dotfile);
free (xdotfile);
return 0;
}
- else return xdotfile;
+ else
+ {
+ return xdotfile;
+
+ }
}
/*
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
{
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);
}
}
#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
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];
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);
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))