Esempio n. 1
0
END_TEST

/* Tests for functions that are in evas_object_text.c but
 * don't really have anything to do with it. */
START_TEST(evas_text_unrelated)
{
   START_TEXT_TEST();
   const char *buf = "נסיון";
   int pos;
   int value;
   /* Actually, they are tested in eina, just doing it for completeness. */
   fail_if(evas_string_char_len_get(buf) != 5);

   pos = 0;
   fail_if(2 != evas_string_char_next_get(buf, pos, &value));
   fail_if(value != 1504);

   pos = 2;
   fail_if(0 != evas_string_char_prev_get(buf, pos, &value));
   fail_if(value != 1505);

   END_TEXT_TEST();
}
Esempio n. 2
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;
}