]> granicus.if.org Git - graphviz/commitdiff
more font feautures added
authorarif <devnull@localhost>
Wed, 29 Oct 2008 22:04:31 +0000 (22:04 +0000)
committerarif <devnull@localhost>
Wed, 29 Oct 2008 22:04:31 +0000 (22:04 +0000)
cmd/smyrna/draw.c
cmd/smyrna/glexpose.c
cmd/smyrna/gltemplate.c
cmd/smyrna/main.c
cmd/smyrna/topview.c
cmd/smyrna/viewport.c
lib/glcomp/glTexFont.c
lib/glcomp/glTexFont.h
lib/glcomp/glTexFontTGA.c
lib/glcomp/glcompset.c
lib/glcomp/glcompset.h

index 341aabfdb1f05c03452bc5e1dea98a67d6df730e..ae7de9592dcc9cac8c13c1becb8487f829178b2a 100755 (executable)
@@ -459,15 +459,14 @@ static void EmbedText(xdot_op * op, int param)
        x = (GLfloat) op->u.text.x;
     if (op->u.text.align == -1)
        x = (GLfloat) op->u.text.x + op->u.text.width;
-    fontSize(view->fontset
-               view->FontSize);
+       fontSize(view->fontset->fonts[view->fontset->activefont],view->FontSize);
     if (param == 0)
-       fontColor(view->penColor.R, view->penColor.G, view->penColor.B);
+       fontColor(view->fontset->fonts[view->fontset->activefont],view->penColor.R, view->penColor.G, view->penColor.B);
     if (param == 1)            //selected
-       fontColor(view->selectedNodeColor.R, view->selectedNodeColor.G,
+       fontColor(view->fontset->fonts[view->fontset->activefont],view->selectedNodeColor.R, view->selectedNodeColor.G,
                  view->selectedNodeColor.B);
 
-    fontDrawString((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);
 }
 
index a1cab09989bc6f0144cd4a6ef5a1b491cda13e69..2cba67e71b92b0ad82b8414488bc4f81ed24f537 100644 (file)
@@ -21,8 +21,6 @@
 #include "topfisheyeview.h"
 #include "glTexFont.h"
 
-extern texFont_t font;
-
 
 
 /*
@@ -124,7 +122,7 @@ void drawtestpoly()
        glEnable(GL_TEXTURE_2D);
        glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 //     glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE , GL_DECAL);
-       glBindTexture(GL_TEXTURE_2D,font.texId);
+       glBindTexture(GL_TEXTURE_2D,view->fontset->fonts[view->fontset->activefont]->texId);
        glColor3f(1,0,0);
        glBegin(GL_POLYGON);
                glTexCoord2f(0.0,0.0);glVertex3f(0.0,0.0,0.0);
index ba187ed1a60826d44c91b482049b4738667b81bb..2394231cbd6d7c774eae3538c8a61db909fd969e 100755 (executable)
@@ -136,9 +136,10 @@ static void realize(GtkWidget * widget, gpointer data)
 #else
     smyrna_font = smyrnaPath("arial.tga");
 #endif
-    g_print("loading font....%i\n", fontLoad(smyrna_font));
+//    g_print("loading font....%i\n", fontLoad(smyrna_font));
 
-  /*** OpenGL BEGIN ***/
+       add_font(view->fontset,"Vladimir script bold 16");//wired default font
+       /*** OpenGL BEGIN ***/
     if (!gdk_gl_drawable_gl_begin(gldrawable, glcontext))
        return;
 
index 0da23d4f0f9af582acb7d2cc386a1f6b2cc1e909..2e6ef2cab1f960514b67fb5c4bbfb2067f0df61d 100755 (executable)
@@ -117,7 +117,6 @@ int main(int argc, char *argv[])
        smyrnaDir = SMYRNA_PATH;
 #endif
 
-       create_font_file("c:\\pango_test.png",(float)64.0,(float)64.0);
        load_attributes();
 
 #ifdef G_OS_WIN32
index 593d1f2404b5ca72f9af102162675ac0c2515487..00e9cb359c3e39631ae3f01d7f1ab60e05adf3a1 100755 (executable)
@@ -229,6 +229,7 @@ void preparetopview(Agraph_t * g, topview * t)
     set_boundaries(t);
     set_update_required(t);
     t->topviewmenu = glcreate_gl_topview_menu();
+       //set componenet set's  font with already loaded default font.This will be inherited by all components added to this set as default
     attach_camera_widget(view);
     load_host_buttons(t, g, t->topviewmenu);
     t->h = '\0';
@@ -628,11 +629,11 @@ static int draw_node_hint_boxes()
                          (GLfloat) fs,agnameof(view->Topview->picked_nodes[ind]->Node)
                          )
                          ;
