Logo Search packages:      
Sourcecode: djvulibre version File versions

void DjVuDocEditor::move_pages ( const GList< int > &  page_list,
int  shift 
)

Shifts all pags from the page_list# according to the shift#. The shift# can be positive (shift toward the end of the document) or negative (shift toward the beginning of the document).

It is OK to make shift# too big in value. Pages will just be moved to the end (or to the beginning, depending on the shift# sign) of the document.

Definition at line 1223 of file DjVuDocEditor.cpp.

References GListTemplate< TYPE, TYPE >::append(), DjVmDir::get_pages_num(), DjVmDir::id_to_file(), GListTemplate< TYPE, TYPE >::lastpos(), move_page(), and DjVmDir::page_to_file().

{
   if (!shift) return;

   GList<int> page_list=sortList(_page_list);

   GList<GUTF8String> id_list;
   for(GPosition pos=page_list;pos;++pos)
   {
      GP<DjVmDir::File> frec=djvm_dir->page_to_file(page_list[pos]);
      if (frec)
         id_list.append(frec->get_load_name());
   }

   if (shift<0)
   {
         // We have to start here from the smallest page number
         // We will move it according to the 'shift', and all
         // further moves are guaranteed not to affect its page number.

         // We will be changing the 'min_page' to make sure that
         // pages moved beyond the document will still be in correct order
      int min_page=0;
      for(GPosition pos=id_list;pos;++pos)
      {
         GP<DjVmDir::File> frec=djvm_dir->id_to_file(id_list[pos]);
         if (frec)
         {
            int page_num=frec->get_page_num();
            int new_page_num=page_num+shift;
            if (new_page_num<min_page)
               new_page_num=min_page++;
            move_page(page_num, new_page_num);
         }
      }
   } else
   {
         // We have to start here from the biggest page number
         // We will move it according to the 'shift', and all
         // further moves will not affect its page number.

         // We will be changing the 'max_page' to make sure that
         // pages moved beyond the document will still be in correct order
      int max_page=djvm_dir->get_pages_num()-1;
      for(GPosition pos=id_list.lastpos();pos;--pos)
      {
         GP<DjVmDir::File> frec=djvm_dir->id_to_file(id_list[pos]);
         if (frec)
         {
            int page_num=frec->get_page_num();
            int new_page_num=page_num+shift;
            if (new_page_num>max_page)
               new_page_num=max_page--;
            move_page(page_num, new_page_num);
         }
      }
   }
}


Generated by  Doxygen 1.6.0   Back to index