CPDFTextAlignUI.xaml.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Navigation;
  16. using System.Windows.Shapes;
  17. namespace compdfkit_tools.Edit
  18. {
  19. /// <summary>
  20. /// CPDFTextAlignUI.xaml 的交互逻辑
  21. /// </summary>
  22. public partial class CPDFTextAlignUI : UserControl
  23. {
  24. public event EventHandler<TextAlignType> TextAlignChanged;
  25. public CPDFTextAlignUI()
  26. {
  27. InitializeComponent();
  28. }
  29. public Orientation Orientation
  30. {
  31. get
  32. {
  33. return TextAlignUI.Orientation;
  34. }
  35. set
  36. {
  37. TextAlignUI.Orientation = value;
  38. }
  39. }
  40. public TextAlignType Alignment { get;private set; }
  41. public void SetFontAlign(TextAlignType newAlign)
  42. {
  43. ClearAlign();
  44. Alignment = newAlign;
  45. switch (newAlign)
  46. {
  47. case TextAlignType.AlignLeft:
  48. AlignLeftPath.Fill = Brushes.Blue;
  49. break;
  50. case TextAlignType.AlignMiddle:
  51. AlignCenterPath.Fill = Brushes.Blue;
  52. break;
  53. case TextAlignType.AlignRight:
  54. AlignRightPath.Fill = Brushes.Blue;
  55. break;
  56. default:
  57. break;
  58. }
  59. }
  60. public void ClearAlign()
  61. {
  62. Alignment = TextAlignType.AlignNone;
  63. AlignLeftPath.Fill = Brushes.Gray;
  64. AlignCenterPath.Fill= Brushes.Gray;
  65. AlignRightPath.Fill= Brushes.Gray;
  66. }
  67. private void TextAlignBtn_Click(object sender, RoutedEventArgs e)
  68. {
  69. Button clickBtn = sender as Button;
  70. if (clickBtn != null && clickBtn.Tag!=null)
  71. {
  72. TextAlignType newAlign = Alignment;
  73. switch(clickBtn.Tag.ToString())
  74. {
  75. case "AlignLeft":
  76. newAlign= TextAlignType.AlignLeft;
  77. break;
  78. case "AlignCenter":
  79. newAlign = TextAlignType.AlignMiddle;
  80. break;
  81. case "AlignRight":
  82. newAlign= TextAlignType.AlignRight;
  83. break;
  84. default:
  85. break;
  86. }
  87. if(newAlign!=Alignment)
  88. {
  89. SetFontAlign(newAlign);
  90. TextAlignChanged?.Invoke(this, newAlign);
  91. }
  92. }
  93. }
  94. }
  95. }