FreetextAnnotPropertyViewModel.cs 26 KB

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