wviewweather.com Forum Index wviewweather.com
wview and Weather Topics
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Use gdImageStringFT instead of gdImageString

 
Post new topic   Reply to topic    wviewweather.com Forum Index -> Wish List
View previous topic :: View next topic  
Author Message
peder



Joined: 20 Mar 2006
Posts: 1

PostPosted: Mon Mar 20, 2006 10:48 am    Post subject: Use gdImageStringFT instead of gdImageString Reply with quote

Apparently gd uses ISO-8859-2 as its internal font charset.

This means that when I want it to print "Solinstrålning" (swedish for Radiation) it prints a lowercase L with an acute instead if "å" (as per http://www.phespirit.info/alphabet/slovak.htm).

I hacked glchart.c and glmultichart.c like this
Code:

--- glchart.c.org       2006-03-20 16:00:45.175094525 +0100
+++ glchart.c   2006-03-20 17:14:43.388789349 +0100
@@ -296,24 +296,39 @@
 
 static void drawTitle (CHART_ID id)
 {
-    gdImageFilledRectangle (id->im,
+   
+    int font_size = 8;
+    char *font_face = "/usr/X11R6/lib/X11/fonts/TTF/VeraMoBd.ttf";
+    int brect[8] ;
+   
+   gdImageFilledRectangle (id->im,
                             0, 0,
                             id->width, gdFontMediumBold->h,
                             id->titleBGcolor);
+   /* obtain brect so that we can size the image */
+   gdImageStringFT(NULL,&brect[0],0,font_face,font_size,0.0,0,0,id->title);
+   gdImageStringFT (id->im,
+                    &brect[0],
+                    id->linecolor,
+                    font_face,
+                    font_size,
+                    0.0,
+                    2 - brect[6],
+                    11,
+                    id->title);
+
+   gdImageStringFT(NULL,&brect[0],0,font_face,font_size,0.0,0,0,id->units);
+   gdImageStringFT (id->im,
+                    &brect[0],
+                    id->linecolor,
+                    font_face,
+                    font_size,
+                    0.0,
+                    id->width - brect[2] - brect[0] - 2,
+                    11,
+                    id->units);
 
-    gdImageString (id->im,
-                   gdFontMediumBold,
-                   2,
-                   0,
-                   (UCHAR *)id->title,
-                   id->linecolor);
-
-    gdImageString (id->im,
-                   gdFontMediumBold,
-                   id->width - (((gdFontMediumBold->h/2)+2) * strlen (id->units)),
-                   0,
-                   (UCHAR *)id->units,
-                   id->titleFGcolor);
 }
 
 static void drawLine (CHART_ID id)

and
Code:

--- glmultichart.c.org  2006-02-11 16:12:13.000000000 +0100
+++ glmultichart.c      2006-03-20 17:38:40.656904012 +0100
@@ -294,7 +294,12 @@
 
 static void drawTitle (MULTICHART_ID id)
 {
-    int         i, totalLen = 0;
+    int         i, totalLen = 2;
+   
+    int font_size = 8;
+    char *font_face = "/usr/X11R6/lib/X11/fonts/TTF/VeraMoBd.ttf";
+    int brect[8] ;
     
     gdImageFilledRectangle (id->im,
                             0, 0,
@@ -303,23 +308,34 @@
 
     for (i = 0; i < id->numdatasets; i ++)
     {
-        totalLen += 2;
-        gdImageString (id->im,
-                       gdFontMediumBold,
-                       totalLen,
-                       0,
-                       (UCHAR *)id->dataset[i].legend,
-                       id->dataset[i].lineColor);
+   /* obtain brect so that we can size the image */
+   gdImageStringFT(NULL,&brect[0],0,font_face,font_size,0.0,0,0,id->dataset[i].legend);
+   gdImageStringFT (id->im,
+                    &brect[0],
+                    id->dataset[i].lineColor,
+                    font_face,
+                    font_size,
+                    0.0,
+                    totalLen ,
+                    11,
+                    id->dataset[i].legend);
                       
-        totalLen += (((gdFontMediumBold->h/2)+2) * strlen (id->dataset[i].legend));
+        totalLen += (((font_size/2)+2) * strlen (id->dataset[i].legend) + 10 );
     }
-   
-    gdImageString (id->im,
-                   gdFontMediumBold,
-                   id->width - (((gdFontMediumBold->h/2)+2) * strlen (id->title)),
-                   0,
-                   (UCHAR *)id->title,
-                   id->titleFGcolor);
+
+   
+   /* obtain brect so that we can size the image */
+   gdImageStringFT(NULL,&brect[0],0,font_face,font_size,0.0,0,0,id->title);
+   gdImageStringFT (id->im,
+                    &brect[0],
+                    id->titleFGcolor,
+                    font_face,
+                    font_size,
+                    0.0,
+                    id->width - brect[2] - brect[0] - 2,
+                    11,
+                    id->title);
+   
 }
 
 static void drawLines (MULTICHART_ID id)

which works resonably well for my font and my titles but probably should be refined for general use.

- Peder
Back to top
View user's profile Send private message
Kippen



Joined: 20 Apr 2006
Posts: 8
Location: Stockholm - Sweden

PostPosted: Thu May 18, 2006 10:05 am    Post subject: Reply with quote

Thank you for this.

I also got it to work with this hack, but only on graphs and not on buckets and dials. Have you had any success with buckets and dials?

/Kippen
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    wviewweather.com Forum Index -> Wish List All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group