Andre Poenitz wrote:

> On Fri, Oct 24, 2003 at 04:22:32PM +0200, Alfredo Braunstein wrote:
>> Andre Poenitz wrote:
>> 
>> > Could you send the .lyx with the problem?
>> 
>> It's the userguide. 3.1.3 "Fine tunning the defaults."
>> But i see different rowbreaking even on the first paragraphs (in current
>> cvs there is typically too much space spreaded around wrt. yesterday
>> night's cvs)
> 
> Hm...
> 
> Anyway, that's rather cosmetical. Of course it needs to be fixed, but
> I'd rather have your sanitize.diff in, and I'll have a closer look in
> the evening.

This is the last version, with rowBreakPoint a bit simplified. They seem to
behave similar here, but I'd rather apply the first one (if any) which is
simpler now that I cannot test if it works well. 

PS: Should I leave the asserts on?

Alfredo
? lyxrow_funcs.C-bad1
? paragraph.C-bad1
? text.C-bad1
? text.C-goood
? text3-save.C
Index: lyxrow_funcs.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxrow_funcs.C,v
retrieving revision 1.23
diff -u -p -u -r1.23 lyxrow_funcs.C
--- lyxrow_funcs.C	22 Oct 2003 16:30:56 -0000	1.23
+++ lyxrow_funcs.C	24 Oct 2003 14:42:06 -0000
@@ -29,8 +29,8 @@ pos_type lastPos(Paragraph const & par, 
 	if (par.empty())
 		return 0;
 	pos_type pos = row.endpos() - 1;
-	if (pos == par.size())
-		--pos;
+//	if (pos == par.size())
+//		--pos;
 	return pos;
 }
 
Index: paragraph.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph.C,v
retrieving revision 1.334
diff -u -p -u -r1.334 paragraph.C
--- paragraph.C	24 Oct 2003 09:45:03 -0000	1.334
+++ paragraph.C	24 Oct 2003 14:42:08 -0000
@@ -1327,12 +1327,13 @@ Paragraph::value_type Paragraph::getChar
 	// This is in the critical path!
 	pos_type const siz = text_.size();
 
-	BOOST_ASSERT(pos <= siz);
+	BOOST_ASSERT(0 <= pos && pos <= siz);
 
 	if (pos == siz) {
 		lyxerr << "getChar() on pos " << pos << " in par id "
 		       << id() << " of size " << siz
 		       << "  is a bit silly !" << endl;
+		BOOST_ASSERT(false);
 		return '\0';
 	}
 
Index: text.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v
retrieving revision 1.482
diff -u -p -u -r1.482 text.C
--- text.C	24 Oct 2003 09:45:04 -0000	1.482
+++ text.C	24 Oct 2003 14:42:11 -0000
@@ -456,7 +456,7 @@ pos_type addressBreakPoint(pos_type i, P
 {
 	for (; i < par.size(); ++i)
 		if (par.isNewline(i))
-			return i;
+			return i + 1;
 
 	return par.size();
 }
@@ -466,6 +466,13 @@ pos_type addressBreakPoint(pos_type i, P
 
 void LyXText::rowBreakPoint(ParagraphList::iterator pit, Row & row) const
 {
+	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)
@@ -474,26 +481,19 @@ void LyXText::rowBreakPoint(ParagraphLis
 	// inset->textWidth() returns -1 via workWidth(),
 	// but why ?
 	if (width < 0) {
-		row.endpos(pit->size() + 1);
+		row.endpos(pit->size());
 		return;
 	}
 
 	LyXLayout_ptr const & layout = pit->layout();
 
 	if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
-		row.endpos(addressBreakPoint(row.pos(), *pit) + 1);
+		row.endpos(addressBreakPoint(row.pos(), *pit));
 		return;
 	}
 
-	pos_type const pos = row.pos();
 	pos_type const body_pos = pit->beginningOfBody();
-	pos_type const last = pit->size();
-	pos_type point = last;
 
-	if (pos == last) {
-		row.endpos(last + 1);
-		return;
-	}
 
 	// Now we iterate through until we reach the right margin
 	// or the end of the par, then choose the possible break
@@ -505,28 +505,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 < last; ++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 < last) {
+		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;
 			}
 		}
@@ -559,46 +561,42 @@ 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 == last || chunkwidth >= width - left) {
-				if (pos < i) {
-					point = i - 1;
-					// exit on last registered breakpoint:
-					break;  
-				}
-			}
-			// emergency exit:
-			if (i + 1 < last)		
+			if (point != end)
+				break;
+			else if (chunkwidth >= width - left && i > pos) {
+				// if no break before, break here
+				point = i;
 				break;  
+			}
 		}
 
