#include "BufferParams.h"
#include "BufferView.h"
#include "Bullet.h"
+#include "Changes.h"
#include "Color.h"
#include "Cursor.h"
#include "CutAndPaste.h"
#include "FuncRequest.h"
#include "gettext.h"
#include "Language.h"
+#include "Layout.h"
#include "Lexer.h"
#include "LyXFunc.h"
#include "LyXRC.h"
#include "ParIterator.h"
#include "Server.h"
#include "ServerSocket.h"
-#include "Undo.h"
+#include "TextMetrics.h"
#include "VSpace.h"
#include "frontends/FontMetrics.h"
#include "support/textutils.h"
#include <boost/current_function.hpp>
+#include <boost/next_prior.hpp>
#include <sstream>
namespace lyx {
Text::Text()
- : background_color_(Color::background),
- autoBreakRows_(false)
+ : autoBreakRows_(false)
{}
}
-// Gets the fully instantiated font at a given position in a paragraph
-// Basically the same routine as Paragraph::getFont() in Paragraph.cpp.
-// The difference is that this one is used for displaying, and thus we
-// are allowed to make cosmetic improvements. For instance make footnotes
-// smaller. (Asger)
-Font Text::getFont(Buffer const & buffer, Paragraph const & par,
- pos_type const pos) const
-{
- BOOST_ASSERT(pos >= 0);
-
- LayoutPtr const & layout = par.layout();
- // FIXME: broken?
- BufferParams const & params = buffer.params();
- pos_type const body_pos = par.beginOfBody();
-
- // We specialize the 95% common case:
- if (!par.getDepth()) {
- Font f = par.getFontSettings(params, pos);
- if (!isMainText(buffer))
- applyOuterFont(buffer, f);
- Font lf;
- Font rlf;
- if (layout->labeltype == LABEL_MANUAL && pos < body_pos) {
- lf = layout->labelfont;
- rlf = layout->reslabelfont;
- } else {
- lf = layout->font;
- rlf = layout->resfont;
- }
- // In case the default family has been customized
- if (lf.family() == Font::INHERIT_FAMILY)
- rlf.setFamily(params.getFont().family());
- return f.realize(rlf);
- }
-
- // The uncommon case need not be optimized as much
- Font layoutfont;
- if (pos < body_pos)
- layoutfont = layout->labelfont;
- else
- layoutfont = layout->font;
-
- Font font = par.getFontSettings(params, pos);
- font.realize(layoutfont);
-
- if (!isMainText(buffer))
- applyOuterFont(buffer, font);
-
- // Find the pit value belonging to paragraph. This will not break
- // even if pars_ would not be a vector anymore.
- // Performance appears acceptable.
-
- pit_type pit = pars_.size();
- for (pit_type it = 0; it < pit; ++it)
- if (&pars_[it] == &par) {
- pit = it;
- break;
- }
- // Realize against environment font information
- // NOTE: the cast to pit_type should be removed when pit_type
- // changes to a unsigned integer.
- if (pit < pit_type(pars_.size()))
- font.realize(outerFont(pit, pars_));
-
- // Realize with the fonts of lesser depth.
- font.realize(params.getFont());
-
- return font;
-}
-
-// There are currently two font mechanisms in LyX:
-// 1. The font attributes in a lyxtext, and
-// 2. The inset-specific font properties, defined in an inset's
-// metrics() and draw() methods and handed down the inset chain through
-// the pi/mi parameters, and stored locally in a lyxtext in font_.
-// This is where the two are integrated in the final fully realized
-// font.
-void Text::applyOuterFont(Buffer const & buffer, Font & font) const {
- Font lf(font_);
- lf.reduce(buffer.params().getFont());
- lf.realize(font);
- lf.setLanguage(font.language());
- font = lf;
-}
-
-
Font Text::getLayoutFont(Buffer const & buffer, pit_type const pit) const
{
LayoutPtr const & layout = pars_[pit].layout();
void Text::setCharFont(Buffer const & buffer, pit_type pit,
- pos_type pos, Font const & fnt)
+ pos_type pos, Font const & fnt, Font const & display_font)
{
Font font = fnt;
LayoutPtr const & layout = pars_[pit].layout();
// Inside inset, apply the inset's font attributes if any
// (charstyle!)
if (!isMainText(buffer))
- layoutfont.realize(font_);
+ layoutfont.realize(display_font);
layoutfont.realize(buffer.params().getFont());
}
-void Text::setInsetFont(Buffer const & buffer, pit_type pit,
+void Text::setInsetFont(BufferView const & bv, pit_type pit,
pos_type pos, Font const & font, bool toggleall)
{
BOOST_ASSERT(pars_[pit].isInset(pos) &&
CursorSlice cellend = cs;
cellend.pit() = cellend.lastpit();
cellend.pos() = cellend.lastpos();
- text->setFont(buffer, cs, cellend, font, toggleall);
+ text->setFont(bv, cs, cellend, font, toggleall);
}
}
}
BOOST_ASSERT(this == cur.text());
pit_type const beg = cur.selBegin().pit();
pit_type const end = cur.selEnd().pit() + 1;
- recordUndoSelection(cur);
+ cur.recordUndoSelection();
int max_depth = (beg != 0 ? pars_[beg - 1].getMaxDepthAfter() : 0);
for (pit_type pit = beg; pit != end; ++pit) {
return;
// Ok, we have a selection.
- recordUndoSelection(cur);
+ cur.recordUndoSelection();
- setFont(cur.buffer(), cur.selectionBegin().top(),
+ setFont(cur.bv(), cur.selectionBegin().top(),
cur.selectionEnd().top(), font, toggleall);
}
-void Text::setFont(Buffer const & buffer, CursorSlice const & begin,
+void Text::setFont(BufferView const & bv, CursorSlice const & begin,
CursorSlice const & end, Font const & font,
bool toggleall)
{
+ Buffer const & buffer = bv.buffer();
+
// Don't use forwardChar here as ditend might have
// pos() == lastpos() and forwardChar would miss it.
// Can't use forwardPos either as this descends into
// text cells of the inset (bug 1973).
// FIXME: This should change, see documentation
// of noFontChange in Inset.h
- setInsetFont(buffer, pit, pos, font, toggleall);
- Font f = getFont(buffer, dit.paragraph(), pos);
+ setInsetFont(bv, pit, pos, font, toggleall);
+ TextMetrics const & tm = bv.textMetrics(this);
+ Font f = tm.getDisplayFont(pit, pos);
f.update(font, language, toggleall);
- setCharFont(buffer, pit, pos, f);
+ setCharFont(buffer, pit, pos, f, tm.font_);
}
}
}
if (!front && cur.pos() == 0)
return false;
Inset * inset = front ? cur.nextInset() : cur.prevInset();
- if (!isHighlyEditableInset(inset))
+ if (!inset || inset->editable() != Inset::HIGHLY_EDITABLE)
return false;
/*
* Apparently, when entering an inset we are expected to be positioned
// move to the previous paragraph or do nothing
if (cur.pit() > 0)
- return setCursor(cur, cur.pit() - 1, getPar(cur.pit() - 1).size());
+ return setCursor(cur, cur.pit() - 1, getPar(cur.pit() - 1).size(), true, false);
return false;
}
if (checkAndActivateInset(cur, true))
return false;
+ TextMetrics const & tm = cur.bv().textMetrics(this);
// if left of boundary -> just jump to right side
- // but for RTL boundaries don't, because: abc|DDEEFFghi -> abcDDEEF|Fghi
- if (cur.boundary() &&
- !isRTLBoundary(cur.buffer(), cur.paragraph(), cur.pos()))
+ // but for RTL boundaries don't, because: abc|DDEEFFghi -> abcDDEEF|Fghi
+ if (cur.boundary() && !tm.isRTLBoundary(cur.pit(), cur.pos()))
return setCursor(cur, cur.pit(), cur.pos(), true, false);
// next position is left of boundary,
// in front of RTL boundary? Stay on this side of the boundary because:
// ab|cDDEEFFghi -> abc|DDEEFFghi
- if (isRTLBoundary(cur.buffer(), cur.paragraph(), cur.pos() + 1))
+ if (tm.isRTLBoundary(cur.pit(), cur.pos() + 1))
return setCursor(cur, cur.pit(), cur.pos() + 1, true, true);
// move right
// move to next paragraph
if (cur.pit() != cur.lastpit())
- return setCursor(cur, cur.pit() + 1, 0);
+ return setCursor(cur, cur.pit() + 1, 0, true, false);
return false;
}
if (oldpar.empty() || (oldpar.size() == 1 && oldpar.isLineSeparator(0))) {
// Delete old par.
- recordUndo(old, Undo::ATOMIC,
+ old.recordUndo(ATOMIC_UNDO,
max(old.pit() - 1, pit_type(0)),
min(old.pit() + 1, old.lastpit()));
ParagraphList & plist = old.text()->paragraphs();
+ bool const soa = oldpar.params().startOfAppendix();
plist.erase(boost::next(plist.begin(), old.pit()));
+ // do not lose start of appendix marker (bug 4212)
+ if (soa)
+ plist[old.pit()].params().startOfAppendix(true);
// see #warning (FIXME?) above
if (cur.depth() >= old.depth()) {
void Text::recUndo(Cursor & cur, pit_type first, pit_type last) const
{
- recordUndo(cur, Undo::ATOMIC, first, last);
+ cur.recordUndo(ATOMIC_UNDO, first, last);
}
void Text::recUndo(Cursor & cur, pit_type par) const
{
- recordUndo(cur, Undo::ATOMIC, par, par);
+ cur.recordUndo(ATOMIC_UNDO, par, par);
}
} // namespace lyx