ClarisWksStruct.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  * Structures used by Claris Works parser
00036  *
00037  */
00038 #ifndef CLARIS_WKS_STRUCT
00039 #  define CLARIS_WKS_STRUCT
00040 
00041 #include <iostream>
00042 #include <set>
00043 #include <vector>
00044 
00045 #include "libmwaw_internal.hxx"
00046 
00047 class MWAWParserState;
00048 
00050 namespace ClarisWksStruct
00051 {
00054 bool readIntZone(MWAWParserState &parserState, char const *zoneName, bool hasEntete, int fSz, std::vector<int> &res);
00056 bool readStructZone(MWAWParserState &parserState, char const *zoneName, bool hasEntete);
00058 struct DSET {
00059   struct Child;
00060 
00062   enum Position { P_Main=0, P_Header, P_Footer, P_Frame, P_Footnote, P_Table,
00063                   P_GraphicMaster,
00064                   P_Slide, P_SlideNote, P_SlideThumbnail, P_SlideMaster, P_Unknown
00065                 };
00067   enum ChildType { C_Zone, C_SubText, C_Graphic, C_Unknown };
00068 
00070   DSET() : m_size(0), m_numData(0), m_dataSz(-1), m_headerSz(-1),
00071     m_position(P_Unknown), m_fileType(-1),
00072     m_page(-1), m_box(), m_pageDimension(0,0), m_id(0), m_fathersList(),
00073     m_beginSelection(0), m_endSelection(-1), m_textType(0),
00074     m_childs(), m_otherChilds(), m_parsed(false), m_internal(0)
00075   {
00076     for (int i = 0; i < 4; i++) m_flags[i] = 0;
00077   }
00078 
00080   virtual ~DSET() {}
00081 
00083   bool isHeaderFooter() const
00084   {
00085     return m_position==P_Header||m_position==P_Footer;
00086   }
00087 
00089   bool isSlide() const
00090   {
00091     return m_position==P_Slide || m_position==P_SlideNote || m_position==P_SlideThumbnail || m_position==P_SlideMaster;
00092   }
00094   MWAWBox2f getBdBox() const
00095   {
00096     MWAWVec2f minPt(m_box[0][0], m_box[0][1]);
00097     MWAWVec2f maxPt(m_box[1][0], m_box[1][1]);
00098     for (int c=0; c<2; ++c) {
00099       if (m_box.size()[c]>=0) continue;
00100       minPt[c]=m_box[1][c];
00101       maxPt[c]=m_box[0][c];
00102     }
00103     return MWAWBox2f(minPt,maxPt);
00104   }
00106   int getMaximumPage() const
00107   {
00108     if (m_position==ClarisWksStruct::DSET::P_Slide)
00109       return m_page;
00110     if (m_position!=ClarisWksStruct::DSET::P_Main)
00111       return 0;
00112     int nPages=m_page;
00113     for (size_t b=0; b < m_childs.size(); b++) {
00114       if (m_childs[b].m_page > nPages)
00115         nPages=m_childs[b].m_page;
00116     }
00117     return nPages;
00118   }
00119 
00121   virtual void removeChild(int cId, bool normalChild);
00123   virtual void removeChild(int cId);
00125   void updateChildPositions(MWAWVec2f const &pageDim, float formLength, int numHorizontalPages=1);
00127   void findForbiddenPagesBreaking(float pageDim, float formDim, int dim, std::set<int> &forbiddenPageBreak) const;
00129   MWAWBox2i getUnionChildBox() const;
00130 
00132   friend std::ostream &operator<<(std::ostream &o, DSET const &doc);
00133 
00135   long m_size;
00137   long m_numData;
00139   long m_dataSz;
00141   long m_headerSz;
00142 
00144   Position m_position;
00146   int m_fileType;
00147 
00149   int m_page;
00151   MWAWBox2f m_box;
00153   MWAWVec2f m_pageDimension;
00154 
00156   int m_id;
00158   std::set<int> m_fathersList;
00159 
00161   int m_beginSelection;
00163   int m_endSelection;
00164 
00166   int m_textType;
00167 
00169   int m_flags[4];
00170 
00172   std::vector<Child> m_childs;
00174   std::vector<int> m_otherChilds;
00175 
00177   mutable bool m_parsed;
00179   mutable int m_internal;
00180 
00182   struct Child {
00184     Child() : m_type(C_Unknown), m_id(-1), m_posC(-1), m_page(-1), m_box()
00185     {
00186     }
00188     MWAWBox2f getBdBox() const
00189     {
00190       MWAWVec2f minPt(m_box[0][0], m_box[0][1]);
00191       MWAWVec2f maxPt(m_box[1][0], m_box[1][1]);
00192       for (int c=0; c<2; ++c) {
00193         if (m_box.size()[c]>=0) continue;
00194         minPt[c]=m_box[1][c];
00195         maxPt[c]=m_box[0][c];
00196       }
00197       return MWAWBox2f(minPt,maxPt);
00198     }
00199 
00201     friend std::ostream &operator<<(std::ostream &o, Child const &ch)
00202     {
00203       switch (ch.m_type) {
00204       case C_SubText:
00205         o << "text,";
00206         break;
00207       case C_Zone:
00208         o << "zone,";
00209         break;
00210       case C_Graphic:
00211         o << "graphic,";
00212         break;
00213       case C_Unknown:
00214         o << "#type,";
00215       default:
00216         break;
00217       }
00218       if (ch.m_id != -1) o << "id=" << ch.m_id << ",";
00219       if (ch.m_posC != -1) o << "posC=" << ch.m_posC << ",";
00220       if (ch.m_page>=0) o << "pg=" << ch.m_page << ",";
00221       if (ch.m_box.size().x() > 0 || ch.m_box.size().y() > 0)
00222         o << "box=" << ch.m_box << ",";
00223       return o;
00224     }
00225 
00227     ChildType m_type;
00229     int m_id;
00231     long m_posC;
00233     int m_page;
00235     MWAWBox2f m_box;
00236   };
00237 };
00238 }
00239 
00240 #endif
00241 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: