Exemplo n.º 1
0
strlist
strlist_range(const strlist* sl, size_t from, size_t to) {
  strlist ret;
  size_t s, e;
  s = strlist_at(sl, from) - sl->sa.s;
  e = strlist_at(sl, to) - sl->sa.s;

  ret.sep = sl->sep;
  ret.sa.s = &sl->sa.s[s];
  ret.sa.len = e - s;
  ret.sa.a = 0;
  return ret;
}
Exemplo n.º 2
0
/* TODO необходимо доработать алгоритм с возможностью расположения по вертикали
 * блока текста с произвольным количество строк.
 * В настоящий момент правильно располагается по вертикали только блок,
 * состящий из одной строки.
 * */
void _cwt_render_textblk(CwtTextBlkPtr tb, CWT_SIZE *sz)
{
	JQ_ASSERT(tb);

	if( tb->lines->count == 1 ) {
		CWT_RECT bounds;
		CWT_CHAR *text;

		bounds.left = 0;
		bounds.top = 0;
		bounds.width = sz->width;
		bounds.height = sz->height;

		text = strlist_at(tb->lines, 0);
		if( text ) {
			_cwt_outtext_box(text
				, &bounds
				, &tb->style->font
				, tb->style->align
				, tb->style->color
				, tb->style->bgcolor);
		}
	} else if( tb->lines->count > 0 ) {
		StringListIterator it;
		int top;

		JQ_ASSERT(tb->style);

		tb->bottom_overflow = FALSE;

		if( !tb->upwards ) {
			strlist_begin_from(tb->lines, tb->top_line, &it);
			top = 0;
		} else {
			strlist_rbegin(tb->lines, &it);
			top = sz->height;
			tb->bottom_overflow = FALSE;
		}

		while( strlist_has_more(&it) ) {
			const CWT_CHAR* text;
			StringListElemPtr node = strlist_node(&it);
			CWT_RECT line_rect;
			int text_height;
			int line_height;

			text = strlist_next(&it);

			text_height = _cwt_text_height(&tb->style->font, text);
			line_height = (tb->style->line_height * text_height)/100 ;

			if( !tb->upwards ) {
				if( top + text_height > sz->height ) {
					tb->bottom_overflow = TRUE;
					break;
				}
			} else {
				if( top - text_height < 0 ) {
					break;
				}
				top -= line_height;
				tb->top_line = node;
			}

			line_rect.top    = top;
			line_rect.left   = 0;
			line_rect.width  = sz->width;
			line_rect.height = line_height;

			_cwt_outtext_box(text
				, &line_rect
				, &tb->style->font
				, (tb->style->align & 0x0F) | CWT_VALIGN_CENTER
				, tb->style->color
				, tb->style->bgcolor);

			if( !tb->upwards )
				top += line_height;
		}
	}

	tb->upwards = FALSE;
}