Blame libdjvu/DjVuAnno.h

Packit df99a1
//C-  -*- C++ -*-
Packit df99a1
//C- -------------------------------------------------------------------
Packit df99a1
//C- DjVuLibre-3.5
Packit df99a1
//C- Copyright (c) 2002  Leon Bottou and Yann Le Cun.
Packit df99a1
//C- Copyright (c) 2001  AT&T
Packit df99a1
//C-
Packit df99a1
//C- This software is subject to, and may be distributed under, the
Packit df99a1
//C- GNU General Public License, either Version 2 of the license,
Packit df99a1
//C- or (at your option) any later version. The license should have
Packit df99a1
//C- accompanied the software or you may obtain a copy of the license
Packit df99a1
//C- from the Free Software Foundation at http://www.fsf.org .
Packit df99a1
//C-
Packit df99a1
//C- This program is distributed in the hope that it will be useful,
Packit df99a1
//C- but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit df99a1
//C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit df99a1
//C- GNU General Public License for more details.
Packit df99a1
//C- 
Packit df99a1
//C- DjVuLibre-3.5 is derived from the DjVu(r) Reference Library from
Packit df99a1
//C- Lizardtech Software.  Lizardtech Software has authorized us to
Packit df99a1
//C- replace the original DjVu(r) Reference Library notice by the following
Packit df99a1
//C- text (see doc/lizard2002.djvu and doc/lizardtech2007.djvu):
Packit df99a1
//C-
Packit df99a1
//C-  ------------------------------------------------------------------
Packit df99a1
//C- | DjVu (r) Reference Library (v. 3.5)
Packit df99a1
//C- | Copyright (c) 1999-2001 LizardTech, Inc. All Rights Reserved.
Packit df99a1
//C- | The DjVu Reference Library is protected by U.S. Pat. No.
Packit df99a1
//C- | 6,058,214 and patents pending.
Packit df99a1
//C- |
Packit df99a1
//C- | This software is subject to, and may be distributed under, the
Packit df99a1
//C- | GNU General Public License, either Version 2 of the license,
Packit df99a1
//C- | or (at your option) any later version. The license should have
Packit df99a1
//C- | accompanied the software or you may obtain a copy of the license
Packit df99a1
//C- | from the Free Software Foundation at http://www.fsf.org .
Packit df99a1
//C- |
Packit df99a1
//C- | The computer code originally released by LizardTech under this
Packit df99a1
//C- | license and unmodified by other parties is deemed "the LIZARDTECH
Packit df99a1
//C- | ORIGINAL CODE."  Subject to any third party intellectual property
Packit df99a1
//C- | claims, LizardTech grants recipient a worldwide, royalty-free, 
Packit df99a1
//C- | non-exclusive license to make, use, sell, or otherwise dispose of 
Packit df99a1
//C- | the LIZARDTECH ORIGINAL CODE or of programs derived from the 
Packit df99a1
//C- | LIZARDTECH ORIGINAL CODE in compliance with the terms of the GNU 
Packit df99a1
//C- | General Public License.   This grant only confers the right to 
Packit df99a1
//C- | infringe patent claims underlying the LIZARDTECH ORIGINAL CODE to 
Packit df99a1
//C- | the extent such infringement is reasonably necessary to enable 
Packit df99a1
//C- | recipient to make, have made, practice, sell, or otherwise dispose 
Packit df99a1
//C- | of the LIZARDTECH ORIGINAL CODE (or portions thereof) and not to 
Packit df99a1
//C- | any greater extent that may be necessary to utilize further 
Packit df99a1
//C- | modifications or combinations.
Packit df99a1
//C- |
Packit df99a1
//C- | The LIZARDTECH ORIGINAL CODE is provided "AS IS" WITHOUT WARRANTY
Packit df99a1
//C- | OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
Packit df99a1
//C- | TO ANY WARRANTY OF NON-INFRINGEMENT, OR ANY IMPLIED WARRANTY OF
Packit df99a1
//C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
Packit df99a1
//C- +------------------------------------------------------------------
Packit df99a1
Packit df99a1
#ifndef _DJVUANNO_H
Packit df99a1
#define _DJVUANNO_H
Packit df99a1
#ifdef HAVE_CONFIG_H
Packit df99a1
#include "config.h"
Packit df99a1
#endif
Packit df99a1
#if NEED_GNUG_PRAGMAS
Packit df99a1
# pragma interface
Packit df99a1
#endif
Packit df99a1
Packit df99a1
Packit df99a1
Packit df99a1
/** @name DjVuAnno.h
Packit df99a1
Packit df99a1
    Files #"DjVuAnno.h"# and #"DjVuAnno.cpp"# implement the mechanism for
Packit df99a1
    annotating DjVuImages. Annotations are additional instructions for the
Packit df99a1
    plugin about how the image should be displayed.  The exact format of
Packit df99a1
    annotations is not strictly defined. The only requirement is that they
Packit df99a1
    have to be stored as a sequence of chunks inside a #FORM:ANNO#.
Packit df99a1
Packit df99a1
    This file implements annotations understood by the DjVu plugins 
Packit df99a1
    and encoders.
Packit df99a1
Packit df99a1
Packit df99a1
    using: contents of #ANT*# chunks.
Packit df99a1
Packit df99a1
    Contents of the #FORM:ANNO# should be passed to \Ref{DjVuAnno::decode}()
Packit df99a1
    for parsing, which initializes \Ref{DjVuAnno::ANT} 
Packit df99a1
    and fills them with decoded data. 
Packit df99a1
    @memo Implements support for DjVuImage annotations
Packit df99a1
    @author Andrei Erofeev <eaf@geocities.com>
Packit df99a1
*/
Packit df99a1
//@{
Packit df99a1
Packit df99a1
Packit df99a1
#include "GString.h"
Packit df99a1
Packit df99a1
#ifdef HAVE_NAMESPACES
Packit df99a1
namespace DJVU {
Packit df99a1
# ifdef NOT_DEFINED // Just to fool emacs c++ mode
Packit df99a1
}
Packit df99a1
#endif
Packit df99a1
#endif
Packit df99a1
Packit df99a1
class GMapArea;
Packit df99a1
class ByteStream;
Packit df99a1
Packit df99a1
// -------- DJVUANT --------
Packit df99a1
Packit df99a1
/** This class contains some trivial annotations of the page or of the
Packit df99a1
    document such as page border color, page alignment, initial zoom and
Packit df99a1
    display mode, hyperlinks and highlighted areas.  All this information is
Packit df99a1
    put inside a textual chunk #ANTa# in pseudo-lisp format. Decoding and
Packit df99a1
    encoding are normally done by \Ref{DjVuANT::decode}() and
Packit df99a1
    \Ref{DjVuANT::encode}() functions. */
