Alfredo Braunstein wrote:

> Alfredo Braunstein wrote:
> 
>> A simplistic rowbreakpoint sanitizing patch... that works (or seems to).
>> It's still somewhat ugly (I'm cleaning it a bit) but loads the UserGuide
>> correctly.
> 
> But it's not working fine. It leaves too much space sometimes and there
> are several visual glitches on the UserGuide.

I'd like to apply this. It fixes the problem mentioned above and cleans
rowBreakPoint a little bit more.

Alfredo

? lyxrow_funcs.C-bad1
? paragraph.C-bad1
? text.C-bad1
? text.C-goood
? text3-save.C
Index: text.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v
retrieving revision 1.483
diff -u -p -u -r1.483 text.C
--- text.C	24 Oct 2003 15:04:15 -0000	1.483
+++ text.C	25 Oct 2003 10:41:00 -0000
@@ -466,39 +466,33 @@ pos_type addressBreakPoint(pos_type i, P
 
 void LyXText::rowBreakPoint(ParagraphList::iterator pit, Row & row) const
 {
-	if (pit->empty()) {
-		row.endpos(pit->size());
+	pos_type const pos = row.pos();
+	pos_type const end = pit->size();
+	if (pos == end) {
+		row.endpos(end);
 		return;
 	}
 	
 	// maximum pixel width of a row.
 	int width = workWidth()
-		- rightMargin(*pit, *bv()->buffer(), row)
-		- leftMargin(pit, row);
+		- rightMargin(*pit, *bv()->buffer(), row);
 
 	// inset->textWidth() returns -1 via workWidth(),
 	// but why ?
 	if (width < 0) {
-		row.endpos(pit->size());
+		row.endpos(end);
 		return;
 	}
 
 	LyXLayout_ptr const & layout = pit->layout();
 
 	if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
-		row.endpos(addressBreakPoint(row.pos(), *pit));
+		row.endpos(addressBreakPoint(pos, *pit));
 		return;
 	}
 
-	pos_type const pos = row.pos();
 	pos_type const body_pos = pit->beginningOfBody();
-	pos_type const end = pit->size();
-	pos_type point = end - 1;
 
-	if (pos == end) {
-		row.endpos(end);
-		return;
-	}
 
 	// Now we iterate through until we reach the right margin
 	// or the end of the par, then choose the possible break
@@ -510,28 +504,30 @@ void LyXText::rowBreakPoint(ParagraphLis
 	// pixel width since last breakpoint
 	int chunkwidth = 0;
 
-	pos_type i = pos;
 
 	// We re-use the font resolution for the entire font span when possible
-	LyXFont font = getFont(pit, i);
-	lyx::pos_type endPosOfFontSpan = pit->getEndPosOfFontSpan(i);
+	LyXFont font = getFont(pit, pos);
+	lyx::pos_type endPosOfFontSpan = pit->getEndPosOfFontSpan(pos);
 
-	for ( ; i < end; ++i) {
+	pos_type point = end;
+	pos_type i = pos;
+	
+	for (; i < end; ++i) {
 		if (pit->isNewline(i)) {
-			point = i;
+			point = i + 1;
 			break;
 		}
 		// Break before...	
 		if (i + 1 < end) {
 			InsetOld * in = pit->getInset(i + 1);
 			if (in && in->display()) {
-				point = i;
+				point = i + 1;
 				break;
 			}
 			// ...and after.
 			in = pit->getInset(i);
 			if (in && in->display()) {
-				point = i;
+				point = i + 1;
 				break;
 			}
 		}
@@ -564,17 +560,16 @@ void LyXText::rowBreakPoint(ParagraphLis
 		// break before a character that will fall off
 		// the right of the row
 		if (x >= width) {
-			// if no break before, break here
 			if (point == end || chunkwidth >= width - left) {
-				if (pos < i) {
-					point = i - 1;
-					// exit on last registered breakpoint:
-					break;  
+				if (i > pos) {
+					point = i;
+					break;
 				}
 			}
-			// emergency exit:
-			if (i + 1 < end)
-				break;  
+			// exit on last registered breakpoint.
+			// why the condition?
+//			if (i + 1 < end)
+			break;
 		}
 
 		InsetOld * in = pit->getInset(i);
@@ -582,28 +577,25 @@ void LyXText::rowBreakPoint(ParagraphLis
 			// some insets are line separators too
 			if (pit->isLineSeparator(i)) {
 				// register breakpoint:
-				point = i; 
+				point = i + 1; 
 				chunkwidth = 0;
 			}
 		}
 	}
 
-	if (point == end && x >= width) {
-		// didn't find one, break at the point we reached the edge
-		point = i;
-	} else if (i == end && x < width) {
-		// found one, but we fell off the end of the par, so prefer
+	if (i == end && x < width) {
+		// maybe found one, but the par is short enough, so prefer
 		// that.
-		point = end - 1;
+		point = end;
 	}
 
 	// manual labels cannot be broken in LaTeX. But we
 	// want to make our on-screen rendering of footnotes
 	// etc. still break
 	if (body_pos && point < body_pos)
-		point = body_pos - 1;
+		point = body_pos;
 
-	row.endpos(point + 1);
+	row.endpos(point);
 }
 
 

Reply via email to