]> git.webhop.me Git - lcd4linux.git/commitdiff
adding autosize with width, heigth and alignment
authorTangoCash <eric@loxat.de>
Fri, 6 May 2016 20:51:09 +0000 (22:51 +0200)
committerTangoCash <eric@loxat.de>
Fri, 6 May 2016 20:51:09 +0000 (22:51 +0200)
autosize:  size 0
           width 800
           height 40
           align 'C'

widget_ttf.c
widget_ttf.h

index 47438a1265b129eda1c1dcb6c0e3d4626e6ca74c..a3b9681895d69d2f0f7241dc4bc649ed7002d2a6 100644 (file)
@@ -74,14 +74,15 @@ static void widget_ttf_render(const char *Name, WIDGET_TTF * Image)
        int color;
        int trans;
        int brect[8];
+       int _width,_height;
+       int asize = 0;
        char *e;
        unsigned long l;
        unsigned char r,g,b;
        char *fcolor;
        char *text;
        double size;
-       char *font;
-       char *err;
+       char *font,*err,*align;
 
 
        /* clear bitmap */
@@ -111,11 +112,29 @@ static void widget_ttf_render(const char *Name, WIDGET_TTF * Image)
                text = P2S(&Image->value);
                font = P2S(&Image->font);
                size = P2N(&Image->size);
+               _width = P2N(&Image->_width);
+               _height = P2N(&Image->_height);
+               align = P2S(&Image->align);
 
-               err = gdImageStringFT(NULL,&brect[0],0,font,size,0.,0,0,text);
-
-               x = brect[2]-brect[6] + 6;
-               y = brect[3]-brect[7] + 6;
+               if (((_width > 0) && (_height > 0)) && (size == 0))
+               {
+                       size = _height;
+                       err = gdImageStringFT(NULL,&brect[0],0,font,size,0.,0,0,text);
+                       do
+                       {
+                               size--;
+                               err = gdImageStringFT(NULL,&brect[0],0,font,size,0.,0,0,text);
+                       }
+                       while (((brect[2]-brect[6] + 6) > _width) || ((brect[3]-brect[7] + 6) > _height));
+                       x = _width;
+                       y = _height;
+                       asize = 1;
+               } else {
+                       err = gdImageStringFT(NULL,&brect[0],0,font,size,0.,0,0,text);
+
+                       x = brect[2]-brect[6] + 6;
+                       y = brect[3]-brect[7] + 6;
+               }
                Image->gdImage = gdImageCreateTrueColor(x,y);
                gdImageSaveAlpha(Image->gdImage, 1);
 
@@ -136,7 +155,24 @@ static void widget_ttf_render(const char *Name, WIDGET_TTF * Image)
 
                color = gdImageColorAllocate(Image->gdImage, r, g, b);
 
-               x = 3 - brect[6];
+               if (((_width > 0) && (_height > 0)) && asize)
+                       switch (toupper(align[0]))
+                       {
+                               case 'R':
+                               x = _width - brect[2] - brect[6] - 3;
+                               break;
+                               case 'L':
+                               x = 3 - brect[6];
+                               break;
+                               case 'C':
+                               x = (_width - brect[2]-brect[6])/2 - brect[6];
+                               break;
+                               default:
+                               x = (_width - brect[2]-brect[6])/2 - brect[6];
+                               break;
+                       }
+               else
+                       x = 3 - brect[6];
                y = 3 - brect[7];
                err = gdImageStringFT(Image->gdImage,&brect[0],color,font,size,0.0,x,y,text);
 
@@ -221,6 +257,9 @@ static void widget_ttf_update(void *Self)
                property_eval(&Image->visible);
                property_eval(&Image->inverted);
                property_eval(&Image->center);
+               property_eval(&Image->_width);
+               property_eval(&Image->_height);
+               property_eval(&Image->align);
 
                /* render image into bitmap */
                widget_ttf_render(W->name, Image);
@@ -273,6 +312,9 @@ int widget_ttf_init(WIDGET * Self)
                property_load(section, "visible", "1", &Image->visible);
                property_load(section, "inverted", "0", &Image->inverted);
                property_load(section, "center", "0", &Image->center);
+               property_load(section, "width", "0", &Image->_width);
+               property_load(section, "height", "0", &Image->_height);
+               property_load(section, "align", "C", &Image->align);
 
                /* sanity checks */
                if (!property_valid(&Image->font))
@@ -326,6 +368,10 @@ int widget_ttf_quit(WIDGET * Self)
                                property_free(&Image->visible);
                                property_free(&Image->inverted);
                                property_free(&Image->center);
+                               property_eval(&Image->_width);
+                               property_eval(&Image->_height);
+                               property_eval(&Image->align);
+
                                free(Self->data);
                                Self->data = NULL;
                        }
index dc30d73bc06ebc2c2960f0ba1548653d42ed50cb..c088ea9ad3a185af019da3f089975b59282ddcc8 100644 (file)
@@ -43,6 +43,9 @@ typedef struct WIDGET_TTF
        PROPERTY visible;               /* image visible? */
        PROPERTY inverted;              /* image inverted? */
        PROPERTY center;                /* image centered? */
+       PROPERTY _width;                /* scale font to witdh */
+       PROPERTY _height;               /* scale font to height */
+       PROPERTY align;         /* align font to L/C/R */
 } WIDGET_TTF;
 
 extern WIDGET_CLASS Widget_Truetype;