Logo Search packages:      
Sourcecode: djvulibre version File versions

void DjVuDocEditor::insert_group ( const GList< GURL > &  furl_list,
int  page_num = -1,
void(*)(void *)  refresh_cb = 0,
void *  cl_data = 0 
)

Inserts a group of pages into this DjVu document.

Like {insert_page}() it will insert every page into the document. The main advantage of calling this function once for the whole group instead of calling {insert_page}() for every page is the processing of included files:

The group of files may include one or more files, which are thus shared by them. If you call {insert_page}() for every page, this shared file will be inserted into the document more than once though under different names. This is how {insert_page}() works: whenever it inserts something, it checks for duplicate names with only one purpose: invent a new name if a given one is already in use.

On the other hand, if you call insert_group#(), it will insert shared included files only once. This is because it can analyze the group of files before inserting them and figure out what files are shared and thus should be inserted only once.

Parameters:
fname_list List of top-level files for the pages to be inserted
page_num Position where the new pages should be inserted at. Negative value means "append"

Definition at line 780 of file DjVuDocEditor.cpp.

References DjVuPortcaster::add_route(), GMapTemplate< KTYPE, VTYPE, VTYPE >::contains(), DjVuDocument::create(), ByteStream::create(), DataPool::create(), DjVuDocument::create_noinit(), GURL::fname(), DjVuDocument::get_djvm_dir(), DjVuPort::get_portcaster(), GURL::is_local_file_url(), GURL::is_valid(), GBaseString::length(), and DjVuDocument::map_ids().

Referenced by insert_page().

{
  refresh_cb=_refresh_cb;
  refresh_cl_data=_cl_data;

  G_TRY
  {

     // First translate the page_num to file_pos.
    const GP<DjVmDir> dir(get_djvm_dir());
    int file_pos;
    if (page_num<0 || page_num>=dir->get_pages_num())
    {
      file_pos=-1;
    }
    else
    {
      file_pos=dir->get_page_pos(page_num);
    }

       // Now call the insert_file() for every page. We will remember the
       // name2id translation table. Thus insert_file() will remember IDs
       // it assigned to shared files
    GMap<GUTF8String, GUTF8String> name2id;

    GUTF8String errors;
    for(GPosition pos=file_urls;pos;++pos)
    {
      const GURL &furl=file_urls[pos];
      DEBUG_MSG( "Inserting file '" << furl << "'\n" );
      G_TRY
      {
               // Check if it's a multipage document...
        GP<DataPool> xdata_pool(DataPool::create(furl));
        if(xdata_pool && furl.is_valid()
           && furl.is_local_file_url() && DjVuDocument::djvu_import_codec)
        {
          (*DjVuDocument::djvu_import_codec)(xdata_pool,furl,
                                             needs_compression_flag,
                                             can_compress_flag);
        }
        GUTF8String chkid;
        IFFByteStream::create(xdata_pool->get_stream())->get_chunk(chkid);
        if (name2id.contains(furl.fname())||(chkid=="FORM:DJVM"))
        {
          GMap<GUTF8String,void *> map;
          map_ids(map);
          DEBUG_MSG("Read DjVuDocument furl='" << furl << "'\n");
          GP<ByteStream> gbs(ByteStream::create());
          GP<DjVuDocument> doca(DjVuDocument::create_noinit());
          doca->set_verbose_eof(verbose_eof);
          doca->set_recover_errors(recover_errors);
          doca->init(furl /* ,this */ );
          doca->wait_for_complete_init();
          get_portcaster()->add_route(doca,this);
          DEBUG_MSG("Saving DjVuDocument url='" << furl << "' with unique names\n");
          doca->write(gbs,map);
          gbs->seek(0L);
          DEBUG_MSG("Loading unique names\n");
          GP<DjVuDocument> doc(DjVuDocument::create(gbs));
          doc->set_verbose_eof(verbose_eof);
          doc->set_recover_errors(recover_errors);
          doc->wait_for_complete_init();
          get_portcaster()->add_route(doc,this);
          gbs=0;
          DEBUG_MSG("Inserting pages\n");
          int pages_num=doc->get_pages_num();
          for(int page_num=0;page_num<pages_num;page_num++)
          {
            const GURL url(doc->page_to_url(page_num));
            insert_file(url, true, file_pos, name2id, doc);
          }
        }
        else
        {
          insert_file(furl, true, file_pos, name2id, this);
        }
      } G_CATCH(exc)
      {
        if (errors.length())
        {
          errors+="\n\n";
        }
        errors+=exc.get_cause();
      }
      G_ENDCATCH;
    }
    if (errors.length())
    {
      G_THROW(errors);
    }
  } G_CATCH_ALL
  {
    refresh_cb=0;
    refresh_cl_data=0;
    G_RETHROW;
  } G_ENDCATCH;
  refresh_cb=0;
  refresh_cl_data=0;
}


Generated by  Doxygen 1.6.0   Back to index