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
9 * Full author contact details are available in file CREDITS.
12 /* Completes the implementation of the Bullet class
13 * It defines the various LaTeX commands etc. required to
14 * generate the bullets in the bullet-panel's.
21 #include <boost/assert.hpp>
28 /** The four LaTeX itemize environment default bullets
31 Bullet const ITEMIZE_DEFAULTS[4] = { Bullet(0, 8),//"\\(\\bullet\\)"
32 Bullet(0, 0),//"\\normalfont\\bfseries{--}"
33 Bullet(0, 6),//"\\(\\ast\\)"
34 Bullet(0, 10) };//"\\(\\cdot\\)"
36 // will need these later if still using full text as below
37 // \usepackage{latexsym,pifont,amssymb}
38 // and wasysym when that panel is created
41 Bullet::Bullet(int f, int c, int s)
42 : font(f), character(c), size(s), user_text(0)
44 if (f < MIN || f >= FONTMAX) {
47 if (c < MIN || c >= CHARMAX) {
50 if (s < MIN || s >= SIZEMAX) {
59 Bullet::Bullet(docstring const & t)
60 : font(MIN), character(MIN), size(MIN), user_text(1), text(t)
66 void Bullet::setCharacter(int c)
68 if (c < MIN || c >= CHARMAX) {
78 void Bullet::setFont(int f)
80 if (f < MIN || f >= FONTMAX) {
90 void Bullet::setSize(int s)
92 if (s < MIN || s >= SIZEMAX) {
102 void Bullet::setText(docstring const & t)
104 font = character = size = MIN;
111 int Bullet::getCharacter() const
117 int Bullet::getFont() const
123 int Bullet::getSize() const
129 Bullet & Bullet::operator=(Bullet const & b)
133 character = b.character;
135 user_text = b.user_text;
137 this->testInvariant();
142 docstring const & Bullet::getText() const
144 if (user_text == 0) {
151 bool operator==(const Bullet & b1, const Bullet & b2)
155 if (b1.user_text && b2.user_text) {
156 /* both have valid text */
157 if (b1.text == b2.text) {
160 } else if (((b1.character == b2.character) &&
161 (b1.font == b2.font)) &&
162 (b1.size == b2.size)) {
169 /*--------------------Private Member Functions-------------------*/
172 void Bullet::generateText() const
175 // user hasn't defined their own text and/or I haven't generated
176 // the text for the current font/character settings yet
177 // thus the calling member function should say:
178 // if (user_text == 0) {
181 // Since a function call is more expensive than a conditional
182 // this is more efficient. Besides this function is internal to
183 // the class so it's only the class author that has access --
184 // external users thus can't make mistakes.
186 if ((font >= 0) && (character >= 0)) {
187 text = bulletEntry(font, character);
189 text = bulletSize(size) + text;
192 // text is now defined and doesn't need to be recalculated
193 // unless font/character or text is modified
198 docstring const Bullet::bulletSize(int s)
200 // use a parameter rather than hard code `size' in here
201 // in case some future function may want to retrieve
202 // an arbitrary entry.
203 // See additional comments in bulletEntry() below.
205 static char const * BulletSize[SIZEMAX] = {
206 "\\tiny", "\\scriptsize", "\\footnotesize", "\\small", "\\normalsize",
207 "\\large", "\\Large", "\\LARGE", "\\huge", "\\Huge"
210 return from_ascii(BulletSize[s]);
214 docstring const Bullet::bulletEntry(int f, int c)
216 // Despite how this may at first appear the static local variables
217 // are only initialized once..
218 // This is a work-around to avoid the "Static Initialization Problem"
219 // and should work for all compilers. See "C++ FAQs" by Cline and Lomow,
220 // Addison-Wesley, 1994, FAQ-180 pp169-171 for an explanation.
221 // Doing things this way also makes it possible to generate `text' at
222 // the time of construction. It also encapsulates the conversion
223 // of font, character and size entries to text.
225 // The single 2-dim array had to be changed to multiple 1-dim arrays
226 // to get around a compiler bug in an earler version of gcc (< 2.7.2.1)
227 // static string const BulletPanels[FONTMAX][CHARMAX] = {
228 static char const * BulletPanel0[CHARMAX] = {
230 "\\normalfont\\bfseries{--}", "\\(\\vdash\\)",
231 "\\(\\dashv\\)", "\\(\\flat\\)", "\\(\\natural\\)",
232 "\\(\\sharp\\)", "\\(\\ast\\)", "\\(\\star\\)",
233 "\\(\\bullet\\)", "\\(\\circ\\)", "\\(\\cdot\\)",
234 "\\(\\dagger\\)", "\\(\\bigtriangleup\\)",
235 "\\(\\bigtriangledown\\)", "\\(\\triangleleft\\)",
236 "\\(\\triangleright\\)", "\\(\\lhd\\)", "\\(\\rhd\\)",
237 "\\(\\oplus\\)", "\\(\\ominus\\)", "\\(\\otimes\\)",
238 "\\(\\oslash\\)", "\\(\\odot\\)", "\\(\\spadesuit\\)",
239 "\\(\\diamond\\)", "\\(\\Diamond\\)", "\\(\\Box\\)",
240 "\\(\\diamondsuit\\)", "\\(\\heartsuit\\)",
241 "\\(\\clubsuit\\)", "\\(\\rightarrow\\)", "\\(\\leadsto\\)",
242 "\\(\\rightharpoonup\\)", "\\(\\rightharpoondown\\)",
243 "\\(\\Rightarrow\\)", "\\(\\succ\\)"
245 static char const * BulletPanel1[CHARMAX] = {
247 "\\(\\Rrightarrow\\)", "\\(\\rightarrowtail\\)",
248 "\\(\\twoheadrightarrow\\)", "\\(\\rightsquigarrow\\)",
249 "\\(\\looparrowright\\)", "\\(\\multimap\\)",
250 "\\(\\boxtimes\\)", "\\(\\boxplus\\)", "\\(\\boxminus\\)",
251 "\\(\\boxdot\\)", "\\(\\divideontimes\\)", "\\(\\Vvdash\\)",
252 "\\(\\lessdot\\)", "\\(\\gtrdot\\)", "\\(\\maltese\\)",
253 "\\(\\bigstar\\)", "\\(\\checkmark\\)", "\\(\\Vdash\\)",
254 "\\(\\backsim\\)", "\\(\\thicksim\\)",
255 "\\(\\centerdot\\)", "\\(\\circleddash\\)",
256 "\\(\\circledast\\)", "\\(\\circledcirc\\)",
257 "\\(\\vartriangleleft\\)", "\\(\\vartriangleright\\)",
258 "\\(\\vartriangle\\)", "\\(\\triangledown\\)",
259 "\\(\\lozenge\\)", "\\(\\square\\)", "\\(\\blacktriangleleft\\)",
260 "\\(\\blacktriangleright\\)", "\\(\\blacktriangle\\)",
261 "\\(\\blacktriangledown\\)", "\\(\\blacklozenge\\)",
262 "\\(\\blacksquare\\)"
264 static char const * BulletPanel2[CHARMAX] = {
266 "\\ding{108}", "\\ding{109}",
267 "\\ding{119}", "\\Pisymbol{psy}{197}",
268 "\\Pisymbol{psy}{196}", "\\Pisymbol{psy}{183}",
269 "\\ding{71}", "\\ding{70}",
270 "\\ding{118}", "\\ding{117}",
271 "\\Pisymbol{psy}{224}", "\\Pisymbol{psy}{215}",
272 "\\ding{111}", "\\ding{112}",
273 "\\ding{113}", "\\ding{114}",
274 "\\Pisymbol{psy}{68}", "\\Pisymbol{psy}{209}",
275 "\\ding{120}", "\\ding{121}",
276 "\\ding{122}", "\\ding{110}",
277 "\\ding{115}", "\\ding{116}",
278 "\\Pisymbol{psy}{42}", "\\ding{67}",
279 "\\ding{66}", "\\ding{82}",
280 "\\ding{81}", "\\ding{228}",
281 "\\ding{162}", "\\ding{163}",
282 "\\ding{166}", "\\ding{167}",
283 "\\ding{226}", "\\ding{227}"
285 static char const * BulletPanel3[CHARMAX] = {
287 "\\ding{37}", "\\ding{38}",
288 "\\ding{34}", "\\ding{36}",
289 "\\ding{39}", "\\ding{40}",
290 "\\ding{41}", "\\ding{42}",
291 "\\ding{43}", "\\ding{44}",
292 "\\ding{45}", "\\ding{47}",
293 "\\ding{53}", "\\ding{54}",
294 "\\ding{59}", "\\ding{57}",
295 "\\ding{62}", "\\ding{61}",
296 "\\ding{55}", "\\ding{56}",
297 "\\ding{58}", "\\ding{60}",
298 "\\ding{63}", "\\ding{64}",
299 "\\ding{51}", "\\ding{52}",
300 "\\Pisymbol{psy}{170}", "\\Pisymbol{psy}{167}",
301 "\\Pisymbol{psy}{168}", "\\Pisymbol{psy}{169}",
302 "\\ding{164}", "\\ding{165}",
303 "\\ding{171}", "\\ding{168}",
304 "\\ding{169}", "\\ding{170}"
306 static char const * BulletPanel4[CHARMAX] = {
308 "\\ding{65}", "\\ding{76}",
309 "\\ding{75}", "\\ding{72}",
310 "\\ding{80}", "\\ding{74}",
311 "\\ding{78}", "\\ding{77}",
312 "\\ding{79}", "\\ding{85}",
313 "\\ding{90}", "\\ding{98}",
314 "\\ding{83}", "\\ding{84}",
315 "\\ding{86}", "\\ding{87}",
316 "\\ding{88}", "\\ding{89}",
317 "\\ding{92}", "\\ding{91}",
318 "\\ding{93}", "\\ding{105}",
319 "\\ding{94}", "\\ding{99}",
320 "\\ding{103}", "\\ding{104}",
321 "\\ding{106}", "\\ding{107}",
322 "\\ding{68}", "\\ding{69}",
323 "\\ding{100}", "\\ding{101}",
324 "\\ding{102}", "\\ding{96}",
325 "\\ding{95}", "\\ding{97}"
327 static char const * BulletPanel5[CHARMAX] = {
329 "\\ding{223}", "\\ding{224}",
330 "\\ding{225}", "\\ding{232}",
331 "\\ding{229}", "\\ding{230}",
332 "\\ding{238}", "\\ding{237}",
333 "\\ding{236}", "\\ding{235}",
334 "\\ding{234}", "\\ding{233}",
335 "\\ding{239}", "\\ding{241}",
336 "\\ding{250}", "\\ding{251}",
337 "\\ding{49}", "\\ding{50}",
338 "\\ding{217}", "\\ding{245}",
339 "\\ding{243}", "\\ding{248}",
340 "\\ding{252}", "\\ding{253}",
341 "\\ding{219}", "\\ding{213}",
342 "\\ding{221}", "\\ding{222}",
343 "\\ding{220}", "\\ding{212}",
344 "\\Pisymbol{psy}{174}", "\\Pisymbol{psy}{222}",
345 "\\ding{254}", "\\ding{242}",
346 "\\ding{231}", "\\Pisymbol{psy}{45}"
347 }; /* string const BulletPanels[][] */
349 static char const ** BulletPanels[FONTMAX] = {
350 BulletPanel0, BulletPanel1,
351 BulletPanel2, BulletPanel3,
352 BulletPanel4, BulletPanel5
355 return from_ascii(BulletPanels[f][c]);
358 void Bullet::testInvariant() const
360 #ifdef ENABLE_ASSERTIONS
361 BOOST_ASSERT(font >= MIN);
362 BOOST_ASSERT(font < FONTMAX);
363 BOOST_ASSERT(character >= MIN);
364 BOOST_ASSERT(character < CHARMAX);
365 BOOST_ASSERT(size >= MIN);
366 BOOST_ASSERT(size < SIZEMAX);
367 BOOST_ASSERT(user_text >= -1);
368 BOOST_ASSERT(user_text <= 1);
369 // now some relational/operational tests
370 if (user_text == 1) {
371 BOOST_ASSERT(font == -1 && (character == -1 && size == -1));
372 // BOOST_ASSERT(!text.empty()); // this isn't necessarily an error
374 // else if (user_text == -1) {
375 // BOOST_ASSERT(!text.empty()); // this also isn't necessarily an error
379 // BOOST_ASSERT(text.empty()); // not usually true