llstyle.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /**
  2. * @file llstyle.cpp
  3. * @brief Text style class
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "linden_common.h"
  33. #include "llstyle.h"
  34. #include "llfontgl.h"
  35. #include "llstring.h"
  36. LLStyle::LLStyle()
  37. {
  38. init(true, LLColor4(0, 0, 0, 1), LLStringUtil::null);
  39. }
  40. LLStyle::LLStyle(const LLStyle& style)
  41. {
  42. if (this != &style)
  43. {
  44. init(style.isVisible(), style.getColor(), style.getFontString());
  45. if (style.isLink())
  46. {
  47. setLinkHREF(style.getLinkHREF());
  48. }
  49. mItalic = style.mItalic;
  50. mBold = style.mBold;
  51. mUnderline = style.mUnderline;
  52. mDropShadow = style.mDropShadow;
  53. mImageHeight = style.mImageHeight;
  54. mImageWidth = style.mImageWidth;
  55. mImagep = style.mImagep;
  56. mIsEmbeddedItem = style.mIsEmbeddedItem;
  57. }
  58. else
  59. {
  60. init(true, LLColor4(0, 0, 0, 1), LLStringUtil::null);
  61. }
  62. }
  63. LLStyle::LLStyle(bool is_visible, const LLColor4& color,
  64. const std::string& font_name)
  65. {
  66. init(is_visible, color, font_name);
  67. }
  68. void LLStyle::init(bool is_visible, const LLColor4& color,
  69. const std::string& font_name)
  70. {
  71. mVisible = is_visible;
  72. mColor = color;
  73. setFontName(font_name);
  74. setLinkHREF(LLStringUtil::null);
  75. mItalic = false;
  76. mBold = false;
  77. mUnderline = false;
  78. mDropShadow = false;
  79. mImageHeight = 0;
  80. mImageWidth = 0;
  81. mIsEmbeddedItem = false;
  82. }
  83. // Copy assignment
  84. LLStyle& LLStyle::operator=(const LLStyle& rhs)
  85. {
  86. if (this != &rhs)
  87. {
  88. setVisible(rhs.isVisible());
  89. setColor(rhs.getColor());
  90. this->mFontName = rhs.getFontString();
  91. this->mLink = rhs.getLinkHREF();
  92. mImagep = rhs.mImagep;
  93. mImageHeight = rhs.mImageHeight;
  94. mImageWidth = rhs.mImageWidth;
  95. mItalic = rhs.mItalic;
  96. mBold = rhs.mBold;
  97. mUnderline = rhs.mUnderline;
  98. mDropShadow = rhs.mDropShadow;
  99. mIsEmbeddedItem = rhs.mIsEmbeddedItem;
  100. }
  101. return *this;
  102. }
  103. void LLStyle::setFontName(const std::string& fontname)
  104. {
  105. mFontName = fontname;
  106. std::string fontname_lc = fontname;
  107. LLStringUtil::toLower(fontname_lc);
  108. mFontID = LLFONT_SMALL; // Default
  109. if (fontname_lc == "sansserif" || fontname_lc == "sans-serif")
  110. {
  111. mFontID = LLFONT_SANSSERIF;
  112. }
  113. else if (fontname_lc == "serif")
  114. {
  115. mFontID = LLFONT_SMALL;
  116. }
  117. else if (fontname_lc == "sansseriflarge" || fontname_lc == "sansserifbig")
  118. {
  119. mFontID = LLFONT_SANSSERIF_LARGE;
  120. }
  121. else if (fontname_lc == "small")
  122. {
  123. mFontID = LLFONT_SANSSERIF_SMALL;
  124. }
  125. else if (fontname_lc == "emoji")
  126. {
  127. mFontID = LLFONT_EMOJI;
  128. }
  129. }