FreetextAnnotPropertyViewModel.cs 26 KB

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