Logo Search packages:      
Sourcecode: djvulibre version File versions

void DjVuDocEditor::simplify_anno ( void(*)(float progress, void *)  progress_cb = 0,
void *  cl_data = 0 
)

Use this function to simplify annotations in the document. The "simplified" format is when annotations are only allowed either in top-level page files or in a special file with SHARED_ANNO# flag on. This file is supposed to be included into every page.

Definition at line 1346 of file DjVuDocEditor.cpp.

References GListTemplate< TYPE, TYPE >::append(), ByteStream::create(), DjVuAnno::create(), DjVuDocument::get_djvu_file(), DjVmDir::get_files_list(), DjVmDir::get_pages_num(), DjVmDir::get_shared_anno_file(), DjVuDocument::id_to_url(), GBaseString::length(), remove_file(), GListTemplate< GP< TYPE >, GPBase >::size(), and GMonitor::wait().

{
      // Get the name of the SHARED_ANNO file. We will not
      // touch that file (will not move annotations from it)
   GP<DjVmDir::File> shared_file=djvm_dir->get_shared_anno_file();
   GUTF8String shared_id;
   if (shared_file)
      shared_id=shared_file->get_load_name();

   GList<GURL> ignore_list;
   if (shared_id.length())
      ignore_list.append(id_to_url(shared_id));

      // First, for every page get merged (or "flatten" or "projected")
      // annotations and store them inside the top-level page file
   int pages_num=djvm_dir->get_pages_num();
   for(int page_num=0;page_num<pages_num;page_num++)
   {
      GP<DjVuFile> djvu_file=get_djvu_file(page_num);
      if (!djvu_file)
         G_THROW( ERR_MSG("DjVuDocEditor.page_fail") "\t"+page_num);
      int max_level=0;
      GP<ByteStream> anno;
      anno=djvu_file->get_merged_anno(ignore_list, &max_level);
      if (anno && max_level>0)
      {
            // This is the moment when we try to modify DjVuFile's annotations
            // Make sure, that it's not being decoded
         GSafeFlags & file_flags=djvu_file->get_safe_flags();
         GMonitorLock lock(&file_flags);
         while(file_flags & DjVuFile::DECODING)
            file_flags.wait();
        
            // Merge all chunks in one by decoding and encoding DjVuAnno
         const GP<DjVuAnno> dec_anno(DjVuAnno::create());
         dec_anno->decode(anno);
         const GP<ByteStream> new_anno(ByteStream::create());
         dec_anno->encode(new_anno);
         new_anno->seek(0);

            // And store it in the file
         djvu_file->anno=new_anno;
         djvu_file->rebuild_data_pool();
         if ((file_flags & (DjVuFile::DECODE_OK |
                            DjVuFile::DECODE_FAILED |
                            DjVuFile::DECODE_STOPPED))==0)
            djvu_file->anno=0;
      }
      if (progress_cb)
    progress_cb((float)(page_num/2.0/pages_num), cl_data);
   }

      // Now remove annotations from every file except for
      // the top-level page files and SHARED_ANNO file.
      // Unlink empty files too.
   GPList<DjVmDir::File> files_list=djvm_dir->get_files_list();
   int cnt;
   GPosition pos;
   for(pos=files_list, cnt=0;pos;++pos, cnt++)
   {
      GP<DjVmDir::File> frec=files_list[pos];
      if (!frec->is_page() && frec->get_load_name()!=shared_id)
      {
         GP<DjVuFile> djvu_file=get_djvu_file(frec->get_load_name());
         if (djvu_file)
         {
            djvu_file->remove_anno();
            if (djvu_file->get_chunks_number()==0)
               remove_file(frec->get_load_name(), true);
         }
      }
      if (progress_cb)
         progress_cb((float)(0.5+cnt/2.0/files_list.size()), cl_data);
   }
}


Generated by  Doxygen 1.6.0   Back to index