llfontregistry.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /**
  2. * @file llfontregistry.h
  3. * @author Brad Payne
  4. * @brief Storage for fonts.
  5. *
  6. * $LicenseInfo:firstyear=2008&license=viewergpl$
  7. *
  8. * Copyright (c) 2008-2009, Linden Research, Inc.
  9. *
  10. * Second Life Viewer Source Code
  11. * The source code in this file ("Source Code") is provided by Linden Lab
  12. * to you under the terms of the GNU General Public License, version 2.0
  13. * ("GPL"), unless you have obtained a separate licensing agreement
  14. * ("Other License"), formally executed by you and Linden Lab. Terms of
  15. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  16. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  17. *
  18. * There are special exceptions to the terms and conditions of the GPL as
  19. * it is applied to this Source Code. View the full text of the exception
  20. * in the file doc/FLOSS-exception.txt in this software distribution, or
  21. * online at
  22. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  23. *
  24. * By copying, modifying or distributing this software, you acknowledge
  25. * that you have read and understood your obligations described above,
  26. * and agree to abide by those obligations.
  27. *
  28. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  29. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  30. * COMPLETENESS OR PERFORMANCE.
  31. * $/LicenseInfo$
  32. */
  33. #ifndef LL_LLFONTREGISTRY_H
  34. #define LL_LLFONTREGISTRY_H
  35. #include <functional>
  36. #include <map>
  37. #include <vector>
  38. #include "llpointer.h"
  39. #include "llstring.h"
  40. class LLFontGL;
  41. typedef std::vector<std::string> string_vec_t;
  42. struct LLFontFileInfo
  43. {
  44. LL_INLINE LLFontFileInfo(const std::string& file_name,
  45. const std::function<bool(llwchar)>& ftor = NULL)
  46. : mFileName(file_name),
  47. mCharFunctor(ftor)
  48. {
  49. }
  50. LL_INLINE LLFontFileInfo(const LLFontFileInfo& ffi)
  51. : mFileName(ffi.mFileName),
  52. mCharFunctor(ffi.mCharFunctor)
  53. {
  54. }
  55. std::string mFileName;
  56. std::function<bool(llwchar)> mCharFunctor;
  57. };
  58. typedef std::vector<LLFontFileInfo> font_file_info_vec_t;
  59. class LLFontDescriptor
  60. {
  61. public:
  62. LLFontDescriptor();
  63. LLFontDescriptor(const std::string& name, const std::string& size,
  64. U8 style = 0); // 0 = NORMAL style
  65. LLFontDescriptor(const std::string& name, const std::string& size,
  66. U8 style, const font_file_info_vec_t& font_list);
  67. LLFontDescriptor normalize() const;
  68. bool operator<(const LLFontDescriptor& b) const;
  69. bool isTemplate() const;
  70. LL_INLINE const std::string& getName() const { return mName; }
  71. LL_INLINE void setName(const std::string& name) { mName = name; }
  72. LL_INLINE const std::string& getSize() const { return mSize; }
  73. LL_INLINE void setSize(const std::string& size) { mSize = size; }
  74. void addFontFile(const std::string& file_name,
  75. const std::string& char_functor = LLStringUtil::null);
  76. LL_INLINE void setFontFiles(const font_file_info_vec_t& font_files)
  77. {
  78. mFontFiles = font_files;
  79. }
  80. LL_INLINE const font_file_info_vec_t& getFontFiles() const
  81. {
  82. return mFontFiles;
  83. }
  84. LL_INLINE font_file_info_vec_t& getFontFiles() { return mFontFiles; }
  85. LL_INLINE U8 getStyle() const { return mStyle; }
  86. LL_INLINE void setStyle(U8 style) { mStyle = style; }
  87. private:
  88. std::string mName;
  89. std::string mSize;
  90. font_file_info_vec_t mFontFiles;
  91. U8 mStyle;
  92. typedef std::map<std::string,
  93. std::function<bool(llwchar)>> char_functor_map_t;
  94. static char_functor_map_t sCharFunctors;
  95. };
  96. class LLFontRegistry
  97. {
  98. friend bool init_from_xml(LLFontRegistry*, LLPointer<class LLXMLNode>);
  99. protected:
  100. LOG_CLASS(LLFontRegistry);
  101. public:
  102. LLFontRegistry(const string_vec_t& xui_paths,
  103. bool create_gl_textures = true);
  104. ~LLFontRegistry();
  105. // Load standard font info from XML file(s).
  106. bool parseFontInfo(const std::string& xml_filename);
  107. // Clear cached glyphs for all fonts.
  108. void reset();
  109. // Destroy all fonts.
  110. void clear();
  111. // GL cleanup
  112. void destroyGL();
  113. LLFontGL* getFont(const LLFontDescriptor& desc, bool normalize = true);
  114. const LLFontDescriptor* getMatchingFontDesc(const LLFontDescriptor& desc);
  115. const LLFontDescriptor* getClosestFontTemplate(const LLFontDescriptor& desc);
  116. bool nameToSize(const std::string& size_name, F32& size);
  117. void dump();
  118. LL_INLINE const string_vec_t& getUltimateFallbackList() const
  119. {
  120. return mUltimateFallbackList;
  121. }
  122. private:
  123. LLFontRegistry(const LLFontRegistry& other); // no-copy
  124. LLFontGL* createFont(const LLFontDescriptor& desc);
  125. private:
  126. // Given a descriptor, look up specific font instantiation.
  127. typedef std::map<LLFontDescriptor, LLFontGL*> font_reg_map_t;
  128. font_reg_map_t mFontMap;
  129. // Given a size name, look up the point size.
  130. typedef std::map<std::string, F32> font_size_map_t;
  131. font_size_map_t mFontSizes;
  132. string_vec_t mUltimateFallbackList;
  133. string_vec_t mXUIPaths;
  134. bool mCreateGLTextures;
  135. };
  136. #endif // LL_LLFONTREGISTRY_H