Browse Source

其他 - 文字编辑部分接入重构PDFViewer

liyuxuan 1 year ago
parent
commit
e0f51444ff

+ 39 - 23
Demo/Examples/Compdfkit_Tools/Edit/ContentEditCOntrol/ContentEditControl.xaml.cs

@@ -1,30 +1,22 @@
 using ComPDFKit.PDFDocument;
 using ComPDFKit.PDFPage;
 using ComPDFKit.PDFPage.Edit;
+using ComPDFKit.Tool;
 using Compdfkit_Tools.Edit;
+using Compdfkit_Tools.Helper;
 using ComPDFKitViewer;
-using ComPDFKitViewer.PdfViewer;
 using Microsoft.Win32;
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Diagnostics;
 using System.Drawing;
-using System.Linq;
 using System.Runtime.CompilerServices;
-using System.Text;
-using System.Threading.Tasks;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Controls.Primitives;
-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;
-using Compdfkit_Tools.Helper;
 
 namespace Compdfkit_Tools.PDFControl
 {
@@ -37,8 +29,8 @@ namespace Compdfkit_Tools.PDFControl
 
         private double[] zoomLevelList = { 1f, 8f, 12f, 25, 33f, 50, 66f, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
 
-        private PDFEditEvent pdfTextCreateParam;
-        private PDFEditEvent lastPDFEditEvent = null;
+        private TextEditParam pdfTextCreateParam;
+        private PDFEditParam lastPDFEditEvent = null;
         private PanelState panelState = PanelState.GetInstance();
 
         private KeyEventHandler KeyDownHandler;
@@ -50,10 +42,20 @@ namespace Compdfkit_Tools.PDFControl
         {
             get
             {
-                if (PdfViewControl != null && PdfViewControl.PDFView != null)
+                try
                 {
-                    return PdfViewControl.PDFView.UndoManager.CanUndo;
+                    if (PdfViewControl != null && PdfViewControl.PDFViewTool != null)
+                    {
+                        CPDFViewerTool viewerTool = PdfViewControl.PDFViewTool;
+                        CPDFViewer pdfViewer = viewerTool.GetCPDFViewer();
+                        return pdfViewer.UndoManager.CanUndo;
+                    }
                 }
+                catch(Exception ex)
+                {
+
+                }
+                
                 return false;
             }
         }
@@ -62,9 +64,18 @@ namespace Compdfkit_Tools.PDFControl
         {
             get
             {
-                if (PdfViewControl != null && PdfViewControl.PDFView != null)
+                try
                 {
-                    return PdfViewControl.PDFView.UndoManager.CanRedo;
+                    if (PdfViewControl != null && PdfViewControl.PDFViewTool != null)
+                    {
+                        CPDFViewerTool viewerTool = PdfViewControl.PDFViewTool;
+                        CPDFViewer pdfViewer = viewerTool.GetCPDFViewer();
+                        return pdfViewer.UndoManager.CanRedo;
+                    }
+                }
+                catch (Exception ex)
+                {
+
                 }
 
                 return false;
@@ -75,9 +86,18 @@ namespace Compdfkit_Tools.PDFControl
         {
             get
             {
-                if (PdfViewControl != null && PdfViewControl.PDFView != null)
+                try
+                {
+                    if (PdfViewControl != null && PdfViewControl.PDFViewTool != null)
+                    {
+                        CPDFViewerTool viewerTool = PdfViewControl.PDFViewTool;
+                        CPDFViewer pdfViewer = viewerTool.GetCPDFViewer();
+                        return (pdfViewer.UndoManager.CanUndo | pdfViewer.UndoManager.CanRedo);
+                    }
+                }
+                catch (Exception ex)
                 {
-                    return PdfViewControl.PDFView.UndoManager.CanSave;
+
                 }
 
                 return false;
@@ -286,17 +306,13 @@ namespace Compdfkit_Tools.PDFControl
             PDFGrid.Child = PdfViewControl;
             FloatPageTool.InitWithPDFViewer(pdfViewer);
             pdfContentEditControl.InitWithPDFViewer(pdfViewer);
-            PdfViewControl.PDFView.PDFEditActiveHandler -= PDFView_PDFEditActiveHandler; 
-            PdfViewControl.PDFView.PDFEditActiveHandler += PDFView_PDFEditActiveHandler;
-            PdfViewControl.PDFView.UndoManager.PropertyChanged -= UndoManager_PropertyChanged;
-            PdfViewControl.PDFView.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
             DataContext = this;
         }
 
         /// <summary>
         /// Text and Image Selected Event
         /// </summary>
-        private void PDFView_PDFEditActiveHandler(object sender, ComPDFKitViewer.PDFEditEvent e)
+        private void PDFView_PDFEditActiveHandler(object sender, PDFEditEvent e)
         {
             lastPDFEditEvent = e; 
 

+ 153 - 69
Demo/Examples/Compdfkit_Tools/Edit/PDFImageEdit/PDFImageEditControl/PDFImageEditControl.xaml.cs

@@ -1,23 +1,26 @@
-using ComPDFKitViewer.PdfViewer;
+using ComPDFKit.PDFDocument;
+using ComPDFKit.PDFPage;
+using ComPDFKit.PDFPage.Edit;
+using ComPDFKit.Tool;
+using ComPDFKit.Tool.UndoManger;
 using ComPDFKitViewer;
+using Microsoft.Win32;
 using System;
 using System.Collections.Generic;
-using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Media.Imaging;
-using ComPDFKit.PDFPage;
-using System.Windows.Controls.Primitives;
-using Microsoft.Win32;
 using System.Diagnostics;
 using System.Drawing;
 using System.IO;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Controls.Primitives;
+using System.Windows.Media;
 
 namespace Compdfkit_Tools.Edit
 {
     public partial class PDFImageEditControl : UserControl
     {
-        public CPDFViewer PDFView { get; private set; }
-        public PDFEditEvent EditEvent { get; set; }
+        public CPDFViewerTool ToolView { get; set; }
+        public ImageEditParam EditEvent { get; set; }
 
         public PDFImageEditControl()
         {
@@ -32,12 +35,12 @@ namespace Compdfkit_Tools.Edit
             FlipUI.FlipChanged -= FlipUI_FlipChanged;
         }
 
-        public void InitWithPDFViewer(CPDFViewer newPDFView)
+        public void InitWithPDFViewer(CPDFViewerTool newPDFView)
         {
-            PDFView = newPDFView;
+            ToolView = newPDFView;
         }
 
-        public void SetPDFImageEditData(PDFEditEvent newEvent)
+        public void SetPDFImageEditData(ImageEditParam newEvent)
         {
             EditEvent = null;
             if (newEvent != null && newEvent.EditType == CPDFEditType.EditImage)
@@ -56,29 +59,51 @@ namespace Compdfkit_Tools.Edit
 
         private void FlipUI_FlipChanged(object sender, bool e)
         {
-            if (EditEvent != null)
+            GetImageArea(out CPDFEditImageArea imageArea, out CPDFPage pdfPage, out CPDFEditPage editPage);
+            if (imageArea != null)
             {
-                if(e)
+                bool result = false;
+                if (e)
                 {
-                    EditEvent.VerticalMirror = true;
+                    result = imageArea.VerticalMirror();
                 }
                 else
                 {
-                    EditEvent.HorizontalMirror = true;
+                    result = imageArea.HorizontalMirror();
+                }
+                if (result)
+                {
+                    PDFEditHistory editHistory = new PDFEditHistory();
+                    editHistory.EditPage = editPage;
+                    if (pdfPage != null)
+                    {
+                        editHistory.PageIndex = pdfPage.PageIndex;
+                    }
+
+                    ToolView.GetCPDFViewer()?.UndoManager.AddHistory(editHistory);
                 }
-              
-                EditEvent.UpdatePDFEditByEventArgs();
+
                 SetImageThumb();
             }
         }
 
         private void RotateUI_RotationChanged(object sender, double e)
         {
-            if (EditEvent != null)
+            GetImageArea(out CPDFEditImageArea imageArea, out CPDFPage pdfPage, out CPDFEditPage editPage);
+            if (imageArea != null)
             {
-                EditEvent.Rotate = (int)e;
-                EditEvent.UpdatePDFEditByEventArgs();
-                SetImageThumb();
+                if (imageArea.Rotate((float)e))
+                {
+                    PDFEditHistory editHistory = new PDFEditHistory();
+                    editHistory.EditPage = editPage;
+                    if (pdfPage != null)
+                    {
+                        editHistory.PageIndex = pdfPage.PageIndex;
+                    }
+
+                    ToolView.GetCPDFViewer()?.UndoManager.AddHistory(editHistory);
+                    SetImageThumb();
+                }
             }
         }
 
@@ -98,11 +123,21 @@ namespace Compdfkit_Tools.Edit
             {
                 slider.Tag = "true";
             }
-            if (EditEvent != null)
+            GetImageArea(out CPDFEditImageArea imageArea, out CPDFPage pdfPage, out CPDFEditPage editPage);
+            if (imageArea != null)
             {
-                EditEvent.Transparency = (int)(ImasgeOpacitySlider.Value * 255);
-                EditEvent.UpdatePDFEditByEventArgs();
-                SetImageThumb();
+                if (imageArea.SetImageTransparency((byte)(ImasgeOpacitySlider.Value * 255)))
+                {
+                    PDFEditHistory editHistory = new PDFEditHistory();
+                    editHistory.EditPage = editPage;
+                    if (pdfPage != null)
+                    {
+                        editHistory.PageIndex = pdfPage.PageIndex;
+                    }
+
+                    ToolView.GetCPDFViewer()?.UndoManager.AddHistory(editHistory);
+                    SetImageThumb();
+                }
             }
         }
 
@@ -118,12 +153,21 @@ namespace Compdfkit_Tools.Edit
             {
                 return;
             }
-
-            if (EditEvent != null)
+            GetImageArea(out CPDFEditImageArea imageArea, out CPDFPage pdfPage, out CPDFEditPage editPage);
+            if (imageArea != null)
             {
-                EditEvent.Transparency = (int)(ImasgeOpacitySlider.Value * 255);
-                EditEvent.UpdatePDFEditByEventArgs();
-                SetImageThumb();
+                if (imageArea.SetImageTransparency((byte)(ImasgeOpacitySlider.Value * 255)))
+                {
+                    PDFEditHistory editHistory = new PDFEditHistory();
+                    editHistory.EditPage = editPage;
+                    if (pdfPage != null)
+                    {
+                        editHistory.PageIndex = pdfPage.PageIndex;
+                    }
+
+                    ToolView.GetCPDFViewer()?.UndoManager.AddHistory(editHistory);
+                    SetImageThumb();
+                }
             }
         }
 
@@ -135,19 +179,34 @@ namespace Compdfkit_Tools.Edit
                 openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
                 if (openFileDialog.ShowDialog() == true)
                 {
-                    EditEvent.ReplaceImagePath = openFileDialog.FileName;
-                    EditEvent.UpdatePDFEditByEventArgs();
-                    // EditEvent = null;
-                    SetImageThumb();
+                    GetImageArea(out CPDFEditImageArea imageArea, out CPDFPage pdfPage, out CPDFEditPage editPage);
+                    if (imageArea != null)
+                    {
+                        Rect imageRect= imageArea.GetClipRect();
+                        if (imageArea.ReplaceImageArea(imageRect,openFileDialog.FileName,string.Empty))
+                        {
+                            PDFEditHistory editHistory = new PDFEditHistory();
+                            editHistory.EditPage = editPage;
+                            if (pdfPage != null)
+                            {
+                                editHistory.PageIndex = pdfPage.PageIndex;
+                            }
+
+                            ToolView.GetCPDFViewer()?.UndoManager.AddHistory(editHistory);
+                            SetImageThumb();
+                        }
+                    }
                 }
             }
         }
 
         private void ImageExportBtn_Click(object sender, RoutedEventArgs e)
         {
-            if (PDFView != null)
+            if (ToolView != null)
             {
-                Dictionary<int, List<Bitmap>> imageDict = PDFView.GetSelectedImages();
+                //需要选中图片对象
+                // Dictionary<int, List<Bitmap>> imageDict = PDFView.GetSelectedImages();
+                Dictionary<int, List<Bitmap>> imageDict=new Dictionary<int, List<Bitmap>>();
                 if (imageDict != null && imageDict.Count > 0)
                 {
                     System.Windows.Forms.FolderBrowserDialog folderBrowser = new System.Windows.Forms.FolderBrowserDialog();
@@ -180,11 +239,7 @@ namespace Compdfkit_Tools.Edit
 
         private void ImageClipBtn_Click(object sender, RoutedEventArgs e)
         {
-            if (EditEvent != null)
-            {
-                EditEvent.ClipImage = true;
-                EditEvent.UpdatePDFEditByEventArgs();
-            }
+            
         }
 
         private void OpacityComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
@@ -202,34 +257,34 @@ namespace Compdfkit_Tools.Edit
 
         public void SetImageThumb()
         {
-            if (PDFView != null && EditEvent!=null)
-            {
-                try
-                {
-                    Dictionary<int, List<Bitmap>> imageDict = PDFView.GetSelectedImages();
-                    foreach (int pageIndex in imageDict.Keys)
-                    {
-                        List<Bitmap> imageList = imageDict[pageIndex];
-                        if (imageList.Count > 0)
-                        {
-                            Bitmap bitmapImage = imageList[0];
-                            MemoryStream memoryStream = new MemoryStream();
-
-                            bitmapImage.Save(memoryStream, bitmapImage.RawFormat);
-                            BitmapImage imageShow = new BitmapImage();
-                            imageShow.BeginInit();
-                            imageShow.StreamSource = memoryStream;
-                            imageShow.EndInit();
-                            ImageThumbUI.Source = imageShow;
-                            break;
-                        }
-                    } 
-                }
-                catch (Exception ex)
-                {
+            //if (PDFView != null && EditEvent!=null)
+            //{
+            //    try
+            //    {
+            //        Dictionary<int, List<Bitmap>> imageDict = PDFView.GetSelectedImages();
+            //        foreach (int pageIndex in imageDict.Keys)
+            //        {
+            //            List<Bitmap> imageList = imageDict[pageIndex];
+            //            if (imageList.Count > 0)
+            //            {
+            //                Bitmap bitmapImage = imageList[0];
+            //                MemoryStream memoryStream = new MemoryStream();
 
-                }
-            }
+            //                bitmapImage.Save(memoryStream, bitmapImage.RawFormat);
+            //                BitmapImage imageShow = new BitmapImage();
+            //                imageShow.BeginInit();
+            //                imageShow.StreamSource = memoryStream;
+            //                imageShow.EndInit();
+            //                ImageThumbUI.Source = imageShow;
+            //                break;
+            //            }
+            //        } 
+            //    }
+            //    catch (Exception ex)
+            //    {
+
+            //    }
+            //}
         }
 
         public void SetImageTransparency(double transparency)
@@ -237,5 +292,34 @@ namespace Compdfkit_Tools.Edit
             ImasgeOpacitySlider.Value = transparency / 255D;
             OpacityTextBox.Text = string.Format("{0}%", (int)(Math.Round(ImasgeOpacitySlider.Value * 100)));
         }
+
+        private void GetImageArea(out CPDFEditImageArea imageArea,out CPDFPage pdfPage, out CPDFEditPage editPage)
+        {
+            imageArea = null;
+            editPage = null;
+            pdfPage=null;
+            if (ToolView == null || EditEvent == null)
+            {
+                return;
+            }
+
+            try
+            {
+                CPDFViewer pdfViewer = ToolView.GetCPDFViewer();
+                CPDFDocument pdfDoc = pdfViewer.GetDocument();
+                pdfPage = pdfDoc.PageAtIndex(EditEvent.PageIndex);
+                editPage = pdfPage.GetEditPage();
+                List<CPDFEditArea> editAreas = editPage.GetEditAreaList();
+                if (editAreas != null && editAreas.Count > EditEvent.EditIndex)
+                {
+                    imageArea = editAreas[EditEvent.EditIndex] as CPDFEditImageArea;
+                }
+            }
+            catch (Exception ex)
+            {
+
+            }
+        }
+
     }
 }

+ 209 - 49
Demo/Examples/Compdfkit_Tools/Edit/PDFTextEdit/PDFTextEditControl/PDFTextEditControl.xaml.cs

@@ -1,54 +1,69 @@
-using ComPDFKit.PDFPage;
+using ComPDFKit.PDFDocument;
+using ComPDFKit.PDFPage;
 using ComPDFKit.PDFPage.Edit;
+using ComPDFKit.Tool;
+using ComPDFKit.Tool.UndoManger;
 using ComPDFKitViewer;
-using ComPDFKitViewer.PdfViewer;
 using System;
+using System.Collections.Generic;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Controls.Primitives;
 using System.Windows.Media;
-
 namespace Compdfkit_Tools.Edit
 {
     public partial class PDFTextEditControl : UserControl
     {
-        public CPDFViewer PDFView { get; private set; }
-        public PDFEditEvent EditEvent { get; set; }
+        public CPDFViewerTool ToolView { get; private set; }
+        public TextEditParam EditEvent { get; set; }
         public PDFTextEditControl()
         {
             InitializeComponent();
             Loaded += PDFTextEditControl_Loaded;
         }
 
-        public void InitWithPDFViewer(CPDFViewer newPDFView)
+        public void InitWithPDFViewer(CPDFViewerTool newPDFView)
         {
-            PDFView = newPDFView;
+            ToolView = newPDFView;
         }
 
-        public void SetPDFTextEditData(PDFEditEvent newEvent)
+        public void SetPDFTextEditData(TextEditParam newEvent)
         {
             EditEvent = null;
             if (newEvent != null && newEvent.EditType == CPDFEditType.EditText)
             {
-                if (newEvent.SystemFontNameList != null && newEvent.SystemFontNameList.Count == 0)
+                GetTextArea(out CPDFEditTextArea textArea, out CPDFPage pdfPage, out CPDFEditPage editPage);
+                List<string> sysfontList = new List<string>();
+                if (textArea != null)
+                {
+                  sysfontList=  textArea.GetFontList();
+                }
+                if (sysfontList.Count == 0)
                 {
-                    newEvent.SystemFontNameList.Add("Helvetica");
-                    newEvent.SystemFontNameList.Add("Courier New");
-                    newEvent.SystemFontNameList.Add("Times New Roman");
+                    sysfontList.Add("Helvetica");
+                    sysfontList.Add("Courier New");
+                    sysfontList.Add("Times New Roman");
                 }
-                if (newEvent.SystemFontNameList.Contains(newEvent.FontName) == false && string.IsNullOrEmpty(newEvent.FontName) == false)
+                if (sysfontList.Contains(newEvent.FontName) == false && string.IsNullOrEmpty(newEvent.FontName) == false)
                 {
-                    newEvent.SystemFontNameList.Add(newEvent.FontName);
+                    sysfontList.Add(newEvent.FontName);
                 }
 
-                TextStyleUI.SetFontNames(newEvent.SystemFontNameList);
+                TextStyleUI.SetFontNames(sysfontList);
                 TextStyleUI.SelectFontName(newEvent.FontName);
                 TextStyleUI.SetFontStyle(newEvent.IsBold, newEvent.IsItalic);
                 TextStyleUI.SetFontSize(newEvent.FontSize);
                 OpacityTextBox.Text = string.Format("{0}%", (int)(Math.Ceiling(newEvent.Transparency * 100 / 255D)));
                 FontOpacitySlider.Value = ((int)(Math.Ceiling(newEvent.Transparency * 100 / 255D))) / 100D;
                 TextAlignUI.SetFontAlign(newEvent.TextAlign);
-                FontColorUI.SetCheckedForColor(newEvent.FontColor);
+                if(newEvent.FontColor != null && newEvent.FontColor.Length==3)
+                {
+                    FontColorUI.SetCheckedForColor(Color.FromRgb(
+                        newEvent.FontColor[0],
+                        newEvent.FontColor[1],
+                        newEvent.FontColor[2]));
+                }
+               
             }
             EditEvent = newEvent;
         }
@@ -60,10 +75,22 @@ namespace Compdfkit_Tools.Edit
             {
                 slider.Tag = "true";
             }
-            if (EditEvent != null)
+            GetTextArea(out CPDFEditTextArea textArea, out CPDFPage pdfPage, out CPDFEditPage editPage);
+            if (textArea != null)
             {
-                EditEvent.FontSize = slider.Value;
-                EditEvent.UpdatePDFEditByEventArgs();
+                Rect oldRect=textArea.GetFrame();
+                if (textArea.SetCharsFontSize((float)slider.Value,false))
+                {
+                    PDFEditHistory editHistory = new PDFEditHistory();
+                    editHistory.EditPage = editPage;
+                    if (pdfPage != null)
+                    {
+                        editHistory.PageIndex = pdfPage.PageIndex;
+                    }
+
+                    ToolView.GetCPDFViewer()?.UndoManager.AddHistory(editHistory);
+                    ToolView.UpDataRender(oldRect, textArea);
+                }
             }
         }
 
@@ -74,10 +101,21 @@ namespace Compdfkit_Tools.Edit
             {
                 slider.Tag = "true";
             }
-            if (EditEvent != null)
+            GetTextArea(out CPDFEditTextArea textArea, out CPDFPage pdfPage, out CPDFEditPage editPage);
+            if (textArea != null)
             {
-                EditEvent.Transparency = (int)(FontOpacitySlider.Value * 255);
-                EditEvent.UpdatePDFEditByEventArgs();
+                Rect oldRect=textArea.GetFrame();
+                if(textArea.SetCharsFontTransparency((byte)(FontOpacitySlider.Value * 255)))
+                {
+                    PDFEditHistory editHistory = new PDFEditHistory();
+                    editHistory.EditPage = editPage;
+                    if (pdfPage != null)
+                    {
+                        editHistory.PageIndex = pdfPage.PageIndex;
+                    }
+                    ToolView.GetCPDFViewer()?.UndoManager.AddHistory(editHistory);
+                    ToolView.UpDataRender(oldRect, textArea);
+                }
             }
         }
 
@@ -93,11 +131,21 @@ namespace Compdfkit_Tools.Edit
             {
                 return;
             }
-
-            if (EditEvent != null)
+            GetTextArea(out CPDFEditTextArea textArea, out CPDFPage pdfPage, out CPDFEditPage editPage);
+            if (textArea != null)
             {
-                EditEvent.Transparency = (int)(FontOpacitySlider.Value * 255);
-                EditEvent.UpdatePDFEditByEventArgs();
+                Rect oldRect=textArea.GetFrame();
+                if (textArea.SetCharsFontTransparency((byte)(FontOpacitySlider.Value * 255)))
+                {
+                    PDFEditHistory editHistory = new PDFEditHistory();
+                    editHistory.EditPage = editPage;
+                    if (pdfPage != null)
+                    {
+                        editHistory.PageIndex = pdfPage.PageIndex;
+                    }
+                    ToolView.GetCPDFViewer()?.UndoManager.AddHistory(editHistory);
+                    ToolView.UpDataRender(oldRect, textArea);
+                }
             }
         }
 
@@ -118,10 +166,21 @@ namespace Compdfkit_Tools.Edit
                 return;
             }
 
-            if (EditEvent != null)
+            GetTextArea(out CPDFEditTextArea textArea, out CPDFPage pdfPage, out CPDFEditPage editPage);
+            if (textArea != null)
             {
-                EditEvent.FontSize = slider.Value;
-                EditEvent.UpdatePDFEditByEventArgs();
+                Rect oldRect=textArea.GetFrame();
+                if (textArea.SetCharsFontSize((float)slider.Value,false))
+                {
+                    PDFEditHistory editHistory = new PDFEditHistory();
+                    editHistory.EditPage = editPage;
+                    if (pdfPage != null)
+                    {
+                        editHistory.PageIndex = pdfPage.PageIndex;
+                    }
+                    ToolView.GetCPDFViewer()?.UndoManager.AddHistory(editHistory);
+                    ToolView.UpDataRender(oldRect, textArea);
+                }
             }
         }
 
@@ -145,59 +204,131 @@ namespace Compdfkit_Tools.Edit
 
         private void TextStyleUI_TextSizeChanged(object sender, double e)
         {
-            if (EditEvent != null)
+            GetTextArea(out CPDFEditTextArea textArea, out CPDFPage pdfPage, out CPDFEditPage editPage);
+            if (textArea != null)
             {
-                EditEvent.FontSize = e;
-                EditEvent.UpdatePDFEditByEventArgs();
+                Rect oldRect=textArea.GetFrame();
+                if (textArea.SetCharsFontSize((float)e, false))
+                {
+                    PDFEditHistory editHistory = new PDFEditHistory();
+                    editHistory.EditPage = editPage;
+                    if (pdfPage != null)
+                    {
+                        editHistory.PageIndex = pdfPage.PageIndex;
+                    }
+                    ToolView.GetCPDFViewer()?.UndoManager.AddHistory(editHistory);
+                    ToolView.UpDataRender(oldRect, textArea);
+                }
             }
         }
 
         private void FontColorUI_ColorChanged(object sender, EventArgs e)
         {
-            if (EditEvent != null)
+            SolidColorBrush newBrush = FontColorUI.Brush as SolidColorBrush;
+            GetTextArea(out CPDFEditTextArea textArea, out CPDFPage pdfPage, out CPDFEditPage editPage);
+            if (textArea != null && newBrush!=null)
             {
-                SolidColorBrush newBrush = FontColorUI.Brush as SolidColorBrush;
-                if (newBrush != null)
+                Rect oldRect= textArea.GetFrame();
+                if (textArea.SetCharsFontColor(newBrush.Color.R, newBrush.Color.G, newBrush.Color.B))
                 {
-                    EditEvent.FontColor = newBrush.Color;
-                    EditEvent.UpdatePDFEditByEventArgs();
+                    PDFEditHistory editHistory = new PDFEditHistory();
+                    editHistory.EditPage = editPage;
+                    if (pdfPage != null)
+                    {
+                        editHistory.PageIndex = pdfPage.PageIndex;
+                    }
+                    ToolView.GetCPDFViewer()?.UndoManager.AddHistory(editHistory);
+                    ToolView.UpDataRender(oldRect, textArea);
                 }
             }
         }
 
         private void TextAlignUI_TextAlignChanged(object sender, TextAlignType e)
         {
-            if (EditEvent != null)
+            GetTextArea(out CPDFEditTextArea textArea, out CPDFPage pdfPage, out CPDFEditPage editPage);
+            if (textArea != null)
             {
-                EditEvent.TextAlign = e;
-                EditEvent.UpdatePDFEditByEventArgs();
+                bool result = false;
+                Rect oldRect= textArea.GetFrame();
+                if(textArea.SelectLineRects!=null && textArea.SelectLineRects.Count>0)
+                {
+                    result = textArea.SetTextRangeAlign(e);
+                }
+                else
+                {
+                    result= textArea.SetTextAreaAlign(e);
+                }
+                if (result)
+                {
+                    PDFEditHistory editHistory = new PDFEditHistory();
+                    editHistory.EditPage = editPage;
+                    if (pdfPage != null)
+                    {
+                        editHistory.PageIndex = pdfPage.PageIndex;
+                    }
+                    ToolView.GetCPDFViewer()?.UndoManager.AddHistory(editHistory);
+                    ToolView.UpDataRender(oldRect, textArea);
+                }
             }
         }
 
         private void TextStyleUI_TextItalicChanged(object sender, bool e)
         {
-            if (EditEvent != null)
+            GetTextArea(out CPDFEditTextArea textArea, out CPDFPage pdfPage, out CPDFEditPage editPage);
+            if (textArea != null)
             {
-                EditEvent.IsItalic = e;
-                EditEvent.UpdatePDFEditByEventArgs();
+                Rect oldRect= textArea.GetFrame();
+                if(textArea.SetCharsFontItalic(e))
+                {
+                    PDFEditHistory editHistory = new PDFEditHistory();
+                    editHistory.EditPage = editPage;
+                    if (pdfPage != null)
+                    {
+                        editHistory.PageIndex = pdfPage.PageIndex;
+                    }
+                    ToolView.GetCPDFViewer()?.UndoManager.AddHistory(editHistory);
+                    ToolView.UpDataRender(oldRect, textArea);
+                }
             }
         }
 
         private void TextStyleUI_TextBoldChanged(object sender, bool e)
         {
-            if (EditEvent != null)
+            GetTextArea(out CPDFEditTextArea textArea, out CPDFPage pdfPage, out CPDFEditPage editPage);
+            if (textArea != null)
             {
-                EditEvent.IsBold = e;
-                EditEvent.UpdatePDFEditByEventArgs();
+                Rect oldRect= textArea.GetFrame();
+                if (textArea.SetCharsFontBold(e))
+                {
+                    PDFEditHistory editHistory = new PDFEditHistory();
+                    editHistory.EditPage = editPage;
+                    if (pdfPage != null)
+                    {
+                        editHistory.PageIndex = pdfPage.PageIndex;
+                    }
+                    ToolView.GetCPDFViewer()?.UndoManager.AddHistory(editHistory);
+                    ToolView.UpDataRender(oldRect, textArea);
+                }
             }
         }
 
         private void TextStyleUI_TextFontChanged(object sender, string e)
         {
-            if (EditEvent != null)
+            GetTextArea(out CPDFEditTextArea textArea, out CPDFPage pdfPage, out CPDFEditPage editPage);
+            if (textArea != null)
             {
-                EditEvent.FontName = e;
-                EditEvent.UpdatePDFEditByEventArgs();
+                Rect oldRect= textArea.GetFrame();
+                if (textArea.SetCharsFontName(e))
+                {
+                    PDFEditHistory editHistory = new PDFEditHistory();
+                    editHistory.EditPage = editPage;
+                    if (pdfPage != null)
+                    {
+                        editHistory.PageIndex = pdfPage.PageIndex;
+                    }
+                    ToolView.GetCPDFViewer()?.UndoManager.AddHistory(editHistory);
+                    ToolView.UpDataRender(oldRect, textArea);
+                }
             }
         }
 
@@ -213,5 +344,34 @@ namespace Compdfkit_Tools.Edit
                 }
             }
         }
+
+        private void GetTextArea(out CPDFEditTextArea textArea, out CPDFPage pdfPage, out CPDFEditPage editPage)
+        {
+            textArea = null;
+            editPage = null;
+            pdfPage = null;
+            if (ToolView == null || EditEvent == null)
+            {
+                return;
+            }
+
+            try
+            {
+                CPDFViewer pdfViewer = ToolView.GetCPDFViewer();
+                CPDFDocument pdfDoc = pdfViewer.GetDocument();
+                pdfPage = pdfDoc.PageAtIndex(EditEvent.PageIndex);
+                editPage = pdfPage.GetEditPage();
+                List<CPDFEditArea> editAreas = editPage.GetEditAreaList();
+                if (editAreas != null && editAreas.Count > EditEvent.EditIndex)
+                {
+                    textArea = editAreas[EditEvent.EditIndex] as CPDFEditTextArea;
+                }
+            }
+            catch (Exception ex)
+            {
+
+            }
+        }
+
     }
 }