From: Jürgen Vigna Date: Fri, 27 Jul 2001 12:03:36 +0000 (+0000) Subject: This should clean up the language stuff a bit and a small new check for X-Git-Tag: 1.6.10~20979 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=d32d0cbb9552186e0d69ee2320baf2570402fc72;p=features.git This should clean up the language stuff a bit and a small new check for 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 --- diff --git a/src/ChangeLog b/src/ChangeLog index 2430c4e776..087933c379 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,38 @@ +2001-07-27 Juergen Vigna + + * 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 + + * 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 * LaTeXFeatures.C (getPackages): clean-up a little of the natbib code. diff --git a/src/CutAndPaste.C b/src/CutAndPaste.C index 36af28fbc7..428c9c9980 100644 --- a/src/CutAndPaste.C +++ b/src/CutAndPaste.C @@ -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; diff --git a/src/bufferparams.C b/src/bufferparams.C index 157b69fe55..9524c5c82e 100644 --- a/src/bufferparams.C +++ b/src/bufferparams.C @@ -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'; diff --git a/src/bufferview_funcs.C b/src/bufferview_funcs.C index f44336ed11..4c81cdd459 100644 --- a/src/bufferview_funcs.C +++ b/src/bufferview_funcs.C @@ -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); } diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 3a044554a0..801707c1b5 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,16 @@ +2001-07-27 Juergen Vigna + + * 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 * insetminipage.C (read): handle missing parameters more gracefully diff --git a/src/insets/inset.h b/src/insets/inset.h index b0951ffe3e..cd778db2bd 100644 --- a/src/insets/inset.h +++ b/src/insets/inset.h @@ -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 /// diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index 2b9bdcd9d0..197c782f4c 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -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(this), - same_id); -} - - bool InsetCollapsable::insertInset(BufferView * bv, Inset * in) { if (!insetAllowed(in->lyxCode())) { diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index 2122b8a3a5..ece8245217 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -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: /// diff --git a/src/insets/insetert.C b/src/insets/insetert.C index 4b2d281bc9..4f2a75c964 100644 --- a/src/insets/insetert.C +++ b/src/insets/insetert.C @@ -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(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; +} diff --git a/src/insets/insetert.h b/src/insets/insetert.h index eed211de99..546b6fe46e 100644 --- a/src/insets/insetert.h +++ b/src/insets/insetert.h @@ -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(); diff --git a/src/insets/insetfoot.C b/src/insets/insetfoot.C index 94a50917e9..a9a103db49 100644 --- a/src/insets/insetfoot.C +++ b/src/insets/insetfoot.C @@ -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(this), same_id); +} + + string const InsetFoot::editMessage() const { return _("Opened Footnote Inset"); diff --git a/src/insets/insetfoot.h b/src/insets/insetfoot.h index 2a64b91872..5f10835f91 100644 --- a/src/insets/insetfoot.h +++ b/src/insets/insetfoot.h @@ -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; diff --git a/src/insets/insetfootlike.C b/src/insets/insetfootlike.C index ea4da1ef0f..edfd20dafb 100644 --- a/src/insets/insetfootlike.C +++ b/src/insets/insetfootlike.C @@ -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); } diff --git a/src/insets/insetfootlike.h b/src/insets/insetfootlike.h index d41829b8e3..1e678ff909 100644 --- a/src/insets/insetfootlike.h +++ b/src/insets/insetfootlike.h @@ -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; diff --git a/src/insets/insetmarginal.C b/src/insets/insetmarginal.C index 80980c9fd1..201c333a7c 100644 --- a/src/insets/insetmarginal.C +++ b/src/insets/insetmarginal.C @@ -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(this), same_id); +} + + string const InsetMarginal::editMessage() const { return _("Opened Marginal Note Inset"); diff --git a/src/insets/insetmarginal.h b/src/insets/insetmarginal.h index 09ae022f6e..10329a9712 100644 --- a/src/insets/insetmarginal.h +++ b/src/insets/insetmarginal.h @@ -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; diff --git a/src/insets/insetnote.C b/src/insets/insetnote.C index a27c71c0ce..7fa321f801 100644 --- a/src/insets/insetnote.C +++ b/src/insets/insetnote.C @@ -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(this), same_id); +} + + InsetNote::InsetNote(Buffer const * buf, string const & contents, bool collapsed) : InsetCollapsable(collapsed) diff --git a/src/insets/insetnote.h b/src/insets/insetnote.h index f4f103f18c..5d5a7b16db 100644 --- a/src/insets/insetnote.h +++ b/src/insets/insetnote.h @@ -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); /// diff --git a/src/insets/insettext.C b/src/insets/insettext.C index a2870f1e65..536851c074 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -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 { diff --git a/src/language.C b/src/language.C index 77f31cf93f..09e4c0e807 100644 --- a/src/language.C +++ b/src/language.C @@ -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() { diff --git a/src/language.h b/src/language.h index e1e8277692..fff0aa636d 100644 --- a/src/language.h +++ b/src/language.h @@ -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 diff --git a/src/layout.C b/src/layout.C index 27efc567d4..c36558ab04 100644 --- a/src/layout.C +++ b/src/layout.C @@ -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; diff --git a/src/lyxfont.C b/src/lyxfont.C index de4d615fac..44f11167ab 100644 --- a/src/lyxfont.C +++ b/src/lyxfont.C @@ -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; diff --git a/src/lyxfont.h b/src/lyxfont.h index c690f19e3f..ccfe7e5466 100644 --- a/src/lyxfont.h +++ b/src/lyxfont.h @@ -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 diff --git a/src/paragraph.C b/src/paragraph.C index 6c904bf92d..d272c778cb 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -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; } diff --git a/src/paragraph.h b/src/paragraph.h index ea20d04a6e..318fea8cae 100644 --- a/src/paragraph.h +++ b/src/paragraph.h @@ -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 &); diff --git a/src/text.C b/src/text.C index 11de551bba..303559a852 100644 --- a/src/text.C +++ b/src/text.C @@ -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; diff --git a/src/text2.C b/src/text2.C index 72c10d5cd3..c61d56219e 100644 --- a/src/text2.C +++ b/src/text2.C @@ -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