StarGraphicStruct.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 /* libstaroffice
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 #ifndef STAR_GRAPHIC_STRUCT
00035 #  define STAR_GRAPHIC_STRUCT
00036 
00037 #include <ostream>
00038 #include <string>
00039 #include <vector>
00040 
00041 #include "libstaroffice_internal.hxx"
00042 
00043 class StarBitmap;
00044 class StarObject;
00045 class StarZone;
00046 
00048 namespace StarGraphicStruct
00049 {
00051 class StarBrush
00052 {
00053 public:
00055   StarBrush() : m_transparency(0), m_color(STOFFColor::white()), m_fillColor(STOFFColor::white()), m_style(0), m_position(0), m_linkName(""), m_filterName(""), m_extra("")
00056   {
00057   }
00059   bool isEmpty() const
00060   {
00061     return m_style<=0 || m_style>=11 || m_transparency>=255;
00062   }
00064   bool hasUniqueColor() const
00065   {
00066     return m_style==1;
00067   }
00069   bool getColor(STOFFColor &color) const;
00071   bool getPattern(STOFFEmbeddedObject &object, STOFFVec2i &sz) const;
00073   bool read(StarZone &zone, int nVers, long endPos, StarObject &document);
00075   friend std::ostream &operator<<(std::ostream &o, StarBrush const &brush);
00077   int m_transparency;
00079   STOFFColor m_color;
00081   STOFFColor m_fillColor;
00084   int m_style;
00086   int m_position;
00088   librevenge::RVNGString m_linkName;
00090   librevenge::RVNGString m_filterName;
00092   std::string m_extra;
00093 };
00094 
00096 class StarGraphic
00097 {
00098 public:
00100   StarGraphic() : m_object(), m_bitmap()
00101   {
00102   }
00104   bool read(StarZone &zone, long lastPos=-1);
00106   STOFFEmbeddedObject m_object;
00108   shared_ptr<StarBitmap> m_bitmap;
00109 };
00110 
00112 class StarPolygon
00113 {
00114 public:
00116   struct Point {
00118     explicit Point(STOFFVec2i point=STOFFVec2i(), int flag=0) : m_point(point), m_flags(flag)
00119     {
00120     }
00122     friend std::ostream &operator<<(std::ostream &o, Point const &point)
00123     {
00124       o << point.m_point;
00125       switch (point.m_flags) {
00126       case 0:
00127         break;
00128       case 1: // smooth
00129         o << ":s";
00130         break;
00131       case 2: // control
00132         o << ":c";
00133         break;
00134       case 3: // symetric
00135         o << ":S";
00136         break;
00137       default:
00138         STOFF_DEBUG_MSG(("StarObjectSmallGraphicStruct::StarPolygon::Point::operator<< unexpected flag\n"));
00139         o << ":[##" << point.m_flags << "]";
00140       }
00141       return o;
00142     }
00144     STOFFVec2i m_point;
00146     int m_flags;
00147   };
00149   StarPolygon() : m_points()
00150   {
00151   }
00153   bool hasSpecialPoints() const
00154   {
00155     for (size_t i=0; i<m_points.size(); ++i) {
00156       if (m_points[i].m_flags)
00157         return true;
00158     }
00159     return false;
00160   }
00162   bool empty() const
00163   {
00164     return m_points.empty();
00165   }
00167   size_t size() const
00168   {
00169     return m_points.size();
00170   }
00172   void addToPath(librevenge::RVNGPropertyListVector &path, bool isClosed) const;
00174   bool convert(librevenge::RVNGString &path, librevenge::RVNGString &viewbox) const;
00176   friend std::ostream &operator<<(std::ostream &o, StarPolygon const &poly);
00178   std::vector<Point> m_points;
00179 };
00180 
00181 }
00182 
00183 #endif
00184 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: