RasterParams.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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 as a call-back by the anti-aliased renderer in order to let client applications draw themselves
  27. /// the gray pixel spans on each scan line.
  28. /// </summary>
  29. /// <remarks><para>
  30. /// This callback allows client applications to directly render the gray spans of the anti-aliased bitmap to any
  31. /// kind of surfaces.
  32. /// </para><para>
  33. /// This can be used to write anti-aliased outlines directly to a given background bitmap, and even perform
  34. /// translucency.
  35. /// </para><para>
  36. /// Note that the ‘count’ field cannot be greater than a fixed value defined by the ‘FT_MAX_GRAY_SPANS’
  37. /// configuration macro in ‘ftoption.h’. By default, this value is set to 32, which means that if there are more
  38. /// than 32 spans on a given scanline, the callback is called several times with the same ‘y’ parameter in order to
  39. /// draw all callbacks.
  40. /// </para><para>
  41. /// Otherwise, the callback is only called once per scan-line, and only for those scanlines that do have ‘gray’
  42. /// pixels on them.
  43. /// </para></remarks>
  44. /// <param name="y">The scanline's y coordinate.</param>
  45. /// <param name="count">The number of spans to draw on this scanline.</param>
  46. /// <param name="spans">A table of ‘count’ spans to draw on the scanline.</param>
  47. /// <param name="user">User-supplied data that is passed to the callback.</param>
  48. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  49. public delegate void RasterSpanFunc(int y, int count, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(SpanMarshaler))] Span spans, IntPtr user);
  50. /// <summary><para>
  51. /// THIS TYPE IS DEPRECATED. DO NOT USE IT.
  52. /// </para><para>
  53. /// A function used as a call-back by the monochrome scan-converter to test whether a given target pixel is already
  54. /// set to the drawing ‘color’. These tests are crucial to implement drop-out control per-se the TrueType spec.
  55. /// </para></summary>
  56. /// <param name="y">The pixel's y coordinate.</param>
  57. /// <param name="x">The pixel's x coordinate.</param>
  58. /// <param name="user">User-supplied data that is passed to the callback.</param>
  59. /// <returns>1 if the pixel is ‘set’, 0 otherwise.</returns>
  60. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  61. public delegate int RasterBitTestFunc(int y, int x, IntPtr user);
  62. /// <summary><para>
  63. /// THIS TYPE IS DEPRECATED. DO NOT USE IT.
  64. /// </para><para>
  65. /// A function used as a call-back by the monochrome scan-converter to set an individual target pixel. This is
  66. /// crucial to implement drop-out control according to the TrueType specification.
  67. /// </para></summary>
  68. /// <param name="y">The pixel's y coordinate.</param>
  69. /// <param name="x">The pixel's x coordinate.</param>
  70. /// <param name="user">User-supplied data that is passed to the callback.</param>
  71. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  72. public delegate void RasterBitSetFunc(int y, int x, IntPtr user);
  73. /// <summary>
  74. /// A structure to hold the arguments used by a raster's render function.
  75. /// </summary>
  76. /// <remarks><para>
  77. /// An anti-aliased glyph bitmap is drawn if the <see cref="RasterFlags.AntiAlias"/> bit flag is set in the ‘flags’
  78. /// field, otherwise a monochrome bitmap is generated.
  79. /// </para><para>
  80. /// If the <see cref="RasterFlags.Direct"/> bit flag is set in ‘flags’, the raster will call the ‘gray_spans’
  81. /// callback to draw gray pixel spans, in the case of an aa glyph bitmap, it will call ‘black_spans’, and
  82. /// ‘bit_test’ and ‘bit_set’ in the case of a monochrome bitmap. This allows direct composition over a pre-existing
  83. /// bitmap through user-provided callbacks to perform the span drawing/composition.
  84. /// </para><para>
  85. /// Note that the ‘bit_test’ and ‘bit_set’ callbacks are required when rendering a monochrome bitmap, as they are
  86. /// crucial to implement correct drop-out control as defined in the TrueType specification.
  87. /// </para></remarks>
  88. public class RasterParams
  89. {
  90. #region Fields
  91. private IntPtr reference;
  92. private RasterParamsRec rec;
  93. #endregion
  94. #region Constructors
  95. internal RasterParams(IntPtr reference)
  96. {
  97. Reference = reference;
  98. }
  99. #endregion
  100. #region Properties
  101. /// <summary>
  102. /// Gets the target bitmap.
  103. /// </summary>
  104. public FTBitmap Target
  105. {
  106. get
  107. {
  108. return new FTBitmap(rec.target);
  109. }
  110. }
  111. /// <summary>
  112. /// Gets a pointer to the source glyph image (e.g., an <see cref="Outline"/>).
  113. /// </summary>
  114. public IntPtr Source
  115. {
  116. get
  117. {
  118. return rec.source;
  119. }
  120. }
  121. /// <summary>
  122. /// Gets the rendering flags.
  123. /// </summary>
  124. public RasterFlags Flags
  125. {
  126. get
  127. {
  128. return rec.flags;
  129. }
  130. }
  131. /// <summary>
  132. /// Gets the gray span drawing callback.
  133. /// </summary>
  134. public RasterSpanFunc GraySpans
  135. {
  136. get
  137. {
  138. return rec.gray_spans;
  139. }
  140. }
  141. /// <summary>
  142. /// Gets the black span drawing callback. UNIMPLEMENTED!
  143. /// </summary>
  144. public RasterSpanFunc BlackSpans
  145. {
  146. get
  147. {
  148. return rec.black_spans;
  149. }
  150. }
  151. /// <summary>
  152. /// Gets the bit test callback. UNIMPLEMENTED!
  153. /// </summary>
  154. public RasterBitTestFunc BitTest
  155. {
  156. get
  157. {
  158. return rec.bit_test;
  159. }
  160. }
  161. /// <summary>
  162. /// Gets the bit set callback. UNIMPLEMENTED!
  163. /// </summary>
  164. public RasterBitSetFunc BitSet
  165. {
  166. get
  167. {
  168. return rec.bit_set;
  169. }
  170. }
  171. /// <summary>
  172. /// Gets the user-supplied data that is passed to each drawing callback.
  173. /// </summary>
  174. public IntPtr User
  175. {
  176. get
  177. {
  178. return rec.user;
  179. }
  180. }
  181. /// <summary>
  182. /// Gets an optional clipping box. It is only used in direct rendering mode. Note that coordinates here should
  183. /// be expressed in integer pixels (and not in 26.6 fixed-point units).
  184. /// </summary>
  185. public BBox ClipBox
  186. {
  187. get
  188. {
  189. return new BBox(rec.clip_box);
  190. }
  191. }
  192. internal IntPtr Reference
  193. {
  194. get
  195. {
  196. return reference;
  197. }
  198. set
  199. {
  200. reference = value;
  201. rec = PInvokeHelper.PtrToStructure<RasterParamsRec>(reference);
  202. }
  203. }
  204. #endregion
  205. }
  206. }