Exemplo n.º 1
0
static cairo_status_t
_word_wrap_stream_write (cairo_output_stream_t  *base,
			 const unsigned char	*data,
			 unsigned int		 length)
{
    word_wrap_stream_t *stream = (word_wrap_stream_t *) base;
    int count;

    while (length) {
	switch (stream->state) {
	case WRAP_STATE_WORD:
	    count = _word_wrap_stream_count_word_up_to (stream, data, length);
	    break;
	case WRAP_STATE_HEXSTRING:
	    count = _word_wrap_stream_count_hexstring_up_to (stream, data, length);
	    break;
	case WRAP_STATE_STRING:
	    count = _word_wrap_stream_count_string_up_to (stream, data, length);
	    break;
	case WRAP_STATE_DELIMITER:
	    count = 1;
	    stream->column++;
	    if (*data == '\n' || stream->column >= stream->max_column) {
		_cairo_output_stream_printf (stream->output, "\n");
		stream->column = 0;
	    }
	    if (*data == '<') {
		stream->state = WRAP_STATE_HEXSTRING;
	    } else if (*data == '(') {
		stream->state = WRAP_STATE_STRING;
	    } else if (!_cairo_isspace (*data)) {
		stream->state = WRAP_STATE_WORD;
	    }
	    if (*data != '\n')
		_cairo_output_stream_write (stream->output, data, 1);
	    break;

	default:
	    ASSERT_NOT_REACHED;
	    count = length;
	    break;
	}
	data += count;
	length -= count;
    }

    return _cairo_output_stream_get_status (stream->output);
}
Exemplo n.º 2
0
static int
_count_word_up_to (const unsigned char *s, int length)
{
    int word = 0;

    while (length--) {
	if (! (_cairo_isspace (*s) || *s == '<')) {
	    s++;
	    word++;
	} else {
	    return word;
	}
    }

    return word;
}
Exemplo n.º 3
0
/* Emit word bytes up to the next delimiter character */
static int
_word_wrap_stream_count_word_up_to (word_wrap_stream_t *stream,
				   const unsigned char *data, int length)
{
    const unsigned char *s = data;
    int count = 0;

    while (length--) {
	if (_cairo_isspace (*s) || *s == '<' || *s == '(') {
	    stream->state = WRAP_STATE_DELIMITER;
	    break;
	}

	count++;
	stream->column++;
	s++;
    }

    if (count)
	_cairo_output_stream_write (stream->output, data, count);

    return count;
}
Exemplo n.º 4
0
static cairo_status_t
_word_wrap_stream_write (cairo_output_stream_t  *base,
			 const unsigned char	*data,
			 unsigned int		 length)
{
    word_wrap_stream_t *stream = (word_wrap_stream_t *) base;
    cairo_bool_t newline;
    int word;

    while (length) {
	if (*data == '<') {
	    stream->in_hexstring = TRUE;
	    stream->empty_hexstring = TRUE;
	    stream->last_write_was_space = FALSE;
	    data++;
	    length--;
	    _cairo_output_stream_printf (stream->output, "<");
	    stream->column++;
	} else if (*data == '>') {
	    stream->in_hexstring = FALSE;
	    stream->last_write_was_space = FALSE;
	    data++;
	    length--;
	    _cairo_output_stream_printf (stream->output, ">");
	    stream->column++;
	} else if (_cairo_isspace (*data)) {
	    newline =  (*data == '\n' || *data == '\r');
	    if (! newline && stream->column >= stream->max_column) {
		_cairo_output_stream_printf (stream->output, "\n");
		stream->column = 0;
	    }
	    _cairo_output_stream_write (stream->output, data, 1);
	    data++;
	    length--;
	    if (newline) {
		stream->column = 0;
	    }
	    else
		stream->column++;
	    stream->last_write_was_space = TRUE;
	} else {
	    if (stream->in_hexstring) {
		word = _count_hexstring_up_to (data, length,
					       MAX (stream->max_column - stream->column, 0));
	    } else {
		word = _count_word_up_to (data, length);
	    }
	    /* Don't wrap if this word is a continuation of a non hex
	     * string word from a previous call to write. */
	    if (stream->column + word >= stream->max_column) {
		if (stream->last_write_was_space ||
		    (stream->in_hexstring && !stream->empty_hexstring))
		{
		    _cairo_output_stream_printf (stream->output, "\n");
		    stream->column = 0;
		}
	    }
	    _cairo_output_stream_write (stream->output, data, word);
	    data += word;
	    length -= word;
	    stream->column += word;
	    stream->last_write_was_space = FALSE;
	    if (stream->in_hexstring)
		stream->empty_hexstring = FALSE;
	}
    }

    return _cairo_output_stream_get_status (stream->output);
}