You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
3.8 KiB

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