FreetextAnnotPropertyViewModel.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  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. {
  225. FontVm.GetCurrentFontFamily(item.mFontFamily.ToString(), item.mFontFamily.ToString());
  226. }
  227. FontVm.GetFontWeights_Style(item.mFontStyle, item.mFontWeight);
  228. Dictionary<AnnotAttrib, object> AnnotAttribDir = new Dictionary<AnnotAttrib, object>();
  229. AnnotAttribDir.Add(AnnotAttrib.FontSize, item.mFontSize);
  230. AnnotAttribDir.Add(AnnotAttrib.FontFamily, item.mFontFamily);
  231. AnnotAttribDir.Add(AnnotAttrib.FontStyle, item.mFontStyle);
  232. AnnotAttribDir.Add(AnnotAttrib.FontWeight, item.mFontWeight);
  233. PropertyPanel.UpdateAnnotAllAttribs(AnnotAttribDir);
  234. }
  235. }
  236. }
  237. //设置文本字重、样式
  238. private void FontStyleWeightChanged()
  239. {
  240. if (FontVm.CurrrentFontWeightStyle != null)
  241. {
  242. FontVm.UpdateFontWeight_Style();
  243. Dictionary<AnnotAttrib, object> AnnotAttribDir = new Dictionary<AnnotAttrib, object>();
  244. AnnotAttribDir.Add(AnnotAttrib.FontStyle, FontVm.FontStyleItem);
  245. AnnotAttribDir.Add(AnnotAttrib.FontWeight, FontVm.FontWeightItem);
  246. PropertyPanel.UpdateAnnotAllAttribs(AnnotAttribDir);
  247. }
  248. }
  249. private void SelectedFillOpacity(object obj)
  250. {
  251. if (obj != null)
  252. {
  253. BasicVm.FillOpacity = (double)obj;
  254. BasicVm.FillColor.Opacity = BasicVm.FillOpacity;
  255. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Transparency, BasicVm.FillOpacity);
  256. }
  257. }
  258. private void SelectedOpacityValue(object obj)
  259. {
  260. if (obj != null && obj is double)
  261. {
  262. BasicVm.FillOpacity = (double)obj;
  263. BasicVm.FillColor.Opacity = BasicVm.FillOpacity;
  264. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Transparency, BasicVm.FillOpacity);
  265. }
  266. }
  267. //设置字体大小
  268. private void FontSizeChanged()
  269. {
  270. if (FontVm.CurrentFontSize != null)
  271. {
  272. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.FontSize, FontVm.CurrentFontSize.Value);
  273. if (BasicVm.IsMultiSelected == false)
  274. PropertyPanel.InvokeToMyTools(BasicVm.AnnotType, Annot);
  275. }
  276. }
  277. //设置字体样式
  278. private void FontFamilyChanged()
  279. {
  280. if (string.IsNullOrEmpty(FontVm.CurrentFontFamily.ValueStr) == false)
  281. {
  282. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.FontFamily, new FontFamily(FontVm.CurrentFontFamily.ValueStr));
  283. }
  284. }
  285. private void SelectedFillColorChange(object obj)
  286. {
  287. if (obj != null)
  288. {
  289. var colorValue = (Color)obj;
  290. if (colorValue != null)
  291. {
  292. BasicVm.FillColor = new SolidColorBrush(colorValue);
  293. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.FillColor, colorValue);
  294. // BasicVm.FillColor.Opacity = BasicVmFillOpacity;
  295. }
  296. }
  297. }
  298. private void SelectedColor_Command(object obj)
  299. {
  300. if (obj != null)
  301. {
  302. var colorValue = (Color)obj;
  303. if (colorValue != null)
  304. {
  305. FontVm.FontColor = new SolidColorBrush(colorValue);
  306. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.FontColor, colorValue);
  307. }
  308. }
  309. }
  310. private void CustomFontStyle()
  311. {
  312. if (FontVm.CurrentPresetFont != null)
  313. {
  314. ContextMenu menu;
  315. if (FontVm.CurrentPresetFont.ValueStr == "custom")
  316. {
  317. menu = SelectAnnotContextMenu(false);
  318. }
  319. else
  320. {
  321. menu = SelectAnnotContextMenu(true);
  322. }
  323. if (menu != null)
  324. {
  325. menu.IsOpen = true;
  326. }
  327. }
  328. }
  329. private ContextMenu SelectAnnotContextMenu(bool isEnable)
  330. {
  331. var popMenu = App.Current.FindResource("CustomFontStyleFlyoutMenu") as ContextMenu;
  332. if (popMenu != null && popMenu.Items.Count == 2)
  333. {
  334. //用所选部分重新定义
  335. MenuItem menuItem = popMenu.Items[0] as MenuItem;
  336. menuItem.IsEnabled = isEnable;
  337. menuItem.Command = ReDefineFontStyleCommand;
  338. //恢复默认预设样式
  339. menuItem = popMenu.Items[1] as MenuItem;
  340. menuItem.IsEnabled = isEnable;
  341. menuItem.Command = RestoreDefaultStyleCommand;
  342. }
  343. return popMenu;
  344. }
  345. public List<PresetFontItem> FontStyleList = new List<PresetFontItem>();
  346. private void ReDefineFontStyle()
  347. {
  348. var item = FontVm.PresetFontList.FirstOrDefault(temp => temp.mTag == FontVm.CurrentPresetFont.ValueStr);
  349. if (item == null) return;
  350. item.mFontFamily = new FontFamily(FontVm.CurrentFontFamily.ValueStr);
  351. if (FontVm.CurrrentFontWeightStyle.ValueStr == "Bold")
  352. {
  353. item.mFontStyle = FontStyles.Normal;
  354. item.mFontWeight = FontWeights.Bold;
  355. }
  356. else if (FontVm.CurrrentFontWeightStyle.ValueStr == "Regular")
  357. {
  358. item.mFontStyle = FontStyles.Normal;
  359. item.mFontWeight = FontWeights.Normal;
  360. }
  361. else
  362. {
  363. item.mFontStyle = FontStyles.Italic;
  364. item.mFontWeight = FontWeights.Bold;
  365. }
  366. item.mFontSize = (int)FontVm.CurrentFontSize.Value;
  367. }
  368. private void RestoreDefaultStyle()
  369. {
  370. var defaultlists = TextFont.GetPresetFontStyle();
  371. if (FontVm.CurrentPresetFont.ValueStr != "custom")
  372. {
  373. var defaulItem = defaultlists.FirstOrDefault(temp => temp.mTag == FontVm.CurrentPresetFont.ValueStr);
  374. if (defaulItem != null)
  375. {
  376. var currentItem = FontVm.PresetFontList.FirstOrDefault(temp => temp.mTag == FontVm.CurrentPresetFont.ValueStr);
  377. if (currentItem != null)
  378. {
  379. currentItem.mTagContent = defaulItem.mTagContent;
  380. currentItem.mFontStyle = defaulItem.mFontStyle;
  381. currentItem.mFontWeight = defaulItem.mFontWeight;
  382. currentItem.mFontFamily = defaulItem.mFontFamily;
  383. currentItem.mFontSize = defaulItem.mFontSize;
  384. FontVm.GetCurrentFontFamily(currentItem.mFontFamily.ToString(), currentItem.mFontFamily.ToString());
  385. FontVm.GetCurrentFontSize(currentItem.mFontSize);
  386. FontVm.GetFontWeights_Style(currentItem.mFontStyle, currentItem.mFontWeight);
  387. }
  388. }
  389. }
  390. }
  391. private void DateFormatChanged()
  392. {
  393. if (CurrrentDateFormat != null)
  394. {
  395. if (IsCheckedTime)
  396. UpdateDateFormatLists();
  397. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.NoteText, CurrrentDateFormat.Content);
  398. }
  399. }
  400. private void ShowTimeCheckedChnaged()
  401. {
  402. if (CurrrentDateFormat != null)
  403. {
  404. UpdateDateFormatLists();
  405. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.NoteText, CurrrentDateFormat.Content);
  406. }
  407. }
  408. public bool IsNavigationTarget(NavigationContext navigationContext)
  409. {
  410. return true;
  411. }
  412. public void OnNavigatedFrom(NavigationContext navigationContext)
  413. {
  414. BasicVm.IsMultiSelected = false;
  415. // IsCheckedTime = false;
  416. }
  417. public void OnNavigatedTo(NavigationContext navigationContext)
  418. {
  419. navigationContext.Parameters.TryGetValue<AnnotTransfer>(ParameterNames.PropertyPanelContentViewModel, out PropertyPanel);
  420. if (PropertyPanel != null)
  421. {
  422. AnnotEvent = PropertyPanel.AnnotEvent;
  423. Annot = PropertyPanel.annot as FreeTextAnnotArgs;
  424. LoadPropertyHandler?.Invoke(this, Annot);
  425. BasicVm.AnnotTypeTitle = "文字";
  426. BasicVm.IsMultiSelected = PropertyPanel.IsMultiSelected;
  427. IsFillFreeTextAnnot = PropertyPanel.IsTextFill;
  428. if (BasicVm.IsMultiSelected)
  429. {
  430. IsAttributeEquals();
  431. BasicVm.IsSolidLine = BasicVm.IsDashLine = false;
  432. }
  433. else
  434. {
  435. GetAnnotProperty();
  436. }
  437. IsFillFreeTextAnnot = PropertyPanel.IsTextFill;
  438. }
  439. }
  440. /// <summary>
  441. /// 多选的注释
  442. /// </summary>
  443. private List<FreeTextAnnotArgs> ConvertLists()
  444. {
  445. List<FreeTextAnnotArgs> FreeTextLists = new List<FreeTextAnnotArgs>();
  446. foreach (var item in PropertyPanel.annotlists)
  447. {
  448. var itemFreeText = item as FreeTextAnnotArgs;
  449. if (itemFreeText != null)
  450. {
  451. FreeTextLists.Add(itemFreeText);
  452. }
  453. }
  454. if (FreeTextLists.Count != PropertyPanel.annotlists.Count)
  455. return null;
  456. else
  457. return FreeTextLists;
  458. }
  459. private void IsAttributeEquals()
  460. {
  461. var list = ConvertLists();
  462. if (list != null)
  463. {
  464. var temp = list[0];
  465. Dictionary<string, bool> isNoEqualsDir = new Dictionary<string, bool>();
  466. isNoEqualsDir.Add("FontFamily", false);
  467. isNoEqualsDir.Add("FontSize", false);
  468. isNoEqualsDir.Add("FontStyleFontWeight", false);
  469. isNoEqualsDir.Add("FontColor", false);
  470. isNoEqualsDir.Add("FillColor", false);
  471. isNoEqualsDir.Add("TextAglin", false);
  472. foreach (var item in list)
  473. {
  474. if (item == list[0])
  475. continue;
  476. if (temp.Align != item.Align)
  477. {
  478. isNoEqualsDir["TextAglin"] = true;
  479. FontVm.StrTextAlign = "None";
  480. }
  481. if (temp.FontFamily != item.FontFamily)
  482. {
  483. isNoEqualsDir["FontFamily"] = true;
  484. FontVm.CurrentFontFamily = null;
  485. }
  486. if (temp.FontSize != item.FontSize)
  487. {
  488. isNoEqualsDir["FontSize"] = true;
  489. FontVm.CurrentFontSize = null;
  490. }
  491. if (temp.FontStyle != item.FontStyle || temp.FontWeight != item.FontWeight)
  492. {
  493. isNoEqualsDir["FontStyleFontWeight"] = true;
  494. FontVm.CurrrentFontWeightStyle = null;
  495. }
  496. if (isNoEqualsDir["FontFamily"] == true || isNoEqualsDir["FontSize"] == true || isNoEqualsDir["FontStyleFontWeight"] == true)
  497. {
  498. FontVm.CurrentPresetFont = null;
  499. }
  500. if (isNoEqualsDir["FontColor"] == false)
  501. {
  502. 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)
  503. {
  504. FontVm.FontColor = new SolidColorBrush(Color.FromArgb(0x01, 0xff, 0xff, 0xff));
  505. isNoEqualsDir["FontColor"] = true;
  506. }
  507. }
  508. if (isNoEqualsDir["FillColor"] == false)
  509. {
  510. 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)
  511. {
  512. BasicVm.FillColor = new SolidColorBrush(Color.FromArgb(0x01, 0xff, 0xff, 0xff));
  513. isNoEqualsDir["FillColor"] = true;
  514. }
  515. }
  516. }
  517. ////以下是多选注释的属性相等时
  518. if (isNoEqualsDir["TextAglin"] == false)
  519. {
  520. GetAnnotAlign(temp.Align);
  521. }
  522. if (isNoEqualsDir["FontFamily"] == false)
  523. {
  524. FontVm.GetCurrentFontFamily(temp.FontFamily.ToString(), temp.FontFamily.ToString());
  525. }
  526. if (isNoEqualsDir["FontSize"] == false)
  527. {
  528. FontVm.GetCurrentFontSize((int)temp.FontSize);
  529. }
  530. if (isNoEqualsDir["FontStyleFontWeight"] == false)
  531. {
  532. FontVm.GetFontWeights_Style(temp.FontStyle, temp.FontWeight);
  533. }
  534. if (isNoEqualsDir["FontColor"] == false)
  535. {
  536. FontVm.FontColor = new SolidColorBrush(temp.FontColor);
  537. }
  538. if (isNoEqualsDir["FillColor"] == false)
  539. {
  540. FontVm.FontColor = new SolidColorBrush(temp.BgColor);
  541. }
  542. }
  543. }
  544. private void GetAnnotProperty()
  545. {
  546. BasicVm.FillColor = new SolidColorBrush(Annot.BgColor);
  547. BasicVm.FillOpacity = Annot.Transparency;
  548. FontVm.FontColor = new SolidColorBrush(Annot.FontColor);
  549. FontVm.GetCurrentFontSize((int)Annot.FontSize);
  550. FontVm.GetCurrentPresetFont(Annot);
  551. FontVm.GetCurrentFontFamily(Annot.FontFamily.ToString(), Annot.FontFamily.ToString());
  552. FontVm.GetFontWeights_Style(Annot.FontStyle, Annot.FontWeight);
  553. GetTimeFormat();
  554. GetAnnotAlign(Annot.Align);
  555. }
  556. //填写与签名
  557. private void GetTimeFormat()
  558. {
  559. if (IsFillFreeTextAnnot == false)
  560. return;
  561. if (string.IsNullOrEmpty(Annot.TextContent))
  562. {
  563. if (CurrrentDateFormat != null)
  564. {
  565. if (IsCheckedTime)
  566. UpdateDateFormatLists();
  567. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.NoteText, CurrrentDateFormat.Content);
  568. }
  569. return;
  570. }
  571. DateTime dtDate;
  572. bool isTime = false;
  573. foreach (var item in DateFormatItems)
  574. {
  575. var strFormat = "";
  576. var strArr = Annot.TextContent.Split(' ');
  577. if (strArr != null && strArr.Count() == 2)
  578. {
  579. strFormat = item.ValueStr + " HH:mm:ss";
  580. }
  581. else
  582. {
  583. strFormat = item.ValueStr;
  584. }
  585. if (DateTime.TryParseExact(Annot.TextContent, strFormat, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AdjustToUniversal, out dtDate))
  586. {
  587. if (strArr != null && strArr.Count() == 2)
  588. {
  589. isTime = true;
  590. }
  591. foreach (var item2 in DateFormatItems)
  592. {
  593. string stadate = System.DateTime.Now.ToString(strFormat);
  594. item.SetContent(stadate);
  595. }
  596. CurrrentDateFormat = new ComboDataItem(item.ValueStr, item.Content);
  597. break;
  598. }
  599. }
  600. IsCheckedTime = isTime;
  601. }
  602. //文本内容对齐
  603. private void GetAnnotAlign(TextAlignment align)
  604. {
  605. switch (align)
  606. {
  607. case TextAlignment.Left:
  608. FontVm.StrTextAlign = "Left";
  609. break;
  610. case TextAlignment.Center:
  611. FontVm.StrTextAlign = "Center";
  612. break;
  613. case TextAlignment.Right:
  614. FontVm.StrTextAlign = "Right";
  615. break;
  616. case TextAlignment.Justify:
  617. FontVm.StrTextAlign = "Justify";
  618. break;
  619. default:
  620. FontVm.StrTextAlign = "None";
  621. break;
  622. }
  623. }
  624. }
  625. }