CPDFFontControl.xaml.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using ComPDFKit.PDFDocument;
  2. using ComPDFKit.Tool.UndoManger;
  3. using System;
  4. using System.Windows;
  5. using System.Windows.Controls;
  6. namespace Compdfkit_Tools.Common
  7. {
  8. public partial class CPDFFontControl : UserControl
  9. {
  10. public bool IsReset = false;
  11. private int _fontSizeValue = 20;
  12. public int FontSizeValue
  13. {
  14. get => CPDFFontUI.FontSizeValue;
  15. set => CPDFFontUI.FontSizeValue = value;
  16. }
  17. private string _postScriptName = string.Empty;
  18. public string PostScriptName
  19. {
  20. get
  21. {
  22. var psName = string.Empty;
  23. CPDFFont.GetPostScriptName(FontFamilyValue, FontStyleValue, ref psName);
  24. return psName;
  25. }
  26. set
  27. {
  28. var _fontFamilyName = string.Empty;
  29. var _fontStyleName = string.Empty;
  30. _postScriptName = value;
  31. CPDFFont.GetFamlyStyleName(_postScriptName, ref _fontFamilyName, ref _fontStyleName);
  32. FontFamilyValue = _fontFamilyName;
  33. FontStyleValue = _fontStyleName;
  34. }
  35. }
  36. public string FontFamilyValue
  37. {
  38. get => CPDFFontUI.FamilyName;
  39. set
  40. {
  41. CPDFFontUI.lockFamilyName = true;
  42. CPDFFontUI.FamilyName = value;
  43. }
  44. }
  45. public string FontStyleValue
  46. {
  47. get => CPDFFontUI.StyleName;
  48. set
  49. {
  50. CPDFFontUI.lockStyleName = true;
  51. CPDFFontUI.StyleName = value;
  52. }
  53. }
  54. public TextAlignment TextAlignment
  55. {
  56. get => CPDFFontUI.TextAlignment;
  57. set => CPDFFontUI.TextAlignment = value;
  58. }
  59. public event EventHandler FontFamilyChanged;
  60. public event EventHandler FontStyleChanged;
  61. public event EventHandler FontSizeChanged;
  62. public event EventHandler FontAlignChanged;
  63. public CPDFFontControl()
  64. {
  65. InitializeComponent();
  66. CPDFFontUI.FontFamilyChanged -= CPDFFontUI_FontFamilyChanged;
  67. CPDFFontUI.FontStyleChanged -= CPDFFontUI_FontStyleChanged;
  68. CPDFFontUI.FontSizeChanged -= CPDFFontUI_FontSizeChanged;
  69. CPDFFontUI.FontAlignChanged -= CPDFFontUI_FontAlignChanged;
  70. CPDFFontUI.FontFamilyChanged += CPDFFontUI_FontFamilyChanged;
  71. CPDFFontUI.FontStyleChanged += CPDFFontUI_FontStyleChanged;
  72. CPDFFontUI.FontSizeChanged += CPDFFontUI_FontSizeChanged;
  73. CPDFFontUI.FontAlignChanged += CPDFFontUI_FontAlignChanged;
  74. }
  75. private void CPDFFontUI_FontAlignChanged(object sender, EventArgs e)
  76. {
  77. FontAlignChanged?.Invoke(this, EventArgs.Empty);
  78. }
  79. private void CPDFFontUI_FontSizeChanged(object sender, EventArgs e)
  80. {
  81. FontSizeChanged?.Invoke(this, EventArgs.Empty);
  82. }
  83. private void CPDFFontUI_FontStyleChanged(object sender, EventArgs e)
  84. {
  85. FontStyleChanged?.Invoke(this, EventArgs.Empty);
  86. }
  87. private void CPDFFontUI_FontFamilyChanged(object sender, EventArgs e)
  88. {
  89. FontFamilyChanged?.Invoke(this, EventArgs.Empty);
  90. }
  91. }
  92. }