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