using ComPDFKitViewer; using ComPDFKitViewer.AnnotEvent; using PDF_Office.Properties; using PDFSettings; 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.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace PDF_Office.Views.PropertyPanel.AnnotPanel { /// /// TextAnnotProperty.xaml 的交互逻辑 /// public partial class TextAnnotProperty : UserControl { public TextAnnotProperty() { InitializeComponent(); } private void OpacitySlider_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e) { } private void OpacitySlider_DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e) { } private void OpacitySlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e) { } } //public partial class TextAnnotProperty : UserControl //{ // /// // /// 属性更改事件 // /// // public event EventHandler> DataChanged; // /// // /// 默认值设置事件 // /// // public event EventHandler DefaultStored; // public Color? SelectedColor { get { return ColorDropPicker.SelectedColor; } } // public string AnnotTitle { get { return AnnotTypeTitle.Text; } } // public string AnnoteNote { get { return AnnotNoteText.Text; } } // public double AnnotOpacity { get { return OpacitySlider.Value; } } // public AnnotArgsType AnnotType { get; private set; } // public AnnotAttribEvent AnnotEvent { get; set; } // private bool DisableValueChange = false; // public TextAnnotProperty() // { // InitializeComponent(); // SetLangText(); // string font = Settings.Default.AppProperties.Annotate.AnchoredFamaily; // if (font.Equals("Courier")) // AnnotNoteText.FontFamily = new FontFamily("Courier New"); // else if (font.Equals("Helvetica")) // AnnotNoteText.FontFamily = new FontFamily("Arial"); // else // AnnotNoteText.FontFamily = new FontFamily("Times New Roman"); // DataContext = this; // PathFigure FigureData = GetSquigglyPathFigure(new Point(0, 0), new Point(62, 0), 60, 2); // PathGeometry SquigglyGeometry = new PathGeometry(); // PathFigureCollection FiguresCollection = new PathFigureCollection(); // SquigglyGeometry.Figures = FiguresCollection; // FiguresCollection.Add(FigureData); // SquigglyPath.Data = SquigglyGeometry; // } // private void SetLangText() // { // //SampleText.Text = App.MainPageLoader.GetString("ProperPanel_Example"); // //colorText.Text = App.MainPageLoader.GetString("ProperPanel_Color"); // //opacityText.Text = App.MainPageLoader.GetString("ProperPanel_Opacity"); // //UseAsDefaultBtn.Content = App.MainPageLoader.GetString("ProperPanel_SetAsDefault"); // //NoteText.Text = App.MainPageLoader.GetString("ProperPanel_Note"); // } // private void SetTextDecoratePath(Color? selectColor, double? opacity) // { // UnderlinePath.Visibility = Visibility.Collapsed; // StrikeoutPath.Visibility = Visibility.Collapsed; // SquigglyPath.Visibility = Visibility.Collapsed; // UnderlinePath.Opacity = 1; // StrikeoutPath.Opacity = 1; // UnderlinePath.Opacity = 1; // switch (AnnotType) // { // case AnnotArgsType.AnnotHighlight: // if (selectColor != null) // { // SampleText.Background = new SolidColorBrush((Color)selectColor); // } // if (opacity != null) // { // SampleText.Background.Opacity = (double)opacity; // } // break; // case AnnotArgsType.AnnotUnderline: // UnderlinePath.Visibility = Visibility.Visible; // SampleText.Background = Brushes.Transparent; // if (opacity != null) // { // UnderlinePath.Opacity = (double)opacity; // } // if (selectColor != null) // { // UnderlinePath.Stroke = new SolidColorBrush((Color)selectColor); // } // break; // case AnnotArgsType.AnnotStrikeout: // StrikeoutPath.Visibility = Visibility.Visible; // SampleText.Background = Brushes.Transparent; // if (opacity != null) // { // StrikeoutPath.Opacity = (double)opacity; // } // if (selectColor != null) // { // StrikeoutPath.Stroke = new SolidColorBrush((Color)selectColor); // } // break; // case AnnotArgsType.AnnotSquiggly: // SquigglyPath.Visibility = Visibility.Visible; // SampleText.Background = Brushes.Transparent; // if (opacity != null) // { // SquigglyPath.Opacity = (double)opacity; // } // if (selectColor != null) // { // SquigglyPath.Stroke = new SolidColorBrush((Color)selectColor); // } // break; // case AnnotArgsType.AnnotSticky: // { // if (opacity != null) // { // StickyPath.Opacity = (double)opacity; // } // if (selectColor != null) // { // StickyPath.Fill = new SolidColorBrush((Color)selectColor); // } // } // break; // default: // break; // } // } // public void SetSelectedColor(Color selectColor) // { // bool changed = false; // if (ColorDropPicker.SelectedColor != selectColor) // { // changed = true; // } // ColorDropPicker.SetSelectedColor(selectColor); // SetTextDecoratePath(selectColor, null); // if (changed) // { // Dictionary changeData = new Dictionary(); // changeData[AnnotType] = selectColor; // DataChanged?.Invoke(this, changeData); // } // } // public void SetSelectOpacity(double opacity) // { // OpacitySlider.Value = opacity; // SetTextDecoratePath(null, opacity); // } // public void SetNoteContent(string textNote) // { // AnnotNoteText.Text = textNote; // } // public void SetAnnotType(AnnotArgsType annotType) // { // //AnnotType = annotType; // //switch (annotType) // //{ // // case AnnotArgsType.AnnotHighlight: // // AnnotTypeTitle.Text = App.MainPageLoader.GetString("SubTools_Tools_Highlight"); // // break; // // case AnnotArgsType.AnnotUnderline: // // AnnotTypeTitle.Text = App.MainPageLoader.GetString("SubTools_Tools_Underline"); // // break; // // case AnnotArgsType.AnnotStrikeout: // // AnnotTypeTitle.Text = App.MainPageLoader.GetString("SubTools_Tools_Strikthrough"); // // break; // // case AnnotArgsType.AnnotSquiggly: // // AnnotTypeTitle.Text = App.MainPageLoader.GetString("SubTools_Tools_Squiggly"); // // break; // // case AnnotArgsType.AnnotSticky: // // AnnotTypeTitle.Text = App.MainPageLoader.GetString("SubTools_Tools_AnchoredNote"); // // SampleText.Visibility = Visibility.Collapsed; // // StickyPath.Visibility = Visibility.Visible; // // break; // // default: // // break; // //} // } // private void ColorDropPicker_SelectedColorChanged(object sender, Color? e) // { // if (e != null && AnnotEvent != null) // { // AnnotEvent.UpdateAttrib(AnnotAttrib.Color, e); // AnnotEvent.UpdateAnnot(); // double? opacity = null; // if (OpacitySlider != null) // { // opacity = OpacitySlider.Value; // } // SetTextDecoratePath(e, opacity); // if (e != null) // { // Dictionary changeData = new Dictionary(); // changeData[AnnotType] = e; // DataChanged?.Invoke(this, changeData); // } // } // } // private void OpacitySlider_DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e) // { // DisableValueChange = false; // if (AnnotEvent != null) // { // AnnotEvent.UpdateAttrib(AnnotAttrib.Transparency, OpacitySlider.Value); // AnnotEvent.UpdateAnnot(); // SetTextDecoratePath(null, OpacitySlider.Value); // if (e != null) // { // Dictionary changeData = new Dictionary(); // changeData[AnnotType] = OpacitySlider.Value; // DataChanged?.Invoke(this, changeData); // } // } // } // private void OpacitySlider_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e) // { // DisableValueChange = true; // } // private void OpacitySlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e) // { // if (AnnotEvent != null && DisableValueChange == false) // { // AnnotEvent.UpdateAttrib(AnnotAttrib.Transparency, e.NewValue); // AnnotEvent.UpdateAnnot(); // SetTextDecoratePath(null, e.NewValue); // if (e != null) // { // Dictionary changeData = new Dictionary(); // changeData[AnnotType] = e.NewValue; // DataChanged?.Invoke(this, changeData); // } // } // } // private PathFigure GetSquigglyPathFigure(Point StartPoint, Point EndPoint, double PathWidth, double PathHeight) // { // PathFigure FigureData = new PathFigure(); // FigureData.StartPoint = StartPoint; // int Radius = (int)Math.Max(2, 2); // if (PathWidth > PathHeight) // { // // 橫線 // var arcCount = PathWidth / (Radius * 2); // var x = StartPoint.X; // if (EndPoint.X > StartPoint.X) // { // // left to right // for (int i = 0; i < arcCount; i++) // { // if (i % 2 == 0) // { // // 上弧 // FigureData.Segments.Add(new BezierSegment() // { // Point1 = new Point(x, StartPoint.Y), // Point2 = new Point(x + Radius, StartPoint.Y - Radius), // Point3 = new Point(x + Radius * 2, StartPoint.Y) // }); // } // else // { // // 下弧 // FigureData.Segments.Add(new BezierSegment() // { // Point1 = new Point(x, StartPoint.Y), // Point2 = new Point(x + Radius, StartPoint.Y + Radius), // Point3 = new Point(x + Radius * 2, StartPoint.Y) // }); // } // x += Radius * 2; // } // } // else // { // // right to left // for (int i = 0; i < arcCount; i++) // { // if (i % 2 == 0) // { // //下弧 // FigureData.Segments.Add(new BezierSegment() // { // Point1 = new Point(x, StartPoint.Y), // Point2 = new Point(x - Radius, StartPoint.Y + Radius), // Point3 = new Point(x - Radius * 2, StartPoint.Y) // }); // } // else // { // //上弧 // FigureData.Segments.Add(new BezierSegment() // { // Point1 = new Point(x, StartPoint.Y), // Point2 = new Point(x - Radius, StartPoint.Y - Radius), // Point3 = new Point(x - Radius * 2, StartPoint.Y) // }); // } // x -= Radius * 2; // } // } // } // else // { // // 直線 // var arcCount = PathHeight / (Radius * 2); // var y = StartPoint.Y; // if (EndPoint.Y > StartPoint.Y) // { // // up to down // for (int i = 0; i < arcCount; i++) // { // if (i % 2 == 0) // { // //右弧 // FigureData.Segments.Add(new BezierSegment() // { // Point1 = new Point(StartPoint.X, y), // Point2 = new Point(StartPoint.X + Radius, y + Radius), // Point3 = new Point(StartPoint.X, y + Radius * 2) // }); // } // else // { // //左弧 // FigureData.Segments.Add(new BezierSegment() // { // Point1 = new Point(StartPoint.X, y), // Point2 = new Point(StartPoint.X - Radius, y + Radius), // Point3 = new Point(StartPoint.X, y + Radius * 2) // }); // } // y += Radius * 2; // } // } // else // { // // down to up // for (int i = 0; i < arcCount; i++) // { // if (i % 2 == 0) // { // //左弧 // FigureData.Segments.Add(new BezierSegment() // { // Point1 = new Point(StartPoint.X, y), // Point2 = new Point(StartPoint.X - Radius, y - Radius), // Point3 = new Point(StartPoint.X, y - Radius * 2) // }); // } // else // { // //右弧 // FigureData.Segments.Add(new BezierSegment() // { // Point1 = new Point(StartPoint.X, y), // Point2 = new Point(StartPoint.X + Radius, y - Radius), // Point3 = new Point(StartPoint.X, y - Radius * 2) // }); // } // y -= Radius * 2; // } // } // } // return FigureData; // } // private void Button_StoreAsDefaultProperty(object sender, RoutedEventArgs e) // { // DefaultAnnotProperty defaultProperty = new DefaultAnnotProperty(); // defaultProperty.AnnotToolType = AnnotType; // defaultProperty.ForgoundColor = ColorDropPicker.SelectedColor == null ? Colors.Yellow : (Color)ColorDropPicker.SelectedColor; // defaultProperty.Opacity = OpacitySlider.Value; // Helper.SettingHelper.SetAnnotDefaultProperty(defaultProperty); // DefaultStored?.Invoke(this, null); // } // private void AnnotNoteText_LostFocus(object sender, RoutedEventArgs e) // { // AnnotEvent?.UpdateAttrib(AnnotAttrib.NoteText, AnnotNoteText.Text); // AnnotEvent?.UpdateAnnot(); // } // public void NoteFocus() // { // AnnotNoteText.Focus(); // } // private void OpacityItem_PreviewMouseDown(object sender, MouseButtonEventArgs e) // { // ComboBoxItem selectItem = sender as ComboBoxItem; // if (selectItem != null && selectItem.Content != null) // { // int opacity = -1; // if (int.TryParse(selectItem.Content.ToString().TrimEnd('%'), out opacity)) // { // OpacitySlider.Value = opacity / 100D; // } // } // } //} }