From 027cb1d867b771ce1fae2c5b68a386b82edf90b7 Mon Sep 17 00:00:00 2001 From: arif Date: Wed, 29 Oct 2008 22:04:31 +0000 Subject: [PATCH] more font feautures added --- cmd/smyrna/draw.c | 9 +++--- cmd/smyrna/glexpose.c | 4 +-- cmd/smyrna/gltemplate.c | 5 +-- cmd/smyrna/main.c | 1 - cmd/smyrna/topview.c | 21 ++++++------ cmd/smyrna/viewport.c | 4 +++ lib/glcomp/glTexFont.c | 67 +++++++++++++++++++++++++++++++++------ lib/glcomp/glTexFont.h | 8 +++++ lib/glcomp/glTexFontTGA.c | 34 +++++++++++++++++--- lib/glcomp/glcompset.c | 43 ++++++++++++++++++++----- lib/glcomp/glcompset.h | 12 ++++++- 11 files changed, 166 insertions(+), 42 deletions(-) diff --git a/cmd/smyrna/draw.c b/cmd/smyrna/draw.c index 341aabfdb..ae7de9592 100755 --- a/cmd/smyrna/draw.c +++ b/cmd/smyrna/draw.c @@ -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); } diff --git a/cmd/smyrna/glexpose.c b/cmd/smyrna/glexpose.c index a1cab0998..2cba67e71 100644 --- a/cmd/smyrna/glexpose.c +++ b/cmd/smyrna/glexpose.c @@ -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); diff --git a/cmd/smyrna/gltemplate.c b/cmd/smyrna/gltemplate.c index ba187ed1a..2394231cb 100755 --- a/cmd/smyrna/gltemplate.c +++ b/cmd/smyrna/gltemplate.c @@ -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; diff --git a/cmd/smyrna/main.c b/cmd/smyrna/main.c index 0da23d4f0..2e6ef2cab 100755 --- a/cmd/smyrna/main.c +++ b/cmd/smyrna/main.c @@ -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 diff --git a/cmd/smyrna/topview.c b/cmd/smyrna/topview.c index 593d1f240..00e9cb359 100755 --- a/cmd/smyrna/topview.c +++ b/cmd/smyrna/topview.c @@ -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"; diff --git a/cmd/smyrna/viewport.c b/cmd/smyrna/viewport.c index 8bbdd6a31..fbfb9bec4 100755 --- a/cmd/smyrna/viewport.c +++ b/cmd/smyrna/viewport.c @@ -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); } diff --git a/lib/glcomp/glTexFont.c b/lib/glcomp/glTexFont.c index edd19d2be..b6a12440e 100755 --- a/lib/glcomp/glTexFont.c +++ b/lib/glcomp/glTexFont.c @@ -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); } diff --git a/lib/glcomp/glTexFont.h b/lib/glcomp/glTexFont.h index 7d4e9b3e7..e52724e16 100755 --- a/lib/glcomp/glTexFont.h +++ b/lib/glcomp/glTexFont.h @@ -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); diff --git a/lib/glcomp/glTexFontTGA.c b/lib/glcomp/glTexFontTGA.c index 90a760bbf..709113488 100755 --- a/lib/glcomp/glTexFontTGA.c +++ b/lib/glcomp/glTexFontTGA.c @@ -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); diff --git a/lib/glcomp/glcompset.c b/lib/glcomp/glcompset.c index cb501453e..11c3b6caa 100644 --- a/lib/glcomp/glcompset.c +++ b/lib/glcomp/glcompset.c @@ -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 diff --git a/lib/glcomp/glcompset.h b/lib/glcomp/glcompset.h index a1f543d10..dec2c5c24 100644 --- a/lib/glcomp/glcompset.h +++ b/lib/glcomp/glcompset.h @@ -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 -- 2.40.0