Packit df99a1
Packit df99a1
class DJVUAPI DjVuANT : public GPEnabled
Packit df99a1
{
Packit df99a1
protected:
Packit df99a1
      /// Constructs an empty annotation object.
Packit df99a1
   DjVuANT(void);
Packit df99a1
Packit df99a1
public:
Packit df99a1
   enum { MODE_UNSPEC=0, MODE_COLOR, MODE_FORE, MODE_BACK, MODE_BW };
Packit df99a1
   enum { ZOOM_STRETCH=-4, ZOOM_ONE2ONE=-3, ZOOM_WIDTH=-2,
Packit df99a1
	  ZOOM_PAGE=-1, ZOOM_UNSPEC=0 };
Packit df99a1
   enum alignment { ALIGN_UNSPEC=0, ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT,
Packit df99a1
	  ALIGN_TOP, ALIGN_BOTTOM };
Packit df99a1
Packit df99a1
      /// Creates an empty annotation object.
Packit df99a1
   static GP<DjVuANT> create(void) { return new DjVuANT; }
Packit df99a1
   virtual ~DjVuANT();
Packit df99a1
Packit df99a1
      /** Background color. Is in #0x00RRBBGG# format. #0xffffffff# if
Packit df99a1
	  there were no background color records in the annotation chunk. */
Packit df99a1
   unsigned long int	bg_color;
Packit df99a1
      /** Initial zoom. Possible values are:
Packit df99a1
	  \begin{description}
Packit df99a1
          \item[ZOOM_STRETCH] the image is stretched to the viewport.
Packit df99a1
          \item[ZOOM_ONE2ONE] the image is displayed pixel-to-pixel.
Packit df99a1
          \item[ZOOM_WIDTH] "Fit width" mode.
Packit df99a1
          \item[ZOOM_PAGE] "Fit page" mode.
Packit df99a1
          \item[ZOOM_UNSPEC] Annotation does not specify a zoom factor.
Packit df99a1
          \end{description} */
Packit df99a1
   int		zoom;
Packit df99a1
      /** Initial mode. Possible values are:
Packit df99a1
	  \begin{description}
Packit df99a1
             \item[MODE_COLOR] color mode.
Packit df99a1
             \item[MODE_FORE] foreground mode.
Packit df99a1
             \item[MODE_BACK] background mode.
Packit df99a1
             \item[MODE_BW] black and white mode.
Packit df99a1
             \item[MODE_UNSPEC] Annotation does not specify a display mode.
Packit df99a1
	     \item[Any positive number] Zoom in \%. Please note that
Packit df99a1
                   all constants above are either negative or ZERO. Thus
Packit df99a1
                   it's possible to distinguish numerical zoom from those
Packit df99a1
                   special cases.
Packit df99a1
          \end{description} */
Packit df99a1
   int		mode;
Packit df99a1
      /** Horizontal page alignment. Possible values are #ALIGN_LEFT#,
Packit df99a1
	  #ALIGN_CENTER#, #ALIGN_RIGHT# and #ALIGN_UNSPEC#. */
Packit df99a1
   alignment hor_align;
Packit df99a1
      /** Vertical page alignment. Possible values are #ALIGN_TOP#,
Packit df99a1
	  #ALIGN_CENTER#, #ALIGN_BOTTOM# and #ALIGN_UNSPEC#. */
Packit df99a1
   alignment ver_align;
Packit df99a1
      /** List of defined map areas. They may be just areas of highlighting
Packit df99a1
	  or hyperlink. Please refer to \Ref{GMapArea}, \Ref{GMapRect},
Packit df99a1
	  \Ref{GMapPoly} and \Ref{GMapOval} for details. */
Packit df99a1
   GPList<GMapArea> map_areas;
Packit df99a1
      /** Metainformations like title, author ... */
Packit df99a1
   GMap<GUTF8String,GUTF8String> metadata;
Packit df99a1
      /** Metainformations like title, author ... */
Packit df99a1
   GUTF8String xmpmetadata;
Packit df99a1
      /** Returns TRUE if no features are specified or specified features
Packit df99a1
         are not different from default ones */
Packit df99a1
   bool	is_empty(void) const;
Packit df99a1
Packit df99a1
      /** Decodes contents of annotation chunk #ANTa#. The chunk data is
Packit df99a1
	  read from ByteStream #bs# until reaching an end-of-stream marker.
Packit df99a1
	  This function is normally called after a call to
Packit df99a1
	  \Ref{IFFByteStream::get_chunk}(). */
Packit df99a1
   void	decode(ByteStream &bs);
Packit df99a1
Packit df99a1
      /** Same as \Ref{decode}() but adds the new data to what has
Packit df99a1
	  been decoded before. */
Packit df99a1
   void merge(ByteStream & bs);
Packit df99a1
Packit df99a1
      /** Encodes the #ANTa# chunk. The annotation data is simply written
Packit df99a1
	  into ByteStream #bs# with no IFF header. This function is normally
Packit df99a1
	  called after a call to \Ref{IFFByteStream::put_chunk}(). */
Packit df99a1
   void encode(ByteStream &bs);
Packit df99a1
Packit df99a1
      /// Encodes data back into raw annotation data.
Packit df99a1
   GUTF8String encode_raw(void) const;
Packit df99a1
Packit df99a1
      /// Returns a copy of this object
Packit df99a1
   GP<DjVuANT>	copy(void) const;
Packit df99a1
   
Packit df99a1
      /** Returns the number of bytes needed by this data structure. It's
Packit df99a1
	  used by caching routines to estimate the size of a \Ref{DjVuImage}. */
Packit df99a1
   unsigned int get_memory_usage() const;
Packit df99a1
Packit df99a1
      /// Converts color from string in \#RRGGBB notation to an unsigned integer
Packit df99a1
   static unsigned long int	cvt_color(const char * color, unsigned long int def);
Packit df99a1
      /// Obtain the <MAP></MAP> tag for these annotations.
Packit df99a1
   GUTF8String get_xmlmap(const GUTF8String &name, const int height) const;
Packit df99a1
      /// Write the <MAP></MAP> tag for these annotations.
Packit df99a1
   void writeMap(
Packit df99a1
     ByteStream &bs,const GUTF8String &name, const int height) const;
Packit df99a1
      /// Obtain the XML flags for the default specifications.
Packit df99a1
   GUTF8String get_paramtags(void) const;
Packit df99a1
      /// Write the XML flags for the default specifications.
Packit df99a1
   void writeParam(ByteStream &out_str) const;
Packit df99a1
private:
Packit df99a1
   void	decode(class GLParser & parser);
Packit df99a1
   static GUTF8String read_raw(ByteStream & str);
Packit df99a1
   static unsigned char	decode_comp(char ch1, char ch2);
Packit df99a1
   static unsigned long int get_bg_color(class GLParser & parser);
Packit df99a1
   static int get_zoom(class GLParser & parser);
Packit df99a1
   static int get_mode(class GLParser & parser);
Packit df99a1
   static alignment get_hor_align(class GLParser & parser);
Packit df99a1
   static alignment get_ver_align(class GLParser & parser);
Packit df99a1
   static GPList<GMapArea> get_map_areas(class GLParser & parser);
Packit df99a1
   static GMap<GUTF8String, GUTF8String>get_metadata(GLParser & parser);
Packit df99a1
   static GUTF8String get_xmpmetadata(GLParser & parser);
Packit df99a1
   static void del_all_items(const char * name, class GLParser & parser);
Packit df99a1
};
Packit df99a1
Packit df99a1
// -------- DJVUANNO --------
Packit df99a1
Packit df99a1
Packit df99a1
/** This is a top-level class containing annotations of a DjVu document (or
Packit df99a1
    just a page). It has only two functions: \Ref{encode}() and
Packit df99a1
    \Ref{decode}().  Both of them work with a sequence of annotation chunks
Packit df99a1
    from #FORM:ANNO# form. Basing on the name of the chunks they call
Packit df99a1
    #encode()# and #decode()# functions of the proper annotation structure
Packit df99a1
    (like \Ref{ANT}). The real work of encoding and decoding is done by
Packit df99a1
    lower-level classes. */
