FreetextAnnotPropertyViewModel.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. using ComPDFKitViewer;
  2. using ComPDFKitViewer.AnnotEvent;
  3. using PDF_Office.CustomControl.CompositeControl;
  4. using PDF_Office.Model;
  5. using PDF_Office.Model.AnnotPanel;
  6. using PDF_Office.Model.PropertyPanel.AnnotPanel;
  7. using PDF_Office.ViewModels.Tools;
  8. using PDFSettings;
  9. using Prism.Commands;
  10. using Prism.Mvvm;
  11. using Prism.Regions;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. using System.Windows;
  18. using System.Windows.Controls;
  19. using System.Windows.Media;
  20. namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
  21. {
  22. public class FreetextAnnotPropertyViewModel : BindableBase, INavigationAware
  23. {
  24. private FontBoardVm _fontVm = new FontBoardVm(true);
  25. public FontBoardVm FontVm
  26. {
  27. get { return _fontVm; }
  28. set { SetProperty(ref _fontVm, value); }
  29. }
  30. private AnnotCommon _basicVm = new AnnotCommon();
  31. public AnnotCommon BasicVm
  32. {
  33. get { return _basicVm; }
  34. set => SetProperty(ref _basicVm, value);
  35. }
  36. private bool _isFillFreeText = false;
  37. public bool IsFillFreeTextAnnot
  38. {
  39. get { return _isFillFreeText; }
  40. set => SetProperty(ref _isFillFreeText, value);
  41. }
  42. private bool _isCheckedTime = false;
  43. public bool IsCheckedTime
  44. {
  45. get { return _isCheckedTime; }
  46. set => SetProperty(ref _isCheckedTime, value);
  47. }
  48. private ComboDataItem _currrentDateFormat = new ComboDataItem("M/d", "format");
  49. public ComboDataItem CurrrentDateFormat
  50. {
  51. get { return _currrentDateFormat; }
  52. set => SetProperty(ref _currrentDateFormat, value);
  53. }
  54. public List<ComboDataItem> DateFormatItems { get; private set; }
  55. public AnnotAttribEvent AnnotEvent { get; set; }
  56. private FreeTextAnnotArgs Annot;
  57. private AnnotPropertyPanel PropertyPanel;
  58. public DelegateCommand SelectedPresetFontCommand { get; set; }
  59. public DelegateCommand FontFamilyChangedCommand { get; set; }
  60. public DelegateCommand FontStyleWeightChangedCommand { get; set; }
  61. public DelegateCommand<object> SelectedFillOpacityCommand { get; set; }
  62. public DelegateCommand<object> SelectedColorCommand { get; set; }
  63. public DelegateCommand<object> SelectedFillColorCommand { get; set; }
  64. public DelegateCommand FontSizeChangedCommand { get; set; }
  65. public DelegateCommand<object> TextAlignCheckedCommand { get; set; }
  66. public DelegateCommand<object> LineModeCheckedCommand { get; set; }
  67. public DelegateCommand<object> SelectedOpacityValueCommand { get; set; }
  68. public DelegateCommand CustomFontStyleCommand { get; set; }
  69. public DelegateCommand ReDefineFontStyleCommand { get; set; }
  70. public DelegateCommand RestoreDefaultStyleCommand { get; set; }
  71. public DelegateCommand DateFormatChangedCommand { get; set; }
  72. public DelegateCommand ShowTimeCheckedChnagedCommand { get; set; }
  73. public event EventHandler<object> LoadPropertyHandler;
  74. public FreetextAnnotPropertyViewModel()
  75. {
  76. //文本设置
  77. //预设文本样式
  78. SelectedPresetFontCommand = new DelegateCommand(SelectedPresetFont);
  79. //文本字重、字体
  80. FontStyleWeightChangedCommand = new DelegateCommand(FontStyleWeightChanged);
  81. //字体
  82. FontFamilyChangedCommand = new DelegateCommand(FontFamilyChanged);
  83. //自定义
  84. CustomFontStyleCommand = new DelegateCommand(CustomFontStyle);
  85. //重新定义
  86. ReDefineFontStyleCommand = new DelegateCommand(ReDefineFontStyle);
  87. //恢复默认
  88. RestoreDefaultStyleCommand = new DelegateCommand(RestoreDefaultStyle);
  89. //颜色
  90. SelectedColorCommand = new DelegateCommand<object>(SelectedColor_Command);
  91. //填充颜色
  92. SelectedFillColorCommand = new DelegateCommand<object>(SelectedFillColorChange);
  93. //填充颜色不透明度
  94. SelectedFillOpacityCommand = new DelegateCommand<object>(SelectedFillOpacity);
  95. //大小
  96. FontSizeChangedCommand = new DelegateCommand(FontSizeChanged);
  97. //内容对齐
  98. TextAlignCheckedCommand = new DelegateCommand<object>(TextAlignChecked);
  99. //填写与签名:日期
  100. DateFormatChangedCommand = new DelegateCommand(DateFormatChanged);
  101. ShowTimeCheckedChnagedCommand = new DelegateCommand(ShowTimeCheckedChnaged);
  102. //MVP不上
  103. LineModeCheckedCommand = new DelegateCommand<object>(LineMode_Checked);
  104. SelectedOpacityValueCommand = new DelegateCommand<object>(SelectedOpacityValue);
  105. InitVariable();
  106. }
  107. private void InitVariable()
  108. {
  109. DateFormatItems = new List<ComboDataItem>();
  110. DateFormatItems = TextFont.GetDateFormats();
  111. UpdateDateFormatLists();
  112. InitFillColorItems();
  113. }
  114. private void InitFillColorItems()
  115. {
  116. BasicVm.FillColorItems = AnnotColorList.GetFillColorList();
  117. }
  118. private void UpdateDateFormatLists()
  119. {
  120. string strTime = " HH:mm:ss";
  121. foreach (var item in DateFormatItems)
  122. {
  123. if (IsCheckedTime)
  124. strTime = item.ValueStr + " HH:mm:ss";
  125. else
  126. strTime = item.ValueStr;
  127. string stadate = System.DateTime.Now.ToString(strTime);
  128. item.SetContent(stadate);
  129. if (CurrrentDateFormat != null && item.ValueStr == CurrrentDateFormat.ValueStr)
  130. CurrrentDateFormat.SetContent(stadate);
  131. }
  132. CurrrentDateFormat = new ComboDataItem(CurrrentDateFormat.ValueStr, CurrrentDateFormat.Content);
  133. }
  134. private void TextAlignChecked(object obj)
  135. {
  136. if ((string)obj != null)
  137. {
  138. switch ((string)obj)
  139. {
  140. case "AlignLeft":
  141. GetAnnotAlign(TextAlignment.Left);
  142. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.TextAlign, TextAlignment.Left);
  143. break;
  144. case "AlignCenter":
  145. GetAnnotAlign(TextAlignment.Center);
  146. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.TextAlign, TextAlignment.Center);
  147. break;
  148. case "AlignRight":
  149. GetAnnotAlign(TextAlignment.Right);
  150. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.TextAlign, TextAlignment.Right);
  151. break;
  152. case "Justify":
  153. GetAnnotAlign(TextAlignment.Justify);
  154. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.TextAlign, TextAlignment.Justify);
  155. break;
  156. }
  157. }
  158. }
  159. private void LineMode_Checked(object obj)
  160. {
  161. if(obj != null)
  162. {
  163. var tag = ((string)obj);
  164. switch (tag)
  165. {
  166. case "Dashed":
  167. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, DashStyles.Dash);
  168. break;
  169. case "Solid":
  170. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, DashStyles.Solid);
  171. break;
  172. }
  173. AnnotEvent?.UpdateAnnot();
  174. }
  175. }
  176. //从预设样式设置文本
  177. private void SelectedPresetFont()
  178. {
  179. if (FontVm.CurrentPresetFont != null)
  180. {
  181. var itemComboxItem = FontVm.CurrentPresetFont;
  182. var item = FontVm.PresetFontList.FirstOrDefault(temp => temp.mTag == itemComboxItem.ValueStr);
  183. if (item != null)
  184. {
  185. FontVm.GetCurrentFontSize(item.mFontSize);
  186. if (item.mFontFamily != null)
  187. FontVm.GetCurrentFontFamily(item.mFontFamily.ToString(), item.mFontFamily.ToString());
  188. FontVm.GetFontWeights_Style(item.mFontStyle, item.mFontWeight);
  189. Dictionary<AnnotAttrib, object> AnnotAttribDir = new Dictionary<AnnotAttrib, object>();
  190. AnnotAttribDir.Add(AnnotAttrib.FontSize, item.mFontSize);
  191. AnnotAttribDir.Add(AnnotAttrib.FontFamily, item.mFontFamily);
  192. AnnotAttribDir.Add(AnnotAttrib.FontStyle, item.mFontStyle);
  193. AnnotAttribDir.Add(AnnotAttrib.FontWeight, item.mFontWeight);
  194. PropertyPanel.UpdateAnnotAllAttribs(AnnotAttribDir);
  195. }
  196. }
  197. }
  198. //设置文本字重、样式
  199. private void FontStyleWeightChanged()
  200. {
  201. if(FontVm.CurrrentFontWeightStyle != null)
  202. {
  203. FontVm.UpdateFontWeight_Style();
  204. Dictionary<AnnotAttrib, object> AnnotAttribDir = new Dictionary<AnnotAttrib, object>();
  205. AnnotAttribDir.Add(AnnotAttrib.FontStyle, FontVm.FontStyleItem);
  206. AnnotAttribDir.Add(AnnotAttrib.FontWeight, FontVm.FontWeightItem);
  207. PropertyPanel.UpdateAnnotAllAttribs(AnnotAttribDir);
  208. }
  209. }
  210. private void SelectedFillOpacity(object obj)
  211. {
  212. if (obj != null)
  213. {
  214. BasicVm.FillOpacity = (double)obj;
  215. BasicVm.FillColor.Opacity = BasicVm.FillOpacity;
  216. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Transparency, BasicVm.FillOpacity);
  217. }
  218. }
  219. private void SelectedOpacityValue(object obj)
  220. {
  221. if (obj != null && obj is double)
  222. {
  223. BasicVm.FillOpacity = (double)obj;
  224. BasicVm.FillColor.Opacity = BasicVm.FillOpacity;
  225. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Transparency, BasicVm.FillOpacity);
  226. }
  227. }
  228. //设置字体大小
  229. private void FontSizeChanged()
  230. {
  231. if (FontVm.CurrentFontSize != null)
  232. {
  233. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.FontSize, FontVm.CurrentFontSize.Value);
  234. }
  235. }
  236. //设置字体样式
  237. private void FontFamilyChanged()
  238. {
  239. if (string.IsNullOrEmpty(FontVm.CurrentFontFamily.ValueStr) == false)
  240. {
  241. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.FontFamily, new FontFamily(FontVm.CurrentFontFamily.ValueStr));
  242. }
  243. }
  244. private void SelectedFillColorChange(object obj)
  245. {
  246. if (obj != null)
  247. {
  248. var colorValue = (Color)obj;
  249. if (colorValue != null)
  250. {
  251. BasicVm.FillColor = new SolidColorBrush(colorValue);
  252. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.FillColor, colorValue);
  253. // BasicVm.FillColor.Opacity = BasicVmFillOpacity;
  254. }
  255. }
  256. }
  257. private void SelectedColor_Command(object obj)
  258. {
  259. if (obj != null)
  260. {
  261. var colorValue = (Color)obj;
  262. if (colorValue != null)
  263. {
  264. FontVm.FontColor = new SolidColorBrush(colorValue);
  265. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.FontColor, colorValue);
  266. }
  267. }
  268. }
  269. private void CustomFontStyle()
  270. {
  271. if (FontVm.CurrentPresetFont != null)
  272. {
  273. ContextMenu menu;
  274. if (FontVm.CurrentPresetFont.ValueStr == "custom")
  275. {
  276. menu = SelectAnnotContextMenu(false);
  277. }
  278. else
  279. {
  280. menu = SelectAnnotContextMenu(true);
  281. }
  282. if (menu != null)
  283. {
  284. menu.IsOpen = true;
  285. }
  286. }
  287. }
  288. private ContextMenu SelectAnnotContextMenu(bool isEnable)
  289. {
  290. var popMenu = App.Current.FindResource("CustomFontStyleFlyoutMenu") as ContextMenu;
  291. if (popMenu != null && popMenu.Items.Count == 2)
  292. {
  293. //用所选部分重新定义
  294. MenuItem menuItem = popMenu.Items[0] as MenuItem;
  295. menuItem.IsEnabled = isEnable;
  296. menuItem.Command = ReDefineFontStyleCommand;
  297. //恢复默认预设样式
  298. menuItem = popMenu.Items[1] as MenuItem;
  299. menuItem.IsEnabled = isEnable;
  300. menuItem.Command = RestoreDefaultStyleCommand;
  301. }
  302. return popMenu;
  303. }
  304. public List<PresetFontItem> FontStyleList = new List<PresetFontItem>();
  305. private void ReDefineFontStyle()
  306. {
  307. var item = FontVm.PresetFontList.FirstOrDefault(temp => temp.mTag == FontVm.CurrentPresetFont.ValueStr);
  308. if (item == null) return;
  309. item.mFontFamily = new FontFamily(FontVm.CurrentFontFamily.ValueStr);
  310. if (FontVm.CurrrentFontWeightStyle.ValueStr == "Bold")
  311. {
  312. item.mFontStyle = FontStyles.Normal;
  313. item.mFontWeight = FontWeights.Bold;
  314. }
  315. else if (FontVm.CurrrentFontWeightStyle.ValueStr == "Regular")
  316. {
  317. item.mFontStyle = FontStyles.Normal;
  318. item.mFontWeight = FontWeights.Normal;
  319. }
  320. else
  321. {
  322. item.mFontStyle = FontStyles.Italic;
  323. item.mFontWeight = FontWeights.Bold;
  324. }
  325. item.mFontSize = (int)FontVm.CurrentFontSize.Value;
  326. }
  327. private void RestoreDefaultStyle()
  328. {
  329. var defaultlists = TextFont.GetPresetFontStyle();
  330. if(FontVm.CurrentPresetFont.ValueStr != "custom")
  331. {
  332. var defaulItem = defaultlists.FirstOrDefault(temp => temp.mTag == FontVm.CurrentPresetFont.ValueStr);
  333. if (defaulItem != null)
  334. {
  335. var currentItem = FontVm.PresetFontList.FirstOrDefault(temp => temp.mTag == FontVm.CurrentPresetFont.ValueStr);
  336. if (currentItem != null)
  337. {
  338. currentItem.mTagContent = defaulItem.mTagContent;
  339. currentItem.mFontStyle = defaulItem.mFontStyle;
  340. currentItem.mFontWeight = defaulItem.mFontWeight;
  341. currentItem.mFontFamily = defaulItem.mFontFamily;
  342. currentItem.mFontSize = defaulItem.mFontSize;
  343. FontVm.GetCurrentFontFamily(currentItem.mFontFamily.ToString(), currentItem.mFontFamily.ToString());
  344. FontVm.GetCurrentFontSize(currentItem.mFontSize);
  345. FontVm.GetFontWeights_Style(currentItem.mFontStyle, currentItem.mFontWeight);
  346. }
  347. }
  348. }
  349. }
  350. private void DateFormatChanged()
  351. {
  352. if(CurrrentDateFormat != null)
  353. {
  354. if (IsCheckedTime)
  355. UpdateDateFormatLists();
  356. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.NoteText, CurrrentDateFormat.Content);
  357. }
  358. }
  359. private void ShowTimeCheckedChnaged()
  360. {
  361. if (CurrrentDateFormat != null)
  362. {
  363. UpdateDateFormatLists();
  364. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.NoteText, CurrrentDateFormat.Content);
  365. }
  366. }
  367. public bool IsNavigationTarget(NavigationContext navigationContext)
  368. {
  369. return true;
  370. }
  371. public void OnNavigatedFrom(NavigationContext navigationContext)
  372. {
  373. BasicVm.IsMultiSelected = false;
  374. // IsCheckedTime = false;
  375. }
  376. public void OnNavigatedTo(NavigationContext navigationContext)
  377. {
  378. navigationContext.Parameters.TryGetValue<AnnotPropertyPanel>(ParameterNames.PropertyPanelContentViewModel, out PropertyPanel);
  379. if (PropertyPanel != null)
  380. {
  381. AnnotEvent = PropertyPanel.AnnotEvent;
  382. Annot = PropertyPanel.annot as FreeTextAnnotArgs;
  383. LoadPropertyHandler?.Invoke(this, Annot);
  384. BasicVm.AnnotTypeTitle = "文字";
  385. BasicVm.IsMultiSelected = PropertyPanel.IsMultiSelected;
  386. IsFillFreeTextAnnot = PropertyPanel.IsTextFill;
  387. if (BasicVm.IsMultiSelected)
  388. {
  389. IsAttributeEquals();
  390. BasicVm.SetStrDashStyle("None");
  391. }
  392. else
  393. {
  394. GetAnnotProperty();
  395. }
  396. IsFillFreeTextAnnot = PropertyPanel.IsTextFill;
  397. }
  398. }
  399. /// <summary>
  400. /// 多选的注释
  401. /// </summary>
  402. private List<FreeTextAnnotArgs> ConvertLists()
  403. {
  404. List<FreeTextAnnotArgs> FreeTextLists = new List<FreeTextAnnotArgs>();
  405. foreach (var item in PropertyPanel.annotlists)
  406. {
  407. var itemFreeText = item as FreeTextAnnotArgs;
  408. if (itemFreeText != null)
  409. {
  410. FreeTextLists.Add(itemFreeText);
  411. }
  412. }
  413. if (FreeTextLists.Count != PropertyPanel.annotlists.Count)
  414. return null;
  415. else
  416. return FreeTextLists;
  417. }
  418. private void IsAttributeEquals()
  419. {
  420. var list = ConvertLists();
  421. if (list != null)
  422. {
  423. var temp = list[0];
  424. Dictionary<string, bool> isNoEqualsDir = new Dictionary<string, bool>();
  425. isNoEqualsDir.Add("FontFamily", false);
  426. isNoEqualsDir.Add("FontSize", false);
  427. isNoEqualsDir.Add("FontStyleFontWeight", false);
  428. isNoEqualsDir.Add("FontColor", false);
  429. isNoEqualsDir.Add("FillColor", false);
  430. isNoEqualsDir.Add("TextAglin", false);
  431. foreach (var item in list)
  432. {
  433. if (item == list[0])
  434. continue;
  435. if (temp.Align != item.Align)
  436. {
  437. isNoEqualsDir["TextAglin"] = true;
  438. FontVm.StrTextAlign = "None";
  439. }
  440. if (temp.FontFamily != item.FontFamily)
  441. {
  442. isNoEqualsDir["FontFamily"] = true;
  443. FontVm.CurrentFontFamily = null;
  444. }
  445. if (temp.FontSize != item.FontSize)
  446. {
  447. isNoEqualsDir["FontSize"] = true;
  448. FontVm.CurrentFontSize = null;
  449. }
  450. if (temp.FontStyle != item.FontStyle || temp.FontWeight != item.FontWeight)
  451. {
  452. isNoEqualsDir["FontStyleFontWeight"] = true;
  453. FontVm.CurrrentFontWeightStyle = null;
  454. }
  455. if (isNoEqualsDir["FontFamily"] == true || isNoEqualsDir["FontSize"] == true || isNoEqualsDir["FontStyleFontWeight"] == true)
  456. {
  457. FontVm.CurrentPresetFont = null;
  458. }
  459. if (isNoEqualsDir["FontColor"] == false)
  460. {
  461. if (temp.FontColor.A != item.FontColor.A || temp.FontColor.R != item.FontColor.R || temp.FontColor.G != item.FontColor.G || temp.FontColor.B != item.FontColor.B)
  462. {
  463. FontVm.FontColor = new SolidColorBrush(Colors.Transparent);
  464. isNoEqualsDir["FontColor"] = true;
  465. }
  466. }
  467. if (isNoEqualsDir["FillColor"] == false)
  468. {
  469. if (temp.BgColor.A != item.BgColor.A || temp.BgColor.R != item.BgColor.R || temp.BgColor.G != item.BgColor.G || temp.BgColor.B != item.BgColor.B)
  470. {
  471. BasicVm.FillColor = new SolidColorBrush(Colors.Transparent);
  472. isNoEqualsDir["FillColor"] = true;
  473. }
  474. }
  475. }
  476. ////以下是多选注释的属性相等时
  477. if (isNoEqualsDir["TextAglin"] == false)
  478. {
  479. GetAnnotAlign(temp.Align);
  480. }
  481. if (isNoEqualsDir["FontFamily"] == false)
  482. {
  483. FontVm.GetCurrentFontFamily(temp.FontFamily.ToString(), temp.FontFamily.ToString());
  484. }
  485. if (isNoEqualsDir["FontSize"] == false)
  486. {
  487. FontVm.GetCurrentFontSize((int)temp.FontSize);
  488. }
  489. if (isNoEqualsDir["FontStyleFontWeight"] == false)
  490. {
  491. FontVm.GetFontWeights_Style(temp.FontStyle, temp.FontWeight);
  492. }
  493. if (isNoEqualsDir["FontColor"] == false)
  494. {
  495. FontVm.FontColor = new SolidColorBrush(temp.FontColor);
  496. }
  497. if (isNoEqualsDir["FillColor"] == false)
  498. {
  499. FontVm.FontColor = new SolidColorBrush(temp.BgColor);
  500. }
  501. }
  502. }
  503. private void GetAnnotProperty()
  504. {
  505. BasicVm.FillColor = new SolidColorBrush(Annot.BgColor);
  506. BasicVm.FillOpacity = Annot.Transparency;
  507. FontVm.FontColor = new SolidColorBrush(Annot.FontColor);
  508. FontVm.GetCurrentFontSize((int)Annot.FontSize);
  509. FontVm.GetCurrentFontFamily(Annot.FontFamily.ToString(), Annot.FontFamily.ToString());
  510. FontVm.GetFontWeights_Style(Annot.FontStyle, Annot.FontWeight);
  511. GetTimeFormat();
  512. GetAnnotAlign(Annot.Align);
  513. }
  514. //填写与签名
  515. private void GetTimeFormat()
  516. {
  517. if (IsFillFreeTextAnnot == false)
  518. return;
  519. if(string.IsNullOrEmpty(Annot.TextContent))
  520. {
  521. if (CurrrentDateFormat != null)
  522. {
  523. if (IsCheckedTime)
  524. UpdateDateFormatLists();
  525. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.NoteText, CurrrentDateFormat.Content);
  526. }
  527. return;
  528. }
  529. DateTime dtDate;
  530. bool isTime = false;
  531. foreach (var item in DateFormatItems)
  532. {
  533. var strFormat = "";
  534. var strArr = Annot.TextContent.Split(' ');
  535. if (strArr != null && strArr.Count() == 2)
  536. {
  537. strFormat = item.ValueStr + " HH:mm:ss";
  538. }
  539. else
  540. {
  541. strFormat = item.ValueStr;
  542. }
  543. if (DateTime.TryParseExact(Annot.TextContent, strFormat, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AdjustToUniversal, out dtDate))
  544. {
  545. if (strArr != null && strArr.Count() == 2)
  546. {
  547. isTime = true;
  548. }
  549. foreach (var item2 in DateFormatItems)
  550. {
  551. string stadate = System.DateTime.Now.ToString(strFormat);
  552. item.SetContent(stadate);
  553. }
  554. CurrrentDateFormat = new ComboDataItem(item.ValueStr, item.Content);
  555. break;
  556. }
  557. }
  558. IsCheckedTime = isTime;
  559. }
  560. //文本内容对齐
  561. private void GetAnnotAlign(TextAlignment align)
  562. {
  563. switch (align)
  564. {
  565. case TextAlignment.Left:
  566. FontVm.StrTextAlign = "Left";
  567. break;
  568. case TextAlignment.Center:
  569. FontVm.StrTextAlign = "Center";
  570. break;
  571. case TextAlignment.Right:
  572. FontVm.StrTextAlign = "Right";
  573. break;
  574. case TextAlignment.Justify:
  575. FontVm.StrTextAlign = "Justify";
  576. break;
  577. default:
  578. FontVm.StrTextAlign = "None";
  579. break;
  580. }
  581. }
  582. }
  583. }