Exemple #1
0
        //---------------------------------------------------------------------
        //! @brief Set the text to display in the Label.
        //! @param[in] _text The text to display.
        //---------------------------------------------------------------------
        void Label::setText( std::string const& _text )
        {
            text__ = _text;
            evas_object_text_text_set( label__
                                     , text__.c_str() );

            int end_char_pos = evas_object_text_last_up_to_pos( label__
                                                              , width__
                                                              , height__ / 2 );
            if( end_char_pos > 0 )
            {
                String short_text = _text.substr( 0
                                                , end_char_pos - 2 ) + "...";
                evas_object_text_text_set( label__
                                         , short_text.c_str() );
            }

            alignText();
        }
Exemple #2
0
END_TEST

/* Various text related geometries */
START_TEST(evas_text_geometries)
{
   START_TEXT_TEST();
   const char *buf = "Tests";
   const char *font = TEST_FONT_NAME;
   Evas_Font_Size size = 14;
   Evas_Coord prev;
   int i;
   Evas_Coord x, y, w, h, px;

   evas_object_text_text_set(to, buf);

   /* All should be 0 without a font set */
   fail_if(evas_object_text_ascent_get(to) != 0);
   fail_if(evas_object_text_descent_get(to) != 0);
   fail_if(evas_object_text_max_ascent_get(to) != 0);
   fail_if(evas_object_text_max_descent_get(to) != 0);
   fail_if(evas_object_text_horiz_advance_get(to) != 0);
   fail_if(evas_object_text_vert_advance_get(to) != 0);

   evas_object_text_font_set(to, font, size);

   /* Check that they are bigger than 0. */
   fail_if(evas_object_text_ascent_get(to) <= 0);
   fail_if(evas_object_text_descent_get(to) <= 0);
   fail_if(evas_object_text_max_ascent_get(to) <= 0);
   fail_if(evas_object_text_max_descent_get(to) <= 0);
   fail_if(evas_object_text_horiz_advance_get(to) <= 0);
   fail_if(evas_object_text_vert_advance_get(to) <= 0);

   /* Check that expanding the text does what we expect it */
   evas_object_text_text_set(to, "Test");
   prev = evas_object_text_ascent_get(to);
   evas_object_text_text_set(to, "Testing");
   fail_if(evas_object_text_ascent_get(to) != prev);

   evas_object_text_text_set(to, "Test");
   prev = evas_object_text_descent_get(to);
   evas_object_text_text_set(to, "Testing");
   fail_if(evas_object_text_descent_get(to) != prev);

   evas_object_text_text_set(to, "Test");
   prev = evas_object_text_max_ascent_get(to);
   evas_object_text_text_set(to, "Testing");
   fail_if(evas_object_text_max_ascent_get(to) != prev);

   evas_object_text_text_set(to, "Test");
   prev = evas_object_text_max_descent_get(to);
   evas_object_text_text_set(to, "Testing");
   fail_if(evas_object_text_max_descent_get(to) != prev);

   evas_object_text_text_set(to, "Test");
   prev = evas_object_text_horiz_advance_get(to);
   evas_object_text_text_set(to, "Testing");
   fail_if(evas_object_text_horiz_advance_get(to) <= prev);

   evas_object_text_text_set(to, "Test");
   prev = evas_object_text_vert_advance_get(to);
   evas_object_text_text_set(to, "Testing");
   fail_if(evas_object_text_vert_advance_get(to) != prev);

   /* Go through all the characters, making sure the geometries we get
    * are in a monotonically increasing order and that all sizes are
    * bigger than 0. */
   evas_object_text_text_set(to, "Testing...");
   x = 0;
   px = -100;
   for (i = 0 ; i < eina_unicode_utf8_get_len("Testing...") ; i++)
     {
        fail_if(!evas_object_text_char_pos_get(to, i, &x, &y, &w, &h));
        fail_if(x <= px);
        px = x;
        /* Get back the coords */
        fail_if(i != evas_object_text_char_coords_get(to, x + (w / 4),
                 y + (h / 2), NULL, NULL, NULL, NULL));
        /* Get back cursor position, if click on right half of char. */
        fail_if((i + 1) != evas_object_text_char_coords_get(to, x + ((3 * w) / 4),
                 y + (h / 2), &x, &y, &w, &h));
     }

   /* Last up to pos */
   Evas_Coord adv;
   int pos, prev_pos;
   evas_object_text_text_set(to, "Test - 유니코드");
   adv = evas_object_text_horiz_advance_get(to);
   pos = prev_pos = 0;
   for (x = 0 ; x <= (adv - 1) ; x++)
     {
        pos = evas_object_text_last_up_to_pos(to, x, 0);
        _ck_assert_int(pos, >=, prev_pos);
        prev_pos = pos;
     }
   pos = evas_object_text_last_up_to_pos(to, x, 0);
   ck_assert_int_eq(pos, -1);
   pos = evas_object_text_last_up_to_pos(to, -50, 0);
   ck_assert_int_eq(pos, -1);

   END_TEXT_TEST();
}
Exemple #3
0
END_TEST

