2002-09-12 14:58:06 +00:00
|
|
|
/**
|
2007-04-26 04:41:58 +00:00
|
|
|
* \file paragraph_funcs.cpp
|
2002-09-12 14:58:06 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-08-21 17:35:24 +00:00
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Lars Gullik Bjønnes
|
2002-08-21 17:35:24 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-09-12 14:58:06 +00:00
|
|
|
*/
|
2002-08-20 19:41:13 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "paragraph_funcs.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "BufferParams.h"
|
2007-10-18 15:29:51 +00:00
|
|
|
#include "Changes.h"
|
|
|
|
#include "InsetList.h"
|
2007-09-29 20:02:32 +00:00
|
|
|
#include "Layout.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Paragraph.h"
|
2007-04-24 10:28:45 +00:00
|
|
|
#include "ParagraphParameters.h"
|
2007-10-18 15:29:51 +00:00
|
|
|
#include "Text.h"
|
2007-11-07 23:25:08 +00:00
|
|
|
#include "TextClass.h"
|
2003-10-30 08:47:16 +00:00
|
|
|
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/debug.h"
|
|
|
|
|
2008-04-30 08:26:40 +00:00
|
|
|
#include "support/lassert.h"
|
2007-09-30 15:47:00 +00:00
|
|
|
#include <boost/next_prior.hpp>
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2002-08-20 19:41:13 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
2003-05-19 17:03:12 +00:00
|
|
|
|
2006-11-05 18:39:03 +00:00
|
|
|
static bool moveItem(Paragraph & fromPar, pos_type fromPos,
|
|
|
|
Paragraph & toPar, pos_type toPos, BufferParams const & params)
|
2003-07-31 13:12:21 +00:00
|
|
|
{
|
2006-11-25 23:02:10 +00:00
|
|
|
// Note: moveItem() does not honour change tracking!
|
|
|
|
// Therefore, it should only be used for breaking and merging paragraphs
|
|
|
|
|
2008-10-28 17:41:56 +00:00
|
|
|
// We need a copy here because the character at fromPos is going to be erased.
|
|
|
|
Font const tmpFont = fromPar.getFontSettings(params, fromPos);
|
|
|
|
Change const tmpChange = fromPar.lookupChange(fromPos);
|
2003-07-31 13:12:21 +00:00
|
|
|
|
2008-10-08 14:52:07 +00:00
|
|
|
if (Inset * tmpInset = fromPar.getInset(fromPos)) {
|
|
|
|
fromPar.releaseInset(fromPos);
|
|
|
|
// The inset is not in fromPar any more.
|
2008-10-08 15:12:49 +00:00
|
|
|
if (!toPar.insertInset(toPos, tmpInset, tmpFont, tmpChange)) {
|
|
|
|
delete tmpInset;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2003-07-31 13:12:21 +00:00
|
|
|
}
|
2006-11-25 23:02:10 +00:00
|
|
|
|
2008-10-08 14:19:31 +00:00
|
|
|
char_type const tmpChar = fromPar.getChar(fromPos);
|
|
|
|
fromPar.eraseChar(fromPos, false);
|
|
|
|
toPar.insertChar(toPos, tmpChar, tmpFont, tmpChange);
|
2003-07-31 13:12:21 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-06 10:02:40 +00:00
|
|
|
void breakParagraph(BufferParams const & bparams,
|
2007-10-08 13:17:15 +00:00
|
|
|
ParagraphList & pars, pit_type par_offset, pos_type pos,
|
|
|
|
bool keep_layout)
|
2002-08-20 19:41:13 +00:00
|
|
|
{
|
2003-03-04 19:52:35 +00:00
|
|
|
// create a new paragraph, and insert into the list
|
2004-03-25 09:16:36 +00:00
|
|
|
ParagraphList::iterator tmp =
|
2006-03-23 20:11:06 +00:00
|
|
|
pars.insert(boost::next(pars.begin(), par_offset + 1),
|
|
|
|
Paragraph());
|
2004-08-13 20:26:26 +00:00
|
|
|
|
|
|
|
Paragraph & par = pars[par_offset];
|
2003-03-04 21:40:36 +00:00
|
|
|
|
It used to be that things like InsetFlex, InsetCaption, and the like used the default layout, whatever that is---usually Standard. That gave rise to bug 2178, the solution to which is to define a new empty layout, which insets like these use instead of the default. See r22966.
So, when we have an older LyX file, it will look like this:
\begin_inset ERT
status open
\begin_layout Standard
this that
\end_layout
\end_inset
which is now invalid, because ERT uses only PlainLayout. So I had put some code into Text::readParToken, where the layout for a paragraph gets set as it is read:
if (par.forceEmptyLayout()) {
// in this case only the empty layout is allowed
layoutname = tclass.emptyLayoutName();
} else if (par.useEmptyLayout()) {
// in this case, default layout maps to empty layout
if (layoutname == tclass.defaultLayoutName())
layoutname = tclass.emptyLayoutName();
} else {
// otherwise, the empty layout maps to the default
if (layoutname == tclass.emptyLayoutName())
layoutname = tclass.defaultLayoutName();
}
This turns out not to work, because par.forceEmptyLayout() and par.useEmptyLayout() always return false here, because par.inInset() always returns a null pointer, because the paragraph's inset hasn't yet been set when Text::readParagraph() gets called from Text::read() gets called from InsetText::read(). The solution is to set the paragraph's inset when it is created, which means passing a pointer to the various read() routines along the way.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23057 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-19 02:35:07 +00:00
|
|
|
// remember to set the inset_owner
|
2008-09-13 17:01:54 +00:00
|
|
|
tmp->setInsetOwner(&par.inInset());
|
2002-08-21 15:39:54 +00:00
|
|
|
// without doing that we get a crash when typing <Return> at the
|
|
|
|
// end of a paragraph
|
2008-07-10 17:41:52 +00:00
|
|
|
tmp->setPlainOrDefaultLayout(bparams.documentClass());
|
2002-08-21 17:35:24 +00:00
|
|
|
|
2002-08-20 19:41:13 +00:00
|
|
|
// layout stays the same with latex-environments
|
2007-10-08 13:17:15 +00:00
|
|
|
if (keep_layout) {
|
2008-02-23 16:45:38 +00:00
|
|
|
tmp->setLayout(par.layout());
|
2004-08-13 20:26:26 +00:00
|
|
|
tmp->setLabelWidthString(par.params().labelWidthString());
|
2006-04-03 18:28:13 +00:00
|
|
|
tmp->params().depth(par.params().depth());
|
2006-09-15 09:38:40 +00:00
|
|
|
} else if (par.params().depth() > 0) {
|
|
|
|
Paragraph const & hook = pars[outerHook(par_offset, pars)];
|
2008-02-23 16:45:38 +00:00
|
|
|
tmp->setLayout(hook.layout());
|
2006-09-15 09:38:40 +00:00
|
|
|
// not sure the line below is useful
|
|
|
|
tmp->setLabelWidthString(par.params().labelWidthString());
|
|
|
|
tmp->params().depth(hook.params().depth());
|
2002-08-20 19:41:13 +00:00
|
|
|
}
|
|
|
|
|
2004-08-13 20:26:26 +00:00
|
|
|
bool const isempty = (par.allowEmpty() && par.empty());
|
2002-08-21 17:35:24 +00:00
|
|
|
|
2007-10-08 13:17:15 +00:00
|
|
|
if (!isempty && (par.size() > pos || par.empty())) {
|
2008-02-23 16:45:38 +00:00
|
|
|
tmp->setLayout(par.layout());
|
2004-08-13 20:26:26 +00:00
|
|
|
tmp->params().align(par.params().align());
|
|
|
|
tmp->setLabelWidthString(par.params().labelWidthString());
|
2002-08-21 17:35:24 +00:00
|
|
|
|
2004-08-13 20:26:26 +00:00
|
|
|
tmp->params().depth(par.params().depth());
|
|
|
|
tmp->params().noindent(par.params().noindent());
|
2002-08-21 17:35:24 +00:00
|
|
|
|
2006-11-26 11:14:16 +00:00
|
|
|
// move everything behind the break position
|
2002-08-20 19:41:13 +00:00
|
|
|
// to the new paragraph
|
2002-11-07 00:37:09 +00:00
|
|
|
|
2004-03-28 19:13:11 +00:00
|
|
|
/* Note: if !keepempty, empty() == true, then we reach
|
|
|
|
* here with size() == 0. So pos_end becomes - 1. This
|
|
|
|
* doesn't cause problems because both loops below
|
|
|
|
* enforce pos <= pos_end and 0 <= pos
|
2002-11-07 00:37:09 +00:00
|
|
|
*/
|
2004-08-13 20:26:26 +00:00
|
|
|
pos_type pos_end = par.size() - 1;
|
2003-02-08 19:18:01 +00:00
|
|
|
|
2006-11-25 23:02:10 +00:00
|
|
|
for (pos_type i = pos, j = 0; i <= pos_end; ++i) {
|
|
|
|
if (moveItem(par, pos, *tmp, j, bparams)) {
|
2002-08-20 19:41:13 +00:00
|
|
|
++j;
|
2003-02-08 19:18:01 +00:00
|
|
|
}
|
2002-08-20 19:41:13 +00:00
|
|
|
}
|
|
|
|
}
|
2002-08-21 17:35:24 +00:00
|
|
|
|
2006-11-26 11:14:16 +00:00
|
|
|
// Move over the end-of-par change information
|
|
|
|
tmp->setChange(tmp->size(), par.lookupChange(par.size()));
|
|
|
|
par.setChange(par.size(), Change(bparams.trackChanges ?
|
2007-05-28 22:27:45 +00:00
|
|
|
Change::INSERTED : Change::UNCHANGED));
|
2006-11-26 11:14:16 +00:00
|
|
|
|
2004-08-13 20:26:26 +00:00
|
|
|
if (pos) {
|
|
|
|
// Make sure that we keep the language when
|
2006-11-25 23:02:10 +00:00
|
|
|
// breaking paragraph.
|
2004-08-13 20:26:26 +00:00
|
|
|
if (tmp->empty()) {
|
2007-04-29 18:17:15 +00:00
|
|
|
Font changed = tmp->getFirstFontSettings(bparams);
|
2008-10-19 07:03:44 +00:00
|
|
|
Font const & old = par.getFontSettings(bparams, par.size());
|
2004-08-13 20:26:26 +00:00
|
|
|
changed.setLanguage(old.language());
|
|
|
|
tmp->setFont(0, changed);
|
|
|
|
}
|
|
|
|
|
2002-09-12 14:58:06 +00:00
|
|
|
return;
|
2004-08-13 20:26:26 +00:00
|
|
|
}
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2006-04-05 23:56:29 +00:00
|
|
|
if (!isempty) {
|
2007-09-07 09:55:57 +00:00
|
|
|
bool const soa = par.params().startOfAppendix();
|
2006-04-05 23:56:29 +00:00
|
|
|
par.params().clear();
|
2007-09-07 09:55:57 +00:00
|
|
|
// do not lose start of appendix marker (bug 4212)
|
|
|
|
par.params().startOfAppendix(soa);
|
2008-07-10 17:41:52 +00:00
|
|
|
par.setPlainOrDefaultLayout(bparams.documentClass());
|
2006-04-05 23:56:29 +00:00
|
|
|
}
|
|
|
|
|
2002-09-12 14:58:06 +00:00
|
|
|
// layout stays the same with latex-environments
|
2007-10-08 13:17:15 +00:00
|
|
|
if (keep_layout) {
|
2008-02-23 16:45:38 +00:00
|
|
|
par.setLayout(tmp->layout());
|
2004-08-13 20:26:26 +00:00
|
|
|
par.setLabelWidthString(tmp->params().labelWidthString());
|
|
|
|
par.params().depth(tmp->params().depth());
|
2002-08-20 19:41:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-06 10:02:40 +00:00
|
|
|
void breakParagraphConservative(BufferParams const & bparams,
|
2004-11-24 21:53:46 +00:00
|
|
|
ParagraphList & pars, pit_type par_offset, pos_type pos)
|
2002-08-20 19:41:13 +00:00
|
|
|
{
|
|
|
|
// create a new paragraph
|
2006-03-23 20:11:06 +00:00
|
|
|
Paragraph & tmp = *pars.insert(boost::next(pars.begin(), par_offset + 1),
|
|
|
|
Paragraph());
|
2004-08-13 20:26:26 +00:00
|
|
|
Paragraph & par = pars[par_offset];
|
|
|
|
|
2008-09-13 17:01:54 +00:00
|
|
|
tmp.setInsetOwner(&par.inInset());
|
2004-08-13 20:26:26 +00:00
|
|
|
tmp.makeSameLayout(par);
|
2002-08-20 19:41:13 +00:00
|
|
|
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(pos <= par.size(), /**/);
|
2006-11-25 23:02:10 +00:00
|
|
|
|
|
|
|
if (pos < par.size()) {
|
|
|
|
// move everything behind the break position to the new paragraph
|
2004-08-13 20:26:26 +00:00
|
|
|
pos_type pos_end = par.size() - 1;
|
2002-08-20 19:41:13 +00:00
|
|
|
|
2006-11-25 23:02:10 +00:00
|
|
|
for (pos_type i = pos, j = 0; i <= pos_end; ++i) {
|
|
|
|
if (moveItem(par, pos, tmp, j, bparams)) {
|
2002-08-20 19:41:13 +00:00
|
|
|
++j;
|
2006-11-05 18:39:03 +00:00
|
|
|
}
|
2005-02-24 13:17:45 +00:00
|
|
|
}
|
2006-11-25 23:02:10 +00:00
|
|
|
// Move over the end-of-par change information
|
|
|
|
tmp.setChange(tmp.size(), par.lookupChange(par.size()));
|
|
|
|
par.setChange(par.size(), Change(bparams.trackChanges ?
|
2007-05-28 22:27:45 +00:00
|
|
|
Change::INSERTED : Change::UNCHANGED));
|
2002-08-20 19:41:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-06 10:02:40 +00:00
|
|
|
void mergeParagraph(BufferParams const & bparams,
|
2004-11-24 21:53:46 +00:00
|
|
|
ParagraphList & pars, pit_type par_offset)
|
2002-08-20 19:41:13 +00:00
|
|
|
{
|
2004-08-13 20:26:26 +00:00
|
|
|
Paragraph & next = pars[par_offset + 1];
|
|
|
|
Paragraph & par = pars[par_offset];
|
2002-08-20 19:41:13 +00:00
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
pos_type pos_end = next.size() - 1;
|
2004-08-13 20:26:26 +00:00
|
|
|
pos_type pos_insert = par.size();
|
2002-08-20 19:41:13 +00:00
|
|
|
|
2006-11-26 13:35:11 +00:00
|
|
|
// the imaginary end-of-paragraph character (at par.size()) has to be
|
2006-11-05 19:00:53 +00:00
|
|
|
// marked as unmodified. Otherwise, its change is adopted by the first
|
|
|
|
// character of the next paragraph.
|
2006-11-26 13:35:11 +00:00
|
|
|
if (par.lookupChange(par.size()).type != Change::UNCHANGED) {
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::CHANGES,
|
|
|
|
"merging par with inserted/deleted end-of-par character");
|
2006-11-26 13:35:11 +00:00
|
|
|
par.setChange(par.size(), Change(Change::UNCHANGED));
|
|
|
|
}
|
2006-03-16 06:54:08 +00:00
|
|
|
|
2006-11-05 19:00:53 +00:00
|
|
|
Change change = next.lookupChange(next.size());
|
2006-11-26 13:35:11 +00:00
|
|
|
|
|
|
|
// move the content of the second paragraph to the end of the first one
|
2006-11-25 23:02:10 +00:00
|
|
|
for (pos_type i = 0, j = pos_insert; i <= pos_end; ++i) {
|
|
|
|
if (moveItem(next, 0, par, j, bparams)) {
|
2002-08-20 19:41:13 +00:00
|
|
|
++j;
|
2006-11-05 18:39:03 +00:00
|
|
|
}
|
2005-02-24 13:17:45 +00:00
|
|
|
}
|
2006-11-26 13:35:11 +00:00
|
|
|
|
|
|
|
// move the change of the end-of-paragraph character
|
2006-11-05 19:00:53 +00:00
|
|
|
par.setChange(par.size(), change);
|
2002-08-20 19:41:13 +00:00
|
|
|
|
2006-03-23 20:11:06 +00:00
|
|
|
pars.erase(boost::next(pars.begin(), par_offset + 1));
|
2002-08-20 19:41:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
pit_type depthHook(pit_type pit, ParagraphList const & pars, depth_type depth)
|
2002-08-20 19:41:13 +00:00
|
|
|
{
|
2004-11-24 21:53:46 +00:00
|
|
|
pit_type newpit = pit;
|
2002-08-20 19:41:13 +00:00
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
if (newpit != 0)
|
2003-04-16 08:12:22 +00:00
|
|
|
--newpit;
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
while (newpit != 0 && pars[newpit].getDepth() > depth)
|
2003-04-16 08:12:22 +00:00
|
|
|
--newpit;
|
2003-04-14 18:35:29 +00:00
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
if (pars[newpit].getDepth() > depth)
|
2003-04-16 08:12:22 +00:00
|
|
|
return pit;
|
|
|
|
|
|
|
|
return newpit;
|
2002-08-20 19:41:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-24 21:53:46 +00:00
|
|
|
pit_type outerHook(pit_type par_offset, ParagraphList const & pars)
|
2002-08-20 19:41:13 +00:00
|
|
|
{
|
2004-08-13 20:26:26 +00:00
|
|
|
Paragraph const & par = pars[par_offset];
|
|
|
|
|
|
|
|
if (par.getDepth() == 0)
|
2004-03-25 09:16:36 +00:00
|
|
|
return pars.size();
|
2006-10-21 00:16:43 +00:00
|
|
|
return depthHook(par_offset, pars, depth_type(par.getDepth() - 1));
|
2002-08-20 19:41:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-24 21:53:46 +00:00
|
|
|
bool isFirstInSequence(pit_type par_offset, ParagraphList const & pars)
|
2002-08-20 19:41:13 +00:00
|
|
|
{
|
2004-08-13 20:26:26 +00:00
|
|
|
Paragraph const & par = pars[par_offset];
|
|
|
|
|
2004-11-24 21:53:46 +00:00
|
|
|
pit_type dhook_offset = depthHook(par_offset, pars, par.getDepth());
|
2004-08-13 20:26:26 +00:00
|
|
|
|
2007-01-11 18:50:39 +00:00
|
|
|
if (dhook_offset == par_offset)
|
|
|
|
return true;
|
|
|
|
|
2004-08-13 20:26:26 +00:00
|
|
|
Paragraph const & dhook = pars[dhook_offset];
|
|
|
|
|
2007-01-11 18:50:39 +00:00
|
|
|
return dhook.layout() != par.layout()
|
2004-08-13 20:26:26 +00:00
|
|
|
|| dhook.getDepth() != par.getDepth();
|
2002-08-20 19:41:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-25 07:52:55 +00:00
|
|
|
void setLabelWidthStringToSequence(pit_type par_offset,
|
|
|
|
ParagraphList & pars, docstring const & s)
|
|
|
|
{
|
|
|
|
Paragraph & par = pars[par_offset];
|
|
|
|
// Find first of same layout in sequence
|
|
|
|
while (!isFirstInSequence(par_offset, pars)) {
|
|
|
|
par_offset = depthHook(par_offset, pars, par.getDepth());
|
|
|
|
par = pars[par_offset];
|
|
|
|
}
|
|
|
|
|
|
|
|
// now apply label width string to every par
|
|
|
|
// in sequence
|
|
|
|
pit_type const end = pars.size();
|
|
|
|
depth_type const depth = par.getDepth();
|
|
|
|
Layout const & layout = par.layout();
|
|
|
|
for (pit_type pit = par_offset; pit != end; ++pit) {
|
|
|
|
while (pars[pit].getDepth() > depth)
|
|
|
|
++pit;
|
|
|
|
if (pars[pit].getDepth() < depth)
|
|
|
|
return;
|
|
|
|
if (pars[pit].layout() != layout)
|
|
|
|
return;
|
|
|
|
pars[pit].setLabelWidthString(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-24 21:53:46 +00:00
|
|
|
int getEndLabel(pit_type p, ParagraphList const & pars)
|
2002-08-20 19:41:13 +00:00
|
|
|
{
|
2004-11-24 21:53:46 +00:00
|
|
|
pit_type pit = p;
|
2006-10-21 00:16:43 +00:00
|
|
|
depth_type par_depth = pars[p].getDepth();
|
2004-11-24 21:53:46 +00:00
|
|
|
while (pit != pit_type(pars.size())) {
|
2008-03-06 21:31:27 +00:00
|
|
|
Layout const & layout = pars[pit].layout();
|
|
|
|
int const endlabeltype = layout.endlabeltype;
|
2003-04-14 18:35:29 +00:00
|
|
|
|
2002-08-20 19:41:13 +00:00
|
|
|
if (endlabeltype != END_LABEL_NO_LABEL) {
|
2004-11-24 21:53:46 +00:00
|
|
|
if (p + 1 == pit_type(pars.size()))
|
2002-08-20 19:41:13 +00:00
|
|
|
return endlabeltype;
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
depth_type const next_depth =
|
2004-03-25 09:16:36 +00:00
|
|
|
pars[p + 1].getDepth();
|
2002-08-20 19:41:13 +00:00
|
|
|
if (par_depth > next_depth ||
|
2004-03-25 09:16:36 +00:00
|
|
|
(par_depth == next_depth && layout != pars[p + 1].layout()))
|
2002-08-20 19:41:13 +00:00
|
|
|
return endlabeltype;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (par_depth == 0)
|
|
|
|
break;
|
2004-03-25 09:16:36 +00:00
|
|
|
pit = outerHook(pit, pars);
|
2004-11-24 21:53:46 +00:00
|
|
|
if (pit != pit_type(pars.size()))
|
2004-03-25 09:16:36 +00:00
|
|
|
par_depth = pars[pit].getDepth();
|
2002-08-20 19:41:13 +00:00
|
|
|
}
|
|
|
|
return END_LABEL_NO_LABEL;
|
|
|
|
}
|
2003-03-03 21:15:49 +00:00
|
|
|
|
|
|
|
|
2007-04-29 18:17:15 +00:00
|
|
|
Font const outerFont(pit_type par_offset, ParagraphList const & pars)
|
2003-03-12 11:52:23 +00:00
|
|
|
{
|
2006-10-21 00:16:43 +00:00
|
|
|
depth_type par_depth = pars[par_offset].getDepth();
|
2007-10-28 18:51:54 +00:00
|
|
|
FontInfo tmpfont = inherit_font;
|
2003-04-14 18:35:29 +00:00
|
|
|
|
|
|
|
// Resolve against environment font information
|
2004-11-24 21:53:46 +00:00
|
|
|
while (par_offset != pit_type(pars.size())
|
2004-03-27 01:18:51 +00:00
|
|
|
&& par_depth
|
|
|
|
&& !tmpfont.resolved()) {
|
2004-08-13 20:26:26 +00:00
|
|
|
par_offset = outerHook(par_offset, pars);
|
2004-11-24 21:53:46 +00:00
|
|
|
if (par_offset != pit_type(pars.size())) {
|
2008-03-06 21:31:27 +00:00
|
|
|
tmpfont.realize(pars[par_offset].layout().font);
|
2004-08-13 20:26:26 +00:00
|
|
|
par_depth = pars[par_offset].getDepth();
|
2003-04-14 18:35:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-28 18:51:54 +00:00
|
|
|
return Font(tmpfont);
|
2003-04-15 00:11:03 +00:00
|
|
|
}
|
2003-08-26 14:50:16 +00:00
|
|
|
|
|
|
|
|
2009-05-14 22:21:05 +00:00
|
|
|
bool isFullyDeleted(ParagraphList const & pars)
|
|
|
|
{
|
|
|
|
pit_type const pars_size = static_cast<pit_type>(pars.size());
|
|
|
|
|
|
|
|
// check all paragraphs
|
|
|
|
for (pit_type pit = 0; pit < pars_size; ++pit) {
|
|
|
|
if (!pars[pit].empty()) // prevent assertion failure
|
|
|
|
if (!pars[pit].isFullyDeleted(0, pars[pit].size()))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-06-26 14:11:42 +00:00
|
|
|
void acceptChanges(ParagraphList & pars, BufferParams const & bparams)
|
|
|
|
{
|
|
|
|
pit_type pars_size = static_cast<pit_type>(pars.size());
|
|
|
|
|
|
|
|
// first, accept changes within each individual paragraph
|
|
|
|
// (do not consider end-of-par)
|
|
|
|
for (pit_type pit = 0; pit < pars_size; ++pit) {
|
|
|
|
if (!pars[pit].empty()) // prevent assertion failure
|
2009-07-16 08:37:32 +00:00
|
|
|
pars[pit].acceptChanges(0, pars[pit].size());
|
2007-06-26 14:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// next, accept imaginary end-of-par characters
|
|
|
|
for (pit_type pit = 0; pit < pars_size; ++pit) {
|
|
|
|
pos_type pos = pars[pit].size();
|
|
|
|
|
|
|
|
if (pars[pit].isInserted(pos)) {
|
|
|
|
pars[pit].setChange(pos, Change(Change::UNCHANGED));
|
|
|
|
} else if (pars[pit].isDeleted(pos)) {
|
|
|
|
if (pit == pars_size - 1) {
|
|
|
|
// we cannot remove a par break at the end of the last
|
|
|
|
// paragraph; instead, we mark it unchanged
|
|
|
|
pars[pit].setChange(pos, Change(Change::UNCHANGED));
|
|
|
|
} else {
|
|
|
|
mergeParagraph(bparams, pars, pit);
|
|
|
|
--pit;
|
|
|
|
--pars_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|