using std::endl;
using std::ostringstream;
using std::string;
+using std::max;
using std::min;
LyXText::LyXText(BufferView * bv)
: maxwidth_(bv ? bv->workWidth() : 100),
+ current_font(LyXFont::ALL_INHERIT),
background_color_(LColor::background),
bv_owner(bv),
autoBreakRows_(false)
if (!isMainText())
applyOuterFont(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
+ if (pit < pars_.size())
+ font.realize(outerFont(pit, pars_));
+
// Realize with the fonts of lesser depth.
- font.realize(defaultfont_);
+ font.realize(params.getFont());
return font;
}
// font.
void LyXText::applyOuterFont(LyXFont & font) const {
LyXFont lf(font_);
- lf.reduce(defaultfont_);
+ lf.reduce(bv()->buffer()->params().getFont());
lf.realize(font);
lf.setLanguage(font.language());
font = lf;
LyXFont font = layout->font;
// Realize with the fonts of lesser depth.
//font.realize(outerFont(pit, paragraphs()));
- font.realize(defaultfont_);
+ font.realize(bv()->buffer()->params().getFont());
return font;
}
LyXFont font = layout->labelfont;
// Realize with the fonts of lesser depth.
- font.realize(defaultfont_);
+ font.realize(bv()->buffer()->params().getFont());
return font;
}
}
}
- layoutfont.realize(defaultfont_);
+ // Inside inset, apply the inset's font attributes if any
+ // (charstyle!)
+ if (!isMainText())
+ layoutfont.realize(font_);
+
+ layoutfont.realize(bv()->buffer()->params().getFont());
// Now, reduce font against full layout font
font.reduce(layoutfont);
}
-// used in setLayout
-// Asger is not sure we want to do this...
-void LyXText::makeFontEntriesLayoutSpecific(BufferParams const & params,
- Paragraph & par)
-{
- LyXLayout_ptr const & layout = par.layout();
- pos_type const psize = par.size();
-
- LyXFont layoutfont;
- for (pos_type pos = 0; pos < psize; ++pos) {
- if (pos < par.beginOfBody())
- layoutfont = layout->labelfont;
- else
- layoutfont = layout->font;
-
- LyXFont tmpfont = par.getFontSettings(params, pos);
- tmpfont.reduce(layoutfont);
- par.setFont(pos, tmpfont);
- }
-}
-
-
// return past-the-last paragraph influenced by a layout change on pit
pit_type LyXText::undoSpan(pit_type pit)
{
for (pit_type pit = start; pit != end; ++pit) {
pars_[pit].applyLayout(lyxlayout);
- makeFontEntriesLayoutSpecific(bufparams, pars_[pit]);
if (lyxlayout->margintype == MARGIN_MANUAL)
pars_[pit].setLabelWidthString(lyxlayout->labelstring());
}
// the cursor set functions have a special mechanism. When they
// realize you left an empty paragraph, they will delete it.
-void LyXText::cursorHome(LCursor & cur)
+bool LyXText::cursorHome(LCursor & cur)
{
BOOST_ASSERT(this == cur.text());
Row const & row = cur.paragraph().getRow(cur.pos(),cur.boundary());
- setCursor(cur, cur.pit(), row.pos());
+ return setCursor(cur, cur.pit(), row.pos());
}
-void LyXText::cursorEnd(LCursor & cur)
+bool LyXText::cursorEnd(LCursor & cur)
{
BOOST_ASSERT(this == cur.text());
// if not on the last row of the par, put the cursor before
pos_type end = cur.textRow().endpos();
if (end == 0)
// empty text, end-1 is no valid position
- return;
+ return false;
bool boundary = false;
if (end != cur.lastpos()) {
if (!cur.paragraph().isLineSeparator(end-1)
else
--end;
}
- setCursor(cur, cur.pit(), end, true, boundary);
+ return setCursor(cur, cur.pit(), end, true, boundary);
}
-void LyXText::cursorTop(LCursor & cur)
+bool LyXText::cursorTop(LCursor & cur)
{
BOOST_ASSERT(this == cur.text());
- setCursor(cur, 0, 0);
+ return setCursor(cur, 0, 0);
}
-void LyXText::cursorBottom(LCursor & cur)
+bool LyXText::cursorBottom(LCursor & cur)
{
BOOST_ASSERT(this == cur.text());
- setCursor(cur, cur.lastpit(), boost::prior(paragraphs().end())->size());
+ return setCursor(cur, cur.lastpit(), boost::prior(paragraphs().end())->size());
}
linestr[i] = ' ';
newline_inserted = true;
}
- } else if (IsPrintable(linestr[i])) {
+ } else if (isPrintable(linestr[i])) {
newline_inserted = false;
}
}
// This should be just before or just behind the
// cursor position set above.
BOOST_ASSERT((pos != 0 && inset == pars_[pit].getInset(pos - 1))
- || inset == pars_[pit].getInset(pos));
+ || inset == pars_[pit].getInset(pos));
// Make sure the cursor points to the position before
// this inset.
if (inset == pars_[pit].getInset(pos - 1))
if (oldpar.empty() || (oldpar.size() == 1 && oldpar.isLineSeparator(0))) {
// Delete old par.
- recordUndo(old, Undo::ATOMIC, old.pit());
+ recordUndo(old, Undo::ATOMIC,
+ max(old.pit() - 1, pit_type(0)),
+ min(old.pit() + 1, old.lastpit()));
ParagraphList & plist = old.text()->paragraphs();
- plist.erase(plist.begin() + old.pit());
+ plist.erase(boost::next(plist.begin(), old.pit()));
// see #warning above
if (cur.depth() >= old.depth()) {
CursorSlice & curslice = cur[old.depth() - 1];
- if (&curslice.inset() == &old.inset()
+ if (&curslice.inset() == &old.inset()
&& curslice.pit() > old.pit()) {
--curslice.pit();
// since a paragraph has been deleted, all the
cur.resetAnchor();
}
}
- updateCounters(old.buffer());
+ ParIterator par_it(old);
+ if (needsUpdateCounters(old.buffer(), par_it))
+ updateCounters(old.buffer());
return true;
}