From 90f00ecfa69b2cea5a8b8a9a3b9cf16b7cd6e6ce Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Mon, 27 Feb 2006 12:22:36 +0000 Subject: [PATCH] fix bug 2316 git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13277 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 4 ++++ src/insets/ChangeLog | 13 ++++++++++ src/insets/insetert.C | 54 ++++++++++++++++++++++++++++++++---------- src/insets/insetert.h | 4 ++++ src/insets/insettext.h | 4 ---- src/lyxfont.C | 3 ++- 6 files changed, 65 insertions(+), 17 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index c554b0f3b6..0d5f19330e 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2006-02-25 Georg Baum + + * lyxfont.C (lyxWriteChanges): Don't write \lang latex + 2006-02-24 Jean-Marc Lasgouttes * text3.C (mathDispatch): fix crash when selection is not empty diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 8a037287a7..6c79f3a4d6 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,16 @@ +2005-02-25 Martin Vermeer +2006-02-25 Georg Baum + + * insetert.[Ch] (read): new, force all paragraphs to latex_language + * insetert.C (doDispatch): set latex_language, not buffer language + for copied text + * insetert.C (doDispatch): force latex_language for newly inserted + text + * insetert.C (draw): realize draw font + * insetert.[Ch] (InsetERT): use latex_language and comment out unused + constructor + * insettext.h (setFont): remove unused declaration + 2006-02-22 Jürgen Spitzmüller * insetfootlike.C (metrics, draw): use buffer's default font (bug 2308). diff --git a/src/insets/insetert.C b/src/insets/insetert.C index 34b2b9fa7b..6477607235 100644 --- a/src/insets/insetert.C +++ b/src/insets/insetert.C @@ -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 InsetERT::doClone() const } +#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, ostream & os) const } +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, FuncRequest & cmd) 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 +261,15 @@ void InsetERT::doDispatch(LCursor & cur, FuncRequest & cmd) break; } default: + // Force any new text to latex_language + // FIXME: This should only be necessary in init(), but + // new paragraphs that are created by pressing enter at the + // start of an existing paragraph get the buffer language + // and not latex_language, so we take this brute force + // approach. + text_.current_font.setLanguage(latex_language); + text_.real_current_font.setLanguage(latex_language); + InsetCollapsable::doDispatch(cur, cmd); break; } @@ -390,8 +421,7 @@ void InsetERT::draw(PainterInfo & pi, int x, int y) const { 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; } diff --git a/src/insets/insetert.h b/src/insets/insetert.h index 162e8950dc..5efe845e40 100644 --- a/src/insets/insetert.h +++ b/src/insets/insetert.h @@ -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; diff --git a/src/insets/insettext.h b/src/insets/insettext.h index ded29d1bc9..c6ba640afb 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -78,10 +78,6 @@ public: /// Code lyxCode() const { return TEXT_CODE; } /// - void setFont(BufferView *, LyXFont const &, - bool toggleall = false, - bool selectall = false); - /// void setText(std::string const &, LyXFont const &); /// void setAutoBreakRows(bool); diff --git a/src/lyxfont.C b/src/lyxfont.C index d7559ca084..c84d71c2b3 100644 --- a/src/lyxfont.C +++ b/src/lyxfont.C @@ -726,7 +726,8 @@ void LyXFont::lyxWriteChanges(LyXFont const & orgfont, 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 -- 2.39.2