Fix bug #6919 by splitting Inset::noFontChange() into inheritFont() and

resetFontEdit(). The former is used for on-screen and export formatting,
and the latter is used for interactive editing.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37761 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Georg Baum 2011-02-22 19:41:04 +00:00
parent 0085a9920a
commit f176a18434
15 changed files with 59 additions and 39 deletions

View File

@ -1091,7 +1091,7 @@ void Paragraph::Private::latexInset(BufferParams const & bparams,
// ArabTeX, though, cannot handle this special behavior, it seems.
bool arabtex = basefont.language()->lang() == "arabic_arabtex"
|| running_font.language()->lang() == "arabic_arabtex";
if (open_font && inset->noFontChange()) {
if (open_font && !inset->inheritFont()) {
bool closeLanguage = arabtex
|| basefont.isRightToLeft() == running_font.isRightToLeft();
unsigned int count = running_font.latexWriteEndChanges(os,

View File

@ -66,11 +66,9 @@ public:
Font const & font, Font const & display_font);
/** Needed to propagate font changes to all text cells of insets
* that are not allowed inside a font change (bug 1973).
* that are not allowed inside a font change (bugs 1973, 6919).
* Must not be called if \p pos denotes an ordinary character or an
* inset that is alowed inside a font change.
* FIXME: This should be removed, see documentation of noFontChange
* in insetbase.h
*/
void setInsetFont(BufferView const & bv, pit_type pit, pos_type pos,
Font const & font, bool toggleall = false);

View File

@ -167,7 +167,7 @@ void Text::setInsetFont(BufferView const & bv, pit_type pit,
pos_type pos, Font const & font, bool toggleall)
{
Inset * const inset = pars_[pit].getInset(pos);
LASSERT(inset && inset->noFontChange(), /**/);
LASSERT(inset && inset->resetFontEdit(), /**/);
CursorSlice::idx_type endidx = inset->nargs();
for (CursorSlice cs(*inset); cs.idx() != endidx; ++cs.idx()) {
@ -345,11 +345,9 @@ void Text::setFont(BufferView const & bv, CursorSlice const & begin,
pit_type const pit = dit.pit();
pos_type const pos = dit.pos();
Inset * inset = pars_[pit].getInset(pos);
if (inset && inset->noFontChange()) {
if (inset && inset->resetFontEdit()) {
// We need to propagate the font change to all
// text cells of the inset (bug 1973).
// FIXME: This should change, see documentation
// of noFontChange in Inset.h
// text cells of the inset (bugs 1973, 6919).
setInsetFont(bv, pit, pos, font, toggleall);
}
TextMetrics const & tm = bv.textMetrics(this);

View File

@ -396,8 +396,6 @@ bool TextMetrics::redoParagraph(pit_type const pit)
}
// redo insets
// FIXME: We should always use getFont(), see documentation of
// noFontChange() in Inset.h.
Font const bufferfont = buffer.params().getFont();
InsetList::const_iterator ii = par.insetList().begin();
InsetList::const_iterator iend = par.insetList().end();
@ -418,8 +416,8 @@ bool TextMetrics::redoParagraph(pit_type const pit)
Dimension dim;
int const w = max_width_ - leftMargin(max_width_, pit, ii->pos)
- right_margin;
Font const & font = ii->inset->noFontChange() ?
bufferfont : displayFont(pit, ii->pos);
Font const & font = ii->inset->inheritFont() ?
displayFont(pit, ii->pos) : bufferfont;
MacroContext mc(&buffer, parPos);
MetricsInfo mi(bv_, font.fontInfo(), w, mc);
ii->inset->metrics(mi, dim);

View File

@ -520,14 +520,29 @@ public:
/// returns whether this inset is allowed in other insets of given mode
virtual bool allowedIn(mode_type) const { return true; }
/**
* Is this inset allowed within a font change?
*
* FIXME: noFontChange means currently that the font change is closed
* in LaTeX before the inset, and that the contents of the inset
* will be in default font. This should be changed so that the inset
* changes the font again.
* The font is inherited from the parent for LaTeX export if this
* method returns true. No open font changes are closed in front of
* the inset for LaTeX export, and the font is inherited for all other
* exports as well as on screen.
* If this method returns false all open font changes are closed in
* front of the inset for LaTeX export. The default font is used
* inside the inset for all exports and on screen.
*/
virtual bool noFontChange() const { return false; }
virtual bool inheritFont() const { return true; }
/**
* If this method returns true all explicitly set font attributes
* are reset during editing operations.
* For copy/paste the operations the language is never changed, since
* the language of a given text never changes if the text is
* formatted differently, while other font attribues like size may
* need to change if the text is copied from one environment to
* another one.
* If it returns false no font attribute is reset.
* The default implementation returns the negation of inheritFont(),
* since inherited inset font attributes do not need to be changed,
* and non-inherited ones need to be set explicitly.
*/
virtual bool resetFontEdit() const { return !inheritFont(); }
/// set the change for the entire inset
virtual void setChange(Change const &) {}

View File

@ -108,8 +108,10 @@ private:
bool forcePlainLayout(idx_type = 0) const;
///
bool neverIndent() const { return true; }
///
bool noFontChange() const { return true; }
/** returns false if, when outputing LaTeX, font changes should
be closed before generating this inset. This is needed for
insets that may contain several paragraphs */
bool inheritFont() const { return false; }
///
void latex(otexstream &, OutputParams const &) const;
///

View File

@ -56,6 +56,14 @@ InsetLayout const & InsetFlex::getLayout() const
}
bool InsetFlex::resetFontEdit() const
{
if (getLayout().resetsFont())
return true;
return InsetCollapsable::resetFontEdit();
}
InsetLayout::InsetDecoration InsetFlex::decoration() const
{
InsetLayout::InsetDecoration const dec = getLayout().decoration();

View File

@ -30,12 +30,14 @@ public:
InsetLayout const & getLayout() const;
///
InsetCode lyxCode() const { return FLEX_CODE; }
///
bool resetFontEdit() const;
/// Default looks
InsetLayout::InsetDecoration decoration() const;
///
void write(std::ostream &) const;
/// should paragraph indendation be ommitted in any case?
bool neverIndent() const { return true; }
bool neverIndent() const { return true; }
///
bool hasSettings() const { return false; }
///

View File

@ -90,10 +90,10 @@ private:
docstring xhtml(XHTMLStream &, OutputParams const &) const;
///
bool insetAllowed(InsetCode) const;
/** returns true if, when outputing LaTeX, font changes should
/** returns false if, when outputing LaTeX, font changes should
be closed before generating this inset. This is needed for
insets that may contain several paragraphs */
bool noFontChange() const { return true; }
bool inheritFont() const { return false; }
///
bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
// Update the counters of this inset and of its contents

View File

@ -35,10 +35,10 @@ private:
void write(std::ostream & os) const;
///
bool insetAllowed(InsetCode) const;
/** returns true if, when outputing LaTeX, font changes should
/** returns false if, when outputing LaTeX, font changes should
be closed before generating this inset. This is needed for
insets that may contain several paragraphs */
bool noFontChange() const { return true; }
bool inheritFont() const { return false; }
};

View File

@ -40,8 +40,8 @@ public:
private:
///
bool isLabeled() const { return true; }
///
bool noFontChange() const { return true; }
/// false is needed since listings do their own font handling.
bool inheritFont() const { return false; }
///
InsetCode lyxCode() const { return LISTINGS_CODE; }
/// lstinline is inlined, normal listing is displayed

View File

@ -63,8 +63,10 @@ private:
docstring name() const;
///
DisplayType display() const;
///
bool noFontChange() const { return params_.type != InsetNoteParams::Note; }
/** returns false if, when outputing LaTeX, font changes should
be closed before generating this inset. This is needed for
insets that may contain several paragraphs */
bool inheritFont() const { return params_.type == InsetNoteParams::Note; }
/// Is the content of this inset part of the output document?
bool producesOutput() const
{ return params_.type == InsetNoteParams::Greyedout; }

View File

@ -803,10 +803,10 @@ public:
bool allowSpellCheck() const { return true; }
///
bool canTrackChanges() const { return true; }
/** returns true if, when outputing LaTeX, font changes should
/** returns false if, when outputing LaTeX, font changes should
be closed before generating this inset. This is needed for
insets that may contain several paragraphs */
bool noFontChange() const { return true; }
bool inheritFont() const { return false; }
///
DisplayType display() const;
///

View File

@ -58,7 +58,7 @@ public:
///
int plaintext(odocstream &, OutputParams const &) const;
///
bool noFontChange() const { return true; }
bool inheritFont() const { return false; }
///
docstring name() const;

View File

@ -125,11 +125,8 @@ void RowPainter::paintInset(Inset const * inset, pos_type const pos)
// requires a full repaint
bool pi_full_repaint = pi_.full_repaint;
// FIXME: We should always use font, see documentation of
// noFontChange() in Inset.h.
pi_.base.font = inset->noFontChange() ?
pi_.base.bv->buffer().params().getFont().fontInfo() :
font.fontInfo();
pi_.base.font = inset->inheritFont() ? font.fontInfo() :
pi_.base.bv->buffer().params().getFont().fontInfo();
pi_.ltr_pos = (bidi_.level(pos) % 2 == 0);
pi_.change_ = change_.changed() ? change_ : par_.lookupChange(pos);