#include "BufferList.h"
#include "BufferParams.h"
#include "BufferView.h"
-#include "bufferview_funcs.h"
#include "Bullet.h"
#include "Color.h"
-#include "CoordCache.h"
#include "Cursor.h"
#include "CutAndPaste.h"
#include "debug.h"
#include "FuncRequest.h"
#include "gettext.h"
#include "Language.h"
+#include "Layout.h"
#include "Lexer.h"
#include "LyXFunc.h"
#include "LyXRC.h"
-#include "Row.h"
#include "Paragraph.h"
-#include "TextMetrics.h"
#include "paragraph_funcs.h"
#include "ParagraphParameters.h"
#include "ParIterator.h"
#include <sstream>
-
-namespace lyx {
-
using std::endl;
using std::ostringstream;
using std::string;
using std::min;
using std::istringstream;
+namespace lyx {
+
Text::Text()
- : current_font(Font::ALL_INHERIT),
- 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);
}
}
}
layoutfont = getLayoutFont(cur.buffer(), pit);
// Update current font
- real_current_font.update(font,
+ cur.real_current_font.update(font,
cur.buffer().params().language,
toggleall);
// Reduce to implicit settings
- current_font = real_current_font;
- current_font.reduce(layoutfont);
+ cur.current_font = cur.real_current_font;
+ cur.current_font.reduce(layoutfont);
// And resolve it completely
- real_current_font.realize(layoutfont);
+ cur.real_current_font.realize(layoutfont);
// if there is no selection that's all we need to do
if (!cur.selection())
// Ok, we have a selection.
recordUndoSelection(cur);
- 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_);
}
}
}
-// the cursor set functions have a special mechanism. When they
-// realize you left an empty paragraph, they will delete it.
-
-bool Text::cursorHome(Cursor & cur)
-{
- BOOST_ASSERT(this == cur.text());
- ParagraphMetrics const & pm = cur.bv().parMetrics(this, cur.pit());
- Row const & row = pm.getRow(cur.pos(),cur.boundary());
- return setCursor(cur, cur.pit(), row.pos());
-}
-
-
-bool Text::cursorEnd(Cursor & cur)
-{
- BOOST_ASSERT(this == cur.text());
- // if not on the last row of the par, put the cursor before
- // the final space exept if I have a spanning inset or one string
- // is so long that we force a break.
- pos_type end = cur.textRow().endpos();
- if (end == 0)
- // empty text, end-1 is no valid position
- return false;
- bool boundary = false;
- if (end != cur.lastpos()) {
- if (!cur.paragraph().isLineSeparator(end-1)
- && !cur.paragraph().isNewline(end-1))
- boundary = true;
- else
- --end;
- }
- return setCursor(cur, cur.pit(), end, true, boundary);
-}
-
-
bool Text::cursorTop(Cursor & cur)
{
BOOST_ASSERT(this == cur.text());
{
BOOST_ASSERT(this == cur.text());
BOOST_ASSERT(inset);
- cur.paragraph().insertInset(cur.pos(), inset, current_font,
+ cur.paragraph().insertInset(cur.pos(), inset, cur.current_font,
Change(cur.buffer().params().trackChanges ?
Change::INSERTED : Change::UNCHANGED));
}
void Text::insertStringAsLines(Cursor & cur, docstring const & str)
{
cur.buffer().insertStringAsLines(pars_, cur.pit(), cur.pos(),
- current_font, str, autoBreakRows_);
+ cur.current_font, str, autoBreakRows_);
}
cur.boundary(boundary);
setCursor(cur.top(), par, pos);
if (setfont)
- setCurrentFont(cur);
-}
-
-
-void Text::setCurrentFont(Cursor & cur)
-{
- BOOST_ASSERT(this == cur.text());
- pos_type pos = cur.pos();
- Paragraph & par = cur.paragraph();
-
- // are we behind previous char in fact? -> go to that char
- if (pos > 0 && cur.boundary())
- --pos;
-
- // find position to take the font from
- if (pos != 0) {
- // paragraph end? -> font of last char
- if (pos == cur.lastpos())
- --pos;
- // on space? -> look at the words in front of space
- else if (pos > 0 && par.isSeparator(pos)) {
- // abc| def -> font of c
- // abc |[WERBEH], i.e. boundary==true -> font of c
- // abc [WERBEH]| def, font of the space
- if (!isRTLBoundary(cur.buffer(), par, pos))
- --pos;
- }
- }
-
- // get font
- BufferParams const & bufparams = cur.buffer().params();
- current_font = par.getFontSettings(bufparams, pos);
- real_current_font = getFont(cur.buffer(), par, pos);
-
- // special case for paragraph end
- if (cur.pos() == cur.lastpos()
- && isRTLBoundary(cur.buffer(), par, cur.pos())
- && !cur.boundary()) {
- Language const * lang = par.getParLanguage(bufparams);
- current_font.setLanguage(lang);
- current_font.setNumber(Font::OFF);
- real_current_font.setLanguage(lang);
- real_current_font.setNumber(Font::OFF);
- }
+ cur.setCurrentFont();
}
// 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;
}
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()) {