BitmapSize.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. /// This structure models the metrics of a bitmap strike (i.e., a set of
  27. /// glyphs for a given point size and resolution) in a bitmap font. It is
  28. /// used for the <see cref="Face.AvailableSizes"/> field of
  29. /// <see cref="Face"/>.
  30. /// </summary>
  31. /// <remarks><para>
  32. /// Windows FNT: The nominal size given in a FNT font is not reliable. Thus
  33. /// when the driver finds it incorrect, it sets ‘size’ to some calculated
  34. /// values and sets ‘x_ppem’ and ‘y_ppem’ to the pixel width and height
  35. /// given in the font, respectively.
  36. /// </para><para>
  37. /// TrueType embedded bitmaps: ‘size’, ‘width’, and ‘height’ values are not
  38. /// contained in the bitmap strike itself. They are computed from the
  39. /// global font parameters.
  40. /// </para></remarks>
  41. public sealed class BitmapSize
  42. {
  43. #region Fields
  44. private IntPtr reference;
  45. private BitmapSizeRec rec;
  46. #endregion
  47. #region Constructors
  48. internal BitmapSize(IntPtr reference)
  49. {
  50. Reference = reference;
  51. }
  52. internal BitmapSize(BitmapSizeRec bmpSizeInt)
  53. {
  54. this.rec = bmpSizeInt;
  55. }
  56. #endregion
  57. #region Properties
  58. /// <summary>
  59. /// Gets the vertical distance, in pixels, between two consecutive
  60. /// baselines. It is always positive.
  61. /// </summary>
  62. public short Height
  63. {
  64. get
  65. {
  66. return rec.height;
  67. }
  68. }
  69. /// <summary>
  70. /// Gets the average width, in pixels, of all glyphs in the strike.
  71. /// </summary>
  72. public short Width
  73. {
  74. get
  75. {
  76. return rec.width;
  77. }
  78. }
  79. /// <summary>
  80. /// Gets the nominal size of the strike in 26.6 fractional points. This
  81. /// field is not very useful.
  82. /// </summary>
  83. public int Size
  84. {
  85. get
  86. {
  87. return (int)rec.size;
  88. }
  89. }
  90. /// <summary>
  91. /// Gets the horizontal ppem (nominal width) in 26.6 fractional pixels.
  92. /// </summary>
  93. public int NominalWidth
  94. {
  95. get
  96. {
  97. return (int)rec.x_ppem;
  98. }
  99. }
  100. /// <summary>
  101. /// Gets the vertical ppem (nominal height) in 26.6 fractional pixels.
  102. /// </summary>
  103. public int NominalHeight
  104. {
  105. get
  106. {
  107. return (int)rec.y_ppem;
  108. }
  109. }
  110. internal IntPtr Reference
  111. {
  112. get
  113. {
  114. return reference;
  115. }
  116. set
  117. {
  118. reference = value;
  119. rec = PInvokeHelper.PtrToStructure<BitmapSizeRec>(reference);
  120. }
  121. }
  122. #endregion
  123. }
  124. }