TTF_Helpers.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using System;
  2. //#pragma warning disable
  3. namespace FastReport.Fonts
  4. {
  5. /// <summary>
  6. ///
  7. /// </summary>
  8. public abstract class TTF_Helpers
  9. {
  10. /// <summary>
  11. ///
  12. /// </summary>
  13. /// <param name="v"></param>
  14. /// <returns></returns>
  15. public static ushort SwapUInt16(ushort v)
  16. {
  17. if (BitConverter.IsLittleEndian)
  18. {
  19. byte[] buf = BitConverter.GetBytes(v);
  20. Array.Reverse(buf);
  21. return BitConverter.ToUInt16(buf, 0);
  22. }
  23. else
  24. return v;
  25. }
  26. /// <summary>
  27. ///
  28. /// </summary>
  29. /// <param name="v"></param>
  30. /// <returns></returns>
  31. public static short SwapInt16(short v)
  32. {
  33. if (BitConverter.IsLittleEndian)
  34. {
  35. byte[] buf = BitConverter.GetBytes(v);
  36. Array.Reverse(buf);
  37. return BitConverter.ToInt16(buf, 0);
  38. }
  39. else
  40. return v;
  41. }
  42. /// <summary>
  43. ///
  44. /// </summary>
  45. /// <param name="v"></param>
  46. /// <returns></returns>
  47. public static uint SwapUInt32(uint v)
  48. {
  49. if (BitConverter.IsLittleEndian)
  50. {
  51. byte[] buf = BitConverter.GetBytes(v);
  52. Array.Reverse(buf);
  53. return BitConverter.ToUInt32(buf, 0);
  54. }
  55. else
  56. return v;
  57. }
  58. /// <summary>
  59. ///
  60. /// </summary>
  61. /// <param name="v"></param>
  62. /// <returns></returns>
  63. public static int SwapInt32(int v)
  64. {
  65. if (BitConverter.IsLittleEndian)
  66. {
  67. byte[] buf = BitConverter.GetBytes(v);
  68. Array.Reverse(buf);
  69. return BitConverter.ToInt32(buf, 0);
  70. }
  71. else
  72. return v;
  73. }
  74. /// <summary>
  75. ///
  76. /// </summary>
  77. /// <param name="v"></param>
  78. /// <returns></returns>
  79. public static ulong SwapUInt64(ulong v)
  80. {
  81. if (BitConverter.IsLittleEndian)
  82. {
  83. byte[] buf = BitConverter.GetBytes(v);
  84. Array.Reverse(buf);
  85. return BitConverter.ToUInt64(buf, 0);
  86. }
  87. else
  88. return v;
  89. }
  90. ///// <summary>
  91. /////
  92. ///// </summary>
  93. ///// <param name="ptr"></param>
  94. ///// <param name="cbSize"></param>
  95. ///// <returns></returns>
  96. //public static IntPtr Increment(IntPtr ptr, int cbSize)
  97. //{
  98. // return new IntPtr(ptr.ToInt64() + cbSize);
  99. //}
  100. ///// <summary>
  101. /////
  102. ///// </summary>
  103. ///// <param name="ptr"></param>
  104. ///// <param name="cbSize"></param>
  105. ///// <returns></returns>
  106. //public static IntPtr Increment(IntPtr ptr, uint cbSize)
  107. //{
  108. // return new IntPtr(ptr.ToInt64() + cbSize);
  109. //}
  110. }
  111. }
  112. #pragma warning restore