X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FParagraph.cpp;h=233057e9163ad9058363f378066dbef466f92de7;hb=2098f1d8c20d51e63e670bcdc9da8996068975bf;hp=0580b10e0d63d5b739277cdc890d5f4c38de1aae;hpb=ff61f41d5b9f2687b6b8539450ed93ea0d4c83c9;p=lyx.git diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index 0580b10e0d..233057e916 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -5,6 +5,7 @@ * * \author Asger Alstrup * \author Lars Gullik Bjønnes + * \author Richard Heck (XHTML output) * \author Jean-Marc Lasgouttes * \author Angus Leeming * \author John Levon @@ -188,9 +189,8 @@ public: FontList fontlist_; /// - unsigned int id_; - /// - static unsigned int paragraph_id; + int id_; + /// ParagraphParameters params_; @@ -207,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 { @@ -239,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; } @@ -264,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); @@ -1071,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"); @@ -1945,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(); @@ -2285,18 +2303,18 @@ pos_type Paragraph::firstWordDocBook(odocstream & os, OutputParams const & runpa } -pos_type Paragraph::firstWordLyXHTML(odocstream & os, OutputParams const & runparams) +pos_type Paragraph::firstWordLyXHTML(XHTMLStream & xs, OutputParams const & runparams) const { pos_type i; for (i = 0; i < size(); ++i) { if (Inset const * inset = getInset(i)) { - inset->xhtml(os, runparams); + inset->xhtml(xs, runparams); } else { char_type c = d->text_[i]; if (c == ' ') break; - os << html::escapeChar(c); + xs << c; } } return i; @@ -2375,20 +2393,26 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf, docstring Paragraph::simpleLyXHTMLOnePar(Buffer const & buf, - odocstream & os, + 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; @@ -2399,37 +2423,41 @@ docstring Paragraph::simpleLyXHTMLOnePar(Buffer const & buf, // emphasis if (font_old.emph() != font.fontInfo().emph()) { if (font.fontInfo().emph() == FONT_ON) { - os << ""; + xs << StartTag("em"); emph_flag = true; } else if (emph_flag && i != initial) { - os << ""; + xs << EndTag("em"); emph_flag = false; } } // bold if (font_old.series() != font.fontInfo().series()) { if (font.fontInfo().series() == BOLD_SERIES) { - os << ""; + xs << StartTag("strong"); bold_flag = true; } else if (bold_flag && i != initial) { - os << ""; + xs << EndTag("strong"); 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(os, 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]; if (style.pass_thru) - os.put(c); + xs << c; else if (c == '-') { docstring str; int j = i + 1; @@ -2445,19 +2473,17 @@ docstring Paragraph::simpleLyXHTMLOnePar(Buffer const & buf, } else str += c; - os << 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 - os << html::escapeChar(c); + xs << c; } font_old = font.fontInfo(); } - // FIXME This could be out of order. See above. - if (emph_flag) - os << ""; - if (bold_flag) - os << ""; - + xs.closeFontTags(); return retval; } @@ -2630,6 +2656,12 @@ int Paragraph::id() const } +void Paragraph::setId(int id) +{ + d->id_ = id; +} + + Layout const & Paragraph::layout() const { return *d->layout_; @@ -2998,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(); } @@ -3053,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); } } } @@ -3061,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); + } } @@ -3124,4 +3166,12 @@ bool Paragraph::isMisspelled(pos_type pos) const } +string Paragraph::magicLabel() const +{ + stringstream ss; + ss << "magicparlabel-" << id(); + return ss.str(); +} + + } // namespace lyx