#include "Paragraph.h"
+#include "LayoutFile.h"
#include "Buffer.h"
#include "BufferParams.h"
#include "Changes.h"
#include "insets/InsetBibitem.h"
#include "insets/InsetLabel.h"
+#include "support/assert.h"
#include "support/convert.h"
#include "support/debug.h"
#include "support/gettext.h"
{
public:
///
- Private(Paragraph * owner);
+ Private(Paragraph * owner, Layout const & layout);
/// "Copy constructor"
Private(Private const &, Paragraph * owner);
///
InsetList insetlist_;
- ///
- LayoutPtr layout_;
-
/// end of label
pos_type begin_of_body_;
typedef std::set<docstring> Words;
///
Words words_;
+ ///
+ Layout const * layout_;
};
} // namespace anon
-Paragraph::Private::Private(Paragraph * owner)
- : owner_(owner), inset_owner_(0), begin_of_body_(0)
+Paragraph::Private::Private(Paragraph * owner, Layout const & layout)
+ : owner_(owner), inset_owner_(0), begin_of_body_(0), layout_(&layout)
{
id_ = paragraph_id++;
text_.reserve(100);
Paragraph::Private::Private(Private const & p, Paragraph * owner)
: owner_(owner), inset_owner_(p.inset_owner_), fontlist_(p.fontlist_),
params_(p.params_), changes_(p.changes_), insetlist_(p.insetlist_),
- layout_(p.layout_), begin_of_body_(p.begin_of_body_), text_(p.text_),
- words_(p.words_)
+ begin_of_body_(p.begin_of_body_), text_(p.text_), words_(p.words_),
+ layout_(p.layout_)
{
id_ = paragraph_id++;
}
bool Paragraph::isChanged(pos_type start, pos_type end) const
{
- BOOST_ASSERT(start >= 0 && start <= size());
- BOOST_ASSERT(end > start && end <= size() + 1);
+ LASSERT(start >= 0 && start <= size(), /**/);
+ LASSERT(end > start && end <= size() + 1, /**/);
return d->changes_.isChanged(start, end);
}
void Paragraph::setChange(pos_type pos, Change const & change)
{
- BOOST_ASSERT(pos >= 0 && pos <= size());
+ LASSERT(pos >= 0 && pos <= size(), /**/);
d->changes_.set(change, pos);
// see comment in setChange(Change const &) above
Change const & Paragraph::lookupChange(pos_type pos) const
{
- BOOST_ASSERT(pos >= 0 && pos <= size());
+ LASSERT(pos >= 0 && pos <= size(), /**/);
return d->changes_.lookup(pos);
}
void Paragraph::acceptChanges(BufferParams const & bparams, pos_type start,
pos_type end)
{
- BOOST_ASSERT(start >= 0 && start <= size());
- BOOST_ASSERT(end > start && end <= size() + 1);
+ LASSERT(start >= 0 && start <= size(), /**/);
+ LASSERT(end > start && end <= size() + 1, /**/);
for (pos_type pos = start; pos < end; ++pos) {
switch (lookupChange(pos).type) {
void Paragraph::rejectChanges(BufferParams const & bparams,
pos_type start, pos_type end)
{
- BOOST_ASSERT(start >= 0 && start <= size());
- BOOST_ASSERT(end > start && end <= size() + 1);
+ LASSERT(start >= 0 && start <= size(), /**/);
+ LASSERT(end > start && end <= size() + 1, /**/);
for (pos_type pos = start; pos < end; ++pos) {
switch (lookupChange(pos).type) {
void Paragraph::Private::insertChar(pos_type pos, char_type c,
Change const & change)
{
- BOOST_ASSERT(pos >= 0 && pos <= int(text_.size()));
+ LASSERT(pos >= 0 && pos <= int(text_.size()), /**/);
// track change
changes_.insert(change, pos);
void Paragraph::insertInset(pos_type pos, Inset * inset,
Change const & change)
{
- BOOST_ASSERT(inset);
- BOOST_ASSERT(pos >= 0 && pos <= size());
+ LASSERT(inset, /**/);
+ LASSERT(pos >= 0 && pos <= size(), /**/);
d->insertChar(pos, META_INSET, change);
- BOOST_ASSERT(d->text_[pos] == META_INSET);
+ LASSERT(d->text_[pos] == META_INSET, /**/);
// Add a new entry in the insetlist_.
d->insetlist_.insert(inset, pos);
bool Paragraph::eraseChar(pos_type pos, bool trackChanges)
{
- BOOST_ASSERT(pos >= 0 && pos <= size());
+ LASSERT(pos >= 0 && pos <= size(), /**/);
// keep the logic here in sync with the logic of isMergedOnEndOfParDeletion()
int Paragraph::eraseChars(pos_type start, pos_type end, bool trackChanges)
{
- BOOST_ASSERT(start >= 0 && start <= size());
- BOOST_ASSERT(end >= start && end <= size() + 1);
+ LASSERT(start >= 0 && start <= size(), /**/);
+ LASSERT(end >= start && end <= size() + 1, /**/);
pos_type i = start;
for (pos_type count = end - start; count; --count) {
unsigned int & column)
{
Inset * inset = owner_->getInset(i);
- BOOST_ASSERT(inset);
+ LASSERT(inset, /**/);
if (style.pass_thru) {
inset->plaintext(os, runparams);
//
/////////////////////////////////////////////////////////////////////
-Paragraph::Paragraph()
- : d(new Paragraph::Private(this))
+namespace {
+ Layout const emptyParagraphLayout;
+}
+
+Paragraph::Paragraph()
+ : d(new Paragraph::Private(this, emptyParagraphLayout))
{
itemdepth = 0;
d->params_.clear();
if (c != '\0')
os << to_utf8(docstring(1, c));
else
- lyxerr << "ERROR (Paragraph::writeFile):"
- " NULL char in structure." << endl;
+ LYXERR0("NUL char in structure.");
++column;
break;
}
pos_type pos) const
{
if (pos > size()) {
- lyxerr << " pos: " << pos << " size: " << size() << endl;
- BOOST_ASSERT(pos <= size());
+ LYXERR0("pos: " << pos << " size: " << size());
+ LASSERT(pos <= size(), /**/);
}
FontList::const_iterator cit = d->fontlist_.fontIterator(pos);
FontSpan Paragraph::fontSpan(pos_type pos) const
{
- BOOST_ASSERT(pos <= size());
+ LASSERT(pos <= size(), /**/);
pos_type start = 0;
FontList::const_iterator cit = d->fontlist_.begin();
}
// This should not happen, but if so, we take no chances.
- //lyxerr << "Paragraph::getEndPosOfFontSpan: This should not happen!"
- // << endl;
+ // LYXERR0("Paragraph::getEndPosOfFontSpan: This should not happen!");
return FontSpan(pos, pos);
}
Font const Paragraph::getFont(BufferParams const & bparams, pos_type pos,
Font const & outerfont) const
{
- BOOST_ASSERT(pos >= 0);
+ LASSERT(pos >= 0, /**/);
Font font = getFontSettings(bparams, pos);
}
-char_type
-Paragraph::getUChar(BufferParams const & bparams, pos_type pos) const
+char_type Paragraph::getUChar(BufferParams const & bparams, pos_type pos) const
{
char_type c = d->text_[pos];
if (!lyxrc.rtl_support)
}
if (uc != c && getFontSettings(bparams, pos).isRightToLeft())
return uc;
- else
- return c;
+ return c;
}
void Paragraph::setFont(pos_type pos, Font const & font)
{
- BOOST_ASSERT(pos <= size());
+ LASSERT(pos <= size(), /**/);
// First, reduce font against layout/label font
// Update: The setCharFont() routine in text2.cpp already
bool Paragraph::hasSameLayout(Paragraph const & par) const
{
- return par.d->layout_ == d->layout_ && d->params_.sameLayout(par.d->params_);
+ return par.d->layout_ == d->layout_
+ && d->params_.sameLayout(par.d->params_);
}
}
-docstring Paragraph::expandLabel(LayoutPtr const & layout,
+docstring Paragraph::expandLabel(Layout const & layout,
BufferParams const & bparams, bool process_appendix) const
{
DocumentClass const & tclass = bparams.documentClass();
docstring fmt;
if (process_appendix && d->params_.appendix())
- fmt = translateIfPossible(layout->labelstring_appendix(),
+ fmt = translateIfPossible(layout.labelstring_appendix(),
bparams);
else
- fmt = translateIfPossible(layout->labelstring(), bparams);
+ fmt = translateIfPossible(layout.labelstring(), bparams);
- if (fmt.empty() && layout->labeltype == LABEL_COUNTER
- && !layout->counter.empty())
- fmt = "\\the" + layout->counter;
+ if (fmt.empty() && layout.labeltype == LABEL_COUNTER
+ && !layout.counter.empty())
+ fmt = "\\the" + layout.counter;
// handle 'inherited level parts' in 'fmt',
// i.e. the stuff between '@' in '@Section@.\arabic{subsection}'
}
-void Paragraph::applyLayout(LayoutPtr const & new_layout)
+void Paragraph::applyLayout(Layout const & new_layout)
{
- d->layout_ = new_layout;
+ d->layout_ = &new_layout;
LyXAlignment const oldAlign = d->params_.align();
if (!(oldAlign & d->layout_->alignpossible)) {
bool Paragraph::forceEmptyLayout() const
{
- return inInset() && inInset()->forceEmptyLayout();
+ Inset const * const inset = inInset();
+ if (!inset)
+ return true;
+ return inset->forceEmptyLayout();
}
bool Paragraph::allowParagraphCustomization() const
{
- return inInset() && inInset()->allowParagraphCustomization(0);
+ Inset const * const inset = inInset();
+ if (!inset)
+ return true;
+ return inset->allowParagraphCustomization();
}
bool Paragraph::useEmptyLayout() const
{
- return inInset() && inInset()->useEmptyLayout();
+ Inset const * const inset = inInset();
+ if (!inset)
+ return false;
+ return inset->useEmptyLayout();
}
bool return_value = false;
- LayoutPtr style;
-
- // well we have to check if we are in an inset with unlimited
- // length (all in one row) if that is true then we don't allow
- // any special options in the paragraph and also we don't allow
- // any environment other than the default layout of the text class
- // to be valid!
bool asdefault = forceEmptyLayout();
- if (asdefault)
- style = bparams.documentClass().emptyLayout();
- else
- style = d->layout_;
+ Layout const & style = asdefault ?
+ bparams.documentClass().emptyLayout() :
+ *d->layout_;
// Current base font for all inherited font changes, without any
// change caused by an individual character, except for the language:
// if the paragraph is empty, the loop will not be entered at all
if (empty()) {
- if (style->isCommand()) {
+ if (style.isCommand()) {
os << '{';
++column;
}
os << "}] ";
column +=3;
}
- if (style->isCommand()) {
+ if (style.isCommand()) {
os << '{';
++column;
}
if (c == ' ') {
// FIXME: integrate this case in latexSpecialChar
// Do not print the separation of the optional argument
- // if style->pass_thru is false. This works because
+ // if style.pass_thru is false. This works because
// latexSpecialChar ignores spaces if
- // style->pass_thru is false.
+ // style.pass_thru is false.
if (i != body_pos - 1) {
if (d->simpleTeXBlanks(
runparams, os, texrow,
- i, column, font, *style)) {
+ i, column, font, style)) {
// A surrogate pair was output. We
// must not call latexSpecialChar
// in this iteration, since it would output
}
OutputParams rp = runparams;
- rp.free_spacing = style->free_spacing;
+ rp.free_spacing = style.free_spacing;
rp.local_font = &font;
- rp.intitle = style->intitle;
+ rp.intitle = style.intitle;
// Two major modes: LaTeX or plain
// Handle here those cases common to both modes
d->latexInset(bparams, os,
texrow, rp, running_font,
basefont, outerfont, open_font,
- runningChange, *style, i, column);
+ runningChange, style, i, column);
else {
try {
d->latexSpecialChar(os, rp, running_font, runningChange,
- *style, i, column);
+ style, i, column);
} catch (EncodingException & e) {
if (runparams.dryrun) {
os << "<" << _("LyX Warning: ")
{
bool emph_flag = false;
- LayoutPtr const & style = d->layout_;
+ Layout const & style = *d->layout_;
FontInfo font_old =
- style->labeltype == LABEL_MANUAL ? style->labelfont : style->font;
+ style.labeltype == LABEL_MANUAL ? style.labelfont : style.font;
- if (style->pass_thru && !d->onlyText(buf, outerfont, initial))
+ if (style.pass_thru && !d->onlyText(buf, outerfont, initial))
os << "]]>";
// parsing main loop
} else {
char_type c = d->text_[i];
- if (style->pass_thru)
+ if (style.pass_thru)
os.put(c);
else
os << sgml::escapeChar(c);
os << "</emphasis>";
}
- if (style->free_spacing)
+ if (style.free_spacing)
os << '\n';
- if (style->pass_thru && !d->onlyText(buf, outerfont, initial))
+ if (style.pass_thru && !d->onlyText(buf, outerfont, initial))
os << "<![CDATA[";
}
bool Paragraph::isHfill(pos_type pos) const
{
Inset const * inset = getInset(pos);
- return inset && inset->lyxCode() == HFILL_CODE;
+ return inset && (inset->lyxCode() == SPACE_CODE &&
+ inset->isStretchableSpace());
}
}
-LayoutPtr const & Paragraph::layout() const
+Layout const & Paragraph::layout() const
{
- return d->layout_;
+ return *d->layout_;
}
-void Paragraph::setLayout(LayoutPtr const & layout)
+void Paragraph::setLayout(Layout const & layout)
{
- d->layout_ = layout;
+ d->layout_ = &layout;
}
char_type Paragraph::transformChar(char_type c, pos_type pos) const
{
- if (!Encodings::is_arabic(c))
+ if (!Encodings::isArabicChar(c))
return c;
char_type prev_char = ' ';
for (pos_type i = pos - 1; i >= 0; --i) {
char_type const par_char = d->text_[i];
- if (!Encodings::isComposeChar_arabic(par_char)) {
+ if (!Encodings::isArabicComposeChar(par_char)) {
prev_char = par_char;
break;
}
for (pos_type i = pos + 1, end = size(); i < end; ++i) {
char_type const par_char = d->text_[i];
- if (!Encodings::isComposeChar_arabic(par_char)) {
+ if (!Encodings::isArabicComposeChar(par_char)) {
next_char = par_char;
break;
}
}
- if (Encodings::is_arabic(next_char)) {
- if (Encodings::is_arabic(prev_char) &&
- !Encodings::is_arabic_special(prev_char))
+ if (Encodings::isArabicChar(next_char)) {
+ if (Encodings::isArabicChar(prev_char) &&
+ !Encodings::isArabicSpecialChar(prev_char))
return Encodings::transformChar(c, Encodings::FORM_MEDIAL);
else
return Encodings::transformChar(c, Encodings::FORM_INITIAL);
} else {
- if (Encodings::is_arabic(prev_char) &&
- !Encodings::is_arabic_special(prev_char))
+ if (Encodings::isArabicChar(prev_char) &&
+ !Encodings::isArabicSpecialChar(prev_char))
return Encodings::transformChar(c, Encodings::FORM_FINAL);
else
return Encodings::transformChar(c, Encodings::FORM_ISOLATED);
void Paragraph::updateWords(CursorSlice const & sl)
{
- BOOST_ASSERT(&sl.paragraph() == this);
+ LASSERT(&sl.paragraph() == this, /**/);
deregisterWords();
collectWords(sl);
registerWords();