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