FontDatabase.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * This source file is part of libRocket, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://www.librocket.com
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. *
  26. */
  27. #ifndef ROCKETCOREFONTDATABASE_H
  28. #define ROCKETCOREFONTDATABASE_H
  29. #include "StringUtilities.h"
  30. #include "Header.h"
  31. #include "Font.h"
  32. #include "FontProvider.h"
  33. namespace Rocket {
  34. namespace Core {
  35. class FontEffect;
  36. class FontFamily;
  37. class FontFaceHandle;
  38. class PropertyDictionary;
  39. /**
  40. The font database contains all font families currently in use by Rocket.
  41. @author Peter Curry
  42. */
  43. class ROCKETCORE_API FontDatabase
  44. {
  45. public:
  46. enum FontProviderType
  47. {
  48. FreeType = 0,
  49. BitmapFont
  50. };
  51. static bool Initialise();
  52. static void Shutdown();
  53. /// Adds a new font face to the database. The face's family, style and weight will be determined from the face itself.
  54. /// @param[in] file_name The file to load the face from.
  55. /// @return True if the face was loaded successfully, false otherwise.
  56. static bool LoadFontFace(const String& file_name);
  57. /// Adds a new font face to the database, ignoring any family, style and weight information stored in the face itself.
  58. /// @param[in] file_name The file to load the face from.
  59. /// @param[in] family The family to add the face to.
  60. /// @param[in] style The style of the face (normal or italic).
  61. /// @param[in] weight The weight of the face (normal or bold).
  62. /// @return True if the face was loaded successfully, false otherwise.
  63. static bool LoadFontFace(const String& file_name, const String& family, Font::Style style, Font::Weight weight);
  64. /// Adds a new font face to the database, loading from memory. The face's family, style and weight will be determined from the face itself.
  65. /// @param[in] data The font data.
  66. /// @param[in] data_length Length of the data.
  67. /// @return True if the face was loaded successfully, false otherwise.
  68. static bool LoadFontFace(FontProviderType font_provider_type, const byte* data, int data_length);
  69. /// Adds a new font face to the database, loading from memory.
  70. /// @param[in] data The font data.
  71. /// @param[in] data_length Length of the data.
  72. /// @param[in] family The family to add the face to.
  73. /// @param[in] style The style of the face (normal or italic).
  74. /// @param[in] weight The weight of the face (normal or bold).
  75. /// @return True if the face was loaded successfully, false otherwise.
  76. static bool LoadFontFace(FontProviderType font_provider_type, const byte* data, int data_length, const String& family, Font::Style style, Font::Weight weight);
  77. /// Returns a handle to a font face that can be used to position and render text. This will return the closest match
  78. /// it can find, but in the event a font family is requested that does not exist, NULL will be returned instead of a
  79. /// valid handle.
  80. /// @param[in] family The family of the desired font handle.
  81. /// @param[in] charset The set of characters required in the font face, as a comma-separated list of unicode ranges.
  82. /// @param[in] style The style of the desired font handle.
  83. /// @param[in] weight The weight of the desired font handle.
  84. /// @param[in] size The size of desired handle, in points.
  85. /// @return A valid handle if a matching (or closely matching) font face was found, NULL otherwise.
  86. static FontFaceHandle* GetFontFaceHandle(const String& family, const String& charset, Font::Style style, Font::Weight weight, int size);
  87. /// Returns a font effect, either a newly-instanced effect from the factory or an identical
  88. /// shared effect.
  89. /// @param[in] name The name of the desired font effect type.
  90. /// @param[in] properties The properties associated with the font effect.
  91. /// @return The requested font effect, or NULL if the font effect could not be found or instanced.
  92. static FontEffect* GetFontEffect(const String& name, const PropertyDictionary& properties);
  93. /// Removes a font effect from the font database's cache.
  94. /// @param[in] The effect to release.
  95. static void ReleaseFontEffect(const FontEffect* effect);
  96. static void AddFontProvider(FontProvider * provider);
  97. static void RemoveFontProvider(FontProvider * provider);
  98. private:
  99. FontDatabase(void);
  100. ~FontDatabase(void);
  101. static FontProviderType GetFontProviderType(const String& file_name);
  102. typedef std::vector< FontProvider *> FontProviderTable;
  103. static FontProviderTable font_provider_table;
  104. static FontDatabase* instance;
  105. };
  106. }
  107. }
  108. #endif