CPDFFontControl.xaml.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using ComPDFKit.PDFDocument;
  2. using ComPDFKit.Tool.UndoManger;
  3. using System;
  4. using System.Windows;
  5. using System.Windows.Controls;
  6. namespace ComPDFKit.Controls.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.GetFamilyStyleName(_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.FamilyName = value;
  42. }
  43. }
  44. public string FontStyleValue
  45. {
  46. get => CPDFFontUI.StyleName;
  47. set => CPDFFontUI.StyleName = value;
  48. }
  49. public TextAlignment TextAlignment
  50. {
  51. get => CPDFFontUI.TextAlignment;
  52. set => CPDFFontUI.TextAlignment = value;
  53. }
  54. public event EventHandler FontFamilyChanged;
  55. public event EventHandler FontStyleChanged;
  56. public event EventHandler FontSizeChanged;
  57. public event EventHandler FontAlignChanged;
  58. public CPDFFontControl()
  59. {
  60. InitializeComponent();
  61. CPDFFontUI.FontFamilyChanged -= CPDFFontUI_FontFamilyChanged;
  62. CPDFFontUI.FontStyleChanged -= CPDFFontUI_FontStyleChanged;
  63. CPDFFontUI.FontSizeChanged -= CPDFFontUI_FontSizeChanged;
  64. CPDFFontUI.FontAlignChanged -= CPDFFontUI_FontAlignChanged;
  65. CPDFFontUI.FontFamilyChanged += CPDFFontUI_FontFamilyChanged;
  66. CPDFFontUI.FontStyleChanged += CPDFFontUI_FontStyleChanged;
  67. CPDFFontUI.FontSizeChanged += CPDFFontUI_FontSizeChanged;
  68. CPDFFontUI.FontAlignChanged += CPDFFontUI_FontAlignChanged;
  69. }
  70. private void CPDFFontUI_FontAlignChanged(object sender, EventArgs e)
  71. {
  72. FontAlignChanged?.Invoke(this, EventArgs.Empty);
  73. }
  74. private void CPDFFontUI_FontSizeChanged(object sender, EventArgs e)
  75. {
  76. FontSizeChanged?.Invoke(this, EventArgs.Empty);
  77. }
  78. private void CPDFFontUI_FontStyleChanged(object sender, EventArgs e)
  79. {
  80. FontStyleChanged?.Invoke(this, EventArgs.Empty);
  81. }
  82. private void CPDFFontUI_FontFamilyChanged(object sender, EventArgs e)
  83. {
  84. FontFamilyChanged?.Invoke(this, EventArgs.Empty);
  85. }
  86. }
  87. }