[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15847] branches/soc-2008-quorn/source/ blender/src/drawtext.c: Word wrap fix: formatting and cursor positioning was not working correctly for wrapped lines containing tabs , or lines with no breaks.

Ian Thompson quornian at googlemail.com
Mon Jul 28 17:48:02 CEST 2008


Revision: 15847
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15847
Author:   quorn
Date:     2008-07-28 17:47:46 +0200 (Mon, 28 Jul 2008)

Log Message:
-----------
Word wrap fix: formatting and cursor positioning was not working correctly for wrapped lines containing tabs, or lines with no breaks.

Modified Paths:
--------------
    branches/soc-2008-quorn/source/blender/src/drawtext.c

Modified: branches/soc-2008-quorn/source/blender/src/drawtext.c
===================================================================
--- branches/soc-2008-quorn/source/blender/src/drawtext.c	2008-07-28 15:21:18 UTC (rev 15846)
+++ branches/soc-2008-quorn/source/blender/src/drawtext.c	2008-07-28 15:47:46 UTC (rev 15847)
@@ -97,7 +97,7 @@
 				This equals region_width/font_width for the region
 	wrap_chars	Characters that allow wrapping. This equals [' ', '\t', '-']
 
-def wrap(line, view_width, wrap_chars):
+def wrap(line, view_width, wrap_chars, tab_size):
 	draw_start = 0
 	draw_end = view_width
 	tab_offset = 0
@@ -111,7 +111,7 @@
 		elif c in wrap_chars:
 			draw_end = pos+1
 			if c == '\t':
-				tab_offset += tab_size-(pos-draw_start)%tab_size
+				tab_offset += tab_size-(pos-draw_start+tab_offset+1)%tab_size
 		pos += 1
 	print line[draw_start:]
 
@@ -574,7 +574,7 @@
 	return count;
 }
 
-/* Sets (offl, offc) to transform (line, curs) combination to its wrapped position */
+/* Sets (offl, offc) for transforming (line, curs) to its wrapped position */
 static void wrap_offset(SpaceText *st, TextLine *linein, int cursin, int *offl, int *offc) {
 	Text *text;
 	TextLine *linep;
@@ -603,8 +603,10 @@
 		*offc= 0;
 		for (i=0; linep->line[i]!='\0'; i++) {
 			if (i-start+taboffs>=max) {
+				if (end-start==max && linep==linein && i >= cursin)
+					break;
 				(*offl)++;
-				*offc -= end-start;
+				*offc -= end-start+taboffs;
 				start= end;
 				end += max;
 				taboffs= 0;
@@ -613,7 +615,7 @@
 				if (linep==linein && i >= cursin)
 					break;
 				else if (linep->line[i]=='\t')
-					taboffs += st->tabnumber-(i-start)%st->tabnumber;
+					taboffs += st->tabnumber-(i-start+taboffs+1)%st->tabnumber;
 			}
 		}
 		if (linep==linein) break;
@@ -1213,7 +1215,7 @@
 {
 	SpaceText *st= curarea->spacedata.first;
 	Text *text;
-	int i, a, x, y, max, offs, len;
+	int i, a, x, y, max, len;
 	TextLine *tmp;
 	char linenr[12], *wrapbuf;
 	float col[3];
@@ -1258,7 +1260,7 @@
 	max= get_wrap_width(st);
 	wrapbuf= MEM_mallocN(max+1, "wrapbuffer");
 
-	for (i=0; i<st->viewlines && tmp; i++, tmp= tmp->next) {
+	for (i=0; y>0 && i<st->viewlines && tmp; i++, tmp= tmp->next) {
 		if (st->showsyntax && !tmp->format) {
 			txt_format_line(st, tmp, 0);
 		}
@@ -1280,26 +1282,27 @@
 			BMF_DrawString(spacetext_get_font(st), linenr);
 		}
 		if (st->wordwrap) {
-			int start, end, taboffs;
-			offs= 0;
+			int start, end, taboffs, fmtoffs;
 			len= tmp->len;
-			taboffs= start= 0; end= max;
+			fmtoffs= taboffs= start= 0;
+			end= max;
 			for (a=0; a<len; a++) {
 				if (a-start+taboffs>=max) {
 					strncpy(wrapbuf, tmp->line+start, end-start);
 					wrapbuf[end-start]= '\0';
-					text_draw(st, wrapbuf, st->left, 0, 1, x, y, tmp->format+start);
+					text_draw(st, wrapbuf, st->left, 0, 1, x, y, tmp->format+start+fmtoffs);
 					y -= st->lheight;
 					start= end;
 					end += max;
+					fmtoffs += taboffs;
 					taboffs= 0;
 				} else if (tmp->line[a]==' ' || tmp->line[a]=='\t' || tmp->line[a]=='-') {
 					if (tmp->line[a]=='\t')
-						taboffs += st->tabnumber-(a-start)%st->tabnumber;
+						taboffs += st->tabnumber-(a-start+taboffs+1)%st->tabnumber;
 					end = a+1;
 				}
 			}
-			text_draw(st, tmp->line+start, st->left, 0, 1, x, y, tmp->format+start);
+			text_draw(st, tmp->line+start, st->left, 0, 1, x, y, tmp->format+start+fmtoffs);
 		} else {
 			text_draw(st, tmp->line, st->left, 0, 1, x, y, tmp->format);
 		}





More information about the Bf-blender-cvs mailing list