• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kviewshell

GRect.h

Go to the documentation of this file.
00001 //C-  -*- C++ -*-
00002 //C- -------------------------------------------------------------------
00003 //C- DjVuLibre-3.5
00004 //C- Copyright (c) 2002  Leon Bottou and Yann Le Cun.
00005 //C- Copyright (c) 2001  AT&T
00006 //C-
00007 //C- This software is subject to, and may be distributed under, the
00008 //C- GNU General Public License, Version 2. The license should have
00009 //C- accompanied the software or you may obtain a copy of the license
00010 //C- from the Free Software Foundation at http://www.fsf.org .
00011 //C-
00012 //C- This program is distributed in the hope that it will be useful,
00013 //C- but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 //C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 //C- GNU General Public License for more details.
00016 //C- 
00017 //C- DjVuLibre-3.5 is derived from the DjVu(r) Reference Library
00018 //C- distributed by Lizardtech Software.  On July 19th 2002, Lizardtech 
00019 //C- Software authorized us to replace the original DjVu(r) Reference 
00020 //C- Library notice by the following text (see doc/lizard2002.djvu):
00021 //C-
00022 //C-  ------------------------------------------------------------------
00023 //C- | DjVu (r) Reference Library (v. 3.5)
00024 //C- | Copyright (c) 1999-2001 LizardTech, Inc. All Rights Reserved.
00025 //C- | The DjVu Reference Library is protected by U.S. Pat. No.
00026 //C- | 6,058,214 and patents pending.
00027 //C- |
00028 //C- | This software is subject to, and may be distributed under, the
00029 //C- | GNU General Public License, Version 2. The license should have
00030 //C- | accompanied the software or you may obtain a copy of the license
00031 //C- | from the Free Software Foundation at http://www.fsf.org .
00032 //C- |
00033 //C- | The computer code originally released by LizardTech under this
00034 //C- | license and unmodified by other parties is deemed "the LIZARDTECH
00035 //C- | ORIGINAL CODE."  Subject to any third party intellectual property
00036 //C- | claims, LizardTech grants recipient a worldwide, royalty-free, 
00037 //C- | non-exclusive license to make, use, sell, or otherwise dispose of 
00038 //C- | the LIZARDTECH ORIGINAL CODE or of programs derived from the 
00039 //C- | LIZARDTECH ORIGINAL CODE in compliance with the terms of the GNU 
00040 //C- | General Public License.   This grant only confers the right to 
00041 //C- | infringe patent claims underlying the LIZARDTECH ORIGINAL CODE to 
00042 //C- | the extent such infringement is reasonably necessary to enable 
00043 //C- | recipient to make, have made, practice, sell, or otherwise dispose 
00044 //C- | of the LIZARDTECH ORIGINAL CODE (or portions thereof) and not to 
00045 //C- | any greater extent that may be necessary to utilize further 
00046 //C- | modifications or combinations.
00047 //C- |
00048 //C- | The LIZARDTECH ORIGINAL CODE is provided "AS IS" WITHOUT WARRANTY
00049 //C- | OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
00050 //C- | TO ANY WARRANTY OF NON-INFRINGEMENT, OR ANY IMPLIED WARRANTY OF
00051 //C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
00052 //C- +------------------------------------------------------------------
00053 // 
00054 // $Id: GRect.h,v 1.9 2003/11/07 22:08:21 leonb Exp $
00055 // $Name: release_3_5_15 $
00056 
00057 #ifndef _GRECT_H_
00058 #define _GRECT_H_
00059 #ifdef HAVE_CONFIG_H
00060 #include "config.h"
00061 #endif
00062 #if NEED_GNUG_PRAGMAS
00063 # pragma interface
00064 #endif
00065 
00066 
00080 
00081 #include "DjVuGlobal.h"
00082 
00083 #ifdef HAVE_NAMESPACES
00084 namespace DJVU {
00085 # ifdef NOT_DEFINED // Just to fool emacs c++ mode
00086 }
00087 #endif
00088 #endif
00089 
00090 
00091 
00121 
00122 
00123 
00124 
00132 class GRect 
00133 {
00134 public:
00145   enum OrientationBits
00146   {
00147     BOTTOM_UP=0x1,  /* Upside down */
00148     MIRROR=0x2,     /* Written backwards. (right to left) */
00149     ROTATE90_CW=0x4 /* rotated 90 degrees */
00150   };
00151 
00165   enum Orientations
00166   {
00167     TDLRNR=0,                                     /* normal orientation */
00168     BULRNR=BOTTOM_UP,                               /* upside down */
00169     TDRLNR=MIRROR,                    /* backwards (right to left) */
00170     BURLNR=MIRROR|BOTTOM_UP,                    /* rotate 180 */
00171     TDLRCW=ROTATE90_CW,                              /* rotated 90 */
00172     BULRCW=ROTATE90_CW|BOTTOM_UP, /* backwards and rotate 180 */
00173     TDRLCW=ROTATE90_CW|MIRROR,     /* backwards and rotate 90 */
00174     BURLCW=ROTATE90_CW|MIRROR|BOTTOM_UP    /* rotate 270 */
00175   };
00176 
00177   static Orientations
00178   rotate(const int angle,Orientations orientation)
00179   {
00180     for(int a=(((angle)%360)+405)%360;a>90;a-=90)
00181       orientation=(Orientations)((int)orientation^(int)(orientation&ROTATE90_CW)?BURLCW:TDLRCW);
00182     return orientation;
00183   }
00184 
00185   static int
00186   findangle(const Orientations orientation)
00187   {
00188     int a=270;
00189     while(a&&(rotate(a,BURLNR)!=orientation)&&(rotate(a,TDRLNR)!=orientation))
00190       a-=90;
00191     return a;
00192   }
00193 
00195   GRect();
00199   GRect(int xmin, int ymin, unsigned int width=0, unsigned int height=0);
00201   int  width() const;
00203   int  height() const;
00205   int  area() const;
00207   int  isempty() const;
00212   int  contains(int x, int y) const;
00216   int  contains(const GRect & rect) const;
00218   friend int operator==(const GRect & r1, const GRect & r2);
00220   friend int operator!=(const GRect & r1, const GRect & r2);
00222   void clear();
00227   int  inflate(int dx, int dy);
00231   int  translate(int dx, int dy);
00234   int  intersect(const GRect &rect1, const GRect &rect2);
00238   int  recthull(const GRect &rect1, const GRect &rect2);
00240   void scale(float factor);
00242   void scale(float xfactor, float yfactor);
00244   int xmin;
00246   int ymin;
00248   int xmax;
00250   int ymax;
00251 };
00252 
00253 
00263 class GRectMapper 
00264 {
00265 public:
00267   GRectMapper();
00270   void clear();
00272   void set_input(const GRect &rect);
00274   GRect get_input();
00276   void set_output(const GRect &rect);
00278   GRect get_output();
00283   void rotate(int count=1);
00288   void mirrorx();
00293   void mirrory();
00300   void map(int &x, int &y);
00305   void map(GRect &rect);
00312   void unmap(int &x, int &y);
00317   void unmap(GRect &rect);
00318 private:
00319   // GRatio
00320   struct GRatio {
00321     GRatio ();
00322     GRatio (int p, int q);
00323     int p;
00324     int q;
00325   };
00326   // Data
00327   GRect rectFrom;
00328   GRect rectTo;
00329   int   code;
00330   // Helper
00331   void  precalc();
00332   friend int operator*(int n, GRatio r ); 
00333   friend int operator/(int n, GRatio r ); 
00334   GRatio rw;
00335   GRatio rh;
00336 };
00337 
00338 
00340 
00341 
00342 
00343 // ---- INLINES
00344 
00345 inline
00346 GRect::GRect()
00347 : xmin(0), ymin(0), xmax(0), ymax(0)
00348 {
00349 }
00350 
00351 inline 
00352 GRect::GRect(int xmin, int ymin, unsigned int width, unsigned int height)
00353 : xmin(xmin), ymin(ymin), xmax(xmin+width), ymax(ymin+height)
00354 {
00355 }
00356 
00357 inline int 
00358 GRect::width() const
00359 {
00360   return xmax - xmin;
00361 }
00362 
00363 inline int 
00364 GRect::height() const
00365 {
00366   return ymax - ymin;
00367 }
00368 
00369 inline int 
00370 GRect::isempty() const
00371 {
00372   return (xmin>=xmax || ymin>=ymax);
00373 }
00374 
00375 inline int 
00376 GRect::area() const
00377 {
00378   return isempty() ? 0 : (xmax-xmin)*(ymax-ymin);
00379 }
00380 
00381 inline int
00382 GRect::contains(int x, int y) const
00383 {
00384   return (x>=xmin && x<xmax && y>=ymin && y<ymax);
00385 }
00386   
00387 inline void 
00388 GRect::clear()
00389 {
00390   xmin = xmax = ymin = ymax = 0;
00391 }
00392 
00393 inline int
00394 operator!=(const GRect & r1, const GRect & r2)
00395 {
00396    return !(r1==r2);
00397 }
00398 
00399 // ---- THE END
00400 
00401 #ifdef HAVE_NAMESPACES
00402 }
00403 # ifndef NOT_USING_DJVU_NAMESPACE
00404 using namespace DJVU;
00405 # endif
00406 #endif
00407 #endif

kviewshell

Skip menu "kviewshell"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • kviewshell
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal