CWStyleManager.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 used to read main style by Claris Works parser
00036  *
00037  */
00038 #ifndef CW_STYLE_MANAGER
00039 #  define CW_STYLE_MANAGER
00040 
00041 #include <iostream>
00042 #include <string>
00043 #include <vector>
00044 
00045 #include "libmwaw_internal.hxx"
00046 
00047 #include "MWAWDebug.hxx"
00048 #include "MWAWGraphicStyle.hxx"
00049 #include "MWAWInputStream.hxx"
00050 
00051 class CWParser;
00052 
00053 namespace CWStyleManagerInternal
00054 {
00055 struct State;
00056 }
00057 
00059 class CWStyleManager
00060 {
00061 public:
00062   struct CellFormat;
00063   struct KSEN;
00064   struct Style;
00065 public:
00067   CWStyleManager(CWParser &mainParser);
00069   ~CWStyleManager();
00070 
00072   bool readColorList(MWAWEntry const &entry);
00074   bool readPatternList(long endPos=-1);
00076   bool readGradientList(long endPos=-1);
00078   bool readStyles(MWAWEntry const &entry);
00080   bool updateGradient(int grad, MWAWGraphicStyle &style) const;
00082   bool updateWallPaper(int wall, MWAWGraphicStyle &style) const;
00083 
00085   int getFontId(int localId) const;
00087   bool getColor(int id, MWAWColor &col) const;
00089   bool getPattern(int id, MWAWGraphicStyle::Pattern &pattern, float &percent) const;
00090 
00092   bool get(int styleId, Style &style) const;
00094   bool get(int fontId, MWAWFont &font) const;
00096   bool get(int formatId, CellFormat &format) const;
00098   bool get(int ksenId, KSEN &ksen) const;
00100   bool get(int graphId, MWAWGraphicStyle &graph) const;
00101 
00103   bool readFont(int id, int fontSize, MWAWFont &font);
00104 
00105 protected:
00107   int version() const;
00108 
00110   bool readGenStyle(int id);
00111 
00113   bool readStylesDef(int N, int fSz);
00115   bool readLookUp(int N, int fSz);
00116 
00117   /* read the STYL CELL sequence */
00118   bool readCellStyles(int N, int fSz);
00120   bool readFontNames(int N, int fSz);
00122   bool readGraphStyles(int N, int fSz);
00124   bool readKSEN(int N, int fSz);
00126   bool readStyleNames(int N, int fSz);
00128   bool readStyleFonts(int N, int fSz);
00129 
00130 protected:
00132   MWAWParserStatePtr m_parserState;
00134   CWParser *m_mainParser;
00136   shared_ptr<CWStyleManagerInternal::State> m_state;
00137 
00138 private:
00139   CWStyleManager(CWStyleManager const &orig);
00140   CWStyleManager &operator=(CWStyleManager const &orig);
00141 
00142 public:
00144   struct CellFormat {
00146     CellFormat() : m_justify(0), m_format(-1), m_numDigits(2), m_separateThousand(false), m_parentheseNegatif(false), m_wrap(false), m_extra("") {
00147     }
00149     friend std::ostream &operator<<(std::ostream &o, CellFormat const &form);
00151     int m_justify;
00153     int m_format;
00155     int m_numDigits;
00157     bool m_separateThousand;
00159     bool m_parentheseNegatif;
00161     bool m_wrap;
00163     std::string m_extra;
00164   };
00165 
00167   struct KSEN {
00169     KSEN() : m_valign(0), m_lineType(MWAWBorder::Simple), m_lineRepeat(MWAWBorder::Single), m_lines(0), m_extra("") {
00170     }
00172     friend std::ostream &operator<<(std::ostream &o, KSEN const &ksen);
00174     int m_valign;
00176     MWAWBorder::Style m_lineType;
00178     MWAWBorder::Type m_lineRepeat;
00180     int m_lines;
00182     std::string m_extra;
00183   };
00184 
00186   struct Style {
00188     Style() : m_fontId(-1), m_cellFormatId(-1), m_rulerId(-1), m_rulerHash(-1), m_ksenId(-1), m_graphicId(-1), m_localStyleId(-1), m_styleId(-1), m_extra("") {
00189     }
00190 
00192     friend std::ostream &operator<<(std::ostream &o, Style const &style);
00193 
00195     int m_fontId;
00197     int m_cellFormatId;
00199     int m_rulerId;
00201     int m_rulerHash;
00203     int m_ksenId;
00205     int m_graphicId;
00207     int m_localStyleId;
00209     int m_styleId;
00211     std::string m_extra;
00212   };
00213 };
00214 
00215 #endif