MWAWPict.hxx
Go to the documentation of this file.
00001 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
00002 
00003 /* libmwaw
00004 * Version: MPL 2.0 / LGPLv2+
00005 *
00006 * The contents of this file are subject to the Mozilla Public License Version
00007 * 2.0 (the "License"); you may not use this file except in compliance with
00008 * the License or as specified alternatively below. You may obtain a copy of
00009 * the License at http://www.mozilla.org/MPL/
00010 *
00011 * Software distributed under the License is distributed on an "AS IS" basis,
00012 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013 * for the specific language governing rights and limitations under the
00014 * License.
00015 *
00016 * Major Contributor(s):
00017 * Copyright (C) 2002 William Lachance (wrlach@gmail.com)
00018 * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
00019 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
00020 * Copyright (C) 2006, 2007 Andrew Ziem
00021 * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
00022 *
00023 *
00024 * All Rights Reserved.
00025 *
00026 * For minor contributions see the git repository.
00027 *
00028 * Alternatively, the contents of this file may be used under the terms of
00029 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
00030 * in which case the provisions of the LGPLv2+ are applicable
00031 * instead of those above.
00032 */
00033 
00034 /*
00035  * This header contains code specific to manage basic picture (line, rectangle, ...)
00036  *
00037  * Note: generic class for all sort of pict
00038  *      - PictBitmap: regroup some classes used to store bitmap
00039  *      - PictData: regroup the data which can be read via a librevenge::RVNGBinaryData
00040  */
00041 
00042 #ifndef MWAW_PICT
00043 #  define MWAW_PICT
00044 
00045 #  include <assert.h>
00046 #  include <ostream>
00047 #  include <vector>
00048 
00049 #  include "libmwaw_internal.hxx"
00050 
00052 class MWAWPict
00053 {
00054 public:
00056   virtual ~MWAWPict() {}
00057 
00064   enum Type { PictData, Bitmap, Unknown };
00066   virtual Type getType() const = 0;
00067 
00074   enum ReadResult { MWAW_R_BAD=0, MWAW_R_OK, MWAW_R_OK_EMPTY, MWAW_R_MAYBE };
00075 
00077   MWAWBox2f getBdBox() const
00078   {
00079     MWAWBox2f res(m_bdbox);
00080     res.extend(m_bdBoxExt);
00081     return res;
00082   }
00083 
00085   void setBdBox(MWAWBox2f const &box)
00086   {
00087     m_bdbox = box;
00088   }
00089 
00094   virtual bool getBinary(librevenge::RVNGBinaryData &, std::string &) const
00095   {
00096     return false;
00097   }
00098 
00102   virtual int cmp(MWAWPict const &a) const
00103   {
00104     // first compare the bdbox
00105     int diff = m_bdbox.cmp(a.m_bdbox);
00106     if (diff) return diff;
00107     // the type
00108     diff = getType() - a.getType();
00109     if (diff) return (diff < 0) ? -1 : 1;
00110 
00111     return 0;
00112   }
00113 protected:
00115   static MWAWBox2f getBdBox(int numPt, MWAWVec2f const *pt)
00116   {
00117     if (numPt <= 0) {
00118       return MWAWBox2f();
00119     }
00120 
00121     float minV[2], maxV[2];
00122     for (int c = 0; c < 2; c++) minV[c] = maxV[c] = pt[0][c];
00123 
00124     for (int i = 1; i < numPt; i++) {
00125       for (int c = 0; c < 2; c++) {
00126         float v = pt[i][c];
00127         if (v < minV[c]) minV[c] = v;
00128         else if (v > maxV[c]) maxV[c] = v;
00129       }
00130     }
00131 
00132     return MWAWBox2f(MWAWVec2f(minV[0], minV[1]), MWAWVec2f(maxV[0], maxV[1]));
00133   }
00134 
00135   // a function to extend the bdbox
00136 
00138   void extendBDBox(float val)
00139   {
00140     m_bdBoxExt = val;
00141   }
00142 
00144   MWAWPict() : m_bdbox(), m_bdBoxExt(0.0) {}
00146   MWAWPict(MWAWPict const &p) : m_bdbox(), m_bdBoxExt(0.0)
00147   {
00148     *this=p;
00149   }
00151   MWAWPict &operator=(MWAWPict const &p)
00152   {
00153     if (&p == this) return *this;
00154     m_bdbox = p.m_bdbox;
00155     m_bdBoxExt = p.m_bdBoxExt;
00156     return *this;
00157   }
00158 
00159 private:
00161   MWAWBox2f m_bdbox;
00163   float m_bdBoxExt;
00164 };
00165 
00166 #endif
00167 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: