ClarisWksStyleManager.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 AppleWorks/ClarisWorks parser
00036  *
00037  */
00038 #ifndef CLARIS_WKS_STYLE_MANAGER
00039 #  define CLARIS_WKS_STYLE_MANAGER
00040 
00041 #include <iostream>
00042 #include <string>
00043 #include <vector>
00044 
00045 #include "libmwaw_internal.hxx"
00046 
00047 #include "MWAWCell.hxx"
00048 #include "MWAWDebug.hxx"
00049 #include "MWAWGraphicStyle.hxx"
00050 #include "MWAWInputStream.hxx"
00051 
00052 class ClarisWksDocument;
00053 
00054 namespace ClarisWksStyleManagerInternal
00055 {
00056 struct State;
00057 }
00058 
00060 class ClarisWksStyleManager
00061 {
00062 public:
00063   struct CellFormat;
00064   struct KSEN;
00065   struct Style;
00066 public:
00068   ClarisWksStyleManager(MWAWParserStatePtr parserState, ClarisWksDocument *document=0);
00070   ~ClarisWksStyleManager();
00071 
00073   bool readColorList(MWAWEntry const &entry);
00075   bool readPatternList(long endPos=-1);
00077   bool readGradientList(long endPos=-1);
00079   bool readStyles(MWAWEntry const &entry);
00081   bool readFontNames();
00083   bool updateGradient(int grad, MWAWGraphicStyle &style) const;
00085   bool updateWallPaper(int wall, MWAWGraphicStyle &style) const;
00086 
00088   int getFontId(int localId) const;
00090   bool getColor(int id, MWAWColor &col) const;
00092   bool getPattern(int id, MWAWGraphicStyle::Pattern &pattern, float &percent) const;
00094   bool getRulerName(int id, std::string &name) const;
00095 
00097   bool get(int styleId, Style &style) const;
00099   bool get(int fontId, MWAWFont &font) const;
00101   bool get(int formatId, CellFormat &format) const;
00103   bool get(int ksenId, KSEN &ksen) const;
00105   bool get(int graphId, MWAWGraphicStyle &graph) const;
00106 
00108   bool readFont(int id, int fontSize, MWAWFont &font);
00109 
00110 protected:
00112   int version() const;
00113 
00115   bool readGenStyle(int id);
00116 
00118   bool readStylesDef(int N, int fSz);
00120   bool readLookUp(int N, int fSz);
00121 
00122   /* read the STYL CELL sequence */
00123   bool readCellStyles(int N, int fSz);
00125   bool readFontNames(int N, int fSz);
00127   bool readGraphStyles(int N, int fSz);
00129   bool readKSEN(int N, int fSz);
00131   bool readStyleNames(int N, int fSz);
00133   bool readStyleFonts(int N, int fSz);
00134 
00135 protected:
00137   ClarisWksDocument *m_document;
00139   MWAWParserStatePtr m_parserState;
00141   shared_ptr<ClarisWksStyleManagerInternal::State> m_state;
00142 
00143 private:
00144   ClarisWksStyleManager(ClarisWksStyleManager const &orig);
00145   ClarisWksStyleManager &operator=(ClarisWksStyleManager const &orig);
00146 
00147 public:
00149   struct CellFormat : public MWAWCell::Format {
00151     CellFormat(MWAWCell::Format const &format=MWAWCell::Format()) :
00152       MWAWCell::Format(format), m_hAlign(MWAWCell::HALIGN_DEFAULT), m_fileFormat(-1), m_borders(0), m_wrap(false), m_extra("")
00153     {
00154     }
00156     friend std::ostream &operator<<(std::ostream &o, CellFormat const &form);
00158     MWAWCell::HorizontalAlignment m_hAlign;
00160     int m_fileFormat;
00162     int m_borders;
00164     bool m_wrap;
00166     std::string m_extra;
00167   };
00168 
00170   struct KSEN {
00172     KSEN() : m_valign(0), m_lineType(MWAWBorder::Simple), m_lineRepeat(MWAWBorder::Single), m_lines(0), m_extra("")
00173     {
00174     }
00176     friend std::ostream &operator<<(std::ostream &o, KSEN const &ksen);
00178     int m_valign;
00180     MWAWBorder::Style m_lineType;
00182     MWAWBorder::Type m_lineRepeat;
00184     int m_lines;
00186     std::string m_extra;
00187   };
00188 
00190   struct Style {
00192     Style() : m_fontId(-1), m_cellFormatId(-1), m_rulerId(-1), m_rulerPId(-1), m_nameId(-1), m_ksenId(-1), m_graphicId(-1), m_localStyleId(-1), m_styleId(-1), m_extra("")
00193     {
00194     }
00195 
00197     friend std::ostream &operator<<(std::ostream &o, Style const &style);
00198 
00200     int m_fontId;
00202     int m_cellFormatId;
00204     int m_rulerId;
00206     int m_rulerPId;
00208     int m_nameId;
00210     int m_ksenId;
00212     int m_graphicId;
00214     int m_localStyleId;
00216     int m_styleId;
00218     std::string m_extra;
00219   };
00220 };
00221 
00222 #endif