OutlineFuncs.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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><para>
  26. /// A function pointer type used to describe the signature of a ‘move to’ function during outline
  27. /// walking/decomposition.
  28. /// </para><para>
  29. /// A ‘move to’ is emitted to start a new contour in an outline.
  30. /// </para></summary>
  31. /// <param name="to">A pointer to the target point of the ‘move to’.</param>
  32. /// <param name="user">A typeless pointer which is passed from the caller of the decomposition function.</param>
  33. /// <returns>Error code. 0 means success.</returns>
  34. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  35. public delegate int MoveToFunc(FTVector to, IntPtr user);
  36. /// <summary><para>
  37. /// A function pointer type used to describe the signature of a ‘line to’ function during outline
  38. /// walking/decomposition.
  39. /// </para><para>
  40. /// A ‘line to’ is emitted to indicate a segment in the outline.
  41. /// </para></summary>
  42. /// <param name="to">A pointer to the target point of the ‘line to’.</param>
  43. /// <param name="user">A typeless pointer which is passed from the caller of the decomposition function.</param>
  44. /// <returns>Error code. 0 means success.</returns>
  45. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  46. public delegate int LineToFunc(FTVector to, IntPtr user);
  47. /// <summary><para>
  48. /// A function pointer type used to describe the signature of a ‘conic to’ function during outline walking or
  49. /// decomposition.
  50. /// </para><para>
  51. /// A ‘conic to’ is emitted to indicate a second-order Bézier arc in the outline.
  52. /// </para></summary>
  53. /// <param name="control">
  54. /// An intermediate control point between the last position and the new target in ‘to’.
  55. /// </param>
  56. /// <param name="to">A pointer to the target end point of the conic arc.</param>
  57. /// <param name="user">A typeless pointer which is passed from the caller of the decomposition function.</param>
  58. /// <returns>Error code. 0 means success.</returns>
  59. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  60. public delegate int ConicToFunc(FTVector control, FTVector to, IntPtr user);
  61. /// <summary><para>
  62. /// A function pointer type used to describe the signature of a ‘cubic to’ function during outline walking or
  63. /// decomposition.
  64. /// </para><para>
  65. /// A ‘cubic to’ is emitted to indicate a third-order Bézier arc.
  66. /// </para></summary>
  67. /// <param name="control1">A pointer to the first Bézier control point.</param>
  68. /// <param name="control2">A pointer to the second Bézier control point.</param>
  69. /// <param name="to">A pointer to the target end point.</param>
  70. /// <param name="user">A typeless pointer which is passed from the caller of the decomposition function.</param>
  71. /// <returns>Error code. 0 means success.</returns>
  72. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  73. public delegate int CubicToFunc(FTVector control1, FTVector control2, FTVector to, IntPtr user);
  74. /// <summary>
  75. /// A structure to hold various function pointers used during outline decomposition in order to emit segments,
  76. /// conic, and cubic Béziers.
  77. /// </summary>
  78. /// <remarks>
  79. /// The point coordinates sent to the emitters are the transformed version of the original coordinates (this is
  80. /// important for high accuracy during scan-conversion). The transformation is simple:
  81. /// <code>
  82. /// x' = (x &lt;&lt; shift) - delta
  83. /// y' = (x &lt;&lt; shift) - delta
  84. /// </code>
  85. /// Set the values of ‘shift’ and ‘delta’ to 0 to get the original point coordinates.
  86. /// </remarks>
  87. public class OutlineFuncs
  88. {
  89. private OutlineFuncsRec rec;
  90. /// <summary>
  91. /// Initializes a new instance of the OutlineFuncs class.
  92. /// </summary>
  93. public OutlineFuncs()
  94. {
  95. }
  96. /// <summary>
  97. /// Initializes a new instance of the OutlineFuncs class.
  98. /// </summary>
  99. /// <param name="moveTo">The move to delegate.</param>
  100. /// <param name="lineTo">The line to delegate.</param>
  101. /// <param name="conicTo">The conic to delegate.</param>
  102. /// <param name="cubicTo">The cubic to delegate.</param>
  103. /// <param name="shift">A value to shift by.</param>
  104. /// <param name="delta">A delta to transform by.</param>
  105. public OutlineFuncs(MoveToFunc moveTo, LineToFunc lineTo, ConicToFunc conicTo, CubicToFunc cubicTo, int shift, int delta)
  106. {
  107. rec.moveTo = moveTo;
  108. rec.lineTo = lineTo;
  109. rec.conicTo = conicTo;
  110. rec.cubicTo = cubicTo;
  111. rec.shift = shift;
  112. #if WIN64
  113. rec.delta = delta;
  114. #else
  115. rec.delta = (IntPtr)delta;
  116. #endif
  117. }
  118. /// <summary>
  119. /// Gets or sets the ‘move to’ emitter.
  120. /// </summary>
  121. public MoveToFunc MoveFunction
  122. {
  123. get
  124. {
  125. return rec.moveTo;
  126. }
  127. set
  128. {
  129. rec.moveTo = value;
  130. }
  131. }
  132. /// <summary>
  133. /// Gets or sets the segment emitter.
  134. /// </summary>
  135. public LineToFunc LineFuction
  136. {
  137. get
  138. {
  139. return rec.lineTo;
  140. }
  141. set
  142. {
  143. rec.lineTo = value;
  144. }
  145. }
  146. /// <summary>
  147. /// Gets or sets the second-order Bézier arc emitter.
  148. /// </summary>
  149. public ConicToFunc ConicFunction
  150. {
  151. get
  152. {
  153. return rec.conicTo;
  154. }
  155. set
  156. {
  157. rec.conicTo = value;
  158. }
  159. }
  160. /// <summary>
  161. /// Gets or sets the third-order Bézier arc emitter.
  162. /// </summary>
  163. public CubicToFunc CubicFunction
  164. {
  165. get
  166. {
  167. return rec.cubicTo;
  168. }
  169. set
  170. {
  171. rec.cubicTo = value;
  172. }
  173. }
  174. /// <summary>
  175. /// Gets or sets the shift that is applied to coordinates before they are sent to the emitter.
  176. /// </summary>
  177. public int Shift
  178. {
  179. get
  180. {
  181. return rec.shift;
  182. }
  183. set
  184. {
  185. rec.shift = value;
  186. }
  187. }
  188. /// <summary>
  189. /// Gets the delta that is applied to coordinates before they are sent to the emitter, but after the
  190. /// shift.
  191. /// </summary>
  192. public int Delta
  193. {
  194. get
  195. {
  196. return (int)rec.delta;
  197. }
  198. /*set
  199. {
  200. funcsInt.delta = (IntPtr)value;
  201. }*/
  202. }
  203. }
  204. }