123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- using ComPDFKit.PDFAnnotation;
- using ComPDFKit.PDFPage;
- using ComPDFKit.Tool.Help;
- using ComPDFKit.Tool.SettingParam;
- using ComPDFKitViewer.Annot;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Media.Imaging;
- using System.Windows.Media;
- namespace ComPDFKit.Tool.UndoManger
- {
- public class SoundAnnotHistory : AnnotHistory
- {
- public override int GetAnnotIndex()
- {
- if (CurrentParam != null)
- {
- return CurrentParam.AnnotIndex;
- }
- return base.GetAnnotIndex();
- }
- public override int GetPageIndex()
- {
- if (CurrentParam != null)
- {
- return CurrentParam.PageIndex;
- }
- return base.GetPageIndex();
- }
- public override void SetAnnotIndex(int newIndex)
- {
- if (CurrentParam != null)
- {
- CurrentParam.AnnotIndex = newIndex;
- }
- if (PreviousParam != null)
- {
- PreviousParam.AnnotIndex = newIndex;
- }
- }
- internal override bool Add()
- {
- SoundParam currentParam = CurrentParam as SoundParam;
- if (currentParam == null || PDFDoc == null || !PDFDoc.IsValid())
- {
- return false;
- }
- CPDFPage pdfPage = PDFDoc.PageAtIndex(currentParam.PageIndex);
- CPDFSoundAnnotation soundAnnot = pdfPage?.CreateAnnot(C_ANNOTATION_TYPE.C_ANNOTATION_SOUND) as CPDFSoundAnnotation;
- if (soundAnnot != null)
- {
- int annotIndex = pdfPage.GetAnnotCount() - 1;
- soundAnnot.SetTransparency((byte)currentParam.Transparency);
- soundAnnot.SetRect(currentParam.ClientRect);
- byte[] imageData = null;
- int imageWidth = 0;
- int imageHeight = 0;
- PDFHelp.ImageStreamToByte(currentParam.ImageStream, ref imageData, ref imageWidth, ref imageHeight);
- if (imageData != null && imageWidth > 0 && imageHeight > 0)
- {
- if (!string.IsNullOrEmpty(currentParam.SoundFilePath))
- {
- soundAnnot.SetSoundPath(imageData, imageWidth, imageHeight, currentParam.SoundFilePath);
- }
- }
- if (!string.IsNullOrEmpty(currentParam.Author))
- {
- soundAnnot.SetAuthor(currentParam.Author);
- }
- if (!string.IsNullOrEmpty(currentParam.Content))
- {
- soundAnnot.SetContent(currentParam.Content);
- }
- soundAnnot.SetIsLocked(currentParam.Locked);
- soundAnnot.SetCreationDate(PDFHelp.GetCurrentPdfTime());
- soundAnnot.UpdateAp();
- soundAnnot.ReleaseAnnot();
- if (currentParam != null)
- {
- currentParam.AnnotIndex = annotIndex;
- }
- if (PreviousParam != null)
- {
- PreviousParam.AnnotIndex = annotIndex;
- }
- return true;
- }
- return false;
- }
- internal override bool Update(bool isUndo)
- {
- if (CurrentParam as SoundParam == null || PreviousParam as SoundParam == null)
- {
- return false;
- }
- if (MakeAnnotValid(CurrentParam))
- {
- CPDFSoundAnnotation circleAnnot = Annot as CPDFSoundAnnotation;
- if (circleAnnot == null || !circleAnnot.IsValid())
- {
- return false;
- }
- SoundParam updateParam = (isUndo ? PreviousParam : CurrentParam) as SoundParam;
- SoundParam checkParam = (isUndo ? CurrentParam : PreviousParam) as SoundParam;
- if (updateParam.Transparency != checkParam.Transparency)
- {
- circleAnnot.SetTransparency((byte)updateParam.Transparency);
- }
- if (!updateParam.ClientRect.Equals(checkParam.ClientRect))
- {
- circleAnnot.SetRect(updateParam.ClientRect);
- }
- if (updateParam.Author != checkParam.Author)
- {
- circleAnnot.SetAuthor(updateParam.Author);
- }
- if (updateParam.Content != checkParam.Content)
- {
- circleAnnot.SetContent(updateParam.Content);
- }
- if (updateParam.Locked != checkParam.Locked)
- {
- circleAnnot.SetIsLocked(updateParam.Locked);
- }
- circleAnnot.SetModifyDate(PDFHelp.GetCurrentPdfTime());
- //circleAnnot.UpdateAp();
- return true;
- }
- return false;
- }
- internal override bool Remove()
- {
- if (MakeAnnotValid(CurrentParam))
- {
- Annot.RemoveAnnot();
- return true;
- }
- return false;
- }
- }
- }
|