GlyphMetrics.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 the metrics of a single glyph. The values are expressed in 26.6 fractional pixel
  27. /// format; if the flag <see cref="LoadFlags.NoScale"/> has been used while loading the glyph, values are expressed
  28. /// in font units instead.
  29. /// </summary>
  30. /// <remarks>
  31. /// If not disabled with <see cref="LoadFlags.NoHinting"/>, the values represent dimensions of the hinted glyph (in
  32. /// case hinting is applicable).
  33. /// </remarks>
  34. public sealed class GlyphMetrics
  35. {
  36. #region Fields
  37. private IntPtr reference;
  38. private GlyphMetricsRec rec;
  39. #endregion
  40. #region Constructors
  41. internal GlyphMetrics(IntPtr reference)
  42. {
  43. Reference = reference;
  44. }
  45. internal GlyphMetrics(GlyphMetricsRec glyphMetInt)
  46. {
  47. this.rec = glyphMetInt;
  48. }
  49. #endregion
  50. #region Properties
  51. /// <summary>
  52. /// Gets the glyph's width.
  53. /// </summary>
  54. public int Width
  55. {
  56. get
  57. {
  58. return (int)rec.width;
  59. }
  60. }
  61. /// <summary>
  62. /// Gets the glyph's height.
  63. /// </summary>
  64. public int Height
  65. {
  66. get
  67. {
  68. return (int)rec.height;
  69. }
  70. }
  71. /// <summary>
  72. /// Gets the left side bearing for horizontal layout.
  73. /// </summary>
  74. public int HorizontalBearingX
  75. {
  76. get
  77. {
  78. return (int)rec.horiBearingX;
  79. }
  80. }
  81. /// <summary>
  82. /// Gets the top side bearing for horizontal layout.
  83. /// </summary>
  84. public int HorizontalBearingY
  85. {
  86. get
  87. {
  88. return (int)rec.horiBearingY;
  89. }
  90. }
  91. /// <summary>
  92. /// Gets the advance width for horizontal layout.
  93. /// </summary>
  94. public int HorizontalAdvance
  95. {
  96. get
  97. {
  98. return (int)rec.horiAdvance;
  99. }
  100. }
  101. /// <summary>
  102. /// Gets the left side bearing for vertical layout.
  103. /// </summary>
  104. public int VerticalBearingX
  105. {
  106. get
  107. {
  108. return (int)rec.vertBearingX;
  109. }
  110. }
  111. /// <summary>
  112. /// Gets the top side bearing for vertical layout. Larger positive values mean further below the vertical glyph
  113. /// origin.
  114. /// </summary>
  115. public int VerticalBearingY
  116. {
  117. get
  118. {
  119. return (int)rec.vertBearingY;
  120. }
  121. }
  122. /// <summary>
  123. /// Gets the advance height for vertical layout. Positive values mean the glyph has a positive advance
  124. /// downward.
  125. /// </summary>
  126. public int VerticalAdvance
  127. {
  128. get
  129. {
  130. return (int)rec.vertAdvance;
  131. }
  132. }
  133. internal IntPtr Reference
  134. {
  135. get
  136. {
  137. return reference;
  138. }
  139. set
  140. {
  141. reference = value;
  142. rec = PInvokeHelper.PtrToStructure<GlyphMetricsRec>(reference);
  143. }
  144. }
  145. #endregion
  146. }
  147. }