tb_font_desc.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // ================================================================================
  2. // == This file is a part of Turbo Badger. (C) 2011-2014, Emil Segerås ==
  3. // == See tb_core.h for more information. ==
  4. // ================================================================================
  5. #ifndef TB_FONT_DESC_H
  6. #define TB_FONT_DESC_H
  7. #include "tb_types.h"
  8. #include "tb_id.h"
  9. namespace tb {
  10. /** TBFontDescription describes a font.
  11. By default when nothing is set, the font is unspecified and means it should be inherited
  12. from a parent widget that specifies a font, or use the default font if no parent does. */
  13. class TBFontDescription
  14. {
  15. public:
  16. /** Set the font ID of the font to use.
  17. This ID maps to the font names in TBFontInfo, which is managed from
  18. TBFontManager::AddFontInfo, TBFontManager::GetFontInfo.
  19. Example:
  20. If a font was added to the font manager with the name "Vera", you can
  21. do font_description.SetID(TBIDC("Vera")).
  22. */
  23. void SetID(const TBID &id) { m_id = id; }
  24. /** Get the TBID for the font name (See SetID). */
  25. TBID GetID() const { return m_id; }
  26. /** Get the TBID for the TBFontFace that matches this font description.
  27. This is a ID combining both the font file, and variation (such as size and style),
  28. and should be used to identify a certain font face.
  29. If this is 0, the font description is unspecified. For a widget, that means that the font
  30. should be inherited from the parent widget. */
  31. TBID GetFontFaceID() const { return m_id + m_packed_init; }
  32. void SetSize(uint32 size) { m_packed.size = MIN(size, 0x8000u); }
  33. uint32 GetSize() const { return m_packed.size; }
  34. //not connected to anything yet
  35. //void SetBold(bool bold) { m_packed.bold = bold; }
  36. //bool GetBold() const { return m_packed.bold; }
  37. //not connected to anything yet
  38. //void SetItalic(bool italic) { m_packed.italic = italic; }
  39. //bool GetItalic() const { return m_packed.italic; }
  40. TBFontDescription() : m_packed_init(0) {}
  41. TBFontDescription(const TBFontDescription &src) { m_packed_init = src.m_packed_init; m_id = src.m_id; }
  42. const TBFontDescription& operator = (const TBFontDescription &src) { m_packed_init = src.m_packed_init; m_id = src.m_id; return *this; }
  43. bool operator == (const TBFontDescription &fd) const { return m_packed_init == fd.m_packed_init && m_id == fd.m_id; }
  44. bool operator != (const TBFontDescription &fd) const { return !(*this == fd); }
  45. private:
  46. TBID m_id;
  47. union {
  48. struct {
  49. uint32 size : 15;
  50. uint32 italic : 1;
  51. uint32 bold : 1;
  52. } m_packed;
  53. uint32 m_packed_init;
  54. };
  55. };
  56. }; // namespace tb
  57. #endif // TB_FONT_DESC_H