Blame libdjvu/DjVmDoc.h

Packit df99a1
//C-  -*- C++ -*-
Packit df99a1
//C- -------------------------------------------------------------------
Packit df99a1
//C- DjVuLibre-3.5
Packit df99a1
//C- Copyright (c) 2002  Leon Bottou and Yann Le Cun.
Packit df99a1
//C- Copyright (c) 2001  AT&T
Packit df99a1
//C-
Packit df99a1
//C- This software is subject to, and may be distributed under, the
Packit df99a1
//C- GNU General Public License, either Version 2 of the license,
Packit df99a1
//C- or (at your option) any later version. The license should have
Packit df99a1
//C- accompanied the software or you may obtain a copy of the license
Packit df99a1
//C- from the Free Software Foundation at http://www.fsf.org .
Packit df99a1
//C-
Packit df99a1
//C- This program is distributed in the hope that it will be useful,
Packit df99a1
//C- but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit df99a1
//C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit df99a1
//C- GNU General Public License for more details.
Packit df99a1
//C- 
Packit df99a1
//C- DjVuLibre-3.5 is derived from the DjVu(r) Reference Library from
Packit df99a1
//C- Lizardtech Software.  Lizardtech Software has authorized us to
Packit df99a1
//C- replace the original DjVu(r) Reference Library notice by the following
Packit df99a1
//C- text (see doc/lizard2002.djvu and doc/lizardtech2007.djvu):
Packit df99a1
//C-
Packit df99a1
//C-  ------------------------------------------------------------------
Packit df99a1
//C- | DjVu (r) Reference Library (v. 3.5)
Packit df99a1
//C- | Copyright (c) 1999-2001 LizardTech, Inc. All Rights Reserved.
Packit df99a1
//C- | The DjVu Reference Library is protected by U.S. Pat. No.
Packit df99a1
//C- | 6,058,214 and patents pending.
Packit df99a1
//C- |
Packit df99a1
//C- | This software is subject to, and may be distributed under, the
Packit df99a1
//C- | GNU General Public License, either Version 2 of the license,
Packit df99a1
//C- | or (at your option) any later version. The license should have
Packit df99a1
//C- | accompanied the software or you may obtain a copy of the license
Packit df99a1
//C- | from the Free Software Foundation at http://www.fsf.org .
Packit df99a1
//C- |
Packit df99a1
//C- | The computer code originally released by LizardTech under this
Packit df99a1
//C- | license and unmodified by other parties is deemed "the LIZARDTECH
Packit df99a1
//C- | ORIGINAL CODE."  Subject to any third party intellectual property
Packit df99a1
//C- | claims, LizardTech grants recipient a worldwide, royalty-free, 
Packit df99a1
//C- | non-exclusive license to make, use, sell, or otherwise dispose of 
Packit df99a1
//C- | the LIZARDTECH ORIGINAL CODE or of programs derived from the 
Packit df99a1
//C- | LIZARDTECH ORIGINAL CODE in compliance with the terms of the GNU 
Packit df99a1
//C- | General Public License.   This grant only confers the right to 
Packit df99a1
//C- | infringe patent claims underlying the LIZARDTECH ORIGINAL CODE to 
Packit df99a1
//C- | the extent such infringement is reasonably necessary to enable 
Packit df99a1
//C- | recipient to make, have made, practice, sell, or otherwise dispose 
Packit df99a1
//C- | of the LIZARDTECH ORIGINAL CODE (or portions thereof) and not to 
Packit df99a1
//C- | any greater extent that may be necessary to utilize further 
Packit df99a1
//C- | modifications or combinations.
Packit df99a1
//C- |
Packit df99a1
//C- | The LIZARDTECH ORIGINAL CODE is provided "AS IS" WITHOUT WARRANTY
Packit df99a1
//C- | OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
Packit df99a1
//C- | TO ANY WARRANTY OF NON-INFRINGEMENT, OR ANY IMPLIED WARRANTY OF
Packit df99a1
//C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
Packit df99a1
//C- +------------------------------------------------------------------
Packit df99a1
Packit df99a1
#ifndef _DJVMDOC_H
Packit df99a1
#define _DJVMDOC_H
Packit df99a1
#ifdef HAVE_CONFIG_H
Packit df99a1
#include "config.h"
Packit df99a1
#endif
Packit df99a1
#if NEED_GNUG_PRAGMAS
Packit df99a1
# pragma interface
Packit df99a1
#endif
Packit df99a1
Packit df99a1
Packit df99a1
#include "DjVmDir.h"
Packit df99a1
Packit df99a1
#ifdef HAVE_NAMESPACES
Packit df99a1
namespace DJVU {
Packit df99a1
# ifdef NOT_DEFINED // Just to fool emacs c++ mode
Packit df99a1
}
Packit df99a1
#endif
Packit df99a1
#endif
Packit df99a1
Packit df99a1
class ByteStream;
Packit df99a1
class DataPool;
Packit df99a1
class GURL;
Packit df99a1
class GUTF8String;
Packit df99a1
class DjVmNav;
Packit df99a1
Packit df99a1
/** @name DjVmDoc.h
Packit df99a1
    Files #"DjVmDoc.h"# and #"DjVmDoc.cpp"# contain implementation of the
Packit df99a1
    \Ref{DjVmDoc} class used to read and write new DjVu multipage documents.
Packit df99a1
Packit df99a1
    @memo DjVu multipage documents reader/writer.
Packit df99a1
    @author Andrei Erofeev <eaf@geocities.com>
Packit df99a1
*/
Packit df99a1
Packit df99a1
//@{
Packit df99a1
Packit df99a1
/** Read/Write DjVu multipage documents.
Packit df99a1
Packit df99a1
    The "new" DjVu multipage documents can be of two types: {\em bundled} and
Packit df99a1
    {\em indirect}. In the first case all pages are packed into one file,
Packit df99a1
    which is very like an archive internally. In the second case every page
Packit df99a1
    is stored in a separate file. Plus there can be other components,
Packit df99a1
    included into one or more pages, which also go into separate files. In
Packit df99a1
    addition to pages and components, in the case of the {\em indirect} format
Packit df99a1
    there is one more top-level file with the document directory (see
Packit df99a1
    \Ref{DjVmDir}), which is basically an index file containing the
Packit df99a1
    list of all files composing the document.
Packit df99a1
Packit df99a1
    This class can read documents of both formats and can save them under any
Packit df99a1
    format.  It is therefore ideal for converting between {\em bundled} and
Packit df99a1
    {\em indirect} formats.  It cannot be used however for reading obsolete
Packit df99a1
    formats.  The best way to convert obsolete formats consists in reading
Packit df99a1
    them with class \Ref{DjVuDocument} class and saving them using
Packit df99a1
    \Ref{DjVuDocument::write} or \Ref{DjVuDocument::expand}.
Packit df99a1
Packit df99a1
    This class can also be used to create and modify multipage documents at
Packit df99a1
    the low level without decoding every page or component (See
Packit df99a1
    \Ref{insert_file}() and \Ref{delete_file}()). 
Packit df99a1
*/
Packit df99a1
Packit df99a1
class DJVUAPI DjVmDoc : public GPEnabled
Packit df99a1
{
Packit df99a1
      // Internal function.
Packit df99a1
protected:   
Packit df99a1
  DjVmDoc(void);
Packit df99a1
  void init(void);
Packit df99a1
public:
Packit df99a1
      /// Creator
Packit df99a1
   static GP<DjVmDoc> create(void);
Packit df99a1
      /** Inserts a file into the document.
Packit df99a1
          @param data  ByteStream containing the file data.
Packit df99a1
          @param file_type Describes the type of the file to be inserted.
Packit df99a1
	  	 See \Ref{DjVmDir::File} for details.
Packit df99a1
          @param name  Name of the file in the document (e.g. an URL).
Packit df99a1
          @param id    Identifier of the file (as used in INCL chunks).
Packit df99a1
          @param title Optional title of the file (shown in browsers).
Packit df99a1
          @param pos   Position of the file in the document (default is append).
Packit df99a1
      */
Packit df99a1
   void	insert_file(
Packit df99a1
     ByteStream &data, DjVmDir::File::FILE_TYPE file_type,
Packit df99a1
     const GUTF8String &name, const GUTF8String &id,
Packit df99a1
     const GUTF8String &title=GUTF8String(), int pos=-1 );
Packit df99a1
      /** Inserts a file into the document.
Packit df99a1
          @param pool  Data pool containing file data.
Packit df99a1
          @param file_type Describes the type of the file to be inserted.
Packit df99a1
	  	 See \Ref{DjVmDir::File} for details.
Packit df99a1
          @param name  Name of the file in the document (e.g. an URL).
Packit df99a1
          @param id    Identifier of the file (as used in INCL chunks).
Packit df99a1
          @param title Optional title of the file (shown in browsers).
Packit df99a1
          @param pos   Position of the file in the document (default is append).
Packit df99a1
      */
Packit df99a1
   void	insert_file(
Packit df99a1
     const GP<DataPool> &pool, DjVmDir::File::FILE_TYPE file_type,
Packit df99a1
     const GUTF8String &name, const GUTF8String &id,
Packit df99a1
     const GUTF8String &title=GUTF8String(), int pos=-1 );
Packit df99a1
Packit df99a1
      /** Inserts a file described by \Ref{DjVmDir::File} structure with
Packit df99a1
	  data #data# at position #pos#. If #pos# is negative, the file
Packit df99a1
          will be appended to the document. Otherwise it will be inserted
Packit df99a1
          at position #pos#. */
Packit df99a1
   void	insert_file(const GP<DjVmDir::File> & f,
Packit df99a1
                    GP<DataPool> data, int pos=-1);
Packit df99a1
Packit df99a1
      /** Removes file with the specified #id# from the document. Every
Packit df99a1
	  file inside a new DjVu multipage document has its unique ID
Packit df99a1
	  (refer to \Ref{DjVmDir} for details), which is passed to this
Packit df99a1
          function. */
Packit df99a1
   void	delete_file(const GUTF8String &id;;
Packit df99a1
Packit df99a1
     /** Set the bookmarks */
Packit df99a1
   void set_djvm_nav(GP<DjVmNav> n);
Packit df99a1
Packit df99a1
      /** Returns the directory of the DjVm document (the one which will
Packit df99a1
	  be encoded into #DJVM# chunk of the top-level file or the bundle). */
Packit df99a1
   GP<DjVmDir>	get_djvm_dir(void);
Packit df99a1
   
Packit df99a1
      /** Returns contents of file with ID #id# from the document.
Packit df99a1
	  Please refer to \Ref{DjVmDir} for the explanation of what
Packit df99a1
          IDs mean. */
Packit df99a1
   GP<DataPool>	get_data(const GUTF8String &id) const;
Packit df99a1
Packit df99a1
      /** Reading routines */
Packit df99a1
      //@{
Packit df99a1
      /** Reads contents of a {\em bundled} multipage DjVu document from
Packit df99a1
	  the stream. */
Packit df99a1
   void	read(ByteStream & str);
Packit df99a1
      /** Reads contents of a {\em bundled} multipage DjVu document from
Packit df99a1
	  the \Ref{DataPool}. */
Packit df99a1
   void	read(const GP<DataPool> & data_pool);
Packit df99a1
      /** Reads the DjVu multipage document in either {\em bundled} or
Packit df99a1
	  {\em indirect} format.
Packit df99a1
Packit df99a1
	  {\bf Note:} For {\em bundled} documents the file is not
Packit df99a1
	  read into memory. We just open it and access data directly there.
Packit df99a1
	  Thus you should not modify the file contents.
Packit df99a1
Packit df99a1
	  @param name For {\em bundled} documents this is the name
Packit df99a1
	         of the document. For {\em indirect} documents this is
Packit df99a1
		 the name of the top-level file of the document (containing
Packit df99a1
		 the \Ref{DjVmDir} with the list of all files).
Packit df99a1
		 The rest of the files are expected to be in the
Packit df99a1
		 same directory and will be read by this function as well. */
Packit df99a1
   void	read(const GURL &url;;
Packit df99a1
      //@}
Packit df99a1
Packit df99a1
      /** Writing routines */
Packit df99a1
      //@{
Packit df99a1
      /** Writes the multipage DjVu document in the {\em bundled} format into
Packit df99a1
	  the stream. */
Packit df99a1
   void	write(const GP<ByteStream> &str);
Packit df99a1
      /** Writes the multipage DjVu document in the {\em bundled} format into
Packit df99a1
	  the stream, reserving any of the specified names. */
Packit df99a1
   void	write(const GP<ByteStream> &str,
Packit df99a1
              const GMap<GUTF8String,void *>& reserved);
Packit df99a1
      /** Stored index (top-level) file of the DjVu document in the {\em
Packit df99a1
	  indirect} format into the specified stream. */
Packit df99a1
   void	write_index(const GP<ByteStream> &str);
Packit df99a1
      /** Writes the multipage DjVu document in the {\em indirect} format
Packit df99a1
	  into the given directory. Every page and included file will be
Packit df99a1
          stored as a separate file. Besides, one top-level file with
Packit df99a1
          the document directory (named #idx_name#) will be created unless
Packit df99a1
	  #idx_name# is empty.
Packit df99a1
Packit df99a1
          @param dir_name Name of the directory where files should be
Packit df99a1
		 created
Packit df99a1
	  @param idx_name Name of the top-level file with the \Ref{DjVmDir}
Packit df99a1
		 with the list of files composing the given document.
Packit df99a1
		 If empty, the file will not be created. */
Packit df99a1
   void	expand(const GURL &codebase, const GUTF8String &idx_name);
Packit df99a1
Packit df99a1
      /** Writes an individual file, and all included files. 
Packit df99a1
          INCL chunks will be remapped as appropriate. */
Packit df99a1
   void save_page(const GURL &codebase, const DjVmDir::File &file) const;
Packit df99a1
Packit df99a1
      /** Writes an individual file if not mapped, and all included files. 
Packit df99a1
          INCL chunks will be remapped as appropriate.  All pages saved
Packit df99a1
          are added to the #incl# map. */
Packit df99a1
   void save_page(const GURL &codebase, const DjVmDir::File &file,
Packit df99a1
                  GMap<GUTF8String,GUTF8String> &incl) const;
Packit df99a1
Packit df99a1
      /** Writes an individual file specified, remapping INCL chunks as
Packit df99a1
          appropriate.  Included files will not be saved. */
Packit df99a1
   void save_file(const GURL &codebase, const DjVmDir::File &file) const;
Packit df99a1
Packit df99a1
      /** Writes the specified file from the given #pool#. */
Packit df99a1
   GUTF8String save_file(const GURL &codebase, const DjVmDir::File &file,
Packit df99a1
                         GMap<GUTF8String,GUTF8String> &incl, 
Packit df99a1
                         const GP<DataPool> &pool) const;
Packit df99a1
  //@}
Packit df99a1
private:
Packit df99a1
   void save_file(const GURL &codebase, const DjVmDir::File &file,
Packit df99a1
                  GMap<GUTF8String,GUTF8String> *incl) const;
Packit df99a1
   GP<DjVmDir> dir;
Packit df99a1
   GP<DjVmNav> nav;
Packit df99a1
   GPMap<GUTF8String, DataPool > data;
Packit df99a1
private: // dummy stuff
Packit df99a1
   static void write(ByteStream *);
Packit df99a1
   static void write_index(ByteStream *);
Packit df99a1
};
Packit df99a1
Packit df99a1
inline GP<DjVmDir>
Packit df99a1
DjVmDoc::get_djvm_dir(void)
Packit df99a1
{
Packit df99a1
   return dir;
Packit df99a1
}
Packit df99a1
Packit df99a1
Packit df99a1
//@}
Packit df99a1
Packit df99a1
Packit df99a1
Packit df99a1
#ifdef HAVE_NAMESPACES
Packit df99a1
}
Packit df99a1
# ifndef NOT_USING_DJVU_NAMESPACE
Packit df99a1
using namespace DJVU;
Packit df99a1
# endif
Packit df99a1
#endif
Packit df99a1
#endif