-       fontSize(fs);
-       fontColorA(0, 0, 1, 1);
+       fontSize(view->fontset->fonts[view->fontset->activefont],fs);
+       fontColorA(view->fontset->fonts[view->fontset->activefont],0, 0, 1, 1);
 
 
-       fontDrawString(
+       fontDrawString(view->fontset->fonts[view->fontset->activefont],
                       (view->Topview->picked_nodes[ind]->distorted_x),
                        (view->Topview->picked_nodes[ind]->
                              distorted_y+fs+fs/5.0 ),
@@ -858,18 +859,18 @@ static int draw_topview_label(topview_node * v, float zdepth)
                fs= 10;
 
 
-       fontSize((int) fs);
+       fontSize(view->fontset->fonts[view->fontset->activefont],(int) fs);
        if ((log((float) v->degree) * -0.6 * view->zoom) > 0)
-           fontColorA((float) log((double) v->degree + (double) 1),
+           fontColorA(view->fontset->fonts[view->fontset->activefont],(float) log((double) v->degree + (double) 1),
                       view->penColor.G, view->penColor.B,
                       view->penColor.A / (float) log((double) v->degree) *
                       (float) -0.6 * (float) view->zoom);
        else
-           fontColorA((float) log((double) v->degree + (double) 1),
+           fontColorA(view->fontset->fonts[view->fontset->activefont],(float) log((double) v->degree + (double) 1),
                       view->penColor.G, view->penColor.B, 1);
 
 //     fontColorA(0,0,0,1);
-       fontDrawString((int) (v->distorted_x - ddx),
+       fontDrawString(view->fontset->fonts[view->fontset->activefont],(int) (v->distorted_x - ddx),
                       (int) (v->distorted_y - ddy), v->Label,
                       (int) (fs * strlen(v->Label)*0.7));
 
@@ -1370,11 +1371,13 @@ static glCompSet *glcreate_gl_topview_menu()
 {
 
     glCompSet *s = NEW(glCompSet);
-    glCompPanel *p;
+
+       glCompPanel *p;
     glCompButton *b;
     glCompLabel *l;
-       /* GtkRequisition requisition; */
 
+       copy_font(&(s->font),view->fontset->fonts[view->fontset->activefont]);
+       /* GtkRequisition requisition; *//* What??*/
     if (!smyrna_icon_pan) {
 #ifdef _WIN32
        smyrna_icon_pan = "c:/pan.raw";
index 8bbdd6a31f2ec7dce8d4cd0c4ac6b6460bcea4f4..fbfb9bec4c586669c292ad6300ff6e293c0a8142 100755 (executable)
@@ -259,6 +259,7 @@ there i go, turn the page
        atoi(get_attribute_value ("drawlabels", view, g));
        view->FontSizeConst=0; //this will be calculated later in topview.c while calculating optimum font size
 
+
 //FIXME: I don't think an openGL function can be called before it
   //     is initialized.
 #ifdef _WIN32
@@ -405,6 +406,9 @@ void init_viewport(ViewInfo * view)
     set_viewport_settings_from_template(view, view->default_attributes);
     view->dfltViewType = VT_NONE;
     view->dfltEngine = GVK_NONE;
+       //create fontset
+       view->fontset=(fontset_t*)malloc(sizeof(fontset_t));
+       fontset_init(view->fontset);
 }
 
 
index edd19d2be50b13327eae87521d507632c39c3788..b6a12440e23e59c346847451e55d03ca10a5996d 100755 (executable)
@@ -725,13 +725,56 @@ void font_init(texFont_t* font)
        font->tIncY=0.0;
        font->blockRow=FONT_BLOCK_ROW;
        font->blockCol=FONT_BLOCK_COL;
-       font->texId=0;
+       font->texId=-1;
        font->fontdesc=(char*)0;
 
-       glGenTextures (1, &(font->texId));
        fontMakeMap (font);
 
 }
+void copy_font(texFont_t* targetfont,const texFont_t* sourcefont)
+{
+       targetfont->fgColor[0]=sourcefont->fgColor[0];
+       targetfont->fgColor[1]=sourcefont->fgColor[1];
+       targetfont->fgColor[2]=sourcefont->fgColor[2];
+       targetfont->fgColor[3]=sourcefont->fgColor[3];
+       targetfont->gdColor[0]=sourcefont->gdColor[0];
+       targetfont->gdColor[1]=sourcefont->gdColor[1];
+       targetfont->gdColor[2]=sourcefont->gdColor[2];
+       targetfont->gdColor[3]=sourcefont->gdColor[3];
+       targetfont->bgColor[0]=sourcefont->bgColor[0];
+       targetfont->bgColor[1]=sourcefont->bgColor[1];
+       targetfont->bgColor[2]=sourcefont->bgColor[2];
+       targetfont->bgColor[3]=sourcefont->bgColor[3];
+       targetfont->size=sourcefont->size;
+       targetfont->shadow=sourcefont->shadow;
+       targetfont->gradient=sourcefont->gradient;
+       targetfont->italic=sourcefont->italic;
+       targetfont->bold=sourcefont->bold;
+       targetfont->region=sourcefont->region;
+       targetfont->regionX=sourcefont->regionX;
+       targetfont->regionY=sourcefont->regionY;
+       targetfont->regionW=sourcefont->regionW;
+       targetfont->regionH=sourcefont->regionH;
+       targetfont->tIncX=sourcefont->tIncX;
+       targetfont->tIncY=sourcefont->tIncY;
+       targetfont->blockRow=sourcefont->blockRow;
+       targetfont->blockCol=sourcefont->blockCol;
+       targetfont->texId=sourcefont->texId;
+       if (targetfont->fontdesc)
+               free(targetfont->fontdesc);
+       if(sourcefont->fontdesc!=(char*)0)
+               targetfont->fontdesc=strdup(sourcefont->fontdesc);
+       else
+               targetfont->fontdesc=(char*)0;
+       fontMakeMap (targetfont);
+}
+void fontset_init(fontset_t* fs)
+{
+       fs->activefont=-1;
+       fs->count=0;
+       fs->font_directory=NULL; //FIX ME
+       fs->fonts=0;
+}
 
 
 int add_font(fontset_t* fontset,char* fontdesc)
@@ -741,17 +784,23 @@ int add_font(fontset_t* fontset,char* fontdesc)
        id=fontId(fontset,fontdesc);
        if (id==-1)
        {
-               sprintf(buf,"%s//%s.png","c://fontfiles//",fontdesc);
-               if(create_font_file(fontdesc,buf,(float)256,(float)256)==0)
+               sprintf(buf,"%s/%s.png","c:/fontfiles",fontdesc);
+               if(create_font_file(fontdesc,buf,(float)32,(float)32)==0)
                {
                        fontset->fonts=realloc(fontset->fonts,sizeof(texFont_t*)*(fontset->count+1));
                        fontset->fonts[fontset->count]=(texFont_t*)malloc(sizeof(texFont_t));
                        font_init(fontset->fonts[fontset->count]);
-                       if(!fontLoadPNG (buf, fontset->fonts[fontset->count]->texId))
+                       glGenTextures (1, &(fontset->fonts[fontset->count]->texId));    //get  opengl texture name
+                       if (fontset->fonts[fontset->count]->texId >= 0)
+                       {
+                               if(!fontLoadPNG (buf, fontset->fonts[fontset->count]->texId))
+                                       return -1;
+                               fontset->activefont=fontset->count;
+                               fontset->count++;
+                               return fontset->count;
+                       }
+                       else
                                return -1;
-
-                       fontset->count++;
-                       return fontset->count;
                }
                else
                        return -1;
@@ -768,7 +817,7 @@ void free_font_set(fontset_t* fontset)
                free(fontset->fonts[ind]);
        }
        free(fontset->fonts);
-       free(fontset->font_directory)
+       free(fontset->font_directory);
        free(fontset);
 }
 
index 7d4e9b3e73555c98ac49da57a4c021a144f567da..e52724e164731af4cf0ac1d640dccba01e91211c 100755 (executable)
@@ -76,8 +76,14 @@ extern "C" {
 */
 int fontId(fontset_t* fontset,char* fontdesc);
 
+/*
+       Initialize fontset as an empty set
+*/
+
+void fontset_init(fontset_t* fs);
 
 
+void copy_font(texFont_t* targetfont,const texFont_t* sourcefont);
 /*
        load font via font description
        returns the id,
@@ -151,9 +157,11 @@ void fontGradient (texFont_t* font);
 =============
 fontColor*, fontShadowColor*, fonrGradientColor*
 
+
 Sets color for various operations. 
 =============
 */
+
 void fontColor (texFont_t* font,float r, float g, float b);
 void fontColorA (texFont_t* font,float r, float g, float b, float a);
 void fontColorp (texFont_t* font,float *clr);
index 90a760bbf7ec092bf21380586019adc911dd6edd..709113488b45759941225d6c567cb26499b6128e 100755 (executable)
@@ -239,8 +239,8 @@ unsigned char *load_png_font(char* file_name,int *imageWidth,int *imageHeight)
 {
        unsigned char *imageData = NULL;
        unsigned char header[8];
-       int rowbytes,i,ii,c,pixeloffset;
-
+       int rowbytes,i,ii,b0,b1,b2,b3,pixeloffset;
+       long int c;
        png_structp png_ptr;
        png_infop info_ptr;
        png_infop end_info;
@@ -302,14 +302,40 @@ unsigned char *load_png_font(char* file_name,int *imageWidth,int *imageHeight)
        //decide what pixel offset to use, ro
        pixeloffset = png_get_rowbytes(png_ptr, info_ptr)/info_ptr->width;
 
+       b0=-1;b1=-1;b2=-1;b3=-1;
+
        for (i=0; i < info_ptr->height; i++)
    {
-          for (ii=0;ii < 1024; ii=ii+pixeloffset)      
+          printf ("Column:%i\n",i);
+          for (ii=0;ii < png_get_rowbytes(png_ptr, info_ptr); ii=ii+pixeloffset)       
                {
-                       imageData[c]=row_pointers[255-i][ii];
+                       imageData[c]=row_pointers[info_ptr->height-i-1][ii];
+
+                       if(
+                                       (b0!=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])
+                                       )
+                       {
+                               b0=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);
index cb501453e0ca1a6fca2d9781ba3e23feb223e3dc..11c3b6caae864739814b9bd2d9c9da22388a7b88 100644 (file)
@@ -105,6 +105,7 @@ glCompPanel *glCompPanelNew(GLfloat x, GLfloat y, GLfloat w, GLfloat h)
     p->pos.y = y;
     p->width = w;
     p->height = h;
+       font_init(&p->font);
     return p;
 }
 
@@ -114,7 +115,10 @@ int glCompSetAddPanel(glCompSet * s, glCompPanel * p)
     s->panels = realloc(s->panels, sizeof(glCompPanel *) * s->panelcount);
     s->panels[s->panelcount - 1] = p;
     p->parentset = s;
-    return 1;
+       if (p->font.texId==-1)  //no font has been set yet
+               copy_font(&(p->font),&(s->font));
+
+       return 1;
 }
 
 int glCompSetAddLabel(glCompSet * s, glCompLabel * p)
@@ -122,6 +126,8 @@ int glCompSetAddLabel(glCompSet * s, glCompLabel * p)
     s->labelcount++;
     s->labels = realloc(s->labels, sizeof(glCompLabel *) * s->labelcount);
     s->labels[s->labelcount - 1] = p;
+       if (p->font.texId==-1)  //no font has been set yet
+               copy_font(&(p->font),&(s->font));
     return 1;
 }
 
@@ -174,10 +180,10 @@ int glCompDrawLabel(glCompLabel * p)
            p->pos.y = p->pos.y + p->panel->pos.y;
        }
 
-       fontSize((int) p->size);
-       fontColorA(p->color.R, p->color.G, p->color.B, p->color.A);
+       fontSize(&p->font,(int) p->size);
+       fontColorA(&p->font,p->color.R, p->color.G, p->color.B, p->color.A);
 
-       fontDrawString((int) p->pos.x, (int) p->pos.y, p->text,
+       fontDrawString(&p->font,(int) p->pos.x, (int) p->pos.y, p->text,
                       (int) (p->size * p->fontsizefactor *
                              strlen(p->text)));
        if (p->panel) {
@@ -298,6 +304,7 @@ glCompButton *glCompButtonNew(GLfloat x, GLfloat y, GLfloat w, GLfloat h,
     p->callbackfunc = '\0';
     p->panel = '\0';
     p->customptr = '\0';
+       font_init(&p->font);
     return p;
 }
 
@@ -308,7 +315,8 @@ int glCompSetAddButton(glCompSet * s, glCompButton * p)
        realloc(s->buttons, sizeof(glCompButton *) * s->buttoncount);
     s->buttons[s->buttoncount - 1] = p;
     p->parentset = s;
-
+       if (p->font.texId==-1)  //no font has been set yet
+               copy_font(&(p->font),&(s->font));
     return 1;
 }
 
@@ -427,10 +435,10 @@ int glCompDrawButton(glCompButton * p)
        fonty =
            (p->height - p->thickness * (GLfloat) 2 -
             p->fontsize) / (GLfloat) 2.0 + p->pos.y + p->thickness;
-       fontSize((int) p->fontsize);
+       fontSize(&p->font,(int) p->fontsize);
 //              fontColorA (p->fontcolor.R,p->fontcolor.B,p->fontcolor.G,p->fontcolor.A);
-       fontColorA(0, 0, 0, 1);
-       fontDrawString((int) fontx, (int) fonty, p->caption,
+       fontColorA(&p->font,0, 0, 0, 1);
+       fontDrawString(&p->font,(int) fontx, (int) fonty, p->caption,
                       (int) (p->fontsize * strlen(p->caption) *
                              GLCOMPSET_FONT_SIZE_FACTOR));
     }
@@ -637,6 +645,7 @@ glCompLabel *glCompLabelNew(GLfloat x, GLfloat y, GLfloat size, char *text)
     p->visible = 1;
     p->fontsizefactor = GLCOMPSET_FONT_SIZE_FACTOR;
     p->panel = '\0';
+       font_init(&p->font);
     return p;
 }
 
@@ -694,3 +703,21 @@ void glCompSetClear(glCompSet * s)
     free(s->panels);
     free(s);
 }
+
+void change_fonts(glCompSet * s,const texFont_t* sourcefont)
+{
+    int ind = 0;
+    for (ind = 0; ind < s->buttoncount; ind++) 
+       {
+               copy_font(&(s->buttons[ind]->font),sourcefont); 
+    }
+    for (ind = 0; ind < s->labelcount; ind++) 
+       {
+               copy_font(&(s->labels[ind]->font),sourcefont);  
+
+    }
+    for (ind = 0; ind < s->panelcount; ind++) 
+       {
+               copy_font(&(s->panels[ind]->font),sourcefont);  
+    }
+}
\ No newline at end of file
index a1f543d10cd43d5dc5a654b74e17b8ecb19fe5d6..dec2c5c24112f0c88d97364ae3c9f678a26d87e9 100644 (file)
@@ -79,7 +79,7 @@ typedef struct _glCompPanel {
     int visible;
     void *parentset;           //parent compset
     int data;
-
+       texFont_t font; //pointer to font to use
 
 } glCompPanel;
 typedef struct _glCompLabel {
@@ -91,6 +91,7 @@ typedef struct _glCompLabel {
     char *text;
     GLfloat fontsizefactor;
     glCompPanel *panel;                //container panel
+       texFont_t font; //pointer to font to use
 } glCompLabel;
 
 
@@ -115,6 +116,7 @@ typedef struct _glCompButton {
     callbackfunc_t callbackfunc;       //call back for button click
     void *customptr;           //general purpose void pointer to pass to call back
     int data;
+       texFont_t font; //pointer to font to use
 } glCompButton;
 
 
@@ -130,6 +132,7 @@ typedef struct {
     int active;                        //0 dont draw, 1 draw
     int enabled;               //0 disabled 1 enabled(allow mouse interaction)
     GLfloat clickedX, clickedY;
+       texFont_t font; //pointer to font to use
 } glCompSet;
 
 glCompPanel *glCompPanelNew(GLfloat x, GLfloat y, GLfloat w, GLfloat h);
@@ -168,5 +171,12 @@ int glCompPanelHide(glCompPanel * p);
 int glCompPanelShow(glCompPanel * p);
 int glCompSetDrawPanels(glCompSet * s);
 
+/*
+       change all components's fonts  in s 
+       to sourcefont
+*/
+void change_fonts(glCompSet * s,const texFont_t* sourcefont);
+
+
 
 #endif