FreetextAnnotPropertyViewModel.cs 30 KB

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