RagTime5StructManager.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 #ifndef RAG_TIME_5_STRUCT_MANAGER
00035 #  define RAG_TIME_5_STRUCT_MANAGER
00036 
00037 #include <ostream>
00038 #include <sstream>
00039 #include <string>
00040 #include <vector>
00041 
00042 #include "libmwaw_internal.hxx"
00043 #include "MWAWDebug.hxx"
00044 #include "MWAWEntry.hxx"
00045 #include "MWAWGraphicStyle.hxx"
00046 
00048 class RagTime5Zone
00049 {
00050 public:
00052   enum FileType { F_Main, F_Data, F_Empty, F_Unknown };
00054   RagTime5Zone(MWAWInputStreamPtr input, libmwaw::DebugFile &asc):
00055     m_fileType(F_Unknown), m_subType(0), m_defPosition(0), m_entry(), m_name(""), m_hiLoEndian(true),
00056     m_entriesList(), m_extra(""), m_isParsed(false),
00057     m_input(input), m_defaultInput(true), m_asciiName(""), m_asciiFile(&asc), m_localAsciiFile()
00058   {
00059     for (int i=0; i<3; ++i) m_ids[i]=m_idsFlag[i]=0;
00060     for (int i=0; i<2; ++i) m_kinds[i]="";
00061     for (int i=0; i<2; ++i) m_variableD[i]=0;
00062   }
00064   virtual ~RagTime5Zone() {}
00066   std::string getZoneName() const;
00068   bool isHeaderZone() const
00069   {
00070     return (m_fileType==F_Data && m_ids[0]==0) ||
00071            (m_fileType==F_Main && (m_ids[0]==1 || m_ids[0]==4 || m_ids[0]==5));
00072   }
00074   std::string getKindLastPart(bool main=true) const
00075   {
00076     std::string res(m_kinds[main ? 0 : 1]);
00077     std::string::size_type pos = res.find_last_of(':');
00078     if (pos == std::string::npos) return res;
00079     return res.substr(pos+1);
00080   }
00081 
00083   friend std::ostream &operator<<(std::ostream &o, RagTime5Zone const &z);
00085   MWAWInputStreamPtr getInput()
00086   {
00087     return m_input;
00088   }
00090   void setInput(MWAWInputStreamPtr input)
00091   {
00092     m_input = input;
00093     m_defaultInput = false;
00094   }
00096   bool isMainInput() const
00097   {
00098     return m_defaultInput;
00099   }
00101   libmwaw::DebugFile &ascii()
00102   {
00103     if (!m_defaultInput && !m_localAsciiFile)
00104       createAsciiFile();
00105     return *m_asciiFile;
00106   }
00108   void setAsciiFileName(std::string const &name)
00109   {
00110     m_asciiName = name;
00111   }
00113   void createAsciiFile();
00114 
00116   FileType m_fileType;
00118   int m_subType;
00120   long m_defPosition;
00122   std::string m_kinds[2];
00124   MWAWEntry m_entry;
00126   std::string m_name;
00128   bool m_hiLoEndian;
00130   int m_ids[3];
00132   int m_idsFlag[3];
00134   std::vector<MWAWEntry> m_entriesList;
00136   std::string m_extra;
00138   int m_variableD[2];
00140   bool m_isParsed;
00141 protected:
00143   MWAWInputStreamPtr m_input;
00145   bool m_defaultInput;
00147   std::string m_asciiName;
00149   libmwaw::DebugFile *m_asciiFile;
00151   shared_ptr<libmwaw::DebugFile> m_localAsciiFile;
00152 private:
00153   RagTime5Zone(RagTime5Zone const &orig);
00154   RagTime5Zone &operator=(RagTime5Zone const &orig);
00155 };
00156 
00158 class RagTime5StructManager
00159 {
00160 public:
00161   struct Field;
00163   RagTime5StructManager();
00165   ~RagTime5StructManager();
00166 
00168   bool readTypeDefinitions(RagTime5Zone &zone);
00170   bool readField(MWAWInputStreamPtr input, long endPos, libmwaw::DebugFile &ascFile,
00171                  Field &field, long fSz=0);
00173   static bool readCompressedLong(MWAWInputStreamPtr &input, long endPos, long &val);
00175   static bool readUnicodeString(MWAWInputStreamPtr input, long endPos, librevenge::RVNGString &string);
00177   static bool readDataIdList(MWAWInputStreamPtr input, int n, std::vector<int> &listIds);
00178 
00180   struct TabStop {
00182     TabStop() : m_position(0), m_type(1), m_leader("")
00183     {
00184     }
00186     friend std::ostream &operator<<(std::ostream &o, TabStop const &tab)
00187     {
00188       o << tab.m_position;
00189       switch (tab.m_type) {
00190       case 1:
00191         break;
00192       case 2:
00193         o << "R";
00194         break;
00195       case 3:
00196         o << "C";
00197         break;
00198       case 4:
00199         o << "D";
00200         break;
00201       case 5: // Kintou Waritsuke: sort of center
00202         o << "K";
00203         break;
00204       default:
00205         o << ":#type=" << tab.m_type;
00206         break;
00207       }
00208       if (!tab.m_leader.empty())
00209         o << ":leader=" << tab.m_leader.cstr();
00210       return o;
00211     }
00213     float m_position;
00215     int m_type;
00217     librevenge::RVNGString m_leader;
00218   };
00220   struct Field {
00222     enum Type { T_Unknown, T_Bool, T_Double, T_Long, T_2Long, T_FieldList, T_LongList, T_DoubleList, T_TabList,
00223                 T_Code, T_Color, T_CondColor, T_PrintInfo, T_String, T_Unicode, T_ZoneId, T_LongDouble, T_Unstructured
00224               };
00225 
00227     Field() : m_type(T_Unknown), m_fileType(0), m_name(""), m_doubleValue(0), m_color(), m_string(""),
00228       m_longList(), m_doubleList(), m_numLongByData(1), m_tabList(), m_fieldList(), m_entry(), m_extra("")
00229     {
00230       for (int i=0; i<2; ++i) m_longValue[i]=0;
00231     }
00233     ~Field()
00234     {
00235     }
00237     friend std::ostream &operator<<(std::ostream &o, Field const &field);
00239     Type m_type;
00241     long m_fileType;
00243     std::string m_name;
00245     long m_longValue[2];
00247     double m_doubleValue;
00249     MWAWColor m_color;
00251     librevenge::RVNGString m_string;
00253     std::vector<long> m_longList;
00255     std::vector<double> m_doubleList;
00257     int m_numLongByData;
00259     std::vector<TabStop> m_tabList;
00261     std::vector<Field> m_fieldList;
00263     MWAWEntry m_entry;
00265     std::string m_extra;
00266   };
00268   struct FieldParser {
00270     FieldParser(std::string const &zoneName) : m_regroupFields(false), m_name(zoneName) {}
00272     virtual ~FieldParser() {}
00274     virtual std::string getZoneName() const
00275     {
00276       return m_name;
00277     }
00279     virtual std::string getZoneName(int n) const
00280     {
00281       std::stringstream s;
00282       s << m_name << "-" << n;
00283       return s.str();
00284     }
00286     virtual bool parseField(Field &field, RagTime5Zone &/*zone*/, int /*n*/, libmwaw::DebugStream &f)
00287     {
00288       f << field;
00289       return true;
00290     }
00292     bool m_regroupFields;
00293   protected:
00295     std::string m_name;
00296   private:
00297     FieldParser(FieldParser const &orig);
00298     FieldParser &operator=(FieldParser const &orig);
00299   };
00301   struct DataParser {
00303     DataParser(std::string const &zoneName) : m_name(zoneName)  {}
00305     virtual ~DataParser() {}
00307     virtual std::string getZoneName() const
00308     {
00309       return m_name;
00310     }
00312     virtual std::string getZoneName(int n) const
00313     {
00314       std::stringstream s;
00315       s << m_name << "-" << n;
00316       return s.str();
00317     }
00319     virtual bool parseData(MWAWInputStreamPtr &/*input*/, long /*endPos*/, RagTime5Zone &/*zone*/, int /*n*/, libmwaw::DebugStream &/*f*/)
00320     {
00321       return true;
00322     }
00323   protected:
00325     std::string m_name;
00326   private:
00327     DataParser(DataParser const &orig);
00328     DataParser &operator=(DataParser const &orig);
00329   };
00331   struct GraphicStyle {
00333     GraphicStyle() : m_parentId(-1), m_width(-1), m_dash(), m_pattern(), m_gradient(0), m_gradientRotation(0), m_gradientCenter(0.5f,0.5f),
00334       m_position(2), m_cap(1), m_mitter(1), m_limitPercent(1), m_hidden(false), m_extra("")
00335     {
00336       m_colors[0]=MWAWColor::black();
00337       m_colors[1]=MWAWColor::white();
00338       m_colorsAlpha[0]=m_colorsAlpha[1]=1;
00339     }
00341     virtual ~GraphicStyle()
00342     {
00343     }
00345     bool isDefault() const
00346     {
00347       return m_parentId<0 && m_width<0 && m_dash.empty() && !m_pattern &&
00348              m_gradient==0 && m_gradientRotation<=0 && m_gradientRotation>=0 && m_gradientCenter!=MWAWVec2f(0.5f, 0.5f) &&
00349              m_position==2 && m_cap==1 && m_mitter==1 &&
00350              m_colors[0].isBlack() && m_colors[1].isWhite() && m_colorsAlpha[0]>=1 && m_colorsAlpha[1]>=1 &&
00351              m_limitPercent>=1 && m_limitPercent<=1 && !m_hidden && m_extra.empty();
00352     }
00354     friend std::ostream &operator<<(std::ostream &o, GraphicStyle const &style);
00356     bool read(MWAWInputStreamPtr &input, Field const &field);
00358     int m_parentId;
00360     float m_width;
00362     MWAWColor m_colors[2];
00364     float m_colorsAlpha[2];
00366     std::vector<long> m_dash;
00368     shared_ptr<MWAWGraphicStyle::Pattern> m_pattern;
00370     int m_gradient;
00372     float m_gradientRotation;
00374     MWAWVec2f m_gradientCenter;
00376     int m_position;
00378     int m_cap;
00380     int m_mitter;
00382     float m_limitPercent;
00384     bool m_hidden;
00386     std::string m_extra;
00387   };
00389   struct TextStyle {
00391     TextStyle() : m_linkIdList(),
00392       m_dateStyleId(-1), m_graphStyleId(-1), m_graphLineStyleId(-1), m_keepWithNext(false), m_justify(-1), m_breakMethod(-1), m_tabList(),
00393       m_fontName(""), m_fontId(-1), m_fontSize(-1), m_scriptPosition(0), m_fontScaling(-1), m_underline(-1), m_caps(-1), m_language(-1),
00394       m_numColumns(-1), m_columnGap(-1), m_extra("")
00395     {
00396       m_parentId[0]=m_parentId[1]=-1;
00397       m_fontFlags[0]=m_fontFlags[1]=0;
00398       for (int i=0; i<3; ++i) {
00399         m_margins[i]=-1;
00400         m_spacings[i]=-1;
00401         m_spacingUnits[i]=-1;
00402         m_letterSpacings[i]=-1;
00403       }
00404     }
00406     virtual ~TextStyle()
00407     {
00408     }
00410     bool isDefault() const
00411     {
00412       if (m_parentId[0]>=0 || m_parentId[1]>=0 || !m_linkIdList.empty() ||
00413           m_dateStyleId>=0 || m_graphStyleId>=0 || m_graphLineStyleId>=0 ||
00414           m_keepWithNext.isSet() || m_justify>=0 || m_breakMethod>=0 || !m_tabList.empty() ||
00415           !m_fontName.empty() || m_fontId>=0 || m_fontSize>=0 || m_fontFlags[0] || m_fontFlags[1] || m_scriptPosition.isSet() ||
00416           m_fontScaling>=0 || m_underline>=0 || m_caps>=0 || m_language>=0 ||
00417           m_numColumns>=0 || m_columnGap>=0 || !m_extra.empty())
00418         return false;
00419       for (int i=0; i<3; ++i) {
00420         if (m_margins[i]>=0 || m_spacings[i]>=0 || m_spacingUnits[i]>=0 || m_letterSpacings[i]>=0)
00421           return false;
00422       }
00423       return true;
00424     }
00426     friend std::ostream &operator<<(std::ostream &o, TextStyle const &style);
00428     bool read(MWAWInputStreamPtr &input, Field const &field);
00430     int m_parentId[2];
00432     std::vector<int> m_linkIdList;
00434     int m_dateStyleId;
00436     int m_graphStyleId;
00438     int m_graphLineStyleId;
00439 
00440     // paragraph
00441 
00443     MWAWVariable<bool> m_keepWithNext;
00445     int m_justify;
00447     double m_spacings[3];
00449     int m_spacingUnits[3];
00451     int m_breakMethod;
00453     double m_margins[3];
00455     std::vector<TabStop> m_tabList;
00456 
00457     // character
00458 
00460     librevenge::RVNGString m_fontName;
00462     long m_fontId;
00464     float m_fontSize;
00466     uint32_t m_fontFlags[2];
00468     MWAWVariable<float> m_scriptPosition;
00470     float m_fontScaling;
00472     int m_underline;
00474     int m_caps;
00476     int m_language;
00478     double m_letterSpacings[3];
00479 
00480     // column
00481 
00483     int m_numColumns;
00485     double m_columnGap;
00486 
00488     std::string m_extra;
00489   };
00490 
00491 private:
00492   RagTime5StructManager(RagTime5StructManager const &orig);
00493   RagTime5StructManager operator=(RagTime5StructManager const &orig);
00494 };
00495 
00496 #endif
00497 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: