SizeMetrics.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. /// The size metrics structure gives the metrics of a size object.
  27. /// </summary>
  28. /// <remarks><para>
  29. /// The scaling values, if relevant, are determined first during a size changing operation. The remaining fields
  30. /// are then set by the driver. For scalable formats, they are usually set to scaled values of the corresponding
  31. /// fields in <see cref="Face"/>.
  32. /// </para><para>
  33. /// Note that due to glyph hinting, these values might not be exact for certain fonts. Thus they must be treated as
  34. /// unreliable with an error margin of at least one pixel!
  35. /// </para><para>
  36. /// Indeed, the only way to get the exact metrics is to render all glyphs. As this would be a definite performance
  37. /// hit, it is up to client applications to perform such computations.
  38. /// </para><para>
  39. /// The <see cref="SizeMetrics"/> structure is valid for bitmap fonts also.
  40. /// </para></remarks>
  41. public sealed class SizeMetrics
  42. {
  43. #region Fields
  44. private IntPtr reference;
  45. private SizeMetricsRec rec;
  46. #endregion
  47. #region Constructors
  48. internal SizeMetrics(IntPtr reference)
  49. {
  50. Reference = reference;
  51. }
  52. internal SizeMetrics(SizeMetricsRec metricsInternal)
  53. {
  54. rec = metricsInternal;
  55. }
  56. #endregion
  57. #region Properties
  58. /// <summary>
  59. /// Gets the width of the scaled EM square in pixels, hence the term ‘ppem’ (pixels per EM). It is also referred to
  60. /// as ‘nominal width’.
  61. /// </summary>
  62. [CLSCompliant(false)]
  63. public ushort NominalWidth
  64. {
  65. get
  66. {
  67. return rec.x_ppem;
  68. }
  69. }
  70. /// <summary>
  71. /// Gets the height of the scaled EM square in pixels, hence the term ‘ppem’ (pixels per EM). It is also referred to
  72. /// as ‘nominal height’.
  73. /// </summary>
  74. [CLSCompliant(false)]
  75. public ushort NominalHeight
  76. {
  77. get
  78. {
  79. return rec.y_ppem;
  80. }
  81. }
  82. /// <summary>
  83. /// Gets a 16.16 fractional scaling value used to convert horizontal metrics from font units to 26.6 fractional
  84. /// pixels. Only relevant for scalable font formats.
  85. /// </summary>
  86. public int ScaleX
  87. {
  88. get
  89. {
  90. return (int)rec.x_scale;
  91. }
  92. }
  93. /// <summary>
  94. /// Gets a 16.16 fractional scaling value used to convert vertical metrics from font units to 26.6 fractional
  95. /// pixels. Only relevant for scalable font formats.
  96. /// </summary>
  97. public int ScaleY
  98. {
  99. get
  100. {
  101. return (int)rec.y_scale;
  102. }
  103. }
  104. /// <summary>
  105. /// Gets the ascender in 26.6 fractional pixels.
  106. /// </summary>
  107. /// <see cref="Face"/>
  108. public int Ascender
  109. {
  110. get
  111. {
  112. return (int)rec.ascender;
  113. }
  114. }
  115. /// <summary>
  116. /// Gets the descender in 26.6 fractional pixels.
  117. /// </summary>
  118. /// <see cref="Face"/>
  119. public int Descender
  120. {
  121. get
  122. {
  123. return (int)rec.descender;
  124. }
  125. }
  126. /// <summary>
  127. /// Gets the height in 26.6 fractional pixels.
  128. /// </summary>
  129. /// <see cref="Face"/>
  130. public int Height
  131. {
  132. get
  133. {
  134. return (int)rec.height;
  135. }
  136. }
  137. /// <summary>
  138. /// Gets the maximal advance width in 26.6 fractional pixels.
  139. /// </summary>
  140. /// <see cref="Face"/>
  141. public int MaxAdvance
  142. {
  143. get
  144. {
  145. return (int)rec.max_advance;
  146. }
  147. }
  148. internal IntPtr Reference
  149. {
  150. get
  151. {
  152. return reference;
  153. }
  154. set
  155. {
  156. reference = value;
  157. rec = PInvokeHelper.PtrToStructure<SizeMetricsRec>(reference);
  158. }
  159. }
  160. #endregion
  161. }
  162. }