+
 		InsetOld * in = pit->getInset(i);
 		if (!in || in->isChar()) {
 			// some insets are line separators too
 			if (pit->isLineSeparator(i)) {
 				// register breakpoint:
-				point = i; 
+				point = i + 1; 
 				chunkwidth = 0;
 			}
 		}
+
+
 	}
 
-	if (point == last && x >= width) {
-		// didn't find one, break at the point we reached the edge
-		point = i;
-	} else if (i == last && x < width) {
+	if (i == end && x < width) {
 		// found one, but we fell off the end of the par, so prefer
 		// that.
-		point = last;
+		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);
 }
 
 
@@ -1227,8 +1225,10 @@ void LyXText::prepareToPrint(ParagraphLi
 		// The test on pit->size() is to catch zero-size pars, which
 		// would trigger the assert in Paragraph::getInset().
 		//inset = pit->size() ? pit->getInset(row.pos()) : 0;
-		inset = pit->isInset(row.pos()) ? pit->getInset(row.pos()) : 0;
-		if (inset && inset->display()) {
+		if (!pit->empty()
+		    && pit->isInset(row.pos())
+		    && pit->getInset(row.pos())->display())
+		{
 			align = LYX_ALIGN_CENTER;
 		}
 		
@@ -1895,18 +1895,30 @@ void LyXText::redoParagraphInternal(Para
 
 	// rebreak the paragraph
 	int const ww = workWidth();
-	for (pos_type z = 0; z < pit->size() + 1; ) {
-		Row row(z);
-		rowBreakPoint(pit, row);
-		z = row.endpos();
-		fill(pit, row, ww);
+	if (pit->empty()) {
+		Row row(0);
+		row.endpos(0);
 		prepareToPrint(pit, row);
 		setHeightOfRow(pit, row);
 		row.y_offset(pit->height);
 		pit->rows.push_back(row);
-		pit->width = std::max(pit->width, row.width());
-		pit->height += row.height();
+		pit->width = 0;
+		pit->height = row.height();
+	} else {
+		for (lyx::pos_type z = 0; z < pit->size();) {
+			Row row(z);
+			rowBreakPoint(pit, row);
+			z = row.endpos();
+			fill(pit, row, ww);
+			prepareToPrint(pit, row);
+			setHeightOfRow(pit, row);
+			row.y_offset(pit->height);
+			pit->rows.push_back(row);
+			pit->width = std::max(pit->width, row.width());
+			pit->height += row.height();
+		}
 	}
+
 	height += pit->height;
 	//lyxerr << "redoParagraph: " << pit->rows.size() << " rows\n";
 }
Index: text2.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v
retrieving revision 1.484
diff -u -p -u -r1.484 text2.C
--- text2.C	24 Oct 2003 09:45:06 -0000	1.484
+++ text2.C	24 Oct 2003 14:42:13 -0000
@@ -1311,18 +1311,27 @@ void LyXText::setCursor(LyXCursor & cur,
 
 	// None of these should happen, but we're scaredy-cats
 	if (pos > pit->size()) {
-		lyxerr << "dont like 1, pos: " << pos << " size: " << pit->size() << endl;
+		lyxerr << "dont like 1, pos: " << pos
+		       << " size: " << pit->size()
+		       << " row.pos():" << row.pos()
+		       << " paroffset: " << par << endl;
 		pos = 0;
 		cur.pos(0);
+		BOOST_ASSERT(false);
 	} else if (pos > last + 1) {
 		lyxerr << "dont like 2 please report" << endl;
 		// This shouldn't happen.
 		pos = last + 1;
 		cur.pos(pos);
+		BOOST_ASSERT(false);
 	} else if (pos < row.pos()) {
-		lyxerr << "dont like 3 please report" << endl;
+		lyxerr << "dont like 3 please report pos:" << pos
+		       << " size: " << pit->size()
+		       << " row.pos():" << row.pos()
+		       << " paroffset: " << par << endl;
 		pos = row.pos();
 		cur.pos(pos);
+		BOOST_ASSERT(false);
 	}
 
 	// now get the cursors x position

Reply via email to