AnnotationListItem.xaml.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. using ComPDFKit.Import;
  2. using ComPDFKit.PDFAnnotation;
  3. using ComPDFKit.PDFDocument;
  4. using ComPDFKit.PDFPage;
  5. using ComPDFKitViewer;
  6. using ComPDFKitViewer.AnnotEvent;
  7. using ComPDFKitViewer.PdfViewer;
  8. using PDF_Master.Helper;
  9. using PDF_Master.Model.BOTA;
  10. using PDF_Master.ViewModels.BOTA;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.IO;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Text.RegularExpressions;
  17. using System.Threading.Tasks;
  18. using System.Windows;
  19. using System.Windows.Controls;
  20. using System.Windows.Data;
  21. using System.Windows.Documents;
  22. using System.Windows.Forms;
  23. using System.Windows.Input;
  24. using System.Windows.Media;
  25. using System.Windows.Media.Imaging;
  26. using System.Windows.Navigation;
  27. using System.Windows.Shapes;
  28. using static Dropbox.Api.Files.SearchMatchTypeV2;
  29. namespace PDF_Master.Views.BOTA
  30. {
  31. /// <summary>
  32. /// AnnotationListItem.xaml 的交互逻辑
  33. /// </summary>
  34. public partial class AnnotationListItem : System.Windows.Controls.UserControl
  35. {
  36. //private Brush strikeoutColor = new SolidColorBrush(Color.FromRgb(0xFF, 0xBB, 0x00));
  37. public AnnotationListItem()
  38. {
  39. InitializeComponent();
  40. }
  41. private void GridIco_Loaded(object sender, RoutedEventArgs e)
  42. {
  43. if (e.Source is Grid grid)
  44. {
  45. if (grid.DataContext == null)
  46. {
  47. //var data= this.DataContext as AnnotationHandlerEventArgs;
  48. }
  49. if (grid.DataContext is AnnotationHandlerEventArgs args)
  50. {
  51. //var args = grid.DataContext as AnnotationHandlerEventArgs;
  52. AnnotHandlerEventArgs data = args.AnnotHandlerEventArgs;
  53. if (data == null)
  54. {
  55. return;
  56. }
  57. TxbMarkupContent.Text = data.MarkupContent;
  58. TxbContent.Text = data.Content;
  59. switch (data.EventType)
  60. {
  61. case AnnotArgsType.AnnotFreeText:
  62. if (data is FreeTextAnnotArgs freeTextAnnotArgs)
  63. {
  64. BtnAnnotFreeText.Visibility = Visibility.Visible;
  65. //TxbContent.Foreground = new SolidColorBrush(freeTextAnnotArgs.FontColor);
  66. }
  67. //BOTA - 注释,MVP不处理高亮 / 下划线 / 删除线的样式,只显示文字
  68. //文本注释、便签、链接、表格不支持添加附注
  69. TxbMarkupContent.Text = Regex.Replace(data.Content, "[\r\n]", " ");
  70. TxbMarkupContent.Text = "";
  71. break;
  72. case AnnotArgsType.AnnotHighlight:
  73. if (data is TextHighlightAnnotArgs textHighlightAnnotArgs)
  74. {
  75. BtnHighlight.Visibility = Visibility.Visible;
  76. PathHighlight.Background = new SolidColorBrush(textHighlightAnnotArgs.Color);
  77. //PathHighlight.Opacity = textHighlightAnnotArgs.Transparency;
  78. //BOTA - 注释,MVP不处理高亮 / 下划线 / 删除线的样式,只显示文字
  79. //文本注释、便签、链接、表格不支持添加附注
  80. //高亮、下划线、删除线,不是文本注释
  81. TxbContent.Text = Regex.Replace(data.MarkupContent, "[\r\n]", " ");
  82. TxbMarkupContent.Text = Regex.Replace(data.Content, "[\r\n]", " ");
  83. }
  84. break;
  85. case AnnotArgsType.AnnotFreehand:
  86. if (data is FreehandAnnotArgs freehandAnnotArgs)
  87. {
  88. BtnFreeHand.Visibility = Visibility.Visible;
  89. PathFreehand.Fill = new SolidColorBrush(freehandAnnotArgs.InkColor);
  90. ImageContext.Visibility = Visibility.Visible;
  91. TxbContent.Visibility = Visibility.Collapsed;
  92. SetImageContext(args, freehandAnnotArgs);
  93. //var encoder = new PngBitmapEncoder();
  94. //encoder.Frames.Add(BitmapFrame.Create((BitmapSource)ImageContext.Source));
  95. //FileStream file = new FileStream(String.Format($@"C:\Users\oyxh\Desktop\images\PDFText\{data.AnnotIndex}.png"), FileMode.Create);
  96. //encoder.Save(file);
  97. //file.Close();
  98. }
  99. if (string.IsNullOrEmpty(data.Content) == false)
  100. {
  101. TxbMarkupContent.Text = Regex.Replace(data.Content, "[\r\n]", " ");
  102. }
  103. break;
  104. case AnnotArgsType.AnnotSquiggly://波浪线
  105. if (data is TextSquigglyAnnotArgs textSquigglyAnnotArgs)
  106. {
  107. AnnotSquiggly.Visibility = Visibility.Visible;
  108. AnnotSquigglycolor.Stroke = new SolidColorBrush(textSquigglyAnnotArgs.Color);
  109. }
  110. #region TO DO
  111. //TextDecoration mySquiggly = new TextDecoration();
  112. //Pen myPen = new Pen();
  113. //myPen.Brush = new SolidColorBrush((data as TextSquigglyAnnotArgs).Color);
  114. //myPen.Brush.Opacity = 0.8;
  115. //myPen.Thickness = 2;
  116. //myPen.DashStyle = DashStyles.Dash;
  117. //mySquiggly.Pen = myPen;
  118. //mySquiggly.PenThicknessUnit = TextDecorationUnit.FontRecommended;
  119. //TextDecorationCollection myCollection = new TextDecorationCollection();
  120. //myCollection.Add(mySquiggly);
  121. //TxbContext.TextDecorations = myCollection;
  122. #endregion TO DO
  123. break;
  124. case AnnotArgsType.AnnotStamp:
  125. BtnAnnotStamp.Visibility = Visibility.Visible;
  126. if (string.IsNullOrEmpty(data.Content) == false)
  127. {
  128. TxbContent.Text = Regex.Replace(data.Content, "[\r\n]", " ");
  129. TxbContent.Text = "";
  130. TxbMarkupContent.Text = Regex.Replace(data.Content, "[\r\n]", " ");
  131. }
  132. break;
  133. case AnnotArgsType.AnnotStrikeout://删除线
  134. if (data is TextStrikeoutAnnotArgs textStrikeoutAnnotArgs)
  135. {
  136. BtnAnnotStrikeout.Visibility = Visibility.Visible;
  137. PathStrikeoutyColor.Fill = new SolidColorBrush(textStrikeoutAnnotArgs.Color);
  138. //BOTA - 注释,MVP不处理高亮 / 下划线 / 删除线的样式,只显示文字
  139. //文本注释、便签、链接、表格不支持添加附注
  140. //高亮、下划线、删除线,不是文本注释
  141. TxbContent.Text = Regex.Replace(data.MarkupContent, "[\r\n]", " ");
  142. TxbMarkupContent.Text = Regex.Replace(data.Content, "[\r\n]", " ");
  143. }
  144. #region to do
  145. //TextDecoration myStrikeout = new TextDecoration();
  146. //Pen myPen2 = new Pen();
  147. //myPen2.Brush = new SolidColorBrush((data as TextStrikeoutAnnotArgs).Color);
  148. //myPen2.Brush.Opacity = 0.8;
  149. //myPen2.Thickness = 2;
  150. //myStrikeout.Pen = myPen2;
  151. //myStrikeout.PenOffset = -4;
  152. //myStrikeout.PenThicknessUnit = TextDecorationUnit.FontRecommended;
  153. //TextDecorationCollection myCollection2 = new TextDecorationCollection();
  154. //myCollection2.Add(myStrikeout);
  155. ////因为波浪线无法实现 暂时只显示文字 不显示下划线,删除线等
  156. //TxbMarkupContent.TextDecorations = myCollection2;
  157. #endregion to do
  158. break;
  159. case AnnotArgsType.AnnotSticky://便签
  160. if (data is StickyAnnotArgs stickyAnnotArgs)
  161. {
  162. BtnAnnotSticky.Visibility = Visibility;
  163. PathSticky.Fill = new SolidColorBrush(stickyAnnotArgs.Color);
  164. }
  165. //BOTA - 注释,MVP不处理高亮 / 下划线 / 删除线的样式,只显示文字
  166. //文本注释、便签、链接、表格不支持添加附注
  167. TxbMarkupContent.Text = Regex.Replace(data.Content, "[\r\n]", " ");
  168. TxbMarkupContent.Text = "";
  169. break;
  170. case AnnotArgsType.AnnotUnderline:
  171. if (data is TextUnderlineAnnotArgs textUnderlineAnnotArgs)
  172. {
  173. BtnUnderLine.Visibility = Visibility.Visible;
  174. RectangleUnderline.Fill = new SolidColorBrush(textUnderlineAnnotArgs.Color);
  175. }
  176. //BOTA - 注释,MVP不处理高亮 / 下划线 / 删除线的样式,只显示文字
  177. //文本注释、便签、链接、表格不支持添加附注
  178. //高亮、下划线、删除线,不是文本注释
  179. TxbContent.Text = Regex.Replace(data.MarkupContent, "[\r\n]", " ");
  180. TxbMarkupContent.Text = Regex.Replace(data.Content, "[\r\n]", " ");
  181. //TxbMarkupContent.Text = "";
  182. #region TO DO
  183. //TextDecoration myUnderline = new TextDecoration();
  184. //Pen myPen1 = new Pen();
  185. //myPen1.Brush = new SolidColorBrush((data as TextUnderlineAnnotArgs).Color);
  186. //myPen1.Brush.Opacity = 0.8;
  187. //myPen1.Thickness = 2;
  188. //myUnderline.Pen = myPen1;
  189. //myUnderline.PenThicknessUnit = TextDecorationUnit.FontRecommended;
  190. //TextDecorationCollection myCollection1 = new TextDecorationCollection();
  191. //myCollection1.Add(myUnderline);
  192. //TxbMarkupContent.TextDecorations = myCollection1;
  193. #endregion TO DO
  194. break;
  195. case AnnotArgsType.AnnotLine:
  196. if (data is LineAnnotArgs lineAnnotArgs)
  197. {
  198. if (lineAnnotArgs.HeadLineType >= (C_LINE_TYPE)1 || lineAnnotArgs.TailLineType >= (C_LINE_TYPE)1)
  199. {
  200. BtnSharpArrow.Visibility = Visibility.Visible;
  201. PathArrow.Fill = new SolidColorBrush(lineAnnotArgs.LineColor);
  202. }
  203. else
  204. {
  205. PathSharpLine.Fill = new SolidColorBrush(lineAnnotArgs.LineColor);
  206. BtnSharpLine.Visibility = Visibility.Visible;
  207. }
  208. ///对于形状注释等只有Note 的处理
  209. if (!string.IsNullOrEmpty(data.Content) && string.IsNullOrEmpty(data.MarkupContent))
  210. {
  211. TxbContent.Text = Regex.Replace(data.Content, "[\r\n]", " ");
  212. TxbContent.Text = "";
  213. }
  214. if (string.IsNullOrEmpty(data.Content) == false)
  215. {
  216. TxbMarkupContent.Text = Regex.Replace(data.Content, "[\r\n]", " ");
  217. }
  218. }
  219. break;
  220. case AnnotArgsType.AnnotSquare:
  221. if (data is SquareAnnotArgs squareAnnotArgs)
  222. {
  223. BtnAnnotSquare.Visibility = Visibility.Visible;
  224. RectAnnotSquare.Stroke = new SolidColorBrush(squareAnnotArgs.LineColor);
  225. RectAnnotSquare.Fill = new SolidColorBrush(squareAnnotArgs.BgColor);
  226. ///对于形状注释等只有Note 的处理
  227. if (!string.IsNullOrEmpty(data.Content) && string.IsNullOrEmpty(data.MarkupContent))
  228. {
  229. TxbContent.Text = Regex.Replace(data.Content, "[\r\n]", " ");
  230. TxbContent.Text = "";
  231. }
  232. }
  233. if (string.IsNullOrEmpty(data.Content) == false)
  234. {
  235. TxbMarkupContent.Text = Regex.Replace(data.Content, "[\r\n]", " ");
  236. }
  237. break;
  238. case AnnotArgsType.AnnotCircle:
  239. if (data is CircleAnnotArgs circleAnnotArgs)
  240. {
  241. BtnAnnotCircle.Visibility = Visibility.Visible;
  242. EllipseCircle.Stroke = new SolidColorBrush(circleAnnotArgs.LineColor);
  243. EllipseCircle.Fill = new SolidColorBrush(circleAnnotArgs.BgColor);
  244. ///对于形状注释等只有Note 的处理
  245. if (!string.IsNullOrEmpty(data.Content) && string.IsNullOrEmpty(data.MarkupContent))
  246. {
  247. TxbContent.Text = Regex.Replace(data.Content, "[\r\n]", " ");
  248. TxbContent.Text = "";
  249. }
  250. }
  251. if (string.IsNullOrEmpty(data.Content) == false)
  252. {
  253. TxbMarkupContent.Text = Regex.Replace(data.Content, "[\r\n]", " ");
  254. }
  255. break;
  256. case AnnotArgsType.AnnotLink:
  257. BtnAnnotLink.Visibility = Visibility.Visible;
  258. if (data is LinkAnnotArgs linkAnnotArgs)
  259. {
  260. if (string.IsNullOrEmpty(linkAnnotArgs.Content))
  261. {
  262. if (linkAnnotArgs.DestIndex != -1)
  263. {
  264. TxbContent.Text = string.Format($"To Page {linkAnnotArgs.DestIndex + 1}");
  265. }
  266. else
  267. {
  268. TxbContent.Text = string.Format($"{linkAnnotArgs.URI}");
  269. }
  270. }
  271. }
  272. break;
  273. default:
  274. break;
  275. }
  276. }
  277. }
  278. }
  279. private void SetImageContext(AnnotationHandlerEventArgs args, FreehandAnnotArgs freehandAnnotArgs)
  280. {
  281. if (args == null && freehandAnnotArgs == null)
  282. {
  283. return;
  284. }
  285. if (args.WriteableBitmap == null)
  286. {
  287. return;
  288. }
  289. double width = args.WriteableBitmap.Width;
  290. double height = args.WriteableBitmap.Height;
  291. CPDFDocument doc = args.Document;
  292. if (doc != null)
  293. {
  294. CPDFPage docPage = doc.PageAtIndex(args.PageIndex, false);
  295. if (docPage != null)
  296. {
  297. double maxWidth = docPage.PageSize.Width;
  298. double maxHeight = docPage.PageSize.Height;
  299. ImageContext.MaxHeight = maxHeight;
  300. if (width > 170)
  301. {
  302. ImageContext.Stretch = Stretch.Uniform;
  303. }
  304. else
  305. {
  306. if (height >= maxHeight / 2)
  307. {
  308. //ImageContext.MaxHeight = 900;
  309. ImageContext.Stretch = Stretch.None;
  310. }
  311. if (height < maxHeight / 2)
  312. {
  313. if (height <= 20)
  314. {
  315. ImageContext.MinHeight = height;
  316. ImageContext.Height = 30;
  317. }
  318. ImageContext.Stretch = Stretch.None;
  319. }
  320. //else
  321. //{
  322. // ImageContext.Stretch = Stretch.Uniform;
  323. //}
  324. }
  325. }
  326. }
  327. }
  328. private void GridIco_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
  329. {
  330. if (e.NewValue is AnnotationHandlerEventArgs args)
  331. {
  332. //var args = grid.DataContext as AnnotationHandlerEventArgs;
  333. AnnotHandlerEventArgs data = args.AnnotHandlerEventArgs;
  334. if (data == null)
  335. {
  336. return;
  337. }
  338. TxbMarkupContent.Text = data.MarkupContent;
  339. TxbContent.Text = data.Content;
  340. switch (data.EventType)
  341. {
  342. case AnnotArgsType.AnnotFreeText:
  343. if (data is FreeTextAnnotArgs freeTextAnnotArgs)
  344. {
  345. BtnAnnotFreeText.Visibility = Visibility.Visible;
  346. //TxbContent.Foreground = new SolidColorBrush(freeTextAnnotArgs.FontColor);
  347. }
  348. //BOTA - 注释,MVP不处理高亮 / 下划线 / 删除线的样式,只显示文字
  349. //文本注释、便签、链接、表格不支持添加附注
  350. TxbMarkupContent.Text = Regex.Replace(data.Content, "[\r\n]", " ");
  351. TxbMarkupContent.Text = "";
  352. break;
  353. case AnnotArgsType.AnnotHighlight:
  354. if (data is TextHighlightAnnotArgs textHighlightAnnotArgs)
  355. {
  356. BtnHighlight.Visibility = Visibility.Visible;
  357. PathHighlight.Background = new SolidColorBrush(textHighlightAnnotArgs.Color);
  358. //PathHighlight.Opacity = textHighlightAnnotArgs.Transparency;
  359. //BOTA - 注释,MVP不处理高亮 / 下划线 / 删除线的样式,只显示文字
  360. //文本注释、便签、链接、表格不支持添加附注
  361. //高亮、下划线、删除线,不是文本注释
  362. TxbContent.Text = Regex.Replace(data.MarkupContent, "[\r\n]", " ");
  363. TxbMarkupContent.Text = Regex.Replace(data.Content, "[\r\n]", " ");
  364. }
  365. break;
  366. case AnnotArgsType.AnnotFreehand:
  367. if (data is FreehandAnnotArgs freehandAnnotArgs)
  368. {
  369. BtnFreeHand.Visibility = Visibility.Visible;
  370. PathFreehand.Fill = new SolidColorBrush(freehandAnnotArgs.InkColor);
  371. ImageContext.Visibility = Visibility.Visible;
  372. TxbContent.Visibility = Visibility.Collapsed;
  373. SetImageContext(args, freehandAnnotArgs);
  374. //var encoder = new PngBitmapEncoder();
  375. //encoder.Frames.Add(BitmapFrame.Create((BitmapSource)ImageContext.Source));
  376. //FileStream file = new FileStream(String.Format($@"C:\Users\oyxh\Desktop\images\PDFText\{data.AnnotIndex}.png"), FileMode.Create);
  377. //encoder.Save(file);
  378. //file.Close();
  379. }
  380. if (string.IsNullOrEmpty(data.Content) == false)
  381. {
  382. TxbMarkupContent.Text = Regex.Replace(data.Content, "[\r\n]", " ");
  383. }
  384. break;
  385. case AnnotArgsType.AnnotSquiggly://波浪线
  386. if (data is TextSquigglyAnnotArgs textSquigglyAnnotArgs)
  387. {
  388. AnnotSquiggly.Visibility = Visibility.Visible;
  389. AnnotSquigglycolor.Stroke = new SolidColorBrush(textSquigglyAnnotArgs.Color);
  390. }
  391. #region TO DO
  392. //TextDecoration mySquiggly = new TextDecoration();
  393. //Pen myPen = new Pen();
  394. //myPen.Brush = new SolidColorBrush((data as TextSquigglyAnnotArgs).Color);
  395. //myPen.Brush.Opacity = 0.8;
  396. //myPen.Thickness = 2;
  397. //myPen.DashStyle = DashStyles.Dash;
  398. //mySquiggly.Pen = myPen;
  399. //mySquiggly.PenThicknessUnit = TextDecorationUnit.FontRecommended;
  400. //TextDecorationCollection myCollection = new TextDecorationCollection();
  401. //myCollection.Add(mySquiggly);
  402. //TxbContext.TextDecorations = myCollection;
  403. #endregion TO DO
  404. break;
  405. case AnnotArgsType.AnnotStamp:
  406. BtnAnnotStamp.Visibility = Visibility.Visible;
  407. if (string.IsNullOrEmpty(data.Content) == false)
  408. {
  409. TxbContent.Text = Regex.Replace(data.Content, "[\r\n]", " ");
  410. TxbContent.Text = "";
  411. TxbMarkupContent.Text = Regex.Replace(data.Content, "[\r\n]", " ");
  412. }
  413. break;
  414. case AnnotArgsType.AnnotStrikeout://删除线
  415. if (data is TextStrikeoutAnnotArgs textStrikeoutAnnotArgs)
  416. {
  417. BtnAnnotStrikeout.Visibility = Visibility.Visible;
  418. PathStrikeoutyColor.Fill = new SolidColorBrush(textStrikeoutAnnotArgs.Color);
  419. //BOTA - 注释,MVP不处理高亮 / 下划线 / 删除线的样式,只显示文字
  420. //文本注释、便签、链接、表格不支持添加附注
  421. //高亮、下划线、删除线,不是文本注释
  422. TxbContent.Text = Regex.Replace(data.MarkupContent, "[\r\n]", " ");
  423. TxbMarkupContent.Text = Regex.Replace(data.Content, "[\r\n]", " ");
  424. }
  425. #region to do
  426. //TextDecoration myStrikeout = new TextDecoration();
  427. //Pen myPen2 = new Pen();
  428. //myPen2.Brush = new SolidColorBrush((data as TextStrikeoutAnnotArgs).Color);
  429. //myPen2.Brush.Opacity = 0.8;
  430. //myPen2.Thickness = 2;
  431. //myStrikeout.Pen = myPen2;
  432. //myStrikeout.PenOffset = -4;
  433. //myStrikeout.PenThicknessUnit = TextDecorationUnit.FontRecommended;
  434. //TextDecorationCollection myCollection2 = new TextDecorationCollection();
  435. //myCollection2.Add(myStrikeout);
  436. ////因为波浪线无法实现 暂时只显示文字 不显示下划线,删除线等
  437. //TxbMarkupContent.TextDecorations = myCollection2;
  438. #endregion to do
  439. break;
  440. case AnnotArgsType.AnnotSticky://便签
  441. if (data is StickyAnnotArgs stickyAnnotArgs)
  442. {
  443. BtnAnnotSticky.Visibility = Visibility;
  444. PathSticky.Fill = new SolidColorBrush(stickyAnnotArgs.Color);
  445. }
  446. //BOTA - 注释,MVP不处理高亮 / 下划线 / 删除线的样式,只显示文字
  447. //文本注释、便签、链接、表格不支持添加附注
  448. TxbMarkupContent.Text = Regex.Replace(data.Content, "[\r\n]", " ");
  449. TxbMarkupContent.Text = "";
  450. break;
  451. case AnnotArgsType.AnnotUnderline:
  452. if (data is TextUnderlineAnnotArgs textUnderlineAnnotArgs)
  453. {
  454. BtnUnderLine.Visibility = Visibility.Visible;
  455. RectangleUnderline.Fill = new SolidColorBrush(textUnderlineAnnotArgs.Color);
  456. }
  457. //BOTA - 注释,MVP不处理高亮 / 下划线 / 删除线的样式,只显示文字
  458. //文本注释、便签、链接、表格不支持添加附注
  459. //高亮、下划线、删除线,不是文本注释
  460. TxbContent.Text = Regex.Replace(data.MarkupContent, "[\r\n]", " ");
  461. TxbMarkupContent.Text = Regex.Replace(data.Content, "[\r\n]", " ");
  462. //TxbMarkupContent.Text = "";
  463. #region TO DO
  464. //TextDecoration myUnderline = new TextDecoration();
  465. //Pen myPen1 = new Pen();
  466. //myPen1.Brush = new SolidColorBrush((data as TextUnderlineAnnotArgs).Color);
  467. //myPen1.Brush.Opacity = 0.8;
  468. //myPen1.Thickness = 2;
  469. //myUnderline.Pen = myPen1;
  470. //myUnderline.PenThicknessUnit = TextDecorationUnit.FontRecommended;
  471. //TextDecorationCollection myCollection1 = new TextDecorationCollection();
  472. //myCollection1.Add(myUnderline);
  473. //TxbMarkupContent.TextDecorations = myCollection1;
  474. #endregion TO DO
  475. break;
  476. case AnnotArgsType.AnnotLine:
  477. if (data is LineAnnotArgs lineAnnotArgs)
  478. {
  479. if (lineAnnotArgs.HeadLineType >= (C_LINE_TYPE)1 || lineAnnotArgs.TailLineType >= (C_LINE_TYPE)1)
  480. {
  481. BtnSharpArrow.Visibility = Visibility.Visible;
  482. PathArrow.Fill = new SolidColorBrush(lineAnnotArgs.LineColor);
  483. }
  484. else
  485. {
  486. PathSharpLine.Fill = new SolidColorBrush(lineAnnotArgs.LineColor);
  487. BtnSharpLine.Visibility = Visibility.Visible;
  488. }
  489. ///对于形状注释等只有Note 的处理
  490. if (!string.IsNullOrEmpty(data.Content) && string.IsNullOrEmpty(data.MarkupContent))
  491. {
  492. TxbContent.Text = Regex.Replace(data.Content, "[\r\n]", " ");
  493. TxbContent.Text = "";
  494. }
  495. if (string.IsNullOrEmpty(data.Content) == false)
  496. {
  497. TxbMarkupContent.Text = Regex.Replace(data.Content, "[\r\n]", " ");
  498. }
  499. }
  500. break;
  501. case AnnotArgsType.AnnotSquare:
  502. if (data is SquareAnnotArgs squareAnnotArgs)
  503. {
  504. BtnAnnotSquare.Visibility = Visibility.Visible;
  505. RectAnnotSquare.Stroke = new SolidColorBrush(squareAnnotArgs.LineColor);
  506. RectAnnotSquare.Fill = new SolidColorBrush(squareAnnotArgs.BgColor);
  507. ///对于形状注释等只有Note 的处理
  508. if (!string.IsNullOrEmpty(data.Content) && string.IsNullOrEmpty(data.MarkupContent))
  509. {
  510. TxbContent.Text = Regex.Replace(data.Content, "[\r\n]", " ");
  511. TxbContent.Text = "";
  512. }
  513. }
  514. if (string.IsNullOrEmpty(data.Content) == false)
  515. {
  516. TxbMarkupContent.Text = Regex.Replace(data.Content, "[\r\n]", " ");
  517. }
  518. break;
  519. case AnnotArgsType.AnnotCircle:
  520. if (data is CircleAnnotArgs circleAnnotArgs)
  521. {
  522. BtnAnnotCircle.Visibility = Visibility.Visible;
  523. EllipseCircle.Stroke = new SolidColorBrush(circleAnnotArgs.LineColor);
  524. EllipseCircle.Fill = new SolidColorBrush(circleAnnotArgs.BgColor);
  525. ///对于形状注释等只有Note 的处理
  526. if (!string.IsNullOrEmpty(data.Content) && string.IsNullOrEmpty(data.MarkupContent))
  527. {
  528. TxbContent.Text = Regex.Replace(data.Content, "[\r\n]", " ");
  529. TxbContent.Text = "";
  530. }
  531. }
  532. if (string.IsNullOrEmpty(data.Content) == false)
  533. {
  534. TxbMarkupContent.Text = Regex.Replace(data.Content, "[\r\n]", " ");
  535. }
  536. break;
  537. case AnnotArgsType.AnnotLink:
  538. BtnAnnotLink.Visibility = Visibility.Visible;
  539. if (data is LinkAnnotArgs linkAnnotArgs)
  540. {
  541. if (string.IsNullOrEmpty(linkAnnotArgs.Content))
  542. {
  543. if (linkAnnotArgs.DestIndex != -1)
  544. {
  545. TxbContent.Text = string.Format($"To Page {linkAnnotArgs.DestIndex + 1}");
  546. }
  547. else
  548. {
  549. TxbContent.Text = string.Format($"{linkAnnotArgs.URI}");
  550. }
  551. }
  552. }
  553. break;
  554. default:
  555. break;
  556. }
  557. }
  558. }
  559. }
  560. }