SFont.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { STextAlign } from "./enums/STextAlign";
  2. import { STextBaseLine } from "./enums/STextBaseLine";
  3. import { STextDirection } from "./enums/STextDirection";
  4. /**
  5. * 字体
  6. *
  7. * @author 庞利祥(sybotan@126.com)
  8. */
  9. export class SFont {
  10. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  11. // 属性定义
  12. /** 字体 */
  13. name = "sans-serif";
  14. /** 字号 */
  15. size = 16;
  16. /** 文本对齐选项 */
  17. textAlign = STextAlign.Start;
  18. /** 文本基线对齐选项 */
  19. readonly textBaseLine = STextBaseLine.Top;
  20. /** 文本方向 */
  21. textDirection = STextDirection.Inherit;
  22. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  23. // 构造函数
  24. /**
  25. * 构造函数
  26. */
  27. constructor();
  28. /**
  29. * 构造函数
  30. *
  31. * @param font FONT
  32. */
  33. constructor(font: SFont);
  34. /**
  35. * 构造函数
  36. *
  37. * @param name 字体
  38. * @param size 字号
  39. */
  40. constructor(name: string, size?: number);
  41. /**
  42. * 构造函数
  43. *
  44. * @param name 字体 | SFont
  45. * @param size 字号
  46. */
  47. constructor(name?: string | SFont, size?: number) {
  48. if (name == undefined) {
  49. return;
  50. }
  51. if (name instanceof SFont) {
  52. this.name = name.name;
  53. this.size = name.size;
  54. this.textAlign = name.textAlign;
  55. // this.textBaseLine = name.textBaseLine;
  56. this.textDirection = name.textDirection;
  57. } else {
  58. this.name = name;
  59. this.size = size != undefined ? size : 16;
  60. }
  61. } // Constructor
  62. } // Class SFont