#ifdef HAVE_FRIBIDI
START_TEST(evas_text_bidi)
{
   START_TEXT_TEST();
   const char *buf = "Test - בדיקה";
   int i;
   Evas_Coord x, y, w, h, px;
   const char *font = TEST_FONT_NAME;
   Evas_Font_Size size = 14;

   evas_object_text_font_set(to, font, size);

   evas_object_text_text_set(to, buf);
   fail_if(evas_object_text_direction_get(to) != EVAS_BIDI_DIRECTION_LTR);
   evas_object_text_text_set(to, "בדיקה");
   fail_if(evas_object_text_direction_get(to) != EVAS_BIDI_DIRECTION_RTL);

   /* With RTL text coords should be monotontically decreasing. */
   evas_object_text_text_set(to, "נסיון...");
   x = 0;
   px = 200;
   for (i = 0 ; i < eina_unicode_utf8_get_len("נסיון...") ; i++)
     {
        fail_if(!evas_object_text_char_pos_get(to, i, &x, &y, &w, &h));
        fail_if(x >= px);
        px = x;
        /* Get back the coords */
        fail_if(i != evas_object_text_char_coords_get(to, x + ((3 * w) / 4),
                 y + (h / 2), &x, &y, &w, &h));
     }

   /* Get back cursor position, if click on left half of char.  */
   evas_object_text_text_set(to, "שלום...");
   x = 0;
   px = 200;
   for (i = 0 ; i < eina_unicode_utf8_get_len("שלום...") ; i++)
     {
        fail_if(!evas_object_text_char_pos_get(to, i, &x, &y, &w, &h));
        fail_if(x >= px);
        px = x;
        fail_if((i + 1) != evas_object_text_char_coords_get(to, x + (w / 4),
                 y + (h / 2), &x, &y, &w, &h));
     }

   /* Bidi text is a bit more complex */
   evas_object_text_text_set(to, "Test - נסיון...");
   x = 0;
   px = -100;
   for (i = 0 ; i < eina_unicode_utf8_get_len("Test - ") ; i++)
     {
        fail_if(!evas_object_text_char_pos_get(to, i, &x, &y, &w, &h));
        fail_if(x <= px);
        px = x;
        /* Get back the coords */
        fail_if(i != evas_object_text_char_coords_get(to, x + (w / 4),
                 y + (h / 2), &x, &y, &w, &h));
     }

   /* First rtl char requires more specific handling */
   fail_if(!evas_object_text_char_pos_get(to, i, &x, &y, &w, &h));
   fail_if(x <= px);
   px = x;
   fail_if(i != evas_object_text_char_coords_get(to, x + ((3 * w) / 4),
            y + (h / 2), &x, &y, &w, &h));
   i++;
   for ( ; i < eina_unicode_utf8_get_len("Test - נסיון") ; i++)
     {
        fail_if(!evas_object_text_char_pos_get(to, i, &x, &y, &w, &h));
        fail_if(x >= px);
        px = x;
        /* Get back the coords */
        fail_if(i != evas_object_text_char_coords_get(to, x + (w / 2),
                 y + (h / 2), &x, &y, &w, &h));
     }
   /* First ltr char requires more specific handling */
   fail_if(!evas_object_text_char_pos_get(to, i, &x, &y, &w, &h));
   fail_if(x <= px);
   px = x;
   i++;
   for ( ; i < eina_unicode_utf8_get_len("Test - נסיון...") ; i++)
     {
        fail_if(!evas_object_text_char_pos_get(to, i, &x, &y, &w, &h));
        fail_if(x <= px);
        px = x;
        /* Get back the coords */
        fail_if(i != evas_object_text_char_coords_get(to, x + (w / 2),
                 y + (h / 2), &x, &y, &w, &h));
     }

   /* And with an rtl text */
   evas_object_text_text_set(to, "נסיון - test...");
   x = 0;
   px = 100;
   for (i = 0 ; i < eina_unicode_utf8_get_len("נסיון - ") ; i++)
     {
        fail_if(!evas_object_text_char_pos_get(to, i, &x, &y, &w, &h));
        fail_if(x >= px);
        px = x;
        /* Get back the coords */
        if (w == 0)
          {
             int cx;
             fail_if(!evas_object_text_char_pos_get(to, i - 1, &cx, NULL, NULL, NULL));
             w = cx - x;
          }
        fail_if(i != evas_object_text_char_coords_get(to, x + (3 * w /4),
                 y + (h / 2), &x, &y, &w, &h));
     }

   /* First ltr char requires more specific handling */
   fail_if(!evas_object_text_char_pos_get(to, i, &x, &y, &w, &h));
   fail_if(x >= px);
   px = x;
   fail_if(i != evas_object_text_char_coords_get(to, x + (w / 2),
            y + (h / 2), &x, &y, &w, &h));
   i++;
   for ( ; i < eina_unicode_utf8_get_len("נסיון - test") ; i++)
     {
        fail_if(!evas_object_text_char_pos_get(to, i, &x, &y, &w, &h));
        fail_if(x <= px);
        px = x;
        /* Get back the coords */
        fail_if(i != evas_object_text_char_coords_get(to, x + (w / 2),
                 y + (h / 2), &x, &y, &w, &h));
     }
   /* First rtl char requires more specific handling */
   fail_if(!evas_object_text_char_pos_get(to, i, &x, &y, &w, &h));
   fail_if(x >= px);
   px = x;
   i++;
   for ( ; i < eina_unicode_utf8_get_len("נסיון - test...") ; i++)
     {
        fail_if(!evas_object_text_char_pos_get(to, i, &x, &y, &w, &h));
        fail_if(x >= px);
        px = x;
        /* Get back the coords */
        fail_if(i != evas_object_text_char_coords_get(to, x + (w / 2),
                 y + (h / 2), &x, &y, &w, &h));
     }

   /* And some last up to pos tests */
   Evas_Coord adv;
   int pos, prev_pos;
   evas_object_text_text_set(to, "Test - נסיון...");
   adv = evas_object_text_horiz_advance_get(to);
   pos = prev_pos = 0;
   for (x = 0 ; x <= (adv - 1) ; x++)
     {
        pos = evas_object_text_last_up_to_pos(to, x, 0);
        _ck_assert_int(pos, >=, prev_pos);
        prev_pos = pos;
     }
   pos = evas_object_text_last_up_to_pos(to, x, 0);
   fail_if(pos != -1);
   pos = evas_object_text_last_up_to_pos(to, -50, 0);
   fail_if(pos != -1);

   END_TEXT_TEST();
}
Exemple #4
0
static const char *
_edje_text_fit_x(Edje *ed, Edje_Real_Part *ep,
                 Edje_Calc_Params *params,
                 const char *text, const char *font, int size,
                 Evas_Coord sw, int *free_text)
{
    Evas_Coord tw = 0, th = 0, p;
    int l, r;
    int i;
    char *buf;
    int uc1 = -1, uc2 = -1, c1 = -1, c2 = -1;
    int loop = 0, extra;
    size_t orig_len;
    FLOAT_T sc;

    sc = ed->scale;
    if (sc == ZERO) sc = _edje_scale;

    *free_text = 0;
    if (sw <= 1) return "";

    if (ep->part->scale) evas_object_scale_set(ep->object, TO_DOUBLE(sc));
    evas_object_text_font_set(ep->object, font, size);
    evas_object_text_text_set(ep->object, text);

    part_get_geometry(ep, &tw, &th);
    evas_object_text_style_pad_get(ep->object, &l, &r, NULL, NULL);

    p = ((sw - tw) * params->type.text.elipsis);

    /* chop chop */
    if (tw > sw)
    {
        if (params->type.text.elipsis != 0.0)
            /* should be the last in text! not the rightmost */
            uc1 = evas_object_text_last_up_to_pos(ep->object,
                                                  -p + l, th / 2);
        if (params->type.text.elipsis != 1.0)
        {
            /* should be the last in text! not the rightmost */
            if ((-p + sw -r) < 0)
                uc2 = evas_object_text_last_up_to_pos(ep->object, 0, th / 2);
            else
                uc2 = evas_object_text_last_up_to_pos(ep->object,
                                                      -p + sw - r, th / 2);
        }
        if ((uc1 < 0) && (uc2 < 0))
        {
            uc1 = 0;
            uc2 = 0;
        }
    }

    if (!(((uc1 >= 0) || (uc2 >= 0)) && (tw > sw)))
        return text;

    if ((uc1 == 0) && (uc2 == 0))
        return text;

    orig_len = strlen(text);

    /* don't overflow orig_len by adding extra
     * FIXME: we might want to set a max string length somewhere...
     */
    extra = 1 + 3 + 3; /* terminator, leading and trailing ellipsis */
    orig_len = MIN(orig_len, ((size_t) 8192 - extra));

    if (!(buf = malloc(orig_len + extra)))
        return text;

    /* Convert uc1, uc2 -> c1, c2 */
    i = 0;
    if (uc1 >= 0)
    {
        c1 = 0;
        for ( ; i < uc1 ; i++)
        {
            c1 = evas_string_char_next_get(text, c1, NULL);
        }
    }
    if (uc2 >= 0)
    {
        if (c1 >= 0)
        {
            c2 = c1;
        }
        else
        {
            c2 = 0;
        }
        for ( ; i < uc2 ; i++)
        {
            c2 = evas_string_char_next_get(text, c2, NULL);
        }
    }

    buf[0] = '\0';

    while (((c1 >= 0) || (c2 >= 0)) && (tw > sw))
    {
        loop++;
        if (sw <= 0.0)
        {
            buf[0] = 0;
            break;
        }
        if ((c1 >= 0) && (c2 >= 0))
        {
            if ((loop & 0x1))
            {
                if (c1 >= 0)
                    c1 = evas_string_char_next_get(text, c1, NULL);
            }
            else
            {
                if (c2 >= 0)
                {
                    c2 = evas_string_char_prev_get(text, c2, NULL);
                    if (c2 < 0)
                    {
                        buf[0] = 0;
                        break;
                    }
                }
            }
        }
        else
        {
            if (c1 >= 0)
                c1 = evas_string_char_next_get(text, c1, NULL);
            else if (c2 >= 0)
            {
                c2 = evas_string_char_prev_get(text, c2, NULL);
                if (c2 < 0)
                {
                    buf[0] = 0;
                    break;
                }
            }
        }
        if ((c1 >= 0) && (c2 >= 0))
        {
            if (c1 >= c2)
            {
                buf[0] = 0;
                break;
            }
        }
        else if ((c1 > 0 && (size_t) c1 >= orig_len) || c2 == 0)
        {
            buf[0] = 0;
            break;
        }

        buf[0] = 0;

        _edje_text_fit_set(buf, text, c1, c2);

        evas_object_text_text_set(ep->object, buf);
        part_get_geometry(ep, &tw, &th);
    }

    *free_text = 1;

    return buf;
}