FontDatabaseDefault.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * This source file is part of RmlUi, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://github.com/mikke89/RmlUi
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. * Copyright (c) 2019 The RmlUi Team, and contributors
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. * THE SOFTWARE.
  26. *
  27. */
  28. #ifndef RMLUICOREFONTDATABASE_H
  29. #define RMLUICOREFONTDATABASE_H
  30. #include <RmlUi/Core/StringUtilities.h>
  31. #include <RmlUi/Core/Header.h>
  32. #include "FontProvider.h"
  33. namespace Rml {
  34. namespace Core {
  35. #ifndef RMLUI_NO_FONT_INTERFACE_DEFAULT
  36. class FontEffect;
  37. class FontFamily;
  38. class FontFaceHandleDefault;
  39. class PropertyDictionary;
  40. /**
  41. The font database contains all font families currently in use by RmlUi.
  42. @author Peter Curry
  43. */
  44. class RMLUICORE_API FontDatabaseDefault
  45. {
  46. public:
  47. enum FontProviderType
  48. {
  49. FreeType = 0,
  50. BitmapFont
  51. };
  52. static bool Initialise();
  53. static void Shutdown();
  54. /// Adds a new font face to the database. The face's family, style and weight will be determined from the face itself.
  55. /// @param[in] file_name The file to load the face from.
  56. /// @return True if the face was loaded successfully, false otherwise.
  57. static bool LoadFontFace(const String& file_name);
  58. /// Returns a handle to a font face that can be used to position and render text. This will return the closest match
  59. /// it can find, but in the event a font family is requested that does not exist, nullptr will be returned instead of a
  60. /// valid handle.
  61. /// @param[in] family The family of the desired font handle.
  62. /// @param[in] charset The set of characters required in the font face, as a comma-separated list of unicode ranges.
  63. /// @param[in] style The style of the desired font handle.
  64. /// @param[in] weight The weight of the desired font handle.
  65. /// @param[in] size The size of desired handle, in points.
  66. /// @return A valid handle if a matching (or closely matching) font face was found, nullptr otherwise.
  67. static SharedPtr<FontFaceHandleDefault> GetFontFaceHandle(const String& family, const String& charset, Style::FontStyle style, Style::FontWeight weight, int size);
  68. static void AddFontProvider(FontProvider * provider);
  69. static void RemoveFontProvider(FontProvider * provider);
  70. private:
  71. FontDatabaseDefault(void);
  72. ~FontDatabaseDefault(void);
  73. static FontProviderType GetFontProviderType(const String& file_name);
  74. typedef std::vector< FontProvider *> FontProviderTable;
  75. static FontProviderTable font_provider_table;
  76. static FontDatabaseDefault* instance;
  77. };
  78. #endif
  79. }
  80. }
  81. #endif