]> git.lyx.org Git - lyx.git/blobdiff - src/Paragraph.cpp
Revert "Objective-C compililation support with cmake and C++11"
[lyx.git] / src / Paragraph.cpp
index 0777a7886273e41b5be604f57e1e75b809b1ebb0..3751cfd933e9ce9e12e3e208eec20df7fa02b82d 100644 (file)
@@ -25,7 +25,7 @@
 #include "BufferParams.h"
 #include "Changes.h"
 #include "Counters.h"
-#include "Encoding.h"
+#include "BufferEncodings.h"
 #include "InsetList.h"
 #include "Language.h"
 #include "LaTeXFeatures.h"
@@ -499,7 +499,7 @@ public:
        TextContainer text_;
 
        typedef set<docstring> Words;
-       typedef map<Language, Words> LangWordsMap;
+       typedef map<string, Words> LangWordsMap;
        ///
        LangWordsMap words_;
        ///
@@ -767,7 +767,7 @@ void Paragraph::Private::insertChar(pos_type pos, char_type c,
 
 
 bool Paragraph::insertInset(pos_type pos, Inset * inset,
-                                  Change const & change)
+                                  Font const & font, Change const & change)
 {
        LASSERT(inset, return false);
        LASSERT(pos >= 0 && pos <= size(), return false);
@@ -785,6 +785,7 @@ bool Paragraph::insertInset(pos_type pos, Inset * inset,
 
        // Some insets require run of spell checker
        requestSpellCheck(pos);
+       setFont(pos, font);
        return true;
 }
 
@@ -1301,7 +1302,7 @@ void Paragraph::Private::latexSpecialChar(otexstream & os,
                docstring nextlatex;
                bool nexttipas = false;
                string nexttipashortcut;
-               if (next != '\0' && next != META_INSET) {
+               if (next != '\0' && next != META_INSET && encoding.encodable(next)) {
                        nextlatex = encoding.latexChar(next).first;
                        if (runparams.inIPA) {
                                nexttipashortcut = Encodings::TIPAShortcut(next);
@@ -1449,7 +1450,8 @@ void Paragraph::Private::validate(LaTeXFeatures & features) const
        if (layout_->inpreamble && inset_owner_) {
                bool const is_command = layout_->latextype == LATEX_COMMAND;
                Buffer const & buf = inset_owner_->buffer();
-               BufferParams const & bp = buf.params();
+               BufferParams const & bp = features.runparams().is_child
+                       ? buf.masterParams() : buf.params();
                Font f;
                TexRow texrow;
                // Using a string stream here circumvents the encoding
@@ -1527,7 +1529,7 @@ void Paragraph::Private::validate(LaTeXFeatures & features) const
                                break;
                        }
                }
-               Encodings::validate(text_[i], features);
+               BufferEncodings::validate(text_[i], features);
        }
 }
 
@@ -1782,16 +1784,6 @@ void Paragraph::insertChar(pos_type pos, char_type c,
 }
 
 
-bool Paragraph::insertInset(pos_type pos, Inset * inset,
-                           Font const & font, Change const & change)
-{
-       bool const success = insertInset(pos, inset, change);
-       // Set the font/language of the inset...
-       setFont(pos, font);
-       return success;
-}
-
-
 void Paragraph::resetFonts(Font const & font)
 {
        d->fontlist_.clear();
@@ -2483,7 +2475,7 @@ void Paragraph::latex(BufferParams const & bparams,
                Change const & change = runparams.inDeletedInset
                        ? runparams.changeOfDeletedInset : lookupChange(i);
 
-               if (bparams.outputChanges && runningChange != change) {
+               if (bparams.output_changes && runningChange != change) {
                        if (open_font) {
                                column += running_font.latexWriteEndChanges(
                                                os, bparams, runparams, basefont, basefont);
@@ -2499,7 +2491,7 @@ void Paragraph::latex(BufferParams const & bparams,
 
                // do not output text which is marked deleted
                // if change tracking output is disabled
-               if (!bparams.outputChanges && change.deleted()) {
+               if (!bparams.output_changes && change.deleted()) {
                        continue;
                }
 
@@ -3355,7 +3347,7 @@ docstring Paragraph::asString(int options) const
 }
 
 
-docstring Paragraph::asString(pos_type beg, pos_type end, int options) const
+docstring Paragraph::asString(pos_type beg, pos_type end, int options, const OutputParams *runparams) const
 {
        odocstringstream os;
 
@@ -3372,9 +3364,14 @@ docstring Paragraph::asString(pos_type beg, pos_type end, int options) const
                    || (c == '\n' && (options & AS_STR_NEWLINES)))
                        os.put(c);
                else if (c == META_INSET && (options & AS_STR_INSETS)) {
-                       getInset(i)->toString(os);
-                       if (getInset(i)->asInsetMath())
-                               os << " ";
+                       if (c == META_INSET && (options & AS_STR_PLAINTEXT)) {
+                               LASSERT(runparams != 0, return docstring());
+                               getInset(i)->plaintext(os, *runparams);
+                       } else {
+                               getInset(i)->toString(os);
+                               if (getInset(i)->asInsetMath())
+                                       os << " ";
+                       }
                }
        }
 
@@ -3382,7 +3379,7 @@ docstring Paragraph::asString(pos_type beg, pos_type end, int options) const
 }
 
 
-void Paragraph::forToc(docstring & os, size_t maxlen) const
+void Paragraph::forOutliner(docstring & os, size_t maxlen) const
 {
        if (!d->params_.labelString().empty())
                os += d->params_.labelString() + ' ';
@@ -3395,35 +3392,8 @@ void Paragraph::forToc(docstring & os, size_t maxlen) const
                else if (c == '\t' || c == '\n')
                        os += ' ';
                else if (c == META_INSET)
-                       getInset(i)->forToc(os, maxlen);
-       }
-}
-
-
-docstring Paragraph::stringify(pos_type beg, pos_type end, int options,
-        OutputParams const & runparams) const
-{
-       odocstringstream os;
-
-       if (beg == 0
-               && options & AS_STR_LABEL
-               && !d->params_.labelString().empty())
-               os << d->params_.labelString() << ' ';
-
-       OutputParams op = runparams;
-       op.for_search = true;
-
-       for (pos_type i = beg; i < end; ++i) {
-               char_type const c = d->text_[i];
-               if (isPrintable(c) || c == '\t'
-                   || (c == '\n' && (options & AS_STR_NEWLINES)))
-                       os.put(c);
-               else if (c == META_INSET && (options & AS_STR_INSETS)) {
-                       getInset(i)->plaintext(os, op);
-               }
+                       getInset(i)->forOutliner(os, maxlen);
        }
-
-       return os.str();
 }
 
 
@@ -3574,7 +3544,7 @@ int Paragraph::fixBiblio(Buffer const & buffer)
        if (d->layout_->labeltype != LABEL_BIBLIO)
                return 0;
 
-       bool const track_changes = buffer.params().trackChanges;
+       bool const track_changes = buffer.params().track_changes;
        int bibitem_pos = d->insetlist_.find(BIBITEM_CODE);
        bool const hasbibitem0 = bibitem_pos == 0;
 
@@ -3589,8 +3559,7 @@ int Paragraph::fixBiblio(Buffer const & buffer)
                // these, which there should be.
                // FIXME: why does it make sense to do that rather
                // than keep the first? (JMarc)
-               Inset * inset = d->insetlist_.release(bibitem_pos);
-               eraseChar(bibitem_pos, track_changes);
+               Inset * inset = releaseInset(bibitem_pos);
                d->insetlist_.begin()->inset = inset;
                return -bibitem_pos;
        }
@@ -3679,9 +3648,11 @@ void Paragraph::changeCase(BufferParams const & bparams, pos_type pos,
        // process sequences of modified characters; in change
        // tracking mode, this approach results in much better
        // usability than changing case on a char-by-char basis
-       docstring changes;
+       // We also need to track the current font, since font
+       // changes within sequences can occur.
+       vector<pair<char_type, Font> > changes;
 
-       bool const trackChanges = bparams.trackChanges;
+       bool const trackChanges = bparams.track_changes;
 
        bool capitalize = true;
 
@@ -3713,7 +3684,7 @@ void Paragraph::changeCase(BufferParams const & bparams, pos_type pos,
                }
 
                if (oldChar != newChar) {
-                       changes += newChar;
+                       changes.push_back(make_pair(newChar, getFontSettings(bparams, pos)));
                        if (pos != right - 1)
                                continue;
                        // step behind the changing area
@@ -3722,9 +3693,8 @@ void Paragraph::changeCase(BufferParams const & bparams, pos_type pos,
 
                int erasePos = pos - changes.size();
                for (size_t i = 0; i < changes.size(); i++) {
-                       insertChar(pos, changes[i],
-                                  getFontSettings(bparams,
-                                                  erasePos),
+                       insertChar(pos, changes[i].first,
+                                  changes[i].second,
                                   trackChanges);
                        if (!eraseChar(erasePos, trackChanges)) {
                                ++erasePos;
@@ -3875,7 +3845,7 @@ void Paragraph::collectWords()
                        if (cit == d->fontlist_.end())
                                return;
                        Language const * lang = cit->font().language();
-                       d->words_[*lang].insert(word);
+                       d->words_[lang->lang()].insert(word);
                }
        }
 }