Am Donnerstag, 23. Februar 2006 18:39 schrieb Martin Vermeer:
> On Thu, Feb 23, 2006 at 06:29:05PM +0100, Jean-Marc Lasgouttes wrote:
> > >>>>> "Martin" == Martin Vermeer <[EMAIL PROTECTED]> writes:
> > 
> > >> I did not try the other part.
> > 
> > Martin> But that's the actual bug fix! This part is just cosmetic (and
> > Martin> I have no strong feelings on it, except that the blue line
> > Martin> might be confusing for some users.)
> > 
> > I know :) But I do not have much time right now. And it is for 1.4.1,
> > right?
> 
> No, I would say it's for 1.4.0: we have to prevent a format change.

I would not call it a format change. I would rather say that LyX can 
produce invalid files currently. These invalid files can only be fixed 
with a text editor, not from within LyX.

> Current 1.4.0svn writes out ERT insets in the buffer language rather
> than latex_language, but the user doesn't notice until it's too late.
> 
> (Georg: correct me if I am wrong on this)

What you describe is correct, but the fix is not. If fonts in the 
constructor are changed they should be changed in init(), so that it is 
done in all constructors. Unfortunately even this is not enough. Load the 
attached file, and change the document language to english. You will see 
that everything (including the ERT contents) has the blue underline.
The reason is that the default paragraph language is the buffer language, 
and this is used in read() because there is no explicit language set.
I extended your patch, now the language of ERT content is always forced to 
"latex".
I don't like this special language, and I don't like all these silly 
attempts to enforce "no text parameters" in ERT insets, but I don't see a 
better fix right now.
One other possibility would be to always enforce buffer langauge, but that 
would be mnore fragile, because one would always need to touch all ERT 
insets when it changes.
ERT contents should really be stored in a std::string in the long term, 
but that would be too risky to do now.


Georg

Attachment: 2316.lyx
Description: application/lyx

Index: src/insets/insetert.h
===================================================================
--- src/insets/insetert.h	(Revision 13270)
+++ src/insets/insetert.h	(Arbeitskopie)
@@ -31,9 +31,11 @@ class InsetERT : public InsetCollapsable
 public:
 	///
 	InsetERT(BufferParams const &, CollapseStatus status = Open);
+#if 0
 	///
 	InsetERT(BufferParams const &,
 		 Language const *, std::string const & contents, CollapseStatus status);
+#endif
 	///
 	~InsetERT();
 	///
@@ -41,6 +43,8 @@ public:
 	///
 	void write(Buffer const & buf, std::ostream & os) const;
 	///
+	void read(Buffer const & buf, LyXLex & lex);
+	///
 	std::string const editMessage() const;
 	///
 	bool insetAllowed(InsetBase::Code code) const;
Index: src/insets/insetert.C
===================================================================
--- src/insets/insetert.C	(Revision 13270)
+++ src/insets/insetert.C	(Arbeitskopie)
@@ -58,6 +58,8 @@ void InsetERT::init()
 	font.decSize();
 	font.setColor(LColor::latex);
 	setLabelFont(font);
+	text_.current_font.setLanguage(latex_language);
+	text_.real_current_font.setLanguage(latex_language);
 
 	setInsetName("ERT");
 }
@@ -83,23 +85,19 @@ auto_ptr<InsetBase> InsetERT::doClone() 
 }
 
 
+#if 0
 InsetERT::InsetERT(BufferParams const & bp,
 		   Language const *, string const & contents, CollapseStatus status)
 	: InsetCollapsable(bp, status)
 {
-	//LyXFont font(LyXFont::ALL_INHERIT, lang);
-	LyXFont font;
-	getDrawFont(font);
-	string::const_iterator cit = contents.begin();
-	string::const_iterator end = contents.end();
-	pos_type pos = 0;
-	for (; cit != end; ++cit)
-		paragraphs().begin()->insertChar(pos++, *cit, font);
+	LyXFont font(LyXFont::ALL_INHERIT, latex_language);
+	paragraphs().begin()->insert(0, contents, font);
 
 	// the init has to be after the initialization of the paragraph
 	// because of the label settings (draw_label for ert insets).
 	init();
 }
+#endif
 
 
 InsetERT::~InsetERT()
@@ -115,6 +113,30 @@ void InsetERT::write(Buffer const & buf,
 }
 
 
+void InsetERT::read(Buffer const & buf, LyXLex & lex)
+{
+	InsetCollapsable::read(buf, lex);
+
+	// Force default font
+	// This avoids paragraphs in buffer language that would have a
+	// foreign language after a document langauge change, and it ensures
+	// that all new text in ERT gets the "latex" language, since new text
+	// inherits the language from the last position of the existing text.
+	// As a side effect this makes us also robust against bugs in LyX
+	// that might lead to font changes in ERT in .lyx files.
+	LyXFont font(LyXFont::ALL_INHERIT, latex_language);
+	ParagraphList::iterator par = paragraphs().begin();
+	ParagraphList::iterator const end = paragraphs().end();
+	while (par != end) {
+		pos_type siz = par->size();
+		for (pos_type i = 0; i <= siz; ++i) {
+			par->setFont(i, font);
+		}
+		++par;
+	}
+}
+
+
 string const InsetERT::editMessage() const
 {
 	return _("Opened ERT Inset");
@@ -222,8 +244,8 @@ void InsetERT::doDispatch(LCursor & cur,
 		LyXLayout_ptr const layout =
 			bp.getLyXTextClass().defaultLayout();
 		LyXFont font = layout->font;
-		// We need to set the language for non-english documents
-		font.setLanguage(bp.language);
+		// ERT contents has always latex_language
+		font.setLanguage(latex_language);
 		ParagraphList::iterator const end = paragraphs().end();
 		for (ParagraphList::iterator par = paragraphs().begin();
 		     par != end; ++par) {
@@ -390,8 +412,7 @@ void InsetERT::draw(PainterInfo & pi, in
 {
 	LyXFont tmpfont = pi.base.font;
 	getDrawFont(pi.base.font);
-	// I don't understand why the above .realize isn't needed, or
-	// even wanted, here. It just works. -- MV 10.04.2005
+	pi.base.font.realize(tmpfont);
 	InsetCollapsable::draw(pi, x, y);
 	pi.base.font = tmpfont;
 }
Index: src/lyxfont.C
===================================================================
--- src/lyxfont.C	(Revision 13270)
+++ src/lyxfont.C	(Arbeitskopie)
@@ -726,7 +726,8 @@ void LyXFont::lyxWriteChanges(LyXFont co
 		if (col_str == "inherit") col_str = "default";
 		os << "\\color " << col_str << "\n";
 	}
-	if (orgfont.language() != language()) {
+	if (orgfont.language() != language() &&
+	    language() != latex_language) {
 		if (language())
 			os << "\\lang " << language()->lang() << "\n";
 		else

Reply via email to