source: trunk/libdjvu/DjVuAnno.h @ 101

Last change on this file since 101 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.9 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: DjVuAnno.h,v 1.8 2003/11/07 22:08:20 leonb Exp $
55// $Name:  $
56
57#ifndef _DJVUANNO_H
58#define _DJVUANNO_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
68/** @name DjVuAnno.h
69
70    Files #"DjVuAnno.h"# and #"DjVuAnno.cpp"# implement the mechanism for
71    annotating DjVuImages. Annotations are additional instructions for the
72    plugin about how the image should be displayed.  The exact format of
73    annotations is not strictly defined. The only requirement is that they
74    have to be stored as a sequence of chunks inside a #FORM:ANNO#.
75
76    This file implements annotations understood by the DjVu plugins
77    and encoders.
78
79
80    using: contents of #ANT*# chunks.
81
82    Contents of the #FORM:ANNO# should be passed to \Ref{DjVuAnno::decode}()
83    for parsing, which initializes \Ref{DjVuAnno::ANT}
84    and fills them with decoded data.
85    @memo Implements support for DjVuImage annotations
86    @author Andrei Erofeev <eaf@geocities.com>
87    @version
88    #$Id: DjVuAnno.h,v 1.8 2003/11/07 22:08:20 leonb Exp $# */
89//@{
90
91
92#include "GString.h"
93
94#ifdef HAVE_NAMESPACES
95namespace DJVU {
96# ifdef NOT_DEFINED // Just to fool emacs c++ mode
97}
98#endif
99#endif
100
101class GMapArea;
102class ByteStream;
103
104// -------- DJVUANT --------
105
106/** This class contains some trivial annotations of the page or of the
107    document such as page border color, page alignment, initial zoom and
108    display mode, hyperlinks and highlighted areas.  All this information is
109    put inside a textual chunk #ANTa# in pseudo-lisp format. Decoding and
110    encoding are normally done by \Ref{DjVuANT::decode}() and
111    \Ref{DjVuANT::encode}() functions. */
112
113class DjVuANT : public GPEnabled
114{
115protected:
116      /// Constructs an empty annotation object.
117   DjVuANT(void);
118
119public:
120   enum { MODE_UNSPEC=0, MODE_COLOR, MODE_FORE, MODE_BACK, MODE_BW };
121   enum { ZOOM_STRETCH=-4, ZOOM_ONE2ONE=-3, ZOOM_WIDTH=-2,
122          ZOOM_PAGE=-1, ZOOM_UNSPEC=0 };
123   enum alignment { ALIGN_UNSPEC=0, ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT,
124          ALIGN_TOP, ALIGN_BOTTOM };
125
126      /// Creates an empty annotation object.
127   static GP<DjVuANT> create(void) { return new DjVuANT; }
128   virtual ~DjVuANT();
129
130      /** Background color. Is in #0x00RRBBGG# format. #0xffffffff# if
131          there were no background color records in the annotation chunk. */
132   unsigned long int    bg_color;
133      /** Initial zoom. Possible values are:
134          \begin{description}
135          \item[ZOOM_STRETCH] the image is stretched to the viewport.
136          \item[ZOOM_ONE2ONE] the image is displayed pixel-to-pixel.
137          \item[ZOOM_WIDTH] "Fit width" mode.
138          \item[ZOOM_PAGE] "Fit page" mode.
139          \item[ZOOM_UNSPEC] Annotation does not specify a zoom factor.
140          \end{description} */
141   int          zoom;
142      /** Initial mode. Possible values are:
143          \begin{description}
144             \item[MODE_COLOR] color mode.
145             \item[MODE_FORE] foreground mode.
146             \item[MODE_BACK] background mode.
147             \item[MODE_BW] black and white mode.
148             \item[MODE_UNSPEC] Annotation does not specify a display mode.
149             \item[Any positive number] Zoom in \%. Please note that
150                   all constants above are either negative or ZERO. Thus
151                   it's possible to distinguish numerical zoom from those
152                   special cases.
153          \end{description} */
154   int          mode;
155      /** Horizontal page alignment. Possible values are #ALIGN_LEFT#,
156          #ALIGN_CENTER#, #ALIGN_RIGHT# and #ALIGN_UNSPEC#. */
157   alignment hor_align;
158      /** Vertical page alignment. Possible values are #ALIGN_TOP#,
159          #ALIGN_CENTER#, #ALIGN_BOTTOM# and #ALIGN_UNSPEC#. */
160   alignment ver_align;
161      /** List of defined map areas. They may be just areas of highlighting
162          or hyperlink. Please refer to \Ref{GMapArea}, \Ref{GMapRect},
163          \Ref{GMapPoly} and \Ref{GMapOval} for details. */
164   GPList<GMapArea>     map_areas;
165#ifndef NO_METADATA_IN_ANT_CHUNK
166      /** Metainformations like title, author ... */
167   GMap<GUTF8String,GUTF8String> metadata;
168#endif
169      /** Returns TRUE if no features are specified or specified features
170          are not different from default ones */
171   bool         is_empty(void) const;
172
173      /** Decodes contents of annotation chunk #ANTa#. The chunk data is
174          read from ByteStream #bs# until reaching an end-of-stream marker.
175          This function is normally called after a call to
176          \Ref{IFFByteStream::get_chunk}(). */
177   void decode(ByteStream &bs);
178
179      /** Same as \Ref{decode}() but adds the new data to what has
180          been decoded before. */
181   void merge(ByteStream & bs);
182
183      /** Encodes the #ANTa# chunk. The annotation data is simply written
184          into ByteStream #bs# with no IFF header. This function is normally
185          called after a call to \Ref{IFFByteStream::put_chunk}(). */
186   void encode(ByteStream &bs);
187
188      /// Encodes data back into raw annotation data.
189   GUTF8String encode_raw(void) const;
190
191      /// Returns a copy of this object
192   GP<DjVuANT>  copy(void) const;
193   
194      /** Returns the number of bytes needed by this data structure. It's
195          used by caching routines to estimate the size of a \Ref{DjVuImage}. */
196   unsigned int get_memory_usage() const;
197
198      /// Converts color from string in \#RRGGBB notation to an unsigned integer
199   static unsigned long int     cvt_color(const char * color, unsigned long int def);
200      /// Obtain the <MAP></MAP> tag for these annotations.
201   GUTF8String get_xmlmap(const GUTF8String &name, const int height) const;
202      /// Write the <MAP></MAP> tag for these annotations.
203   void writeMap(
204     ByteStream &bs,const GUTF8String &name, const int height) const;
205      /// Obtain the XML flags for the default specifications.
206   GUTF8String get_paramtags(void) const;
207      /// Write the XML flags for the default specifications.
208   void writeParam(ByteStream &out_str) const;
209private:
210   void decode(class GLParser & parser);
211   static GUTF8String read_raw(ByteStream & str);
212   static unsigned char decode_comp(char ch1, char ch2);
213   static unsigned long int get_bg_color(class GLParser & parser);
214   static int get_zoom(class GLParser & parser);
215   static int get_mode(class GLParser & parser);
216   static alignment get_hor_align(class GLParser & parser);
217   static alignment get_ver_align(class GLParser & parser);
218   static GPList<GMapArea> get_map_areas(class GLParser & parser);
219#ifndef NO_METADATA_IN_ANT_CHUNK
220   static GMap<GUTF8String, GUTF8String>get_metadata(GLParser & parser);
221#endif
222   static void del_all_items(const char * name, class GLParser & parser);
223};
224
225// -------- DJVUANNO --------
226
227
228/** This is a top-level class containing annotations of a DjVu document (or
229    just a page). It has only two functions: \Ref{encode}() and
230    \Ref{decode}().  Both of them work with a sequence of annotation chunks
231    from #FORM:ANNO# form. Basing on the name of the chunks they call
232    #encode()# and #decode()# functions of the proper annotation structure
233    (like \Ref{ANT}). The real work of encoding and decoding is done by
234    lower-level classes. */
235class DjVuAnno : public GPEnabled
236{
237protected:
238   DjVuAnno(void) {}
239public:
240   /// Creation method.
241   static GP<DjVuAnno> create(void) { return new DjVuAnno; }
242
243   GP<DjVuANT>  ant;
244
245      /** Decodes a sequence of annotation chunks and merges contents of every
246          chunk with previously decoded information. This function
247          should be called right after applying \Ref{IFFByteStream::get_chunk}()
248          to data from #FORM:ANNO#. */
249   void decode(const GP<ByteStream> &bs);
250
251      /** Encodes all annotations back into a sequence of chunks to be put
252          inside a #FORM:ANNO#. */
253   void encode(const GP<ByteStream> &bs);
254
255      /// Returns a copy of this object
256   GP<DjVuAnno> copy(void) const;
257
258      /** Merged the contents of this class and of annotations
259          pointed by #anno# pointer */
260   void         merge(const GP<DjVuAnno> & anno);
261
262      /** Returns the number of bytes needed by this data structure. It's
263          used by caching routines to estimate the size of a \Ref{DjVuImage}. */
264   inline unsigned int get_memory_usage() const;
265      /// Obtain the <MAP></MAP> tag for these annotations.
266   GUTF8String get_xmlmap(const GUTF8String &name, const int height) const;
267      /// Write the <MAP></MAP> tag for these annotations.
268   void writeMap(
269     ByteStream &bs,const GUTF8String &name, const int height) const;
270      /// Obtain the XML flags for the default specifications.
271   GUTF8String get_paramtags(void) const;
272      /// Write the XML flags for the default specifications.
273   void writeParam(ByteStream &out_str) const;
274private: // dummy stuff
275   static void decode(ByteStream *);
276   static void encode(ByteStream *);
277};
278
279//@}
280
281inline unsigned int 
282DjVuAnno::get_memory_usage() const
283{
284  return (ant)?(ant->get_memory_usage()):0;
285}
286
287// ----- THE END
288
289#ifdef HAVE_NAMESPACES
290}
291# ifndef NOT_USING_DJVU_NAMESPACE
292using namespace DJVU;
293# endif
294#endif
295#endif
Note: See TracBrowser for help on using the repository browser.