-int countWords(DocIterator const & from, DocIterator const & to)
-{
- int count = 0;
- bool inword = false;
- for (DocIterator dit = from ; dit != to ; dit.forwardPos()) {
- // Copied and adapted from isLetter() in ControlSpellChecker
- if (dit.inTexted()
- && dit.pos() != dit.lastpos()
- && dit.paragraph().isLetter(dit.pos())
- && !dit.paragraph().isDeleted(dit.pos())) {
- if (!inword) {
- ++count;
- inword = true;
- }
- } else if (inword)
- inword = false;
- }
-
- return count;
-}
-
-
-namespace {
-
-depth_type getDepth(DocIterator const & it)
-{
- depth_type depth = 0;
- for (size_t i = 0 ; i < it.depth() ; ++i)
- if (!it[i].inset().inMathed())
- depth += it[i].paragraph().getDepth() + 1;
- // remove 1 since the outer inset does not count
- return depth - 1;
-}
-
-depth_type getItemDepth(ParIterator const & it)
-{
- Paragraph const & par = *it;
- LabelType const labeltype = par.layout()->labeltype;
-
- if (labeltype != LABEL_ENUMERATE && labeltype != LABEL_ITEMIZE)
- return 0;
-
- // this will hold the lowest depth encountered up to now.
- depth_type min_depth = getDepth(it);
- ParIterator prev_it = it;
- while (true) {
- if (prev_it.pit())
- --prev_it.top().pit();
- else {
- // start of nested inset: go to outer par
- prev_it.pop_back();
- if (prev_it.empty()) {
- // start of document: nothing to do
- return 0;
- }
- }
-
- // We search for the first paragraph with same label
- // that is not more deeply nested.
- Paragraph & prev_par = *prev_it;
- depth_type const prev_depth = getDepth(prev_it);
- if (labeltype == prev_par.layout()->labeltype) {
- if (prev_depth < min_depth) {
- return prev_par.itemdepth + 1;
- }
- else if (prev_depth == min_depth) {
- return prev_par.itemdepth;
- }
- }
- min_depth = std::min(min_depth, prev_depth);
- // small optimization: if we are at depth 0, we won't
- // find anything else
- if (prev_depth == 0) {
- return 0;
- }
- }
-}
-
-
-bool needEnumCounterReset(ParIterator const & it)
-{
- Paragraph const & par = *it;
- BOOST_ASSERT(par.layout()->labeltype == LABEL_ENUMERATE);
- depth_type const cur_depth = par.getDepth();
- ParIterator prev_it = it;
- while (prev_it.pit()) {
- --prev_it.top().pit();
- Paragraph const & prev_par = *prev_it;
- if (prev_par.getDepth() <= cur_depth)
- return prev_par.layout()->labeltype != LABEL_ENUMERATE;
- }
- // start of nested inset: reset
- return true;
-}
-
-
-// set the label of a paragraph. This includes the counters.
-void setLabel(Buffer const & buf, ParIterator & it)