|
@@ -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)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|