X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FBullet.cpp;h=1e617773ad4053e50bd00e9402df73b659af4549;hb=bfe98181169d9e697e515da974d9b6a15a06c940;hp=5c0f91741991387208e4ee88454c91b94171ba45;hpb=f630be890494c849981e4fb52ea4740506e92bed;p=lyx.git diff --git a/src/Bullet.cpp b/src/Bullet.cpp index 5c0f917419..1e617773ad 100644 --- a/src/Bullet.cpp +++ b/src/Bullet.cpp @@ -3,7 +3,7 @@ * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * - * \author Lars Gullik Bjønnes + * \author Lars Gullik Bjønnes * \author Allan Rae * * Full author contact details are available in file CREDITS. @@ -18,11 +18,11 @@ #include "Bullet.h" -#include +#include "support/lassert.h" -namespace lyx { +using namespace std; -using std::string; +namespace lyx { /** The four LaTeX itemize environment default bullets @@ -41,15 +41,12 @@ Bullet const ITEMIZE_DEFAULTS[4] = { Bullet(0, 8),//"\\(\\bullet\\)" Bullet::Bullet(int f, int c, int s) : font(f), character(c), size(s), user_text(0) { - if (f < MIN || f >= FONTMAX) { + if (f < MIN || f >= FONTMAX) font = MIN; - } - if (c < MIN || c >= CHARMAX) { + if (c < MIN || c >= CHARMAX) character = MIN; - } - if (s < MIN || s >= SIZEMAX) { + if (s < MIN || s >= SIZEMAX) size = MIN; - } generateText(); testInvariant(); } @@ -57,7 +54,7 @@ Bullet::Bullet(int f, int c, int s) Bullet::Bullet(docstring const & t) - : font(MIN), character(MIN), size(MIN), user_text(1), text(t) + : font(MIN), character(MIN), size(MIN), user_text(1), text(t), unicode(t) { testInvariant(); } @@ -65,11 +62,10 @@ Bullet::Bullet(docstring const & t) void Bullet::setCharacter(int c) { - if (c < MIN || c >= CHARMAX) { + if (c < MIN || c >= CHARMAX) character = MIN; - } else { + else character = c; - } user_text = 0; testInvariant(); } @@ -77,11 +73,10 @@ void Bullet::setCharacter(int c) void Bullet::setFont(int f) { - if (f < MIN || f >= FONTMAX) { + if (f < MIN || f >= FONTMAX) font = MIN; - } else { + else font = f; - } user_text = 0; testInvariant(); } @@ -89,11 +84,10 @@ void Bullet::setFont(int f) void Bullet::setSize(int s) { - if (s < MIN || s >= SIZEMAX) { + if (s < MIN || s >= SIZEMAX) size = MIN; - } else { + else size = s; - } user_text = 0; testInvariant(); } @@ -104,6 +98,7 @@ void Bullet::setText(docstring const & t) font = character = size = MIN; user_text = 1; text = t; + unicode = t; testInvariant(); } @@ -126,6 +121,16 @@ int Bullet::getSize() const } +FontSize Bullet::getFontSize() const +{ + + if (size >= 0) + return bulletFontSize(size); + else + return INHERIT_SIZE; +} + + Bullet & Bullet::operator=(Bullet const & b) { b.testInvariant(); @@ -134,6 +139,7 @@ Bullet & Bullet::operator=(Bullet const & b) size = b.size; user_text = b.user_text; text = b.text; + unicode = b.unicode; this->testInvariant(); return *this; } @@ -141,25 +147,30 @@ Bullet & Bullet::operator=(Bullet const & b) docstring const & Bullet::getText() const { - if (user_text == 0) { + if (user_text == 0) generateText(); - } return text; } +docstring const & Bullet::getUnicode() const +{ + if (user_text == 0) + generateText(); + return unicode; +} + + bool operator==(const Bullet & b1, const Bullet & b2) { bool result = false; if (b1.user_text && b2.user_text) { /* both have valid text */ - if (b1.text == b2.text) { + if (b1.text == b2.text) result = true; - } - } else if (((b1.character == b2.character) && - (b1.font == b2.font)) && - (b1.size == b2.size)) { + } else if (b1.character == b2.character && b1.font == b2.font && + b1.size == b2.size) { result = true; } return result; @@ -185,9 +196,9 @@ void Bullet::generateText() const if ((font >= 0) && (character >= 0)) { text = bulletEntry(font, character); - if (size >= 0) { + unicode = bulletUnicode(font, character); + if (size >= 0) text = bulletSize(size) + text; - } user_text = -1; // text is now defined and doesn't need to be recalculated // unless font/character or text is modified @@ -355,28 +366,175 @@ docstring const Bullet::bulletEntry(int f, int c) return from_ascii(BulletPanels[f][c]); } + +FontSize Bullet::bulletFontSize(int s) +{ + // see comment at bulletSize + static FontSize BulletFontSize[SIZEMAX] = { + TINY_SIZE, SCRIPT_SIZE, FOOTNOTE_SIZE, SMALL_SIZE, NORMAL_SIZE, + LARGE_SIZE, LARGER_SIZE, LARGEST_SIZE, HUGE_SIZE, HUGER_SIZE + }; + + return BulletFontSize[s]; +} + + +docstring const Bullet::bulletUnicode(int f, int c) +{ + // see comment at bulletEntry + static int UnicodeBulletPanel0[CHARMAX] = { + /* standard */ + 0x02013, 0x22A2, + 0x022A3, 0x0266D, 0x0266E, + 0x0266F, 0x02217, 0x022C6, + 0x02022, 0x02218, 0x022C5, + 0x02020, 0x025B3, + 0x025BD, 0x025C3, + 0x025B9, 0x025C1, 0x025B7, + 0x02295, 0x02296, 0x02297, + 0x02298, 0x02299, 0x02660, + 0x022C4, 0x025C7, /* \square */ 0x025FB, + 0x02662, 0x02661, + 0x02663, 0x02192, 0x02933, + 0x021C0, 0x021C1, + 0x021D2, 0x0227B + }; + static int UnicodeBulletPanel1[CHARMAX] = { + /* amssymb */ + 0x021DB, 0x021A3, + 0x021A0, 0x021DD, + 0x021AC, 0x022B8, + 0x022A0, 0x0229E, 0x0229F, + 0x022A1, 0x022C7, 0x022AA, + 0x022D6, 0x022D7, 0x02720, + 0x02605, 0x02713, 0x022A9, + 0x0223D, 0x0223C, + 0x02B1D, 0x0229D, + 0x0229B, 0x025CE, + 0x022B2, 0x022B3, + 0x025B3, 0x025BD, + 0x025CA, 0x025FB, 0x025C0, + 0x025B6, 0x025B4, + 0x025BE, 0x029EB, + 0x025FC + }; + static int UnicodeBulletPanel2[CHARMAX] = { + /* psnfss1 */ + 0x025CF, 0x0274D, + 0x025D7, 0x02295, + 0x02297, 0x02022, + 0x02727, 0x02726, + 0x02756, 0x025C6, + 0x025CA, 0x022C5, + 0x02751, 0x02752, + 0x0274F, 0x02750, + 0x02206, 0x02207, + 0x02758, 0x02759, + 0x0275A, 0x025A0, + 0x025B2, 0x025BC, + 0x02217, 0x02723, + 0x02722, 0x02732, + 0x02731, 0x027A4, + 0x02762, 0x02763, + 0x02766, 0x02767, + 0x027A2, 0x027A3 + }; + static int UnicodeBulletPanel3[CHARMAX] = { + /* psnfss2 */ + 0x0260E, 0x02706, + 0x02702, 0x02704, + 0x02707, 0x02708, + 0x02709, 0x0261B, + 0x0261E, 0x0270C, + 0x0270D, 0x0270F, + 0x02715, 0x02716, + 0x0271B, 0x02719, + 0x0271E, 0x0271D, + 0x02717, 0x02718, + 0x0271A, 0x0271C, + 0x0271F, 0x02720, + 0x02713, 0x02714, + 0x02660, 0x02663, + 0x02666, 0x02665, + 0x02764, 0x02765, + 0x02660, 0x02663, + 0x02666, 0x02665 + }; + static int UnicodeBulletPanel4[CHARMAX] = { + /* psnfss3 */ + 0x02721, 0x0272C, + 0x0272B, 0x02B51, + 0x02730, 0x0272A, + 0x0272E, 0x0272D, + 0x0272F, 0x02735, + 0x0273A, 0x02742, + 0x02733, 0x02734, + 0x02736, 0x02737, + 0x02738, 0x02739, + 0x0273C, 0x0273B, + 0x0273D, 0x02749, + 0x0273E, 0x02743, + 0x02747, 0x02748, + 0x0274A, 0x0274B, + 0x02724, 0x02725, + 0x02744, 0x02745, + 0x02746, 0x02740, + 0x0273F, 0x02741 + }; + static int UnicodeBulletPanel5[CHARMAX] = { + /* psnfss4 */ + 0x0279F, 0x027A0, + 0x027A1, 0x027A8, + 0x027A5, 0x027A6, + 0x027AE, 0x027AD, + 0x027AC, 0x027AB, + 0x027AA, 0x027A9, + 0x027AF, 0x027B1, + 0x027BA, 0x027BB, + 0x02711, 0x02712, + 0x02799, 0x027B5, + 0x027B3, 0x027B8, + 0x027BC, 0x027BD, + 0x0279B, 0x02192, + 0x0279D, 0x0279E, + 0x0279C, 0x02794, + 0x02192, 0x021D2, + 0x027BE, 0x027B2, + 0x027A7, 0x02212 + }; /* string const BulletPanels[][] */ + + static int * UnicodeBulletPanels[FONTMAX] = { + UnicodeBulletPanel0, UnicodeBulletPanel1, + UnicodeBulletPanel2, UnicodeBulletPanel3, + UnicodeBulletPanel4, UnicodeBulletPanel5 + }; + + return docstring(1, char_type(UnicodeBulletPanels[f][c])); +} + + void Bullet::testInvariant() const { #ifdef ENABLE_ASSERTIONS - BOOST_ASSERT(font >= MIN); - BOOST_ASSERT(font < FONTMAX); - BOOST_ASSERT(character >= MIN); - BOOST_ASSERT(character < CHARMAX); - BOOST_ASSERT(size >= MIN); - BOOST_ASSERT(size < SIZEMAX); - BOOST_ASSERT(user_text >= -1); - BOOST_ASSERT(user_text <= 1); + LATTEST(font >= MIN); + LATTEST(font < FONTMAX); + LATTEST(character >= MIN); + LATTEST(character < CHARMAX); + LATTEST(size >= MIN); + LATTEST(size < SIZEMAX); + LATTEST(user_text >= -1); + LATTEST(user_text <= 1); // now some relational/operational tests if (user_text == 1) { - BOOST_ASSERT(font == -1 && (character == -1 && size == -1)); - // BOOST_ASSERT(!text.empty()); // this isn't necessarily an error + LATTEST(font == -1 && (character == -1 && size == -1)); + // LATTEST(!text.empty()); // this isn't necessarily an error } // else if (user_text == -1) { - // BOOST_ASSERT(!text.empty()); // this also isn't necessarily an error + // LATTEST(!text.empty()); // this also isn't necessarily an error // } // else { // // user_text == 0 - // BOOST_ASSERT(text.empty()); // not usually true + // LATTEST(text.empty()); // not usually true // } #endif }