source: trunk/libdjvu/DjVmDoc.h @ 206

Last change on this file since 206 was 206, checked in by Eugene Romanenko, 14 years ago

DJVU plugin: djvulibre updated to version 3.5.19

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