]> git.lyx.org Git - lyx.git/blob - src/lyxtextclass.h
setFont rework + some code simplification
[lyx.git] / src / lyxtextclass.h
1 // -*- C++ -*-
2 /**
3  * \file lyxtextclass.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * Full author contact details are available in file CREDITS.
8  */
9
10 #ifndef LYXTEXTCLASS_H
11 #define LYXTEXTCLASS_H
12
13 #include "lyxlayout.h"
14 #include "lyxlayout_ptr_fwd.h"
15
16 #include <boost/shared_ptr.hpp>
17
18 #include <vector>
19
20 class LyXLex;
21 class Counters;
22 class FloatList;
23
24
25 ///
26 struct CharStyle {
27         std::string name;
28         std::string latextype;
29         std::string latexname;
30         LyXFont font;
31         LyXFont labelfont;
32         std::string preamble;
33 };
34
35
36 /// List of semantically defined character style insets
37 typedef std::vector<CharStyle> CharStyles;
38
39
40 /// Stores the layout specification of a LyX document class.
41 class LyXTextClass {
42 public:
43         /// The individual styles comprising the document class
44         typedef std::vector<LyXLayout_ptr> LayoutList;
45         /// Enumerate the paragraph styles.
46         typedef LayoutList::const_iterator const_iterator;
47         /// Construct a layout with default values. Actual values loaded later.
48         explicit
49         LyXTextClass(std::string const & = std::string(),
50                      std::string const & = std::string(),
51                      std::string const & = std::string(),
52                      bool = false);
53
54         /// check whether the TeX class is available
55         bool isTeXClassAvailable() const;
56
57         /// paragraph styles begin iterator.
58         const_iterator begin() const { return layoutlist_.begin(); }
59         /// paragraph styles end iterator
60         const_iterator end() const { return layoutlist_.end(); }
61
62         /// Performs the read of the layout file.
63         bool Read(std::string const & filename, bool merge = false);
64         ///
65         void readOutputType(LyXLex &);
66         ///
67         void readTitleType(LyXLex &);
68         ///
69         void readMaxCounter(LyXLex &);
70         ///
71         void readClassOptions(LyXLex &);
72         ///
73         void readCharStyle(LyXLex &, std::string const &);
74         ///
75         void readFloat(LyXLex &);
76         ///
77         void readCounter(LyXLex &);
78         ///
79         bool hasLayout(std::string const & name) const;
80
81         ///
82         LyXLayout_ptr const & operator[](std::string const & vname) const;
83
84         /// Sees to that the textclass structure has been loaded
85         bool load() const;
86
87         /// the list of floats defined in the document class
88         FloatList & floats();
89         /// the list of floats defined in the document class
90         FloatList const & floats() const;
91         /// The Counters present in this document class.
92         Counters & counters() const;
93         /// CharStyles of this doc class
94         CharStyles & charstyles() const { return charstylelist_; };
95         /// Retrieve element of name s:
96         CharStyles::iterator charstyle(std::string const & s) const;
97         ///
98         std::string const & defaultLayoutName() const;
99         ///
100         LyXLayout_ptr const & defaultLayout() const;
101         ///
102         std::string const & name() const;
103         ///
104         std::string const & latexname() const;
105         ///
106         std::string const & description() const;
107         ///
108         std::string const & opt_fontsize() const;
109         ///
110         std::string const & opt_pagestyle() const;
111         ///
112         std::string const & options() const;
113         ///
114         std::string const & pagestyle() const;
115         ///
116         std::string const & preamble() const;
117
118         /// Packages that are already loaded by the class
119         enum Provides {
120                 ///
121                 nothing = 0,
122                 ///
123                 amsmath = 1,
124                 ///
125                 makeidx = 2,
126                 ///
127                 url = 4,
128                 ///
129                 natbib = 8
130         };
131         ///
132         bool provides(Provides p) const;
133
134         ///
135         unsigned int columns() const;
136         ///
137         enum PageSides {
138                 ///
139                 OneSide,
140                 ///
141                 TwoSides
142         };
143         ///
144         PageSides sides() const;
145         ///
146         int secnumdepth() const;
147         ///
148         int tocdepth() const;
149
150         /// Can be LaTeX, LinuxDoc, etc.
151         OutputType outputType() const;
152
153         ///
154         LyXFont const & defaultfont() const;
155
156         /// Text that dictates how wide the left margin is on the screen
157         std::string const & leftmargin() const;
158
159         /// Text that dictates how wide the right margin is on the screen
160         std::string const & rightmargin() const;
161
162         /// The type of command used to produce a title
163         LYX_TITLE_LATEX_TYPES titletype() const;
164         /// The name of the title command
165         std::string const & titlename() const;
166
167         ///
168         int size() const;
169 private:
170         ///
171         bool delete_layout(std::string const &);
172         ///
173         bool do_readStyle(LyXLex &, LyXLayout &);
174         /// Layout file name
175         std::string name_;
176         /// document class name
177         std::string latexname_;
178         /// document class description
179         std::string description_;
180         /// Specific class options
181         std::string opt_fontsize_;
182         ///
183         std::string opt_pagestyle_;
184         ///
185         std::string options_;
186         ///
187         std::string pagestyle_;
188         ///
189         std::string defaultlayout_;
190         /// preamble text to support layout styles
191         std::string preamble_;
192         /// latex packages loaded by document class.
193         Provides provides_;
194         ///
195         unsigned int columns_;
196         ///
197         PageSides sides_;
198         /// header depth to have numbering
199         int secnumdepth_;
200         /// header depth to appear in table of contents
201         int tocdepth_;
202         /// Can be LaTeX, LinuxDoc, etc.
203         OutputType outputType_;
204         /** Base font. The paragraph and layout fonts are resolved against
205             this font. This has to be fully instantiated. Attributes
206             LyXFont::INHERIT, LyXFont::IGNORE, and LyXFont::TOGGLE are
207             extremely illegal.
208         */
209         LyXFont defaultfont_;
210         /// Text that dictates how wide the left margin is on the screen
211         std::string leftmargin_;
212
213         /// Text that dictates how wide the right margin is on the screen
214         std::string rightmargin_;
215
216         /// The type of command used to produce a title
217         LYX_TITLE_LATEX_TYPES titletype_;
218         /// The name of the title command
219         std::string titlename_;
220
221         /// Paragraph styles used in this layout
222         LayoutList layoutlist_;
223         /// CharStyles available to this layout
224         mutable CharStyles charstylelist_;
225         
226         /// available types of float, eg. figure, algorithm.
227         boost::shared_ptr<FloatList> floatlist_;
228
229         /// Types of counters, eg. sections, eqns, figures, avail. in document class.
230         boost::shared_ptr<Counters> ctrs_;
231
232         /// Has this layout file been loaded yet?
233         mutable bool loaded;
234
235         /// Is the TeX class available?
236         bool texClassAvail_;
237 };
238
239
240 /// Merge two different provides flags into one bit field record
241 inline
242 void operator|=(LyXTextClass::Provides & p1, LyXTextClass::Provides p2)
243 {
244         p1 = static_cast<LyXTextClass::Provides>(p1 | p2);
245 }
246
247
248 /// convert page sides option to text 1 or 2
249 std::ostream & operator<<(std::ostream & os, LyXTextClass::PageSides p);
250
251 #endif