From 9443f625d8b9ec136444d1d438eb786c911492b0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrgen=20Vigna?= Date: Wed, 20 Feb 2002 14:55:17 +0000 Subject: [PATCH] Fix for #143. Changed handling of Font stuff for ERTInsets so that the latex fonts are not really set but only displayed on screen. So we fixed the problem of cut&paste in and out of ERT insets retaining the latex color and font. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3576 a592a061-630c-0410-9148-cb99ea01b6c8 --- po/POTFILES.in | 1 + src/CutAndPaste.C | 2 +- src/buffer.C | 2 +- src/insets/inset.h | 12 +++++++----- src/insets/insetert.C | 40 +++++++++++++++++++++++++++++----------- src/insets/insetert.h | 7 ++++++- src/insets/insettext.C | 8 ++++++++ src/insets/insettext.h | 2 ++ src/text.C | 2 +- src/text2.C | 11 ++++++++--- 10 files changed, 64 insertions(+), 23 deletions(-) diff --git a/po/POTFILES.in b/po/POTFILES.in index 3570609547..5585e5ec15 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -9,6 +9,7 @@ src/converter.C src/CutAndPaste.C src/debug.C src/exporter.C +src/ext_l10n.h src/figure_form.C src/figureForm.C src/FontLoader.C diff --git a/src/CutAndPaste.C b/src/CutAndPaste.C index 8d0977bcb8..3a943f85ed 100644 --- a/src/CutAndPaste.C +++ b/src/CutAndPaste.C @@ -219,11 +219,11 @@ bool CutAndPaste::pasteSelection(Paragraph ** par, Paragraph ** endpar, if (pos > (*par)->size()) pos = (*par)->size(); +#if 0 // Paragraph * tmpbuf; Paragraph * tmppar = *par; int tmppos = pos; -#if 0 // There are two cases: cutbuffer only one paragraph or many if (!buf->next()) { // only within a paragraph diff --git a/src/buffer.C b/src/buffer.C index 29fc68cc46..14094621af 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -406,7 +406,7 @@ void Buffer::insertErtContents(Paragraph * par, int & pos, bool set_inactive) if (!ert_comp.contents.empty()) { lyxerr[Debug::INSETS] << "ERT contents:\n'" << ert_comp.contents << "'" << endl; - Inset * inset = new InsetERT(ert_comp.contents, true); + Inset * inset = new InsetERT(params.language, ert_comp.contents, true); par->insertInset(pos++, inset, ert_comp.font); ert_comp.contents.erase(); } diff --git a/src/insets/inset.h b/src/insets/inset.h index aae88009d7..5093c3eeea 100644 --- a/src/insets/inset.h +++ b/src/insets/inset.h @@ -317,10 +317,12 @@ public: // if this inset has paragraphs should they be output all as default // paragraphs with "Standard" layout? virtual bool forceDefaultParagraphs(Inset const *) const; - // needed for widths which are % of something - /* returns the value of \textwidth in this inset. Most of the - time this is the width of the workarea, but if there is a - minipage somewhere, it will be the width of this minipage */ + // + virtual void getDrawFont(LyXFont &) const {} + /* needed for widths which are % of something + returns the value of \textwidth in this inset. Most of the + time this is the width of the workarea, but if there is a + minipage somewhere, it will be the width of this minipage */ virtual int latexTextWidth(BufferView *) const; protected: @@ -529,7 +531,7 @@ public: /// virtual bool searchBackward(BufferView *, string const &, bool = true, bool = false); - + protected: /// void toggleCursorVisible() const { diff --git a/src/insets/insetert.C b/src/insets/insetert.C index 9daea852d7..94b0f41115 100644 --- a/src/insets/insetert.C +++ b/src/insets/insetert.C @@ -75,20 +75,20 @@ Inset * InsetERT::clone(Buffer const &, bool same_id) const } -InsetERT::InsetERT(string const & contents, bool collapsed) +InsetERT::InsetERT(Language const * l, string const & contents, bool collapsed) : InsetCollapsable(collapsed) { if (collapsed) status_ = Collapsed; else status_ = Open; -#ifndef INHERIT_LANG - LyXFont font(LyXFont::ALL_INHERIT, latex_language); -#else - LyXFont font(LyXFont::ALL_INHERIT); -#endif + + LyXFont font(LyXFont::ALL_INHERIT, l); +#ifdef SET_HARD_FONT font.setFamily(LyXFont::TYPEWRITER_FAMILY); font.setColor(LColor::latex); +#endif + string::const_iterator cit = contents.begin(); string::const_iterator end = contents.end(); pos_type pos = 0; @@ -151,12 +151,12 @@ void InsetERT::read(Buffer const * buf, LyXLex & lex) #endif inset.read(buf, lex); +#ifdef SET_HARD_FONT #ifndef INHERIT_LANG LyXFont font(LyXFont::ALL_INHERIT, latex_language); #else LyXFont font(LyXFont::ALL_INHERIT); #endif - font.setFamily(LyXFont::TYPEWRITER_FAMILY); font.setColor(LColor::latex); Paragraph * par = inset.paragraph(); @@ -167,7 +167,8 @@ void InsetERT::read(Buffer const * buf, LyXLex & lex) } par = par->next(); } - +#endif + if (!token_found) { if (collapsed_) { status(0, Collapsed); @@ -511,8 +512,9 @@ void InsetERT::setButtonLabel() const } -bool InsetERT::checkInsertChar(LyXFont & font) +bool InsetERT::checkInsertChar(LyXFont & /* font */) { +#ifdef SET_HARD_FONT #ifndef INHERIT_LANG LyXFont f(LyXFont::ALL_INHERIT, latex_language); #else @@ -521,6 +523,7 @@ bool InsetERT::checkInsertChar(LyXFont & font) font = f; font.setFamily(LyXFont::TYPEWRITER_FAMILY); font.setColor(LColor::latex); +#endif return true; } @@ -603,8 +606,9 @@ void InsetERT::draw(BufferView * bv, LyXFont const & f, } -void InsetERT::set_latex_font(BufferView * bv) +void InsetERT::set_latex_font(BufferView * /* bv */) { +#ifdef SET_HARD_FONT #ifndef INHERIT_LANG LyXFont font(LyXFont::ALL_INHERIT, latex_language); #else @@ -613,7 +617,9 @@ void InsetERT::set_latex_font(BufferView * bv) font.setFamily(LyXFont::TYPEWRITER_FAMILY); font.setColor(LColor::latex); + inset.getLyXText(bv)->setFont(bv, font, false); +#endif } @@ -671,6 +677,18 @@ void InsetERT::close(BufferView * bv) const string const InsetERT::selectNextWordToSpellcheck(BufferView * bv,float &) const { - bv->unlockInset(const_cast(this)); + bv->unlockInset(const_cast(this)); return string(); } + +void InsetERT::getDrawFont(LyXFont & font) const +{ +#ifndef INHERIT_LANG + LyXFont f(LyXFont::ALL_INHERIT, latex_language); +#else + LyXFont f(LyXFont::ALL_INHERIT); +#endif + font = f; + font.setFamily(LyXFont::TYPEWRITER_FAMILY); + font.setColor(LColor::latex); +} diff --git a/src/insets/insetert.h b/src/insets/insetert.h index b42fa9e405..f1537267c9 100644 --- a/src/insets/insetert.h +++ b/src/insets/insetert.h @@ -29,6 +29,9 @@ Note that collapsed_ encompasses both the inline and collapsed button versions of this inset. */ + +class Language; + class InsetERT : public InsetCollapsable { public: /// @@ -44,7 +47,7 @@ public: /// Inset * clone(Buffer const &, bool same_id = false) const; /// - InsetERT(string const & contents, bool collapsed); + InsetERT(Language const *, string const & contents, bool collapsed); /// ~InsetERT(); /// @@ -123,6 +126,8 @@ public: /// bool showInsetDialog(BufferView *) const; /// + void getDrawFont(LyXFont &) const; + /// bool forceDefaultParagraphs(Inset const *) const { return true; } diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 8889f2869e..0f4823e496 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -2627,3 +2627,11 @@ void InsetText::collapseParagraphs(BufferParams const & bparams) const } reinitLyXText(); } + + +void InsetText::getDrawFont(LyXFont & font) const +{ + if (!owner()) + return; + owner()->getDrawFont(font); +} diff --git a/src/insets/insettext.h b/src/insets/insettext.h index 54ee58bec7..55aea7d4e9 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -246,6 +246,8 @@ public: /// bool checkInsertChar(LyXFont &); /// + void getDrawFont(LyXFont &) const; + /// // // Public structures and variables /// diff --git a/src/text.C b/src/text.C index b369b02330..044a051779 100644 --- a/src/text.C +++ b/src/text.C @@ -581,7 +581,7 @@ void LyXText::drawArabicComposeChar(DrawRowParams & p, pos_type & vpos) void LyXText::drawChars(DrawRowParams & p, pos_type & vpos, - bool hebrew, bool arabic) + bool hebrew, bool arabic) { pos_type pos = vis2log(vpos); pos_type const last = rowLastPrintable(p.row); diff --git a/src/text2.C b/src/text2.C index 74e7dff931..ca8502196e 100644 --- a/src/text2.C +++ b/src/text2.C @@ -172,9 +172,10 @@ LyXFont const LyXText::getFont(Buffer const * buf, Paragraph * par, if (!par_depth) { if (layout.labeltype == LABEL_MANUAL && pos < beginningOfMainBody(buf, par)) { - // 1% goes here - LyXFont f = par->getFontSettings(buf->params, - pos); + // 1% goes here + LyXFont f = par->getFontSettings(buf->params, pos); + if (par->inInset()) + par->inInset()->getDrawFont(f); #ifndef INHERIT_LANGUAGE return f.realize(layout.reslabelfont); #else @@ -182,6 +183,8 @@ LyXFont const LyXText::getFont(Buffer const * buf, Paragraph * par, #endif } else { LyXFont f = par->getFontSettings(buf->params, pos); + if (par->inInset()) + par->inInset()->getDrawFont(f); #ifndef INHERIT_LANGUAGE return f.realize(layout.resfont); #else @@ -208,6 +211,8 @@ LyXFont const LyXText::getFont(Buffer const * buf, Paragraph * par, #else tmpfont.realize(layoutfont, buf->params.language); #endif + if (par->inInset()) + par->inInset()->getDrawFont(tmpfont); return realizeFont(tmpfont, buf, par); } -- 2.39.2