Logo Search packages:      
Sourcecode: djvulibre version File versions

GURL DjVuDocument::page_to_url ( int  page_num  )  const

Translates the page number to the full URL of the page. This URL is "artificial" for the {bundled} formats and is obtained by appending the page name to the document's URL honoring possible #;# and #?# in it. Negative page number has a special meaning for OLD_INDEXED# documents: it points to the URL, which the DjVuDocument# has been initialized with. For other formats this is the same as page #0#.

The function tries it best to map the page number to the URL. Although, if the document structure has not been fully discovered yet, an empty URL will be returned. Use {wait_for_complete_init}() to wait until the document initialization completes. Refer to {init}() for details.

Depending on the document format, the function assumes, that there is enough information to complete the request when: {itemize} OLD_INDEXED#: If page_num<0#, DOC_TYPE_KNOWN# flag must be set. Otherwise DOC_NDIR_KNOWN# must be set. OLD_BUNDLED#: If page_num=0#, DOC_DIR_KNOWN# flag must be set. Otherwise DOC_NDIR_KNOWN# flag must be set. INDIRECT# and BUNDLED#: DOC_DIR_KNOWN# flag must be set. {itemize}

Definition at line 661 of file DjVuDocument.cpp.

References GURL::base().

Referenced by get_djvu_file(), get_id_list(), page_to_id(), and DjVuDocEditor::save_as().

{
   check();
   DEBUG_MSG("DjVuDocument::page_to_url(): page_num=" << page_num << "\n");
   DEBUG_MAKE_INDENT(3);
   
   GURL url;
   if (flags & DOC_TYPE_KNOWN)
      switch(doc_type)
      {
       case SINGLE_PAGE:
       case OLD_INDEXED:
       {
          if (page_num<0) url=init_url;
          else if (flags & DOC_NDIR_KNOWN) url=ndir->page_to_url(page_num);
          break;
       }
       case OLD_BUNDLED:
       {
          if (page_num<0) page_num=0;
          if (page_num==0 && (flags & DOC_DIR_KNOWN))
             url=GURL::UTF8(first_page_name,init_url);
          else if (flags & DOC_NDIR_KNOWN)
             url=ndir->page_to_url(page_num);
          break;
       }
       case BUNDLED:
       {
          if (page_num<0)
              page_num=0;
          if (flags & DOC_DIR_KNOWN)
          {
            GP<DjVmDir::File> file=djvm_dir->page_to_file(page_num);
            if (!file) G_THROW( ERR_MSG("DjVuDocument.big_num") );
            url=GURL::UTF8(file->get_load_name(),init_url);
          }
          break;
       }
       case INDIRECT:
       {
          if (page_num<0) page_num=0;
          if (flags & DOC_DIR_KNOWN)
          {
             GP<DjVmDir::File> file=djvm_dir->page_to_file(page_num);
             if (!file)
                 G_THROW( ERR_MSG("DjVuDocument.big_num") );
             url=GURL::UTF8(file->get_load_name(),init_url.base());
          }
          break;
       }
       default:
          G_THROW( ERR_MSG("DjVuDocument.unk_type") );
      }
   return url;
}


Generated by  Doxygen 1.6.0   Back to index