MsWksGraph.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  * Parser to Microsoft Works text document ( graphic part )
00036  *
00037  */
00038 #ifndef MS_WKS_MWAW_GRAPH
00039 #  define MS_WKS_MWAW_GRAPH
00040 
00041 #include <list>
00042 #include <string>
00043 #include <vector>
00044 
00045 #include "MWAWPosition.hxx"
00046 
00047 #include "MWAWEntry.hxx"
00048 #include "MWAWGraphicStyle.hxx"
00049 #include "MWAWParser.hxx"
00050 
00051 namespace MsWksGraphInternal
00052 {
00053 struct GroupZone;
00054 struct RBZone;
00055 struct TextBox;
00056 struct Zone;
00057 
00058 struct State;
00059 
00060 class SubDocument;
00061 }
00062 
00063 class MsWksTable;
00064 class MsWksDocument;
00065 
00066 class MsWksParser;
00067 class MsWks4Zone;
00068 class MsWksDBParser;
00069 class MsWksDRParser;
00070 class MsWksSSParser;
00071 
00073 class MsWksGraph
00074 {
00075   friend class MsWksDocument;
00076   friend class MsWksTable;
00077 
00078   friend class MsWksParser;
00079   friend class MsWks4Zone;
00080   friend class MsWksDBParser;
00081   friend class MsWksDRParser;
00082   friend class MsWksSSParser;
00083   friend class MsWksGraphInternal::SubDocument;
00084 public:
00085   struct Style;
00086 
00088   MsWksGraph(MsWksDocument &document);
00090   virtual ~MsWksGraph();
00091 
00093   void setPageLeftTop(MWAWVec2f const &leftTop);
00094 
00096   int version() const;
00098   int numPages(int zoneId) const;
00099 
00104   void send(int id, MWAWPosition const &pos);
00106   void sendAll(int zoneId, bool mainZone);
00107 
00109   struct SendData {
00111     SendData() : m_type(RBDR), m_id(-1), m_anchor(MWAWPosition::Char), m_page(-1), m_size()
00112     {
00113     }
00115     enum Type { RBDR, RBIL, ALL } m_type;
00117     int m_id;
00119     MWAWPosition::AnchorTo m_anchor;
00121     int m_page;
00123     MWAWVec2i m_size;
00124   };
00126   void sendObjects(SendData const &what);
00127 
00129   void computePositions(int zoneId, std::vector<int> &linesHeight, std::vector<int> &pagesHeight);
00130 
00131 protected:
00133   void flushExtra();
00134 
00135   //
00136   // Intermediate level
00137   //
00138 
00140   bool readPictHeader(MsWksGraphInternal::Zone &pict);
00142   bool readGradient(Style &style);
00144   int getEntryPictureV1(int zoneId, MWAWEntry &zone, bool autoSend=true);
00145 
00147   int getEntryPicture(int zoneId, MWAWEntry &zone, bool autoSend=true, int order=-1000);
00148 
00155   bool readRB(MWAWInputStreamPtr input, MWAWEntry const &entry, int kind);
00156 
00157   // version 4 file
00158 
00160   bool readPictureV4(MWAWInputStreamPtr input, MWAWEntry const &entry);
00161 
00163   bool readText(MsWksGraphInternal::TextBox &textBox);
00165   void sendTextBox(int zId, MWAWListenerPtr listener);
00167   void checkTextBoxLinks(MsWksGraphInternal::RBZone &rbZone);
00168 
00169   // interface function
00170 
00172   bool getZoneGraphicStyle(int zoneId, MWAWGraphicStyle &style) const;
00174   bool getZonePosition(int zoneId, MWAWPosition::AnchorTo anchor, MWAWPosition &pos) const;
00175 
00177   void sendFrameText(MWAWEntry const &entry, std::string const &frame);
00178 
00180   void sendTable(int id);
00181 
00183   void sendChart(int zoneId);
00184 
00185   //
00186   // low level
00187   //
00189   shared_ptr<MsWksGraphInternal::GroupZone> readGroup(MsWksGraphInternal::Zone &group);
00191   void sendGroup(int zoneId, MWAWPosition const &pos);
00193   void sendGroupChild(int zoneId, MWAWPosition const &pos);
00195   bool canCreateGraphic(MsWksGraphInternal::GroupZone const &group) const;
00197   void sendGroup(MsWksGraphInternal::GroupZone const &group, MWAWGraphicListenerPtr &listener) const;
00199   bool readFont(MWAWFont &font);
00200 
00201 public:
00203   struct Style : public MWAWGraphicStyle {
00205     Style() : MWAWGraphicStyle(), m_baseLineColor(MWAWColor::black()), m_baseSurfaceColor(MWAWColor::white())
00206     {
00207       m_fillRuleEvenOdd=true;
00208     }
00210     friend std::ostream &operator<<(std::ostream &o, Style const &st)
00211     {
00212       o << static_cast<MWAWGraphicStyle const &>(st);
00213       if (st.m_baseLineColor != st.m_lineColor)
00214         o << "lineColor[base]=" << st.m_baseLineColor << ",";
00215       if (st.m_baseSurfaceColor != st.m_surfaceColor)
00216         o << "surfaceColor[base]=" << st.m_baseSurfaceColor << ",";
00217 
00218       return o;
00219     }
00220 
00222     MWAWColor m_baseLineColor;
00224     MWAWColor m_baseSurfaceColor;
00225   };
00226 
00227 private:
00228   MsWksGraph(MsWksGraph const &orig);
00229   MsWksGraph &operator=(MsWksGraph const &orig);
00230 
00231 protected:
00232   //
00233   // data
00234   //
00236   MWAWParserStatePtr m_parserState;
00237 
00239   shared_ptr<MsWksGraphInternal::State> m_state;
00240 
00242   MWAWParser *m_mainParser;
00244   MsWksDocument &m_document;
00245 
00247   shared_ptr<MsWksTable> m_tableParser;
00248 };
00249 #endif
00250 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: