Please have a look at this patch. IMO this is the right fix for all
the problems we have with the different fonts in an ERT inset. This
patch does not change the fonts it only changes them for drawing so
we can copy inside whatever we will when we copy it outside again it
will hold all it's original values.

With this we can also get rid of the latex_language (but I still didn't
do that change).

One missing thing I see for insetERT to make it nearer a InsetEditor is
that all paragraphs should be left aligned!

             Jug

--
-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._
Dr. Jürgen Vigna        E-Mail:  [EMAIL PROTECTED]
Italienallee 13/N       Tel/Fax: +39-0471-450260 / +39-0471-450253
I-39100 Bozen           Web:     http://www.sad.it/~jug
-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._

If it weren't for the last minute, nothing would ever get done.

Index: src/buffer.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer.C,v
retrieving revision 1.295
diff -u -p -r1.295 buffer.C
--- src/buffer.C        2002/01/17 23:09:29     1.295
+++ src/buffer.C        2002/01/18 14:47:35
@@ -407,7 +407,7 @@ void Buffer::insertErtContents(Paragraph
        if (!ert_comp.contents.empty()) {
                lyxerr[Debug::INSETS] << "ERT contents:\n'"
                                      << ert_comp.contents << "'" << endl;
-               Inset * inset = new InsetERT(ert_comp.contents, true);
+               Inset * inset = new InsetERT(params.language, ert_comp.contents, true);
                par->insertInset(pos++, inset, ert_comp.font);
                ert_comp.contents.erase();
        }
Index: src/text.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v
retrieving revision 1.226
diff -u -p -r1.226 text.C
--- src/text.C  2002/01/18 03:50:18     1.226
+++ src/text.C  2002/01/18 14:47:41
@@ -581,7 +581,7 @@ void LyXText::drawArabicComposeChar(Draw
  
  
 void LyXText::drawChars(DrawRowParams & p, pos_type & vpos,
-       bool hebrew, bool arabic)
+                        bool hebrew, bool arabic)
 {
        pos_type pos = vis2log(vpos);
        pos_type const last = rowLastPrintable(p.row);
Index: src/text2.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v
retrieving revision 1.197
diff -u -p -r1.197 text2.C
--- src/text2.C 2002/01/18 03:50:19     1.197
+++ src/text2.C 2002/01/18 14:47:43
@@ -171,9 +171,10 @@ LyXFont const LyXText::getFont(Buffer co
        if (!par_depth) {
                if (layout.labeltype == LABEL_MANUAL
                    && pos < beginningOfMainBody(buf, par)) {
-                               // 1% goes here
-                       LyXFont f = par->getFontSettings(buf->params,
-                                                        pos);
+                       // 1% goes here
+                       LyXFont f = par->getFontSettings(buf->params, pos);
+                       if (par->inInset())
+                               par->inInset()->getFontSettings(f);
 #ifndef INHERIT_LANGUAGE
                        return f.realize(layout.reslabelfont);
 #else
@@ -181,6 +182,8 @@ LyXFont const LyXText::getFont(Buffer co
 #endif
                } else {
                        LyXFont f = par->getFontSettings(buf->params, pos);
+                       if (par->inInset())
+                               par->inInset()->getFontSettings(f);
 #ifndef INHERIT_LANGUAGE
                        return f.realize(layout.resfont);
 #else
@@ -207,6 +210,8 @@ LyXFont const LyXText::getFont(Buffer co
 #else
        tmpfont.realize(layoutfont, buf->params.language);
 #endif
+       if (par->inInset())
+               par->inInset()->getFontSettings(tmpfont);
        
        return realizeFont(tmpfont, buf, par);
 }
Index: src/insets/inset.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/inset.h,v
retrieving revision 1.37
diff -u -p -r1.37 inset.h
--- src/insets/inset.h  2002/01/14 16:10:28     1.37
+++ src/insets/inset.h  2002/01/18 14:47:43
@@ -314,6 +314,8 @@ public:
        // if this inset has paragraphs should they be outputed all as default
        // paragraps with "Standard" layout?
        virtual bool forceDefaultParagraphs(Inset const *) const;
+       //
+       virtual void getFontSettings(LyXFont &) const {}
 
 protected:
        ///
@@ -521,7 +523,7 @@ public:
        ///
        virtual bool searchBackward(BufferView *, string const &,
                                    bool = true, bool = false);
-
+       
 protected:
        ///
        void toggleCursorVisible() const {
Index: src/insets/insetert.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetert.C,v
retrieving revision 1.64
diff -u -p -r1.64 insetert.C
--- src/insets/insetert.C       2001/12/28 13:26:54     1.64
+++ src/insets/insetert.C       2002/01/18 14:47:44
@@ -71,20 +71,20 @@ Inset * InsetERT::clone(Buffer const &, 
 }
 
 
-InsetERT::InsetERT(string const & contents, bool collapsed)
+InsetERT::InsetERT(Language const * l, string const & contents, bool collapsed)
        : InsetCollapsable(collapsed)
 {
        if (collapsed)
                status_ = Collapsed;
        else
                status_ = Open;
-#ifndef INHERIT_LANG
-       LyXFont font(LyXFont::ALL_INHERIT, latex_language);
-#else 
-       LyXFont font(LyXFont::ALL_INHERIT);
-#endif
+
+       LyXFont font(LyXFont::ALL_INHERIT, l);
+#ifdef SET_HARD_FONT
        font.setFamily(LyXFont::TYPEWRITER_FAMILY);
        font.setColor(LColor::latex);
+#endif
+       
        string::const_iterator cit = contents.begin();
        string::const_iterator end = contents.end();
        pos_type pos = 0;
@@ -147,12 +147,12 @@ void InsetERT::read(Buffer const * buf, 
 #endif
        inset.read(buf, lex);
 
+#ifdef SET_HARD_FONT
 #ifndef INHERIT_LANG
        LyXFont font(LyXFont::ALL_INHERIT, latex_language);
 #else 
        LyXFont font(LyXFont::ALL_INHERIT);
 #endif
-
        font.setFamily(LyXFont::TYPEWRITER_FAMILY);
        font.setColor(LColor::latex);
        Paragraph * par = inset.paragraph();
@@ -163,7 +163,8 @@ void InsetERT::read(Buffer const * buf, 
                }
                par = par->next();
        }
-
+#endif
+       
        if (!token_found) {
                if (collapsed_) {
                        status(0, Collapsed);
@@ -507,8 +508,9 @@ void InsetERT::setButtonLabel() const
 }
 
 
-bool InsetERT::checkInsertChar(LyXFont & font)
+bool InsetERT::checkInsertChar(LyXFont & /* font */)
 {
+#ifdef SET_HARD_FONT
 #ifndef INHERIT_LANG
        LyXFont f(LyXFont::ALL_INHERIT, latex_language);
 #else 
@@ -517,6 +519,7 @@ bool InsetERT::checkInsertChar(LyXFont &
        font = f;
        font.setFamily(LyXFont::TYPEWRITER_FAMILY);
        font.setColor(LColor::latex);
+#endif
        return true;
 }
 
@@ -599,8 +602,9 @@ void InsetERT::draw(BufferView * bv, LyX
 }
 
 
-void InsetERT::set_latex_font(BufferView * bv)
+void InsetERT::set_latex_font(BufferView * /* bv */)
 {
+#ifdef SET_HARD_FONT
 #ifndef INHERIT_LANG
        LyXFont font(LyXFont::ALL_INHERIT, latex_language);
 #else 
@@ -609,7 +613,9 @@ void InsetERT::set_latex_font(BufferView
 
        font.setFamily(LyXFont::TYPEWRITER_FAMILY);
        font.setColor(LColor::latex);
+
        inset.getLyXText(bv)->setFont(bv, font, false);
+#endif
 }
 
 
@@ -667,6 +673,18 @@ void InsetERT::close(BufferView * bv) co
 
 string const InsetERT::selectNextWordToSpellcheck(BufferView * bv,float &) const
 {
-        bv->unlockInset(const_cast<InsetERT *>(this));
+       bv->unlockInset(const_cast<InsetERT *>(this));
        return string();
+}
+
+void InsetERT::getFontSettings(LyXFont & font) const
+{
+#ifndef INHERIT_LANG
+       LyXFont f(LyXFont::ALL_INHERIT, latex_language);
+#else 
+       LyXFont f(LyXFont::ALL_INHERIT);
+#endif
+       font = f;
+       font.setFamily(LyXFont::TYPEWRITER_FAMILY);
+       font.setColor(LColor::latex);
 }
Index: src/insets/insetert.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetert.h,v
retrieving revision 1.38
diff -u -p -r1.38 insetert.h
--- src/insets/insetert.h       2001/12/17 13:33:21     1.38
+++ src/insets/insetert.h       2002/01/18 14:47:44
@@ -29,6 +29,9 @@
   Note that collapsed_ encompasses both the inline and collapsed button
   versions of this inset. 
 */
+
+class Language;
+
 class InsetERT : public InsetCollapsable {
 public:
        ///
@@ -44,7 +47,7 @@ public:
        ///
        Inset * clone(Buffer const &, bool same_id = false) const;
        ///
-       InsetERT(string const & contents, bool collapsed);
+       InsetERT(Language const *, string const & contents, bool collapsed);
        ///
        ~InsetERT();
        ///
@@ -122,6 +125,8 @@ public:
        void status(BufferView *, ERTStatus const st) const;
        ///
        bool showInsetDialog(BufferView *) const;
+       ///
+       void getFontSettings(LyXFont &) const;
 
 private:
        ///
Index: src/insets/insettabular.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettabular.C,v
retrieving revision 1.172
diff -u -p -r1.172 insettabular.C
--- src/insets/insettabular.C   2002/01/17 23:09:31     1.172
+++ src/insets/insettabular.C   2002/01/18 14:47:45
@@ -646,9 +646,6 @@ bool InsetTabular::lockInsetInInset(Buff
                        if (in->getInsetFromID(id)) {
                                actcell = i;
                                in->edit(bv);
-//                             the_locking_inset = in;
-//                             locked = true;
-//                             resetPos(bv);
                                return the_locking_inset->lockInsetInInset(bv, inset);
                        }
                }
Index: src/insets/insettext.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettext.C,v
retrieving revision 1.258
diff -u -p -r1.258 insettext.C
--- src/insets/insettext.C      2002/01/17 14:27:01     1.258
+++ src/insets/insettext.C      2002/01/18 14:47:46
@@ -2626,3 +2626,11 @@ void InsetText::collapseParagraphs(Buffe
        }
        reinitLyXText();
 }
+
+
+void InsetText::getFontSettings(LyXFont & font) const
+{
+       if (!owner())
+               return;
+       owner()->getFontSettings(font);
+}
Index: src/insets/insettext.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettext.h,v
retrieving revision 1.110
diff -u -p -r1.110 insettext.h
--- src/insets/insettext.h      2001/12/24 14:36:31     1.110
+++ src/insets/insettext.h      2002/01/18 14:47:46
@@ -246,6 +246,8 @@ public:
        ///
        bool checkInsertChar(LyXFont &);
        ///
+       void getFontSettings(LyXFont &) const;
+       ///
        //
        // Public structures and variables
        ///

Reply via email to