X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FParagraph.cpp;h=c29ca4cb930110e780b8011b19ef7fea4d77a246;hb=45e3a8f82701e981b1ccb2ab8d76f269867d7889;hp=da4dccf3f4f40307f22c53a270b9d33e356e2bb8;hpb=897b2e73a1d547311db6cb83097d351c9d3676ef;p=lyx.git diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index da4dccf3f4..c29ca4cb93 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -510,6 +510,8 @@ Paragraph::Private::Private(Paragraph * owner, Layout const & layout) // 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. +// However, this per-session id is used in LFUN_PARAGRAPH_GOTO to +// switch to a different buffer, as used in the outliner for instance. static int paragraph_id = -1; Paragraph::Private::Private(Private const & p, Paragraph * owner) @@ -560,6 +562,18 @@ void Paragraph::addChangesToToc(DocIterator const & cdit, } +void Paragraph::addChangesToBuffer(Buffer const & buf) const +{ + d->changes_.updateBuffer(buf); +} + + +bool Paragraph::isChangeUpdateRequired() const +{ + return d->changes_.isUpdateRequired(); +} + + bool Paragraph::isDeleted(pos_type start, pos_type end) const { LASSERT(start >= 0 && start <= size(), return false); @@ -915,10 +929,13 @@ int Paragraph::Private::writeScriptChars(otexstream & os, { // FIXME: modifying i here is not very nice... - // We only arrive here when a proper language for character text_[i] has - // not been specified (i.e., it could not be translated in the current - // latex encoding) or its latex translation has been forced, and it - // belongs to a known script. + // We only arrive here when character text_[i] could not be translated + // into the current latex encoding (or its latex translation has been forced,) + // and it belongs to a known script. + // TODO: We need \textcyr and \textgreek wrappers also for characters + // that can be encoded in the "LaTeX encoding" but not in the + // current *font encoding*. + // (See #9681 for details and test) // Parameter ltx contains the latex translation of text_[i] as specified // in the unicodesymbols file and is something like "\textXXX{}". // The latex macro name "textXXX" specifies the script to which text_[i] @@ -934,6 +951,10 @@ int Paragraph::Private::writeScriptChars(otexstream & os, bool closing_brace = true; if (script == "textgreek" && encoding.latexName() == "iso-8859-7") { // Correct encoding is being used, so we can avoid \textgreek. + // TODO: wrong test: we need to check the *font encoding* + // (i.e. the active language and its FontEncoding tag) + // instead of the LaTeX *input encoding*! + // See #9637 for details and test-cases. pos = brace1 + 1; length -= pos; closing_brace = false; @@ -1156,9 +1177,9 @@ void Paragraph::Private::latexSpecialChar(otexstream & os, return; // If T1 font encoding is used, use the special // characters it provides. - // NOTE: Some languages reset the font encoding internally. - // If we are using such a language, we do not output - // special T1 chars. + // NOTE: Some languages reset the font encoding internally to a + // non-standard font encoding. If we are using such a language, + // we do not output special T1 chars. if (!runparams.inIPA && !running_font.language()->internalFontEncoding() && bparams.font_encoding() == "T1" && latexSpecialT1(c, os, i, column)) return; @@ -1183,7 +1204,9 @@ void Paragraph::Private::latexSpecialChar(otexstream & os, break; case '-': os << '-'; - if (i + 1 < end_pos && text_[i+1] == '-') { + if (i + 1 < static_cast(text_.size()) && + (end_pos == -1 || i + 1 < end_pos) && + text_[i+1] == '-') { // Prevent "--" becoming an endash and "---" becoming // an emdash. // Within \ttfamily, "--" is merged to "-" (no endash) @@ -1386,7 +1409,7 @@ void Paragraph::Private::validate(LaTeXFeatures & features) const } } string const snippet = to_utf8(ods.str()); - features.addPreambleSnippet(snippet); + features.addPreambleSnippet(snippet, true); } } @@ -1417,7 +1440,7 @@ void Paragraph::Private::validate(LaTeXFeatures & features) const icit->inset->validate(features); if (layout_->needprotect && icit->inset->lyxCode() == FOOT_CODE) - features.require("footmisc"); + features.require("NeedLyXFootnoteCode"); } } @@ -1722,7 +1745,10 @@ Font const & Paragraph::getFontSettings(BufferParams const & bparams, FontSpan Paragraph::fontSpan(pos_type pos) const { - LBUFERR(pos < size()); + LBUFERR(pos <= size()); + + if (pos == size()) + return FontSpan(pos, pos); pos_type start = 0; FontList::const_iterator cit = d->fontlist_.begin(); @@ -1811,14 +1837,6 @@ Font const Paragraph::getLayoutFont } -/// Returns the height of the highest font in range -FontSize Paragraph::highestFontInRange - (pos_type startpos, pos_type endpos, FontSize def_size) const -{ - return d->fontlist_.highestInRange(startpos, endpos, def_size); -} - - char_type Paragraph::getUChar(BufferParams const & bparams, pos_type pos) const { char_type c = d->text_[pos]; @@ -1990,7 +2008,7 @@ docstring Paragraph::expandParagraphLabel(Layout const & layout, docstring parent(fmt, i + 1, j - i - 1); docstring label = from_ascii("??"); if (tclass.hasLayout(parent)) - docstring label = expandParagraphLabel(tclass[parent], bparams, + label = expandParagraphLabel(tclass[parent], bparams, process_appendix); fmt = docstring(fmt, 0, i) + label + docstring(fmt, j + 1, docstring::npos); @@ -2034,14 +2052,12 @@ void Paragraph::setBeginOfBody() pos_type end = size(); if (i < end && !(isNewline(i) || isEnvSeparator(i))) { ++i; - char_type previous_char = 0; - char_type temp = 0; if (i < end) { - previous_char = d->text_[i]; + char_type previous_char = d->text_[i]; if (!(isNewline(i) || isEnvSeparator(i))) { ++i; while (i < end && previous_char != ' ') { - temp = d->text_[i]; + char_type temp = d->text_[i]; if (isNewline(i) || isEnvSeparator(i)) break; ++i; @@ -2138,8 +2154,12 @@ int Paragraph::Private::startTeXParParams(BufferParams const & bparams, { int column = 0; - if (params_.noindent() && !layout_->pass_thru - && (layout_->toggle_indent != ITOGGLE_NEVER)) { + bool canindent = + (bparams.paragraph_separation == BufferParams::ParagraphIndentSeparation) ? + (layout_->toggle_indent != ITOGGLE_NEVER) : + (layout_->toggle_indent == ITOGGLE_ALWAYS); + + if (canindent && params_.noindent() && !layout_->pass_thru) { os << "\\noindent "; column += 10; } @@ -2184,7 +2204,6 @@ int Paragraph::Private::startTeXParParams(BufferParams const & bparams, corrected_env(os, begin_tag, "flushright", code, lastpar, column); break; } case LYX_ALIGN_RIGHT: { - string output; if (owner_->getParLanguage(bparams)->babel() != "hebrew") corrected_env(os, begin_tag, "flushright", code, lastpar, column); else @@ -2557,8 +2576,7 @@ void Paragraph::latex(BufferParams const & bparams, if (allowcust && d->endTeXParParams(bparams, os, runparams) && runparams.encoding != prev_encoding) { runparams.encoding = prev_encoding; - if (!runparams.isFullUnicode()) - os << setEncoding(prev_encoding->iconvName()); + os << setEncoding(prev_encoding->iconvName()); } LYXERR(Debug::LATEX, "Paragraph::latex... done " << this); @@ -3127,10 +3145,9 @@ bool Paragraph::isHardHyphenOrApostrophe(pos_type pos) const } -bool Paragraph::isSameSpellRange(pos_type pos1, pos_type pos2) const +FontSpan const & Paragraph::getSpellRange(pos_type pos) const { - return pos1 == pos2 - || d->speller_state_.getRange(pos1) == d->speller_state_.getRange(pos2); + return d->speller_state_.getRange(pos); } @@ -3249,21 +3266,23 @@ docstring Paragraph::asString(pos_type beg, pos_type end, int options, const Out } -void Paragraph::forOutliner(docstring & os, size_t maxlen) const +void Paragraph::forOutliner(docstring & os, size_t const maxlen, + bool const shorten) const { + size_t tmplen = shorten ? maxlen + 1 : maxlen; if (!d->params_.labelString().empty()) os += d->params_.labelString() + ' '; - for (pos_type i = 0; i < size() && os.length() < maxlen; ++i) { + for (pos_type i = 0; i < size() && os.length() < tmplen; ++i) { if (isDeleted(i)) continue; char_type const c = d->text_[i]; if (isPrintable(c)) os += c; - else if (c == '\t' || c == '\n') - os += ' '; else if (c == META_INSET) - getInset(i)->forOutliner(os, maxlen); + getInset(i)->forOutliner(os, tmplen, false); } + if (shorten) + Text::shortenForOutliner(os, maxlen); }