X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FParagraph.cpp;h=233057e9163ad9058363f378066dbef466f92de7;hb=2098f1d8c20d51e63e670bcdc9da8996068975bf;hp=cf7c7145d4ef26cc81cd6db03e795f4356c7aa86;hpb=d305930f47e623aee14190454a0164464b0103d1;p=lyx.git diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index cf7c7145d4..233057e916 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -189,9 +189,8 @@ public: FontList fontlist_; /// - unsigned int id_; - /// - static unsigned int paragraph_id; + int id_; + /// ParagraphParameters params_; @@ -208,17 +207,14 @@ public: /// TextContainer text_; - typedef std::set Words; + typedef set Words; /// - Words words_; + map words_; /// Layout const * layout_; }; -// Initialization of the counter for the paragraph id's, -unsigned int Paragraph::Private::paragraph_id = 0; - namespace { struct special_phrase { @@ -240,20 +236,26 @@ size_t const phrases_nr = sizeof(special_phrases)/sizeof(special_phrase); Paragraph::Private::Private(Paragraph * owner, Layout const & layout) - : owner_(owner), inset_owner_(0), begin_of_body_(0), layout_(&layout) + : owner_(owner), inset_owner_(0), id_(-1), begin_of_body_(0), layout_(&layout) { - id_ = paragraph_id++; text_.reserve(100); } +// Initialization of the counter for the paragraph id's, +// +// FIXME: There should be a more intelligent way to generate and use the +// paragraph ids per buffer instead a global static counter for all InsetText +// in the running program. +static int paragraph_id = -1; + 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_), begin_of_body_(p.begin_of_body_), text_(p.text_), words_(p.words_), layout_(p.layout_) { - id_ = paragraph_id++; + id_ = ++paragraph_id; } @@ -265,7 +267,7 @@ Paragraph::Private::Private(Private const & p, Paragraph * owner, begin_of_body_(p.begin_of_body_), words_(p.words_), layout_(p.layout_) { - id_ = paragraph_id++; + id_ = ++paragraph_id; if (beg >= pos_type(p.text_.size())) return; text_ = p.text_.substr(beg, end - beg); @@ -1072,6 +1074,18 @@ bool Paragraph::Private::latexSpecialPhrase(odocstream & os, pos_type & i, void Paragraph::Private::validate(LaTeXFeatures & features) const { + if (layout_->inpreamble && inset_owner_) { + Buffer const & buf = inset_owner_->buffer(); + BufferParams const & bp = buf.params(); + Font f; + TexRow tr; + odocstringstream ods; + owner_->latex(bp, f, ods, tr, features.runparams()); + docstring d = ods.str(); + if (!d.empty()) + features.addPreambleSnippet(to_utf8(d)); + } + // check the params. if (!params_.spacing().isDefault()) features.require("setspace"); @@ -1946,6 +1960,9 @@ bool Paragraph::latex(BufferParams const & bparams, { LYXERR(Debug::LATEX, "Paragraph::latex... " << this); + if (layout().inpreamble) + return true; + bool return_value = false; bool const allowcust = allowParagraphCustomization(); @@ -2297,7 +2314,7 @@ pos_type Paragraph::firstWordLyXHTML(XHTMLStream & xs, OutputParams const & runp char_type c = d->text_[i]; if (c == ' ') break; - xs << html::escapeChar(c); + xs << c; } } return i; @@ -2379,17 +2396,23 @@ docstring Paragraph::simpleLyXHTMLOnePar(Buffer const & buf, XHTMLStream & xs, OutputParams const & runparams, Font const & outerfont, + bool fortoc, pos_type initial) const { docstring retval; - // FIXME We really need to manage the tag nesting here. - // Probably in the same sort of way as in output_xhtml. bool emph_flag = false; bool bold_flag = false; - std::string closing_tag; + string closing_tag; Layout const & style = *d->layout_; + + if (!fortoc) { + // generate a magic label for this paragraph + string const attr = "id='" + magicLabel() + "'"; + xs << CompTag("a", attr); + } + FontInfo font_old = style.labeltype == LABEL_MANUAL ? style.labelfont : style.font; @@ -2417,15 +2440,19 @@ docstring Paragraph::simpleLyXHTMLOnePar(Buffer const & buf, bold_flag = false; } } - // FIXME Other such tags? + // FIXME XHTML + // Other such tags? What about the other text ranges? Inset const * inset = getInset(i); if (inset) { + InsetCommand const * ic = inset->asInsetCommand(); InsetLayout const & il = inset->getLayout(); - OutputParams np = runparams; - if (!il.htmlisblock()) - np.html_in_par = true; - retval += inset->xhtml(xs, np); + if (!fortoc || il.isInToc() || (ic && ic->isInToc())) { + OutputParams np = runparams; + if (!il.htmlisblock()) + np.html_in_par = true; + retval += inset->xhtml(xs, np); + } } else { char_type c = d->text_[i]; @@ -2446,7 +2473,10 @@ docstring Paragraph::simpleLyXHTMLOnePar(Buffer const & buf, } else str += c; - xs << str; + // We don't want to escape the entities. Note that + // it is safe to do this, since str can otherwise + // only be "-". E.g., it can't be "<". + xs << XHTMLStream::NextRaw() << str; } else xs << c; } @@ -2626,6 +2656,12 @@ int Paragraph::id() const } +void Paragraph::setId(int id) +{ + d->id_ = id; +} + + Layout const & Paragraph::layout() const { return *d->layout_; @@ -2994,10 +3030,13 @@ bool Paragraph::isSeparator(pos_type pos) const void Paragraph::deregisterWords() { + map::const_iterator itl; Private::Words::const_iterator it; - WordList & wl = theWordList(); - for (it = d->words_.begin(); it != d->words_.end(); ++it) - wl.remove(*it); + for (itl = d->words_.begin(); itl != d->words_.end(); ++itl) { + WordList * wl = theWordList(itl->first); + for (it = (itl->second).begin(); it != (itl->second).end(); ++it) + wl->remove(*it); + } d->words_.clear(); } @@ -3049,7 +3088,11 @@ void Paragraph::collectWords() locateWord(from, pos, WHOLE_WORD); if (pos - from >= 6) { docstring word = asString(from, pos, AS_STR_NONE); - d->words_.insert(word); + FontList::const_iterator cit = d->fontlist_.fontIterator(pos); + if (cit == d->fontlist_.end()) + return; + Language const * lang = cit->font().language(); + d->words_[*lang].insert(word); } } } @@ -3057,10 +3100,13 @@ void Paragraph::collectWords() void Paragraph::registerWords() { + map::const_iterator itl; Private::Words::const_iterator it; - WordList & wl = theWordList(); - for (it = d->words_.begin(); it != d->words_.end(); ++it) - wl.insert(*it); + for (itl = d->words_.begin(); itl != d->words_.end(); ++itl) { + WordList * wl = theWordList(itl->first); + for (it = (itl->second).begin(); it != (itl->second).end(); ++it) + wl->insert(*it); + } } @@ -3120,4 +3166,12 @@ bool Paragraph::isMisspelled(pos_type pos) const } +string Paragraph::magicLabel() const +{ + stringstream ss; + ss << "magicparlabel-" << id(); + return ss.str(); +} + + } // namespace lyx