ModuleClass.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. /// A function used to initialize (not create) a new module object.
  27. /// </summary>
  28. /// <param name="module">The module to initialize.</param>
  29. /// <returns>FreeType error code.</returns>
  30. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  31. public delegate Error ModuleConstructor([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(ModuleMarshaler))] Module module);
  32. /// <summary>
  33. /// A function used to finalize (not destroy) a given module object.
  34. /// </summary>
  35. /// <param name="module">The module to finalize.</param>
  36. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  37. public delegate void ModuleDestructor([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(ModuleMarshaler))] Module module);
  38. /// <summary>
  39. /// A function used to query a given module for a specific interface.
  40. /// </summary>
  41. /// <param name="module">The module that contains the interface.</param>
  42. /// <param name="name">The name of the interface in the module.</param>
  43. /// <returns>The interface.</returns>
  44. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  45. public delegate IntPtr ModuleRequester([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(ModuleMarshaler))] Module module, [MarshalAs(UnmanagedType.LPStr)] string name);
  46. /// <summary>
  47. /// The module class descriptor.
  48. /// </summary>
  49. public class ModuleClass
  50. {
  51. #region Fields
  52. private IntPtr reference;
  53. private ModuleClassRec rec;
  54. #endregion
  55. #region Constructors
  56. internal ModuleClass(IntPtr reference)
  57. {
  58. Reference = reference;
  59. }
  60. #endregion
  61. #region Properties
  62. /// <summary>
  63. /// Gets bit flags describing the module.
  64. /// </summary>
  65. [CLSCompliant(false)]
  66. public uint Flags
  67. {
  68. get
  69. {
  70. return rec.module_flags;
  71. }
  72. }
  73. /// <summary>
  74. /// Gets the size of one module object/instance in bytes.
  75. /// </summary>
  76. public int Size
  77. {
  78. get
  79. {
  80. return (int)rec.module_size;
  81. }
  82. }
  83. /// <summary>
  84. /// Gets the name of the module.
  85. /// </summary>
  86. public string Name
  87. {
  88. get
  89. {
  90. return rec.module_name;
  91. }
  92. }
  93. /// <summary>
  94. /// Gets the version, as a 16.16 fixed number (major.minor).
  95. /// </summary>
  96. public int Version
  97. {
  98. get
  99. {
  100. return (int)rec.module_version;
  101. }
  102. }
  103. /// <summary>
  104. /// Gets the version of FreeType this module requires, as a 16.16 fixed number (major.minor). Starts at version
  105. /// 2.0, i.e., 0x20000.
  106. /// </summary>
  107. public int Requires
  108. {
  109. get
  110. {
  111. return (int)rec.module_requires;
  112. }
  113. }
  114. public IntPtr Interface
  115. {
  116. get
  117. {
  118. return rec.module_interface;
  119. }
  120. }
  121. /// <summary>
  122. /// Gets the initializing function.
  123. /// </summary>
  124. public ModuleConstructor Init
  125. {
  126. get
  127. {
  128. return rec.module_init;
  129. }
  130. }
  131. /// <summary>
  132. /// Gets the finalizing function.
  133. /// </summary>
  134. public ModuleDestructor Done
  135. {
  136. get
  137. {
  138. return rec.module_done;
  139. }
  140. }
  141. /// <summary>
  142. /// Gets the interface requesting function.
  143. /// </summary>
  144. public ModuleRequester GetInterface
  145. {
  146. get
  147. {
  148. return rec.get_interface;
  149. }
  150. }
  151. internal IntPtr Reference
  152. {
  153. get
  154. {
  155. return reference;
  156. }
  157. set
  158. {
  159. reference = value;
  160. rec = PInvokeHelper.PtrToStructure<ModuleClassRec>(reference);
  161. }
  162. }
  163. #endregion
  164. }
  165. }