MsWrdStruct.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  * Class to read/store the MsWrd structures
00036  */
00037 
00038 #ifndef MS_WRD_STRUCT
00039 #  define MS_WRD_STRUCT
00040 
00041 #include <iostream>
00042 #include <string>
00043 #include <vector>
00044 
00045 #include "libmwaw_internal.hxx"
00046 
00047 #include "MWAWFont.hxx"
00048 #include "MWAWParagraph.hxx"
00049 
00051 namespace MsWrdStruct
00052 {
00054 MWAWBorder getBorder(int val, std::string &extra);
00055 
00057 struct Font {
00058   enum { NumFlags =9 };
00059 
00061   Font(): m_font(MWAWFont(-1,0)), m_size(0), m_value(0), m_picturePos(0), m_unknown(0), m_extra("")
00062   {
00063     for (int i = 0; i < NumFlags; i++) m_flags[i]=MWAWVariable<int>(0);
00064   }
00065 
00067   void insert(Font const &font, Font const *styleFont=0);
00068 
00070   void updateFontToFinalState(Font const *styleFont=0);
00071 
00073   friend std::ostream &operator<<(std::ostream &o, Font const &font);
00074 
00076   int cmp(Font const &oth) const
00077   {
00078     int diff = m_font.get().cmp(oth.m_font.get());
00079     if (diff) return diff;
00080     if (m_size.get() < oth.m_size.get()) return -1;
00081     if (m_size.get() > oth.m_size.get()) return 1;
00082     diff = m_value.get()-oth.m_value.get();
00083     if (diff) return diff;
00084     for (int i = 0; i < NumFlags; i++) {
00085       diff = m_flags[i].get()-oth.m_flags[i].get();
00086       if (diff) return diff;
00087     }
00088     if (m_picturePos.get()<oth.m_picturePos.get()) return -1;
00089     if (m_picturePos.get()>oth.m_picturePos.get()) return 1;
00090     diff = m_unknown.get()-oth.m_unknown.get();
00091     if (diff) return diff;
00092     return 0;
00093   }
00095   MWAWVariable<MWAWFont> m_font;
00097   MWAWVariable<float> m_size;
00099   MWAWVariable<int> m_value;
00101   MWAWVariable<int> m_flags[NumFlags];
00103   MWAWVariable<long> m_picturePos;
00105   MWAWVariable<int> m_unknown;
00107   std::string m_extra;
00108 };
00109 
00111 struct Section {
00113   Section() : m_id(-1), m_type(0), m_paragraphId(-9999), m_col(1),
00114     m_colSep(0.5), m_colBreak(false), m_flag(0), m_extra("")
00115   {
00116   }
00118   MWAWSection getSection(double pageWidth) const;
00119 
00121   void insert(Section const &sec)
00122   {
00123     m_id.insert(sec.m_id);
00124     m_type.insert(sec.m_type);
00125     m_paragraphId.insert(sec.m_paragraphId);
00126     m_col.insert(sec.m_col);
00127     m_colSep.insert(sec.m_colSep);
00128     m_colBreak.insert(sec.m_colBreak);
00129     m_flag.insert(sec.m_flag);
00130     m_extra+=sec.m_extra;
00131   }
00133   bool read(MWAWInputStreamPtr &input, long endPos);
00135   bool readV3(MWAWInputStreamPtr &input, long endPos);
00136 
00138   friend std::ostream &operator<<(std::ostream &o, Section const &section);
00139 
00141   MWAWVariable<int> m_id;
00143   MWAWVariable<int> m_type;
00145   MWAWVariable<int> m_paragraphId;
00147   MWAWVariable<int> m_col;
00149   MWAWVariable<float> m_colSep;
00151   MWAWVariable<bool> m_colBreak;
00153   MWAWVariable<int> m_flag;
00155   std::string m_extra;
00156 };
00157 
00159 struct Table {
00160   struct Cell;
00162   Table() : m_height(0), m_justify(MWAWParagraph::JustificationLeft), m_indent(0),
00163     m_columns(), m_columnsWidthMod(), m_cells(), m_extra("")
00164   {
00165   }
00167   void insert(Table const &table);
00169   bool read(MWAWInputStreamPtr &input, long endPos);
00171   MWAWVariable<Cell> &getCell(int id);
00172 
00174   friend std::ostream &operator<<(std::ostream &o, Table const &table);
00175 
00177   MWAWVariable<float> m_height;
00179   MWAWVariable<MWAWParagraph::Justification> m_justify;
00181   MWAWVariable<float> m_indent;
00183   MWAWVariable<std::vector<float> > m_columns;
00185   MWAWVariable<std::vector<float> > m_columnsWidthMod;
00187   std::vector<MWAWVariable<Cell> > m_cells;
00189   std::string m_extra;
00190 
00192   struct Cell {
00194     Cell() : m_borders(), m_backColor(1.0f), m_extra("")
00195     {
00196     }
00198     void insert(Cell const &cell)
00199     {
00200       size_t cNumBorders = cell.m_borders.size();
00201       if (cNumBorders > m_borders.size())
00202         m_borders.resize(cNumBorders);
00203       for (size_t i=0; i < cNumBorders; i++)
00204         if (cell.m_borders[i].isSet()) m_borders[i]=*cell.m_borders[i];
00205       m_backColor.insert(cell.m_backColor);
00206       m_extra+=cell.m_extra;
00207     }
00209     bool hasBorders() const
00210     {
00211       for (size_t i = 0; i < m_borders.size(); i++)
00212         if (m_borders[i].isSet() && m_borders[i]->m_style != MWAWBorder::None)
00213           return true;
00214       return false;
00215     }
00217     friend std::ostream &operator<<(std::ostream &o, Cell const &cell);
00219     std::vector<MWAWVariable<MWAWBorder> > m_borders;
00221     MWAWVariable<float> m_backColor;
00223     std::string m_extra;
00224   };
00225 };
00226 
00228 struct ParagraphInfo {
00230   ParagraphInfo() : m_type(0), m_dim(), m_numLines(-1), m_error("")
00231   {
00232   }
00234   bool isLineSet() const
00235   {
00236     return *m_numLines!=0;
00237   }
00239   bool isEmpty() const
00240   {
00241     if (*m_numLines || *m_type) return false;
00242     if (!m_dim.isSet()) return true;
00243     if ((*m_dim)[0] > 0 || (*m_dim)[1] > 0) return false;
00244     return true;
00245   }
00247   bool read(MWAWInputStreamPtr &input, long endPos, int vers);
00249   friend std::ostream &operator<<(std::ostream &o, ParagraphInfo const &pInfo)
00250   {
00251     // find also pInfo.m_type&0x40 : ?
00252     if (*pInfo.m_type&0xd0) o << "type?=" << ((*pInfo.m_type&0xd0)>>4) << ",";
00253     if (*pInfo.m_type&0x0f) o << "#unkn=" << (*pInfo.m_type&0xf) << ",";
00254     if (pInfo.m_dim.isSet()) {
00255       if ((*pInfo.m_dim)[0] > 0)
00256         o << "width=" << (*pInfo.m_dim)[0] << ",";
00257       if ((*pInfo.m_dim)[1] > 0) {
00258         o << "height=" << (*pInfo.m_dim)[1];
00259         if (*pInfo.m_type&0x20)
00260           o << "[total]";
00261         o << ",";
00262       }
00263     }
00264     if (pInfo.m_numLines.isSet() && *pInfo.m_numLines!=-1 && *pInfo.m_numLines!=1)
00265       o << "nLines=" << *pInfo.m_numLines << ",";
00266     if (pInfo.m_error.length()) o << pInfo.m_error << ",";
00267     return o;
00268   }
00270   void insert(ParagraphInfo const &pInfo);
00272   MWAWVariable<int> m_type;
00274   MWAWVariable<MWAWVec2f> m_dim;
00276   MWAWVariable<int> m_numLines;
00278   std::string m_error;
00279 };
00280 
00282 struct Paragraph : public MWAWParagraph {
00284   Paragraph(int version) : MWAWParagraph(), m_version(version), m_styleId(-1000),
00285     m_interline(0), m_deletedTabs(), m_info(), m_font(), m_modFont(), m_section(),
00286     m_bordersStyle(), m_inCell(false), m_tableDef(false), m_table()
00287   {
00288     m_tabsRelativeToLeftMargin=false;
00289   }
00291   void insert(Paragraph const &para, bool insertModif=true);
00293   bool read(MWAWInputStreamPtr &input, long endPos);
00295   void updateParagraphToFinalState(Paragraph const *style=0);
00297   bool getFont(Font &font, Font const *styleFont=0) const;
00299   bool inTable() const
00300   {
00301     return m_inCell.get();
00302   }
00304   friend std::ostream &operator<<(std::ostream &o, Paragraph const &ind);
00305 
00307   void print(std::ostream &o, MWAWFontConverterPtr converter) const;
00308 
00310   int getNumLines() const
00311   {
00312     return m_info.get().m_numLines.get();
00313   }
00315   int m_version;
00317   MWAWVariable<int> m_styleId;
00319   MWAWVariable<double> m_interline;
00321   std::vector<float> m_deletedTabs;
00323   MWAWVariable<ParagraphInfo> m_info;
00325   MWAWVariable<Font> m_font, m_modFont ;
00327   MWAWVariable<Section> m_section;
00329   MWAWVariable<MWAWBorder> m_bordersStyle;
00331   MWAWVariable<bool> m_inCell;
00333   MWAWVariable<bool> m_tableDef;
00335   MWAWVariable<Table> m_table;
00336 };
00337 }
00338 #endif
00339 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: