MWAWPict.hxx
Go to the documentation of this file.
/* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
/* libmwaw
* Version: MPL 2.0 / LGPLv2+
*
* The contents of this file are subject to the Mozilla Public License Version
* 2.0 (the "License"); you may not use this file except in compliance with
* the License or as specified alternatively below. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* Major Contributor(s):
* Copyright (C) 2002 William Lachance (wrlach@gmail.com)
* Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
* Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
* Copyright (C) 2006, 2007 Andrew Ziem
* Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
*
*
* All Rights Reserved.
*
* For minor contributions see the git repository.
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
* in which case the provisions of the LGPLv2+ are applicable
* instead of those above.
*/
/*
* This header contains code specific to manage basic picture (line, rectangle, ...)
*
* Note: generic class for all sort of pict
* - PictBitmap: regroup some classes used to store bitmap
* - PictData: regroup the data which can be read via a librevenge::RVNGBinaryData
*/
#ifndef MWAW_PICT
# define MWAW_PICT
# include <ostream>
# include <vector>
# include "libmwaw_internal.hxx"
class MWAWPict
{
public:
virtual ~MWAWPict();
enum Type { PictData, Bitmap, Unknown };
virtual Type getType() const = 0;
enum ReadResult { MWAW_R_BAD=0, MWAW_R_OK, MWAW_R_OK_EMPTY, MWAW_R_MAYBE };
MWAWBox2f getBdBox() const
{
MWAWBox2f res(m_bdbox);
res.extend(m_bdBoxExt);
return res;
}
void setBdBox(MWAWBox2f const &box)
{
m_bdbox = box;
}
virtual bool getBinary(MWAWEmbeddedObject &) const
{
return false;
}
virtual int cmp(MWAWPict const &a) const
{
// first compare the bdbox
if (m_bdbox!=a.m_bdbox)
return m_bdbox < a.m_bdbox ? -1 : 1;
// the type
int diff = getType() - a.getType();
if (diff) return (diff < 0) ? -1 : 1;
return 0;
}
protected:
static MWAWBox2f getBdBox(int numPt, MWAWVec2f const *pt)
{
if (numPt <= 0) {
return MWAWBox2f();
}
float minV[2], maxV[2];
for (int c = 0; c < 2; c++) minV[c] = maxV[c] = pt[0][c];
for (int i = 1; i < numPt; i++) {
for (int c = 0; c < 2; c++) {
float v = pt[i][c];
if (v < minV[c]) minV[c] = v;
else if (v > maxV[c]) maxV[c] = v;
}
}
return MWAWBox2f(MWAWVec2f(minV[0], minV[1]), MWAWVec2f(maxV[0], maxV[1]));
}
// a function to extend the bdbox
void extendBDBox(float val)
{
m_bdBoxExt = val;
}
MWAWPict()
: m_bdbox()
, m_bdBoxExt(0.0)
{
}
explicit MWAWPict(MWAWPict const &p)
: m_bdbox()
, m_bdBoxExt(0.0)
{
*this=p;
}
MWAWPict &operator=(MWAWPict const &p)
{
if (&p == this) return *this;
m_bdbox = p.m_bdbox;
m_bdBoxExt = p.m_bdBoxExt;
return *this;
}
private:
MWAWBox2f m_bdbox;
float m_bdBoxExt;
};
#endif
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
MWAWBox2::extend
void extend(T val)
extends the bdbox by (val, val) keeping the center
Definition libmwaw_internal.hxx:1122
MWAWPict::MWAWPict
MWAWPict()
protected constructor must not be called directly
Definition MWAWPict.hxx:143
MWAWPict::getBdBox
static MWAWBox2f getBdBox(int numPt, MWAWVec2f const *pt)
computes the minimum and maximum of a list of point
Definition MWAWPict.hxx:114
MWAWPict::Type
Type
the different picture types:
Definition MWAWPict.hxx:63
MWAWPict::Bitmap
@ Bitmap
Definition MWAWPict.hxx:63
MWAWPict::Unknown
@ Unknown
Definition MWAWPict.hxx:63
MWAWPict::PictData
@ PictData
Definition MWAWPict.hxx:63
MWAWPict::ReadResult
ReadResult
an enum to defined the result of a parsing use by some picture's classes which can read their data
Definition MWAWPict.hxx:73
MWAWPict::MWAW_R_OK
@ MWAW_R_OK
Definition MWAWPict.hxx:73
MWAWPict::MWAW_R_BAD
@ MWAW_R_BAD
Definition MWAWPict.hxx:73
MWAWPict::MWAW_R_MAYBE
@ MWAW_R_MAYBE
Definition MWAWPict.hxx:73
MWAWPict::MWAW_R_OK_EMPTY
@ MWAW_R_OK_EMPTY
Definition MWAWPict.hxx:73
MWAWPict::m_bdbox
MWAWBox2f m_bdbox
the bdbox (min and max pt)
Definition MWAWPict.hxx:166
MWAWPict::getType
virtual Type getType() const =0
returns the picture type
MWAWPict::cmp
virtual int cmp(MWAWPict const &a) const
a virtual function used to obtain a strict order, must be redefined in the subs class
Definition MWAWPict.hxx:101
MWAWPict::~MWAWPict
virtual ~MWAWPict()
virtual destructor
Definition MWAWPict.cxx:36
MWAWPict::m_bdBoxExt
float m_bdBoxExt
the actual extension of the original box,
Definition MWAWPict.hxx:168
MWAWPict::MWAWPict
MWAWPict(MWAWPict const &p)
protected constructor must not be called directly
Definition MWAWPict.hxx:149
MWAWPict::setBdBox
void setBdBox(MWAWBox2f const &box)
sets the bdbox of the picture
Definition MWAWPict.hxx:84
MWAWPict::operator=
MWAWPict & operator=(MWAWPict const &p)
protected operator= must not be called directly
Definition MWAWPict.hxx:156
MWAWPict::getBinary
virtual bool getBinary(MWAWEmbeddedObject &) const
tries to convert the picture in a binary data :
Definition MWAWPict.hxx:93
MWAWPict::extendBDBox
void extendBDBox(float val)
udaptes the bdbox, by extended it by (val-previousVal)
Definition MWAWPict.hxx:137
MWAWPict::getBdBox
MWAWBox2f getBdBox() const
returns the bdbox of the picture
Definition MWAWPict.hxx:76
libmwaw_internal.hxx
MWAWBox2f
MWAWBox2< float > MWAWBox2f
MWAWBox2 of float.
Definition libmwaw_internal.hxx:1193
MWAWVec2f
MWAWVec2< float > MWAWVec2f
MWAWVec2 of float.
Definition libmwaw_internal.hxx:842
MWAWEmbeddedObject
small class use to define a embedded object
Definition libmwaw_internal.hxx:467