source: trunk/libdjvu/DjVmDoc.h @ 199

Last change on this file since 199 was 17, checked in by Eugene Romanenko, 16 years ago

update makefiles, remove absolute paths, update djvulibre to version 3.5.17

File size: 11.4 KB
Line 
1//C-  -*- C++ -*-
2//C- -------------------------------------------------------------------
3//C- DjVuLibre-3.5
4//C- Copyright (c) 2002  Leon Bottou and Yann Le Cun.
5//C- Copyright (c) 2001  AT&T
6//C-
7//C- This software is subject to, and may be distributed under, the
8//C- GNU General Public License, Version 2. The license should have
9//C- accompanied the software or you may obtain a copy of the license
10//C- from the Free Software Foundation at http://www.fsf.org .
11//C-
12//C- This program is distributed in the hope that it will be useful,
13//C- but WITHOUT ANY WARRANTY; without even the implied warranty of
14//C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15//C- GNU General Public License for more details.
16//C-
17//C- DjVuLibre-3.5 is derived from the DjVu(r) Reference Library
18//C- distributed by Lizardtech Software.  On July 19th 2002, Lizardtech
19//C- Software authorized us to replace the original DjVu(r) Reference
20//C- Library notice by the following text (see doc/lizard2002.djvu):
21//C-
22//C-  ------------------------------------------------------------------
23//C- | DjVu (r) Reference Library (v. 3.5)
24//C- | Copyright (c) 1999-2001 LizardTech, Inc. All Rights Reserved.
25//C- | The DjVu Reference Library is protected by U.S. Pat. No.
26//C- | 6,058,214 and patents pending.
27//C- |
28//C- | This software is subject to, and may be distributed under, the
29//C- | GNU General Public License, Version 2. The license should have
30//C- | accompanied the software or you may obtain a copy of the license
31//C- | from the Free Software Foundation at http://www.fsf.org .
32//C- |
33//C- | The computer code originally released by LizardTech under this
34//C- | license and unmodified by other parties is deemed "the LIZARDTECH
35//C- | ORIGINAL CODE."  Subject to any third party intellectual property
36//C- | claims, LizardTech grants recipient a worldwide, royalty-free,
37//C- | non-exclusive license to make, use, sell, or otherwise dispose of
38//C- | the LIZARDTECH ORIGINAL CODE or of programs derived from the
39//C- | LIZARDTECH ORIGINAL CODE in compliance with the terms of the GNU
40//C- | General Public License.   This grant only confers the right to
41//C- | infringe patent claims underlying the LIZARDTECH ORIGINAL CODE to
42//C- | the extent such infringement is reasonably necessary to enable
43//C- | recipient to make, have made, practice, sell, or otherwise dispose
44//C- | of the LIZARDTECH ORIGINAL CODE (or portions thereof) and not to
45//C- | any greater extent that may be necessary to utilize further
46//C- | modifications or combinations.
47//C- |
48//C- | The LIZARDTECH ORIGINAL CODE is provided "AS IS" WITHOUT WARRANTY
49//C- | OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
50//C- | TO ANY WARRANTY OF NON-INFRINGEMENT, OR ANY IMPLIED WARRANTY OF
51//C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
52//C- +------------------------------------------------------------------
53//
54// $Id: DjVmDoc.h,v 1.10 2005/05/25 20:24:52 leonb Exp $
55// $Name:  $
56
57#ifndef _DJVMDOC_H
58#define _DJVMDOC_H
59#ifdef HAVE_CONFIG_H
60#include "config.h"
61#endif
62#if NEED_GNUG_PRAGMAS
63# pragma interface
64#endif
65
66
67#include "DjVmDir.h"
68
69#ifdef HAVE_NAMESPACES
70namespace DJVU {
71# ifdef NOT_DEFINED // Just to fool emacs c++ mode
72}
73#endif
74#endif
75
76class ByteStream;
77class DataPool;
78class GURL;
79class GUTF8String;
80class DjVmNav;
81
82/** @name DjVmDoc.h
83    Files #"DjVmDoc.h"# and #"DjVmDoc.cpp"# contain implementation of the
84    \Ref{DjVmDoc} class used to read and write new DjVu multipage documents.
85
86    @memo DjVu multipage documents reader/writer.
87    @author Andrei Erofeev <eaf@geocities.com>
88    @version #$Id: DjVmDoc.h,v 1.10 2005/05/25 20:24:52 leonb Exp $#
89*/
90
91//@{
92
93/** Read/Write DjVu multipage documents.
94
95    The "new" DjVu multipage documents can be of two types: {\em bundled} and
96    {\em indirect}. In the first case all pages are packed into one file,
97    which is very like an archive internally. In the second case every page
98    is stored in a separate file. Plus there can be other components,
99    included into one or more pages, which also go into separate files. In
100    addition to pages and components, in the case of the {\em indirect} format
101    there is one more top-level file with the document directory (see
102    \Ref{DjVmDir}), which is basically an index file containing the
103    list of all files composing the document.
104
105    This class can read documents of both formats and can save them under any
106    format.  It is therefore ideal for converting between {\em bundled} and
107    {\em indirect} formats.  It cannot be used however for reading obsolete
108    formats.  The best way to convert obsolete formats consists in reading
109    them with class \Ref{DjVuDocument} class and saving them using
110    \Ref{DjVuDocument::write} or \Ref{DjVuDocument::expand}.
111
112    This class can also be used to create and modify multipage documents at
113    the low level without decoding every page or component (See
114    \Ref{insert_file}() and \Ref{delete_file}()).
115*/
116
117class DjVmDoc : public GPEnabled
118{
119      // Internal function.
120protected:   
121  DjVmDoc(void);
122  void init(void);
123public:
124      /// Creator
125   static GP<DjVmDoc> create(void);
126      /** Inserts a file into the document.
127          @param data  ByteStream containing the file data.
128          @param file_type Describes the type of the file to be inserted.
129                 See \Ref{DjVmDir::File} for details.
130          @param name  Name of the file in the document (e.g. an URL).
131          @param id    Identifier of the file (as used in INCL chunks).
132          @param title Optional title of the file (shown in browsers).
133          @param pos   Position of the file in the document (default is append).
134      */
135   void insert_file(
136     ByteStream &data, DjVmDir::File::FILE_TYPE file_type,
137     const GUTF8String &name, const GUTF8String &id,
138     const GUTF8String &title=GUTF8String(), int pos=-1 );
139      /** Inserts a file into the document.
140          @param pool  Data pool containing file data.
141          @param file_type Describes the type of the file to be inserted.
142                 See \Ref{DjVmDir::File} for details.
143          @param name  Name of the file in the document (e.g. an URL).
144          @param id    Identifier of the file (as used in INCL chunks).
145          @param title Optional title of the file (shown in browsers).
146          @param pos   Position of the file in the document (default is append).
147      */
148   void insert_file(
149     const GP<DataPool> &pool, DjVmDir::File::FILE_TYPE file_type,
150     const GUTF8String &name, const GUTF8String &id,
151     const GUTF8String &title=GUTF8String(), int pos=-1 );
152
153      /** Inserts a file described by \Ref{DjVmDir::File} structure with
154          data #data# at position #pos#. If #pos# is negative, the file
155          will be appended to the document. Otherwise it will be inserted
156          at position #pos#. */
157   void insert_file(const GP<DjVmDir::File> & f,
158                    GP<DataPool> data, int pos=-1);
159
160      /** Removes file with the specified #id# from the document. Every
161          file inside a new DjVu multipage document has its unique ID
162          (refer to \Ref{DjVmDir} for details), which is passed to this
163          function. */
164   void delete_file(const GUTF8String &id);
165
166     /** Set the bookmarks */
167   void set_djvm_nav(GP<DjVmNav> n);
168
169      /** Returns the directory of the DjVm document (the one which will
170          be encoded into #DJVM# chunk of the top-level file or the bundle). */
171   GP<DjVmDir>  get_djvm_dir(void);
172   
173      /** Returns contents of file with ID #id# from the document.
174          Please refer to \Ref{DjVmDir} for the explanation of what
175          IDs mean. */
176   GP<DataPool> get_data(const GUTF8String &id) const;
177
178      /** Reading routines */
179      //@{
180      /** Reads contents of a {\em bundled} multipage DjVu document from
181          the stream. */
182   void read(ByteStream & str);
183      /** Reads contents of a {\em bundled} multipage DjVu document from
184          the \Ref{DataPool}. */
185   void read(const GP<DataPool> & data_pool);
186      /** Reads the DjVu multipage document in either {\em bundled} or
187          {\em indirect} format.
188
189          {\bf Note:} For {\em bundled} documents the file is not
190          read into memory. We just open it and access data directly there.
191          Thus you should not modify the file contents.
192
193          @param name For {\em bundled} documents this is the name
194                 of the document. For {\em indirect} documents this is
195                 the name of the top-level file of the document (containing
196                 the \Ref{DjVmDir} with the list of all files).
197                 The rest of the files are expected to be in the
198                 same directory and will be read by this function as well. */
199   void read(const GURL &url);
200      //@}
201
202      /** Writing routines */
203      //@{
204      /** Writes the multipage DjVu document in the {\em bundled} format into
205          the stream. */
206   void write(const GP<ByteStream> &str);
207      /** Writes the multipage DjVu document in the {\em bundled} format into
208          the stream, reserving any of the specified names. */
209   void write(const GP<ByteStream> &str,
210              const GMap<GUTF8String,void *>& reserved);
211      /** Stored index (top-level) file of the DjVu document in the {\em
212          indirect} format into the specified stream. */
213   void write_index(const GP<ByteStream> &str);
214      /** Writes the multipage DjVu document in the {\em indirect} format
215          into the given directory. Every page and included file will be
216          stored as a separate file. Besides, one top-level file with
217          the document directory (named #idx_name#) will be created unless
218          #idx_name# is empty.
219
220          @param dir_name Name of the directory where files should be
221                 created
222          @param idx_name Name of the top-level file with the \Ref{DjVmDir}
223                 with the list of files composing the given document.
224                 If empty, the file will not be created. */
225   void expand(const GURL &codebase, const GUTF8String &idx_name);
226
227      /** Writes an individual file, and all included files.
228          INCL chunks will be remapped as appropriate. */
229   void save_page(const GURL &codebase, const DjVmDir::File &file) const;
230
231      /** Writes an individual file if not mapped, and all included files.
232          INCL chunks will be remapped as appropriate.  All pages saved
233          are added to the #incl# map. */
234   void save_page(const GURL &codebase, const DjVmDir::File &file,
235                  GMap<GUTF8String,GUTF8String> &incl) const;
236
237      /** Writes an individual file specified, remapping INCL chunks as
238          appropriate.  Included files will not be saved. */
239   void save_file(const GURL &codebase, const DjVmDir::File &file) const;
240
241      /** Writes the specified file from the given #pool#. */
242   GUTF8String save_file(const GURL &codebase, const DjVmDir::File &file,
243                         GMap<GUTF8String,GUTF8String> &incl, 
244                         const GP<DataPool> &pool) const;
245  //@}
246private:
247   void save_file(const GURL &codebase, const DjVmDir::File &file,
248                  GMap<GUTF8String,GUTF8String> *incl) const;
249   GP<DjVmDir> dir;
250   GP<DjVmNav> nav;
251   GPMap<GUTF8String, DataPool > data;
252private: // dummy stuff
253   static void write(ByteStream *);
254   static void write_index(ByteStream *);
255};
256
257inline GP<DjVmDir>
258DjVmDoc::get_djvm_dir(void)
259{
260   return dir;
261}
262
263
264//@}
265
266
267
268#ifdef HAVE_NAMESPACES
269}
270# ifndef NOT_USING_DJVU_NAMESPACE
271using namespace DJVU;
272# endif
273#endif
274#endif
Note: See TracBrowser for help on using the repository browser.