]> git.lyx.org Git - features.git/blob - src/TextClass.h
Clean-up in CharStyles, externalize detection of undefined styles to
[features.git] / src / TextClass.h
1 // -*- C++ -*-
2 /**
3  * \file TextClass.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 "Layout.h"
14 #include "lyxlayout_ptr_fwd.h"
15
16 #include <boost/shared_ptr.hpp>
17
18 #include <vector>
19 #include <set>
20 #include <map>
21
22 namespace lyx {
23
24 namespace support { class FileName; }
25
26 class Lexer;
27 class Counters;
28 class FloatList;
29
30
31 ///
32 class InsetLayout {
33 public:
34         std::string name;
35         std::string lyxtype;
36         docstring labelstring;
37         std::string decoration;
38         std::string latextype;
39         std::string latexname;
40         std::string latexparam;
41         Font font;
42         Font labelfont;
43         std::string preamble;
44 };
45
46
47 /// List of semantically defined character style insets
48 typedef std::vector<InsetLayout> CharStyles;
49
50 /// List of inset layouts
51 typedef std::map<docstring, InsetLayout> InsetLayouts;
52
53 /// Stores the layout specification of a LyX document class.
54 class TextClass {
55 public:
56         /// The individual styles comprising the document class
57         typedef std::vector<LayoutPtr> LayoutList;
58         /// Enumerate the paragraph styles.
59         typedef LayoutList::const_iterator const_iterator;
60         /// Construct a layout with default values. Actual values loaded later.
61         explicit
62         TextClass(std::string const & = std::string(),
63                      std::string const & = std::string(),
64                      std::string const & = std::string(),
65                      bool = false);
66
67         /// check whether the TeX class is available
68         bool isTeXClassAvailable() const;
69
70         /// paragraph styles begin iterator.
71         const_iterator begin() const { return layoutlist_.begin(); }
72         /// paragraph styles end iterator
73         const_iterator end() const { return layoutlist_.end(); }
74
75         /// Performs the read of the layout file.
76         bool read(support::FileName const & filename, bool merge = false);
77         ///
78         void readOutputType(Lexer &);
79         ///
80         void readTitleType(Lexer &);
81         ///
82         void readMaxCounter(Lexer &);
83         ///
84         void readClassOptions(Lexer &);
85         ///
86         void readCharStyle(Lexer &, std::string const &);
87         ///
88         void readInsetLayout(Lexer &, docstring const &);
89         ///
90         void readFloat(Lexer &);
91         ///
92         void readCounter(Lexer &);
93         ///
94         bool hasLayout(docstring const & name) const;
95
96         ///
97         LayoutPtr const & operator[](docstring const & vname) const;
98
99         /// Sees to that the textclass structure has been loaded
100         bool load(std::string const & path = std::string()) const;
101         /// Has this layout file been loaded yet?
102         bool loaded() const { return loaded_; }
103
104         /// the list of floats defined in the document class
105         FloatList & floats();
106         /// the list of floats defined in the document class
107         FloatList const & floats() const;
108         /// The Counters present in this document class.
109         Counters & counters() const;
110         /// CharStyles of this doc class
111         CharStyles & charstyles() const { return charstylelist_; };
112         /// Inset layouts of this doc class
113         InsetLayouts & insetlayouts() const { return insetlayoutlist_; };
114         ///
115         InsetLayout const & insetlayout(docstring const & name) const;
116         ///
117         docstring const & defaultLayoutName() const;
118         ///
119         LayoutPtr const & defaultLayout() const;
120         ///
121         std::string const & name() const;
122         ///
123         docstring const & labelstring() const;
124         ///
125         std::string const & latexname() const;
126         ///
127         std::string const & description() const;
128         ///
129         std::string const & opt_fontsize() const;
130         ///
131         std::string const & opt_pagestyle() const;
132         ///
133         std::string const & options() const;
134         ///
135         std::string const & class_header() const;
136         ///
137         std::string const & pagestyle() const;
138         ///
139         docstring const & preamble() const;
140
141         /// is this feature already provided by the class?
142         bool provides(std::string const & p) const;
143
144         ///
145         unsigned int columns() const;
146         ///
147         enum PageSides {
148                 ///
149                 OneSide,
150                 ///
151                 TwoSides
152         };
153         ///
154         PageSides sides() const;
155         ///
156         int secnumdepth() const;
157         ///
158         int tocdepth() const;
159
160         /// Can be LaTeX, DocBook, etc.
161         OutputType outputType() const;
162
163         ///
164         Font const & defaultfont() const;
165
166         /// Text that dictates how wide the left margin is on the screen
167         docstring const & leftmargin() const;
168
169         /// Text that dictates how wide the right margin is on the screen
170         docstring const & rightmargin() const;
171
172         /// The type of command used to produce a title
173         LYX_TITLE_LATEX_TYPES titletype() const;
174         /// The name of the title command
175         std::string const & titlename() const;
176
177         ///
178         int size() const;
179         /// The minimal TocLevel of sectioning layouts
180         int min_toclevel() const;
181         /// The maximal TocLevel of sectioning layouts
182         int max_toclevel() const;
183         /// returns true if the class has a ToC structure
184         bool hasTocLevels() const;
185 private:
186         ///
187         bool delete_layout(docstring const &);
188         ///
189         bool do_readStyle(Lexer &, Layout &);
190         /// Layout file name
191         std::string name_;
192         /// document class name
193         std::string latexname_;
194         /// document class description
195         std::string description_;
196         /// Specific class options
197         std::string opt_fontsize_;
198         ///
199         std::string opt_pagestyle_;
200         ///
201         std::string options_;
202         ///
203         std::string pagestyle_;
204         ///
205         std::string class_header_;
206         ///
207         docstring defaultlayout_;
208         /// preamble text to support layout styles
209         docstring preamble_;
210         /// latex packages loaded by document class.
211         std::set<std::string> provides_;
212         ///
213         unsigned int columns_;
214         ///
215         PageSides sides_;
216         /// header depth to have numbering
217         int secnumdepth_;
218         /// header depth to appear in table of contents
219         int tocdepth_;
220         /// Can be LaTeX, DocBook, etc.
221         OutputType outputType_;
222         /** Base font. The paragraph and layout fonts are resolved against
223             this font. This has to be fully instantiated. Attributes
224             Font::INHERIT, Font::IGNORE, and Font::TOGGLE are
225             extremely illegal.
226         */
227         Font defaultfont_;
228         /// Text that dictates how wide the left margin is on the screen
229         docstring leftmargin_;
230
231         /// Text that dictates how wide the right margin is on the screen
232         docstring rightmargin_;
233
234         /// The type of command used to produce a title
235         LYX_TITLE_LATEX_TYPES titletype_;
236         /// The name of the title command
237         std::string titlename_;
238
239         /// Paragraph styles used in this layout
240         LayoutList layoutlist_;
241         /// CharStyles available to this layout
242         mutable CharStyles charstylelist_;
243
244         /// Input layouts available to this layout
245         mutable InsetLayouts insetlayoutlist_;
246
247         /// available types of float, eg. figure, algorithm.
248         boost::shared_ptr<FloatList> floatlist_;
249
250         /// Types of counters, eg. sections, eqns, figures, avail. in document class.
251         boost::shared_ptr<Counters> counters_;
252
253         /// Has this layout file been loaded yet?
254         mutable bool loaded_;
255
256         /// Is the TeX class available?
257         bool texClassAvail_;
258
259         /// The minimal TocLevel of sectioning layouts
260         int min_toclevel_;
261         /// The maximal TocLevel of sectioning layouts
262         int max_toclevel_;
263 };
264
265
266 /// convert page sides option to text 1 or 2
267 std::ostream & operator<<(std::ostream & os, TextClass::PageSides p);
268
269
270 } // namespace lyx
271
272 #endif