FreetextAnnotPropertyViewModel.cs 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999
  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. /// <summary>
  227. /// 从预设样式设置文本
  228. /// </summary>
  229. private void SelectedPresetFont()
  230. {
  231. if (FontVm.CurrentPresetFont != null)
  232. {
  233. var itemComboxItem = FontVm.CurrentPresetFont;
  234. var item = FontVm.PresetFontList.FirstOrDefault(temp => temp.mTag == itemComboxItem.ValueStr);
  235. if (item != null)
  236. {
  237. if (item.mTag != "Custom")
  238. {
  239. FontVm.GetCurrentFontSize(item.mFontSize);
  240. if (item.mFontFamily != null)
  241. {
  242. FontVm.GetCurrentFontFamily(item.mFontFamily.ToString(), item.mFontFamily.ToString());
  243. }
  244. FontVm.GetFontWeights_Style(item.mFontStyle, item.mFontWeight);
  245. Dictionary<AnnotAttrib, object> AnnotAttribDir = new Dictionary<AnnotAttrib, object>();
  246. AnnotAttribDir.Add(AnnotAttrib.FontSize, item.mFontSize);
  247. AnnotAttribDir.Add(AnnotAttrib.FontName, item.mFontFamily.Source);
  248. AnnotAttribDir.Add(AnnotAttrib.IsItalic, item.mFontStyle == FontStyles.Italic);
  249. AnnotAttribDir.Add(AnnotAttrib.IsBold, item.mFontWeight == FontWeights.Bold);
  250. PropertyPanel.UpdateAnnotAllAttribs(AnnotAttribDir);
  251. }
  252. }
  253. }
  254. }
  255. //设置文本字重、样式
  256. /// <summary>
  257. /// 设置文本字重、样式
  258. /// </summary>
  259. private void FontStyleWeightChanged()
  260. {
  261. if (FontVm.CurrrentFontWeightStyle != null)
  262. {
  263. FontVm.UpdateFontWeight_Style();
  264. Dictionary<AnnotAttrib, object> AnnotAttribDir = new Dictionary<AnnotAttrib, object>();
  265. AnnotAttribDir.Add(AnnotAttrib.IsItalic, FontVm.FontStyleItem == FontStyles.Italic);
  266. AnnotAttribDir.Add(AnnotAttrib.IsBold, FontVm.FontWeightItem == FontWeights.Bold);
  267. PropertyPanel.UpdateAnnotAllAttribs(AnnotAttribDir);
  268. if (FontVm.CurrentPresetFont != null)
  269. {
  270. var currentItem = FontVm.PresetFontList.FirstOrDefault(temp => temp.mTag == FontVm.CurrentPresetFont.ValueStr);
  271. if (currentItem.mTag != "Custom")
  272. {
  273. foreach (var item in FontVm.PresetFontList)
  274. {
  275. if (item.mTag == currentItem.mTag)
  276. {
  277. if (FontVm.FontWeightItem != item.mFontWeight || FontVm.FontStyleItem != item.mFontStyle)
  278. {
  279. string txt = string.Format($" * {currentItem.mTagContent}");
  280. if (Title == txt)
  281. {
  282. Title = "";
  283. }
  284. Title = txt;
  285. break;
  286. }
  287. else
  288. {
  289. if (FontVm.FontWeightItem == item.mFontWeight && FontVm.FontStyleItem == item.mFontStyle && FontVm.CurrentFontSize.Value == item.mFontSize && FontVm.CurrentFontFamily.ValueStr == item.mFontFamily.Source)
  290. {
  291. string txt = currentItem.mTagContent;
  292. if (Title == txt)
  293. {
  294. Title = "";
  295. }
  296. Title = txt;
  297. }
  298. }
  299. }
  300. }
  301. }
  302. else
  303. {
  304. bool isExist = FontVm.GetCurrentPresetFont(Annot);
  305. if (isExist)
  306. {
  307. }
  308. }
  309. }
  310. }
  311. }
  312. private void SelectedFillOpacity(object obj)
  313. {
  314. if (obj != null)
  315. {
  316. BasicVm.FillOpacity = (double)obj;
  317. BasicVm.FillColor.Opacity = BasicVm.FillOpacity;
  318. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Transparency, BasicVm.FillOpacity);
  319. }
  320. }
  321. /// <summary>
  322. /// 设置颜色透明度
  323. /// </summary>
  324. /// <param name="obj"></param>
  325. private void SelectedOpacityValue(object obj)
  326. {
  327. if (obj != null && obj is double)
  328. {
  329. if (BasicVm.FillOpacity != (double)obj)
  330. {
  331. BasicVm.FillOpacity = (double)obj;
  332. }
  333. if (BasicVm.FontColor.Opacity != BasicVm.FillOpacity)
  334. {
  335. BasicVm.FontColor.Opacity = BasicVm.FillOpacity;
  336. }
  337. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.Transparency, BasicVm.FillOpacity);
  338. PropertyPanel.InvokeToMyTools(AnnotArgsType.AnnotFreeText, BasicVm.FillOpacity);
  339. }
  340. }
  341. //设置字体大小
  342. private void FontSizeChanged()
  343. {
  344. if (FontVm.CurrentFontSize != null)
  345. {
  346. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.FontSize, FontVm.CurrentFontSize.Value);
  347. //if (BasicVm.IsMultiSelected == false)
  348. // PropertyPanel.InvokeToMyTools(BasicVm.AnnotType, Annot);
  349. }
  350. if (FontVm.CurrentPresetFont != null)
  351. {
  352. var currentItem = FontVm.PresetFontList.FirstOrDefault(temp => temp.mTag == FontVm.CurrentPresetFont.ValueStr);
  353. //var comboDataItem = FontVm.PresetFontItems.FirstOrDefault(temp => temp.ValueStr == FontVm.CurrentPresetFont.ValueStr);
  354. if (currentItem.mTag != "Custom")
  355. {
  356. foreach (var item in FontVm.PresetFontList)
  357. {
  358. if (item.mTag == currentItem.mTag)
  359. {
  360. if (FontVm.CurrentFontSize.Value != item.mFontSize)
  361. {
  362. string txt = string.Format($" * {currentItem.mTagContent}");
  363. if (Title == txt)
  364. {
  365. Title = "";
  366. }
  367. Title = txt;
  368. break;
  369. }
  370. else
  371. {
  372. if (FontVm.FontWeightItem == item.mFontWeight && FontVm.FontStyleItem == item.mFontStyle && FontVm.CurrentFontSize.Value == item.mFontSize && FontVm.CurrentFontFamily.ValueStr == item.mFontFamily.Source)
  373. {
  374. string txt = currentItem.mTagContent;
  375. if (Title == txt)
  376. {
  377. Title = "";
  378. }
  379. Title = txt;
  380. }
  381. }
  382. }
  383. }
  384. }
  385. else
  386. {
  387. bool isExist = FontVm.GetCurrentPresetFont(Annot);
  388. if (isExist)
  389. {
  390. }
  391. }
  392. }
  393. }
  394. //设置字体样式
  395. private void FontFamilyChanged()
  396. {
  397. if (string.IsNullOrEmpty(FontVm.CurrentFontFamily.ValueStr) == false)
  398. {
  399. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.FontName, FontVm.CurrentFontFamily.ValueStr);
  400. }
  401. if (FontVm.CurrentPresetFont != null)
  402. {
  403. var currentItem = FontVm.PresetFontList.FirstOrDefault(temp => temp.mTag == FontVm.CurrentPresetFont.ValueStr);
  404. //var comboDataItem = FontVm.PresetFontItems.FirstOrDefault(temp => temp.ValueStr == FontVm.CurrentPresetFont.ValueStr);
  405. if (currentItem.mTag != "Custom")
  406. {
  407. foreach (var item in FontVm.PresetFontList)
  408. {
  409. if (item.mTag == currentItem.mTag)
  410. {
  411. if (FontVm.CurrentFontFamily.ValueStr != item.mFontFamily.Source)
  412. {
  413. string txt = string.Format($" * {currentItem.mTagContent}");
  414. if (Title == txt)
  415. {
  416. Title = "";
  417. }
  418. Title = txt;
  419. break;
  420. }
  421. else
  422. {
  423. if (FontVm.FontWeightItem == item.mFontWeight && FontVm.FontStyleItem == item.mFontStyle && FontVm.CurrentFontSize.Value == item.mFontSize && FontVm.CurrentFontFamily.ValueStr == item.mFontFamily.Source)
  424. {
  425. string txt = currentItem.mTagContent;
  426. if (Title == txt)
  427. {
  428. Title = "";
  429. }
  430. Title = txt;
  431. }
  432. }
  433. }
  434. }
  435. }
  436. else
  437. {
  438. bool isExist = FontVm.GetCurrentPresetFont(Annot);
  439. if (isExist)
  440. {
  441. }
  442. }
  443. }
  444. }
  445. private void SelectedFillColorChange(object obj)
  446. {
  447. if (obj != null)
  448. {
  449. var colorValue = (Color)obj;
  450. if (colorValue != null)
  451. {
  452. BasicVm.FillColor = new SolidColorBrush(colorValue);
  453. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.FillColor, colorValue);
  454. // BasicVm.FillColor.Opacity = BasicVmFillOpacity;
  455. }
  456. }
  457. }
  458. private void SelectedColor_Command(object obj)
  459. {
  460. if (obj != null)
  461. {
  462. var colorValue = (Color)obj;
  463. if (colorValue != null)
  464. {
  465. FontVm.FontColor = new SolidColorBrush(colorValue);
  466. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.FontColor, colorValue);
  467. }
  468. }
  469. }
  470. /// <summary>
  471. /// 设置更多菜单
  472. /// </summary>
  473. private void CustomFontStyle()
  474. {
  475. if (FontVm.CurrentPresetFont != null)
  476. {
  477. ContextMenu menu;
  478. if (FontVm.CurrentPresetFont.ValueStr == "Custom")
  479. {
  480. menu = SelectAnnotContextMenu(false, false);
  481. }
  482. else
  483. {
  484. menu = SelectAnnotContextMenu(false,false);
  485. var currentItem = FontVm.PresetFontList.FirstOrDefault(temp => temp.mTag == FontVm.CurrentPresetFont.ValueStr);
  486. if (currentItem.mTag != "Custom")
  487. {
  488. if (FontVm.FontWeightItem != currentItem.mFontWeight ||
  489. FontVm.FontStyleItem != currentItem.mFontStyle ||
  490. FontVm.CurrentFontSize.Value != currentItem.mFontSize ||
  491. FontVm.CurrentFontFamily.ValueStr != currentItem.mFontFamily.Source)
  492. {
  493. //重新定义按钮 调整
  494. menu = SelectAnnotContextMenu(true);
  495. }
  496. else
  497. {
  498. //更改默认后 ,可以右键恢复
  499. var defaultlists = TextFont.GetPresetFontStyle();
  500. var defaulItem = defaultlists.FirstOrDefault(temp => temp.mTag == FontVm.CurrentPresetFont.ValueStr);
  501. if (defaulItem != null && currentItem != null)
  502. {
  503. if (currentItem.mTagContent == defaulItem.mTagContent)
  504. {
  505. if (currentItem.mFontStyle != defaulItem.mFontStyle ||
  506. currentItem.mFontWeight != defaulItem.mFontWeight ||
  507. currentItem.mFontFamily.Source != defaulItem.mFontFamily.Source ||
  508. currentItem.mFontSize != defaulItem.mFontSize)
  509. {
  510. menu = SelectAnnotContextMenu(true, false);
  511. }
  512. else
  513. {
  514. menu = SelectAnnotContextMenu(false, false);
  515. }
  516. }
  517. }
  518. }
  519. }
  520. }
  521. if (menu != null)
  522. {
  523. menu.IsOpen = true;
  524. }
  525. }
  526. }
  527. /// <summary>
  528. /// 更多菜单
  529. /// 230606 文本预设,修改参数后,redefine按钮应当只能点一次,后面要置灰
  530. /// </summary>
  531. /// <param name="isEnable"></param>
  532. /// <returns></returns>
  533. private ContextMenu SelectAnnotContextMenu(bool isEnable,bool isReDefine=true)
  534. {
  535. var popMenu = App.Current.FindResource("CustomFontStyleFlyoutMenu") as ContextMenu;
  536. if (popMenu != null && popMenu.Items.Count == 2)
  537. {
  538. //用所选部分重新定义
  539. MenuItem menuItem = popMenu.Items[0] as MenuItem;
  540. menuItem.IsEnabled = isReDefine;
  541. menuItem.Command = ReDefineFontStyleCommand;
  542. //恢复默认预设样式
  543. menuItem = popMenu.Items[1] as MenuItem;
  544. menuItem.IsEnabled = isEnable;
  545. menuItem.Command = RestoreDefaultStyleCommand;
  546. }
  547. return popMenu;
  548. }
  549. public List<PresetFontItem> FontStyleList = new List<PresetFontItem>();
  550. /// <summary>
  551. /// 用所选部分重新定义
  552. /// </summary>
  553. private void ReDefineFontStyle()
  554. {
  555. var item = FontVm.PresetFontList.FirstOrDefault(temp => temp.mTag == FontVm.CurrentPresetFont.ValueStr);
  556. if (item == null) return;
  557. item.mFontFamily = new FontFamily(FontVm.CurrentFontFamily.ValueStr);
  558. if (FontVm.CurrrentFontWeightStyle.ValueStr == "Bold")
  559. {
  560. item.mFontStyle = FontStyles.Normal;
  561. item.mFontWeight = FontWeights.Bold;
  562. }
  563. else if (FontVm.CurrrentFontWeightStyle.ValueStr == "Regular")
  564. {
  565. item.mFontStyle = FontStyles.Normal;
  566. item.mFontWeight = FontWeights.Normal;
  567. }
  568. else if (FontVm.CurrrentFontWeightStyle.ValueStr == "Italic")
  569. {
  570. item.mFontStyle = FontStyles.Italic;
  571. item.mFontWeight = FontWeights.Normal;
  572. }
  573. else
  574. {
  575. item.mFontStyle = FontStyles.Italic;
  576. item.mFontWeight = FontWeights.Bold;
  577. }
  578. item.mFontSize = (int)FontVm.CurrentFontSize.Value;
  579. FontVm.CurrentPresetFont = new ComboDataItem(item.mTag, item.mTagContent);
  580. SelectedPresetFont();
  581. if (BasicVm.IsMultiSelected == false)
  582. PropertyPanel.InvokeToMyTools(BasicVm.AnnotType, Annot);
  583. //更改后 保存到本地缓存
  584. TextFont.SavePresetFontList(FontVm.PresetFontList);
  585. }
  586. /// <summary>
  587. /// 恢复默认预设样式
  588. /// </summary>
  589. private void RestoreDefaultStyle()
  590. {
  591. var defaultlists = TextFont.GetPresetFontStyle();
  592. if (FontVm.CurrentPresetFont.ValueStr != "Custom")
  593. {
  594. var defaulItem = defaultlists.FirstOrDefault(temp => temp.mTag == FontVm.CurrentPresetFont.ValueStr);
  595. if (defaulItem != null)
  596. {
  597. var currentItem = FontVm.PresetFontList.FirstOrDefault(temp => temp.mTag == FontVm.CurrentPresetFont.ValueStr);
  598. if (currentItem != null)
  599. {
  600. currentItem.mTagContent = defaulItem.mTagContent;
  601. currentItem.mFontStyle = defaulItem.mFontStyle;
  602. currentItem.mFontWeight = defaulItem.mFontWeight;
  603. currentItem.mFontFamily = defaulItem.mFontFamily;
  604. currentItem.mFontSize = defaulItem.mFontSize;
  605. FontVm.GetCurrentFontFamily(currentItem.mFontFamily.ToString(), currentItem.mFontFamily.ToString());
  606. FontVm.GetCurrentFontSize(currentItem.mFontSize);
  607. FontVm.GetFontWeights_Style(currentItem.mFontStyle, currentItem.mFontWeight);
  608. FontVm.CurrentPresetFont = new ComboDataItem(defaulItem.mTag, defaulItem.mTagContent);
  609. SelectedPresetFont();
  610. //更改后 保存到本地缓存
  611. TextFont.SavePresetFontList(FontVm.PresetFontList);
  612. }
  613. }
  614. }
  615. }
  616. private void DateFormatChanged()
  617. {
  618. if (CurrrentDateFormat != null)
  619. {
  620. if (IsCheckedTime)
  621. UpdateDateFormatLists();
  622. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.NoteText, CurrrentDateFormat.Content);
  623. }
  624. }
  625. private void ShowTimeCheckedChnaged()
  626. {
  627. if (CurrrentDateFormat != null)
  628. {
  629. UpdateDateFormatLists();
  630. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.NoteText, CurrrentDateFormat.Content);
  631. }
  632. }
  633. public bool IsNavigationTarget(NavigationContext navigationContext)
  634. {
  635. return true;
  636. }
  637. public void OnNavigatedFrom(NavigationContext navigationContext)
  638. {
  639. BasicVm.IsMultiSelected = false;
  640. // IsCheckedTime = false;
  641. }
  642. public void OnNavigatedTo(NavigationContext navigationContext)
  643. {
  644. navigationContext.Parameters.TryGetValue<AnnotTransfer>(ParameterNames.PropertyPanelContentViewModel, out PropertyPanel);
  645. if (PropertyPanel != null)
  646. {
  647. AnnotEvent = PropertyPanel.AnnotEvent;
  648. Annot = PropertyPanel.annot as FreeTextAnnotArgs;
  649. LoadPropertyHandler?.Invoke(this, Annot);
  650. BasicVm.AnnotType = PropertyPanel.annot.EventType;
  651. BasicVm.AnnotTypeTitle = App.MainPageLoader.GetString("FreeText_Title");
  652. BasicVm.IsMultiSelected = PropertyPanel.IsMultiSelected;
  653. IsFillFreeTextAnnot = PropertyPanel.IsTextFill;
  654. if (BasicVm.IsMultiSelected)
  655. {
  656. IsAttributeEquals();
  657. BasicVm.IsSolidLine = BasicVm.IsDashLine = false;
  658. }
  659. else
  660. {
  661. GetAnnotProperty();
  662. }
  663. IsFillFreeTextAnnot = PropertyPanel.IsTextFill;
  664. }
  665. }
  666. /// <summary>
  667. /// 多选的注释
  668. /// </summary>
  669. private List<FreeTextAnnotArgs> ConvertLists()
  670. {
  671. List<FreeTextAnnotArgs> FreeTextLists = new List<FreeTextAnnotArgs>();
  672. foreach (var item in PropertyPanel.annotlists)
  673. {
  674. var itemFreeText = item as FreeTextAnnotArgs;
  675. if (itemFreeText != null)
  676. {
  677. FreeTextLists.Add(itemFreeText);
  678. }
  679. }
  680. if (FreeTextLists.Count != PropertyPanel.annotlists.Count)
  681. return null;
  682. else
  683. return FreeTextLists;
  684. }
  685. private void IsAttributeEquals()
  686. {
  687. var list = ConvertLists();
  688. if (list != null)
  689. {
  690. var temp = list[0];
  691. Dictionary<string, bool> isNoEqualsDir = new Dictionary<string, bool>();
  692. isNoEqualsDir.Add("FontFamily", false);
  693. isNoEqualsDir.Add("FontSize", false);
  694. isNoEqualsDir.Add("FontStyleFontWeight", false);
  695. isNoEqualsDir.Add("FontColor", false);
  696. isNoEqualsDir.Add("FillColor", false);
  697. isNoEqualsDir.Add("TextAglin", false);
  698. foreach (var item in list)
  699. {
  700. //if (item == list[0])
  701. // continue;
  702. //if (temp.Align != item.Align)
  703. //{
  704. // isNoEqualsDir["TextAglin"] = true;
  705. // FontVm.StrTextAlign = "None";
  706. //}
  707. //if (temp.FontFamily.ToString() != item.FontFamily.ToString())
  708. //{
  709. // isNoEqualsDir["FontFamily"] = true;
  710. // //FontVm.CurrentFontFamily = null;
  711. //}
  712. //if (temp.FontSize != item.FontSize)
  713. //{
  714. // isNoEqualsDir["FontSize"] = true;
  715. // FontVm.CurrentFontSize = null;
  716. //}
  717. //if (temp.FontStyle != item.FontStyle || temp.FontWeight != item.FontWeight)
  718. //{
  719. // isNoEqualsDir["FontStyleFontWeight"] = true;
  720. // FontVm.CurrrentFontWeightStyle = null;
  721. //}
  722. //if (isNoEqualsDir["FontFamily"] == true || isNoEqualsDir["FontSize"] == true || isNoEqualsDir["FontStyleFontWeight"] == true)
  723. //{
  724. // FontVm.CurrentPresetFont = null;
  725. //}
  726. if (isNoEqualsDir["FontColor"] == false)
  727. {
  728. 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)
  729. {
  730. FontVm.FontColor = new SolidColorBrush(Color.FromArgb(0x01, 0xff, 0xff, 0xff));
  731. isNoEqualsDir["FontColor"] = true;
  732. }
  733. }
  734. if (isNoEqualsDir["FillColor"] == false)
  735. {
  736. 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)
  737. {
  738. BasicVm.FillColor = new SolidColorBrush(Color.FromArgb(0x01, 0xff, 0xff, 0xff));
  739. isNoEqualsDir["FillColor"] = true;
  740. }
  741. }
  742. }
  743. ////以下是多选注释的属性相等时
  744. //if (isNoEqualsDir["TextAglin"] == false)
  745. // {
  746. GetAnnotAlign(temp.Align);
  747. //}
  748. //if (isNoEqualsDir["FontFamily"] == false)
  749. //{
  750. FontVm.GetCurrentFontFamily(temp.FontName, temp.FontName);
  751. // }
  752. // if (isNoEqualsDir["FontSize"] == false)
  753. //{
  754. FontVm.GetCurrentFontSize((int)temp.FontSize);
  755. //}
  756. //if (isNoEqualsDir["FontStyleFontWeight"] == false)
  757. //{
  758. FontVm.GetFontWeights_Style(temp.IsItalic ? FontStyles.Italic : FontStyles.Normal, temp.IsBold ? FontWeights.Bold : FontWeights.Normal);
  759. //}
  760. if (isNoEqualsDir["FontColor"] == false)
  761. {
  762. FontVm.FontColor = new SolidColorBrush(temp.FontColor);
  763. }
  764. if (isNoEqualsDir["FillColor"] == false)
  765. {
  766. FontVm.FontColor = new SolidColorBrush(temp.BgColor);
  767. }
  768. }
  769. }
  770. private void GetAnnotProperty()
  771. {
  772. BasicVm.FillColor = new SolidColorBrush(Annot.BgColor);
  773. BasicVm.FillOpacity = Annot.Transparency;
  774. FontVm.FontColor = new SolidColorBrush(Annot.FontColor);
  775. bool isExist = FontVm.GetCurrentPresetFont(Annot);
  776. if (isExist == false)
  777. {
  778. FontVm.CurrentPresetFont = new ComboDataItem("Custom", "Custom");
  779. FontVm.GetCurrentFontSize((int)Annot.FontSize);
  780. FontVm.GetCurrentFontFamily(Annot.FontName, Annot.FontName);
  781. FontVm.GetFontWeights_Style(Annot.IsItalic ? FontStyles.Italic : FontStyles.Normal, Annot.IsBold ? FontWeights.Bold : FontWeights.Normal);
  782. }
  783. else
  784. {
  785. if (FontVm.CurrentPresetFont != null)
  786. {
  787. var itemComboxItem = FontVm.CurrentPresetFont;
  788. var item = FontVm.PresetFontList.FirstOrDefault(temp => temp.mTag == itemComboxItem.ValueStr);
  789. if (item != null)
  790. {
  791. if (item.mTag != "Custom")
  792. {
  793. FontVm.GetCurrentFontSize(item.mFontSize);
  794. if (item.mFontFamily != null)
  795. {
  796. FontVm.GetCurrentFontFamily(item.mFontFamily.ToString(), item.mFontFamily.ToString());
  797. }
  798. FontVm.GetFontWeights_Style(item.mFontStyle, item.mFontWeight);
  799. }
  800. }
  801. }
  802. }
  803. GetTimeFormat();
  804. GetAnnotAlign(Annot.Align);
  805. }
  806. //填写与签名
  807. private void GetTimeFormat()
  808. {
  809. if (IsFillFreeTextAnnot == false)
  810. return;
  811. if (string.IsNullOrEmpty(Annot.TextContent))
  812. {
  813. if (CurrrentDateFormat != null)
  814. {
  815. if (IsCheckedTime)
  816. UpdateDateFormatLists();
  817. PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.NoteText, CurrrentDateFormat.Content);
  818. }
  819. return;
  820. }
  821. DateTime dtDate;
  822. bool isTime = false;
  823. foreach (var item in DateFormatItems)
  824. {
  825. var strFormat = "";
  826. var strArr = Annot.TextContent.Split(' ');
  827. if (strArr != null && strArr.Count() == 2)
  828. {
  829. strFormat = item.ValueStr + " HH:mm:ss";
  830. }
  831. else
  832. {
  833. strFormat = item.ValueStr;
  834. }
  835. if (DateTime.TryParseExact(Annot.TextContent, strFormat, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AdjustToUniversal, out dtDate))
  836. {
  837. if (strArr != null && strArr.Count() == 2)
  838. {
  839. isTime = true;
  840. }
  841. foreach (var item2 in DateFormatItems)
  842. {
  843. string stadate = System.DateTime.Now.ToString(strFormat);
  844. item.SetContent(stadate);
  845. }
  846. CurrrentDateFormat = new ComboDataItem(item.ValueStr, item.Content);
  847. break;
  848. }
  849. }
  850. IsCheckedTime = isTime;
  851. }
  852. //文本内容对齐
  853. private void GetAnnotAlign(TextAlignment align)
  854. {
  855. switch (align)
  856. {
  857. case TextAlignment.Left:
  858. FontVm.StrTextAlign = "Left";
  859. break;
  860. case TextAlignment.Center:
  861. FontVm.StrTextAlign = "Center";
  862. break;
  863. case TextAlignment.Right:
  864. FontVm.StrTextAlign = "Right";
  865. break;
  866. case TextAlignment.Justify:
  867. FontVm.StrTextAlign = "Justify";
  868. break;
  869. default:
  870. FontVm.StrTextAlign = "None";
  871. break;
  872. }
  873. }
  874. }
  875. }