Bug 1973 is half fixed currently: The on-screen fonts are the same as the 
fonts in the .tex file, but if you change the font of a selection that 
does include a tabular the tabular font gets not changed.
This is fixed by the attached patch. I added a comment that this is not 
the intended meaning of InsetBase::noFontChange, so that it can be 
changed later.
The patch works for me, please test and report problems.


Georg
Index: src/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ChangeLog,v
retrieving revision 1.2352
diff -u -p -r1.2352 ChangeLog
--- src/ChangeLog	4 Jan 2006 14:24:39 -0000	1.2352
+++ src/ChangeLog	8 Jan 2006 11:29:26 -0000
@@ -1,3 +1,10 @@
+2006-01-08  Georg Baum  <[EMAIL PROTECTED]>
+
+	* lyxtext.h, text2.C (setCharFont): add Language argument
+	* text2.C (setCharFont): set font of tabulars, too
+	* lyxtext.h, text2.C (setFont): new method with DocIterators
+	* dociterator.C (forwardIdx): implement
+
 2006-01-04  Jean-Marc Lasgouttes  <[EMAIL PROTECTED]>
 
 	* text2.C (deleteEmptyParagraphMechanism): since we delete a
Index: src/dociterator.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/dociterator.C,v
retrieving revision 1.33
diff -u -p -r1.33 dociterator.C
--- src/dociterator.C	24 Nov 2005 16:22:39 -0000	1.33
+++ src/dociterator.C	8 Jan 2006 11:29:26 -0000
@@ -420,6 +420,19 @@ void DocIterator::forwardPar()
 }
 
 
+void DocIterator::forwardIdx()
+{
+	CursorSlice & tip = top();
+	if (tip.idx() < lastidx()) {
+		++tip.idx();
+		tip.pit() = 0;
+		tip.pos() = 0;
+	} else
+		//prevent endless loops
+		BOOST_ASSERT(false);
+}
+
+
 void DocIterator::forwardChar()
 {
 	forwardPos();
Index: src/lyxtext.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxtext.h,v
retrieving revision 1.334
diff -u -p -r1.334 lyxtext.h
--- src/lyxtext.h	1 Jan 2006 20:28:03 -0000	1.334
+++ src/lyxtext.h	8 Jan 2006 11:29:26 -0000
@@ -31,12 +31,11 @@ class BufferView;
 class CursorSlice;
 class Dimension;
 class InsetBase;
-class InsetBase_code;
 class FuncRequest;
 class FuncStatus;
+class Language;
 class LColor_color;
 class LCursor;
-class LyXTextClass;
 class MetricsInfo;
 class PainterInfo;
 class Row;
@@ -65,13 +64,14 @@ public:
 	LyXFont getLayoutFont(pit_type pit) const;
 	///
 	LyXFont getLabelFont(Paragraph const & par) const;
-	///
-	void setCharFont(pit_type pit, pos_type pos, LyXFont const & font);
-	///
-	void setCharFont(pit_type pit, pos_type pos, LyXFont const & font,
-		bool toggleall);
+	/** Set font of character at position \p pos in paragraph \p pit.
+	 *  If the character is an inset with text contents, and the inset
+	 *  is not allowed inside a font change, set the font of the inset.
+	 */
+	void setCharFont(pit_type pit, pos_type pos, LyXFont const &,
+		Language const *);
 
-	/// what you expect when pressing <enter> at cursor position
+	/// what you expect when pressing \<enter\> at cursor position
 	void breakParagraph(LCursor & cur, bool keep_layout = false);
 
 	/// set layout over selection
@@ -93,6 +93,9 @@ public:
 
 	/// Set font over selection paragraphs and rebreak.
 	void setFont(LCursor & cur, LyXFont const &, bool toggleall = false);
+	/// Set font from \p begin to \p end and rebreak.
+	void setFont(DocIterator const & begin, DocIterator const & end,
+		LyXFont const &, Language const *, bool toggleall = false);
 
 	/// rebreaks the given par
 	bool redoParagraph(pit_type pit);
Index: src/text.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v
retrieving revision 1.639
diff -u -p -r1.639 text.C
--- src/text.C	19 Dec 2005 12:30:33 -0000	1.639
+++ src/text.C	8 Jan 2006 11:29:27 -0000
@@ -1138,11 +1138,13 @@ void LyXText::insertChar(LCursor & cur, 
 				     || par.isSeparator(cur.pos() - 2)
 				     || par.isNewline(cur.pos() - 2))
 				  ) {
-					setCharFont(pit, cur.pos() - 1, current_font);
+					setCharFont(pit, cur.pos() - 1, current_font,
+					            cur.buffer().params().language);
 				} else if (contains(number_seperators, c)
 				     && cur.pos() >= 2
 				     && getFont(par, cur.pos() - 2).number() == LyXFont::ON) {
-					setCharFont(pit, cur.pos() - 1, current_font);
+					setCharFont(pit, cur.pos() - 1, current_font,
+					            cur.buffer().params().language);
 				}
 			}
 		}
