Span.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 structure used to model a single span of gray (or black) pixels when rendering a monochrome or anti-aliased
  27. /// bitmap.
  28. /// </summary>
  29. /// <remarks><para>
  30. /// This structure is used by the span drawing callback type named <see cref="RasterSpanFunc"/> which takes the y
  31. /// coordinate of the span as a a parameter.
  32. /// </para><para>
  33. /// The coverage value is always between 0 and 255. If you want less gray values, the callback function has to
  34. /// reduce them.
  35. /// </para></remarks>
  36. public class Span
  37. {
  38. #region Fields
  39. private IntPtr reference;
  40. private SpanRec rec;
  41. #endregion
  42. #region Constructors
  43. internal Span(IntPtr reference)
  44. {
  45. Reference = reference;
  46. }
  47. #endregion
  48. #region Properties
  49. /// <summary>
  50. /// Gets the span's horizontal start position.
  51. /// </summary>
  52. public short X
  53. {
  54. get
  55. {
  56. return rec.x;
  57. }
  58. }
  59. /// <summary>
  60. /// Gets the span's length in pixels.
  61. /// </summary>
  62. [CLSCompliant(false)]
  63. public ushort Length
  64. {
  65. get
  66. {
  67. return rec.len;
  68. }
  69. }
  70. /// <summary>
  71. /// Gets the span color/coverage, ranging from 0 (background) to 255 (foreground). Only used for anti-aliased
  72. /// rendering.
  73. /// </summary>
  74. public byte Coverage
  75. {
  76. get
  77. {
  78. return rec.coverage;
  79. }
  80. }
  81. internal IntPtr Reference
  82. {
  83. get
  84. {
  85. return reference;
  86. }
  87. set
  88. {
  89. reference = value;
  90. rec = PInvokeHelper.PtrToStructure<SpanRec>(reference);
  91. }
  92. }
  93. #endregion
  94. }
  95. }