TMP_FontFeaturesCommon.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.TextCore.LowLevel;
  6. namespace TMPro
  7. {
  8. public enum FontFeatureLookupFlags
  9. {
  10. IgnoreLigatures = 0x004,
  11. IgnoreSpacingAdjustments = 0x100,
  12. }
  13. /// <summary>
  14. /// The values used to adjust the position of a glyph or set of glyphs.
  15. /// </summary>
  16. [Serializable]
  17. public struct TMP_GlyphValueRecord
  18. {
  19. /// <summary>
  20. /// The positional adjustment affecting the horizontal bearing X of the glyph.
  21. /// </summary>
  22. public float xPlacement { get { return m_XPlacement; } set { m_XPlacement = value; } }
  23. /// <summary>
  24. /// The positional adjustment affecting the horizontal bearing Y of the glyph.
  25. /// </summary>
  26. public float yPlacement { get { return m_YPlacement; } set { m_YPlacement = value; } }
  27. /// <summary>
  28. /// The positional adjustment affecting the horizontal advance of the glyph.
  29. /// </summary>
  30. public float xAdvance { get { return m_XAdvance; } set { m_XAdvance = value; } }
  31. /// <summary>
  32. /// The positional adjustment affecting the vertical advance of the glyph.
  33. /// </summary>
  34. public float yAdvance { get { return m_YAdvance; } set { m_YAdvance = value; } }
  35. // =============================================
  36. // Private backing fields for public properties.
  37. // =============================================
  38. [SerializeField]
  39. private float m_XPlacement;
  40. [SerializeField]
  41. private float m_YPlacement;
  42. [SerializeField]
  43. private float m_XAdvance;
  44. [SerializeField]
  45. private float m_YAdvance;
  46. /// <summary>
  47. /// Constructor
  48. /// </summary>
  49. /// <param name="xPlacement">The positional adjustment affecting the horizontal bearing X of the glyph.</param>
  50. /// <param name="yPlacement">The positional adjustment affecting the horizontal bearing Y of the glyph.</param>
  51. /// <param name="xAdvance">The positional adjustment affecting the horizontal advance of the glyph.</param>
  52. /// <param name="yAdvance">The positional adjustment affecting the vertical advance of the glyph.</param>
  53. public TMP_GlyphValueRecord(float xPlacement, float yPlacement, float xAdvance, float yAdvance)
  54. {
  55. m_XPlacement = xPlacement;
  56. m_YPlacement = yPlacement;
  57. m_XAdvance = xAdvance;
  58. m_YAdvance = yAdvance;
  59. }
  60. internal TMP_GlyphValueRecord(GlyphValueRecord_Legacy valueRecord)
  61. {
  62. m_XPlacement = valueRecord.xPlacement;
  63. m_YPlacement = valueRecord.yPlacement;
  64. m_XAdvance = valueRecord.xAdvance;
  65. m_YAdvance = valueRecord.yAdvance;
  66. }
  67. internal TMP_GlyphValueRecord(GlyphValueRecord valueRecord)
  68. {
  69. m_XPlacement = valueRecord.xPlacement;
  70. m_YPlacement = valueRecord.yPlacement;
  71. m_XAdvance = valueRecord.xAdvance;
  72. m_YAdvance = valueRecord.yAdvance;
  73. }
  74. public static TMP_GlyphValueRecord operator +(TMP_GlyphValueRecord a, TMP_GlyphValueRecord b)
  75. {
  76. TMP_GlyphValueRecord c;
  77. c.m_XPlacement = a.xPlacement + b.xPlacement;
  78. c.m_YPlacement = a.yPlacement + b.yPlacement;
  79. c.m_XAdvance = a.xAdvance + b.xAdvance;
  80. c.m_YAdvance = a.yAdvance + b.yAdvance;
  81. return c;
  82. }
  83. }
  84. /// <summary>
  85. /// The positional adjustment values of a glyph.
  86. /// </summary>
  87. [Serializable]
  88. public struct TMP_GlyphAdjustmentRecord
  89. {
  90. /// <summary>
  91. /// The index of the glyph in the source font file.
  92. /// </summary>
  93. public uint glyphIndex { get { return m_GlyphIndex; } set { m_GlyphIndex = value; } }
  94. /// <summary>
  95. /// The GlyphValueRecord contains the positional adjustments of the glyph.
  96. /// </summary>
  97. public TMP_GlyphValueRecord glyphValueRecord { get { return m_GlyphValueRecord; } set { m_GlyphValueRecord = value; } }
  98. // =============================================
  99. // Private backing fields for public properties.
  100. // =============================================
  101. [SerializeField]
  102. private uint m_GlyphIndex;
  103. [SerializeField]
  104. private TMP_GlyphValueRecord m_GlyphValueRecord;
  105. /// <summary>
  106. /// Constructor
  107. /// </summary>
  108. /// <param name="glyphIndex">The index of the glyph in the source font file.</param>
  109. /// <param name="glyphValueRecord">The GlyphValueRecord contains the positional adjustments of the glyph.</param>
  110. public TMP_GlyphAdjustmentRecord(uint glyphIndex, TMP_GlyphValueRecord glyphValueRecord)
  111. {
  112. m_GlyphIndex = glyphIndex;
  113. m_GlyphValueRecord = glyphValueRecord;
  114. }
  115. internal TMP_GlyphAdjustmentRecord(GlyphAdjustmentRecord adjustmentRecord)
  116. {
  117. m_GlyphIndex = adjustmentRecord.glyphIndex;
  118. m_GlyphValueRecord = new TMP_GlyphValueRecord(adjustmentRecord.glyphValueRecord);
  119. }
  120. }
  121. /// <summary>
  122. /// The positional adjustment values for a pair of glyphs.
  123. /// </summary>
  124. [Serializable]
  125. public class TMP_GlyphPairAdjustmentRecord
  126. {
  127. /// <summary>
  128. /// Contains the positional adjustment values for the first glyph.
  129. /// </summary>
  130. public TMP_GlyphAdjustmentRecord firstAdjustmentRecord { get { return m_FirstAdjustmentRecord; } set { m_FirstAdjustmentRecord = value; } }
  131. /// <summary>
  132. /// Contains the positional adjustment values for the second glyph.
  133. /// </summary>
  134. public TMP_GlyphAdjustmentRecord secondAdjustmentRecord { get { return m_SecondAdjustmentRecord; } set { m_SecondAdjustmentRecord = value; } }
  135. /// <summary>
  136. ///
  137. /// </summary>
  138. public FontFeatureLookupFlags featureLookupFlags { get { return m_FeatureLookupFlags; } set { m_FeatureLookupFlags = value; } }
  139. // =============================================
  140. // Private backing fields for public properties.
  141. // =============================================
  142. [SerializeField]
  143. private TMP_GlyphAdjustmentRecord m_FirstAdjustmentRecord;
  144. [SerializeField]
  145. private TMP_GlyphAdjustmentRecord m_SecondAdjustmentRecord;
  146. [SerializeField]
  147. private FontFeatureLookupFlags m_FeatureLookupFlags;
  148. /// <summary>
  149. /// Constructor
  150. /// </summary>
  151. /// <param name="firstAdjustmentRecord">First glyph adjustment record.</param>
  152. /// <param name="secondAdjustmentRecord">Second glyph adjustment record.</param>
  153. public TMP_GlyphPairAdjustmentRecord(TMP_GlyphAdjustmentRecord firstAdjustmentRecord, TMP_GlyphAdjustmentRecord secondAdjustmentRecord)
  154. {
  155. m_FirstAdjustmentRecord = firstAdjustmentRecord;
  156. m_SecondAdjustmentRecord = secondAdjustmentRecord;
  157. }
  158. /// <summary>
  159. /// Internal constructor
  160. /// </summary>
  161. /// <param name="firstAdjustmentRecord"></param>
  162. /// <param name="secondAdjustmentRecord"></param>
  163. internal TMP_GlyphPairAdjustmentRecord(GlyphPairAdjustmentRecord glyphPairAdjustmentRecord)
  164. {
  165. m_FirstAdjustmentRecord = new TMP_GlyphAdjustmentRecord(glyphPairAdjustmentRecord.firstAdjustmentRecord);
  166. m_SecondAdjustmentRecord = new TMP_GlyphAdjustmentRecord(glyphPairAdjustmentRecord.secondAdjustmentRecord);
  167. }
  168. }
  169. public struct GlyphPairKey
  170. {
  171. public uint firstGlyphIndex;
  172. public uint secondGlyphIndex;
  173. public long key;
  174. public GlyphPairKey(uint firstGlyphIndex, uint secondGlyphIndex)
  175. {
  176. this.firstGlyphIndex = firstGlyphIndex;
  177. this.secondGlyphIndex = secondGlyphIndex;
  178. key = (long)secondGlyphIndex << 32 | firstGlyphIndex;
  179. }
  180. internal GlyphPairKey(TMP_GlyphPairAdjustmentRecord record)
  181. {
  182. firstGlyphIndex = record.firstAdjustmentRecord.glyphIndex;
  183. secondGlyphIndex = record.secondAdjustmentRecord.glyphIndex;
  184. key = (long)secondGlyphIndex << 32 | firstGlyphIndex;
  185. }
  186. }
  187. }