BitmapGlyph.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. //TODO some sort of pseudo-inheritance for glyphs following FreeType's method.
  26. /// <summary>
  27. /// A structure used for bitmap glyph images. This really is a ‘sub-class’ of <see cref="Glyph"/>.
  28. /// </summary>
  29. /// <remarks><para>
  30. /// You can typecast an <see cref="Glyph"/> to <see cref="BitmapGlyph"/> if you have ‘<see cref="Glyph.Format"/> ==
  31. /// <see cref="GlyphFormat.Bitmap"/>’. This lets you access the bitmap's contents easily.
  32. /// </para><para>
  33. /// The corresponding pixel buffer is always owned by <see cref="BitmapGlyph"/> and is thus created and destroyed
  34. /// with it.
  35. /// </para></remarks>
  36. public class BitmapGlyph
  37. {
  38. #region Fields
  39. private IntPtr reference;
  40. private BitmapGlyphRec rec;
  41. #endregion
  42. #region Constructors
  43. internal BitmapGlyph(IntPtr reference)
  44. {
  45. Reference = reference;
  46. }
  47. #endregion
  48. #region Properties
  49. /// <summary>
  50. /// Gets the root <see cref="Glyph"/> fields.
  51. /// </summary>
  52. public Glyph Root
  53. {
  54. get
  55. {
  56. //HACK fix this later.
  57. return new Glyph(rec.root, null);
  58. }
  59. }
  60. /// <summary>
  61. /// Gets the left-side bearing, i.e., the horizontal distance from the current pen position to the left border
  62. /// of the glyph bitmap.
  63. /// </summary>
  64. public int Left
  65. {
  66. get
  67. {
  68. return rec.left;
  69. }
  70. }
  71. /// <summary>
  72. /// Gets the top-side bearing, i.e., the vertical distance from the current pen position to the top border of
  73. /// the glyph bitmap. This distance is positive for upwards y!
  74. /// </summary>
  75. public int Top
  76. {
  77. get
  78. {
  79. return rec.top;
  80. }
  81. }
  82. /// <summary>
  83. /// Gets a descriptor for the bitmap.
  84. /// </summary>
  85. public FTBitmap Bitmap
  86. {
  87. get
  88. {
  89. return new FTBitmap(rec.bitmap);
  90. }
  91. }
  92. internal IntPtr Reference
  93. {
  94. get
  95. {
  96. return reference;
  97. }
  98. set
  99. {
  100. reference = value;
  101. rec = PInvokeHelper.PtrToStructure<BitmapGlyphRec>(reference);
  102. }
  103. }
  104. #endregion
  105. }
  106. }