X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fparagraph_pimpl.C;h=bad7602b1d0e286ef030524a38709432eb5f81d0;hb=ca6838b288daf07eec7d7a381d74c639c0de3a46;hp=7e311e5bd69b418112ffd5b7332a2a98e0dd0ab8;hpb=af54be2d01cc02d6e28e57b88965fff3d4f43802;p=lyx.git diff --git a/src/paragraph_pimpl.C b/src/paragraph_pimpl.C index 7e311e5bd6..bad7602b1d 100644 --- a/src/paragraph_pimpl.C +++ b/src/paragraph_pimpl.C @@ -58,6 +58,15 @@ special_phrase const special_phrases[] = { size_t const phrases_nr = sizeof(special_phrases)/sizeof(special_phrase); + +bool isEncoding(BufferParams const & bparams, LyXFont const & font, + string const & encoding) +{ + return (bparams.inputenc == encoding + || (bparams.inputenc == "auto" + && font.language()->encoding()->latexName() == encoding)); +} + } // namespace anon @@ -78,15 +87,6 @@ Paragraph::Pimpl::Pimpl(Pimpl const & p, Paragraph * owner) } -void Paragraph::Pimpl::setContentsFromPar(Paragraph const & par) -{ - owner_->text_ = par.text_; - // FIXME: change tracking (MG) - // check whether this method is really needed - changes_ = par.pimpl_->changes_; -} - - bool Paragraph::Pimpl::isChanged(pos_type start, pos_type end) const { BOOST_ASSERT(start >= 0 && start <= size()); @@ -96,6 +96,19 @@ bool Paragraph::Pimpl::isChanged(pos_type start, pos_type end) const } +bool Paragraph::Pimpl::isMergedOnEndOfParDeletion(bool trackChanges) const { + // keep the logic here in sync with the logic of eraseChars() + + if (!trackChanges) { + return true; + } + + Change change = changes_.lookup(size()); + + return change.type == Change::INSERTED && change.author == 0; +} + + void Paragraph::Pimpl::setChange(Change const & change) { // beware of the imaginary end-of-par character! @@ -150,14 +163,23 @@ void Paragraph::Pimpl::acceptChanges(pos_type start, pos_type end) { BOOST_ASSERT(start >= 0 && start <= size()); BOOST_ASSERT(end > start && end <= size() + 1); - + for (pos_type pos = start; pos < end; ++pos) { switch (lookupChange(pos).type) { case Change::UNCHANGED: + // accept changes in nested inset + if (pos < size() && owner_->isInset(pos)) { + owner_->getInset(pos)->acceptChanges(); + } + break; case Change::INSERTED: changes_.set(Change(Change::UNCHANGED), pos); + // also accept changes in nested inset + if (pos < size() && owner_->isInset(pos)) { + owner_->getInset(pos)->acceptChanges(); + } break; case Change::DELETED: @@ -171,10 +193,6 @@ void Paragraph::Pimpl::acceptChanges(pos_type start, pos_type end) break; } - // also accept changes in nested insets - if (pos < size() && owner_->isInset(pos)) { - owner_->getInset(pos)->acceptChanges(); - } } } @@ -187,7 +205,7 @@ void Paragraph::Pimpl::rejectChanges(pos_type start, pos_type end) for (pos_type pos = start; pos < end; ++pos) { switch (lookupChange(pos).type) { case Change::UNCHANGED: - // also reject changes inside of insets + // reject changes in nested inset if (pos < size() && owner_->isInset(pos)) { owner_->getInset(pos)->rejectChanges(); } @@ -272,6 +290,8 @@ bool Paragraph::Pimpl::eraseChar(pos_type pos, bool trackChanges) { BOOST_ASSERT(pos >= 0 && pos <= size()); + // keep the logic here in sync with the logic of isMergedOnEndOfParDeletion() + if (trackChanges) { Change change = changes_.lookup(pos); @@ -289,10 +309,10 @@ bool Paragraph::Pimpl::eraseChar(pos_type pos, bool trackChanges) return false; } - // Don't physically access nonexistent end-of-paragraph char + // Don't physically access the imaginary end-of-paragraph character. + // eraseChar() can only mark it as DELETED. A physical deletion of + // end-of-par must be handled externally. if (pos == size()) { - // FIXME: change tracking (MG) - // how do we handle end-of-pars previously marked inserted? return false; } @@ -346,7 +366,7 @@ bool Paragraph::Pimpl::eraseChar(pos_type pos, bool trackChanges) int Paragraph::Pimpl::eraseChars(pos_type start, pos_type end, bool trackChanges) { BOOST_ASSERT(start >= 0 && start <= size()); - BOOST_ASSERT(end > start && end <= size() + 1); + BOOST_ASSERT(end >= start && end <= size() + 1); pos_type i = start; for (pos_type count = end - start; count; --count) { @@ -563,13 +583,8 @@ void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const & buf, case 0xb9: // ¹ SUPERSCRIPT ONE case 0xac: // ¬ NOT SIGN case 0xb5: // µ MICRO SIGN - if ((bparams.inputenc == "latin1" || - bparams.inputenc == "latin9") || - (bparams.inputenc == "auto" && - (font.language()->encoding()->latexName() - == "latin1" || - font.language()->encoding()->latexName() - == "latin9"))) { + if (isEncoding(bparams, font, "latin1") + || isEncoding(bparams, font, "latin9")) { os << "\\ensuremath{"; os.put(c); os << '}'; @@ -645,6 +660,73 @@ void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const & buf, } break; + case 0x20ac: // EURO SIGN + if (isEncoding(bparams, font, "latin9") + || isEncoding(bparams, font, "cp1251") + || isEncoding(bparams, font, "utf8") + || isEncoding(bparams, font, "latin10") + || isEncoding(bparams, font, "cp858")) { + os.put(c); + } else { + os << "\\texteuro{}"; + column += 10; + } + break; + + // These characters are covered by latin1, but not + // by latin9 (a.o.). We have to support them because + // we switched the default of latin1-languages to latin9 + case 0xa4: // CURRENCY SYMBOL + case 0xa6: // BROKEN BAR + case 0xa8: // DIAERESIS + case 0xb4: // ACUTE ACCENT + case 0xb8: // CEDILLA + case 0xbd: // 1/2 FRACTION + case 0xbc: // 1/4 FRACTION + case 0xbe: // 3/4 FRACTION + if (isEncoding(bparams, font, "latin1") + || isEncoding(bparams, font, "latin5") + || isEncoding(bparams, font, "utf8")) { + os.put(c); + break; + } else { + switch (c) { + case 0xa4: + os << "\\textcurrency{}"; + column += 15; + break; + case 0xa6: + os << "\\textbrokenbar{}"; + column += 16; + break; + case 0xa8: + os << "\\textasciidieresis{}"; + column += 20; + break; + case 0xb4: + os << "\\textasciiacute{}"; + column += 17; + break; + case 0xb8: // from latin1.def: + os << "\\c\\ "; + column += 3; + break; + case 0xbd: + os << "\\textonehalf{}"; + column += 14; + break; + case 0xbc: + os << "\\textonequarter{}"; + column += 17; + break; + case 0xbe: + os << "\\textthreequarters{}"; + column += 20; + break; + } + break; + } + case '$': case '&': case '%': case '#': case '{': case '}': case '_': @@ -741,7 +823,7 @@ void Paragraph::Pimpl::validate(LaTeXFeatures & features, << endl; features.require("noun"); lyxerr[Debug::LATEX] << "Noun enabled. Font: " - << fcit->font().stateText(0) + << to_utf8(fcit->font().stateText(0)) << endl; } switch (fcit->font().color()) { @@ -756,7 +838,7 @@ void Paragraph::Pimpl::validate(LaTeXFeatures & features, default: features.require("color"); lyxerr[Debug::LATEX] << "Color enabled. Font: " - << fcit->font().stateText(0) + << to_utf8(fcit->font().stateText(0)) << endl; } @@ -795,6 +877,12 @@ void Paragraph::Pimpl::validate(LaTeXFeatures & features, break; } } + // these glyphs require the textcomp package + if (getChar(i) == 0x20ac || getChar(i) == 0xa4 + || getChar(i) == 0xa6 || getChar(i) == 0xa8 + || getChar(i) == 0xb4 || getChar(i) == 0xbd + || getChar(i) == 0xbc || getChar(i) == 0xbe) + features.require("textcomp"); } }