BsFontDesc.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. namespace bs
  6. {
  7. /** @addtogroup Text
  8. * @{
  9. */
  10. /** Kerning pair representing larger or smaller offset between a specific pair of characters. */
  11. struct BS_SCRIPT_EXPORT(pl:true,m:GUI_Engine) KerningPair
  12. {
  13. UINT32 otherCharId;
  14. INT32 amount;
  15. };
  16. /** Describes a single character in a font of a specific size. */
  17. struct BS_SCRIPT_EXPORT(pl:true,m:GUI_Engine) CharDesc
  18. {
  19. UINT32 charId; /**< Character ID, corresponding to a Unicode key. */
  20. UINT32 page; /**< Index of the texture the character is located on. */
  21. float uvX, uvY; /**< Texture coordinates of the character in the page texture. */
  22. float uvWidth, uvHeight; /**< Width/height of the character in texture coordinates. */
  23. UINT32 width, height; /**< Width/height of the character in pixels. */
  24. INT32 xOffset, yOffset; /**< Offset for the visible portion of the character in pixels. */
  25. INT32 xAdvance, yAdvance; /**< Determines how much to advance the pen after writing this character, in pixels. */
  26. /**
  27. * Pairs that determine if certain character pairs should be closer or father together. for example "AV"
  28. * combination.
  29. */
  30. Vector<KerningPair> kerningPairs;
  31. };
  32. /** @cond SPECIALIZATIONS */
  33. // Make CHAR_DESC serializable
  34. template<> struct RTTIPlainType<CharDesc>
  35. {
  36. enum { id = TID_CHAR_DESC }; enum { hasDynamicSize = 1 };
  37. static void toMemory(const CharDesc& data, char* memory)
  38. {
  39. UINT32 size = getDynamicSize(data);
  40. memcpy(memory, &size, sizeof(UINT32));
  41. memory += sizeof(UINT32);
  42. memory = rttiWriteElem(data.charId, memory);
  43. memory = rttiWriteElem(data.page, memory);
  44. memory = rttiWriteElem(data.uvX, memory);
  45. memory = rttiWriteElem(data.uvY, memory);
  46. memory = rttiWriteElem(data.uvWidth, memory);
  47. memory = rttiWriteElem(data.uvHeight, memory);
  48. memory = rttiWriteElem(data.width, memory);
  49. memory = rttiWriteElem(data.height, memory);
  50. memory = rttiWriteElem(data.xOffset, memory);
  51. memory = rttiWriteElem(data.yOffset, memory);
  52. memory = rttiWriteElem(data.xAdvance, memory);
  53. memory = rttiWriteElem(data.yAdvance, memory);
  54. memory = rttiWriteElem(data.kerningPairs, memory);
  55. }
  56. static UINT32 fromMemory(CharDesc& data, char* memory)
  57. {
  58. UINT32 size;
  59. memcpy(&size, memory, sizeof(UINT32));
  60. memory += sizeof(UINT32);
  61. memory = rttiReadElem(data.charId, memory);
  62. memory = rttiReadElem(data.page, memory);
  63. memory = rttiReadElem(data.uvX, memory);
  64. memory = rttiReadElem(data.uvY, memory);
  65. memory = rttiReadElem(data.uvWidth, memory);
  66. memory = rttiReadElem(data.uvHeight, memory);
  67. memory = rttiReadElem(data.width, memory);
  68. memory = rttiReadElem(data.height, memory);
  69. memory = rttiReadElem(data.xOffset, memory);
  70. memory = rttiReadElem(data.yOffset, memory);
  71. memory = rttiReadElem(data.xAdvance, memory);
  72. memory = rttiReadElem(data.yAdvance, memory);
  73. memory = rttiReadElem(data.kerningPairs, memory);
  74. return size;
  75. }
  76. static UINT32 getDynamicSize(const CharDesc& data)
  77. {
  78. UINT64 dataSize = sizeof(data.charId)
  79. + sizeof(data.page)
  80. + sizeof(data.uvX)
  81. + sizeof(data.uvY)
  82. + sizeof(data.uvWidth)
  83. + sizeof(data.uvHeight)
  84. + sizeof(data.width)
  85. + sizeof(data.height)
  86. + sizeof(data.xOffset)
  87. + sizeof(data.yOffset)
  88. + sizeof(data.xAdvance)
  89. + sizeof(data.yAdvance)
  90. + RTTIPlainType<Vector<KerningPair>>::getDynamicSize(data.kerningPairs);
  91. dataSize += sizeof(UINT32);
  92. return (UINT32)dataSize;
  93. }
  94. };
  95. /** @endcond */
  96. /** @} */
  97. }