Пример #1
0
static inline off_t
line_pixel_length (unsigned char *t, off_t b, off_t l, gboolean utf8)
{
    off_t xn, x;                /* position conters */
    off_t cw;                   /* character width in bytes */

#ifndef HAVE_CHARSET
    (void) utf8;
#endif

    for (xn = 0, x = 0; xn <= l; x = xn, b += cw)
    {
        char *tb;

        tb = (char *) t + b;
        cw = 1;

        switch (tb[0])
        {
        case '\n':
            return b;
        case '\t':
            xn = next_tab_pos (x);
            break;
        default:
#ifdef HAVE_CHARSET
            if (utf8)
            {
                gunichar ch;

                ch = g_utf8_get_char_validated (tb, -1);
                if (ch != (gunichar) (-2) && ch != (gunichar) (-1))
                {
                    char *next_ch;

                    /* Calculate UTF-8 char width */
                    next_ch = g_utf8_next_char (tb);
                    if (next_ch != NULL)
                        cw = next_ch - tb;

                    if (g_unichar_iswide (ch))
                        x++;
                }
            }
#endif

            xn = x + 1;
            break;
        }
    }

    return b;
}
Пример #2
0
static int line_pixel_length (unsigned char *t, long b, int l)
{
    int x = 0, c, xn = 0;
    for (;;) {
	c = t[b];
	switch (c) {
	case '\n':
	    return b;
	case '\t':
	    xn = next_tab_pos (x);
	    break;
	default:
	    xn = x + 1;
	    break;
	}
	if (xn > l)
	    break;
	x = xn;
	b++;
    }
    return b;
}