TMPro_FontPlugin.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Collections;
  4. using System;
  5. using System.Runtime.InteropServices;
  6. namespace TMPro.EditorUtilities
  7. {
  8. /*
  9. public class TMPro_FontPlugin
  10. {
  11. [UnmanagedFunctionPointer(CallingConvention.StdCall)]
  12. private delegate void DebugLog(string log);
  13. private static readonly DebugLog debugLog = DebugWrapper;
  14. private static readonly IntPtr functionPointer = Marshal.GetFunctionPointerForDelegate(debugLog);
  15. private static void DebugWrapper(string log)
  16. {
  17. Debug.Log(log);
  18. }
  19. public static void LinkDebugLog()
  20. {
  21. LinkDebug(functionPointer);
  22. }
  23. [DllImport("TMPro_Plugin")]
  24. private static extern void LinkDebug([MarshalAs(UnmanagedType.FunctionPtr)]IntPtr debugCall);
  25. [DllImport("TMPro_Plugin")]
  26. public static extern
  27. int Initialize_FontEngine();
  28. [DllImport("TMPro_Plugin")]
  29. public static extern
  30. int Destroy_FontEngine();
  31. [DllImport("TMPro_Plugin")]
  32. public static extern
  33. int Load_TrueType_Font(string fontPath);
  34. [DllImport("TMPro_Plugin")]
  35. public static extern
  36. int FT_Size_Font(int fontSize);
  37. [DllImport("TMPro_Plugin")]
  38. public static extern
  39. int Render_Character(byte[] buffer_fill, byte[] buffer_edge, int buffer_width, int buffer_height, int offset, int asc, FaceStyles style, float thickness, RenderModes rasterMode, ref FT_GlyphInfo glyphInfo);
  40. [DllImport("TMPro_Plugin")]
  41. public static extern
  42. int Render_Characters(byte[] buffer, int buffer_width, int buffer_height, int character_padding, int[] asc_set, int char_count, FaceStyles style, float style_mod, bool autoSize, RenderModes renderMode, int method, ref FT_FaceInfo fontData, FT_GlyphInfo[] Output);
  43. [DllImport("TMPro_Plugin")]
  44. public static extern
  45. int FT_GetKerningPairs(string fontPath, int[] characterSet, int setCount, FT_KerningPair[] kerningPairs);
  46. [DllImport("TMPro_Plugin")]
  47. public static extern
  48. float Check_RenderProgress();
  49. [DllImport("TMPro_Plugin")]
  50. internal static extern
  51. void SendCancellationRequest(CancellationRequestType request);
  52. }
  53. public enum FaceStyles { Normal, Bold, Italic, Bold_Italic, Outline, Bold_Sim };
  54. public enum RenderModes { HintedSmooth = 0, Smooth = 1, RasterHinted = 2, Raster = 3, DistanceField16 = 6, DistanceField32 = 7 }; // SignedDistanceField64 = 8
  55. internal enum CancellationRequestType : byte { None = 0x0, CancelInProgess = 0x1, WindowClosed = 0x2 };
  56. [StructLayout(LayoutKind.Sequential)]
  57. public struct FT_KerningPair
  58. {
  59. public int ascII_Left;
  60. public int ascII_Right;
  61. public float xAdvanceOffset;
  62. }
  63. [StructLayout(LayoutKind.Sequential)]
  64. public struct FT_GlyphInfo
  65. {
  66. public int id;
  67. public float x;
  68. public float y;
  69. public float width;
  70. public float height;
  71. public float xOffset;
  72. public float yOffset;
  73. public float xAdvance;
  74. }
  75. [StructLayout(LayoutKind.Sequential)]
  76. public struct FT_FaceInfo
  77. {
  78. [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
  79. public string name;
  80. public int pointSize;
  81. public int padding;
  82. public float lineHeight;
  83. public float baseline;
  84. public float ascender;
  85. public float descender;
  86. public float centerLine;
  87. public float underline;
  88. public float underlineThickness;
  89. public int characterCount;
  90. public int atlasWidth;
  91. public int atlasHeight;
  92. }
  93. */
  94. }