peder
Joined: 20 Mar 2006 Posts: 1
|
Posted: Mon Mar 20, 2006 10:48 am Post subject: Use gdImageStringFT instead of gdImageString |
|
|
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 |
|