TMP_FontFeaturesCommon.cs 8.4 KB

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