]> git.lyx.org Git - features.git/commitdiff
This should clean up the language stuff a bit and a small new check for
authorJürgen Vigna <jug@sad.it>
Fri, 27 Jul 2001 12:03:36 +0000 (12:03 +0000)
committerJürgen Vigna <jug@sad.it>
Fri, 27 Jul 2001 12:03:36 +0000 (12:03 +0000)
inserting characters in insets (forced font change) which does not work
as the method seems not to be called.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2366 a592a061-630c-0410-9148-cb99ea01b6c8

28 files changed:
src/ChangeLog
src/CutAndPaste.C
src/bufferparams.C
src/bufferview_funcs.C
src/insets/ChangeLog
src/insets/inset.h
src/insets/insetcollapsable.C
src/insets/insetcollapsable.h
src/insets/insetert.C
src/insets/insetert.h
src/insets/insetfoot.C
src/insets/insetfoot.h
src/insets/insetfootlike.C
src/insets/insetfootlike.h
src/insets/insetmarginal.C
src/insets/insetmarginal.h
src/insets/insetnote.C
src/insets/insetnote.h
src/insets/insettext.C
src/language.C
src/language.h
src/layout.C
src/lyxfont.C
src/lyxfont.h
src/paragraph.C
src/paragraph.h
src/text.C
src/text2.C

index 2430c4e776f452a9101f407747d190d1cba110e7..087933c3794ddd131e7e1238da874b8124a12c51 100644 (file)
@@ -1,3 +1,38 @@
+2001-07-27  Juergen Vigna  <jug@sad.it>
+
+       * text2.C: font.realize function adaption.
+
+       * text.C (draw): add a warnings lyxerr text if needed.
+
+       * layout.C: font.realize function adaption.
+
+       * language.C: add inherit_language and implement it's handlings
+
+       * bufferview_funcs.C (StyleReset): remove language parameter from
+       font creation (should be language_inherit now).
+
+       * bufferparams.C (writeFile): handle ignore_language.
+
+       * paragraph.C (getFontSettings): the language has to be resolved
+       otherwise we have problems in LyXFont!
+
+       * lyxfont.C (lyxWriteChanges): added document_language parameter
+       (update): removed unneeded language parameter
+
+       * paragraph.C (validate): fixed wrong output of color-package when
+       using interface colors for certain fonts in certain environments,
+       which should not seen as that on the final output.
+
+2001-07-26  Juergen Vigna  <jug@sad.it>
+
+       * lyxfont.C (realize): honor ignore_language too!
+       (resolved): ditto.
+
+       * paragraph.C (TeXOnePar): handle ignore language right (hopefully).
+
+       * text.C (draw): one place more for ignore_language to not draw
+       itself!
+
 2001-07-25  Angus Leeming  <a.leeming@ic.ac.uk>
 
        * LaTeXFeatures.C (getPackages): clean-up a little of the natbib code.
index 36af28fbc7bd6a0022348748a1f05e780526113c..428c9c9980c6c5af95be30e56d4bef27e902aeee 100644 (file)
@@ -187,7 +187,7 @@ bool CutAndPaste::copySelection(Paragraph * startpar, Paragraph * endpar,
 
 
 bool CutAndPaste::pasteSelection(Paragraph ** par, Paragraph ** endpar,
-                                int & pos, char tc)
+                                 int & pos, char tc)
 {
        if (!checkPastePossible(*par))
                return false;
index 157b69fe550f1dfdb6e351eaeb0ddd70b70ff9a6..9524c5c82ed2364f7aaff7b16a7cd1a4bd2b4a8a 100644 (file)
@@ -89,8 +89,9 @@ void BufferParams::writeFile(ostream & os) const
        }
    
        /* then the text parameters */
-       os << "\\language " << language->lang()
-          << "\n\\inputencoding " << inputenc
+       if (language != ignore_language)
+               os << "\\language " << language->lang() << '\n';
+       os << "\\inputencoding " << inputenc
           << "\n\\fontscheme " << fonts
           << "\n\\graphics " << graphicsDriver << '\n';
 
index f44336ed1191146456333add476542b02e082982..4c81cdd459270db5bccae6b383502543412a6cdb 100644 (file)
@@ -129,7 +129,7 @@ void Roman(BufferView * bv)
 
 void StyleReset(BufferView * bv)
 {
-       LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
+       LyXFont font(LyXFont::ALL_INHERIT);
        ToggleAndShow(bv, font);
 }
 
index 3a044554a0c34058efb0ddceee1fcbc04cb93a99..801707c1b52cc41350565f014238aa7ce41ab280 100644 (file)
@@ -1,3 +1,16 @@
+2001-07-27  Juergen Vigna  <jug@sad.it>
+
+       * insetert.C (checkInsertChar): implementation of function
+       checkInsertChar.
+
+       * inset.h: added new function checkInsertChar.
+
+       * various files: added c-tor and clone() function.
+       
+       * insetcollapsable.h: removed clone function here as this should
+       be only realized in REAL insets and added it to all collapsable
+       insets! (with the copy-constructor).
+
 2001-07-26  Lars Gullik Bjønnes  <larsbj@birdstep.com>
 
        * insetminipage.C (read): handle missing parameters more gracefully
