No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TMP_FontFeatureTable.cs 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.TextCore.LowLevel;
  6. namespace TMPro
  7. {
  8. /// <summary>
  9. /// Table that contains the various font features available for the given font asset.
  10. /// </summary>
  11. [Serializable]
  12. public class TMP_FontFeatureTable
  13. {
  14. /// <summary>
  15. /// List that contains the glyph multiple substitution records.
  16. /// </summary>
  17. public List<MultipleSubstitutionRecord> multipleSubstitutionRecords
  18. {
  19. get { return m_MultipleSubstitutionRecords; }
  20. set { m_MultipleSubstitutionRecords = value; }
  21. }
  22. /// <summary>
  23. /// List that contains the glyph ligature records.
  24. /// </summary>
  25. public List<LigatureSubstitutionRecord> ligatureRecords
  26. {
  27. get { return m_LigatureSubstitutionRecords; }
  28. set { m_LigatureSubstitutionRecords = value; }
  29. }
  30. /// <summary>
  31. /// List that contains the glyph pair adjustment records.
  32. /// </summary>
  33. public List<GlyphPairAdjustmentRecord> glyphPairAdjustmentRecords
  34. {
  35. get { return m_GlyphPairAdjustmentRecords; }
  36. set { m_GlyphPairAdjustmentRecords = value; }
  37. }
  38. /// <summary>
  39. ///
  40. /// </summary>
  41. public List<MarkToBaseAdjustmentRecord> MarkToBaseAdjustmentRecords
  42. {
  43. get { return m_MarkToBaseAdjustmentRecords; }
  44. set { m_MarkToBaseAdjustmentRecords = value; }
  45. }
  46. /// <summary>
  47. ///
  48. /// </summary>
  49. public List<MarkToMarkAdjustmentRecord> MarkToMarkAdjustmentRecords
  50. {
  51. get { return m_MarkToMarkAdjustmentRecords; }
  52. set { m_MarkToMarkAdjustmentRecords = value; }
  53. }
  54. // =============================================
  55. // Private backing fields for public properties.
  56. // =============================================
  57. [SerializeField]
  58. internal List<MultipleSubstitutionRecord> m_MultipleSubstitutionRecords;
  59. [SerializeField]
  60. internal List<LigatureSubstitutionRecord> m_LigatureSubstitutionRecords;
  61. [SerializeField]
  62. internal List<GlyphPairAdjustmentRecord> m_GlyphPairAdjustmentRecords;
  63. [SerializeField]
  64. internal List<MarkToBaseAdjustmentRecord> m_MarkToBaseAdjustmentRecords;
  65. [SerializeField]
  66. internal List<MarkToMarkAdjustmentRecord> m_MarkToMarkAdjustmentRecords;
  67. // =============================================
  68. // Lookup data structures.
  69. // =============================================
  70. internal Dictionary<uint, List<LigatureSubstitutionRecord>> m_LigatureSubstitutionRecordLookup;
  71. internal Dictionary<uint, GlyphPairAdjustmentRecord> m_GlyphPairAdjustmentRecordLookup;
  72. internal Dictionary<uint, MarkToBaseAdjustmentRecord> m_MarkToBaseAdjustmentRecordLookup;
  73. internal Dictionary<uint, MarkToMarkAdjustmentRecord> m_MarkToMarkAdjustmentRecordLookup;
  74. // =============================================
  75. // Constructor(s)
  76. // =============================================
  77. public TMP_FontFeatureTable()
  78. {
  79. m_LigatureSubstitutionRecords = new List<LigatureSubstitutionRecord>();
  80. m_LigatureSubstitutionRecordLookup = new Dictionary<uint, List<LigatureSubstitutionRecord>>();
  81. m_GlyphPairAdjustmentRecords = new List<GlyphPairAdjustmentRecord>();
  82. m_GlyphPairAdjustmentRecordLookup = new Dictionary<uint, GlyphPairAdjustmentRecord>();
  83. m_MarkToBaseAdjustmentRecords = new List<MarkToBaseAdjustmentRecord>();
  84. m_MarkToBaseAdjustmentRecordLookup = new Dictionary<uint, MarkToBaseAdjustmentRecord>();
  85. m_MarkToMarkAdjustmentRecords = new List<MarkToMarkAdjustmentRecord>();
  86. m_MarkToMarkAdjustmentRecordLookup = new Dictionary<uint, MarkToMarkAdjustmentRecord>();
  87. }
  88. // =============================================
  89. // Utility Functions
  90. // =============================================
  91. /// <summary>
  92. /// Sort the glyph pair adjustment records by glyph index.
  93. /// </summary>
  94. public void SortGlyphPairAdjustmentRecords()
  95. {
  96. // Sort List of Kerning Info
  97. if (m_GlyphPairAdjustmentRecords.Count > 0)
  98. m_GlyphPairAdjustmentRecords = m_GlyphPairAdjustmentRecords.OrderBy(s => s.firstAdjustmentRecord.glyphIndex).ThenBy(s => s.secondAdjustmentRecord.glyphIndex).ToList();
  99. }
  100. /// <summary>
  101. /// Sort the Mark-to-Base Adjustment Table records.
  102. /// </summary>
  103. public void SortMarkToBaseAdjustmentRecords()
  104. {
  105. // Sort List of Kerning Info
  106. if (m_MarkToBaseAdjustmentRecords.Count > 0)
  107. m_MarkToBaseAdjustmentRecords = m_MarkToBaseAdjustmentRecords.OrderBy(s => s.baseGlyphID).ThenBy(s => s.markGlyphID).ToList();
  108. }
  109. /// <summary>
  110. /// Sort the Mark-to-Mark Adjustment Table records.
  111. /// </summary>
  112. public void SortMarkToMarkAdjustmentRecords()
  113. {
  114. // Sort List of Kerning Info
  115. if (m_MarkToMarkAdjustmentRecords.Count > 0)
  116. m_MarkToMarkAdjustmentRecords = m_MarkToMarkAdjustmentRecords.OrderBy(s => s.baseMarkGlyphID).ThenBy(s => s.combiningMarkGlyphID).ToList();
  117. }
  118. }
  119. }