source: trunk/libdjvu/DjVuNavDir.h @ 81

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

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

File size: 7.7 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: DjVuNavDir.h,v 1.8 2003/11/07 22:08:21 leonb Exp $
55// $Name:  $
56
57#ifndef _DJVUNAVDIR_H
58#define _DJVUNAVDIR_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 "GString.h"
68#include "GThreads.h"
69#include "GURL.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;
79
80/** @name DjVuNavDir.h
81    Files #"DjVuNavDir.h"# and #"DjVuNavDir.cpp"# contain implementation of the
82    multipage DjVu navigation directory. This directory lists all the pages,
83    that a given document is composed of. The navigation (switching from page
84    to page in the plugin) is not possible before this directory is decoded.
85
86    Refer to the \Ref{DjVuNavDir} class description for greater details.
87
88    @memo DjVu Navigation Directory
89    @author Andrei Erofeev <eaf@geocities.com>
90    @version #$Id: DjVuNavDir.h,v 1.8 2003/11/07 22:08:21 leonb Exp $#
91*/
92
93//@{
94
95//*****************************************************************************
96//********************* Note: this class is thread-safe ***********************
97//*****************************************************************************
98
99/** DjVu Navigation Directory.
100
101    This class implements the {\em navigation directory} of a multipage
102    DjVu document - basically a list of pages that this document is composed
103    of. We would like to emphasize, that this is the list of namely
104    {\bf pages}, not {\bf files}. Any page may include any
105    number of additional files. When you've got an all-in-one-file multipage
106    DjVu document (DjVm archive) you may get the files list from \Ref{DjVmDir0}
107    class.
108
109    The \Ref{DjVuNavDir} class can decode and encode the navigation directory
110    from {\bf NDIR} IFF chunk. It's normally created by the library during
111    decoding procedure and can be accessed like any other component of
112    the \Ref{DjVuImage} being decoded.
113   
114    In a typical multipage DjVu document the navigation directory is stored
115    in a separate IFF file containing only one chunk: {\bf NDIR} chunk.
116    This file should be included (by means of the {\bf INCL} chunk) into
117    every page of the document to enable the navigation. */
118class DjVuNavDir : public GPEnabled
119{
120private:
121   GCriticalSection             lock;
122   GURL                         baseURL;
123   GArray<GUTF8String>          page2name;
124   GMap<GUTF8String, int>               name2page;
125   GMap<GURL, int>              url2page;
126protected:
127   DjVuNavDir(const GURL &dir_url);
128   DjVuNavDir(ByteStream & str, const GURL &dir_url);
129
130public:
131   int          get_memory_usage(void) const { return 1024; };
132
133      /** Creates a #DjVuNavDir# object. #dir_url# is the URL of the file
134          containing the directory source data. It will be used later
135          in translation by functions like \Ref{url_to_page}() and
136          \Ref{page_to_url}() */
137   static GP<DjVuNavDir> create(const GURL &dir_url)
138   {return new DjVuNavDir(dir_url);}
139
140      /** Creates #DjVuNavDir# object by decoding its contents from
141          the stream. #dir_url# is the URL of the file containing the
142          directory source data. */
143   static GP<DjVuNavDir> create(ByteStream & str, const GURL &dir_url)
144   { return new DjVuNavDir(str,dir_url); }
145
146   virtual ~DjVuNavDir(void) {};
147
148      /// Decodes the directory contents from the given \Ref{ByteStream}
149   void         decode(ByteStream & str);
150
151      /// Encodes the directory contents into the given \Ref{ByteStream}
152   void         encode(ByteStream & str);
153
154      /** Inserts a new page at position #where# pointing to a file
155          with name #name#.
156
157          @param where The position where the page should be inserted.
158                 #-1# means to append.
159          @param name The name of the file corresponding to this page.
160                 The name may not contain slashes. The file may include
161                 other files. */
162   void         insert_page(int where, const char * name);
163
164      /// Deletes page with number #page_num# from the directory.
165   void         delete_page(int page_num);
166
167      /// Returns the number of pages in the directory.
168   int          get_pages_num(void) const;
169      /** Converts the #url# to page number. Returns #-1# if the #url#
170          does not correspond to anything in the directory. */
171   int          url_to_page(const GURL & url) const;
172      /** Converts file name #name# to page number. Returns #-1# if file
173          with given name cannot be found. */
174   int          name_to_page(const char * name) const;
175      /** Converts given #page# to URL. Throws an exception if page number
176          is invalid. */
177   GURL         page_to_url(int page) const;
178      /** Converts given #page# to URL. Throws an exception if page number
179          is invalid. */
180   GUTF8String  page_to_name(int page) const;
181};
182
183//@}
184
185
186#ifdef HAVE_NAMESPACES
187}
188# ifndef NOT_USING_DJVU_NAMESPACE
189using namespace DJVU;
190# endif
191#endif
192#endif
Note: See TracBrowser for help on using the repository browser.