TextAnnotProperty.xaml.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. using ComPDFKitViewer;
  2. using ComPDFKitViewer.AnnotEvent;
  3. using PDF_Office.Properties;
  4. using PDF_Office.ViewModels.PropertyPanel.AnnotPanel;
  5. using PDFSettings;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows;
  12. using System.Windows.Controls;
  13. using System.Windows.Data;
  14. using System.Windows.Documents;
  15. using System.Windows.Input;
  16. using System.Windows.Media;
  17. using System.Windows.Media.Imaging;
  18. using System.Windows.Navigation;
  19. using System.Windows.Shapes;
  20. namespace PDF_Office.Views.PropertyPanel.AnnotPanel
  21. {
  22. /// <summary>
  23. /// TextAnnotProperty.xaml 的交互逻辑
  24. /// </summary>
  25. public partial class TextAnnotProperty : UserControl
  26. {
  27. public TextAnnotProperty()
  28. {
  29. InitializeComponent();
  30. }
  31. private void OpacitySlider_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
  32. {
  33. }
  34. private void OpacitySlider_DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e)
  35. {
  36. }
  37. private void OpacitySlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
  38. {
  39. }
  40. private void ColorDropPicker_SelectedColorChanged(object sender, Color? e)
  41. {
  42. var data = this.DataContext as TextAnnotPropertyViewModel;
  43. if(data != null)
  44. {
  45. data.SelectedColorChangedCommand?.Execute(e.Value);
  46. }
  47. }
  48. }
  49. //public partial class TextAnnotProperty : UserControl
  50. //{
  51. // /// <summary>
  52. // /// 属性更改事件
  53. // /// </summary>
  54. // public event EventHandler<Dictionary<AnnotArgsType, object>> DataChanged;
  55. // /// <summary>
  56. // /// 默认值设置事件
  57. // /// </summary>
  58. // public event EventHandler<object> DefaultStored;
  59. // public Color? SelectedColor { get { return ColorDropPicker.SelectedColor; } }
  60. // public string AnnotTitle { get { return AnnotTypeTitle.Text; } }
  61. // public string AnnoteNote { get { return AnnotNoteText.Text; } }
  62. // public double AnnotOpacity { get { return OpacitySlider.Value; } }
  63. // public AnnotArgsType AnnotType { get; private set; }
  64. // public AnnotAttribEvent AnnotEvent { get; set; }
  65. // private bool DisableValueChange = false;
  66. // public TextAnnotProperty()
  67. // {
  68. // InitializeComponent();
  69. // SetLangText();
  70. // string font = Settings.Default.AppProperties.Annotate.AnchoredFamaily;
  71. // if (font.Equals("Courier"))
  72. // AnnotNoteText.FontFamily = new FontFamily("Courier New");
  73. // else if (font.Equals("Helvetica"))
  74. // AnnotNoteText.FontFamily = new FontFamily("Arial");
  75. // else
  76. // AnnotNoteText.FontFamily = new FontFamily("Times New Roman");
  77. // DataContext = this;
  78. // PathFigure FigureData = GetSquigglyPathFigure(new Point(0, 0), new Point(62, 0), 60, 2);
  79. // PathGeometry SquigglyGeometry = new PathGeometry();
  80. // PathFigureCollection FiguresCollection = new PathFigureCollection();
  81. // SquigglyGeometry.Figures = FiguresCollection;
  82. // FiguresCollection.Add(FigureData);
  83. // SquigglyPath.Data = SquigglyGeometry;
  84. // }
  85. // private void SetLangText()
  86. // {
  87. // //SampleText.Text = App.MainPageLoader.GetString("ProperPanel_Example");
  88. // //colorText.Text = App.MainPageLoader.GetString("ProperPanel_Color");
  89. // //opacityText.Text = App.MainPageLoader.GetString("ProperPanel_Opacity");
  90. // //UseAsDefaultBtn.Content = App.MainPageLoader.GetString("ProperPanel_SetAsDefault");
  91. // //NoteText.Text = App.MainPageLoader.GetString("ProperPanel_Note");
  92. // }
  93. // private void SetTextDecoratePath(Color? selectColor, double? opacity)
  94. // {
  95. // UnderlinePath.Visibility = Visibility.Collapsed;
  96. // StrikeoutPath.Visibility = Visibility.Collapsed;
  97. // SquigglyPath.Visibility = Visibility.Collapsed;
  98. // UnderlinePath.Opacity = 1;
  99. // StrikeoutPath.Opacity = 1;
  100. // UnderlinePath.Opacity = 1;
  101. // switch (AnnotType)
  102. // {
  103. // case AnnotArgsType.AnnotHighlight:
  104. // if (selectColor != null)
  105. // {
  106. // SampleText.Background = new SolidColorBrush((Color)selectColor);
  107. // }
  108. // if (opacity != null)
  109. // {
  110. // SampleText.Background.Opacity = (double)opacity;
  111. // }
  112. // break;
  113. // case AnnotArgsType.AnnotUnderline:
  114. // UnderlinePath.Visibility = Visibility.Visible;
  115. // SampleText.Background = Brushes.Transparent;
  116. // if (opacity != null)
  117. // {
  118. // UnderlinePath.Opacity = (double)opacity;
  119. // }
  120. // if (selectColor != null)
  121. // {
  122. // UnderlinePath.Stroke = new SolidColorBrush((Color)selectColor);
  123. // }
  124. // break;
  125. // case AnnotArgsType.AnnotStrikeout:
  126. // StrikeoutPath.Visibility = Visibility.Visible;
  127. // SampleText.Background = Brushes.Transparent;
  128. // if (opacity != null)
  129. // {
  130. // StrikeoutPath.Opacity = (double)opacity;
  131. // }
  132. // if (selectColor != null)
  133. // {
  134. // StrikeoutPath.Stroke = new SolidColorBrush((Color)selectColor);
  135. // }
  136. // break;
  137. // case AnnotArgsType.AnnotSquiggly:
  138. // SquigglyPath.Visibility = Visibility.Visible;
  139. // SampleText.Background = Brushes.Transparent;
  140. // if (opacity != null)
  141. // {
  142. // SquigglyPath.Opacity = (double)opacity;
  143. // }
  144. // if (selectColor != null)
  145. // {
  146. // SquigglyPath.Stroke = new SolidColorBrush((Color)selectColor);
  147. // }
  148. // break;
  149. // case AnnotArgsType.AnnotSticky:
  150. // {
  151. // if (opacity != null)
  152. // {
  153. // StickyPath.Opacity = (double)opacity;
  154. // }
  155. // if (selectColor != null)
  156. // {
  157. // StickyPath.Fill = new SolidColorBrush((Color)selectColor);
  158. // }
  159. // }
  160. // break;
  161. // default:
  162. // break;
  163. // }
  164. // }
  165. // public void SetSelectedColor(Color selectColor)
  166. // {
  167. // bool changed = false;
  168. // if (ColorDropPicker.SelectedColor != selectColor)
  169. // {
  170. // changed = true;
  171. // }
  172. // ColorDropPicker.SetSelectedColor(selectColor);
  173. // SetTextDecoratePath(selectColor, null);
  174. // if (changed)
  175. // {
  176. // Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
  177. // changeData[AnnotType] = selectColor;
  178. // DataChanged?.Invoke(this, changeData);
  179. // }
  180. // }
  181. // public void SetSelectOpacity(double opacity)
  182. // {
  183. // OpacitySlider.Value = opacity;
  184. // SetTextDecoratePath(null, opacity);
  185. // }
  186. // public void SetNoteContent(string textNote)
  187. // {
  188. // AnnotNoteText.Text = textNote;
  189. // }
  190. // public void SetAnnotType(AnnotArgsType annotType)
  191. // {
  192. // //AnnotType = annotType;
  193. // //switch (annotType)
  194. // //{
  195. // // case AnnotArgsType.AnnotHighlight:
  196. // // AnnotTypeTitle.Text = App.MainPageLoader.GetString("SubTools_Tools_Highlight");
  197. // // break;
  198. // // case AnnotArgsType.AnnotUnderline:
  199. // // AnnotTypeTitle.Text = App.MainPageLoader.GetString("SubTools_Tools_Underline");
  200. // // break;
  201. // // case AnnotArgsType.AnnotStrikeout:
  202. // // AnnotTypeTitle.Text = App.MainPageLoader.GetString("SubTools_Tools_Strikthrough");
  203. // // break;
  204. // // case AnnotArgsType.AnnotSquiggly:
  205. // // AnnotTypeTitle.Text = App.MainPageLoader.GetString("SubTools_Tools_Squiggly");
  206. // // break;
  207. // // case AnnotArgsType.AnnotSticky:
  208. // // AnnotTypeTitle.Text = App.MainPageLoader.GetString("SubTools_Tools_AnchoredNote");
  209. // // SampleText.Visibility = Visibility.Collapsed;
  210. // // StickyPath.Visibility = Visibility.Visible;
  211. // // break;
  212. // // default:
  213. // // break;
  214. // //}
  215. // }
  216. // private void ColorDropPicker_SelectedColorChanged(object sender, Color? e)
  217. // {
  218. // if (e != null && AnnotEvent != null)
  219. // {
  220. // AnnotEvent.UpdateAttrib(AnnotAttrib.Color, e);
  221. // AnnotEvent.UpdateAnnot();
  222. // double? opacity = null;
  223. // if (OpacitySlider != null)
  224. // {
  225. // opacity = OpacitySlider.Value;
  226. // }
  227. // SetTextDecoratePath(e, opacity);
  228. // if (e != null)
  229. // {
  230. // Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
  231. // changeData[AnnotType] = e;
  232. // DataChanged?.Invoke(this, changeData);
  233. // }
  234. // }
  235. // }
  236. // private void OpacitySlider_DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e)
  237. // {
  238. // DisableValueChange = false;
  239. // if (AnnotEvent != null)
  240. // {
  241. // AnnotEvent.UpdateAttrib(AnnotAttrib.Transparency, OpacitySlider.Value);
  242. // AnnotEvent.UpdateAnnot();
  243. // SetTextDecoratePath(null, OpacitySlider.Value);
  244. // if (e != null)
  245. // {
  246. // Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
  247. // changeData[AnnotType] = OpacitySlider.Value;
  248. // DataChanged?.Invoke(this, changeData);
  249. // }
  250. // }
  251. // }
  252. // private void OpacitySlider_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
  253. // {
  254. // DisableValueChange = true;
  255. // }
  256. // private void OpacitySlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
  257. // {
  258. // if (AnnotEvent != null && DisableValueChange == false)
  259. // {
  260. // AnnotEvent.UpdateAttrib(AnnotAttrib.Transparency, e.NewValue);
  261. // AnnotEvent.UpdateAnnot();
  262. // SetTextDecoratePath(null, e.NewValue);
  263. // if (e != null)
  264. // {
  265. // Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
  266. // changeData[AnnotType] = e.NewValue;
  267. // DataChanged?.Invoke(this, changeData);
  268. // }
  269. // }
  270. // }
  271. // private PathFigure GetSquigglyPathFigure(Point StartPoint, Point EndPoint, double PathWidth, double PathHeight)
  272. // {
  273. // PathFigure FigureData = new PathFigure();
  274. // FigureData.StartPoint = StartPoint;
  275. // int Radius = (int)Math.Max(2, 2);
  276. // if (PathWidth > PathHeight)
  277. // {
  278. // // 橫線
  279. // var arcCount = PathWidth / (Radius * 2);
  280. // var x = StartPoint.X;
  281. // if (EndPoint.X > StartPoint.X)
  282. // {
  283. // // left to right
  284. // for (int i = 0; i < arcCount; i++)
  285. // {
  286. // if (i % 2 == 0)
  287. // {
  288. // // 上弧
  289. // FigureData.Segments.Add(new BezierSegment()
  290. // {
  291. // Point1 = new Point(x, StartPoint.Y),
  292. // Point2 = new Point(x + Radius, StartPoint.Y - Radius),
  293. // Point3 = new Point(x + Radius * 2, StartPoint.Y)
  294. // });
  295. // }
  296. // else
  297. // {
  298. // // 下弧
  299. // FigureData.Segments.Add(new BezierSegment()
  300. // {
  301. // Point1 = new Point(x, StartPoint.Y),
  302. // Point2 = new Point(x + Radius, StartPoint.Y + Radius),
  303. // Point3 = new Point(x + Radius * 2, StartPoint.Y)
  304. // });
  305. // }
  306. // x += Radius * 2;
  307. // }
  308. // }
  309. // else
  310. // {
  311. // // right to left
  312. // for (int i = 0; i < arcCount; i++)
  313. // {
  314. // if (i % 2 == 0)
  315. // {
  316. // //下弧
  317. // FigureData.Segments.Add(new BezierSegment()
  318. // {
  319. // Point1 = new Point(x, StartPoint.Y),
  320. // Point2 = new Point(x - Radius, StartPoint.Y + Radius),
  321. // Point3 = new Point(x - Radius * 2, StartPoint.Y)
  322. // });
  323. // }
  324. // else
  325. // {
  326. // //上弧
  327. // FigureData.Segments.Add(new BezierSegment()
  328. // {
  329. // Point1 = new Point(x, StartPoint.Y),
  330. // Point2 = new Point(x - Radius, StartPoint.Y - Radius),
  331. // Point3 = new Point(x - Radius * 2, StartPoint.Y)
  332. // });
  333. // }
  334. // x -= Radius * 2;
  335. // }
  336. // }
  337. // }
  338. // else
  339. // {
  340. // // 直線
  341. // var arcCount = PathHeight / (Radius * 2);
  342. // var y = StartPoint.Y;
  343. // if (EndPoint.Y > StartPoint.Y)
  344. // {
  345. // // up to down
  346. // for (int i = 0; i < arcCount; i++)
  347. // {
  348. // if (i % 2 == 0)
  349. // {
  350. // //右弧
  351. // FigureData.Segments.Add(new BezierSegment()
  352. // {
  353. // Point1 = new Point(StartPoint.X, y),
  354. // Point2 = new Point(StartPoint.X + Radius, y + Radius),
  355. // Point3 = new Point(StartPoint.X, y + Radius * 2)
  356. // });
  357. // }
  358. // else
  359. // {
  360. // //左弧
  361. // FigureData.Segments.Add(new BezierSegment()
  362. // {
  363. // Point1 = new Point(StartPoint.X, y),
  364. // Point2 = new Point(StartPoint.X - Radius, y + Radius),
  365. // Point3 = new Point(StartPoint.X, y + Radius * 2)
  366. // });
  367. // }
  368. // y += Radius * 2;
  369. // }
  370. // }
  371. // else
  372. // {
  373. // // down to up
  374. // for (int i = 0; i < arcCount; i++)
  375. // {
  376. // if (i % 2 == 0)
  377. // {
  378. // //左弧
  379. // FigureData.Segments.Add(new BezierSegment()
  380. // {
  381. // Point1 = new Point(StartPoint.X, y),
  382. // Point2 = new Point(StartPoint.X - Radius, y - Radius),
  383. // Point3 = new Point(StartPoint.X, y - Radius * 2)
  384. // });
  385. // }
  386. // else
  387. // {
  388. // //右弧
  389. // FigureData.Segments.Add(new BezierSegment()
  390. // {
  391. // Point1 = new Point(StartPoint.X, y),
  392. // Point2 = new Point(StartPoint.X + Radius, y - Radius),
  393. // Point3 = new Point(StartPoint.X, y - Radius * 2)
  394. // });
  395. // }
  396. // y -= Radius * 2;
  397. // }
  398. // }
  399. // }
  400. // return FigureData;
  401. // }
  402. // private void Button_StoreAsDefaultProperty(object sender, RoutedEventArgs e)
  403. // {
  404. // DefaultAnnotProperty defaultProperty = new DefaultAnnotProperty();
  405. // defaultProperty.AnnotToolType = AnnotType;
  406. // defaultProperty.ForgoundColor = ColorDropPicker.SelectedColor == null ? Colors.Yellow : (Color)ColorDropPicker.SelectedColor;
  407. // defaultProperty.Opacity = OpacitySlider.Value;
  408. // Helper.SettingHelper.SetAnnotDefaultProperty(defaultProperty);
  409. // DefaultStored?.Invoke(this, null);
  410. // }
  411. // private void AnnotNoteText_LostFocus(object sender, RoutedEventArgs e)
  412. // {
  413. // AnnotEvent?.UpdateAttrib(AnnotAttrib.NoteText, AnnotNoteText.Text);
  414. // AnnotEvent?.UpdateAnnot();
  415. // }
  416. // public void NoteFocus()
  417. // {
  418. // AnnotNoteText.Focus();
  419. // }
  420. // private void OpacityItem_PreviewMouseDown(object sender, MouseButtonEventArgs e)
  421. // {
  422. // ComboBoxItem selectItem = sender as ComboBoxItem;
  423. // if (selectItem != null && selectItem.Content != null)
  424. // {
  425. // int opacity = -1;
  426. // if (int.TryParse(selectItem.Content.ToString().TrimEnd('%'), out opacity))
  427. // {
  428. // OpacitySlider.Value = opacity / 100D;
  429. // }
  430. // }
  431. // }
  432. //}
  433. }