X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FParagraph.cpp;h=e26f70f4bce4ca04754af67565dd6263acd09e30;hb=3f7d2a66f522a45583e0a8b0ba734bb71f0ddde0;hp=ada2517b3b358af70c1f67bb0ede656b1c058881;hpb=db8c16d554ebb1dcb319e44d318572de6eff024b;p=lyx.git diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index ada2517b3b..e26f70f4bc 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -19,6 +19,7 @@ #include "Paragraph.h" +#include "LayoutFile.h" #include "Buffer.h" #include "BufferParams.h" #include "Changes.h" @@ -78,7 +79,7 @@ class Paragraph::Private { public: /// - Private(Paragraph * owner); + Private(Paragraph * owner, Layout const & layout); /// "Copy constructor" Private(Private const &, Paragraph * owner); @@ -189,9 +190,6 @@ public: /// InsetList insetlist_; - /// - LayoutPtr layout_; - /// end of label pos_type begin_of_body_; @@ -202,6 +200,8 @@ public: typedef std::set Words; /// Words words_; + /// + Layout const * layout_; }; @@ -228,8 +228,8 @@ size_t const phrases_nr = sizeof(special_phrases)/sizeof(special_phrase); } // 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); @@ -239,8 +239,8 @@ Paragraph::Private::Private(Paragraph * owner) 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++; } @@ -1034,8 +1034,12 @@ void Paragraph::Private::validate(LaTeXFeatures & features, // ///////////////////////////////////////////////////////////////////// -Paragraph::Paragraph() - : d(new Paragraph::Private(this)) +namespace { + Layout const emptyParagraphLayout; +} + +Paragraph::Paragraph() + : d(new Paragraph::Private(this, emptyParagraphLayout)) { itemdepth = 0; d->params_.clear(); @@ -1455,7 +1459,8 @@ bool Paragraph::stripLeadingSpaces(bool trackChanges) 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_); } @@ -1519,21 +1524,21 @@ docstring const Paragraph::translateIfPossible(docstring const & s, } -docstring Paragraph::expandLabel(LayoutPtr const & layout, +docstring Paragraph::expandLabel(Layout const & layout, BufferParams const & bparams, bool process_appendix) const { - TextClass const & tclass = bparams.textClass(); + 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}' @@ -1555,9 +1560,9 @@ docstring Paragraph::expandLabel(LayoutPtr const & layout, } -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)) { @@ -1817,19 +1822,11 @@ bool Paragraph::latex(BufferParams const & bparams, 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.textClass().defaultLayout(); - 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: @@ -1864,7 +1861,7 @@ bool Paragraph::latex(BufferParams const & bparams, // if the paragraph is empty, the loop will not be entered at all if (empty()) { - if (style->isCommand()) { + if (style.isCommand()) { os << '{'; ++column; } @@ -1893,7 +1890,7 @@ bool Paragraph::latex(BufferParams const & bparams, os << "}] "; column +=3; } - if (style->isCommand()) { + if (style.isCommand()) { os << '{'; ++column; } @@ -1993,13 +1990,13 @@ bool Paragraph::latex(BufferParams const & bparams, 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 @@ -2011,9 +2008,9 @@ bool Paragraph::latex(BufferParams const & bparams, } 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 @@ -2022,11 +2019,11 @@ bool Paragraph::latex(BufferParams const & bparams, 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: ") @@ -2170,11 +2167,11 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf, { 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 @@ -2197,7 +2194,7 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf, } else { char_type c = d->text_[i]; - if (style->pass_thru) + if (style.pass_thru) os.put(c); else os << sgml::escapeChar(c); @@ -2209,9 +2206,9 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf, os << ""; } - 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 << "layout_; + return *d->layout_; } -void Paragraph::setLayout(LayoutPtr const & layout) +void Paragraph::setLayout(Layout const & layout) { - d->layout_ = layout; + d->layout_ = &layout; } -void Paragraph::setEmptyOrDefaultLayout(TextClass const & tclass) +void Paragraph::setEmptyOrDefaultLayout(DocumentClass const & tclass) { if (useEmptyLayout()) setLayout(tclass.emptyLayout()); @@ -2699,7 +2696,7 @@ void Paragraph::deregisterWords() } -void Paragraph::collectWords(Buffer const & buf, CursorSlice const & sl) +void Paragraph::collectWords(CursorSlice const & sl) { // find new words bool inword = false; @@ -2743,11 +2740,11 @@ void Paragraph::registerWords() } -void Paragraph::updateWords(Buffer const & buf, CursorSlice const & sl) +void Paragraph::updateWords(CursorSlice const & sl) { BOOST_ASSERT(&sl.paragraph() == this); deregisterWords(); - collectWords(buf, sl); + collectWords(sl); registerWords(); }