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.
19 #include "support/debug.h"
25 FontInfo
const sane_font(
40 FontInfo
const inherit_font(
55 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 LYXERR0("Can't FontInfo::decSize on FONT_SIZE_INCREASE");
93 case FONT_SIZE_DECREASE
:
94 LYXERR0("Can't FontInfo::decSize on FONT_SIZE_DECREASE");
96 case FONT_SIZE_INHERIT
:
97 LYXERR0("Can't FontInfo::decSize on FONT_SIZE_INHERIT");
99 case FONT_SIZE_IGNORE
:
100 LYXERR0("Can't FontInfo::decSize on FONT_SIZE_IGNORE");
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 LYXERR0("Can't FontInfo::incSize on FONT_SIZE_INCREASE");
124 case FONT_SIZE_DECREASE
:
125 LYXERR0("Can't FontInfo::incSize on FONT_SIZE_DECREASE");
127 case FONT_SIZE_INHERIT
:
128 LYXERR0("Can't FontInfo::incSize on FONT_SIZE_INHERIT");
130 case FONT_SIZE_IGNORE
:
131 LYXERR0("Can't FontInfo::incSize on FONT_SIZE_IGNORE");
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 (strikeout_
== tmplt
.strikeout_
)
154 strikeout_
= FONT_INHERIT
;
155 if (uuline_
== tmplt
.uuline_
)
156 uuline_
= FONT_INHERIT
;
157 if (uwave_
== tmplt
.uwave_
)
158 uwave_
= FONT_INHERIT
;
159 if (noun_
== tmplt
.noun_
)
160 noun_
= FONT_INHERIT
;
161 if (color_
== tmplt
.color_
)
162 color_
= Color_inherit
;
163 if (background_
== tmplt
.background_
)
164 background_
= Color_inherit
;
168 /// Realize font from a template
169 FontInfo
& FontInfo::realize(FontInfo
const & tmplt
)
171 if ((*this) == inherit_font
) {
176 if (family_
== INHERIT_FAMILY
)
177 family_
= tmplt
.family_
;
179 if (series_
== INHERIT_SERIES
)
180 series_
= tmplt
.series_
;
182 if (shape_
== INHERIT_SHAPE
)
183 shape_
= tmplt
.shape_
;
185 if (size_
== FONT_SIZE_INHERIT
)
188 if (emph_
== FONT_INHERIT
)
191 if (underbar_
== FONT_INHERIT
)
192 underbar_
= tmplt
.underbar_
;
194 if (strikeout_
== FONT_INHERIT
)
195 strikeout_
= tmplt
.strikeout_
;
197 if (uuline_
== FONT_INHERIT
)
198 uuline_
= tmplt
.uuline_
;
200 if (uwave_
== FONT_INHERIT
)
201 uwave_
= tmplt
.uwave_
;
203 if (noun_
== FONT_INHERIT
)
206 if (color_
== Color_inherit
)
207 color_
= tmplt
.color_
;
209 if (background_
== Color_inherit
)
210 background_
= tmplt
.background_
;
216 /// Updates a misc setting according to request
217 static FontState
setMisc(FontState newfont
,
220 if (newfont
== FONT_TOGGLE
) {
223 else if (org
== FONT_OFF
)
226 LYXERR0("Font::setMisc: Need state"
227 " FONT_ON or FONT_OFF to toggle. Setting to FONT_ON");
230 } else if (newfont
== FONT_IGNORE
)
236 /// Updates font settings according to request
237 void FontInfo::update(FontInfo
const & newfont
, bool toggleall
)
239 if (newfont
.family_
== family_
&& toggleall
)
240 setFamily(INHERIT_FAMILY
); // toggle 'back'
241 else if (newfont
.family_
!= IGNORE_FAMILY
)
242 setFamily(newfont
.family_
);
243 // else it's IGNORE_SHAPE
245 // "Old" behaviour: "Setting" bold will toggle bold on/off.
246 switch (newfont
.series_
) {
249 if (series_
== BOLD_SERIES
&& toggleall
)
250 setSeries(MEDIUM_SERIES
);
252 setSeries(BOLD_SERIES
);
256 setSeries(newfont
.series_
);
262 if (newfont
.shape_
== shape_
&& toggleall
)
263 shape_
= INHERIT_SHAPE
; // toggle 'back'
264 else if (newfont
.shape_
!= IGNORE_SHAPE
)
265 shape_
= newfont
.shape_
;
266 // else it's IGNORE_SHAPE
268 if (newfont
.size_
!= FONT_SIZE_IGNORE
) {
269 if (newfont
.size_
== FONT_SIZE_INCREASE
)
271 else if (newfont
.size_
== FONT_SIZE_DECREASE
)
274 size_
= newfont
.size_
;
277 setEmph(setMisc(newfont
.emph_
, emph_
));
278 setUnderbar(setMisc(newfont
.underbar_
, underbar_
));
279 setStrikeout(setMisc(newfont
.strikeout_
, strikeout_
));
280 setUuline(setMisc(newfont
.uuline_
, uuline_
));
281 setUwave(setMisc(newfont
.uwave_
, uwave_
));
282 setNoun(setMisc(newfont
.noun_
, noun_
));
283 setNumber(setMisc(newfont
.number_
, number_
));
285 if (newfont
.color_
== color_
&& toggleall
)
286 setColor(Color_inherit
); // toggle 'back'
287 else if (newfont
.color_
!= Color_ignore
)
288 setColor(newfont
.color_
);
290 if (newfont
.background_
== background_
&& toggleall
)
291 setBackground(Color_inherit
); // toggle 'back'
292 else if (newfont
.background_
!= Color_ignore
)
293 setBackground(newfont
.background_
);
296 /// Is font resolved?
297 bool FontInfo::resolved() const
299 return (family_
!= INHERIT_FAMILY
&& series_
!= INHERIT_SERIES
300 && shape_
!= INHERIT_SHAPE
&& size_
!= FONT_SIZE_INHERIT
301 && emph_
!= FONT_INHERIT
&& underbar_
!= FONT_INHERIT
302 && uuline_
!= FONT_INHERIT
&& uwave_
!= FONT_INHERIT
303 && strikeout_
!= FONT_INHERIT
&& noun_
!= FONT_INHERIT
304 && color_
!= Color_inherit
305 && background_
!= Color_inherit
);
309 Color
FontInfo::realColor() const
311 if (paint_color_
!= Color_none
)
313 if (color_
== Color_none
)
314 return Color_foreground
;