On Fri, Feb 24, 2006 at 02:21:04PM +0100, Georg Baum wrote: > Jean-Marc Lasgouttes wrote: > > It seems to me from your discussions with Martin that the complete fix > > is not very clear yet :) > > I think it is clear now. A combination of Martins and my patches would fix > all problems. What is missing now is the actual patch and testing.
Attached your patch with the current_font/real_current_font thing moved to the dispatcher. Tested as follows: - entered an ERT, entered text. Changed (in multilingual doc) language. OK, no blue line. - entered ERT, entered text, deleted it, entered new text. Changed language: OK. - entered multi-paragraph ERT, where empty paragraphs were created by two different methods: 1) press ENTER at end of paragraph 2) press ENTER at start of paragraph Changed doc language -> no blue lines appearing. - Saved the doc with ERT's in it, and reloaded -> no blue lines - Changed again doc language -> still no blue lines. The patch may be a bit overkill, but it certainly works. - Martin
Index: src/lyxfont.C =================================================================== --- src/lyxfont.C (revision 13276) +++ src/lyxfont.C (working copy) @@ -726,7 +726,8 @@ 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 Index: src/insets/insetert.C =================================================================== --- src/insets/insetert.C (revision 13276) +++ src/insets/insetert.C (working copy) @@ -83,23 +83,19 @@ } +#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 +111,30 @@ } +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 +242,8 @@ 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) { @@ -239,6 +259,9 @@ break; } default: + // Force any new text to latex_language: + text_.current_font.setLanguage(latex_language); + text_.real_current_font.setLanguage(latex_language); InsetCollapsable::doDispatch(cur, cmd); break; } @@ -390,8 +413,7 @@ { 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/insets/insetert.h =================================================================== --- src/insets/insetert.h (revision 13276) +++ src/insets/insetert.h (working copy) @@ -31,9 +31,11 @@ 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 @@ /// 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;
pgp9UBDfXfGvS.pgp
Description: PGP signature