]> git.lyx.org Git - lyx.git/blobdiff - src/Paragraph.cpp
* src/frontends/GuiDocument.{cpp,h}:
[lyx.git] / src / Paragraph.cpp
index 61fe11117bf5f64e1b75cf7c0d05729cce1dbb6b..4f4d9ff5630454a6e255d9183443a39fdf8786b7 100644 (file)
@@ -53,7 +53,6 @@
 #include "support/lstrings.h"
 #include "support/Messages.h"
 #include "support/textutils.h"
-#include "support/unicode.h"
 
 #include <sstream>
 #include <vector>
@@ -250,15 +249,13 @@ bool Paragraph::isChanged(pos_type start, pos_type end) const
 }
 
 
-bool Paragraph::isMergedOnEndOfParDeletion(bool trackChanges) const {
+bool Paragraph::isMergedOnEndOfParDeletion(bool trackChanges) const
+{
        // keep the logic here in sync with the logic of eraseChars()
-
-       if (!trackChanges) {
+       if (!trackChanges)
                return true;
-       }
-
-       Change change = d->changes_.lookup(size());
 
+       Change const change = d->changes_.lookup(size());
        return change.type == Change::INSERTED && change.author == 0;
 }
 
@@ -292,22 +289,17 @@ void Paragraph::setChange(Change const & change)
 void Paragraph::setChange(pos_type pos, Change const & change)
 {
        BOOST_ASSERT(pos >= 0 && pos <= size());
-
        d->changes_.set(change, pos);
 
        // see comment in setChange(Change const &) above
-
-       if (change.type != Change::DELETED &&
-           pos < size() && isInset(pos)) {
+       if (change.type != Change::DELETED && pos < size() && isInset(pos))
                getInset(pos)->setChange(change);
-       }
 }
 
 
 Change const & Paragraph::lookupChange(pos_type pos) const
 {
        BOOST_ASSERT(pos >= 0 && pos <= size());
-
        return d->changes_.lookup(pos);
 }
 
@@ -999,6 +991,13 @@ void Paragraph::Private::validate(LaTeXFeatures & features,
 
        // then the layouts
        features.useLayout(layout.name());
+       if (!layout.requires().empty()) {
+               vector<string> req = layout.requires();
+               for (vector<string>::const_iterator it = req.begin();
+                    it != req.end(); ++it) {
+                       features.require(*it);
+               }
+       }
 
        // then the fonts
        fontlist_.validate(features);
@@ -1158,11 +1157,9 @@ void Paragraph::write(Buffer const & buf, ostream & os,
                        }
                        // this check is to amend a bug. LyX sometimes
                        // inserts '\0' this could cause problems.
-                       if (c != '\0') {
-                               vector<char> tmp = ucs4_to_utf8(c);
-                               tmp.push_back('\0');
-                               os << &tmp[0];
-                       } else
+                       if (c != '\0')
+                               os << to_utf8(docstring(1, c));
+                       else
                                lyxerr << "ERROR (Paragraph::writeFile):"
                                        " NULL char in structure." << endl;
                        ++column;
@@ -2024,10 +2021,17 @@ bool Paragraph::latex(Buffer const & buf,
                                d->latexSpecialChar(os, rp, running_font, runningChange,
                                        *style, i, column);
                        } catch (EncodingException & e) {
-                               // add location information and throw again.
-                               e.par_id = id();
-                               e.pos = i;
-                               throw(e);
+                               if (runparams.dryrun) {
+                                       os << "<" << _("LyX Warning: ")
+                                          << _("uncodable character") << " '";
+                                       os.put(c);
+                                       os << "'>";
+                               } else {
+                                       // add location information and throw again.
+                                       e.par_id = id();
+                                       e.pos = i;
+                                       throw(e);
+                               }
                        }
                }
 
@@ -2210,15 +2214,13 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf,
 
 bool Paragraph::isHfill(pos_type pos) const
 {
-       return isInset(pos)
-               && getInset(pos)->lyxCode() == HFILL_CODE;
+       return isInset(pos) && getInset(pos)->lyxCode() == HFILL_CODE;
 }
 
 
 bool Paragraph::isNewline(pos_type pos) const
 {
-       return isInset(pos)
-               && getInset(pos)->lyxCode() == NEWLINE_CODE;
+       return isInset(pos) && getInset(pos)->lyxCode() == NEWLINE_CODE;
 }
 
 
@@ -2236,10 +2238,8 @@ bool Paragraph::isLetter(pos_type pos) const
 {
        if (isInset(pos))
                return getInset(pos)->isLetter();
-       else {
-               char_type const c = d->text_[pos];
-               return isLetterChar(c) || isDigit(c);
-       }
+       char_type const c = d->text_[pos];
+       return isLetterChar(c) || isDigit(c);
 }
 
 
@@ -2352,8 +2352,7 @@ Inset * Paragraph::inInset() const
 
 InsetCode Paragraph::ownerCode() const
 {
-       return d->inset_owner_ ?
-               d->inset_owner_->lyxCode() : NO_CODE;
+       return d->inset_owner_ ? d->inset_owner_->lyxCode() : NO_CODE;
 }