source: trunk/libdjvu/DjVuAnno.h @ 280

Last change on this file since 280 was 280, checked in by rbri, 11 years ago

DJVU plugin: djvulibre updated to version 3.5.22

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