2 * \file src/FontInfo.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
7 * \author Jean-Marc Lasgouttes
8 * \author Angus Leeming
12 * Full author contact details are available in file CREDITS.
23 using std::ostringstream;
24 using std::istringstream;
27 #ifndef CXX_GLOBAL_CSTD
34 FontInfo const sane_font(
46 FontInfo const inherit_font(
58 FontInfo const ignore_font(
76 /// Decreases font size_ by one
77 FontInfo & FontInfo::decSize()
80 case FONT_SIZE_HUGER: size_ = FONT_SIZE_HUGE; break;
81 case FONT_SIZE_HUGE: size_ = FONT_SIZE_LARGEST; break;
82 case FONT_SIZE_LARGEST: size_ = FONT_SIZE_LARGER; break;
83 case FONT_SIZE_LARGER: size_ = FONT_SIZE_LARGE; break;
84 case FONT_SIZE_LARGE: size_ = FONT_SIZE_NORMAL; break;
85 case FONT_SIZE_NORMAL: size_ = FONT_SIZE_SMALL; break;
86 case FONT_SIZE_SMALL: size_ = FONT_SIZE_FOOTNOTE; break;
87 case FONT_SIZE_FOOTNOTE: size_ = FONT_SIZE_SCRIPT; break;
88 case FONT_SIZE_SCRIPT: size_ = FONT_SIZE_TINY; break;
89 case FONT_SIZE_TINY: break;
90 case FONT_SIZE_INCREASE:
91 lyxerr << "Can't FontInfo::decSize on FONT_SIZE_INCREASE" << endl;
93 case FONT_SIZE_DECREASE:
94 lyxerr <<"Can't FontInfo::decSize on FONT_SIZE_DECREASE" << endl;
96 case FONT_SIZE_INHERIT:
97 lyxerr <<"Can't FontInfo::decSize on FONT_SIZE_INHERIT" << endl;
99 case FONT_SIZE_IGNORE:
100 lyxerr <<"Can't FontInfo::decSize on FONT_SIZE_IGNORE" << endl;
107 /// Increases font size_ by one
108 FontInfo & FontInfo::incSize()
111 case FONT_SIZE_HUGER: break;
112 case FONT_SIZE_HUGE: size_ = FONT_SIZE_HUGER; break;
113 case FONT_SIZE_LARGEST: size_ = FONT_SIZE_HUGE; break;
114 case FONT_SIZE_LARGER: size_ = FONT_SIZE_LARGEST; break;
115 case FONT_SIZE_LARGE: size_ = FONT_SIZE_LARGER; break;
116 case FONT_SIZE_NORMAL: size_ = FONT_SIZE_LARGE; break;
117 case FONT_SIZE_SMALL: size_ = FONT_SIZE_NORMAL; break;
118 case FONT_SIZE_FOOTNOTE: size_ = FONT_SIZE_SMALL; break;
119 case FONT_SIZE_SCRIPT: size_ = FONT_SIZE_FOOTNOTE; break;
120 case FONT_SIZE_TINY: size_ = FONT_SIZE_SCRIPT; break;
121 case FONT_SIZE_INCREASE:
122 lyxerr <<"Can't FontInfo::incSize on FONT_SIZE_INCREASE" << endl;
124 case FONT_SIZE_DECREASE:
125 lyxerr <<"Can't FontInfo::incSize on FONT_SIZE_DECREASE" << endl;
127 case FONT_SIZE_INHERIT:
128 lyxerr <<"Can't FontInfo::incSize on FONT_SIZE_INHERIT" << endl;
130 case FONT_SIZE_IGNORE:
131 lyxerr <<"Can't FontInfo::incSize on FONT_SIZE_IGNORE" << endl;
138 /// Reduce font to fall back to template where possible
139 void FontInfo::reduce(FontInfo const & tmplt)
141 if (family_ == tmplt.family_)
142 family_ = INHERIT_FAMILY;
143 if (series_ == tmplt.series_)
144 series_ = INHERIT_SERIES;
145 if (shape_ == tmplt.shape_)
146 shape_ = INHERIT_SHAPE;
147 if (size_ == tmplt.size_)
148 size_ = FONT_SIZE_INHERIT;
149 if (emph_ == tmplt.emph_)
150 emph_ = FONT_INHERIT;
151 if (underbar_ == tmplt.underbar_)
152 underbar_ = FONT_INHERIT;
153 if (noun_ == tmplt.noun_)
154 noun_ = FONT_INHERIT;
155 if (color_ == tmplt.color_)
156 color_ = Color_inherit;
157 if (background_ == tmplt.background_)
158 background_ = Color_inherit;
162 /// Realize font from a template
163 FontInfo & FontInfo::realize(FontInfo const & tmplt)
165 if ((*this) == inherit_font) {
170 if (family_ == INHERIT_FAMILY)
171 family_ = tmplt.family_;
173 if (series_ == INHERIT_SERIES)
174 series_ = tmplt.series_;
176 if (shape_ == INHERIT_SHAPE)
177 shape_ = tmplt.shape_;
179 if (size_ == FONT_SIZE_INHERIT)
182 if (emph_ == FONT_INHERIT)
185 if (underbar_ == FONT_INHERIT)
186 underbar_ = tmplt.underbar_;
188 if (noun_ == FONT_INHERIT)
191 if (color_ == Color_inherit)
192 color_ = tmplt.color_;
194 if (background_ == Color_inherit)
195 background_ = tmplt.background_;
201 /// Updates a misc setting according to request
202 static FontState setMisc(FontState newfont,
205 if (newfont == FONT_TOGGLE) {
208 else if (org == FONT_OFF)
211 lyxerr <<"Font::setMisc: Need state"
212 " FONT_ON or FONT_OFF to toggle. Setting to FONT_ON" << endl;
215 } else if (newfont == FONT_IGNORE)
221 /// Updates font settings according to request
222 void FontInfo::update(FontInfo const & newfont, bool toggleall)
224 if (newfont.family_ == family_ && toggleall)
225 setFamily(INHERIT_FAMILY); // toggle 'back'
226 else if (newfont.family_ != IGNORE_FAMILY)
227 setFamily(newfont.family_);
228 // else it's IGNORE_SHAPE
230 // "Old" behaviour: "Setting" bold will toggle bold on/off.
231 switch (newfont.series_) {
234 if (series_ == BOLD_SERIES && toggleall)
235 setSeries(MEDIUM_SERIES);
237 setSeries(BOLD_SERIES);
241 setSeries(newfont.series_);
247 if (newfont.shape_ == shape_ && toggleall)
248 shape_ = INHERIT_SHAPE; // toggle 'back'
249 else if (newfont.shape_ != IGNORE_SHAPE)
250 shape_ = newfont.shape_;
251 // else it's IGNORE_SHAPE
253 if (newfont.size_ != FONT_SIZE_IGNORE) {
254 if (newfont.size_ == FONT_SIZE_INCREASE)
256 else if (newfont.size_ == FONT_SIZE_DECREASE)
259 size_ = newfont.size_;
262 setEmph(setMisc(newfont.emph_, emph_));
263 setUnderbar(setMisc(newfont.underbar_, underbar_));
264 setNoun(setMisc(newfont.noun_, noun_));
265 setNumber(setMisc(newfont.number_, number_));
267 if (newfont.color_ == color_ && toggleall)
268 setColor(Color_inherit); // toggle 'back'
269 else if (newfont.color_ != Color_ignore)
270 setColor(newfont.color_);
272 if (newfont.background_ == background_ && toggleall)
273 setBackground(Color_inherit); // toggle 'back'
274 else if (newfont.background_ != Color_ignore)
275 setBackground(newfont.background_);
278 /// Is font resolved?
279 bool FontInfo::resolved() const
281 return (family_ != INHERIT_FAMILY && series_ != INHERIT_SERIES
282 && shape_ != INHERIT_SHAPE && size_ != FONT_SIZE_INHERIT
283 && emph_ != FONT_INHERIT && underbar_ != FONT_INHERIT
284 && noun_ != FONT_INHERIT
285 && color_ != Color_inherit
286 && background_ != Color_inherit);
290 ColorCode FontInfo::realColor() const
292 if (color_ == Color_none)
293 return Color_foreground;