CPDFTextAlignUI.xaml.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using ComPDFKit.PDFPage.Edit;
  2. using ComPDFKitViewer.PdfViewer;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Controls.Primitives;
  11. using System.Windows.Data;
  12. using System.Windows.Documents;
  13. using System.Windows.Input;
  14. using System.Windows.Media;
  15. using System.Windows.Media.Imaging;
  16. using System.Windows.Navigation;
  17. using System.Windows.Shapes;
  18. namespace compdfkit_tools.Edit
  19. {
  20. /// <summary>
  21. /// CPDFTextAlignUI.xaml 的交互逻辑
  22. /// </summary>
  23. public partial class CPDFTextAlignUI : UserControl
  24. {
  25. public event EventHandler<TextAlignType> TextAlignChanged;
  26. public CPDFTextAlignUI()
  27. {
  28. InitializeComponent();
  29. }
  30. public Orientation Orientation
  31. {
  32. get
  33. {
  34. return TextAlignUI.Orientation;
  35. }
  36. set
  37. {
  38. TextAlignUI.Orientation = value;
  39. }
  40. }
  41. public TextAlignType Alignment { get;private set; }
  42. public void SetFontAlign(TextAlignType newAlign)
  43. {
  44. ClearAlign();
  45. Alignment = newAlign;
  46. switch (newAlign)
  47. {
  48. case TextAlignType.AlignLeft:
  49. AlignLeftBtn.IsChecked = true;
  50. AlignLeftPath.Fill = Brushes.Blue;
  51. break;
  52. case TextAlignType.AlignMiddle:
  53. AlignCenterBtn.IsChecked = true;
  54. AlignCenterPath.Fill = Brushes.Blue;
  55. break;
  56. case TextAlignType.AlignRight:
  57. AlignRightBtn.IsChecked = true;
  58. AlignRightPath.Fill = Brushes.Blue;
  59. break;
  60. default:
  61. break;
  62. }
  63. }
  64. public void ClearAlign()
  65. {
  66. Alignment = TextAlignType.AlignNone;
  67. AlignLeftPath.Fill = Brushes.Gray;
  68. AlignCenterPath.Fill= Brushes.Gray;
  69. AlignRightPath.Fill= Brushes.Gray;
  70. AlignLeftBtn.IsChecked = false;
  71. AlignCenterBtn.IsChecked = false;
  72. AlignRightBtn.IsChecked= false;
  73. }
  74. private void TextAlignBtn_Click(object sender, RoutedEventArgs e)
  75. {
  76. ClearAlign();
  77. ToggleButton clickBtn = sender as ToggleButton;
  78. if (clickBtn != null && clickBtn.Tag!=null)
  79. {
  80. clickBtn.IsChecked = true;
  81. TextAlignType newAlign = Alignment;
  82. switch(clickBtn.Tag.ToString())
  83. {
  84. case "AlignLeft":
  85. newAlign = TextAlignType.AlignLeft;
  86. break;
  87. case "AlignCenter":
  88. newAlign = TextAlignType.AlignMiddle;
  89. break;
  90. case "AlignRight":
  91. newAlign= TextAlignType.AlignRight;
  92. break;
  93. default:
  94. break;
  95. }
  96. if(newAlign!=Alignment)
  97. {
  98. SetFontAlign(newAlign);
  99. TextAlignChanged?.Invoke(this, newAlign);
  100. }
  101. }
  102. }
  103. }
  104. }