From ed74e24b8020a70678d05489639e0e8c4574f87d Mon Sep 17 00:00:00 2001 From: arif Date: Mon, 23 Mar 2009 15:38:58 +0000 Subject: [PATCH] gdi_plus fixed glcopm:most of the licensed code removed , few left --- cmd/smyrna/draw.c | 4 +- cmd/smyrna/glexpose.c | 4 + cmd/smyrna/gltemplate.c | 1 - cmd/smyrna/gui/menucallbacks.c | 11 +- cmd/smyrna/main.c | 4 +- cmd/smyrna/smyrna.vcproj | 6 +- cmd/smyrna/smyrnadefs.h | 4 +- cmd/smyrna/topfisheyeview.c | 118 ++++-- cmd/smyrna/topview.c | 33 +- cmd/smyrna/viewport.c | 2 +- graphviz.sln | 6 - lib/glcomp/glTexFont.c | 554 ++++------------------------ lib/glcomp/glTexFont.h | 146 +------- lib/glcomp/glcomp.vcproj | 24 +- lib/glcomp/glcompbutton.c | 2 +- lib/glcomp/glcompdefs.h | 55 +-- lib/glcomp/glcomplabel.c | 2 +- lib/glcomp/glcompset.h | 4 +- plugin/gdiplus/gvplugin_gdiplus.h | 7 + plugin/gdiplus/gvrender_gdiplus.cpp | 46 ++- 20 files changed, 320 insertions(+), 713 deletions(-) diff --git a/cmd/smyrna/draw.c b/cmd/smyrna/draw.c index 51116e480..e991333aa 100755 --- a/cmd/smyrna/draw.c +++ b/cmd/smyrna/draw.c @@ -476,10 +476,10 @@ static void EmbedText(xdot_op * op, int param) x = (GLfloat) op->u.text.x + op->u.text.width; fontSize(view->fontset->fonts[view->fontset->activefont],view->FontSize); if (param == 0) - fontColor(view->fontset->fonts[view->fontset->activefont],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,1); if (param == 1) //selected fontColor(view->fontset->fonts[view->fontset->activefont],view->selectedNodeColor.R, view->selectedNodeColor.G, - view->selectedNodeColor.B); + view->selectedNodeColor.B,1); fontDrawString(view->fontset->fonts[view->fontset->activefont], (x - dx), (GLfloat)op->u.text.y - dy, (GLfloat)op->u.text.width, op->u.text.text); } diff --git a/cmd/smyrna/glexpose.c b/cmd/smyrna/glexpose.c index 43439e750..ea63cdcb5 100644 --- a/cmd/smyrna/glexpose.c +++ b/cmd/smyrna/glexpose.c @@ -102,6 +102,7 @@ int glexpose_main(ViewInfo * view) draw_selection_box(view); drawBorders(view); drawRotatingTools(); + // drawtestpoly(); /*DEBUG*/ /* if (view->mouse.mouse_mode == MM_PAN) @@ -183,6 +184,9 @@ int glexpose_drawgraph(ViewInfo * view) drawtopologicalfisheye(view->Topview); } glCompSetDraw(view->Topview->topviewmenu); +// OtkUpdateCheck(); + // OtkDisplayFunct(); + } else drawGraph(view->g[view->activeGraph]); //xdot based drawing functions diff --git a/cmd/smyrna/gltemplate.c b/cmd/smyrna/gltemplate.c index b5dd952e9..89faaf3d1 100755 --- a/cmd/smyrna/gltemplate.c +++ b/cmd/smyrna/gltemplate.c @@ -137,7 +137,6 @@ static void realize(GtkWidget * widget, gpointer data) #else smyrna_font = smyrnaPath("arial.tga"); #endif -// g_print("loading font....%i\n", fontLoad(smyrna_font)); add_font(view->fontset,"Times 14");//wired in default font /*** OpenGL BEGIN ***/ diff --git a/cmd/smyrna/gui/menucallbacks.c b/cmd/smyrna/gui/menucallbacks.c index d4bb72f8d..6ec572671 100755 --- a/cmd/smyrna/gui/menucallbacks.c +++ b/cmd/smyrna/gui/menucallbacks.c @@ -140,10 +140,15 @@ void mTopviewSettingsSlot(GtkWidget * widget, gpointer user_data) void mShowToolBoxSlot(GtkWidget * widget, gpointer user_data) { - gtk_widget_hide(glade_xml_get_widget(xml, "frmToolBox")); - gtk_widget_show(glade_xml_get_widget(xml, "frmToolBox")); + gtk_widget_hide(glade_xml_get_widget(xml, "gtkglwindow")); + gtk_widget_show(glade_xml_get_widget(xml, "gtkglwindow")); gtk_window_set_keep_above((GtkWindow *) - glade_xml_get_widget(xml, "frmToolBox"), 1); + glade_xml_get_widget(xml, "gtkglwindow"), 1); + +if(!gtk_widget_set_gl_capability (glade_xml_get_widget(xml, "glfixed"), configure_gl(),gtk_widget_get_gl_context(view->drawing_area),0,0)) + printf("glwidget creation failed \n"); + + } diff --git a/cmd/smyrna/main.c b/cmd/smyrna/main.c index 1803a0d82..ba37f5712 100755 --- a/cmd/smyrna/main.c +++ b/cmd/smyrna/main.c @@ -22,7 +22,9 @@ #if defined(_WIN32) && !defined(__CYGWIN__) #define WIN32_LEAN_AND_MEAN 1 #include +#include #endif +#include "otk_lib.h" #include #include #include @@ -116,7 +118,7 @@ int main(int argc, char *argv[]) GdkGLConfig *glconfig; char* initFileName; - smyrnaDir = getenv ("SMYRNA_PATH"); + smyrnaDir = getenv ("SMYRNA_PATH"); #ifndef _WIN32 if (!smyrnaDir) smyrnaDir = SMYRNA_PATH; diff --git a/cmd/smyrna/smyrna.vcproj b/cmd/smyrna/smyrna.vcproj index afe8e7d43..d474b9567 100644 --- a/cmd/smyrna/smyrna.vcproj +++ b/cmd/smyrna/smyrna.vcproj @@ -40,13 +40,13 @@ Name="VCCLCompilerTool" AdditionalOptions="/D "_CRT_SECURE_NO_DEPRECATE"" Optimization="0" - AdditionalIncludeDirectories=""$(SolutionDir)/lib/gvc";"C:\gtk\include\libglade-2.0";"$(SolutionDir)/lib/neatogen";"$(SolutionDir)/lib/sparse";"$(SolutionDir)/lib/topfish";"C:\gtk\lib\gtkglext-1.0\include";"C:\gtk\include\gtkglext-1.0\";C:\gtk\include\cairo;"C:\gtk\include\atk-1.0";"C:\gtk\lib\gtk-2.0\include\cairo";"C:\gtk\lib\gtk-2.0\include";"C:\gtk\include\gtk-2.0\";"$(SolutionDir)/cmd/smyrna/gui";"$(SolutionDir)/cmd/smyrna";"$(SolutionDir)";"$(SolutionDir)/lib/glcomp";"C:\gtk\lib\glib-2.0\include";"C:\gtk\include\glib-2.0";"C:\gtk\include\pango-1.0\";C:\gtk\include;"$(SolutionDir)/lib/common";"$(SolutionDir)/lib/cdt";"$(SolutionDir)/lib/cgraph";"$(SolutionDir)/windows\lib\ingraphs";"$(SolutionDir)/lib/xdot"" + AdditionalIncludeDirectories=""C:\graphviz-ms\graphviz2\lib\windirent";"$(SolutionDir)/lib/gvc";"C:\gtk\include\libglade-2.0";"$(SolutionDir)/lib/neatogen";"$(SolutionDir)/lib/sparse";"$(SolutionDir)/lib/topfish";"C:\gtk\lib\gtkglext-1.0\include";"C:\gtk\include\gtkglext-1.0\";C:\gtk\include\cairo;"C:\gtk\include\atk-1.0";"C:\gtk\lib\gtk-2.0\include\cairo";"C:\gtk\lib\gtk-2.0\include";"C:\gtk\include\gtk-2.0\";"$(SolutionDir)/cmd/smyrna/gui";"$(SolutionDir)/cmd/smyrna";"$(SolutionDir)";"$(SolutionDir)/lib/glcomp";"C:\gtk\lib\glib-2.0\include";"C:\gtk\include\glib-2.0";"C:\gtk\include\pango-1.0\";C:\gtk\include;"$(SolutionDir)/lib/common";"$(SolutionDir)/lib/cdt";"$(SolutionDir)/lib/cgraph";"$(SolutionDir)/windows\lib\ingraphs";"$(SolutionDir)/lib/xdot";"$(SolutionDir)/lib/otk_lib"" PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;HAVE_TRIANGLE;HAVE_CONFIG_H;HAVE_GTS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE" MinimalRebuild="true" BasicRuntimeChecks="3" RuntimeLibrary="3" UsePrecompiledHeader="0" - WarningLevel="3" + WarningLevel="0" Detect64BitPortabilityProblems="true" DebugInformationFormat="4" DisableSpecificWarnings="4995;4996" @@ -62,7 +62,7 @@ /> +#include "color.h" + static int get_temp_coords(topview* t,int level,int v,double* coord_x,double* coord_y); static int get_temp_coords2(topview* t,int level,int v,double* coord_x,double* coord_y,float *R,float *G,float *B); static int FLUSH=0; + +static void color_interpolation(glCompColor srcColor,glCompColor tarColor,glCompColor* color,int levelcount,int level) +{ + if (levelcount <=0) + return; + + + color->R=((float)level*tarColor.R-(float)level*srcColor.R+(float)levelcount*srcColor.R) / + (float)levelcount; + color->G=((float)level*tarColor.G-(float)level*srcColor.G+(float)levelcount*srcColor.G) / + (float)levelcount; + color->B=((float)level*tarColor.B-(float)level*srcColor.B+(float)levelcount*srcColor.B) / + (float)levelcount; +} + static double dist(double x1, double y1, double x2, double y2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); @@ -52,6 +67,7 @@ static double G(double x) 1) * x / (view->fmg.fisheye_distortion_fac * x + 1); } + void fisheye_polar(double x_focus, double y_focus, topview * t) { int i; @@ -230,6 +246,7 @@ void prepare_topological_fisheye(topview* t) Hierarchy *hp; ex_vtx_data *gg; topview_node *np; + gvcolor_t cl; v_data *graph = makeGraph(t, &ne); @@ -258,6 +275,20 @@ void prepare_topological_fisheye(topview* t) view->Topview->parms.repos.height =(int) (view->bdyTop-view->bdyBottom); view->Topview->parms.repos.rescale=Polar; + //topological fisheye + + colorxlate(get_attribute_value("topologicalfisheyefinestcolor", view, view->g[view->activeGraph]), &cl, + RGBA_DOUBLE); + view->Topview->srcColor.R = (float) cl.u.RGBA[0]; + view->Topview->srcColor.G = (float) cl.u.RGBA[1]; + view->Topview->srcColor.B = (float) cl.u.RGBA[2]; + colorxlate(get_attribute_value("topologicalfisheyecoarsestcolor", view, view->g[view->activeGraph]), &cl, + RGBA_DOUBLE); + view->Topview->tarColor.R = (float) cl.u.RGBA[0]; + view->Topview->tarColor.G = (float) cl.u.RGBA[1]; + view->Topview->tarColor.B = (float) cl.u.RGBA[2]; + + sscanf(agget(view->g[0],"topologicalfisheyedistortionfactor"),"%lf",&view->Topview->parms.repos.distortion); sscanf(agget(view->g[0],"topologicalfisheyefinenodes"),"%d",&view->Topview->parms.level.num_fine_nodes); sscanf(agget(view->g[0],"topologicalfisheyecoarseningfactor"),"%lf",&view->Topview->parms.level.coarsening_rate); @@ -301,9 +332,19 @@ void printalllevels(topview* t) void drawtopfishnodes(topview * t) { - int level, v; + glCompColor srcColor; + glCompColor tarColor; + glCompColor color; + int level, v; Hierarchy *hp = t->h; - + static max_visible_level=0; + srcColor.R=view->Topview->srcColor.R; + srcColor.G=view->Topview->srcColor.G; + srcColor.B=view->Topview->srcColor.B; + tarColor.R=view->Topview->tarColor.R; + tarColor.G=view->Topview->tarColor.G; + tarColor.B=view->Topview->tarColor.B; + glEnable(GL_POINT_SMOOTH); /*turn this off to make points look square*/ //draw focused node little bigger than others @@ -331,12 +372,17 @@ void drawtopfishnodes(topview * t) && (-y0 / view->zoom < view->clipY2)))) continue; - if (level !=0) - glColor4f((GLfloat) (hp->nlevels - level)*(GLfloat)0.5 / (GLfloat) hp->nlevels, - (GLfloat) level / (GLfloat) hp->nlevels, (GLfloat)0,(GLfloat)view->defaultnodealpha); - else - glColor4f((GLfloat) 1, - (GLfloat) level / (GLfloat) hp->nlevels*2, 0,view->defaultnodealpha); +// if (level !=0) +// glColor4f((GLfloat) (hp->nlevels - level)*(GLfloat)0.5 / (GLfloat) hp->nlevels, +// (GLfloat) level / (GLfloat) hp->nlevels, (GLfloat)0,(GLfloat)view->defaultnodealpha); + // else +// glColor4f((GLfloat) 1, +// (GLfloat) level / (GLfloat) hp->nlevels*2, 0,view->defaultnodealpha); + + if (max_visible_level < level) + max_visible_level=level; + color_interpolation(srcColor,tarColor,&color,max_visible_level,level); + glColor4f(color.R,color.G,color.B,(GLfloat)view->defaultnodealpha); /* glColor3f((GLfloat) (hp->nlevels - level)*0.5 / (GLfloat) hp->nlevels, (GLfloat) level / (GLfloat) hp->nlevels, 0);*/ @@ -375,14 +421,14 @@ void drawtopfishnodelabels(topview* t) if((v==t->fs->foci_nodes[0]) &&(focusnodes)) { fs=view->FontSizeConst*(float)1.4; - fontColorA(view->fontset->fonts[view->fontset->activefont],(float)0, (float)0, (float)1, (float)1); + fontColor(view->fontset->fonts[view->fontset->activefont],(float)0, (float)0, (float)1, (float)1); fontSize(view->fontset->fonts[view->fontset->activefont],fs); fontDrawString(view->fontset->fonts[view->fontset->activefont],gg[v].physical_x_coord,gg[v].physical_y_coord, (fs*strlen(buf)*(GLfloat)0.4),buf); } else if (finenodes) { - fs=view->FontSizeConst; - fontColorA(view->fontset->fonts[view->fontset->activefont],0, 0, 0, 1); + fs=view->FontSizeConst*1.2; + fontColor(view->fontset->fonts[view->fontset->activefont],0, 0, 0, 1); fontSize(view->fontset->fonts[view->fontset->activefont],fs); fontDrawString(view->fontset->fonts[view->fontset->activefont],gg[v].physical_x_coord,gg[v].physical_y_coord, (fs*strlen(buf)*(GLfloat)0.4),buf); } @@ -394,8 +440,20 @@ void drawtopfishnodelabels(topview* t) } void drawtopfishedges(topview * t) { - int level, v, i, n; + glCompColor srcColor; + glCompColor tarColor; + glCompColor color; + + int level, v, i, n; Hierarchy *hp = t->h; + static max_visible_level=0; + srcColor.R=view->Topview->srcColor.R; + srcColor.G=view->Topview->srcColor.G; + srcColor.B=view->Topview->srcColor.B; + tarColor.R=view->Topview->tarColor.R; + tarColor.G=view->Topview->tarColor.G; + tarColor.B=view->Topview->tarColor.B; + //and edges glBegin(GL_LINES); for (level = 0; level < hp->nlevels; level++) @@ -411,12 +469,14 @@ void drawtopfishedges(topview * t) { double x, y; n = g[v].edges[i]; - if (level !=0) - glColor4f((GLfloat) (hp->nlevels - level)*(GLfloat)0.5 / (GLfloat) hp->nlevels, - (GLfloat) level / (GLfloat) hp->nlevels, 0,view->defaultedgealpha); - else - glColor4f((GLfloat) 1, - (GLfloat) level / (GLfloat) hp->nlevels*2, 0,view->defaultedgealpha); + + + if (max_visible_level < level) + max_visible_level=level; + color_interpolation(srcColor,tarColor,&color,max_visible_level,level); + glColor4f(color.R,color.G,color.B,(GLfloat)view->defaultnodealpha); + + if (get_temp_coords(t,level,n,&x,&y)) { glVertex3f((GLfloat) x0, (GLfloat) y0,(GLfloat) 0); @@ -573,6 +633,7 @@ void changetopfishfocus(topview * t, float *x, float *y, float *z, int num_foci) { + gvcolor_t cl; focus_t *fs = t->fs; int i; int closest_fine_node; @@ -594,6 +655,19 @@ void changetopfishfocus(topview * t, float *x, float *y, view->Topview->parms.repos.width =(int) (view->bdxRight-view->bdxLeft); view->Topview->parms.repos.height =(int) (view->bdyTop-view->bdyBottom); + colorxlate(get_attribute_value("topologicalfisheyefinestcolor", view, view->g[view->activeGraph]), &cl, + RGBA_DOUBLE); + view->Topview->srcColor.R = (float) cl.u.RGBA[0]; + view->Topview->srcColor.G = (float) cl.u.RGBA[1]; + view->Topview->srcColor.B = (float) cl.u.RGBA[2]; + colorxlate(get_attribute_value("topologicalfisheyecoarsestcolor", view, view->g[view->activeGraph]), &cl, + RGBA_DOUBLE); + view->Topview->tarColor.R = (float) cl.u.RGBA[0]; + view->Topview->tarColor.G = (float) cl.u.RGBA[1]; + view->Topview->tarColor.B = (float) cl.u.RGBA[2]; + + + sscanf(agget(view->g[0],"topologicalfisheyedistortionfactor"),"%lf",&view->Topview->parms.repos.distortion); sscanf(agget(view->g[0],"topologicalfisheyefinenodes"),"%d",&view->Topview->parms.level.num_fine_nodes); sscanf(agget(view->g[0],"topologicalfisheyecoarseningfactor"),"%lf",&view->Topview->parms.level.coarsening_rate); @@ -602,6 +676,7 @@ void changetopfishfocus(topview * t, float *x, float *y, + set_active_levels(hp, fs->foci_nodes, fs->num_foci, &(t->parms.level)); @@ -726,4 +801,3 @@ void drawtopologicalfisheyestatic(topview * t) glEnd();*/ } - diff --git a/cmd/smyrna/topview.c b/cmd/smyrna/topview.c index 8480b23be..45b2a5947 100755 --- a/cmd/smyrna/topview.c +++ b/cmd/smyrna/topview.c @@ -14,9 +14,7 @@ * AT&T Research, Florham Park NJ * **********************************************************/ #include "glTexFont.h" -#include "glTexFontTGA.h" -#include "glTexFontDefs.h" -#include "glTexFontInclude.h" +#include "glcomptextpng.h" #include "glcompbutton.h" #include "glcomppanel.h" #include "glcomplabel.h" @@ -37,6 +35,9 @@ #else #include "regex.h" #endif +#include "otk_lib.h" + + static float dx = 0.0; static float dy = 0.0; @@ -55,6 +56,7 @@ static int get_color_from_edge(topview_edge * e); static int draw_node_hint_boxes(void); static int pick_node(topview_node * n); + void cleartopview(topview * t) { /*clear nodes */ @@ -81,6 +83,13 @@ void preparetopview(Agraph_t * g, topview * t) int maxlabelsize=0; float maxedgelen,minedgelen,len,edgelength; + +// OtkInitWindow( 700, 500, NULL, NULL ); +// OtkMakeButton( OtkOuterWindow, 10.0, 10.0, 80.0, 80.0, "Hello World !", 0, 0 ); +// OtkMainLoop(); + + + maxedgelen=0; minedgelen=(float)99999999.00000; //FIX ME if you have a giant graph or fix your graph edgelength=0; @@ -641,7 +650,7 @@ static int draw_node_hint_boxes(void) ) ; fontSize(view->fontset->fonts[view->fontset->activefont],fs); - fontColorA(view->fontset->fonts[view->fontset->activefont],0, 0, 1, 1); + fontColor(view->fontset->fonts[view->fontset->activefont],0, 0, 1, 1); fontDrawString( @@ -858,7 +867,8 @@ static int draw_topview_label(topview_node * v, float zdepth) && (v->distorted_y / view->zoom * -1 < view->clipY2)) { fs=calculate_font_size(v); - + if (v->degree==0) + printf("haha\n"); /* fs = (v->degree ==1) ? @@ -866,9 +876,11 @@ static int draw_topview_label(topview_node * v, float zdepth) : (float) (log((double) v->degree +(double) 0.5) *(double) 3)*14;*/ - fs =(float) (log((double) v->degree +(double) 0.5) *(double) 3)*14; + fs =(float) (log((double) v->degree +(double) 0.7) *(double) 3)*14; // fs=view->FontSize; fs = fs * v->zoom_factor; + if (v->degree < 3) + fs=fs*2; if (OD_Selected(v->Node) == 1) { ddx = dx; ddy = dy; @@ -877,21 +889,22 @@ static int draw_topview_label(topview_node * v, float zdepth) return 0; // fs= 10; - fs= fs * (float)0.2; + fs= fs * (float)0.182; fontSize(view->fontset->fonts[view->fontset->activefont],fs); if ((log((float) v->degree) * -0.6 * view->zoom) > 0) - fontColorA(view->fontset->fonts[view->fontset->activefont],(float) log((double) v->degree + (double) 1), + fontColor(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.4 * (float) view->zoom); else - fontColorA(view->fontset->fonts[view->fontset->activefont],(float) log((double) v->degree + (double) 1), + fontColor(view->fontset->fonts[view->fontset->activefont],(float) log((double) v->degree + (double) 1), view->penColor.G, view->penColor.B, (float)0.7); -// fontColorA(0,0,0,1); + fontColor(view->fontset->fonts[view->fontset->activefont],0,0,0,view->penColor.A / (float) log((double) v->degree) * + (float) -0.4 * (float) view->zoom); fontDrawString(view->fontset->fonts[view->fontset->activefont],(v->distorted_x - ddx), (v->distorted_y - ddy), (fs * strlen(v->Label)*(float)0.6),v->Label ); diff --git a/cmd/smyrna/viewport.c b/cmd/smyrna/viewport.c index aa3d989b2..92a0c96c7 100755 --- a/cmd/smyrna/viewport.c +++ b/cmd/smyrna/viewport.c @@ -70,7 +70,7 @@ void clear_viewport(ViewInfo * view) free(view); } -static char *get_attribute_value(char *attr, ViewInfo * view, Agraph_t * g) +char *get_attribute_value(char *attr, ViewInfo * view, Agraph_t * g) { char *buf; buf = agget(g, attr); diff --git a/graphviz.sln b/graphviz.sln index fc653bf6e..1bde76cf7 100644 --- a/graphviz.sln +++ b/graphviz.sln @@ -184,8 +184,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libpng", "lib\libpng\1.2.24 EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gvplugin_gdiplus", "plugin\gdiplus\gvplugin_gdiplus.vcproj", "{0F4D5D8F-F4D6-4A5D-97E0-9B482257F493}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "otk", "lib\otk_lib\otk.vcproj", "{343EB043-1F93-4F40-989D-FA309E4668AF}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -396,10 +394,6 @@ Global {0F4D5D8F-F4D6-4A5D-97E0-9B482257F493}.Debug|Win32.Build.0 = Debug|Win32 {0F4D5D8F-F4D6-4A5D-97E0-9B482257F493}.Release|Win32.ActiveCfg = Release|Win32 {0F4D5D8F-F4D6-4A5D-97E0-9B482257F493}.Release|Win32.Build.0 = Release|Win32 - {343EB043-1F93-4F40-989D-FA309E4668AF}.Debug|Win32.ActiveCfg = Debug|Win32 - {343EB043-1F93-4F40-989D-FA309E4668AF}.Debug|Win32.Build.0 = Debug|Win32 - {343EB043-1F93-4F40-989D-FA309E4668AF}.Release|Win32.ActiveCfg = Release|Win32 - {343EB043-1F93-4F40-989D-FA309E4668AF}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/lib/glcomp/glTexFont.c b/lib/glcomp/glTexFont.c index d3df30643..1c51218c0 100755 --- a/lib/glcomp/glTexFont.c +++ b/lib/glcomp/glTexFont.c @@ -1,324 +1,45 @@ -/* vim:set shiftwidth=4 ts=8: */ -/* - glTexFont Library R6 - - Copyright (c) 1999 Nate Miller - - Notice: Usage of any code in this file is subject to the rules - described in the LICENSE.TXT file included in this directory. - Reading, compiling, or otherwise using this code constitutes - automatic acceptance of the rules in said text file. - - File -- glTexFont.c - Date -- 5/30/99 - Author -- Nate 'm|d' Miller - Contact -- vandals1@home.com - Web -- http://members.home.com/vandals1 -*/ -//#define FONT_LIB_DEBUG /* un-comment for debug regions */ #include "glTexFont.h" -#include "glTexFontTGA.h" -#include "glTexFontDefs.h" -#include "glTexFontInclude.h" #include "glpangofont.h" #include "memory.h" -/* just a global for our default colors */ -float white[] = {1.0, 1.0, 1.0, 1.0}; -float gray[] = {0.5, 0.5, 0.5, 1.0}; - - -/* - tPoints contains our map for the font image. After fontMakeMap this array - will contain all the information to get the proper key from the font map. -*/ vec2_t tPoints[257]; -/* -============= -fontLoad - -Load the passed image name and use it for the font. -============= -*/ -int fontLoad (texFont_t* font,char *name) -{ - glGenTextures (1, &(font->texId)); - - font->blockRow = FONT_BLOCK_ROW; - font->blockCol = FONT_BLOCK_COL; - - fontMakeMap (font); - -// return fontLoadTGA (name, font.texId); - return fontLoadPNG ("c:\\pango_test.png", font->texId); -} -/* -============= -fontLoadEx - -Loads the passed image which has 'col' characters per column and 'row' -characters per row. -============= -*/ -int fontLoadEx (texFont_t* font,char *name, int row, int col) +int glCompLoadFont (glCompText* font,char *name) { - /* make sure we have valid dimensions */ -/* if (row * col != 256) - return 0;*/ - glGenTextures (1, &(font->texId)); - - font->blockRow = row; - font->blockCol = col; - fontMakeMap (font); + return glCompLoadFontPNG ("c:\\pango_test.png", font->texId); - return fontLoadTGA (name, font->texId); } -/* -============= -fontDrawChar - -Draws a character that is 'size' pixels in w and h. -============= -*/ -void fontDrawChar (texFont_t* font,char c, GLfloat x, GLfloat y, GLfloat size, int shadow) -{ - if (!font->gradient && !shadow) - glColor4fv (font->fgColor); - else if (!font->gradient && shadow) - glColor4fv (font->bgColor); - else if (font->gradient && !shadow) - glColor4fv (font->gdColor); - - glBegin (GL_QUADS); - glTexCoord2f (tPoints[(int)c][0], tPoints[(int)c][1]); - glVertex3f (x, y,0); - glTexCoord2f (tPoints[(int)c][0] + font->tIncX, tPoints[(int)c][1]); - glVertex3f (x + size, y,0); - - if (!shadow) - glColor4fv (font->fgColor); - else glColor4fv (font->bgColor); - - glTexCoord2f (tPoints[(int)c][0] + font->tIncX, tPoints[(int)c][1] + font->tIncY); - glVertex3f (x + size + font->italic, y + size,0); - glTexCoord2f (tPoints[(int)c][0], tPoints[(int)c][1] + font->tIncY); - glVertex3f (x + font->italic, y + size,0); - glEnd (); -} -/* -============= -fontScissorNormal - -Normal scissor region for text rendering. -============= -*/ -void fontScissorNormal (texFont_t* font,int xpos, int ypos, int tabs, int carrage, int size, int len) +void fontForeColorReset (glCompText* font) { - int sy; - int ex; - int ey; - - ex = len * size * tabs; - - if (carrage) - { - sy = ypos - (size * carrage); - ey = size * (carrage + 1); - } else { - sy = ypos; - ey = size; - } - glScissor (xpos, sy, ex, ey); -} -/* -============= -============= -fontFgColorReset - -Resets the font color. -============= -*/ -void fontForeColorReset (texFont_t* font) -{ - fontColorCopy (white, font->fgColor); -} -/* -============= -fontBgColorReset + font->color.R=1.00; + font->color.G=1.00; + font->color.B=1.00; + font->color.A=1.00; -Resets the shadow color. -============= -*/ -void fontShadowColorReset (texFont_t* font) -{ - fontColorCopy (gray, font->bgColor); -} -/* -============= -fontGdColorReset -Resets the gradient color. -============= -*/ -void fontGradientColorReset (texFont_t* font) -{ - fontColorCopy (gray, font->gdColor); } -/* -============= -fontReset - -Resets the font. Only resets variables that could possible change. -============= -*/ -void fontReset (texFont_t* font) +void fontReset (glCompText* font) { - font->size = 12; - font->shadow = 0; - font->region = 0; - font->gradient = 0; - font->italic = 0; - font->bold = 0; - font->regionX = 0; - font->regionY = 0; - font->regionW = 0; - font->regionH = 0; + font->fontheight = 12; fontForeColorReset (font); - fontShadowColorReset (font); - fontGradientColorReset (font); -} -/* -============= -fontRegion - -Sets up a font region. Only good for one fontDrawString. -============= -*/ -void fontRegion (texFont_t* font,float x, float y, float w, float h) -{ - font->region = 1; - font->regionX = x; - font->regionY = y - h; - font->regionW = w; - font->regionH = h; } -/* -============= -fontSize - -Sets the font size. -============= -*/ -void fontSize (texFont_t* font,GLfloat size) +void fontSize (glCompText* font,GLfloat size) { - font->size = size; + font->fontheight = size; } -void fontzdepth(texFont_t* font,GLfloat zdepth) +void fontzdepth(glCompText* font,GLfloat zdepth) { font->zdepth=zdepth; } -/* -============= -fontShadow - -Draws a shadow if called. -============= -*/ -void fontShadow (texFont_t* font) -{ - font->shadow = 1; -} -/* -============= -fontGradient - -Draws gradient text if called. -============= -*/ -void fontGradient (texFont_t* font) -{ - font->gradient = 1; -} -/* -============= -fontRenderChar - -Draws a character to the screen -Bold is just a hack, nothing special -============= -*/ -void fontRenderChar (texFont_t* font,char c, GLfloat x, GLfloat y, GLfloat size) -{ - if (font->shadow) - { - if (!font->bold) - fontDrawChar (font,c, x + (GLfloat)1.0, y + (GLfloat)1.0, size, 1); - else fontDrawChar (font,c, x + (GLfloat)2.0, y + (GLfloat)1.0, size, 1); - } - - - - fontDrawChar (font,c, x, y, size, 0); - - if (font->bold) - fontDrawChar (font,c, x + (GLfloat)1.0, y, size, 0); -} -/* -============= -fontSlashParser - -Handles all the fun that comes with a \\, returns amount to advance string. -After this funtion *buffptr ++ will be the next character to draw or parse. -============= -*/ -int fontSlashParser (texFont_t* font,char *buffPtr, GLfloat *x, GLfloat *y) -{ - int ret = 0; - - *buffPtr ++; - - if (!*buffPtr) - return ret; - - switch (*buffPtr) - { - case 'a': - case 'c': - *x -= font->size; - return fontSetColorFromToken (font,buffPtr); - break; - case 'i': - *x -= font->size; - return fontItalicsMode (font,buffPtr); - break; - case 'b': - *x -= font->size; - return fontBoldMode (font,buffPtr); - break; - default: - *buffPtr --; - fontRenderChar (font,*buffPtr, *x, *y, font->size); - return ret; - break; - } -} -/* -============= -fontWalkString - -Does the actual rendering of our string. -============= -*/ -void fontWalkString (texFont_t* font,char *buffPtr, GLfloat xpos, GLfloat ypos, int *vPort,float width) +void fontWalkString (glCompText* font,char *bf, GLfloat xpos, GLfloat ypos, int *vPort,float width) { - GLfloat size = font->size; + GLfloat size = font->fontheight; GLfloat x = xpos; GLfloat y = ypos; GLfloat carrage = 0; @@ -330,30 +51,16 @@ void fontWalkString (texFont_t* font,char *buffPtr, GLfloat xpos, GLfloat ypos, GLfloat charGap; xMax = vPort[0] + vPort[2]; - carrage = (GLfloat) fontGetCharHits (buffPtr, '\n'); - tabs = (GLfloat) fontGetCharHits (buffPtr, '\t'); + carrage = (GLfloat) fontGetCharHits (bf, '\n'); + tabs = (GLfloat) fontGetCharHits (bf, '\t'); if (!tabs) tabs = 1; else tabs *= FONT_TAB_SPACE; - -/* if (font.region) - { - fontScissorTextRegion (); - x = font.regionX; - y = (font.regionY + font.regionH) - font.size; - } else - fontScissorNormal (xpos, ypos, tabs, carrage, font.size, len); */ - -#ifdef FONT_LIB_DEBUG - glClearColor (1,0,1,1); - glClear (GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); -#endif - /* lets draw! */ //width for each char should be calculated , we need the max line length of the paragraph - tempC=buffPtr; + tempC=bf; charCount=0; maxcharCount=0; @@ -380,52 +87,24 @@ void fontWalkString (texFont_t* font,char *buffPtr, GLfloat xpos, GLfloat ypos, charGap=(width / (float)maxcharCount); - for ( ; *buffPtr; *buffPtr ++, x += charGap) //size*0.7 is the distance between2 characters + for ( ; *bf; *bf ++, x += charGap) //size*0.7 is the distance between2 characters { - // if (x > xMax) - // break; - /* if (font.region) - { - if (x + size > (font.regionX + font.regionW)) - { - y -= size; - x = font.regionX; - } - if (y < font.regionY) - break; - }*/ + glBegin (GL_QUADS); + glTexCoord2f (tPoints[(int)(*bf)][0], tPoints[(int)(*bf)][1]); + glVertex3f (x, y,0); + glTexCoord2f (tPoints[(int)(*bf)][0] + font->tIncX, tPoints[(int)(*bf)][1]); + glVertex3f (x + size, y,0); -/* - if(*buffPtr==' ') //SPACE - x = x + size;*/ + glColor4f (font->color.R,font->color.G,font->color.B,font->color.A); - switch (*buffPtr) - { + glTexCoord2f (tPoints[(int)(*bf)][0] + font->tIncX, tPoints[(int)(*bf)][1] + font->tIncY); + glVertex3f (x + size, y + size,0); - - case '\n': - y -= size; - x = xpos - size; - continue; - break; - case '\t': - x += (size * FONT_TAB_SPACE); - continue; - break; - case '\\': - buffPtr += fontSlashParser (font,buffPtr, &x, &y); - if (*buffPtr == '\n' || *buffPtr == '\t') - { - buffPtr -= 1; - continue; - } - break; - default : - fontRenderChar (font,*buffPtr, x, y, size); - break; - } + glTexCoord2f (tPoints[(int)(*bf)][0], tPoints[(int)(*bf)][1] + font->tIncY); + glVertex3f (x , y + size,0); + glEnd (); } } /* @@ -436,21 +115,10 @@ Renders a string at xpos, ypos. ============= */ void -fontDrawString (texFont_t* font, GLfloat xpos, GLfloat ypos, - GLfloat width, char *s, ...) +fontDrawString (glCompText* font, GLfloat xpos, GLfloat ypos, + GLfloat width, char *s) { - va_list msg; - char buffer[FONT_MAX_LEN] = {'\0'}; int vPort[4]; - - va_start (msg, s); -#ifdef _WIN32 - _vsntprintf (buffer, FONT_MAX_LEN - 1, s, msg); -#else /* not Windows */ - vsnprintf (buffer, FONT_MAX_LEN - 1, s, msg); -#endif - va_end (msg); - /* get current viewport */ glGetIntegerv (GL_VIEWPORT, vPort); /* setup various opengl things that we need */ @@ -471,7 +139,7 @@ fontDrawString (texFont_t* font, GLfloat xpos, GLfloat ypos, /* draw the string */ - fontWalkString (font,buffer, xpos, ypos, vPort,(float)width); + fontWalkString (font,s, xpos, ypos, vPort,(float)width); /* glMatrixMode (GL_PROJECTION); glPopMatrix (); @@ -483,75 +151,6 @@ fontDrawString (texFont_t* font, GLfloat xpos, GLfloat ypos, } /* ============= -fontSetColorFromToken - -Grabs a color token from a buffer and sets color. -============= -*/ -int fontSetColorFromToken (texFont_t* font,char *s) -{ - int clr[4]; - int ret = 1; - - if (*s == 'c') - { - s += 1; - if (sscanf (s, "(%d %d %d)", &clr[0], &clr[1], &clr[2]) != 3) - return -1; - fontColor (font,clr[0] * FONT_ITOF, clr[1] * FONT_ITOF, clr[2] * FONT_ITOF); - } else if (*s == 'a') - { - s += 1; - if (sscanf (s, "(%d %d %d %d)", &clr[0], &clr[1], &clr[2], &clr[3]) != 4) - return -1; - fontColorA (font,clr[0] * FONT_ITOF, clr[1] * FONT_ITOF, clr[2] * FONT_ITOF, clr[3] * FONT_ITOF); - } - - while (*s != ')' && ret ++) - s += 1; - - return ret + 1; -} -/* -============= -fontItalicsMode - -Either turns on or off italics. -============= -*/ -int fontItalicsMode (texFont_t* font,char *s) -{ - s += 1; - - if (*s == '+') - font->italic = FONT_ITALIC; - else if (*s == '-') - font->italic = 0; - else return -1; - - return 2; -} -/* -============= -fontBoldMode - -Either turns on or off bold. -============= -*/ -int fontBoldMode (texFont_t* font,char *s) -{ - s += 1; - - if (*s == '+') - font->bold = 1; - else if (*s == '-') - font->bold = 0; - else return -1; - - return 2; -} -/* -============= fontGetCharHits Returns number of times a character is found in a buffer. @@ -577,15 +176,15 @@ fontMakeMap Makes the font map which allows the correct characters to be drawn. ============= */ -void fontMakeMap (texFont_t* font) +void fontMakeMap (glCompText* font) { #define VCOPY(d,x,y) {d[0] = x; d[1] = y;} int i = 0; float x, y; - font->tIncX = (float)pow (font->blockCol, -1); - font->tIncY = (float)pow (font->blockRow, -1); + font->tIncX = (float)pow (C_DPI, -1); + font->tIncY = (float)pow (R_DPI, -1); for (y = 1 - font->tIncY; y >= 0; y -= font->tIncY) @@ -695,33 +294,21 @@ static int fontId(fontset_t* fontset,char* fontdesc) } return -1; } -/* - load font via font description - returns the id, - if font already exists no malloc just returns the id -*/ -texFont_t* font_init() + +glCompText* font_init() { - texFont_t* font = NEW(texFont_t); - - font->fgColor[0]=1.0;font->fgColor[1]=1.0;font->fgColor[2]=1.0;font->fgColor[3]=1.0; - font->gdColor[0]=0.5;font->gdColor[1]=0.5;font->gdColor[2]=0.5;font->gdColor[3]=1.0; - font->bgColor[0]=0.5;font->bgColor[1]=0.5;font->bgColor[2]=0.5;font->bgColor[3]=1.0; - font->size=12; - font->shadow=0; - font->gradient=0; - font->italic=0; - font->bold=0; - font->region=0; - font->regionX=0; - font->regionY=0; - font->regionW=0; - font->regionH=0; + glCompText* font = NEW(glCompText); + + font->color.R=1.00; + font->color.G=1.00; + font->color.B=1.00; + font->color.A=1.00; + + + font->fontheight=12; font->tIncX=0.0; font->tIncY=0.0; - font->blockRow=FONT_BLOCK_ROW; - font->blockCol=FONT_BLOCK_COL; font->texId=-1; font->fontdesc=(char*)0; @@ -730,34 +317,18 @@ texFont_t* font_init() return font; } -void copy_font(texFont_t* targetfont,const texFont_t* sourcefont) +void copy_font(glCompText* targetfont,const glCompText* 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->color.R=sourcefont->color.R; + targetfont->color.G=sourcefont->color.G; + targetfont->color.B=sourcefont->color.B; + targetfont->color.A=sourcefont->color.A; + + + + targetfont->fontheight=sourcefont->fontheight; 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); @@ -794,7 +365,7 @@ int add_font(fontset_t* fontset,char* fontdesc) { int id; size_t sz; - texFont_t* tf; + glCompText* tf; id=fontId(fontset,fontdesc); @@ -806,11 +377,11 @@ int add_font(fontset_t* fontset,char* fontdesc) } sprintf(fontpath,"%s/%s.png",fontset->font_directory,fontdesc); if(create_font_file(fontdesc,fontpath,(float)32,(float)32)==0) { - fontset->fonts = ALLOC(fontset->count+1,fontset->fonts,texFont_t*); + fontset->fonts = ALLOC(fontset->count+1,fontset->fonts,glCompText*); fontset->fonts[fontset->count] = tf = font_init (); tf->fontdesc = strdup(fontdesc); glGenTextures (1, &(tf->texId)); //get opengl texture name - if ((tf->texId >= 0) && fontLoadPNG (fontpath, tf->texId)) { + if ((tf->texId >= 0) && glCompLoadFontPNG (fontpath, tf->texId)) { fontset->activefont=fontset->count; fontset->count++; return fontset->count; @@ -846,3 +417,12 @@ void free_font_set(fontset_t* fontset) free(fontset); } +void fontColor (glCompText* font,float r, float g, float b,float a) +{ + + + font->color.R=r; + font->color.G=g; + font->color.B=b; + font->color.A=a; +} diff --git a/lib/glcomp/glTexFont.h b/lib/glcomp/glTexFont.h index 8d257d8f1..f666e6d10 100755 --- a/lib/glcomp/glTexFont.h +++ b/lib/glcomp/glTexFont.h @@ -1,19 +1,5 @@ -/* - Copyright (c) 1999 Nate Miller - - Notice: Usage of any code in this file is subject to the rules - described in the LICENSE.TXT file included in this directory. - Reading, compiling, or otherwise using this code constitutes - automatic acceptance of the rules in said text file. - - File -- glTexFont.h - Date -- 5/30/99 - Author -- Nate 'm|d' Miller - Contact -- vandals1@home.com - Web -- http://members.home.com/vandals1 -*/ -#ifndef __GLTEXFONTH__ -#define __GLTEXFONTH__ +#ifndef GLCOMPTEXT_H +#define GLTEXFONTH_H #include #include @@ -26,13 +12,6 @@ typedef float GLfloat; #endif #include "glcompdefs.h" -/* Error Codes */ -#define FONT_FILE_NOT_FOUND -13 /* file was not found */ -#define FONT_BAD_IMAGE_TYPE -14 /* color mapped image or image is not uncompressed */ -#define FONT_BAD_DIMENSION -15 /* dimension is not a power of 2 */ -#define FONT_BAD_BITS -16 /* image bits is not 8, 24 or 32 */ -#define FONT_BAD_DATA -17 /* image data could not be loaded */ -#define GL_TEX_FONT_VERSION 6 #ifndef vec2_t typedef float vec2_t[2]; @@ -42,112 +21,27 @@ typedef float vec2_t[2]; #ifdef __cplusplus extern "C" { #endif -/* - check if font is already loaded - if loaded returns the id - else returns -1 -*/ -/* int fontId(fontset_t* fontset,char* fontdesc); */ - -/* - Initialize fontset as an empty set -*/ - extern fontset_t* fontset_init(void); - void free_font_set(fontset_t* fontset); -void copy_font(texFont_t* targetfont,const texFont_t* sourcefont); -/* - load font via font description - returns the id, - if font already exists no malloc just returns the id -*/ +void copy_font(glCompText* targetfont,const glCompText* sourcefont); int add_font(fontset_t* fontset,char* fontdesc); - -/* -============= -fontLoad - -Loads up out font from the passed image file name. -============= -*/ -int fontLoad (texFont_t* font,char *name); -/* -============= -fontLoadEx - -Same as above but it loads a custom font map with row chars per row and col -chars per column. -============= -*/ -int fontLoadEx (texFont_t* font,char *name, int row, int col); -/* -============= -fontDrawString - -Draws a string at (xpos, ypos) in the applications window. -============= -*/ -void fontDrawString (texFont_t*, GLfloat , GLfloat , GLfloat, char*, ...); -/* -============= -fontRegion - -Sets up a font region. Upper left corner is described by (xpos, ypos). -The region is w units wide and h units tall. -============= -*/ -void fontRegion (texFont_t* font,float xpos, float ypos, float w, float h); -/* -============= -fontSize - -Sets the font size. -============= -*/ -void fontSize (texFont_t* font,GLfloat size); - - -void fontzdepth(texFont_t* font,float zdepth); - -/* -============= -fontShadow - -Draws shadowed text. -============= -*/ -void fontShadow (texFont_t* font); -/* -============= -fontGradient - -Draws gradient text. -============= -*/ -void fontGradient (texFont_t* font); -/* -============= -fontColor*, fontShadowColor*, fonrGradientColor* - - -Sets color for various operations. -============= -*/ - -texFont_t* font_init(void); -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); -void fontColorAp (texFont_t* font,float *clr); -void fontShadowColor (texFont_t* font,float r, float g, float b); -void fontShadowColorA (texFont_t* font,float r, float g, float b, float a); -void fontShadowColorp (texFont_t* font,float *clr); -void fontShadowColorAp (texFont_t* font,float *clr); -void fontGradientColor (texFont_t* font,float r, float g, float b); -void fontGradientColorA (texFont_t* font,float r, float g, float b, float a); -void fontGradientColorp (texFont_t* font,float *clr); -void fontGradientColorAp (texFont_t* font,float *clr); +int glCompLoadFont (glCompText* font,char *name); +void fontDrawString (glCompText*, GLfloat , GLfloat , GLfloat, char*); +void fontSize (glCompText* font,GLfloat size); +void fontzdepth(glCompText* font,float zdepth); +glCompText* font_init(void); +void fontColor (glCompText* font,float r, float g, float b,float a); + +void fontDrawChar (glCompText*,char, GLfloat, GLfloat, GLfloat); +void fontScissorNormal (glCompText* font,int xpos, int ypos, int tabs, int carrage, int size, int len); +int fontSetColorFromToken (glCompText* font,char *s); +int fontGetCharHits (char *s, char f); +void fontMakeMap (glCompText* font); +void fontSetModes (int state); +void fontReset (glCompText* font); +int fontItalicsMode (glCompText* font,char *s); +int fontBoldMode (glCompText* font,char *s); +void fontRenderChar (glCompText* font,char c, GLfloat x, GLfloat y, GLfloat size); #ifdef __cplusplus } #endif diff --git a/lib/glcomp/glcomp.vcproj b/lib/glcomp/glcomp.vcproj index 15f9898b0..6a0d70bc9 100644 --- a/lib/glcomp/glcomp.vcproj +++ b/lib/glcomp/glcomp.vcproj @@ -175,18 +175,6 @@ RelativePath=".\glTexFont.h" > - - - - - - @@ -219,6 +207,10 @@ RelativePath=".\glcompset.c" > + + @@ -235,14 +227,6 @@ RelativePath=".\glTexFont.c" > - - - - diff --git a/lib/glcomp/glcompbutton.c b/lib/glcomp/glcompbutton.c index 36396d169..dea3d3df8 100644 --- a/lib/glcomp/glcompbutton.c +++ b/lib/glcomp/glcompbutton.c @@ -184,7 +184,7 @@ int glCompDrawButton(glCompButton * p) p->fontsize) / (GLfloat) 2.0 + p->pos.y + p->thickness; fontSize(p->font,p->fontsize); // fontColorA (p->fontcolor.R,p->fontcolor.B,p->fontcolor.G,p->fontcolor.A); - fontColorA(p->font,0, 0, 0, 1); + fontColor(p->font,0, 0, 0, 1); fontDrawString(p->font,(GLfloat) fontx, (GLfloat) fonty, (p->fontsize *(GLfloat) strlen(p->caption) * GLCOMPSET_FONT_SIZE_FACTOR), p->caption); diff --git a/lib/glcomp/glcompdefs.h b/lib/glcomp/glcompdefs.h index 826273a7f..c38e5b0e6 100644 --- a/lib/glcomp/glcompdefs.h +++ b/lib/glcomp/glcompdefs.h @@ -1,9 +1,17 @@ #ifndef GLCOMPDEFS_H #define GLCOMPDEFS_H +#include +#include +#include +#include +#include #ifdef _WIN32 -#include "windows.h" +#include +#include +#include #endif +#include #include #include #include @@ -44,6 +52,18 @@ #define GLCOMPSET_BEVEL_DIFF (GLfloat)0.001 #define GLCOMPSET_DEFAULT_PAD (GLfloat)3 +#define FONT_GET_MODES 1 +#define FONT_RESTORE_MODES 2 +#define FONT_MAX_LEN 1024 /* maximum chars to draw to the screen, used for buffers also */ +#define FONT_TAB_SPACE 4 /* spaces to draw for a tab, make option? */ +#define FONT_ITOF (float) pow (255, -1) +#define FONT_ITALIC 8 /* italic amount in pixels */ +#define fontColorCopy(a,b) {b[0]= a[0]; b[1]= a[1]; b[2]= a[2]; b[3]= a[3];} /* copys colors */ + +#define C_DPI 16 +#define R_DPI 16 + + typedef void (*callbackfunc_t) (void *component); typedef enum { inverted_y,scientific_y} glCompOrientation; @@ -62,32 +82,21 @@ typedef struct { } glCompTexture; typedef struct { - float fgColor[4]; /* foreground color, default white */ - float gdColor[4]; /* gradient color, default gray */ - float bgColor[4]; /* background color, default gray */ - float size; /* size of text, default 12 */ - int shadow; /* shadow text? default 0 */ - int gradient; /* gradient? default 0 */ - int italic; /* italic amount, defaul 0 */ - int bold; /* bold text? */ - int region; /* do we have a text region */ - float regionX; /* lower left x */ - float regionY; /* lower left y */ - float regionW; /* text region w */ - float regionH; /* text region h */ + char* fontdesc; //font description + glCompColor color; + float fontheight; /* size of text, default 12 */ float tIncX; /* used for texture coords, x axis amount to move */ float tIncY; /* used for texture coords, y axis amount to move */ int blockRow; /* characters per row */ int blockCol; /* characters per col */ - unsigned int texId; /* texture id */ + int texId; /* texture id */ float zdepth; //third dimension , depth of fonts - char* fontdesc; //font description -} texFont_t; +} glCompText; typedef struct { - texFont_t** fonts; + glCompText** fonts; int count; int activefont; char* font_directory; //location where the glfont files are stored @@ -109,7 +118,7 @@ typedef struct _glCompPanel { int visible; void *parentset; //parent compset int data; - texFont_t* font; //pointer to font to use + glCompText* font; //pointer to font to use glCompOrientation orientation; } glCompPanel; @@ -131,7 +140,7 @@ typedef struct _glCompTrackBar { int visible; void *parentset; //parent compset int data; - texFont_t* font; //pointer to font to use + glCompText* font; //pointer to font to use glCompOrientation orientation; }glCompTrackBar; @@ -144,7 +153,7 @@ typedef struct _glCompLabel { char *text; GLfloat fontsizefactor; glCompPanel *panel; //container panel - texFont_t* font; //pointer to font to use + glCompText* font; //pointer to font to use glCompOrientation orientation; } glCompLabel; @@ -171,7 +180,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 + glCompText* font; //pointer to font to use glCompOrientation orientation; } glCompButton; @@ -187,7 +196,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 + glCompText* font; //pointer to font to use } glCompSet; #endif diff --git a/lib/glcomp/glcomplabel.c b/lib/glcomp/glcomplabel.c index af23f9fd6..ef22c0743 100644 --- a/lib/glcomp/glcomplabel.c +++ b/lib/glcomp/glcomplabel.c @@ -65,7 +65,7 @@ int glCompDrawLabel(glCompLabel * p) } fontSize(p->font, p->size); - fontColorA(p->font,p->color.R, p->color.G, p->color.B, p->color.A); + fontColor(p->font,p->color.R, p->color.G, p->color.B, p->color.A); fontDrawString(p->font, p->pos.x, p->pos.y, (p->size * p->fontsizefactor * diff --git a/lib/glcomp/glcompset.h b/lib/glcomp/glcompset.h index d9c5eb433..17166d00e 100644 --- a/lib/glcomp/glcompset.h +++ b/lib/glcomp/glcompset.h @@ -20,9 +20,7 @@ #define GLCOMPSET_H #include "glTexFont.h" -#include "glTexFontTGA.h" -#include "glTexFontDefs.h" -#include "glTexFontInclude.h" +#include "glcomptextpng.h" #include "glcomptexture.h" diff --git a/plugin/gdiplus/gvplugin_gdiplus.h b/plugin/gdiplus/gvplugin_gdiplus.h index 19eb14085..5cbf359d8 100755 --- a/plugin/gdiplus/gvplugin_gdiplus.h +++ b/plugin/gdiplus/gvplugin_gdiplus.h @@ -41,6 +41,13 @@ struct GraphicsContext static const int BYTES_PER_PIXEL = 4; /* bytes per pixel */ +#define ADD_ATTR(a) \ + if (a) { \ + strcat(buf, comma ? " " : ", "); \ + comma = 1; \ + strcat(buf, a); \ + } + extern void SaveBitmapToStream(Gdiplus::Bitmap &bitmap, IStream *stream, int format); #endif diff --git a/plugin/gdiplus/gvrender_gdiplus.cpp b/plugin/gdiplus/gvrender_gdiplus.cpp index b880abf06..a2b486c9a 100755 --- a/plugin/gdiplus/gvrender_gdiplus.cpp +++ b/plugin/gdiplus/gvrender_gdiplus.cpp @@ -34,6 +34,22 @@ extern "C" size_t gvwrite(GVJ_t *job, const unsigned char *s, unsigned int len); using namespace std; using namespace Gdiplus; + + +static char* gdiplus_psfontResolve (PostscriptAlias* pa) +{ + static char buf[1024]; + int comma=0; + strcpy(buf, pa->family); + + ADD_ATTR(pa->weight); + ADD_ATTR(pa->stretch); + ADD_ATTR(pa->style); + + return buf; +} + + /* Graphics for internal use, so that we can record image etc. for subsequent retrieval off the job struct */ struct ImageGraphics: public Graphics { @@ -186,13 +202,31 @@ static auto_ptr find_font(char *fontname, double fontsize) return auto_ptr(new Font(reference.hdc, &found_font)); } else - return auto_ptr(new Font(FontFamily::GenericSerif(), fontsize)); + { + strncpy(font_to_find.lfFaceName,"Times New Roman", sizeof(font_to_find.lfFaceName) - 1); + font_to_find.lfFaceName[sizeof(font_to_find.lfFaceName) - 1] = '\0'; + font_to_find.lfPitchAndFamily = 0; + if(EnumFontFamiliesExA(reference.hdc, + &font_to_find, + fetch_first_font, + (LPARAM)&found_font, + 0) == 0) + { + found_font.lfHeight = (LONG)-fontsize; + found_font.lfWidth = 0; + return auto_ptr(new Font(reference.hdc, &found_font)); + } + + } +// "gdiplus cannot find the default font Times New Roman." + return NULL; } static void gdiplusgen_textpara(GVJ_t *job, pointf p, textpara_t *para) { /* convert incoming UTF8 string to wide chars */ /* NOTE: conversion is 1 or more UTF8 chars to 1 wide char */ + char* fontname; int wide_count = MultiByteToWideChar(CP_UTF8, 0, para->str, -1, NULL, 0); if (wide_count > 1) { vector wide_str(wide_count); @@ -224,7 +258,15 @@ static void gdiplusgen_textpara(GVJ_t *job, pointf p, textpara_t *para) Gdiplus::Font* a=find_font(para->fontname, para->fontsize).get(); /* draw the text */ SolidBrush brush(Color(job->obj->pencolor.u.rgba [3], job->obj->pencolor.u.rgba [0], job->obj->pencolor.u.rgba [1], job->obj->pencolor.u.rgba [2])); - context->DrawString(&wide_str.front(), wide_count - 1, find_font(para->fontname, para->fontsize).get(), PointF(0, -center), &brush); + + +#ifdef HAVE_GD_FONTCONFIG + if (para->postscript_alias) + fontname = para->postscript_alias->family; + else +#endif + fontname = para->fontname; + context->DrawString(&wide_str.front(), wide_count - 1, find_font(fontname, para->fontsize).get(), PointF(0, -center), &brush); context->Restore(saved); } } -- 2.40.0