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(
37 FontInfo
const inherit_font(
49 FontInfo
const ignore_font(
67 /// Decreases font size_ by one
68 FontInfo
& FontInfo::decSize()
71 case FONT_SIZE_HUGER
: size_
= FONT_SIZE_HUGE
; break;
72 case FONT_SIZE_HUGE
: size_
= FONT_SIZE_LARGEST
; break;
73 case FONT_SIZE_LARGEST
: size_
= FONT_SIZE_LARGER
; break;
74 case FONT_SIZE_LARGER
: size_
= FONT_SIZE_LARGE
; break;
75 case FONT_SIZE_LARGE
: size_
= FONT_SIZE_NORMAL
; break;
76 case FONT_SIZE_NORMAL
: size_
= FONT_SIZE_SMALL
; break;
77 case FONT_SIZE_SMALL
: size_
= FONT_SIZE_FOOTNOTE
; break;
78 case FONT_SIZE_FOOTNOTE
: size_
= FONT_SIZE_SCRIPT
; break;
79 case FONT_SIZE_SCRIPT
: size_
= FONT_SIZE_TINY
; break;
80 case FONT_SIZE_TINY
: break;
81 case FONT_SIZE_INCREASE
:
82 LYXERR0("Can't FontInfo::decSize on FONT_SIZE_INCREASE");
84 case FONT_SIZE_DECREASE
:
85 LYXERR0("Can't FontInfo::decSize on FONT_SIZE_DECREASE");
87 case FONT_SIZE_INHERIT
:
88 LYXERR0("Can't FontInfo::decSize on FONT_SIZE_INHERIT");
90 case FONT_SIZE_IGNORE
:
91 LYXERR0("Can't FontInfo::decSize on FONT_SIZE_IGNORE");
98 /// Increases font size_ by one
99 FontInfo
& FontInfo::incSize()
102 case FONT_SIZE_HUGER
: break;
103 case FONT_SIZE_HUGE
: size_
= FONT_SIZE_HUGER
; break;
104 case FONT_SIZE_LARGEST
: size_
= FONT_SIZE_HUGE
; break;
105 case FONT_SIZE_LARGER
: size_
= FONT_SIZE_LARGEST
; break;
106 case FONT_SIZE_LARGE
: size_
= FONT_SIZE_LARGER
; break;
107 case FONT_SIZE_NORMAL
: size_
= FONT_SIZE_LARGE
; break;
108 case FONT_SIZE_SMALL
: size_
= FONT_SIZE_NORMAL
; break;
109 case FONT_SIZE_FOOTNOTE
: size_
= FONT_SIZE_SMALL
; break;
110 case FONT_SIZE_SCRIPT
: size_
= FONT_SIZE_FOOTNOTE
; break;
111 case FONT_SIZE_TINY
: size_
= FONT_SIZE_SCRIPT
; break;
112 case FONT_SIZE_INCREASE
:
113 LYXERR0("Can't FontInfo::incSize on FONT_SIZE_INCREASE");
115 case FONT_SIZE_DECREASE
:
116 LYXERR0("Can't FontInfo::incSize on FONT_SIZE_DECREASE");
118 case FONT_SIZE_INHERIT
:
119 LYXERR0("Can't FontInfo::incSize on FONT_SIZE_INHERIT");
121 case FONT_SIZE_IGNORE
:
122 LYXERR0("Can't FontInfo::incSize on FONT_SIZE_IGNORE");
129 /// Reduce font to fall back to template where possible
130 void FontInfo::reduce(FontInfo
const & tmplt
)
132 if (family_
== tmplt
.family_
)
133 family_
= INHERIT_FAMILY
;
134 if (series_
== tmplt
.series_
)
135 series_
= INHERIT_SERIES
;
136 if (shape_
== tmplt
.shape_
)
137 shape_
= INHERIT_SHAPE
;
138 if (size_
== tmplt
.size_
)
139 size_
= FONT_SIZE_INHERIT
;
140 if (emph_
== tmplt
.emph_
)
141 emph_
= FONT_INHERIT
;
142 if (underbar_
== tmplt
.underbar_
)
143 underbar_
= FONT_INHERIT
;
144 if (noun_
== tmplt
.noun_
)
145 noun_
= FONT_INHERIT
;
146 if (color_
== tmplt
.color_
)
147 color_
= Color_inherit
;
148 if (background_
== tmplt
.background_
)
149 background_
= Color_inherit
;
153 /// Realize font from a template
154 FontInfo
& FontInfo::realize(FontInfo
const & tmplt
)
156 if ((*this) == inherit_font
) {
161 if (family_
== INHERIT_FAMILY
)
162 family_
= tmplt
.family_
;
164 if (series_
== INHERIT_SERIES
)
165 series_
= tmplt
.series_
;
167 if (shape_
== INHERIT_SHAPE
)
168 shape_
= tmplt
.shape_
;
170 if (size_
== FONT_SIZE_INHERIT
)
173 if (emph_
== FONT_INHERIT
)
176 if (underbar_
== FONT_INHERIT
)
177 underbar_
= tmplt
.underbar_
;
179 if (noun_
== FONT_INHERIT
)
182 if (color_
== Color_inherit
)
183 color_
= tmplt
.color_
;
185 if (background_
== Color_inherit
)
186 background_
= tmplt
.background_
;
192 /// Updates a misc setting according to request
193 static FontState
setMisc(FontState newfont
,
196 if (newfont
== FONT_TOGGLE
) {
199 else if (org
== FONT_OFF
)
202 LYXERR0("Font::setMisc: Need state"
203 " FONT_ON or FONT_OFF to toggle. Setting to FONT_ON");
206 } else if (newfont
== FONT_IGNORE
)
212 /// Updates font settings according to request
213 void FontInfo::update(FontInfo
const & newfont
, bool toggleall
)
215 if (newfont
.family_
== family_
&& toggleall
)
216 setFamily(INHERIT_FAMILY
); // toggle 'back'
217 else if (newfont
.family_
!= IGNORE_FAMILY
)
218 setFamily(newfont
.family_
);
219 // else it's IGNORE_SHAPE
221 // "Old" behaviour: "Setting" bold will toggle bold on/off.
222 switch (newfont
.series_
) {
225 if (series_
== BOLD_SERIES
&& toggleall
)
226 setSeries(MEDIUM_SERIES
);
228 setSeries(BOLD_SERIES
);
232 setSeries(newfont
.series_
);
238 if (newfont
.shape_
== shape_
&& toggleall
)
239 shape_
= INHERIT_SHAPE
; // toggle 'back'
240 else if (newfont
.shape_
!= IGNORE_SHAPE
)
241 shape_
= newfont
.shape_
;
242 // else it's IGNORE_SHAPE
244 if (newfont
.size_
!= FONT_SIZE_IGNORE
) {
245 if (newfont
.size_
== FONT_SIZE_INCREASE
)
247 else if (newfont
.size_
== FONT_SIZE_DECREASE
)
250 size_
= newfont
.size_
;
253 setEmph(setMisc(newfont
.emph_
, emph_
));
254 setUnderbar(setMisc(newfont
.underbar_
, underbar_
));
255 setNoun(setMisc(newfont
.noun_
, noun_
));
256 setNumber(setMisc(newfont
.number_
, number_
));
258 if (newfont
.color_
== color_
&& toggleall
)
259 setColor(Color_inherit
); // toggle 'back'
260 else if (newfont
.color_
!= Color_ignore
)
261 setColor(newfont
.color_
);
263 if (newfont
.background_
== background_
&& toggleall
)
264 setBackground(Color_inherit
); // toggle 'back'
265 else if (newfont
.background_
!= Color_ignore
)
266 setBackground(newfont
.background_
);
269 /// Is font resolved?
270 bool FontInfo::resolved() const
272 return (family_
!= INHERIT_FAMILY
&& series_
!= INHERIT_SERIES
273 && shape_
!= INHERIT_SHAPE
&& size_
!= FONT_SIZE_INHERIT
274 && emph_
!= FONT_INHERIT
&& underbar_
!= FONT_INHERIT
275 && noun_
!= FONT_INHERIT
276 && color_
!= Color_inherit
277 && background_
!= Color_inherit
);
281 Color
FontInfo::realColor() const
283 if (paint_color_
!= Color_none
)
285 if (color_
== Color_none
)
286 return Color_foreground
;