- // this function re-creates the cache of inset pointers
- //lyxerr << "converting:\n" << *this << endl;
- DocIterator dit = DocIterator(*inset);
- for (size_t i = 0, n = data_.size(); i != n; ++i) {
- if (inset == 0) {
- // FIXME
- lyxerr << BOOST_CURRENT_FUNCTION
- << " Should not happen, but does e.g. after C-n C-l C-z S-C-z\n"
- << " or when a Buffer has been concurently edited by two views"
- << '\n' << "dit: " << dit << '\n'
- << " lastpos: " << dit.lastpos() << endl;
- dit.fixIfBroken();
- break;
+ slices_.insert(slices_.end(), x.begin(), x.end());
+}
+
+
+void DocIterator::append(idx_type idx, pos_type pos)
+{
+ slices_.push_back(CursorSlice());
+ top().idx() = idx;
+ top().pos() = pos;
+}
+
+
+docstring DocIterator::getPossibleLabel() const
+{
+ return inMathed() ? from_ascii("eq:") : text()->getPossibleLabel(*this);
+}
+
+
+Encoding const * DocIterator::getEncoding() const
+{
+ if (empty())
+ return nullptr;
+
+ BufferParams const & bp = buffer()->params();
+ if (bp.useNonTeXFonts)
+ return encodings.fromLyXName("utf8-plain");
+
+ // With platex, we don't switch encodings (not even if forced).
+ if (bp.encoding().package() == Encoding::japanese)
+ return &bp.encoding();
+
+ CursorSlice const & sl = innerTextSlice();
+ Text const & text = *sl.text();
+ Language const * lang =
+ text.getPar(sl.pit()).getFont(bp, sl.pos(), text.outerFont(sl.pit())).language();
+ // If we have a custom encoding for the buffer, we don't switch
+ // encodings (see output_latex::switchEncoding())
+ bool const customenc = bp.inputenc != "auto-legacy" && bp.inputenc != "auto-legacy-plain";
+ Encoding const * enc = customenc ? &bp.encoding() : lang->encoding();
+
+ // Some insets force specific encodings sometimes (e.g., listings in
+ // multibyte context forces singlebyte).
+ if (inset().forcedEncoding(enc, encodings.fromLyXName("iso8859-1"))) {
+ // Get the language outside the inset
+ size_t const n = depth();
+ for (size_t i = 0; i < n; ++i) {
+ Text const & otext = *slices_[i].text();
+ Language const * olang =
+ otext.getPar(slices_[i].pit()).getFont(bp, slices_[i].pos(),
+ otext.outerFont(slices_[i].pit())).language();
+ Encoding const * oenc = olang->encoding();
+ if (oenc->name() != "inherit")
+ return inset().forcedEncoding(enc, oenc);