MSKGraph.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 MSK_MWAW_GRAPH
00039 #  define MSK_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 MSKGraphInternal
00052 {
00053 struct GroupZone;
00054 struct TextBox;
00055 struct Zone;
00056 
00057 struct State;
00058 
00059 class SubDocument;
00060 }
00061 
00062 class MSKParser;
00063 class MSK3Parser;
00064 class MSK4Zone;
00065 class MSKTable;
00066 
00068 class MSKGraph
00069 {
00070   friend class MSK3Parser;
00071   friend class MSK4Zone;
00072   friend class MSKTable;
00073   friend class MSKGraphInternal::SubDocument;
00074 public:
00075   struct Style;
00077   MSKGraph(MSKParser &parser);
00079   virtual ~MSKGraph();
00080 
00082   int version() const;
00083 
00085   int numPages(int zoneId) const;
00086 
00091   void send(int id, MWAWPosition const &pos);
00092 
00094   void sendAll(int zoneId, bool mainZone);
00095 
00097   struct SendData {
00099     SendData() : m_type(RBDR), m_id(-1), m_anchor(MWAWPosition::Char), m_page(-1), m_size() {
00100     }
00102     enum Type { RBDR, RBIL, ALL } m_type;
00104     int m_id;
00106     MWAWPosition::AnchorTo m_anchor;
00108     int m_page;
00110     Vec2i m_size;
00111   };
00113   void sendObjects(SendData const what);
00114 
00116   void computePositions(int zoneId, std::vector<int> &linesHeight, std::vector<int> &pagesHeight);
00117 
00118 protected:
00120   void flushExtra();
00121 
00122   //
00123   // Intermediate level
00124   //
00125 
00127   bool readPictHeader(MSKGraphInternal::Zone &pict);
00129   bool readGradient(Style &style);
00131   int getEntryPictureV1(int zoneId, MWAWEntry &zone, bool autoSend=true);
00132 
00134   int getEntryPicture(int zoneId, MWAWEntry &zone, bool autoSend=true, int order=-1000);
00135 
00136   // version 4 file
00137 
00139   bool readRB(MWAWInputStreamPtr input, MWAWEntry const &entry);
00140 
00141 
00143   bool readPictureV4(MWAWInputStreamPtr input, MWAWEntry const &entry);
00144 
00146   bool readText(MSKGraphInternal::TextBox &textBox);
00148   void sendTextBox(int zId);
00150   void checkTextBoxLinks(int zId);
00151 
00152   // interface function
00153 
00155   bool getZoneGraphicStyle(int zoneId, MWAWGraphicStyle &style) const;
00157   bool getZonePosition(int zoneId, MWAWPosition::AnchorTo anchor, MWAWPosition &pos) const;
00158 
00160   void sendFrameText(MWAWEntry const &entry, std::string const &frame);
00161 
00163   void sendTable(int id);
00164 
00166   void sendChart(int zoneId);
00167 
00168   //
00169   // low level
00170   //
00172   shared_ptr<MSKGraphInternal::GroupZone> readGroup(MSKGraphInternal::Zone &group);
00174   void sendGroup(int zoneId, MWAWPosition const &pos);
00176   void sendGroupChild(int zoneId, MWAWPosition const &pos);
00178   bool canCreateGraphic(MSKGraphInternal::GroupZone const &group) const;
00180   void sendGroup(MSKGraphInternal::GroupZone const &group, MWAWGraphicListenerPtr &listener) const;
00182   bool readFont(MWAWFont &font);
00183 
00184 public:
00186   struct Style : public MWAWGraphicStyle {
00188     Style() : MWAWGraphicStyle(), m_baseLineColor(MWAWColor::black()), m_baseSurfaceColor(MWAWColor::white()) {
00189       m_fillRuleEvenOdd=true;
00190     }
00192     friend std::ostream &operator<<(std::ostream &o, Style const &st) {
00193       o << static_cast<MWAWGraphicStyle const &>(st);
00194       if (st.m_baseLineColor != st.m_lineColor)
00195         o << "lineColor[base]=" << st.m_baseLineColor << ",";
00196       if (st.m_baseSurfaceColor != st.m_surfaceColor)
00197         o << "surfaceColor[base]=" << st.m_baseSurfaceColor << ",";
00198 
00199       return o;
00200     }
00201 
00203     MWAWColor m_baseLineColor;
00205     MWAWColor m_baseSurfaceColor;
00206   };
00207 
00208 private:
00209   MSKGraph(MSKGraph const &orig);
00210   MSKGraph &operator=(MSKGraph const &orig);
00211 
00212 protected:
00213   //
00214   // data
00215   //
00217   MWAWParserStatePtr m_parserState;
00218 
00220   shared_ptr<MSKGraphInternal::State> m_state;
00221 
00223   MSKParser *m_mainParser;
00224 
00226   shared_ptr<MSKTable> m_tableParser;
00227 };
00228 #endif
00229 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: