]> git.lyx.org Git - lyx.git/blob - src/FontList.h
* Paragraph: reserve memory by chunks of 100 chars. This improve the loading of big...
[lyx.git] / src / FontList.h
1 /**
2  * \file FontList.h
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Abdelrazak Younes
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #ifndef FONT_LIST_H
12 #define FONT_LIST_H
13
14 #include "Font.h"
15
16 #include "support/types.h"
17
18 #include <vector>
19
20 namespace lyx {
21
22 /** A font entry covers a range of positions. Notice that the
23     entries in the list are inserted in random order.
24     I don't think it's worth the effort to implement a more effective
25     datastructure, because the number of different fonts in a paragraph
26     is limited. (Asger)
27     Nevertheless, I decided to store fontlist_ using a sorted vector:
28     fontlist_ = { {pos_1,font_1} , {pos_2,font_2} , ... } where
29     pos_1 < pos_2 < ..., font_{i-1} != font_i for all i,
30     and font_i covers the chars in positions pos_{i-1}+1,...,pos_i
31     (font_1 covers the chars 0,...,pos_1) (Dekel)
32 */
33 class FontTable
34 {
35 public:
36         ///
37         FontTable(pos_type p, Font const & f)
38                 : pos_(p), font_(f)
39         {}
40         ///
41         pos_type pos() const { return pos_; }
42         ///
43         void pos(pos_type p) { pos_ = p; }
44         ///
45         Font const & font() const { return font_; }
46         ///
47         void font(Font const & f) { font_ = f;}
48
49 private:
50         friend class FontList;
51         /// End position of paragraph this font attribute covers
52         pos_type pos_;
53         /** Font. Interpretation of the font values:
54         If a value is Font::INHERIT_*, it means that the font
55         attribute is inherited from either the layout of this
56         paragraph or, in the case of nested paragraphs, from the
57         layout in the environment one level up until completely
58         resolved.
59         The values Font::IGNORE_* and Font::TOGGLE are NOT
60         allowed in these font tables.
61         */
62         Font font_;
63 };
64
65 class LaTeXFeatures;
66
67 ///
68 class FontList
69 {
70 public:
71         typedef std::vector<FontTable> List;
72         ///
73         typedef List::iterator iterator;
74         ///
75         typedef List::const_iterator const_iterator;
76         ///
77         iterator begin() { return list_.begin(); }
78         ///
79         iterator end() { return list_.end(); }
80         ///
81         const_iterator begin() const { return list_.begin(); }
82         ///
83         const_iterator end() const { return list_.end(); }
84         ///
85         bool empty() const { return list_.empty(); }
86         ///
87         void erase(pos_type pos);
88         ///
89         iterator fontIterator(pos_type pos);
90         ///
91         const_iterator fontIterator(pos_type pos) const;
92         ///
93         Font & get(pos_type pos);
94         ///
95         void set(pos_type pos, Font const & font);
96         ///
97         void setRange(
98                 pos_type startpos,
99                 pos_type endpos,
100                 Font const & font);
101         ///
102         void increasePosAfterPos(pos_type pos);
103         ///
104         void decreasePosAfterPos(pos_type pos);
105
106         /// Returns the height of the highest font in range
107         Font_size highestInRange(
108                 pos_type startpos,
109                 pos_type endpos,
110                 Font_size def_size
111                 ) const;
112
113         /// is there a font change in middle of the word?
114         bool hasChangeInRange(
115                 pos_type pos, ///< position in the paragraph.
116                 int len ///< length of the range to check.
117                 ) const;
118
119         ///
120         void validate(LaTeXFeatures & features) const;
121
122 private:
123         ///
124         List list_;
125 };
126
127 } // namespace lyx
128
129 #endif