source: trunk/libdjvu/GMapAreas.h @ 15

Last change on this file since 15 was 15, checked in by Eugene Romanenko, 15 years ago

needed libs update

File size: 20.8 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: GMapAreas.h,v 1.8 2003/11/07 22:08:21 leonb Exp $
55// $Name: release_3_5_16 $
56
57#ifndef _GMAPAREAS_H
58#define _GMAPAREAS_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 "GSmartPointer.h"
68#include "GContainer.h"
69#include "GString.h"
70#include "GRect.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
80
81/** @name GMapAreas.h
82
83    Files #"GMapAreas.h"# and #"GMapAreas.cpp"# implement base objects
84    used by the plugin to display and manage hyperlinks and highlighted
85    areas inside a \Ref{DjVuImage} page.
86
87    The currently supported areas can be rectangular (\Ref{GMapRect}),
88    elliptical (\Ref{GMapOval}) and polygonal (\Ref{GMapPoly}). Every
89    map area besides the definition of its shape contains information
90    about display style and optional {\bf URL}, which it may refer to.
91    If this {\bf URL} is not empty then the map area will work like a
92    hyperlink.
93
94    The classes also implement some useful functions to ease geometry
95    manipulations
96
97    @memo Definition of base map area classes
98    @author Andrei Erofeev <eaf@geocities.com>
99    @version
100    #$Id: GMapAreas.h,v 1.8 2003/11/07 22:08:21 leonb Exp $# */
101//@{
102
103
104// ---------- GMAPAREA ---------
105
106/** This is the base object for all map areas. It defines some standard
107    interface to access the geometrical properties of the areas and
108    describes the area itsef:
109    \begin{itemize}
110       \item #url# If the optional #URL# is specified, the map area will
111             also work as a hyperlink meaning that if you click it with
112             your mouse pointer, the browser will be advised to load
113             the page referenced by the #URL#.
114       \item #target# Defines where the specified #URL# should be loaded
115       \item #comment# This is a string displayed in a status line or in
116             a popup window when the mouse pointer moves over the hyperlink
117             area
118       \item #border_type#, #border_color# and #border_width# describes
119             how the area border should be drawn
120       \item #area_color# describes how the area should be highlighted.
121    \end{itemize}
122
123    The map areas can be displayed using two different techniques, which
124    can be combined together:
125    \begin{itemize}
126       \item Visible border. The border of a map area can be drawn in several
127             different ways (like #XOR_BORDER# or #SHADOW_IN_BORDER#).
128             It can be made always visible, or appearing only when the
129             mouse pointer moves over the map area.
130       \item Highlighted contents. Contents of rectangular map areas can
131             also be highlighted with some given color.
132    \end{itemize}
133*/
134
135class GMapArea : public GPEnabled
136{
137protected:
138   GMapArea(void);
139public:
140//      // Default creator.
141//   static GP<GMapArea> create(void) {return new GMapArea();}
142
143      /// Virtual destructor.
144   virtual ~GMapArea();
145
146   static const char MAPAREA_TAG [];
147   static const char RECT_TAG [];
148   static const char POLY_TAG [];
149   static const char OVAL_TAG [];
150   static const char NO_BORDER_TAG [];
151   static const char XOR_BORDER_TAG [];
152   static const char SOLID_BORDER_TAG [];
153   static const char SHADOW_IN_BORDER_TAG [];
154   static const char SHADOW_OUT_BORDER_TAG [];
155   static const char SHADOW_EIN_BORDER_TAG [];
156   static const char SHADOW_EOUT_BORDER_TAG [];
157   static const char BORDER_AVIS_TAG [];
158   static const char HILITE_TAG [];
159   static const char URL_TAG [];
160   static const char TARGET_SELF [];
161
162   enum BorderType { NO_BORDER=0, XOR_BORDER=1, SOLID_BORDER=2,
163                     SHADOW_IN_BORDER=3, SHADOW_OUT_BORDER=4,
164                     SHADOW_EIN_BORDER=5, SHADOW_EOUT_BORDER=6 };
165
166   enum Special_Hilite_Color{ NO_HILITE=0xFFFFFFFF, XOR_HILITE=0xFF000000};
167
168   // Enumeration for reporting the type of map area. "MapUnknown" is reported
169   // for objects of type GMapArea (there shouldn't be any).
170   enum MapAreaType { UNKNOWN, RECT, OVAL, POLY };
171
172      /** Optional URL which this map area can be associated with.
173          If it's not empty then clicking this map area with the mouse
174          will make the browser load the HTML page referenced by
175          this #url#.  Note: This may also be a relative URL, so the
176          GURL class is not used. */
177   GUTF8String  url;
178      /** The target for the #URL#. Standard targets are:
179          \begin{itemize}
180             \item #_blank# - Load the link in a new blank window
181             \item #_self# - Load the link into the plugin window
182             \item #_top# - Load the link into the top-level frame
183          \end{itemize} */
184   GUTF8String  target;
185      /** Comment (displayed in a status line or as a popup hint when
186          the mouse pointer moves over the map area */
187   GUTF8String  comment;
188      /** Border type. Defines how the map area border should be drawn
189          \begin{itemize}
190             \item #NO_BORDER# - No border drawn
191             \item #XOR_BORDER# - The border is drawn using XOR method.
192             \item #SOLID_BORDER# - The border is drawn as a solid line
193                   of a given color.
194             \item #SHADOW_IN_BORDER# - Supported for \Ref{GMapRect} only.
195                   The map area area looks as if it was "pushed-in".
196             \item #SHADOW_OUT_BORDER# - The opposite of #SHADOW_OUT_BORDER#
197             \item #SHADOW_EIN_BORDER# - Also for \Ref{GMapRect} only.
198                   Is translated as "shadow etched in"
199             \item #SHADOW_EOUT_BORDER# - The opposite of #SHADOW_EIN_BORDER#.
200          \end{itemize} */
201   BorderType   border_type;
202      /** If #TRUE#, the border will be made always visible. Otherwise
203          it will be drawn when the mouse moves over the map area. */
204   bool         border_always_visible;
205      /// Border color (when relevant) in #0x00RRGGBB# format
206   unsigned long int    border_color;
207      /// Border width in pixels
208   int          border_width;
209      /** Specified a color for highlighting the internal area of the map
210          area. Will work with rectangular map areas only. The color is
211          specified in \#00RRGGBB format. A special value of \#FFFFFFFF disables
212          highlighting and \#FF000000 is for XOR highlighting. */
213   unsigned long int    hilite_color;
214
215      /// Returns 1 if the given point is inside the hyperlink area
216   bool         is_point_inside(int x, int y) const;
217
218      /// Returns xmin of the bounding rectangle
219   int          get_xmin(void) const;
220      /// Returns ymin of the bounding rectangle
221   int          get_ymin(void) const;
222      /** Returns xmax of the bounding rectangle. In other words, if #X# is
223          a coordinate of the last point in the right direction, the
224          function will return #X+1# */
225   int          get_xmax(void) const;
226      /** Returns xmax of the bounding rectangle. In other words, if #Y# is
227          a coordinate of the last point in the top direction, the
228          function will return #Y+1# */
229   int          get_ymax(void) const;
230      /// Returns the hyperlink bounding rectangle
231   GRect        get_bound_rect(void) const;
232      /** Moves the hyperlink along the given vector. Is used by the
233          hyperlinks editor. */
234   void         move(int dx, int dy);
235      /** Resizes the hyperlink to fit new bounding rectangle while
236          keeping the (xmin, ymin) points at rest. */
237   void         resize(int new_width, int new_height);
238      /** Transforms the hyperlink to be within the specified rectangle */
239   void         transform(const GRect & grect);
240      /** Checks if the object is OK. Especially useful with \Ref{GMapPoly}
241          where edges may intersect. If there is a problem it returns a
242          string describing it. */
243   char const * const check_object(void);
244      /** Stores the contents of the hyperlink object in a lisp-like format
245          for saving into #ANTa# chunk (see \Ref{DjVuAnno}) */
246   GUTF8String  print(void);
247
248   virtual GUTF8String get_xmltag(const int height) const=0;
249
250      /// Virtual function returning the shape type.
251   virtual MapAreaType const get_shape_type( void ) const { return UNKNOWN; };
252      /// Virtual function returning the shape name.
253   virtual char const * const   get_shape_name(void) const=0;
254      /// Virtual function generating a copy of this object
255   virtual GP<GMapArea> get_copy(void) const=0;
256      /// Virtual function generating a list of defining coordinates
257      /// (default are the opposite corners of the enclosing rectangle)
258   virtual void get_coords( GList<int> & CoordList ) const;
259   /// Virtual function maps maparea from one area to another using mapper
260   virtual void map(GRectMapper &mapper)=0;
261   /// Virtual function unmaps maparea from one area to another using mapper
262   virtual void unmap(GRectMapper &mapper)=0;
263
264protected:
265   virtual int          gma_get_xmin(void) const=0;
266   virtual int          gma_get_ymin(void) const=0;
267   virtual int          gma_get_xmax(void) const=0;
268   virtual int          gma_get_ymax(void) const=0;
269   virtual void         gma_move(int dx, int dy)=0;
270   virtual void         gma_resize(int new_width, int new_height)=0;
271   virtual void         gma_transform(const GRect & grect)=0;
272   virtual bool         gma_is_point_inside(const int x, const int y) const=0;
273   virtual char const * const   gma_check_object(void) const=0;
274   virtual GUTF8String  gma_print(void)=0;
275   
276   void         clear_bounds(void) { bounds_initialized=0; }
277private:
278   int          xmin, xmax, ymin, ymax;
279   bool         bounds_initialized;
280
281   void         initialize_bounds(void);
282};
283
284// ---------- GMAPRECT ---------
285
286/** Implements rectangular map areas. This is the only kind of map areas
287    supporting #SHADOW_IN_BORDER#, #SHADOW_OUT_BORDER#, #SHADOW_EIN_BORDER#
288    and #SHADOW_EOUT_BORDER# types of border and area highlighting. */
289
290class GMapRect: public GMapArea
291{
292protected:
293   GMapRect(void);
294   GMapRect(const GRect & rect);
295public:
296   /// Default creator.
297   static GP<GMapRect> create(void) {return new GMapRect();}
298   /// Create with the specified GRect.
299   static GP<GMapRect> create(const GRect &rect) {return new GMapRect(rect);}
300
301   virtual ~GMapRect();
302
303      /// Returns the width of the rectangle
304   int          get_width(void) const { return xmax-xmin; }
305      /// Returns the height of the rectangle
306   int          get_height(void) const { return ymax-ymin; }
307
308      /// Changes the #GMapRect#'s geometry
309   GMapRect & operator=(const GRect & rect);
310
311      /// Returns \Ref{GRect} describing the map area's rectangle
312   operator GRect(void);
313   
314   virtual GUTF8String get_xmltag(const int height) const;
315      /// Returns MapRect
316   virtual MapAreaType const get_shape_type( void ) const { return RECT; };
317      /// Returns #"rect"#
318   virtual char const * const   get_shape_name(void) const;
319      /// Returns a copy of the rectangle
320   virtual GP<GMapArea> get_copy(void) const;
321      /// Virtual function maps rectangle from one area to another using mapper
322   virtual void map(GRectMapper &mapper);
323      /// Virtual function unmaps rectangle from one area to another using mapper
324   virtual void unmap(GRectMapper &mapper);
325protected:
326   int                  xmin, ymin, xmax, ymax;
327   virtual int          gma_get_xmin(void) const;
328   virtual int          gma_get_ymin(void) const;
329   virtual int          gma_get_xmax(void) const;
330   virtual int          gma_get_ymax(void) const;
331   virtual void         gma_move(int dx, int dy);
332   virtual void         gma_resize(int new_width, int new_height);
333   virtual void         gma_transform(const GRect & grect);
334   virtual bool         gma_is_point_inside(const int x, const int y) const;
335   virtual char const * const gma_check_object(void) const;
336   virtual GUTF8String  gma_print(void);
337};
338
339// ---------- GMAPPOLY ---------
340
341/** Implements polygonal map areas. The only supported types of border
342    are #NO_BORDER#, #XOR_BORDER# and #SOLID_BORDER#. Its contents can not
343    be highlighted either. It's worth mentioning here that despite its
344    name the polygon may be open, which basically makes it a broken line.
345    This very specific mode is used by the hyperlink editor when creating
346    the polygonal hyperlink. */
347
348class GMapPoly : public GMapArea
349{
350protected:
351   GMapPoly(void);
352   GMapPoly(const int * xx, const int * yy, int points, bool open=false);
353public:
354   /// Default creator
355   static GP<GMapPoly> create(void) {return new GMapPoly();}
356
357   /// Create from specified coordinates.
358   static GP<GMapPoly> create(
359     const int xx[], const int yy[], const int points, const bool open=false)
360   {return new GMapPoly(xx,yy,points,open);}
361
362   /// Virtual destructor.
363   virtual ~GMapPoly();
364
365      /// Returns 1 if side #side# crosses the specified rectangle #rect#.
366   bool         does_side_cross_rect(const GRect & grect, int side);
367
368      /// Returns the number of vertices in the polygon
369   int          get_points_num(void) const;
370
371      /// Returns the number sides in the polygon
372   int          get_sides_num(void) const;
373
374      /// Returns x coordinate of vertex number #i#
375   int          get_x(int i) const;
376   
377      /// Returns y coordinate of vertex number #i#
378   int          get_y(int i) const;
379
380      /// Moves vertex #i# to position (#x#, #y#)
381   void         move_vertex(int i, int x, int y);
382
383      /// Adds a new vertex and returns number of vertices in the polygon
384   int      add_vertex(int x, int y);
385
386      /// Closes the polygon if it is not closed
387   void     close_poly();
388      /// Optimizes the polygon
389   void         optimize_data(void);
390      /// Checks validity of the polygon
391   char const * const   check_data(void);
392
393   virtual GUTF8String get_xmltag(const int height) const;
394      /// Returns MapPoly
395   virtual MapAreaType const get_shape_type( void ) const { return POLY; };
396      /// Returns #"poly"# all the time
397   virtual char const * const   get_shape_name(void) const;
398      /// Returns a copy of the polygon
399   virtual GP<GMapArea> get_copy(void) const;
400      /// Virtual function generating a list of defining coordinates
401   void get_coords( GList<int> & CoordList ) const;
402      /// Virtual function maps polygon from one area to another using mapper
403   virtual void map(GRectMapper &mapper);
404   /// Virtual function unmaps polygon from one area to another using mapper
405   virtual void unmap(GRectMapper &mapper);
406protected:
407   virtual int          gma_get_xmin(void) const;
408   virtual int          gma_get_ymin(void) const;
409   virtual int          gma_get_xmax(void) const;
410   virtual int          gma_get_ymax(void) const;
411   virtual void         gma_move(int dx, int dy);
412   virtual void         gma_resize(int new_width, int new_height);
413   virtual void         gma_transform(const GRect & grect);
414   virtual bool         gma_is_point_inside(const int x, const int y) const;
415   virtual char const * const gma_check_object(void) const;
416   virtual GUTF8String  gma_print(void);
417private:
418   bool         open;
419   int          points, sides;
420   GTArray<int> xx, yy;
421   static int   sign(int x);
422   static bool  is_projection_on_segment(int x, int y, int x1, int y1, int x2, int y2);
423   static bool  do_segments_intersect(int x11, int y11, int x12, int y12,
424                                      int x21, int y21, int x22, int y22);
425   static bool  are_segments_parallel(int x11, int y11, int x12, int y12,
426                                      int x21, int y21, int x22, int y22);
427};
428
429// ---------- GMAPOVAL ---------
430
431/** Implements elliptical map areas. The only supported types of border
432    are #NO_BORDER#, #XOR_BORDER# and #SOLID_BORDER#. Its contents can not
433    be highlighted either. */
434
435class GMapOval: public GMapArea
436{
437protected:
438   GMapOval(void);
439   GMapOval(const GRect & rect);
440public:
441   /// Default creator.
442   static GP<GMapOval> create(void) {return new GMapOval();}
443
444   /// Create from the specified GRect.
445   static GP<GMapOval> create(const GRect &rect) {return new GMapOval(rect);}
446
447   /// Virtual destructor.
448   virtual ~GMapOval();
449
450      /// Returns (xmax-xmin)/2
451   int          get_a(void) const;
452      /// Returns (ymax-ymin)/2
453   int          get_b(void) const;
454      /// Returns the lesser of \Ref{get_a}() and \Ref{get_b}()
455   int          get_rmin(void) const;
456      /// Returns the greater of \Ref{get_a}() and \Ref{get_b}()
457   int          get_rmax(void) const;
458
459   virtual GUTF8String get_xmltag(const int height) const;
460      /// Returns MapOval
461   virtual MapAreaType const get_shape_type( void ) const { return OVAL; };
462      /// Returns #"oval"#
463   virtual char const * const get_shape_name(void) const;
464      /// Returns a copy of the oval
465   virtual GP<GMapArea> get_copy(void) const;
466      /// Virtual function maps oval from one area to another using mapper
467   virtual void map(GRectMapper &mapper);
468      /// Virtual function unmaps oval from one area to another using mapper
469   virtual void unmap(GRectMapper &mapper);
470protected:
471   virtual int          gma_get_xmin(void) const;
472   virtual int          gma_get_ymin(void) const;
473   virtual int          gma_get_xmax(void) const;
474   virtual int          gma_get_ymax(void) const;
475   virtual void         gma_move(int dx, int dy);
476   virtual void         gma_resize(int new_width, int new_height);
477   virtual void         gma_transform(const GRect & grect);
478   virtual bool         gma_is_point_inside(const int x, const int y) const;
479   virtual char const * const   gma_check_object(void) const;
480   virtual GUTF8String  gma_print(void);
481private:
482   int          rmax, rmin;
483   int          a, b;
484   int          xf1, yf1, xf2, yf2;
485   int          xmin, ymin, xmax, ymax;
486   
487   void         initialize(void);
488};
489
490inline
491GMapRect::operator GRect(void)
492{
493  return GRect(xmin, ymin, xmax-xmin, ymax-ymin);
494}
495
496inline int
497GMapRect::gma_get_xmin(void) const { return xmin; }
498
499inline int
500GMapRect::gma_get_ymin(void) const { return ymin; }
501
502inline int
503GMapRect::gma_get_xmax(void) const { return xmax; }
504
505inline int
506GMapRect::gma_get_ymax(void) const { return ymax; }
507
508inline char const * const
509GMapRect::gma_check_object(void)  const{ return ""; }
510
511inline char const * const 
512GMapRect::get_shape_name(void) const { return RECT_TAG; }
513
514inline int
515GMapPoly::get_points_num(void) const { return points; }
516
517inline int
518GMapPoly::get_sides_num(void) const { return sides; }
519
520inline int
521GMapPoly::get_x(int i) const { return xx[i]; }
522
523inline int
524GMapPoly::get_y(int i) const { return yy[i]; }
525
526inline char const * const
527GMapPoly::get_shape_name(void) const { return POLY_TAG; }
528
529inline int
530GMapOval::get_a(void) const { return a; }
531
532inline int
533GMapOval::get_b(void) const { return b; }
534
535inline int
536GMapOval::get_rmin(void) const { return rmin; }
537
538inline int
539GMapOval::get_rmax(void) const { return rmax; }
540
541inline int
542GMapOval::gma_get_xmin(void) const { return xmin; }
543
544inline int
545GMapOval::gma_get_ymin(void) const { return ymin; }
546
547inline int
548GMapOval::gma_get_xmax(void) const { return xmax; }
549
550inline int
551GMapOval::gma_get_ymax(void) const { return ymax; }
552
553inline char const * const
554GMapOval::get_shape_name(void) const { return OVAL_TAG; }
555
556//@}
557
558
559#ifdef HAVE_NAMESPACES
560}
561# ifndef NOT_USING_DJVU_NAMESPACE
562using namespace DJVU;
563# endif
564#endif
565#endif
Note: See TracBrowser for help on using the repository browser.