Packit df99a1
class DJVUAPI DjVuAnno : public GPEnabled
Packit df99a1
{
Packit df99a1
protected:
Packit df99a1
   DjVuAnno(void) {}
Packit df99a1
public:
Packit df99a1
   /// Creation method.
Packit df99a1
   static GP<DjVuAnno> create(void) { return new DjVuAnno; }
Packit df99a1
Packit df99a1
   GP<DjVuANT>	ant;
Packit df99a1
Packit df99a1
      /** Decodes a sequence of annotation chunks and merges contents of every
Packit df99a1
	  chunk with previously decoded information. This function
Packit df99a1
	  should be called right after applying \Ref{IFFByteStream::get_chunk}()
Packit df99a1
	  to data from #FORM:ANNO#. */
Packit df99a1
   void decode(const GP<ByteStream> &bs);
Packit df99a1
Packit df99a1
      /** Encodes all annotations back into a sequence of chunks to be put
Packit df99a1
	  inside a #FORM:ANNO#. */
Packit df99a1
   void	encode(const GP<ByteStream> &bs);
Packit df99a1
Packit df99a1
      /// Returns a copy of this object
Packit df99a1
   GP<DjVuAnno>	copy(void) const;
Packit df99a1
Packit df99a1
      /** Merged the contents of this class and of annotations
Packit df99a1
	  pointed by #anno# pointer */
Packit df99a1
   void		merge(const GP<DjVuAnno> & anno);
Packit df99a1
Packit df99a1
      /** Returns the number of bytes needed by this data structure. It's
Packit df99a1
	  used by caching routines to estimate the size of a \Ref{DjVuImage}. */
Packit df99a1
   inline unsigned int get_memory_usage() const;
Packit df99a1
      /// Obtain the <MAP></MAP> tag for these annotations.
Packit df99a1
   GUTF8String get_xmlmap(const GUTF8String &name, const int height) const;
Packit df99a1
      /// Write the <MAP></MAP> tag for these annotations.
Packit df99a1
   void writeMap(
Packit df99a1
     ByteStream &bs,const GUTF8String &name, const int height) const;
Packit df99a1
      /// Obtain the XML flags for the default specifications.
Packit df99a1
   GUTF8String get_paramtags(void) const;
Packit df99a1
      /// Write the XML flags for the default specifications.
Packit df99a1
   void writeParam(ByteStream &out_str) const;
Packit df99a1
private: // dummy stuff
Packit df99a1
   static void decode(ByteStream *);
Packit df99a1
   static void encode(ByteStream *);
Packit df99a1
};
Packit df99a1
Packit df99a1
//@}
Packit df99a1
Packit df99a1
inline unsigned int 
Packit df99a1
DjVuAnno::get_memory_usage() const
Packit df99a1
{
Packit df99a1
  return (ant)?(ant->get_memory_usage()):0;
Packit df99a1
}
Packit df99a1
Packit df99a1
// ----- THE END
Packit df99a1
Packit df99a1
#ifdef HAVE_NAMESPACES
Packit df99a1
}
Packit df99a1
# ifndef NOT_USING_DJVU_NAMESPACE
Packit df99a1
using namespace DJVU;
Packit df99a1
# endif
Packit df99a1
#endif
Packit df99a1
#endif