Index: src/text2.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v
retrieving revision 1.637
diff -u -p -r1.637 text2.C
--- src/text2.C	4 Jan 2006 14:24:40 -0000	1.637
+++ src/text2.C	8 Jan 2006 11:29:28 -0000
@@ -244,7 +244,8 @@ LyXFont LyXText::getLabelFont(Paragraph 
 }
 
 
-void LyXText::setCharFont(pit_type pit, pos_type pos, LyXFont const & fnt)
+void LyXText::setCharFont(pit_type pit, pos_type pos, LyXFont const & fnt,
+		Language const * language)
 {
 	LyXFont font = fnt;
 	LyXLayout_ptr const & layout = pars_[pit].layout();
@@ -274,7 +275,42 @@ void LyXText::setCharFont(pit_type pit, 
 	// Now, reduce font against full layout font
 	font.reduce(layoutfont);
 
-	pars_[pit].setFont(pos, font);
+	if (!pars_[pit].isInset(pos)) {
+		pars_[pit].setFont(pos, font);
+		return;
+	}
+
+	InsetBase * const inset = pars_[pit].getInset(pos);
+	if (inset->noFontChange()) {
+		// We need to propagate the font change to all text
+		// cells of the inset (bug 1973).
+		// FIXME: This should change, see documentation of
+		// noFontChange in insetbase.h
+
+		DocIterator dit = doc_iterator_begin(*inset);
+		// start of the last cell
+		DocIterator end = dit;
+		end.idx() = end.lastidx();
+
+		while (true) {
+			LyXText * text = dit.text();
+			InsetBase * cell = dit.realInset();
+			if (text && cell) {
+				DocIterator cellbegin =
+					doc_iterator_begin(*cell);
+				// last position of the cell
+				DocIterator cellend = cellbegin;
+				cellend.pit() = cellend.lastpit();
+				cellend.pos() = cellend.lastpos();
+				text->setFont(cellbegin, cellend, font,
+				              language);
+			}
+			if (dit == end)
+				break;
+			dit.forwardIdx();
+		}
+	} else
+		pars_[pit].setFont(pos, font);
 }
 
 
@@ -434,20 +470,23 @@ void LyXText::setFont(LCursor & cur, LyX
 	// Ok, we have a selection.
 	recordUndoSelection(cur);
 
-	DocIterator dit = cur.selectionBegin();
-	DocIterator ditend = cur.selectionEnd();
+	setFont(cur.selectionBegin(), cur.selectionEnd(), font,
+	        cur.buffer().params().language, toggleall);
+}
 
-	BufferParams const & params = cur.buffer().params();
 
+void LyXText::setFont(DocIterator const & begin, DocIterator const & end,
+		LyXFont const & font, Language const * language, bool toggleall)
+{
 	// Don't use forwardChar here as ditend might have
 	// pos() == lastpos() and forwardChar would miss it.
 	// Can't use forwardPos either as this descends into
 	// nested insets.
-	for (; dit != ditend; dit.forwardPosNoDescend()) {
+	for (DocIterator dit = begin; dit != end; dit.forwardPosNoDescend()) {
 		if (dit.pos() != dit.lastpos()) {
 			LyXFont f = getFont(dit.paragraph(), dit.pos());
-			f.update(font, params.language, toggleall);
-			setCharFont(dit.pit(), dit.pos(), f);
+			f.update(font, language, toggleall);
+			setCharFont(dit.pit(), dit.pos(), f, language);
 		}
 	}
 }

Reply via email to