Exemple #1
0
int text_get_visible_lines(SpaceText *st, ARegion *ar, const char *str)
{
	int i, j, start, end, max, lines, chars;
	char ch;

	max= wrap_width(st, ar);
	lines= 1;
	start= 0;
	end= max;
	for(i= 0, j= 0; str[j] != '\0'; j++) {
		/* Mimic replacement of tabs */
		ch= str[j];
		if(ch=='\t') {
			chars= st->tabnumber-i%st->tabnumber;
			ch= ' ';
		}
		else chars= 1;

		while(chars--) {
			if(i-start >= max) {
				lines++;
				start= end;
				end += max;
			}
			else if(ch==' ' || ch=='-') {
				end= i+1;
			}

			i++;
		}
	}

	return lines;
}
Exemple #2
0
void wrap_offset_in_line(SpaceText *st, ARegion *ar, TextLine *linein, int cursin, int *offl, int *offc)
{
	int i, j, start, end, chars, max, chop;
	char ch;

	*offl= *offc= 0;

	if(!st->text) return;
	if(!st->wordwrap) return;

	max= wrap_width(st, ar);

	start= 0;
	end= max;
	chop= 1;
	*offc= 0;

	for(i=0, j=0; linein->line[j]!='\0'; j++) {

		/* Mimic replacement of tabs */
		ch= linein->line[j];
		if(ch=='\t') {
			chars= st->tabnumber-i%st->tabnumber;
			if(i<cursin) cursin += chars-1;
			ch= ' ';
		}
		else
			chars= 1;

		while(chars--) {
			if(i-start>=max) {
				if(chop && i >= cursin) {
					if (i==cursin) {
						(*offl)++;
						*offc -= end-start;
					}

					return;
				}

				(*offl)++;
				*offc -= end-start;

				start= end;
				end += max;
				chop= 1;
			}
			else if(ch==' ' || ch=='-') {
				end = i+1;
				chop= 0;
				if(i >= cursin)
					return;
			}
			i++;
		}
	}
}
Exemple #3
0
int text_get_visible_lines(SpaceText *st, ARegion *ar, const char *str)
{
	int i, j, start, end, max, lines, chars;
	char ch;

	max = wrap_width(st, ar);
	lines = 1;
	start = 0;
	end = max;
	for (i = 0, j = 0; str[j]; j += BLI_str_utf8_size_safe(str + j)) {
		int columns = BLI_str_utf8_char_width_safe(str + j); /* = 1 for tab */

		/* Mimic replacement of tabs */
		ch = str[j];
		if (ch == '\t') {
			chars = st->tabnumber - i % st->tabnumber;
			ch = ' ';
		}
		else {
			chars = 1;
		}

		while (chars--) {
			if (i + columns - start > max) {
				lines++;
				start = MIN2(end, i);
				end += max;
			}
			else if (ch == ' ' || ch == '-') {
				end = i + 1;
			}

			i += columns;
		}
	}

	return lines;
}
Exemple #4
0
/* cursin - mem, offc - view */
void wrap_offset_in_line(SpaceText *st, ARegion *ar, TextLine *linein, int cursin, int *offl, int *offc)
{
	int i, j, start, end, chars, max, chop;
	char ch;

	*offl = *offc = 0;

	if (!st->text) return;
	if (!st->wordwrap) return;

	max = wrap_width(st, ar);

	start = 0;
	end = max;
	chop = 1;
	*offc = 0;
	cursin = txt_utf8_offset_to_column(linein->line, cursin);

	for (i = 0, j = 0; linein->line[j]; j += BLI_str_utf8_size_safe(linein->line + j)) {
		int columns = BLI_str_utf8_char_width_safe(linein->line + j); /* = 1 for tab */

		/* Mimic replacement of tabs */
		ch = linein->line[j];
		if (ch == '\t') {
			chars = st->tabnumber - i % st->tabnumber;
			if (i < cursin) cursin += chars - 1;
			ch = ' ';
		}
		else
			chars = 1;

		while (chars--) {
			if (i + columns - start > max) {
				end = MIN2(end, i);

				if (chop && i >= cursin) {
					if (i == cursin) {
						(*offl)++;
						*offc -= end - start;
					}

					return;
				}

				(*offl)++;
				*offc -= end - start;

				start = end;
				end += max;
				chop = 1;
			}
			else if (ch == ' ' || ch == '-') {
				end = i + 1;
				chop = 0;
				if (i >= cursin)
					return;
			}
			i += columns;
		}
	}
}
Exemple #5
0
/* Sets (offl, offc) for transforming (line, curs) to its wrapped position */
void wrap_offset(SpaceText *st, ARegion *ar, TextLine *linein, int cursin, int *offl, int *offc)
{
	Text *text;
	TextLine *linep;
	int i, j, start, end, max, chop;
	char ch;

	*offl = *offc = 0;

	if (!st->text) return;
	if (!st->wordwrap) return;

	text = st->text;

	/* Move pointer to first visible line (top) */
	linep = text->lines.first;
	i = st->top;
	while (i > 0 && linep) {
		int lines = text_get_visible_lines(st, ar, linep->line);

		/* Line before top */
		if (linep == linein) {
			if (lines <= i)
				/* no visible part of line */
				return;
		}

		if (i - lines < 0) {
			break;
		}
		else {
			linep = linep->next;
			(*offl) += lines - 1;
			i -= lines;
		}
	}

	max = wrap_width(st, ar);
	cursin = txt_utf8_offset_to_column(linein->line, cursin);

	while (linep) {
		start = 0;
		end = max;
		chop = 1;
		*offc = 0;
		for (i = 0, j = 0; linep->line[j]; j += BLI_str_utf8_size_safe(linep->line + j)) {
			int chars;
			int columns = BLI_str_utf8_char_width_safe(linep->line + j); /* = 1 for tab */

			/* Mimic replacement of tabs */
			ch = linep->line[j];
			if (ch == '\t') {
				chars = st->tabnumber - i % st->tabnumber;
				if (linep == linein && i < cursin) cursin += chars - 1;
				ch = ' ';
			}
			else {
				chars = 1;
			}

			while (chars--) {
				if (i + columns - start > max) {
					end = MIN2(end, i);

					if (chop && linep == linein && i >= cursin) {
						if (i == cursin) {
							(*offl)++;
							*offc -= end - start;
						}

						return;
					}

					(*offl)++;
					*offc -= end - start;

					start = end;
					end += max;
					chop = 1;
				}
				else if (ch == ' ' || ch == '-') {
					end = i + 1;
					chop = 0;
					if (linep == linein && i >= cursin)
						return;
				}
				i += columns;
			}
		}
		if (linep == linein) break;
		linep = linep->next;
	}
}
Exemple #6
0
/* Sets (offl, offc) for transforming (line, curs) to its wrapped position */
void wrap_offset(SpaceText *st, ARegion *ar, TextLine *linein, int cursin, int *offl, int *offc)
{
	Text *text;
	TextLine *linep;
	int i, j, start, end, chars, max, chop;
	char ch;

	*offl= *offc= 0;

	if(!st->text) return;
	if(!st->wordwrap) return;

	text= st->text;

	/* Move pointer to first visible line (top) */
	linep= text->lines.first;
	i= st->top;
	while(i>0 && linep) {
		int lines= text_get_visible_lines(st, ar, linep->line);

		/* Line before top */
		if(linep == linein) {
			if(lines <= i)
				/* no visible part of line */
				return;
		}

		if (i-lines<0) {
			break;
		} else {
			linep= linep->next;
			(*offl)+= lines-1;
			i-= lines;
		}
	}

	max= wrap_width(st, ar);

	while(linep) {
		start= 0;
		end= max;
		chop= 1;
		chars= 0;
		*offc= 0;
		for(i=0, j=0; linep->line[j]!='\0'; j++) {

			/* Mimic replacement of tabs */
			ch= linep->line[j];
			if(ch=='\t') {
				chars= st->tabnumber-i%st->tabnumber;
				if(linep==linein && i<cursin) cursin += chars-1;
				ch= ' ';
			}
			else
				chars= 1;

			while(chars--) {
				if(i-start>=max) {
					if(chop && linep==linein && i >= cursin) {
						if (i==cursin) {
							(*offl)++;
							*offc -= end-start;
						}

						return;
					}

					(*offl)++;
					*offc -= end-start;

					start= end;
					end += max;
					chop= 1;
				}
				else if(ch==' ' || ch=='-') {
					end = i+1;
					chop= 0;
					if(linep==linein && i >= cursin)
						return;
				}
				i++;
			}
		}
		if(linep==linein) break;
		linep= linep->next;
	}
}