Browse Source

add: Annotation 添加

liutian 3 months ago
parent
commit
190b3e31c5

+ 47 - 0
packages/core/src/utils.ts

@@ -37,6 +37,53 @@ function scrollIntoView(element: HTMLDivElement, spot: {
   parent.scrollTop = offsetY;
 }
 
+export function convertAdobeDate(timestamp: string) {
+  if (timestamp) {
+    const year = parseInt(timestamp.substring(2, 6), 10)
+    const month = parseInt(timestamp.substring(6, 8), 10) - 1
+    const day = parseInt(timestamp.substring(8, 10), 10)
+    const hours = parseInt(timestamp.substring(10, 12), 10)
+    const minutes = parseInt(timestamp.substring(12, 14), 10)
+    const seconds = parseInt(timestamp.substring(14, 16), 10)
+    const date = new Date(Date.UTC(year, month, day, hours, minutes, seconds, 0))
+    const timezone = timestamp.substring(16)
+    if (7 === timezone.length) {
+      let offset: string | number = timezone.substring(0, 1);
+      if ("Z" !== offset) {
+        offset = "-" === offset ? 1 : -1;
+        const offsetMinutes = parseInt(timezone.substring(4, 6), 10);
+        date.setUTCHours(date.getUTCHours() + offset * parseInt(timezone.substring(1, 3), 10))
+        date.setUTCMinutes(date.getUTCMinutes() + offset * offsetMinutes)
+      }
+    }
+    return date
+  }
+}
+
+function padZero(str: string) {
+  return 2 > str.length ? "0" + str : str
+}
+
+export function toAdobeDate(date: Date) {
+  if (!date) return
+  var timeString = "D:" + date.getFullYear().toString()
+  timeString += padZero((date.getMonth() + 1).toString())
+  timeString += padZero(date.getDate().toString())
+  timeString += padZero(date.getHours().toString())
+  timeString += padZero(date.getMinutes().toString())
+  timeString += padZero(date.getSeconds().toString())
+  let offset  = date.getTimezoneOffset()
+  if (0 === offset) {
+    timeString += "Z00'00'"
+  } else {
+    0 > offset ? (timeString += "+", offset *= -1) : timeString += "-"
+    var qa = offset % 60
+    timeString += padZero(parseInt((offset / 60).toString(), 10).toString()) + "'"
+    timeString += padZero(qa.toString()) + "'"
+  }
+  return timeString
+}
+
 export {
   scrollIntoView
 }

+ 46 - 0
packages/core/src/worker/annotations/AnnotationManager.ts

@@ -0,0 +1,46 @@
+class AnnotationManager {
+    constructor() {
+      this.annotations = [];
+    }
+    addAnnotation(annotation) {
+      this.annotations.push(annotation);
+    }
+    addAnnotations(annotation) {
+      this.annotations.push(annotation);
+    }
+    getAnnotationById() {
+      return this.annotations.find(annotation => annotation.Id === id);
+    }
+    canModify(annotation) {
+      return !annotation.ReadOnly;
+    }
+    canModifyContents(annotation) {
+      return !annotation.ReadOnly;
+    }
+    createAnnotationReply(annotation, ) {
+      return annotation;
+    }
+    deleteAnnotation(annotation) {
+      if (!Array.isArray(annotation)) {
+        annotation = [annotation];
+      }
+      this.deleteAnnotations(annotation);
+    }
+    deleteAnnotations(annotations) {
+      const annotationList = this.anntations
+      annotations.forEach(annotation => {
+        const index = annotationList.findIndex(item => item.Id === annotation.Id);
+        if (index > -1) {
+          const annotPtr = annotationList[index].annotPtr
+          Module._RemoveAnnot(annotPtr)
+          annotationList.splice(index, 1)
+        }
+      })
+    }
+    getAnnotationsList() {
+      return this.annotations;
+    }
+    clearAnnotations() {
+      this.annotations = [];
+    }
+}

+ 39 - 5
packages/core/src/worker/annotations/annotation.ts

@@ -1,15 +1,49 @@
 import { uuid } from 'uuidv4'
+import { convertAdobeDate } from '../utils'
 
 class Annotation {
-  id: string;
-  pageNumber: number;
+  annotPtr: number;
+  Author: string;
+  Color: string;
+  DateModified: string;
+  Height: number;
+  Hidden: boolean = false;
+  Id: string;
+  InReplyTo: string;
+  Invisible: boolean = false;
+  IsAdded: boolean = false;
+  IsClickableOutsideRect: boolean = false;
+  IsDeleted: boolean = false;
+  IsModified: boolean = false;
+  Listable: boolean = true;
+  NoDelete: boolean = false;
+  NoMove: boolean = false;
+  NoResize: boolean = false;
+  NoRotate: boolean = false;
+  NoView: boolean = false;
+  NoZoom: boolean = false;
+  PageNumber: number;
+  ReadOnly: boolean = false;
+  ReplyType: string;
+  Rotation: number = 0;
+  selectionModel: any;
+  Subject: string = 'Annotation';
+  Width: number;
+  X: number;
+  Y: number;
   constructor({
+    annotPtr,
     pageNumber,
+    creationDate,
   }: {
-    pageNumber: number
+    annotPtr: number,
+    pageNumber: number,
+    creationDate: string
   }) {
-    this.id = uuid()
-    this.pageNumber = pageNumber
+    this.annotPtr = annotPtr
+    this.Id = uuid()
+    this.PageNumber = pageNumber
+    this.DateModified = creationDate
   }
 }
 

+ 0 - 0
packages/core/src/worker/annotations/markup.ts