X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FParagraph.cpp;h=507702f90d2a4b4ff769874874fed51587ec5a8f;hb=b874bdfd402a94428c8f5fe7ef2180146069120a;hp=3ce354cc940a03e3529f601604601b506eebeb25;hpb=3e9e6e344ace9160f93fd882bf2243d24a069fa5;p=lyx.git diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index 3ce354cc94..507702f90d 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -40,6 +40,7 @@ #include "ParagraphParameters.h" #include "SpellChecker.h" #include "sgml.h" +#include "texstream.h" #include "TextClass.h" #include "TexRow.h" #include "Text.h" @@ -510,6 +511,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 +563,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 +930,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 +952,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; @@ -1139,7 +1161,9 @@ void Paragraph::Private::latexSpecialChar(otexstream & os, char_type const c = (runparams.use_polyglossia) ? owner_->getUChar(bparams, i) : text_[i]; - if (style.pass_thru || runparams.pass_thru) { + if (style.pass_thru || runparams.pass_thru + || contains(style.pass_thru_chars, c) + || contains(runparams.pass_thru_chars, c)) { if (c != '\0') { Encoding const * const enc = runparams.encoding; if (enc && !enc->encodable(c)) @@ -1154,10 +1178,11 @@ 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 + // 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() - && lyxrc.fontenc == "T1" && latexSpecialT1(c, os, i, column)) + && bparams.font_encoding() == "T1" && latexSpecialT1(c, os, i, column)) return; // Otherwise, we use what LaTeX provides us. @@ -1180,7 +1205,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) @@ -1351,13 +1378,12 @@ void Paragraph::Private::validate(LaTeXFeatures & features) const BufferParams const & bp = features.runparams().is_child ? buf.masterParams() : buf.params(); Font f; - TexRow texrow; // Using a string stream here circumvents the encoding // switching machinery of odocstream. Therefore the // output is wrong if this paragraph contains content // that needs to switch encoding. odocstringstream ods; - otexstream os(ods, texrow); + otexstream os(ods, false); if (is_command) { os << '\\' << from_ascii(layout_->latexname()); // we have to provide all the optional arguments here, even though @@ -1383,7 +1409,7 @@ void Paragraph::Private::validate(LaTeXFeatures & features) const } } string const snippet = to_utf8(ods.str()); - features.addPreambleSnippet(snippet); + features.addPreambleSnippet(snippet, true); } } @@ -1414,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"); } } @@ -1719,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(); @@ -1808,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]; @@ -1987,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); @@ -2031,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; @@ -2135,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; } @@ -2181,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 @@ -2554,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); @@ -3124,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); } @@ -3246,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); }