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 WPXBinaryData
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   Box2f getBdBox() const {
00078     Box2f res(m_bdbox);
00079     res.extend(m_bdBoxExt);
00080     return res;
00081   }
00082 
00084   void setBdBox(Box2f const &box) {
00085     m_bdbox = box;
00086   }
00087 
00092   virtual bool getBinary(WPXBinaryData &, std::string &) const {
00093     return false;
00094   }
00095 
00099   virtual int cmp(MWAWPict const &a) const {
00100     // first compare the bdbox
00101     int diff = m_bdbox.cmp(a.m_bdbox);
00102     if (diff) return diff;
00103     // the type
00104     diff = getType() - a.getType();
00105     if (diff) return (diff < 0) ? -1 : 1;
00106 
00107     return 0;
00108   }
00109 protected:
00111   static Box2f getBdBox(int numPt, Vec2f const *pt) {
00112     if (numPt <= 0) {
00113       return Box2f();
00114     }
00115 
00116     float minV[2], maxV[2];
00117     for (int c = 0; c < 2; c++) minV[c] = maxV[c] = pt[0][c];
00118 
00119     for (int i = 1; i < numPt; i++) {
00120       for (int c = 0; c < 2; c++) {
00121         float v = pt[i][c];
00122         if (v < minV[c]) minV[c] = v;
00123         else if (v > maxV[c]) maxV[c] = v;
00124       }
00125     }
00126 
00127     return Box2f(Vec2f(minV[0], minV[1]), Vec2f(maxV[0], maxV[1]));
00128   }
00129 
00130   // a function to extend the bdbox
00131 
00133   void extendBDBox(float val) {
00134     m_bdBoxExt = val;
00135   }
00136 
00138   MWAWPict() : m_bdbox(), m_bdBoxExt (0.0) {}
00140   MWAWPict(MWAWPict const &p) : m_bdbox(), m_bdBoxExt (0.0) {
00141     *this=p;
00142   }
00144   MWAWPict &operator=(MWAWPict const &p) {
00145     if (&p == this) return *this;
00146     m_bdbox = p.m_bdbox;
00147     m_bdBoxExt = p.m_bdBoxExt;
00148     return *this;
00149   }
00150 
00151 private:
00153   Box2f m_bdbox;
00155   float m_bdBoxExt;
00156 };
00157 
00158 #endif
00159 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: