CharMap.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. #region MIT License
  2. /*Copyright (c) 2012 Robert Rouhani <robert.rouhani@gmail.com>
  3. SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
  4. Permission is hereby granted, free of charge, to any person obtaining a copy of
  5. this software and associated documentation files (the "Software"), to deal in
  6. the Software without restriction, including without limitation the rights to
  7. use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  8. of the Software, and to permit persons to whom the Software is furnished to do
  9. so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in all
  11. copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18. SOFTWARE.*/
  19. #endregion
  20. using System;
  21. using System.Runtime.InteropServices;
  22. using SharpFont.Internal;
  23. namespace SharpFont
  24. {
  25. /// <summary>
  26. /// The base charmap structure.
  27. /// </summary>
  28. public sealed class CharMap
  29. {
  30. #region Fields
  31. private IntPtr reference;
  32. private CharMapRec rec;
  33. private Face parentFace;
  34. #endregion
  35. #region Constructors
  36. internal CharMap(IntPtr reference, Face parent)
  37. {
  38. Reference = reference;
  39. this.parentFace = parent;
  40. }
  41. #endregion
  42. #region Properties
  43. /// <summary>
  44. /// Gets a handle to the parent face object.
  45. /// </summary>
  46. public Face Face
  47. {
  48. get
  49. {
  50. return parentFace;
  51. }
  52. }
  53. /// <summary>
  54. /// Gets an <see cref="Encoding"/> tag identifying the charmap. Use this with
  55. /// <see cref="SharpFont.Face.SelectCharmap"/>.
  56. /// </summary>
  57. [CLSCompliant(false)]
  58. public Encoding Encoding
  59. {
  60. get
  61. {
  62. return rec.encoding;
  63. }
  64. }
  65. /// <summary>
  66. /// Gets an ID number describing the platform for the following encoding ID. This comes directly from the
  67. /// TrueType specification and should be emulated for other formats.
  68. /// </summary>
  69. [CLSCompliant(false)]
  70. public PlatformID PlatformId
  71. {
  72. get
  73. {
  74. return rec.platform_id;
  75. }
  76. }
  77. /// <summary>
  78. /// Gets a platform specific encoding number. This also comes from the TrueType specification and should be
  79. /// emulated similarly.
  80. /// </summary>
  81. [CLSCompliant(false)]
  82. public ushort EncodingId
  83. {
  84. get
  85. {
  86. //TODO find some way of getting a proper encoding ID enum...
  87. return rec.encoding_id;
  88. }
  89. }
  90. internal IntPtr Reference
  91. {
  92. get
  93. {
  94. return reference;
  95. }
  96. set
  97. {
  98. reference = value;
  99. rec = PInvokeHelper.PtrToStructure<CharMapRec>(reference);
  100. }
  101. }
  102. #endregion
  103. #region Methods
  104. #region Base Interface
  105. /// <summary>
  106. /// Retrieve index of a given charmap.
  107. /// </summary>
  108. /// <returns>The index into the array of character maps within the face to which ‘charmap’ belongs.</returns>
  109. public int GetCharmapIndex()
  110. {
  111. return FT.FT_Get_Charmap_Index(Reference);
  112. }
  113. #endregion
  114. #region TrueType Tables
  115. /// <summary>
  116. /// Return TrueType/sfnt specific cmap language ID. Definitions of language ID values are in
  117. /// ‘freetype/ttnameid.h’.
  118. /// </summary>
  119. /// <returns>
  120. /// The language ID of ‘charmap’. If ‘charmap’ doesn't belong to a TrueType/sfnt face, just return 0 as the
  121. /// default value.
  122. /// </returns>
  123. [CLSCompliant(false)]
  124. public uint GetCMapLanguageId()
  125. {
  126. return FT.FT_Get_CMap_Language_ID(Reference);
  127. }
  128. /// <summary>
  129. /// Return TrueType/sfnt specific cmap format.
  130. /// </summary>
  131. /// <returns>The format of ‘charmap’. If ‘charmap’ doesn't belong to a TrueType/sfnt face, return -1.</returns>
  132. public int GetCMapFormat()
  133. {
  134. return FT.FT_Get_CMap_Format(Reference);
  135. }
  136. #endregion
  137. #endregion
  138. }
  139. }