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
This commit is contained in:
Jürgen Vigna 2001-07-27 12:03:36 +00:00
parent 811980f739
commit d32d0cbb95
28 changed files with 296 additions and 89 deletions

View 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> 2001-07-25 Angus Leeming <a.leeming@ic.ac.uk>
* LaTeXFeatures.C (getPackages): clean-up a little of the natbib code. * LaTeXFeatures.C (getPackages): clean-up a little of the natbib code.

View File

@ -89,8 +89,9 @@ void BufferParams::writeFile(ostream & os) const
} }
/* then the text parameters */ /* then the text parameters */
os << "\\language " << language->lang() if (language != ignore_language)
<< "\n\\inputencoding " << inputenc os << "\\language " << language->lang() << '\n';
os << "\\inputencoding " << inputenc
<< "\n\\fontscheme " << fonts << "\n\\fontscheme " << fonts
<< "\n\\graphics " << graphicsDriver << '\n'; << "\n\\graphics " << graphicsDriver << '\n';

View File

@ -129,7 +129,7 @@ void Roman(BufferView * bv)
void StyleReset(BufferView * bv) void StyleReset(BufferView * bv)
{ {
LyXFont font(LyXFont::ALL_INHERIT, ignore_language); LyXFont font(LyXFont::ALL_INHERIT);
ToggleAndShow(bv, font); ToggleAndShow(bv, font);
} }

View 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> 2001-07-26 Lars Gullik Bjønnes <larsbj@birdstep.com>
* insetminipage.C (read): handle missing parameters more gracefully * insetminipage.C (read): handle missing parameters more gracefully

View File

