PolyFontManager.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. Copyright (C) 2011 by Ivan Safrin
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #pragma once
  20. #include "PolyGlobals.h"
  21. #include "PolyString.h"
  22. #include <vector>
  23. #include "ft2build.h"
  24. #include FT_FREETYPE_H
  25. namespace Polycode {
  26. class Font;
  27. class FontEntry {
  28. public:
  29. String fontName;
  30. Font *font;
  31. };
  32. /**
  33. * Manages fonts. The font manager shoudl only be accessed via the CoreServices singleton.
  34. */
  35. class _PolyExport FontManager : public PolyBase {
  36. public:
  37. FontManager();
  38. ~FontManager();
  39. /**
  40. * Loads and registers a new font for use.
  41. * @param fontName Name to register the font as.
  42. * @param fontPath Filename of the font to load.
  43. */
  44. void registerFont(const String& fontName, const String& fontPath);
  45. /**
  46. * Retuns a font based on the registerd font name.
  47. * @param fontName Name of registered font name.
  48. * @return The font instance associated with the font name or NULL if one doesn't exist.
  49. */
  50. Font *getFontByName(const String& fontName);
  51. /**
  52. * Returns number of registered fonts.
  53. */
  54. unsigned int getNumFonts() const;
  55. /**
  56. * Returns the font entry by specified index or NULL if index is invalid.
  57. */
  58. FontEntry *getFontEntryByIndex(const unsigned int index);
  59. /**
  60. * Returns the font entry based on the font path or NULL if no fonts are registered with the specified path.
  61. */
  62. FontEntry *getFontEntryByFontPath(const String &fontPath);
  63. /**
  64. * Removes the font entry from manager and optionally delets the associated Font.
  65. * @param entry FontEntry to remove.
  66. */
  67. void removeFontEntry(FontEntry *entry, bool deleteFont);
  68. private:
  69. FT_Library FTLibrary;
  70. std::vector <FontEntry> fonts;
  71. };
  72. }