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 "support/lassert.h"
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)
46 if (c < MIN || c >= CHARMAX)
48 if (s < MIN || s >= SIZEMAX)
56 Bullet::Bullet(docstring const & t)
57 : font(MIN), character(MIN), size(MIN), user_text(1), text(t), label(t)
63 void Bullet::setCharacter(int c)
65 if (c < MIN || c >= CHARMAX)
74 void Bullet::setFont(int f)
76 if (f < MIN || f >= FONTMAX)
85 void Bullet::setSize(int s)
87 if (s < MIN || s >= SIZEMAX)
96 void Bullet::setText(docstring const & t)
98 font = character = size = MIN;
106 int Bullet::getCharacter() const
112 int Bullet::getFont() const
118 int Bullet::getSize() const
124 FontSize Bullet::getFontSize() const
127 return bulletFontSize(size);
133 Bullet & Bullet::operator=(Bullet const & b)
137 character = b.character;
139 user_text = b.user_text;
142 this->testInvariant();
147 docstring const & Bullet::getText() const
155 docstring const & Bullet::getLabel() const
163 bool operator==(const Bullet & b1, const Bullet & b2)
167 if (b1.user_text && b2.user_text) {
168 /* both have valid text */
169 if (b1.text == b2.text)
171 } else if (b1.character == b2.character && b1.font == b2.font &&
172 b1.size == b2.size) {
179 /*--------------------Private Member Functions-------------------*/
182 void Bullet::generateText() const
185 // user hasn't defined their own text and/or I haven't generated
186 // the text for the current font/character settings yet
187 // thus the calling member function should say:
188 // if (user_text == 0) {
191 // Since a function call is more expensive than a conditional
192 // this is more efficient. Besides this function is internal to
193 // the class so it's only the class author that has access --
194 // external users thus can't make mistakes.
196 if ((font >= 0) && (character >= 0)) {
197 text = bulletEntry(font, character);
198 label = bulletLabel(font, character);
200 text = bulletSize(size) + text;
202 // text is now defined and doesn't need to be recalculated
203 // unless font/character or text is modified
208 docstring const Bullet::bulletSize(int s)
210 // use a parameter rather than hard code `size' in here
211 // in case some future function may want to retrieve
212 // an arbitrary entry.
213 // See additional comments in bulletEntry() below.
215 static char const * BulletSize[SIZEMAX] = {
216 "\\tiny", "\\scriptsize", "\\footnotesize", "\\small", "\\normalsize",
217 "\\large", "\\Large", "\\LARGE", "\\huge", "\\Huge"
220 return from_ascii(BulletSize[s]);
224 docstring const Bullet::bulletEntry(int f, int c)
226 // Despite how this may at first appear the static local variables
227 // are only initialized once..
228 // This is a work-around to avoid the "Static Initialization Problem"
229 // and should work for all compilers. See "C++ FAQs" by Cline and Lomow,
230 // Addison-Wesley, 1994, FAQ-180 pp169-171 for an explanation.
231 // Doing things this way also makes it possible to generate `text' at
232 // the time of construction. It also encapsulates the conversion
233 // of font, character and size entries to text.
235 // The single 2-dim array had to be changed to multiple 1-dim arrays
236 // to get around a compiler bug in an earler version of gcc (< 2.7.2.1)
237 // static string const BulletPanels[FONTMAX][CHARMAX] = {
238 static char const * BulletPanel0[CHARMAX] = {
240 "\\normalfont\\bfseries{--}", "\\(\\vdash\\)",
241 "\\(\\dashv\\)", "\\(\\flat\\)", "\\(\\natural\\)",
242 "\\(\\sharp\\)", "\\(\\ast\\)", "\\(\\star\\)",
243 "\\(\\bullet\\)", "\\(\\circ\\)", "\\(\\cdot\\)",
244 "\\(\\dagger\\)", "\\(\\bigtriangleup\\)",
245 "\\(\\bigtriangledown\\)", "\\(\\triangleleft\\)",
246 "\\(\\triangleright\\)", "\\(\\lhd\\)", "\\(\\rhd\\)",
247 "\\(\\oplus\\)", "\\(\\ominus\\)", "\\(\\otimes\\)",
248 "\\(\\oslash\\)", "\\(\\odot\\)", "\\(\\spadesuit\\)",
249 "\\(\\diamond\\)", "\\(\\Diamond\\)", "\\(\\Box\\)",
250 "\\(\\diamondsuit\\)", "\\(\\heartsuit\\)",
251 "\\(\\clubsuit\\)", "\\(\\rightarrow\\)", "\\(\\leadsto\\)",
252 "\\(\\rightharpoonup\\)", "\\(\\rightharpoondown\\)",
253 "\\(\\Rightarrow\\)", "\\(\\succ\\)"
255 static char const * BulletPanel1[CHARMAX] = {
257 "\\(\\Rrightarrow\\)", "\\(\\rightarrowtail\\)",
258 "\\(\\twoheadrightarrow\\)", "\\(\\rightsquigarrow\\)",
259 "\\(\\looparrowright\\)", "\\(\\multimap\\)",
260 "\\(\\boxtimes\\)", "\\(\\boxplus\\)", "\\(\\boxminus\\)",
261 "\\(\\boxdot\\)", "\\(\\divideontimes\\)", "\\(\\Vvdash\\)",
262 "\\(\\lessdot\\)", "\\(\\gtrdot\\)", "\\(\\maltese\\)",
263 "\\(\\bigstar\\)", "\\(\\checkmark\\)", "\\(\\Vdash\\)",
264 "\\(\\backsim\\)", "\\(\\thicksim\\)",
265 "\\(\\centerdot\\)", "\\(\\circleddash\\)",
266 "\\(\\circledast\\)", "\\(\\circledcirc\\)",
267 "\\(\\vartriangleleft\\)", "\\(\\vartriangleright\\)",
268 "\\(\\vartriangle\\)", "\\(\\triangledown\\)",
269 "\\(\\lozenge\\)", "\\(\\square\\)", "\\(\\blacktriangleleft\\)",
270 "\\(\\blacktriangleright\\)", "\\(\\blacktriangle\\)",
271 "\\(\\blacktriangledown\\)", "\\(\\blacklozenge\\)",
272 "\\(\\blacksquare\\)"
274 static char const * BulletPanel2[CHARMAX] = {
276 "\\ding{108}", "\\ding{109}",
277 "\\ding{119}", "\\Pisymbol{psy}{197}",
278 "\\Pisymbol{psy}{196}", "\\Pisymbol{psy}{183}",
279 "\\ding{71}", "\\ding{70}",
280 "\\ding{118}", "\\ding{117}",
281 "\\Pisymbol{psy}{224}", "\\Pisymbol{psy}{215}",
282 "\\ding{111}", "\\ding{112}",
283 "\\ding{113}", "\\ding{114}",
284 "\\Pisymbol{psy}{68}", "\\Pisymbol{psy}{209}",
285 "\\ding{120}", "\\ding{121}",
286 "\\ding{122}", "\\ding{110}",
287 "\\ding{115}", "\\ding{116}",
288 "\\Pisymbol{psy}{42}", "\\ding{67}",
289 "\\ding{66}", "\\ding{82}",
290 "\\ding{81}", "\\ding{228}",
291 "\\ding{162}", "\\ding{163}",
292 "\\ding{166}", "\\ding{167}",
293 "\\ding{226}", "\\ding{227}"
295 static char const * BulletPanel3[CHARMAX] = {
297 "\\ding{37}", "\\ding{38}",
298 "\\ding{34}", "\\ding{36}",
299 "\\ding{39}", "\\ding{40}",
300 "\\ding{41}", "\\ding{42}",
301 "\\ding{43}", "\\ding{44}",
302 "\\ding{45}", "\\ding{47}",
303 "\\ding{53}", "\\ding{54}",
304 "\\ding{59}", "\\ding{57}",
305 "\\ding{62}", "\\ding{61}",
306 "\\ding{55}", "\\ding{56}",
307 "\\ding{58}", "\\ding{60}",
308 "\\ding{63}", "\\ding{64}",
309 "\\ding{51}", "\\ding{52}",
310 "\\Pisymbol{psy}{170}", "\\Pisymbol{psy}{167}",
311 "\\Pisymbol{psy}{168}", "\\Pisymbol{psy}{169}",
312 "\\ding{164}", "\\ding{165}",
313 "\\ding{171}", "\\ding{168}",
314 "\\ding{169}", "\\ding{170}"
316 static char const * BulletPanel4[CHARMAX] = {
318 "\\ding{65}", "\\ding{76}",
319 "\\ding{75}", "\\ding{72}",
320 "\\ding{80}", "\\ding{74}",
321 "\\ding{78}", "\\ding{77}",
322 "\\ding{79}", "\\ding{85}",
323 "\\ding{90}", "\\ding{98}",
324 "\\ding{83}", "\\ding{84}",
325 "\\ding{86}", "\\ding{87}",
326 "\\ding{88}", "\\ding{89}",
327 "\\ding{92}", "\\ding{91}",
328 "\\ding{93}", "\\ding{105}",
329 "\\ding{94}", "\\ding{99}",
330 "\\ding{103}", "\\ding{104}",
331 "\\ding{106}", "\\ding{107}",
332 "\\ding{68}", "\\ding{69}",
333 "\\ding{100}", "\\ding{101}",
334 "\\ding{102}", "\\ding{96}",
335 "\\ding{95}", "\\ding{97}"
337 static char const * BulletPanel5[CHARMAX] = {
339 "\\ding{223}", "\\ding{224}",
340 "\\ding{225}", "\\ding{232}",
341 "\\ding{229}", "\\ding{230}",
342 "\\ding{238}", "\\ding{237}",
343 "\\ding{236}", "\\ding{235}",
344 "\\ding{234}", "\\ding{233}",
345 "\\ding{239}", "\\ding{241}",
346 "\\ding{250}", "\\ding{251}",
347 "\\ding{49}", "\\ding{50}",
348 "\\ding{217}", "\\ding{245}",
349 "\\ding{243}", "\\ding{248}",
350 "\\ding{252}", "\\ding{253}",
351 "\\ding{219}", "\\ding{213}",
352 "\\ding{221}", "\\ding{222}",
353 "\\ding{220}", "\\ding{212}",
354 "\\Pisymbol{psy}{174}", "\\Pisymbol{psy}{222}",
355 "\\ding{254}", "\\ding{242}",
356 "\\ding{231}", "\\Pisymbol{psy}{45}"
357 }; /* string const BulletPanels[][] */
359 static char const ** BulletPanels[FONTMAX] = {
360 BulletPanel0, BulletPanel1,
361 BulletPanel2, BulletPanel3,
362 BulletPanel4, BulletPanel5
365 return from_ascii(BulletPanels[f][c]);
369 FontSize Bullet::bulletFontSize(int s)
371 // see comment at bulletSize
372 static FontSize BulletFontSize[SIZEMAX] = {
373 TINY_SIZE, SCRIPT_SIZE, FOOTNOTE_SIZE, SMALL_SIZE, NORMAL_SIZE,
374 LARGE_SIZE, LARGER_SIZE, LARGEST_SIZE, HUGE_SIZE, HUGER_SIZE
377 return BulletFontSize[s];
381 docstring const Bullet::bulletLabel(int f, int c)
383 // see comment at bulletEntry
384 static int UnicodeBulletPanel0[CHARMAX] = {
387 0x022A3, 0x0266D, 0x0266E,
388 0x0266F, 0x02217, 0x022C6,
389 0x02022, 0x02218, 0x022C5,
392 0x025B9, 0x025C1, 0x025B7,
393 0x02295, 0x02296, 0x02297,
394 0x02298, 0x02299, 0x02660,
395 0x022C4, 0x025C7, /* \square */ 0x025FB,
397 0x02663, 0x02192, 0x02933,
401 static int UnicodeBulletPanel1[CHARMAX] = {
406 0x022A0, 0x0229E, 0x0229F,
407 0x022A1, 0x022C7, 0x022AA,
408 0x022D6, 0x022D7, 0x02720,
409 0x02605, 0x02713, 0x022A9,
415 0x025CA, 0x025FB, 0x025C0,
420 static int UnicodeBulletPanel2[CHARMAX] = {
441 static int UnicodeBulletPanel3[CHARMAX] = {
462 static int UnicodeBulletPanel4[CHARMAX] = {
483 static int UnicodeBulletPanel5[CHARMAX] = {
503 }; /* string const BulletPanels[][] */
505 static int * UnicodeBulletPanels[FONTMAX] = {
506 UnicodeBulletPanel0, UnicodeBulletPanel1,
507 UnicodeBulletPanel2, UnicodeBulletPanel3,
508 UnicodeBulletPanel4, UnicodeBulletPanel5
511 return docstring(1, char_type(UnicodeBulletPanels[f][c]));
515 void Bullet::testInvariant() const
517 #ifdef ENABLE_ASSERTIONS
518 LATTEST(font >= MIN);
519 LATTEST(font < FONTMAX);
520 LATTEST(character >= MIN);
521 LATTEST(character < CHARMAX);
522 LATTEST(size >= MIN);
523 LATTEST(size < SIZEMAX);
524 LATTEST(user_text >= -1);
525 LATTEST(user_text <= 1);
526 // now some relational/operational tests
527 if (user_text == 1) {
528 LATTEST(font == -1 && (character == -1 && size == -1));
529 // LATTEST(!text.empty()); // this isn't necessarily an error
531 // else if (user_text == -1) {
532 // LATTEST(!text.empty()); // this also isn't necessarily an error
536 // LATTEST(text.empty()); // not usually true