Font.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // Copyright (c) 2008-2014 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "ArrayPtr.h"
  24. #include "Resource.h"
  25. namespace Urho3D
  26. {
  27. class FontFace;
  28. static const int FONT_TEXTURE_MIN_SIZE = 128;
  29. static const int FONT_DPI = 96;
  30. /// %Font file type.
  31. enum FONT_TYPE
  32. {
  33. FONT_NONE = 0,
  34. FONT_FREETYPE,
  35. FONT_BITMAP,
  36. MAX_FONT_TYPES
  37. };
  38. /// %Font resource.
  39. class URHO3D_API Font : public Resource
  40. {
  41. OBJECT(Font);
  42. public:
  43. /// Construct.
  44. Font(Context* context);
  45. /// Destruct.
  46. virtual ~Font();
  47. /// Register object factory.
  48. static void RegisterObject(Context* context);
  49. /// Load resource. Return true if successful.
  50. virtual bool Load(Deserializer& source);
  51. /// Save resource as a new bitmap font type in XML format. Return true if successful.
  52. bool SaveXML(Serializer& dest, int pointSize, bool usedGlyphs = false);
  53. /// Return font face. Pack and render to a texture if not rendered yet. Return null on error.
  54. FontFace* GetFace(int pointSize);
  55. /// Release font faces and recreate them next time when requested. Called when font textures lost or global font properties change.
  56. void ReleaseFaces();
  57. private:
  58. /// Return font face using FreeTyp. Called internally. Return null on error.
  59. FontFace* GetFaceFreeType(int pointSize);
  60. /// Return bitmap font face. Called internally. Return null on error.
  61. FontFace* GetFaceBitmap(int pointSize);
  62. /// Created faces.
  63. HashMap<int, SharedPtr<FontFace> > faces_;
  64. /// Font data.
  65. SharedArrayPtr<unsigned char> fontData_;
  66. /// Size of font data.
  67. unsigned fontDataSize_;
  68. /// Font type.
  69. FONT_TYPE fontType_;
  70. };
  71. }