@ -287,6 +287,9 @@ public:
#endif #endif
/// close the inset /// close the inset
virtual void close(BufferView *) {} 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: protected:
/// ///
@ -444,6 +447,9 @@ public:
virtual bool nodraw() const { virtual bool nodraw() const {
return block_drawing_; 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 // needed for spellchecking text
/// ///

View 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) bool InsetCollapsable::insertInset(BufferView * bv, Inset * in)
{ {
if (!insetAllowed(in->lyxCode())) { if (!insetAllowed(in->lyxCode())) {

View File

@ -46,8 +46,6 @@ public:
/// ///
InsetCollapsable(InsetCollapsable const & in, bool same_id = false); InsetCollapsable(InsetCollapsable const & in, bool same_id = false);
/// ///
Inset * clone(Buffer const &, bool same_id = false) const;
void read(Buffer const *, LyXLex &); void read(Buffer const *, LyXLex &);
/// ///
void write(Buffer const *, std::ostream &) const; void write(Buffer const *, std::ostream &) const;
@ -70,7 +68,7 @@ public:
/// ///
bool insertInset(BufferView *, Inset * inset); bool insertInset(BufferView *, Inset * inset);
/// ///
bool insetAllowed(Inset::Code code) const { virtual bool insetAllowed(Inset::Code code) const {
return inset.insetAllowed(code); return inset.insetAllowed(code);
} }
/// ///
@ -203,6 +201,9 @@ public:
bool const & cs = true, bool const & mw = false) { bool const & cs = true, bool const & mw = false) {
return inset.searchBackward(bv, str, cs, mw); 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: protected:
/// ///

View File

@ -28,7 +28,6 @@ using std::ostream;
void InsetERT::init() void InsetERT::init()
{ {
setButtonLabel(); setButtonLabel();
labelfont = LyXFont(LyXFont::ALL_SANE); labelfont = LyXFont(LyXFont::ALL_SANE);
labelfont.decSize(); labelfont.decSize();
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) InsetERT::InsetERT(string const & contents, bool collapsed)
: InsetCollapsable(collapsed) : InsetCollapsable(collapsed)
{ {
@ -238,3 +250,13 @@ void InsetERT::setButtonLabel()
setLabel(_("666")); 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;
}

View File

@ -30,8 +30,14 @@ public:
/// ///
InsetERT(); InsetERT();
/// ///
InsetERT(InsetERT const &, bool same_id = false);
///
Inset * clone(Buffer const &, bool same_id = false) const;
///
InsetERT(string const & contents, bool collapsed); InsetERT(string const & contents, bool collapsed);
/// ///
Inset::Code lyxCode() const { return Inset::ERT_CODE; }
///
void read(Buffer const * buf, LyXLex & lex); void read(Buffer const * buf, LyXLex & lex);
/// ///
void write(Buffer const * buf, std::ostream & os) const; void write(Buffer const * buf, std::ostream & os) const;
@ -63,6 +69,9 @@ public:
/// ///
UpdatableInset::RESULT localDispatch(BufferView *, kb_action, UpdatableInset::RESULT localDispatch(BufferView *, kb_action,
string const &); string const &);
///
bool checkInsertChar(LyXFont &);
private: private:
/// ///
void init(); void init();

View 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 string const InsetFoot::editMessage() const
{ {
return _("Opened Footnote Inset"); return _("Opened Footnote Inset");

View File

@ -28,6 +28,10 @@ public:
/// ///
InsetFoot(); 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; } Inset::Code lyxCode() const { return Inset::FOOT_CODE; }
/// ///
int latex(Buffer const *, std::ostream &, bool fragile, bool fp) const; int latex(Buffer const *, std::ostream &, bool fragile, bool fp) const;

View File

@ -29,9 +29,17 @@ InsetFootlike::InsetFootlike()
font.decSize(); font.decSize();
font.setColor(LColor::collapsable); font.setColor(LColor::collapsable);
setLabelFont(font); 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);
} }

View File

@ -30,6 +30,8 @@ public:
/// ///
InsetFootlike(); InsetFootlike();
/// ///
InsetFootlike(InsetFootlike const &, bool same_id = false);
///
void write(Buffer const * buf, std::ostream & os) const; void write(Buffer const * buf, std::ostream & os) const;
/// ///
bool insetAllowed(Inset::Code) const; bool insetAllowed(Inset::Code) const;

View 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 string const InsetMarginal::editMessage() const
{ {
return _("Opened Marginal Note Inset"); return _("Opened Marginal Note Inset");

View File

@ -26,6 +26,10 @@ public:
/// ///
InsetMarginal(); 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; } Inset::Code lyxCode() const { return Inset::MARGIN_CODE; }
/// ///
int latex(Buffer const *, std::ostream &, bool fragile, bool fp) const; int latex(Buffer const *, std::ostream &, bool fragile, bool fp) const;

View File

@ -33,11 +33,7 @@ void InsetNote::init()
font.decSize(); font.decSize();
font.setColor(LColor::note); font.setColor(LColor::note);
setLabelFont(font); setLabelFont(font);
#if 0
setAutoCollapse(false);
#endif
setBackgroundColor(LColor::note); setBackgroundColor(LColor::note);
setLabel(_("note")); setLabel(_("note"));
setInsetName("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, InsetNote::InsetNote(Buffer const * buf, string const & contents,
bool collapsed) bool collapsed)
: InsetCollapsable(collapsed) : InsetCollapsable(collapsed)

View File

@ -25,6 +25,10 @@ class InsetNote : public InsetCollapsable {
public: public:
/// ///
InsetNote(); InsetNote();
///
InsetNote(InsetNote const &, bool same_id = false);
///
Inset * clone(Buffer const &, bool same_id = false) const;
/// constructor with initial contents /// constructor with initial contents
InsetNote(Buffer const *, string const & contents, bool collapsed); InsetNote(Buffer const *, string const & contents, bool collapsed);
/// ///

View File

@ -1801,7 +1801,7 @@ LyXText * InsetText::getLyXText(BufferView const * lbv,
return the_locking_inset->getLyXText(bv); return the_locking_inset->getLyXText(bv);
} }
return cached_text.get(); return cached_text.get();
} else if (it->second.remove) { } else if (it != cache.end() && it->second.remove) {
if (locked) { if (locked) {
saveLyXTextState(it->second.text.get()); saveLyXTextState(it->second.text.get());
} else { } else {

View File

@ -29,6 +29,8 @@ Language const * english_language;
Language const * default_language; Language const * default_language;
Language ignore_lang("ignore", "ignore", "Ignore", false, 0, "ignore", ""); Language ignore_lang("ignore", "ignore", "Ignore", false, 0, "ignore", "");
Language const * ignore_language = &ignore_lang; Language const * ignore_language = &ignore_lang;
Language inherit_lang("inherit", "inherit", "Inherit", false, 0, "inherit", "");
Language const * inherit_language = &inherit_lang;
void Languages::setDefaults() void Languages::setDefaults()
{ {

View File

@ -116,5 +116,6 @@ extern Languages languages;
extern Language const * default_language; extern Language const * default_language;
extern Language const * english_language; extern Language const * english_language;
extern Language const * ignore_language; extern Language const * ignore_language;
extern Language const * inherit_language;
#endif #endif

View File

@ -775,9 +775,9 @@ bool LyXTextClass::do_readStyle(LyXLex & lexrc, LyXLayout & lay)
if (!lay.Read(lexrc, *this)) { if (!lay.Read(lexrc, *this)) {
// Reslove fonts // Reslove fonts
lay.resfont = lay.font; lay.resfont = lay.font;
lay.resfont.realize(defaultfont()); lay.resfont.realize(defaultfont(), default_language);
lay.reslabelfont = lay.labelfont; lay.reslabelfont = lay.labelfont;
lay.reslabelfont.realize(defaultfont()); lay.reslabelfont.realize(defaultfont(), default_language);
return false; // no errors return false; // no errors
} }
lyxerr << "Error parsing style `" << lay.name() << "'" << endl; lyxerr << "Error parsing style `" << lay.name() << "'" << endl;
@ -938,7 +938,8 @@ bool LyXTextClass::Read(string const & filename, bool merge)
if (!defaultfont_.resolved()) { if (!defaultfont_.resolved()) {
lexrc.printError("Warning: defaultfont should " lexrc.printError("Warning: defaultfont should "
"be fully instantiated!"); "be fully instantiated!");
defaultfont_.realize(LyXFont(LyXFont::ALL_SANE)); defaultfont_.realize(LyXFont(LyXFont::ALL_SANE),
default_language);
} }
break; break;

View File

@ -169,7 +169,7 @@ bool LyXFont::FontBits::operator!=(LyXFont::FontBits const & fb1) const
LyXFont::LyXFont(LyXFont::FONT_INIT1) 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 /// Updates font settings according to request
void LyXFont::update(LyXFont const & newfont, void LyXFont::update(LyXFont const & newfont, bool toggleall)
Language const * document_language, bool toggleall)
{ {
if (newfont.family() == family() && toggleall) if (newfont.family() == family() && toggleall)
setFamily(INHERIT_FAMILY); // toggle 'back' setFamily(INHERIT_FAMILY); // toggle 'back'
@ -459,10 +458,7 @@ void LyXFont::update(LyXFont const & newfont,
setNumber(setMisc(newfont.number(), number())); setNumber(setMisc(newfont.number(), number()));
if (newfont.language() == language() && toggleall) if (newfont.language() == language() && toggleall)
if (language() == document_language) setLanguage(inherit_language);
setLanguage(default_language);
else
setLanguage(document_language);
else if (newfont.language() != ignore_language) else if (newfont.language() != ignore_language)
setLanguage(newfont.language()); setLanguage(newfont.language());
@ -496,12 +492,24 @@ void LyXFont::reduce(LyXFont const & tmplt)
#endif #endif
if (color() == tmplt.color()) if (color() == tmplt.color())
setColor(LColor::inherit); setColor(LColor::inherit);
if (language() == tmplt.language())
setLanguage(inherit_language);
} }
/// Realize font from a template /// 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) { if (bits == inherit) {
bits = tmplt.bits; bits = tmplt.bits;
return *this; return *this;
@ -550,7 +558,8 @@ bool LyXFont::resolved() const
#ifndef NO_LATEX #ifndef NO_LATEX
latex() != INHERIT && latex() != INHERIT &&
#endif #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 /// 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"; os << "\n";
if (orgfont.family() != family()) { if (orgfont.family() != family()) {
@ -829,7 +839,9 @@ void LyXFont::lyxWriteChanges(LyXFont const & orgfont, ostream & os) const
os << "\\color " << col_str << "\n"; os << "\\color " << col_str << "\n";
} }
if (orgfont.language() != language()) { if (orgfont.language() != language()) {
if (language()) if (language() == inherit_language)
os << "\\lang " << doclang->lang() << "\n";
else if (language())
os << "\\lang " << language()->lang() << "\n"; os << "\\lang " << language()->lang() << "\n";
else else
os << "\\lang unknown\n"; os << "\\lang unknown\n";

View File

@ -262,16 +262,14 @@ public:
a INHERIT_FAMILY was asked for. This is necessary for the a INHERIT_FAMILY was asked for. This is necessary for the
toggle-user-defined-style button on the toolbar. toggle-user-defined-style button on the toolbar.
*/ */
void update(LyXFont const & newfont, void update(LyXFont const & newfont, bool toggleall = false);
Language const * default_lang,
bool toggleall = false);
/** Reduce font to fall back to template where possible. /** Reduce font to fall back to template where possible.
Equal fields are reduced to INHERIT */ Equal fields are reduced to INHERIT */
void reduce(LyXFont const & tmplt); void reduce(LyXFont const & tmplt);
/// Realize font from a template (INHERIT are realized) /// 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? /// Is a given font fully resolved?
bool resolved() const; bool resolved() const;
@ -280,7 +278,8 @@ public:
LyXFont & lyxRead(LyXLex &); LyXFont & lyxRead(LyXLex &);
/// Writes the changes from this font to orgfont in .lyx format in file /// 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 the head of the LaTeX needed to change to this font.
Writes to string, the head of the LaTeX needed to change Writes to string, the head of the LaTeX needed to change

View File

@ -251,7 +251,7 @@ void Paragraph::writeFile(Buffer const * buf, ostream & os,
// Write font changes // Write font changes
LyXFont font2 = getFontSettings(bparams, i); LyXFont font2 = getFontSettings(bparams, i);
if (font2 != font1) { if (font2 != font1) {
font2.lyxWriteChanges(font1, os); font2.lyxWriteChanges(font1, bparams.language, os);
column = 0; column = 0;
font1 = font2; font1 = font2;
} }
@ -349,6 +349,10 @@ void Paragraph::validate(LaTeXFeatures & features) const
case LColor::none: case LColor::none:
case LColor::inherit: case LColor::inherit:
case LColor::ignore: 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; break;
default: default:
features.color = true; features.color = true;
@ -358,7 +362,10 @@ void Paragraph::validate(LaTeXFeatures & features) const
} }
Language const * language = cit->font().language(); 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); features.UsedLanguages.insert(language);
lyxerr[Debug::LATEX] << "Found language " lyxerr[Debug::LATEX] << "Found language "
<< language->babel() << endl; << language->babel() << endl;
@ -434,8 +441,11 @@ bool Paragraph::insertFromMinibuffer(Paragraph::size_type pos)
return false; return false;
if (minibuffer_char == Paragraph::META_INSET) if (minibuffer_char == Paragraph::META_INSET)
insertInset(pos, minibuffer_inset, minibuffer_font); insertInset(pos, minibuffer_inset, minibuffer_font);
else else {
insertChar(pos, minibuffer_char, minibuffer_font); LyXFont f = minibuffer_font;
if (checkInsertChar(f))
insertChar(pos, minibuffer_char, f);
}
return true; 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, void Paragraph::insertChar(Paragraph::size_type pos,
Paragraph::value_type c) Paragraph::value_type c)
{ {
@ -558,13 +576,17 @@ LyXFont const Paragraph::getFontSettings(BufferParams const & bparams,
Pimpl::FontList::const_iterator cit = lower_bound(pimpl_->fontlist.begin(), Pimpl::FontList::const_iterator cit = lower_bound(pimpl_->fontlist.begin(),
pimpl_->fontlist.end(), pimpl_->fontlist.end(),
search_font, Pimpl::matchFT()); search_font, Pimpl::matchFT());
if (cit != pimpl_->fontlist.end()) LyXFont retfont;
return cit->font(); 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);
if (pos == size() && size()) return retfont;
return getFontSettings(bparams, pos - 1);
return LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
} }
@ -605,7 +627,7 @@ LyXFont const Paragraph::getFont(BufferParams const & bparams,
else else
layoutfont = layout.font; layoutfont = layout.font;
tmpfont = getFontSettings(bparams, pos); tmpfont = getFontSettings(bparams, pos);
tmpfont.realize(layoutfont); tmpfont.realize(layoutfont, bparams.language);
} else { } else {
// process layoutfont for pos == -1 and labelfont for pos < -1 // process layoutfont for pos == -1 and labelfont for pos < -1
if (pos == -1) if (pos == -1)
@ -623,14 +645,14 @@ LyXFont const Paragraph::getFont(BufferParams const & bparams,
if (par) { if (par) {
tmpfont.realize(textclasslist. tmpfont.realize(textclasslist.
Style(bparams.textclass, Style(bparams.textclass,
par->getLayout()).font); par->getLayout()).font, bparams.language);
par_depth = par->getDepth(); par_depth = par->getDepth();
} }
} }
tmpfont.realize(textclasslist tmpfont.realize(textclasslist
.TextClass(bparams.textclass) .TextClass(bparams.textclass)
.defaultfont()); .defaultfont(), bparams.language);
return tmpfont; return tmpfont;
} }
@ -1235,6 +1257,8 @@ Paragraph * Paragraph::TeXOnePar(Buffer const * buf,
Language const * doc_language = bparams.language; Language const * doc_language = bparams.language;
Language const * previous_language = previous_ Language const * previous_language = previous_
? previous_->getParLanguage(bparams) : doc_language; ? previous_->getParLanguage(bparams) : doc_language;
if (language == ignore_language || language == inherit_language)
lyxerr << "1:" << language->lang() << endl;
if (language->babel() != doc_language->babel() && if (language->babel() != doc_language->babel() &&
language->babel() != previous_language->babel()) { language->babel() != previous_language->babel()) {
os << subst(lyxrc.language_command_begin, "$$lang", os << subst(lyxrc.language_command_begin, "$$lang",
@ -1244,7 +1268,8 @@ Paragraph * Paragraph::TeXOnePar(Buffer const * buf,
} }
if (bparams.inputenc == "auto" && if (bparams.inputenc == "auto" &&
language->encoding() != previous_language->encoding()) { language->encoding() != previous_language->encoding())
{
os << "\\inputencoding{" os << "\\inputencoding{"
<< language->encoding()->LatexName() << language->encoding()->LatexName()
<< "}" << endl; << "}" << endl;
@ -1295,8 +1320,9 @@ Paragraph * Paragraph::TeXOnePar(Buffer const * buf,
os << "}"; os << "}";
if (language->babel() != doc_language->babel() && if (language->babel() != doc_language->babel() &&
(!next_ (!next_ ||
|| next_->getParLanguage(bparams)->babel() != language->babel())) { next_->getParLanguage(bparams)->babel() != language->babel()))
{
os << endl os << endl
<< subst(lyxrc.language_command_end, "$$lang", << subst(lyxrc.language_command_end, "$$lang",
doc_language->babel()); doc_language->babel());
@ -1550,6 +1576,7 @@ bool Paragraph::simpleTeXOnePar(Buffer const * buf,
// If we have an open font definition, we have to close it // If we have an open font definition, we have to close it
if (open_font) { if (open_font) {
#ifdef FIXED_LANGUAGE_END_DETECTION
if (next_) { if (next_) {
running_font running_font
.latexWriteEndChanges(os, basefont, .latexWriteEndChanges(os, basefont,
@ -1559,6 +1586,14 @@ bool Paragraph::simpleTeXOnePar(Buffer const * buf,
running_font.latexWriteEndChanges(os, basefont, 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. // Needed if there is an optional argument but no contents.
@ -1794,9 +1829,13 @@ bool Paragraph::isWord(size_type pos ) const
Language const * Language const *
Paragraph::getParLanguage(BufferParams const & bparams) const Paragraph::getParLanguage(BufferParams const & bparams) const
{ {
if (size() > 0) if (size() > 0) {
return getFirstFontSettings().language(); Language const * lang = getFirstFontSettings().language();
else if (previous_) #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); return previous_->getParLanguage(bparams);
else else
return bparams.language; return bparams.language;
@ -1828,7 +1867,9 @@ bool Paragraph::isMultiLingual(BufferParams const & bparams)
Language const * doc_language = bparams.language; Language const * doc_language = bparams.language;
for (Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin(); for (Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin();
cit != pimpl_->fontlist.end(); ++cit) 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 true;
return false; return false;
} }

View File

@ -268,6 +268,8 @@ public:
/// ///
void insertChar(size_type pos, value_type c, LyXFont const &); 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);
/// ///
void insertInset(size_type pos, Inset * inset, LyXFont const &); void insertInset(size_type pos, Inset * inset, LyXFont const &);

View File

@ -564,6 +564,11 @@ void LyXText::draw(BufferView * bview, Row const * row,
x += lyxfont::width(textstring, font); 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 && if (lyxrc.mark_foreign_language &&
font.language() != bview->buffer()->params.language) { font.language() != bview->buffer()->params.language) {
int const y = offset + row->height() - 1; int const y = offset + row->height() - 1;

View File

@ -128,10 +128,10 @@ LyXFont const LyXText::getFont(Buffer const * buf, Paragraph * par,
// 1% goes here // 1% goes here
LyXFont f = par->getFontSettings(buf->params, LyXFont f = par->getFontSettings(buf->params,
pos); pos);
return f.realize(layout.reslabelfont); return f.realize(layout.reslabelfont, buf->params.language);
} else { } else {
LyXFont f = par->getFontSettings(buf->params, pos); LyXFont f = par->getFontSettings(buf->params, pos);
return f.realize(layout.resfont); return f.realize(layout.resfont, buf->params.language);
} }
} else { } else {
@ -158,7 +158,7 @@ LyXFont const LyXText::getFont(Buffer const * buf, Paragraph * par,
layoutfont = layout.font; layoutfont = layout.font;
} }
tmpfont = par->getFontSettings(buf->params, pos); tmpfont = par->getFontSettings(buf->params, pos);
tmpfont.realize(layoutfont); tmpfont.realize(layoutfont, buf->params.language);
} else { } else {
// 5% goes here. // 5% goes here.
// process layoutfont for pos == -1 and labelfont for pos < -1 // 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) { if (par) {
tmpfont.realize(textclasslist. tmpfont.realize(textclasslist.
Style(buf->params.textclass, Style(buf->params.textclass,
par->getLayout()).font); par->getLayout()).font,
buf->params.language);
par_depth = par->getDepth(); 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; return tmpfont;
} }
@ -191,7 +193,7 @@ void LyXText::setCharFont(BufferView * bv, Paragraph * par,
{ {
Buffer const * buf = bv->buffer(); Buffer const * buf = bv->buffer();
LyXFont font = getFont(buf, par, pos); LyXFont font = getFont(buf, par, pos);
font.update(fnt, buf->params.language, toggleall); font.update(fnt, toggleall);
// Let the insets convert their font // Let the insets convert their font
if (par->getChar(pos) == Paragraph::META_INSET) { if (par->getChar(pos) == Paragraph::META_INSET) {
Inset * inset = par->getInset(pos); Inset * inset = par->getInset(pos);
@ -225,11 +227,13 @@ void LyXText::setCharFont(BufferView * bv, Paragraph * par,
if (tp) if (tp)
layoutfont.realize(textclasslist. layoutfont.realize(textclasslist.
Style(buf->params.textclass, Style(buf->params.textclass,
tp->getLayout()).font); 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 // Now, reduce font against full layout font
font.reduce(layoutfont); font.reduce(layoutfont);
@ -267,11 +271,13 @@ void LyXText::setCharFont(Buffer const * buf, Paragraph * par,
if (tp) if (tp)
layoutfont.realize(textclasslist. layoutfont.realize(textclasslist.
Style(buf->params.textclass, Style(buf->params.textclass,
tp->getLayout()).font); 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 // Now, reduce font against full layout font
font.reduce(layoutfont); font.reduce(layoutfont);
@ -674,15 +680,14 @@ void LyXText::setFont(BufferView * bview, LyXFont const & font, bool toggleall)
else else
layoutfont = getFont(bview->buffer(), cursor.par(),-1); layoutfont = getFont(bview->buffer(), cursor.par(),-1);
// Update current font // Update current font
real_current_font.update(font, real_current_font.update(font, toggleall);
bview->buffer()->params.language,
toggleall);
// Reduce to implicit settings // Reduce to implicit settings
current_font = real_current_font; current_font = real_current_font;
current_font.reduce(layoutfont); current_font.reduce(layoutfont);
// And resolve it completely // And resolve it completely
real_current_font.realize(layoutfont); real_current_font.realize(layoutfont,
bview->buffer()->params.language);
return; return;
} }