123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482 |
- using ComPDFKitViewer;
- using ComPDFKitViewer.AnnotEvent;
- using PDF_Office.CustomControl.CompositeControl;
- using PDF_Office.Model;
- using PDF_Office.Model.PropertyPanel.AnnotPanel;
- using PDF_Office.ViewModels.Tools;
- using Prism.Commands;
- using Prism.Mvvm;
- using Prism.Regions;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media;
- namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
- {
- public class FreetextAnnotPropertyViewModel : BindableBase, INavigationAware
- {
- private double fillOpacity = 1;
- public double FillOpacity
- {
- get { return fillOpacity; }
- set
- {
- SetProperty(ref fillOpacity, value);
- }
- }
- private Brush selectColor = new SolidColorBrush(Colors.Black);
- public Brush SelectColor
- {
- get { return selectColor; }
- set
- {
- SetProperty(ref selectColor, value);
- AnnotEvent?.UpdateAttrib(AnnotAttrib.FontColor, (selectColor as SolidColorBrush).Color);
- AnnotEvent?.UpdateAnnot();
- }
- }
- private Brush fillColor = new SolidColorBrush(Colors.Transparent);
- public Brush FillColor
- {
- get { return fillColor; }
- set
- {
- SetProperty(ref fillColor, value);
- AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, (fillColor as SolidColorBrush).Color);
- AnnotEvent?.UpdateAnnot();
- }
- }
- private FontFamily fontFamily = new FontFamily("Courier");
- public FontFamily TextFontFamily
- {
- get { return fontFamily; }
- set
- {
- SetProperty(ref fontFamily, value);
- }
- }
- private FontWeight fontWeights = FontWeights.Normal;
- public FontWeight TextFontWeights
- {
- get { return fontWeights; }
- set
- {
- SetProperty(ref fontWeights, value);
- }
- }
- private FontStyle fontStyle = FontStyles.Normal;
- public FontStyle TextFontStyle
- {
- get { return fontStyle; }
- set
- {
- SetProperty(ref fontStyle, value);
- }
- }
- private int fontSize = 24;
- public int TextFontSize
- {
- get { return fontSize; }
- set
- {
- SetProperty(ref fontSize, value);
- }
- }
- private List<FontStyleItem> fontStyleList = new List<FontStyleItem>();
- public List<FontStyleItem> FontStyleList
- {
- get { return fontStyleList; }
- set
- {
- SetProperty(ref fontStyleList, value);
- }
- }
- private ComboDataItem _presetTextData;
- public ComboDataItem PresetTextData
- {
- get { return _presetTextData; }
- set
- {
- SetProperty(ref _presetTextData, value);
- if (_presetTextData != null && FontStyleList != null)
- {
- }
- }
- }
- private ComboDataItem _fontSizeData = new ComboDataItem(6);
- public ComboDataItem FontSizeData
- {
- get { return _fontSizeData; }
- set
- {
- SetProperty(ref _fontSizeData, value);
- }
- }
- private ComboDataItem _fontFamilyData;
- public ComboDataItem FontFamilyData
- {
- get { return _fontFamilyData; }
- set
- {
- SetProperty(ref _fontFamilyData, value);
- }
- }
- private FontStyle _fontStyle;
- public FontStyle FontStyleItem
- {
- get { return _fontStyle; }
- set { SetProperty(ref _fontStyle, value); }
- }
- private FontWeight _fontWeight;
- public FontWeight FontWeightItem
- {
- get { return _fontWeight; }
- set { SetProperty(ref _fontWeight, value); }
- }
- private ComboDataItem _fontWeightStyleItem;
- public ComboDataItem FontWeightStyleItem
- {
- get { return _fontWeightStyleItem; }
- set
- {
- SetProperty(ref _fontWeightStyleItem, value);
- if (_fontWeightStyleItem.ValueStr != null && string.IsNullOrEmpty((string)_fontWeightStyleItem.ValueStr) == false)
- {
- switch ((string)_fontWeightStyleItem.ValueStr)
- {
- case "Regular":
- FontStyleItem = FontStyles.Normal;
- FontWeightItem = FontWeights.Normal;
- break;
- case "Bold":
- FontStyleItem = FontStyles.Normal;
- FontWeightItem = FontWeights.Bold;
- break;
- case "Italic":
- FontStyleItem = FontStyles.Italic;
- FontWeightItem = FontWeights.Normal;
- break;
- case "Bold Italic":
- FontStyleItem = FontStyles.Italic;
- FontWeightItem = FontWeights.Bold;
- break;
- }
-
- }
- }
- }
- public List<ComboDataItem> PresetTextItems { get; private set; }
- public List<ComboDataItem> FontFamilyItems { get; private set; }
- public List<ComboDataItem> FontStyleItems { get; private set; }
- public DelegateCommand<object> SelectedFillOpacityCommand { get; set; }
- public DelegateCommand<object> SelectedFontStyleCommand { get; set; }
- public DelegateCommand<object> SelectedColorCommand { get; set; }
- public DelegateCommand<object> SelectedFillColorCommand { get; set; }
- public DelegateCommand<object> FontFamilyChangedCommand { get; set; }
- public DelegateCommand<object> FontStyleChangedCommand { get; set; }
- public DelegateCommand<object> FontSizeChangedCommand { get; set; }
- public DelegateCommand<object> TextAlignCheckedCommand { get; set; }
- public DelegateCommand<object> LineModeCheckedCommand { get; set; }
-
- public event EventHandler<object> LoadPropertyHandler;
- public FreetextAnnotPropertyViewModel()
- {
- SelectedFillOpacityCommand = new DelegateCommand<object>(SelectedFillOpacity);
- SelectedFontStyleCommand = new DelegateCommand<object>(SelectedFontStyle);
- SelectedColorCommand = new DelegateCommand<object>(SelectedColor_Command);
- SelectedFillColorCommand = new DelegateCommand<object>(SelectedFillColor_Command);
- FontFamilyChangedCommand = new DelegateCommand<object>(FontFamilyChanged_Command);
- FontStyleChangedCommand = new DelegateCommand<object>(FontStyleChanged_Command);
- FontSizeChangedCommand = new DelegateCommand<object>(FontSizeChanged_Command);
- TextAlignCheckedCommand = new DelegateCommand<object>(TextAlignChecked);
- LineModeCheckedCommand = new DelegateCommand<object>(LineMode_Checked);
- InitVariable();
- }
- private void InitVariable()
- {
- InitFontStyles();
- InitFontFamilyComboBox();
- InitFontStyleComboBox();
- }
- private void InitFontFamilyComboBox()
- {
- FontFamilyItems = TextFont.GetFamily();
- }
- private void InitFontStyleComboBox()
- {
- FontStyleItems = TextFont.GetFontStyle();
- }
- private void InitFontStyles()
- {
- PresetTextItems = new List<ComboDataItem>();
- FontStyleList = TextFont.GetPresetFontStyle();
- foreach (var item in FontStyleList)
- {
- ComboDataItem itemData = new ComboDataItem(item.mTag, item.mTagContent);
- PresetTextItems.Add(itemData);
- }
- }
- private void TextAlignChecked(object obj)
- {
- if ((string)obj != null /*&& TextEditEvent != null*/)
- {
- switch ((string)obj)
- {
- case "AlignLeft":
- AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Left);
- break;
- case "AlignCenter":
- AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Center);
- break;
- case "AlignRight":
- AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Right);
- break;
- case "Align":
- break;
- }
- AnnotEvent?.UpdateAnnot();
- }
- }
- private void LineMode_Checked(object obj)
- {
- if(obj != null)
- {
- var tag = ((string)obj);
- switch (tag)
- {
- case "Dashed":
- AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, DashStyles.Dash);
- break;
- case "Solid":
- AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, DashStyles.Solid);
- break;
- }
- AnnotEvent?.UpdateAnnot();
- }
- }
-
- private void SelectedFontStyle(object obj)
- {
- if (obj != null && (FontStyleItem)obj != null)
- {
- var item = (FontStyleItem)obj;
- AnnotEvent?.UpdateAttrib(AnnotAttrib.FontSize, item.mFontSize);
- AnnotEvent?.UpdateAnnot();
- }
- }
- private void SelectedFillOpacity(object obj)
- {
- if (obj != null)
- {
- FillOpacity = (double)obj;
- SelectColor.Opacity = FillOpacity;
- AnnotEvent?.UpdateAttrib(AnnotAttrib.Transparency, FillOpacity);
- AnnotEvent?.UpdateAnnot();
- }
- }
- private void FontSizeChanged_Command(object obj)
- {
- if (obj != null)
- {
- var item = (ComboBoxItem)obj;
- var content = (string)item.Content;
- if (content != null)
- {
- var intData = int.Parse(content);
- TextFontSize = intData;
- AnnotEvent?.UpdateAttrib(AnnotAttrib.FontSize, intData);
-
- AnnotEvent?.UpdateAnnot();
- }
- }
- }
- private void FontStyleChanged_Command(object obj)
- {
- if (obj != null)
- {
- var item = (ComboBoxItem)obj;
- var content = (string)item.Content;
- if (content != null)
- {
- if (content == "Regular")
- {
- AnnotEvent?.UpdateAttrib(AnnotAttrib.FontStyle, FontStyles.Normal);
- AnnotEvent?.UpdateAttrib(AnnotAttrib.FontWeight, FontWeights.Normal);
- TextFontWeights = FontWeights.Normal;
- TextFontStyle = FontStyles.Normal;
- }
- if (content == "Bold")
- {
- AnnotEvent?.UpdateAttrib(AnnotAttrib.FontStyle, FontStyles.Normal);
- AnnotEvent?.UpdateAttrib(AnnotAttrib.FontWeight, FontWeights.Bold);
- TextFontWeights = FontWeights.Bold;
- TextFontStyle = FontStyles.Normal;
- }
- if (content == "Italic")
- {
- AnnotEvent?.UpdateAttrib(AnnotAttrib.FontStyle, FontStyles.Italic);
- AnnotEvent?.UpdateAttrib(AnnotAttrib.FontWeight, FontWeights.Normal);
- TextFontWeights = FontWeights.Normal;
- TextFontStyle = FontStyles.Italic;
- }
- if (content == "Bold Italic")
- {
- AnnotEvent?.UpdateAttrib(AnnotAttrib.FontStyle, FontStyles.Italic);
- AnnotEvent?.UpdateAttrib(AnnotAttrib.FontWeight, FontWeights.Bold);
- TextFontWeights = FontWeights.Bold;
- TextFontStyle = FontStyles.Italic;
- }
- AnnotEvent?.UpdateAnnot();
- }
- }
- }
- private void FontFamilyChanged_Command(object obj)
- {
- if (obj != null)
- {
- if ((int)obj > -1)
- {
- if ((int)obj == 0)
- {
- AnnotEvent?.UpdateAttrib(AnnotAttrib.FontFamily, new FontFamily("Courier"));
- TextFontFamily = new FontFamily("Courier");
- }
-
- if ((int)obj == 1)
- {
- TextFontFamily = new FontFamily("Helvetica");
- AnnotEvent?.UpdateAttrib(AnnotAttrib.FontFamily, new FontFamily("Helvetica"));
- }
-
- if ((int)obj == 2)
- {
- TextFontFamily = new FontFamily("Times");
- AnnotEvent?.UpdateAttrib(AnnotAttrib.FontFamily, new FontFamily("Times"));
- }
-
- AnnotEvent?.UpdateAnnot();
- }
- }
- }
- private void SelectedFillColor_Command(object obj)
- {
- if (obj != null)
- {
- var colorValue = (Color)obj;
- if (colorValue != null)
- {
- FillColor = new SolidColorBrush(colorValue);
- FillColor.Opacity = FillOpacity;
- Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
- changeData[AnnotArgsType.AnnotFreehand] = obj;
- PropertyPanel.DataChangedInvoke(this, changeData);
- }
- }
- }
- private void SelectedColor_Command(object obj)
- {
- if (obj != null)
- {
- var colorValue = (Color)obj;
- if (colorValue != null)
- {
- SelectColor = new SolidColorBrush(colorValue);
- SelectColor.Opacity = FillOpacity;
- Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
- changeData[AnnotArgsType.AnnotFreehand] = obj;
- PropertyPanel.DataChangedInvoke(this, changeData);
- }
- }
- }
- public bool IsNavigationTarget(NavigationContext navigationContext)
- {
- return true;
- }
- public void OnNavigatedFrom(NavigationContext navigationContext)
- {
- }
- public AnnotAttribEvent AnnotEvent { get; set; }
- private FreeTextAnnotArgs Annot;
- private AnnotPropertyPanel PropertyPanel;
- public void OnNavigatedTo(NavigationContext navigationContext)
- {
- navigationContext.Parameters.TryGetValue<AnnotPropertyPanel>(ParameterNames.PropertyPanelContentViewModel, out PropertyPanel);
- if (PropertyPanel != null)
- {
- AnnotEvent = PropertyPanel.AnnotEvent;
- Annot = PropertyPanel.annot as FreeTextAnnotArgs;
- LoadPropertyHandler?.Invoke(this, Annot);
- }
- }
- }
- }
|