index b0951ffe3ec483ba94e4a0ae9afedd4af6cb80c5..cd778db2bdffb07bc94acaa6808ea4e7bae521df 100644 (file)
@@ -287,6 +287,9 @@ public:
 #endif
        /// close the inset
        virtual void close(BufferView *) {}
+       /// check if the font of the char we want inserting is correct
+       /// and modify it if it is not.
+       virtual bool checkInsertChar(LyXFont & font) { return true; }
        
 protected:
        ///
@@ -444,6 +447,9 @@ public:
        virtual bool nodraw() const {
                return block_drawing_;
        }
+       /// check if the font of the char we want inserting is correct
+       /// and modify it if it is not.
+       virtual bool checkInsertChar(LyXFont & font) { return true; }
        ///
        // needed for spellchecking text
        ///
index 2b9bdcd9d0651fe798155a033c9640f515ac5e2d..197c782f4c89e6e53a775306d0f434342123922c 100644 (file)
@@ -79,13 +79,6 @@ InsetCollapsable::InsetCollapsable(InsetCollapsable const & in, bool same_id)
 }
 
 
-Inset * InsetCollapsable::clone(Buffer const &, bool same_id) const
-{
-       return new InsetCollapsable(*const_cast<InsetCollapsable *>(this),
-                                                               same_id);
-}
-
-
 bool InsetCollapsable::insertInset(BufferView * bv, Inset * in)
 {
        if (!insetAllowed(in->lyxCode())) {
index 2122b8a3a5cae2202237295f8373de3c10a0821c..ece824521747b57cb079e5baa35893357ddf85ae 100644 (file)
@@ -46,8 +46,6 @@ public:
        ///
        InsetCollapsable(InsetCollapsable const & in, bool same_id = false);
        ///
-       Inset * clone(Buffer const &, bool same_id = false) const;
-       
        void read(Buffer const *, LyXLex &);
        ///
        void write(Buffer const *, std::ostream &) const;
@@ -70,7 +68,7 @@ public:
        ///
        bool insertInset(BufferView *, Inset * inset);
        ///
-       bool insetAllowed(Inset::Code code) const {
+       virtual bool insetAllowed(Inset::Code code) const {
                return inset.insetAllowed(code);
        }
        ///
@@ -203,6 +201,9 @@ public:
                            bool const & cs = true, bool const & mw = false) {
                return inset.searchBackward(bv, str, cs, mw);
        }
+       /// check if the font of the char we want inserting is correct
+       /// and modify it if it is not.
+       virtual bool checkInsertChar(LyXFont &) { return false; }
 
 protected:
        ///
index 4b2d281bc9ffdce478f4cbbdb4b65c9075642f8b..4f2a75c9648659867838ded742593ced5eb0a1eb 100644 (file)
@@ -28,7 +28,6 @@ using std::ostream;
 void InsetERT::init()
 {
        setButtonLabel();
-
        labelfont = LyXFont(LyXFont::ALL_SANE);
        labelfont.decSize();
        labelfont.decSize();
@@ -43,6 +42,19 @@ InsetERT::InsetERT() : InsetCollapsable()
 }
 
 
+InsetERT::InsetERT(InsetERT const & in, bool same_id)
+       : InsetCollapsable(in, same_id)
+{
+       init();
+}
+
+
+Inset * InsetERT::clone(Buffer const &, bool same_id) const
+{
+       return new InsetERT(*const_cast<InsetERT *>(this), same_id);
+}
+
+
 InsetERT::InsetERT(string const & contents, bool collapsed)
        : InsetCollapsable(collapsed)
 {
@@ -238,3 +250,13 @@ void InsetERT::setButtonLabel()
                setLabel(_("666"));
        }
 }
+
+
+bool InsetERT::checkInsertChar(LyXFont & font)
+{
+       LyXFont f(LyXFont::ALL_INHERIT);
+       font = f;
+       font.setFamily(LyXFont::TYPEWRITER_FAMILY);
+       font.setColor(LColor::latex);
+       return true;
+}
index eed211de9943f4d3ad3a60dc28dc5ca9b815200b..546b6fe46e3402eba3c223514c365ab8364b8bd2 100644 (file)
@@ -30,8 +30,14 @@ public:
        ///
        InsetERT();
        ///
+       InsetERT(InsetERT const &, bool same_id = false);
+       ///
+       Inset * clone(Buffer const &, bool same_id = false) const;
+       ///
        InsetERT(string const & contents, bool collapsed);
        ///
+       Inset::Code lyxCode() const { return Inset::ERT_CODE; }
+       ///
        void read(Buffer const * buf, LyXLex & lex);
        ///
        void write(Buffer const * buf, std::ostream & os) const;
@@ -63,6 +69,9 @@ public:
        ///
        UpdatableInset::RESULT localDispatch(BufferView *, kb_action,
                                             string const &);
+       ///
+       bool checkInsertChar(LyXFont &);
+
 private:
        ///
        void init();
index 94a50917e9f7abcf72833691b76146e6a9e562d6..a9a103db497d6d5451ef5559a55c431a759c1f08 100644 (file)
@@ -32,6 +32,20 @@ InsetFoot::InsetFoot()
 }
 
 
