TextAnnotProperty.xaml.cs 18 KB

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