Add latex_language and remove inherit_language

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2492 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Dekel Tsur 2001-08-11 18:31:14 +00:00
parent b727c2947f
commit a277759770
15 changed files with 186 additions and 23 deletions

View File

@ -420,8 +420,7 @@ void BufferView::showLockedInsetCursor(int x, int y, int asc, int desc)
cursor.par(), cursor.pos() - 1);
LyXScreen::Cursor_Shape shape = LyXScreen::BAR_SHAPE;
LyXText * txt = getLyXText();
if (theLockingInset()->getLockingInset()->lyxCode() ==
Inset::TEXT_CODE &&
if (theLockingInset()->getLockingInset()->isTextInset() &&
(txt->real_current_font.language() !=
buffer()->params.language
|| txt->real_current_font.isVisibleRightToLeft()

View File

@ -1,3 +1,10 @@
2001-08-11 Dekel Tsur <dekelts@tau.ac.il>
* Many files: Remove inherit_language, and add latex_language
* BufferView2.C (showLockedInsetCursor): Fix cursor shape in
collapsible insets.
2001-08-10 Juergen Vigna <jug@sad.it>
* text.C (prepareToPrint): fixed hfill-width in draw!

View File

@ -120,7 +120,11 @@ void roman(BufferView * bv)
void styleReset(BufferView * bv)
{
#ifndef INHERIT_LANG
LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
#else
LyXFont font(LyXFont::ALL_INHERIT);
#endif
toggleAndShow(bv, font);
}

View File

@ -1,3 +1,8 @@
2001-08-11 Dekel Tsur <dekelts@tau.ac.il>
* insettext.C (localDispatch): Change language only when the inset
becomes empty.
2001-08-10 Juergen Vigna <jug@sad.it>
* insettabular.C (selectNextWordInt): use the front using edit call.

View File

@ -67,7 +67,11 @@ Inset * InsetERT::clone(Buffer const &, bool same_id) const
InsetERT::InsetERT(string const & contents, bool collapsed)
: InsetCollapsable(collapsed)
{
#ifndef INHERIT_LANG
LyXFont font(LyXFont::ALL_INHERIT, latex_language);
#else
LyXFont font(LyXFont::ALL_INHERIT);
#endif
font.setFamily(LyXFont::TYPEWRITER_FAMILY);
font.setColor(LColor::latex);
string::const_iterator cit = contents.begin();
@ -354,7 +358,11 @@ void InsetERT::setButtonLabel() const
bool InsetERT::checkInsertChar(LyXFont & font)
{
#ifndef INHERIT_LANG
LyXFont f(LyXFont::ALL_INHERIT, latex_language);
#else
LyXFont f(LyXFont::ALL_INHERIT);
#endif
font = f;
font.setFamily(LyXFont::TYPEWRITER_FAMILY);
font.setColor(LColor::latex);
@ -442,7 +450,11 @@ void InsetERT::draw(BufferView * bv, LyXFont const & f,
void InsetERT::set_latex_font(BufferView * bv)
{
#ifndef INHERIT_LANG
LyXFont font(LyXFont::ALL_INHERIT, latex_language);
#else
LyXFont font(LyXFont::ALL_INHERIT);
#endif
font.setFamily(LyXFont::TYPEWRITER_FAMILY);
font.setColor(LColor::latex);

View File

@ -987,6 +987,7 @@ UpdatableInset::RESULT
InsetText::localDispatch(BufferView * bv,
kb_action action, string const & arg)
{
bool was_empty = par->size() == 0 && !par->next();
no_selection = false;
UpdatableInset::RESULT
result= UpdatableInset::localDispatch(bv, action, arg);
@ -1310,7 +1311,7 @@ InsetText::localDispatch(BufferView * bv,
/// If the action has deleted all text in the inset, we need to change the
// language to the language of the surronding text.
if (par->size() == 0 && !par->next()) {
if (!was_empty && par->size() == 0 && !par->next()) {
LyXFont font(LyXFont::ALL_IGNORE);
font.setLanguage(bv->getParentLanguage(this));
setFont(bv, font, false);

View File

@ -29,8 +29,12 @@ Language const * english_language;
Language const * default_language;
Language ignore_lang("ignore", "ignore", "Ignore", false, 0, "ignore", "");
Language const * ignore_language = &ignore_lang;
Language latex_lang("latex", "latex", "Latex", false, 0, "latex", "");
Language const * latex_language = &latex_lang;
#ifdef INHERIT_LANG
Language inherit_lang("inherit", "inherit", "Inherit", false, 0, "inherit", "");
Language const * inherit_language = &inherit_lang;
#endif
void Languages::setDefaults()
{

View File

@ -116,6 +116,9 @@ extern Languages languages;
extern Language const * default_language;
extern Language const * english_language;
extern Language const * ignore_language;
extern Language const * latex_language;
#ifdef INHERIT_LANGUAGE
extern Language const * inherit_language;
#endif
#endif

View File

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

View File

@ -157,7 +157,11 @@ bool LyXFont::FontBits::operator!=(LyXFont::FontBits const & fb1) const
LyXFont::LyXFont(LyXFont::FONT_INIT1)
#ifndef INHERIT_LANGUAGE
: bits(inherit), lang(default_language)
#else
: bits(inherit), lang(inherit_language)
#endif
{}
@ -377,7 +381,9 @@ LyXFont::FONT_MISC_STATE LyXFont::setMisc(FONT_MISC_STATE newfont,
/// Updates font settings according to request
void LyXFont::update(LyXFont const & newfont, bool toggleall)
void LyXFont::update(LyXFont const & newfont,
Language const * document_language,
bool toggleall)
{
if (newfont.family() == family() && toggleall)
setFamily(INHERIT_FAMILY); // toggle 'back'
@ -423,7 +429,14 @@ void LyXFont::update(LyXFont const & newfont, bool toggleall)
setNumber(setMisc(newfont.number(), number()));
if (newfont.language() == language() && toggleall)
if (language() == document_language)
setLanguage(default_language);
else
#ifndef INHERIT_LANGUAGE
setLanguage(document_language);
#else
setLanguage(inherit_language);
#endif
else if (newfont.language() != ignore_language)
setLanguage(newfont.language());
@ -453,14 +466,21 @@ void LyXFont::reduce(LyXFont const & tmplt)
setNoun(INHERIT);
if (color() == tmplt.color())
setColor(LColor::inherit);
#ifdef INHERIT_LANGUAGE
if (language() == tmplt.language())
setLanguage(inherit_language);
#endif
}
/// Realize font from a template
#ifndef INHERIT_LANGUAGE
LyXFont & LyXFont::realize(LyXFont const & tmplt)
#else
LyXFont & LyXFont::realize(LyXFont const & tmplt, Language const * deflang)
#endif
{
#ifdef INHERIT_LANGUAGE
if (language() == inherit_language) {
if (tmplt.language() == inherit_language ||
tmplt.language() == ignore_language ||
@ -471,6 +491,7 @@ LyXFont & LyXFont::realize(LyXFont const & tmplt, Language const * deflang)
setLanguage(tmplt.language());
}
}
#endif
if (bits == inherit) {
bits = tmplt.bits;
return *this;
@ -511,8 +532,10 @@ bool LyXFont::resolved() const
shape() != INHERIT_SHAPE && size() != INHERIT_SIZE &&
emph() != INHERIT && underbar() != INHERIT &&
noun() != INHERIT &&
color() != LColor::inherit &&
language() != inherit_language);
#ifdef INHERIT_LANGUAGE
language() != inherit_language &&
#endif
color() != LColor::inherit);
}
@ -708,7 +731,10 @@ LyXFont & LyXFont::lyxRead(LyXLex & lex)
/// Writes the changes from this font to orgfont in .lyx format in file
void LyXFont::lyxWriteChanges(LyXFont const & orgfont,
Language const * doclang, ostream & os) const
#ifdef INHERIT_LANGUAGE
Language const * doclang,
#endif
ostream & os) const
{
os << "\n";
if (orgfont.family() != family()) {
@ -757,9 +783,13 @@ void LyXFont::lyxWriteChanges(LyXFont const & orgfont,
os << "\\color " << col_str << "\n";
}
if (orgfont.language() != language()) {
#ifndef INHERIT_LANGUAGE
if (language())
#else
if (language() == inherit_language)
os << "\\lang " << doclang->lang() << "\n";
else if (language())
#endif
os << "\\lang " << language()->lang() << "\n";
else
os << "\\lang unknown\n";

View File

@ -252,15 +252,20 @@ 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, bool toggleall = false);
void update(LyXFont const & newfont,
Language const * default_lang,
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)
#ifndef INHERIT_LANGUAGE
LyXFont & realize(LyXFont const & tmplt);
#else
LyXFont & realize(LyXFont const & tmplt, Language const * language);
#endif
/// Is a given font fully resolved?
bool resolved() const;
@ -268,8 +273,12 @@ public:
LyXFont & lyxRead(LyXLex &);
/// Writes the changes from this font to orgfont in .lyx format in file
#ifndef INHERIT_LANGUAGE
void lyxWriteChanges(LyXFont const & orgfont, std::ostream &) const;
#else
void lyxWriteChanges(LyXFont const & orgfont, Language const * doclang,
std::ostream &) const;
#endif
/** Writes the head of the LaTeX needed to change to this font.
Writes to string, the head of the LaTeX needed to change

View File

@ -252,7 +252,11 @@ void Paragraph::writeFile(Buffer const * buf, ostream & os,
// Write font changes
LyXFont font2 = getFontSettings(bparams, i);
if (font2 != font1) {
#ifndef INHERIT_LANGUAGE
font2.lyxWriteChanges(font1, os);
#else
font2.lyxWriteChanges(font1, bparams.language, os);
#endif
column = 0;
font1 = font2;
}
@ -363,9 +367,12 @@ void Paragraph::validate(LaTeXFeatures & features) const
}
Language const * language = cit->font().language();
if (language != ignore_language &&
if (language->babel() != doc_language->babel() &&
language != ignore_language &&
#ifdef INHERIT_LANGUAGE
language != inherit_language &&
language->babel() != doc_language->babel())
#endif
language != latex_language)
{
features.UsedLanguages.insert(language);
lyxerr[Debug::LATEX] << "Found language "
@ -584,8 +591,10 @@ LyXFont const Paragraph::getFontSettings(BufferParams const & bparams,
retfont = getFontSettings(bparams, pos - 1);
} else
retfont = LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
#ifdef INHERIT_LANGUAGE
if (retfont.language() == inherit_language)
retfont.setLanguage(bparams.language);
#endif
return retfont;
}
@ -629,7 +638,11 @@ LyXFont const Paragraph::getFont(BufferParams const & bparams,
layoutfont = layout.font;
LyXFont tmpfont = getFontSettings(bparams, pos);
#ifndef INHERIT_LANGUAGE
tmpfont.realize(layoutfont);
#else
tmpfont.realize(layoutfont, bparams.language);
#endif
return pimpl_->realizeFont(tmpfont, bparams);
}
@ -1265,8 +1278,6 @@ 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",
@ -1837,11 +1848,15 @@ Language const *
Paragraph::getParLanguage(BufferParams const & bparams) const
{
if (size() > 0) {
#ifndef INHERIT_LANGUAGE
return getFirstFontSettings().language();
#else
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;
#endif
} else if (previous_)
return previous_->getParLanguage(bparams);
else
@ -1874,8 +1889,11 @@ 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() != inherit_language &&
cit->font().language() != ignore_language &&
if (cit->font().language() != ignore_language &&
cit->font().language() != latex_language &&
#ifdef INHERIT_LANGUAGE
cit->font().language() != inherit_language &&
#endif
cit->font().language() != doc_language)
return true;
return false;

View File

@ -538,15 +538,25 @@ LyXFont const Paragraph::Pimpl::realizeFont(LyXFont const & font,
while (par && par->getDepth() && !tmpfont.resolved()) {
par = par->outerHook();
if (par) {
#ifndef INHERIT_LANGUAGE
tmpfont.realize(textclasslist.
Style(bparams.textclass,
par->getLayout()).font);
#else
tmpfont.realize(textclasslist.
Style(bparams.textclass,
par->getLayout()).font, bparams.language);
#endif
par_depth = par->getDepth();
}
}
tmpfont.realize(textclasslist
.TextClass(bparams.textclass)
#ifndef INHERIT_LANGUAGE
tmpfont.realize(textclasslist.TextClass(bparams.textclass)
.defaultfont());
#else
tmpfont.realize(textclasslist.TextClass(bparams.textclass)
.defaultfont(), bparams.language);
#endif
return tmpfont;
}

View File

@ -452,7 +452,7 @@ void LyXText::draw(BufferView * bview, Row const * row,
++vpos;
if (lyxrc.mark_foreign_language &&
font.language() != ignore_language &&
font.language() != latex_language &&
font.language() != bview->buffer()->params.language) {
int const y = offset + row->height() - 1;
pain.line(int(tmpx), y, int(x), y, LColor::language);
@ -568,12 +568,15 @@ void LyXText::draw(BufferView * bview, Row const * row,
x += lyxfont::width(textstring, font);
}
#ifdef INHERIT_LANGUAGE
#ifdef WITH_WARNINGS
if ((font.language() == inherit_language) ||
(font.language() == ignore_language))
lyxerr << "No this shouldn't happen!\n";
#endif
#endif
if (lyxrc.mark_foreign_language &&
font.language() != latex_language &&
font.language() != bview->buffer()->params.language) {
int const y = offset + row->height() - 1;
pain.line(int(tmpx), y, int(x), y,

View File

@ -120,16 +120,26 @@ LyXFont const realizeFont(LyXFont const & font,
while (par && par_depth && !tmpfont.resolved()) {
par = par->outerHook();
if (par) {
#ifndef INHERIT_LANGUAGE
tmpfont.realize(textclasslist.
Style(buf->params.textclass,
par->getLayout()).font);
#else
tmpfont.realize(textclasslist.
Style(buf->params.textclass,
par->getLayout()).font,
buf->params.language);
#endif
par_depth = par->getDepth();
}
}
#ifndef INHERIT_LANGUAGE
tmpfont.realize(textclasslist.TextClass(buf->params.textclass).defaultfont());
#else
tmpfont.realize(textclasslist.TextClass(buf->params.textclass).defaultfont(),
buf->params.language);
#endif
return tmpfont;
}
@ -160,10 +170,18 @@ LyXFont const LyXText::getFont(Buffer const * buf, Paragraph * par,
// 1% goes here
LyXFont f = par->getFontSettings(buf->params,
pos);
#ifndef INHERIT_LANGUAGE
return f.realize(layout.reslabelfont);
#else
return f.realize(layout.reslabelfont, buf->params.language);
#endif
} else {
LyXFont f = par->getFontSettings(buf->params, pos);
#ifndef INHERIT_LANGUAGE
return f.realize(layout.resfont);
#else
return f.realize(layout.resfont, buf->params.language);
#endif
}
}
@ -180,7 +198,11 @@ LyXFont const LyXText::getFont(Buffer const * buf, Paragraph * par,
}
LyXFont tmpfont = par->getFontSettings(buf->params, pos);
#ifndef INHERIT_LANGUAGE
tmpfont.realize(layoutfont);
#else
tmpfont.realize(layoutfont, buf->params.language);
#endif
return realizeFont(tmpfont, buf, par);
}
@ -222,7 +244,7 @@ void LyXText::setCharFont(BufferView * bv, Paragraph * par,
{
Buffer const * buf = bv->buffer();
LyXFont font = getFont(buf, par, pos);
font.update(fnt, toggleall);
font.update(fnt, buf->params.language, toggleall);
// Let the insets convert their font
if (par->getChar(pos) == Paragraph::META_INSET) {
Inset * inset = par->getInset(pos);
@ -253,15 +275,25 @@ void LyXText::setCharFont(BufferView * bv, Paragraph * par,
while (!layoutfont.resolved() && tp && tp->getDepth()) {
tp = tp->outerHook();
if (tp)
#ifndef INHERIT_LANGUAGE
layoutfont.realize(textclasslist.
Style(buf->params.textclass,
tp->getLayout()).font);
#else
layoutfont.realize(textclasslist.
Style(buf->params.textclass,
tp->getLayout()).font,
buf->params.language);
#endif
}
}
#ifndef INHERIT_LANGUAGE
layoutfont.realize(textclasslist.TextClass(buf->params.textclass).defaultfont());
#else
layoutfont.realize(textclasslist.TextClass(buf->params.textclass).defaultfont(),
buf->params.language);
#endif
// Now, reduce font against full layout font
font.reduce(layoutfont);
@ -293,15 +325,25 @@ void LyXText::setCharFont(Buffer const * buf, Paragraph * par,
while (!layoutfont.resolved() && tp && tp->getDepth()) {
tp = tp->outerHook();
if (tp)
#ifndef INHERIT_LANGUAGE
layoutfont.realize(textclasslist.
Style(buf->params.textclass,
tp->getLayout()).font);
#else
layoutfont.realize(textclasslist.
Style(buf->params.textclass,
tp->getLayout()).font,
buf->params.language);
#endif
}
}
#ifndef INHERIT_LANGUAGE
layoutfont.realize(textclasslist.TextClass(buf->params.textclass).defaultfont());
#else
layoutfont.realize(textclasslist.TextClass(buf->params.textclass).defaultfont(),
buf->params.language);
#endif
// Now, reduce font against full layout font
font.reduce(layoutfont);
@ -706,14 +748,20 @@ void LyXText::setFont(BufferView * bview, LyXFont const & font, bool toggleall)
cursor.par());
}
// Update current font
real_current_font.update(font, toggleall);
real_current_font.update(font,
bview->buffer()->params.language,
toggleall);
// Reduce to implicit settings
current_font = real_current_font;
current_font.reduce(layoutfont);
// And resolve it completely
#ifndef INHERIT_LANGUAGE
real_current_font.realize(layoutfont);
#else
real_current_font.realize(layoutfont,
bview->buffer()->params.language);
#endif
return;
}