Logo Search packages:      
Sourcecode: djvulibre version File versions

void DjVuDocEditor::init ( const GURL url  )  [protected]

Initialization function. Opens document with name filename#.

{ Note}: You must call either of the two available {init}() function before you start doing anything else with the DjVuDocEditor#.

Definition at line 170 of file DjVuDocEditor.cpp.

References ByteStream::create(), DataPool::create(), DjVuDocument::create_wait(), DjVuDocument::get_pages_num(), GURL::get_string(), DjVuDocument::get_thumbnail(), DjVuDocument::init(), and page_to_id().

{
   DEBUG_MSG("DjVuDocEditor::init() called: url='" << url << "'\n");
   DEBUG_MAKE_INDENT(3);

      // If you remove this check be sure to delete thumb_map
   if (initialized)
     G_THROW( ERR_MSG("DjVuDocEditor.init") );

      // First - create a temporary DjVuDocument and check its type
   doc_pool=DataPool::create(url);
   doc_url=url;
   const GP<DjVuDocument> tmp_doc(DjVuDocument::create_wait(doc_url,this));
   if (!tmp_doc->is_init_ok())
      G_THROW( ERR_MSG("DjVuDocEditor.open_fail") "\t" +url.get_string());

   orig_doc_type=tmp_doc->get_doc_type();
   orig_doc_pages=tmp_doc->get_pages_num();
   if (orig_doc_type==OLD_BUNDLED ||
       orig_doc_type==OLD_INDEXED ||
       orig_doc_type==SINGLE_PAGE)
   {
         // Suxx. I need to convert it NOW.
         // We will unlink this file in the destructor
#ifndef UNDER_CE
      tmp_doc_url=GURL::Filename::Native(tmpnam(0));
#else
      tmp_doc_url=GURL::Filename::UTF8("tempFileForDjVu");
#endif
      const GP<ByteStream> gstr(ByteStream::create(tmp_doc_url, "wb"));
      tmp_doc->write(gstr, true);        // Force DJVM format
      gstr->flush();
      doc_pool=DataPool::create(tmp_doc_url);
   }

      // OK. Now doc_pool contains data of the document in one of the
      // new formats. It will be a lot easier to insert/delete pages now.

      // 'doc_url' below of course doesn't refer to the file with the converted
      // data, but we will take care of it by redirecting the request_data().
   initialized=true;
   DjVuDocument::init(doc_url, this);

      // Cool. Now extract the thumbnails...
   GCriticalSectionLock lock(&thumb_lock);
   int pages_num=get_pages_num();
   for(int page_num=0;page_num<pages_num;page_num++)
   {
       // Call DjVuDocument::get_thumbnail() here to bypass logic
       // of DjVuDocEditor::get_thumbnail(). init() is the only safe
       // place where we can still call DjVuDocument::get_thumbnail();
      const GP<DataPool> pool(DjVuDocument::get_thumbnail(page_num, true));
      if (pool)
      {
        thumb_map[page_to_id(page_num)]=pool;
      }
   }
      // And remove then from DjVmDir so that DjVuDocument
      // does not try to use them
   unfile_thumbnails();
}


Generated by  Doxygen 1.6.0   Back to index