+InsetFoot::InsetFoot(InsetFoot const & in, bool same_id)
+       : InsetFootlike(in, same_id)
+{
+       setLabel(_("foot"));
+       setInsetName("Foot");
+}
+
+
+Inset * InsetFoot::clone(Buffer const &, bool same_id) const
+{
+       return new InsetFoot(*const_cast<InsetFoot *>(this), same_id);
+}
+
+
 string const InsetFoot::editMessage() const
 {
        return _("Opened Footnote Inset");
index 2a64b918726127adba50fea8d8cc33cb2d9206a8..5f10835f91a79f7eb033a4e97ee7be074b6bc2ad 100644 (file)
@@ -28,6 +28,10 @@ public:
        ///
        InsetFoot();
        ///
+       InsetFoot(InsetFoot const &, bool same_id = false);
+       ///
+       Inset * clone(Buffer const &, bool same_id = false) const;
+       ///
        Inset::Code lyxCode() const { return Inset::FOOT_CODE; }
        ///
        int latex(Buffer const *, std::ostream &, bool fragile, bool fp) const;
index ea4da1ef0f447e3fdc97266c98bbe687f03b9732..edfd20dafbfde25e8841302eeef8e640de810b2e 100644 (file)
@@ -29,9 +29,17 @@ InsetFootlike::InsetFootlike()
        font.decSize();
        font.setColor(LColor::collapsable);
        setLabelFont(font);
-#if 0
-       setAutoCollapse(false);
-#endif
+}
+
+
+InsetFootlike::InsetFootlike(InsetFootlike const & in, bool same_id)
+       : InsetCollapsable(in, same_id)
+{
+       LyXFont font(LyXFont::ALL_SANE);
+       font.decSize();
+       font.decSize();
+       font.setColor(LColor::collapsable);
+       setLabelFont(font);
 }
 
 
index d41829b8e3ef40ba9285a19b03d9f74d66a72610..1e678ff90997d4bf5e678633897697be8f035e82 100644 (file)
@@ -30,6 +30,8 @@ public:
        ///
        InsetFootlike();
        ///
+       InsetFootlike(InsetFootlike const &, bool same_id = false);
+       ///
        void write(Buffer const * buf, std::ostream & os) const;
        ///
        bool insetAllowed(Inset::Code) const;
index 80980c9fd15e7e9c96feebda74c9a2405466a2e9..201c333a7ca6af9f0d907e4f0441d55be98af7a1 100644 (file)
@@ -32,6 +32,20 @@ InsetMarginal::InsetMarginal()
 }
 
 
+InsetMarginal::InsetMarginal(InsetMarginal const & in, bool same_id)
+       : InsetFootlike(in, same_id)
+{
+       setLabel(_("margin"));
+       setInsetName("Marginal");
+}
+
+
+Inset * InsetMarginal::clone(Buffer const &, bool same_id) const
+{
+       return new InsetMarginal(*const_cast<InsetMarginal *>(this), same_id);
+}
+
+
 string const InsetMarginal::editMessage() const
 {
        return _("Opened Marginal Note Inset");
index 09ae022f6e70cf2de77518eb80c1788a7d06743a..10329a97127ffcede2b96d9332dcaa01a8f932df 100644 (file)
@@ -26,6 +26,10 @@ public:
        ///
        InsetMarginal();
        ///
+       InsetMarginal(InsetMarginal const &, bool same_id = false);
+       ///
+       Inset * clone(Buffer const &, bool same_id = false) const;
+       ///
        Inset::Code lyxCode() const { return Inset::MARGIN_CODE; }
        ///
        int latex(Buffer const *, std::ostream &, bool fragile, bool fp) const;
index a27c71c0ce6a30c0285bc0f7fd9c68f0edee9261..7fa321f80124d27637fcc4b45ec14745bd9f16e1 100644 (file)
@@ -33,11 +33,7 @@ void InsetNote::init()
        font.decSize();
        font.setColor(LColor::note);
        setLabelFont(font);
-#if 0
-       setAutoCollapse(false);
-#endif
        setBackgroundColor(LColor::note);
-
        setLabel(_("note"));
        setInsetName("Note");
 }
