Logo Search packages:      
Sourcecode: adesklets version File versions

void imlib_get_text_size ( const char *  text,
int *  width_return,
int *  height_return 
)

Parameters:
text A string.
width_return The width of the text.
height_return The height of the text.
Gets the width and height in pixels the text string would use up if drawn with the current font.

Definition at line 3621 of file imlib2.c.

Referenced by imlib_text_get_index_and_location(), and imlib_text_get_location_at_index().

{
   ImlibFont          *fn;
   int                 w, h;
   int                 dir;

   if (!ctx)
      ctx = imlib_context_new();
   CHECK_PARAM_POINTER("imlib_get_text_size", "font", ctx->font);
   CHECK_PARAM_POINTER("imlib_get_text_size", "text", text);
   fn = (ImlibFont *) ctx->font;

   dir = ctx->direction;
   if (ctx->direction == IMLIB_TEXT_TO_ANGLE && ctx->angle == 0.0)
      dir = IMLIB_TEXT_TO_RIGHT;

   imlib_font_query_size(fn, text, &w, &h);

   switch (dir)
     {
       case IMLIB_TEXT_TO_RIGHT:
       case IMLIB_TEXT_TO_LEFT:
          if (width_return)
             *width_return = w;
          if (height_return)
             *height_return = h;
          break;
       case IMLIB_TEXT_TO_DOWN:
       case IMLIB_TEXT_TO_UP:
          if (width_return)
             *width_return = h;
          if (height_return)
             *height_return = w;
          break;
       case IMLIB_TEXT_TO_ANGLE:
          if (width_return || height_return)
            {
               double              sa, ca;

               sa = sin(ctx->angle);
               ca = cos(ctx->angle);

               if (width_return)
                 {
                    double              x1, x2, xt;

                    x1 = x2 = 0.0;
                    xt = ca * w;
                    if (xt < x1)
                       x1 = xt;
                    if (xt > x2)
                       x2 = xt;
                    xt = -(sa * h);
                    if (xt < x1)
                       x1 = xt;
                    if (xt > x2)
                       x2 = xt;
                    xt = ca * w - sa * h;
                    if (xt < x1)
                       x1 = xt;
                    if (xt > x2)
                       x2 = xt;
                    *width_return = (int)(x2 - x1);
                 }
               if (height_return)
                 {
                    double              y1, y2, yt;

                    y1 = y2 = 0.0;
                    yt = sa * w;
                    if (yt < y1)
                       y1 = yt;
                    if (yt > y2)
                       y2 = yt;
                    yt = ca * h;
                    if (yt < y1)
                       y1 = yt;
                    if (yt > y2)
                       y2 = yt;
                    yt = sa * w + ca * h;
                    if (yt < y1)
                       y1 = yt;
                    if (yt > y2)
                       y2 = yt;
                    *height_return = (int)(y2 - y1);
                 }
            }
          break;
       default:
          break;
     }
}


Generated by  Doxygen 1.6.0   Back to index