Scaler.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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.Cache.Internal;
  23. namespace SharpFont.Cache
  24. {
  25. /// <summary>
  26. /// A structure used to describe a given character size in either pixels or points to the cache manager.
  27. /// </summary>
  28. /// <remarks>
  29. /// This type is mainly used to retrieve <see cref="FTSize"/> objects through the cache manager.
  30. /// </remarks>
  31. /// <see cref="Manager.LookupSize"/>
  32. public class Scaler
  33. {
  34. #region Fields
  35. private IntPtr reference;
  36. private ScalerRec rec;
  37. #endregion
  38. #region Constructors
  39. internal Scaler(IntPtr reference)
  40. {
  41. Reference = reference;
  42. }
  43. #endregion
  44. #region Properties
  45. /// <summary>
  46. /// Gets the source face ID.
  47. /// </summary>
  48. public IntPtr FaceId
  49. {
  50. get
  51. {
  52. return rec.face_id;
  53. }
  54. }
  55. /// <summary>
  56. /// Gets the character width.
  57. /// </summary>
  58. [CLSCompliant(false)]
  59. public uint Width
  60. {
  61. get
  62. {
  63. return rec.width;
  64. }
  65. }
  66. /// <summary>
  67. /// Gets the character height.
  68. /// </summary>
  69. [CLSCompliant(false)]
  70. public uint Height
  71. {
  72. get
  73. {
  74. return rec.height;
  75. }
  76. }
  77. /// <summary>
  78. /// Gets a boolean. If true, the ‘width’ and ‘height’ fields are interpreted as integer pixel character sizes.
  79. /// Otherwise, they are expressed as 1/64th of points.
  80. /// </summary>
  81. public bool Pixel
  82. {
  83. get
  84. {
  85. return rec.pixel == 1;
  86. }
  87. }
  88. /// <summary>
  89. /// Gets the horizontal resolution in dpi; only used when ‘pixel’ is value 0.
  90. /// </summary>
  91. [CLSCompliant(false)]
  92. public uint ResolutionX
  93. {
  94. get
  95. {
  96. return rec.x_res;
  97. }
  98. }
  99. /// <summary>
  100. /// Gets the vertical resolution in dpi; only used when ‘pixel’ is value 0.
  101. /// </summary>
  102. [CLSCompliant(false)]
  103. public uint ResolutionY
  104. {
  105. get
  106. {
  107. return rec.y_res;
  108. }
  109. }
  110. internal IntPtr Reference
  111. {
  112. get
  113. {
  114. return reference;
  115. }
  116. set
  117. {
  118. reference = value;
  119. rec = PInvokeHelper.PtrToStructure<ScalerRec>(reference);
  120. }
  121. }
  122. #endregion
  123. }
  124. }