@@ -50,6 +46,19 @@ InsetNote::InsetNote()
 }
 
 
+InsetNote::InsetNote(InsetNote const & in, bool same_id)
+       : InsetCollapsable(in, same_id)
+{
+       init();
+}
+
+
+Inset * InsetNote::clone(Buffer const &, bool same_id) const
+{
+       return new InsetNote(*const_cast<InsetNote *>(this), same_id);
+}
+
+
 InsetNote::InsetNote(Buffer const * buf, string const & contents, 
                     bool collapsed)
        : InsetCollapsable(collapsed)
index f4f103f18cd73d714bb400c1daa056e6d0d79ff3..5d5a7b16db4688f8a99c4b70818935031c5de5cc 100644 (file)
@@ -25,6 +25,10 @@ class InsetNote : public InsetCollapsable {
 public:
        /// 
        InsetNote();
+       ///
+       InsetNote(InsetNote const &, bool same_id = false);
+       ///
+       Inset * clone(Buffer const &, bool same_id = false) const;
        /// constructor with initial contents
        InsetNote(Buffer const *, string const & contents, bool collapsed);
        ///
index a2870f1e65dc0da4b2c41d3325d1267e1325384c..536851c07478f78d1acd7e2b73f3d7a9dfc1b6ba 100644 (file)
@@ -1801,7 +1801,7 @@ LyXText * InsetText::getLyXText(BufferView const * lbv,
                        return the_locking_inset->getLyXText(bv);
                }
                return cached_text.get();
-       } else if (it->second.remove) {
+       } else if (it != cache.end() && it->second.remove) {
                if (locked) {
                        saveLyXTextState(it->second.text.get());
                } else {
index 77f31cf93f4d577e322ba16d5f66cd9c014edede..09e4c0e8079c8c4e21973a6c7a2db6692dde7805 100644 (file)
@@ -29,6 +29,8 @@ Language const * english_language;
 Language const * default_language;
 Language ignore_lang("ignore", "ignore", "Ignore", false, 0, "ignore", "");
 Language const * ignore_language = &ignore_lang;
+Language inherit_lang("inherit", "inherit", "Inherit", false, 0, "inherit", "");
+Language const * inherit_language = &inherit_lang;
 
 void Languages::setDefaults()
 {
index e1e82776923f62199b0fe152481ce91287666628..fff0aa636d214d80f5ecb5df3447653f3f378593 100644 (file)
@@ -116,5 +116,6 @@ extern Languages languages;
 extern Language const * default_language;
 extern Language const * english_language;
 extern Language const * ignore_language;
+extern Language const * inherit_language;
 
 #endif
index 27efc567d46a80a833a3523a67c4f1122cc99b45..c36558ab04b9d8497ad34061c52e60fbafe913ed 100644 (file)
@@ -775,9 +775,9 @@ bool LyXTextClass::do_readStyle(LyXLex & lexrc, LyXLayout & lay)
        if (!lay.Read(lexrc, *this)) {
                // Reslove fonts
                lay.resfont = lay.font;
-               lay.resfont.realize(defaultfont());
+               lay.resfont.realize(defaultfont(), default_language);
                lay.reslabelfont = lay.labelfont;
-               lay.reslabelfont.realize(defaultfont());
+               lay.reslabelfont.realize(defaultfont(), default_language);
                return false; // no errors
        } 
        lyxerr << "Error parsing style `" << lay.name() << "'" << endl;
@@ -938,7 +938,8 @@ bool LyXTextClass::Read(string const & filename, bool merge)
                        if (!defaultfont_.resolved()) {
                                lexrc.printError("Warning: defaultfont should "
                                                 "be fully instantiated!");
-                               defaultfont_.realize(LyXFont(LyXFont::ALL_SANE));
+                               defaultfont_.realize(LyXFont(LyXFont::ALL_SANE),
+                                                    default_language);
                        }
                        break;
 
index de4d615face303227ded968a7d3b04bf39a7a369..44f11167ab71d3a4085f9bd37b392bfcfcd6552f 100644 (file)
@@ -169,7 +169,7 @@ bool LyXFont::FontBits::operator!=(LyXFont::FontBits const & fb1) const
 
 
 LyXFont::LyXFont(LyXFont::FONT_INIT1)
-       : bits(inherit), lang(ignore_language)
+       : bits(inherit), lang(inherit_language)
 {}
 
 
@@ -409,8 +409,7 @@ LyXFont::FONT_MISC_STATE LyXFont::setMisc(FONT_MISC_STATE newfont,
 
 
 /// Updates font settings according to request
-void LyXFont::update(LyXFont const & newfont,
-                    Language const * document_language, bool toggleall)
+void LyXFont::update(LyXFont const & newfont, bool toggleall)
 {
        if (newfont.family() == family() && toggleall)
                setFamily(INHERIT_FAMILY); // toggle 'back'
@@ -459,10 +458,7 @@ void LyXFont::update(LyXFont const & newfont,
        
        setNumber(setMisc(newfont.number(), number()));
        if (newfont.language() == language() && toggleall)
-               if (language() == document_language)
-                       setLanguage(default_language);
-               else
-                       setLanguage(document_language);
+               setLanguage(inherit_language);
        else if (newfont.language() != ignore_language)
                setLanguage(newfont.language());
 
@@ -496,12 +492,24 @@ void LyXFont::reduce(LyXFont const & tmplt)
 #endif
        if (color() == tmplt.color())
                setColor(LColor::inherit);
+       if (language() == tmplt.language())
+               setLanguage(inherit_language);
 }
 
 
 /// Realize font from a template
-LyXFont & LyXFont::realize(LyXFont const & tmplt)
+LyXFont & LyXFont::realize(LyXFont const & tmplt, Language const * deflang)
 {
+       if (language() == inherit_language) {
+               if (tmplt.language() == inherit_language ||
+                       tmplt.language() == ignore_language ||
+                       tmplt.language() == default_language)
+               {
+                       setLanguage(deflang);
+               } else {
+                       setLanguage(tmplt.language());
+               }
+       }
        if (bits == inherit) {
                bits = tmplt.bits;
                return *this;
@@ -550,7 +558,8 @@ bool LyXFont::resolved() const
 #ifndef NO_LATEX
                latex() != INHERIT &&
 #endif
-               color() != LColor::inherit);
+               color() != LColor::inherit &&
+               language() != inherit_language);
 }
 
 
@@ -762,7 +771,8 @@ LyXFont & LyXFont::lyxRead(LyXLex & lex)
 
 
 /// Writes the changes from this font to orgfont in .lyx format in file
-void LyXFont::lyxWriteChanges(LyXFont const & orgfont, ostream & os) const
+void LyXFont::lyxWriteChanges(LyXFont const & orgfont,
+                              Language const * doclang, ostream & os) const
 {
        os << "\n";
        if (orgfont.family() != family()) {
@@ -829,7 +839,9 @@ void LyXFont::lyxWriteChanges(LyXFont const & orgfont, ostream & os) const
                os << "\\color " << col_str << "\n";
        }
        if (orgfont.language() != language()) {
-               if (language())
+               if (language() == inherit_language)
+                       os << "\\lang " << doclang->lang() << "\n";
+               else if (language())
                        os << "\\lang " << language()->lang() << "\n";
                else
                        os << "\\lang unknown\n";
@@ -936,7 +948,7 @@ int LyXFont::latexWriteStartChanges(ostream & os, LyXFont const & base,
 // Returns number of chars written
 // This one corresponds to latexWriteStartChanges(). (Asger)
 int LyXFont::latexWriteEndChanges(ostream & os, LyXFont const & base,
-                                 LyXFont const & next) const
+                                  LyXFont const & next) const
 {
        int count = 0;
        bool env = false;
index c690f19e3f33646a2870570da2da130fc819cf67..ccfe7e54669e563c7a0c4451d59dbdc3cac6cf17 100644 (file)
@@ -262,16 +262,14 @@ public:
            a INHERIT_FAMILY was asked for.  This is necessary for the
            toggle-user-defined-style button on the toolbar.
        */
-       void update(LyXFont const & newfont, 
-                   Language const * default_lang,
-                   bool toggleall = false);
+       void update(LyXFont const & newfont, bool toggleall = false);
  
        /** Reduce font to fall back to template where possible.
            Equal fields are reduced to INHERIT */
        void reduce(LyXFont const & tmplt);
  
        /// Realize font from a template (INHERIT are realized)
-       LyXFont & realize(LyXFont const & tmplt);
+       LyXFont & realize(LyXFont const & tmplt, Language const * language);
 
        /// Is a given font fully resolved?
        bool resolved() const;
@@ -280,7 +278,8 @@ public:
        LyXFont & lyxRead(LyXLex &);
  
        /// Writes the changes from this font to orgfont in .lyx format in file
-       void lyxWriteChanges(LyXFont const & orgfont, std::ostream &) const;
+       void lyxWriteChanges(LyXFont const & orgfont, Language const * doclang,
+                            std::ostream &) const;
 
        /** Writes the head of the LaTeX needed to change to this font.
            Writes to string, the head of the LaTeX needed to change
index 6c904bf92daf4ba6d893ac38410fba41adfd5197..d272c778cbf3645106a7c8b83ef5121e05e2c0ed 100644 (file)
@@ -164,8 +164,8 @@ Paragraph::~Paragraph()
 
 
 void Paragraph::writeFile(Buffer const * buf, ostream & os,
-                            BufferParams const & bparams,
-                            depth_type dth) const
+                          BufferParams const & bparams,
+                          depth_type dth) const
 {
        // The beginning or end of a deeper (i.e. nested) area?
        if (dth != params().depth()) {
@@ -251,7 +251,7 @@ void Paragraph::writeFile(Buffer const * buf, ostream & os,
                // Write font changes
                LyXFont font2 = getFontSettings(bparams, i);
                if (font2 != font1) {
-                       font2.lyxWriteChanges(font1, os);
+                       font2.lyxWriteChanges(font1, bparams.language, os);
                        column = 0;
                        font1 = font2;
                }
@@ -349,6 +349,10 @@ void Paragraph::validate(LaTeXFeatures & features) const
                case LColor::none:
                case LColor::inherit:
                case LColor::ignore:
+                       // probably we should put here all interface colors used for
+                       // font displaying! For now I just add this ones I know of (Jug)
+               case LColor::latex:
+               case LColor::note:
                        break;
                default:
                        features.color = true;
@@ -358,7 +362,10 @@ void Paragraph::validate(LaTeXFeatures & features) const
                }
 
                Language const * language = cit->font().language();
-               if (language->babel() != doc_language->babel()) {
+               if (language != ignore_language &&
+                       language != inherit_language &&
+                       language->babel() != doc_language->babel())
+               {
                        features.UsedLanguages.insert(language);
                        lyxerr[Debug::LATEX] << "Found language "
                                             << language->babel() << endl;
@@ -434,8 +441,11 @@ bool Paragraph::insertFromMinibuffer(Paragraph::size_type pos)
                return false;
        if (minibuffer_char == Paragraph::META_INSET)
                insertInset(pos, minibuffer_inset, minibuffer_font);
-       else
-               insertChar(pos, minibuffer_char, minibuffer_font);
+       else {
+               LyXFont f = minibuffer_font;
+               if (checkInsertChar(f))
+                       insertChar(pos, minibuffer_char, f);
+       }
        return true;
 }
 
@@ -458,6 +468,14 @@ void Paragraph::erase(Paragraph::size_type pos)
 }
 
 
+bool Paragraph::checkInsertChar(LyXFont & font)
+{
+       if (pimpl_->inset_owner)
+               return pimpl_->inset_owner->checkInsertChar(font);
+       return true;
+}
+
+
 void Paragraph::insertChar(Paragraph::size_type pos,
                              Paragraph::value_type c)
 {
@@ -550,7 +568,7 @@ Inset const * Paragraph::getInset(Paragraph::size_type pos) const
 
 // Gets uninstantiated font setting at position.
 LyXFont const Paragraph::getFontSettings(BufferParams const & bparams,
-                                           Paragraph::size_type pos) const
+                                         Paragraph::size_type pos) const
 {
        lyx::Assert(pos <= size());
        
@@ -558,13 +576,17 @@ LyXFont const Paragraph::getFontSettings(BufferParams const & bparams,
        Pimpl::FontList::const_iterator cit = lower_bound(pimpl_->fontlist.begin(),
                                                   pimpl_->fontlist.end(),
                                                   search_font, Pimpl::matchFT());
-       if (cit != pimpl_->fontlist.end())
-               return cit->font();
-       
-       if (pos == size() && size())
-               return getFontSettings(bparams, pos - 1);
-       
-       return LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
+       LyXFont retfont;
+       if (cit != pimpl_->fontlist.end()) {
+               retfont = cit->font();
+       } else if (pos == size() && size()) {
+               retfont = getFontSettings(bparams, pos - 1);
+       } else
+               retfont = LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
+       if (retfont.language() == inherit_language)
+               retfont.setLanguage(bparams.language);
+
+       return retfont;
 }
 
 
@@ -605,7 +627,7 @@ LyXFont const Paragraph::getFont(BufferParams const & bparams,
                else
                        layoutfont = layout.font;
                tmpfont = getFontSettings(bparams, pos);
-               tmpfont.realize(layoutfont);
+               tmpfont.realize(layoutfont, bparams.language);
        } else {
                // process layoutfont for pos == -1 and labelfont for pos < -1
                if (pos == -1)
@@ -623,14 +645,14 @@ LyXFont const Paragraph::getFont(BufferParams const & bparams,
                if (par) {
                        tmpfont.realize(textclasslist.
                                        Style(bparams.textclass,
-                                             par->getLayout()).font);
+                                             par->getLayout()).font, bparams.language);
                        par_depth = par->getDepth();
                }
        }
 
        tmpfont.realize(textclasslist
                        .TextClass(bparams.textclass)
-                       .defaultfont());
+                       .defaultfont(), bparams.language);
        return tmpfont;
 }
 
@@ -1235,6 +1257,8 @@ Paragraph * Paragraph::TeXOnePar(Buffer const * buf,
        Language const * doc_language = bparams.language;
        Language const * previous_language = previous_
                ? previous_->getParLanguage(bparams) : doc_language;
+       if (language == ignore_language || language == inherit_language)
+               lyxerr << "1:" << language->lang() << endl;
        if (language->babel() != doc_language->babel() &&
            language->babel() != previous_language->babel()) {
                os << subst(lyxrc.language_command_begin, "$$lang",
@@ -1244,13 +1268,14 @@ Paragraph * Paragraph::TeXOnePar(Buffer const * buf,
        }
 
        if (bparams.inputenc == "auto" &&
-           language->encoding() != previous_language->encoding()) {
+           language->encoding() != previous_language->encoding())
+       {
                os << "\\inputencoding{"
                   << language->encoding()->LatexName()
                   << "}" << endl;
                texrow.newline();
        }
-       
+
        switch (style.latextype) {
        case LATEX_COMMAND:
                os << '\\'
@@ -1295,8 +1320,9 @@ Paragraph * Paragraph::TeXOnePar(Buffer const * buf,
                os << "}";
 
        if (language->babel() != doc_language->babel() &&
-           (!next_
-            || next_->getParLanguage(bparams)->babel() != language->babel())) {
+           (!next_ ||
+            next_->getParLanguage(bparams)->babel() != language->babel()))
+       {
                os << endl 
                   << subst(lyxrc.language_command_end, "$$lang",
                            doc_language->babel());
@@ -1550,15 +1576,24 @@ bool Paragraph::simpleTeXOnePar(Buffer const * buf,
 
        // If we have an open font definition, we have to close it
        if (open_font) {
+#ifdef FIXED_LANGUAGE_END_DETECTION
                if (next_) {
                        running_font
                                .latexWriteEndChanges(os, basefont,
-                                                     next_->getFont(bparams,
-                                                                    0));
+                                                     next_->getFont(bparams,
+                                                     0));
                } else {
                        running_font.latexWriteEndChanges(os, basefont,
-                                                         basefont);
+                                                         basefont);
                }
+#else
+#ifdef WITH_WARNINGS
+#warning For now we ALWAYS have to close the foreign font settings if they are
+#warning there as we start another \selectlanguage with the next paragraph if
+#warning we are in need of this. This should be fixed sometime (Jug)
+#endif
+               running_font.latexWriteEndChanges(os, basefont,  basefont);
+#endif
        }
 
        // Needed if there is an optional argument but no contents.
@@ -1794,9 +1829,13 @@ bool Paragraph::isWord(size_type pos ) const
 Language const *
 Paragraph::getParLanguage(BufferParams const & bparams) const 
 {
-       if (size() > 0)
-               return getFirstFontSettings().language();
-       else if (previous_)
+       if (size() > 0) {
+               Language const * lang = getFirstFontSettings().language();
+#warning We should make this somewhat better, any ideas? (Jug)
+               if (lang == inherit_language || lang == ignore_language)
+                       lang = bparams.language;
+               return lang;
+       } else if (previous_)
                return previous_->getParLanguage(bparams);
        else
                return bparams.language;
@@ -1828,7 +1867,9 @@ bool Paragraph::isMultiLingual(BufferParams const & bparams)
        Language const * doc_language = bparams.language;
        for (Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
             cit != pimpl_->fontlist.end(); ++cit)
-               if (cit->font().language() != doc_language)
+               if (cit->font().language() != inherit_language &&
+                       cit->font().language() != ignore_language &&
+                       cit->font().language() != doc_language)
                        return true;
        return false;
 }
index ea20d04a6ec3addb5e27e0b99301741d6c4ac467..318fea8caeeee55d64c3543f73de25eff2057a31 100644 (file)
@@ -268,6 +268,8 @@ public:
        ///
        void insertChar(size_type pos, value_type c, LyXFont const &);
        ///
+       bool checkInsertChar(LyXFont &);
+       ///
        void insertInset(size_type pos, Inset * inset);
        ///
        void insertInset(size_type pos, Inset * inset, LyXFont const &);
index 11de551bbaa0848f75f7ea866d025038c46d7325..303559a852df35b30ee1918ea837e2be14864e92 100644 (file)
@@ -564,6 +564,11 @@ void LyXText::draw(BufferView * bview, Row const * row,
                x += lyxfont::width(textstring, font);
        }
 
+#ifdef WITH_WARNINGS
+       if ((font.language() == inherit_language) ||
+               (font.language() == ignore_language))
+               lyxerr << "No this shouldn't happen!\n";
+#endif
        if (lyxrc.mark_foreign_language &&
            font.language() != bview->buffer()->params.language) {
                int const y = offset + row->height() - 1;
index 72c10d5cd32d9eeb6e00c2e82443320f1c6065e8..c61d56219ea49188cbb6af5881c50000d3a5f54d 100644 (file)
@@ -113,7 +113,7 @@ LyXText::~LyXText()
 // If position is -1, we get the layout font of the paragraph.
 // If position is -2, we get the font of the manual label of the paragraph.
 LyXFont const LyXText::getFont(Buffer const * buf, Paragraph * par,
-                              Paragraph::size_type pos) const
+                               Paragraph::size_type pos) const
 {
        LyXLayout const & layout = 
                textclasslist.Style(buf->params.textclass, par->getLayout());
@@ -128,10 +128,10 @@ LyXFont const LyXText::getFont(Buffer const * buf, Paragraph * par,
                                // 1% goes here
                                LyXFont f = par->getFontSettings(buf->params,
                                                                 pos);
-                               return f.realize(layout.reslabelfont);
+                               return f.realize(layout.reslabelfont, buf->params.language);
                        } else {
                                LyXFont f = par->getFontSettings(buf->params, pos);
-                               return f.realize(layout.resfont);
+                               return f.realize(layout.resfont, buf->params.language);
                        }
                        
                } else {
@@ -158,7 +158,7 @@ LyXFont const LyXText::getFont(Buffer const * buf, Paragraph * par,
                        layoutfont = layout.font;
                }
                tmpfont = par->getFontSettings(buf->params, pos);
-               tmpfont.realize(layoutfont);
+               tmpfont.realize(layoutfont, buf->params.language);
        } else {
                // 5% goes here.
                // process layoutfont for pos == -1 and labelfont for pos < -1
@@ -174,12 +174,14 @@ LyXFont const LyXText::getFont(Buffer const * buf, Paragraph * par,
                if (par) {
                        tmpfont.realize(textclasslist.
                                        Style(buf->params.textclass,
-                                             par->getLayout()).font);
+                                             par->getLayout()).font,
+                                                       buf->params.language);
                        par_depth = par->getDepth();
                }
        }
 
-       tmpfont.realize(textclasslist.TextClass(buf->params.textclass).defaultfont());
+       tmpfont.realize(textclasslist.TextClass(buf->params.textclass).defaultfont(),
+                       buf->params.language);
 
        return tmpfont;
 }
@@ -191,7 +193,7 @@ void LyXText::setCharFont(BufferView * bv, Paragraph * par,
 {
        Buffer const * buf = bv->buffer();
        LyXFont font = getFont(buf, par, pos);
-       font.update(fnt, buf->params.language, toggleall);
+       font.update(fnt, toggleall);
        // Let the insets convert their font
        if (par->getChar(pos) == Paragraph::META_INSET) {
                Inset * inset = par->getInset(pos);
@@ -224,12 +226,14 @@ void LyXText::setCharFont(BufferView * bv, Paragraph * par,
                        tp = tp->outerHook();
                        if (tp)
                                layoutfont.realize(textclasslist.
-                                                  Style(buf->params.textclass,
-                                                        tp->getLayout()).font);
+                                                  Style(buf->params.textclass,
+                                                        tp->getLayout()).font,
+                                                  buf->params.language);
                }
        }
 
-       layoutfont.realize(textclasslist.TextClass(buf->params.textclass).defaultfont());
+       layoutfont.realize(textclasslist.TextClass(buf->params.textclass).defaultfont(),
+                          buf->params.language);
 
        // Now, reduce font against full layout font
        font.reduce(layoutfont);
@@ -266,12 +270,14 @@ void LyXText::setCharFont(Buffer const * buf, Paragraph * par,
                        tp = tp->outerHook();
                        if (tp)
                                layoutfont.realize(textclasslist.
-                                                  Style(buf->params.textclass,
-                                                        tp->getLayout()).font);
+                                                  Style(buf->params.textclass,
+                                                        tp->getLayout()).font,
+                                                  buf->params.language);
                }
        }
 
-       layoutfont.realize(textclasslist.TextClass(buf->params.textclass).defaultfont());
+       layoutfont.realize(textclasslist.TextClass(buf->params.textclass).defaultfont(),
+                          buf->params.language);
 
        // Now, reduce font against full layout font
        font.reduce(layoutfont);
@@ -674,15 +680,14 @@ void LyXText::setFont(BufferView * bview, LyXFont const & font, bool toggleall)
                else
                        layoutfont = getFont(bview->buffer(), cursor.par(),-1);
                // Update current font
-               real_current_font.update(font,
-                                        bview->buffer()->params.language,
-                                        toggleall);
+               real_current_font.update(font, toggleall);
 
                // Reduce to implicit settings
                current_font = real_current_font;
                current_font.reduce(layoutfont);
                // And resolve it completely
-               real_current_font.realize(layoutfont);
+               real_current_font.realize(layoutfont,
+                                         bview->buffer()->params.language);
                return;
        }
 
@@ -1034,7 +1039,7 @@ void LyXText::toggleFree(BufferView * bview,
        // is disabled.
        LyXCursor resetCursor = cursor;
        bool implicitSelection = (font.language() == ignore_language
-                                 && font.number() == LyXFont::IGNORE)
+                                 && font.number() == LyXFont::IGNORE)
                ? selectWordWhenUnderCursor(bview) : false;
 
        // Set font