|
@@ -4,6 +4,8 @@ import { parseAdobePDFTimestamp, convertToPDFTimestamp, roundToDecimalPlaces, co
|
|
|
import { AnnotationType, WidgetType, LineTypeString, StampType, StampTypeString, TextStampShapeString, ActionTypeString, WidgetTypeString, AnnotationFlags, BorderStyleInt, BorderStyleString, ALIGN, ALIGNMAP } from '../../constants'
|
|
|
|
|
|
let ComPDFKitJS = {}
|
|
|
+ComPDFKitJS.opened_Font = []
|
|
|
+ComPDFKitJS.opened_FontNames = []
|
|
|
let DataArray = []
|
|
|
let LineType = {}
|
|
|
let BorderStyle = {}
|
|
@@ -78,11 +80,36 @@ class CPDFWorker {
|
|
|
messageHandler.on('LoadFile', (data) => {
|
|
|
ComPDFKitJS.opened_files = []
|
|
|
ComPDFKitJS.opened_files[0] = data.buffer
|
|
|
- return true
|
|
|
+
|
|
|
+ let reader = new FileReader()
|
|
|
+ reader.onload = async (e) => {
|
|
|
+ let buf = new Uint8Array(e.target.result)
|
|
|
+ console.log(9999)
|
|
|
+ ComPDFKitJS.opened_Font[0] = buf
|
|
|
+ ComPDFKitJS.opened_FontNames[0] = data.fontName
|
|
|
+ }
|
|
|
+ if (!data.fontFile) return true
|
|
|
+
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ const fileReader = new FileReader()
|
|
|
+ fileReader.onload = () => {
|
|
|
+ const buf = new Uint8Array(fileReader.result)
|
|
|
+
|
|
|
+ ComPDFKitJS.opened_Font[0] = buf
|
|
|
+ ComPDFKitJS.opened_FontNames[0] = data.fontName
|
|
|
+
|
|
|
+ resolve(true)
|
|
|
+ }
|
|
|
+ fileReader.onerror = () => {
|
|
|
+ reject(fileReader.error)
|
|
|
+ }
|
|
|
+ fileReader.readAsArrayBuffer(data.fontFile)
|
|
|
+ })
|
|
|
})
|
|
|
|
|
|
messageHandler.on('LoadDocumentByStream', (data) => {
|
|
|
const { doc, fileId, length, password: rawPassword } = data
|
|
|
+
|
|
|
const password = stringToNewUTF8(rawPassword)
|
|
|
return Module._LoadDocumentByStream(doc, fileId, length, password)
|
|
|
})
|
|
@@ -984,21 +1011,9 @@ class CPDFWorker {
|
|
|
})
|
|
|
|
|
|
messageHandler.on('SetFontCallBackForEditPage', (data) => {
|
|
|
- const { editPagePtr, file } = data
|
|
|
+ const { editPagePtr } = data
|
|
|
|
|
|
- let reader = new FileReader()
|
|
|
- reader.onload = async (e) => {
|
|
|
- let buf = new Uint8Array(e.target.result)
|
|
|
- ComPDFKitJS.opened_Font = []
|
|
|
- ComPDFKitJS.opened_FontNames = []
|
|
|
- let cur_file_id = 0
|
|
|
- cur_file_id = ComPDFKitJS.opened_Font.length
|
|
|
- ComPDFKitJS.opened_Font[cur_file_id] = buf
|
|
|
- ComPDFKitJS.opened_FontNames[cur_file_id] = 'DroidSansFallbackFull'
|
|
|
-
|
|
|
- Module._SetFontCallBackForEditPage(editPagePtr)
|
|
|
- }
|
|
|
- reader.readAsArrayBuffer(file)
|
|
|
+ Module._SetFontCallBackForEditPage(editPagePtr)
|
|
|
})
|
|
|
}
|
|
|
|
|
@@ -1052,7 +1067,7 @@ function createAnnotation(doc, pagePtr, annotation) {
|
|
|
|
|
|
const annotPtr = Module._CreateAnnot(doc, pagePtr, typeInt)
|
|
|
|
|
|
- const { color, lineWidth, content, createDate, transparency, fillTransparency, rect } = annotation
|
|
|
+ const { color, lineWidth, content, date, transparency, fillTransparency, rect } = annotation
|
|
|
if (color) {
|
|
|
setAnnotRGBColor({
|
|
|
annotPtr,
|
|
@@ -1067,10 +1082,10 @@ function createAnnotation(doc, pagePtr, annotation) {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- if (createDate) {
|
|
|
+ if (date) {
|
|
|
setAnnotCreationDate({
|
|
|
annotPtr,
|
|
|
- createDate
|
|
|
+ date
|
|
|
})
|
|
|
}
|
|
|
|
|
@@ -1097,11 +1112,15 @@ function createAnnotation(doc, pagePtr, annotation) {
|
|
|
}
|
|
|
switch (typeInt) {
|
|
|
case AnnotationType.TEXT:
|
|
|
+ setAnnotRGBColor({
|
|
|
+ annotPtr,
|
|
|
+ color: annotation.textColor
|
|
|
+ })
|
|
|
break
|
|
|
case AnnotationType.LINK:
|
|
|
break
|
|
|
case AnnotationType.FREETEXT:
|
|
|
- const { bgColor, fontName, fontSize, textAlignment } = annotation
|
|
|
+ const { bgColor, fontName, fontSize, textAlignment, textColor } = annotation
|
|
|
if (bgColor) {
|
|
|
Module._SetFreeTextBgColor(annotPtr, bgColor.R / 255, bgColor.G / 255, bgColor.B / 255)
|
|
|
} else {
|
|
@@ -1112,7 +1131,7 @@ function createAnnotation(doc, pagePtr, annotation) {
|
|
|
annotPtr,
|
|
|
fontName,
|
|
|
fontSize,
|
|
|
- color,
|
|
|
+ textColor,
|
|
|
textAlignment,
|
|
|
content
|
|
|
})
|
|
@@ -1127,10 +1146,12 @@ function createAnnotation(doc, pagePtr, annotation) {
|
|
|
case AnnotationType.CIRCLE:
|
|
|
createShape({
|
|
|
annotPtr,
|
|
|
- color,
|
|
|
lineWidth,
|
|
|
- transparency,
|
|
|
- fillTransparency
|
|
|
+ })
|
|
|
+
|
|
|
+ setAnnotRGBColor({
|
|
|
+ annotPtr,
|
|
|
+ color: annotation.borderColor
|
|
|
})
|
|
|
break
|
|
|
case AnnotationType.HIGHLIGHT:
|
|
@@ -1188,15 +1209,15 @@ function createAnnotation(doc, pagePtr, annotation) {
|
|
|
}
|
|
|
|
|
|
function createWidget(doc, pagePtr, annotation) {
|
|
|
- const { type, createDate, fieldName, backgroundColor, checkStyle, rect } = annotation
|
|
|
+ const { type, date, fieldName, backgroundColor, checkStyle, rect } = annotation
|
|
|
|
|
|
const typeInt = WidgetType[type.toUpperCase()]
|
|
|
const annotPtr = Module._CreateWidget(doc, pagePtr, typeInt)
|
|
|
|
|
|
- if (createDate) {
|
|
|
+ if (date) {
|
|
|
setAnnotCreationDate({
|
|
|
annotPtr,
|
|
|
- createDate
|
|
|
+ date
|
|
|
})
|
|
|
}
|
|
|
|
|
@@ -1432,8 +1453,8 @@ function getAnnotation({
|
|
|
}
|
|
|
|
|
|
Module._GetAnnotCreationDate(annotPtr)
|
|
|
- const rawCreateDate = U8StringData
|
|
|
- const createDate = parseAdobePDFTimestamp(rawCreateDate)
|
|
|
+ const rawDate = U8StringData
|
|
|
+ const date = parseAdobePDFTimestamp(rawDate)
|
|
|
Module._GetAnnotContent(annotPtr)
|
|
|
const content = U8StringData
|
|
|
Module._GetAnnotTitle(annotPtr)
|
|
@@ -1442,7 +1463,7 @@ function getAnnotation({
|
|
|
const transparency = roundToDecimalPlaces(Module._GetAnnotTransparency(annotPtr))
|
|
|
|
|
|
const annotation = {
|
|
|
- createDate,
|
|
|
+ date,
|
|
|
content,
|
|
|
rect,
|
|
|
transparency
|
|
@@ -1459,7 +1480,7 @@ function getAnnotation({
|
|
|
if (hasColor) {
|
|
|
const { R, G, B } = RGBColor
|
|
|
const hex = convertCppRGBToHex(R, G, B)
|
|
|
- annotation.color = hex
|
|
|
+ annotation.textColor = hex
|
|
|
}
|
|
|
|
|
|
return annotation
|
|
@@ -1497,7 +1518,7 @@ function getAnnotation({
|
|
|
|
|
|
const { R, G, B } = FontDa
|
|
|
const hex = convertCppRGBToHex(R, G, B)
|
|
|
- annotation.color = hex
|
|
|
+ annotation.textColor = hex
|
|
|
|
|
|
Module._GetFreeTextContent(annotPtr)
|
|
|
const freetextContent = U8StringData
|
|
@@ -1528,7 +1549,7 @@ function getAnnotation({
|
|
|
const { R, G, B } = RGBColor
|
|
|
const hex = convertCppRGBToHex(R, G, B)
|
|
|
|
|
|
- annotation.color = hex
|
|
|
+ annotation.borderColor = hex
|
|
|
}
|
|
|
|
|
|
annotation.lineWidth = Module._GetAnnotBorderWidth(annotPtr)
|
|
@@ -1545,7 +1566,7 @@ function getAnnotation({
|
|
|
const { R, G, B } = RGBColor
|
|
|
const hex = convertCppRGBToHex(R, G, B)
|
|
|
|
|
|
- annotation.color = hex
|
|
|
+ annotation.borderColor = hex
|
|
|
}
|
|
|
|
|
|
RGBColor = {}
|
|
@@ -1625,15 +1646,15 @@ function getWidgetAnnotation({
|
|
|
}
|
|
|
|
|
|
Module._GetAnnotCreationDate(annotPtr)
|
|
|
- const rawCreateDate = U8StringData
|
|
|
- const createDate = parseAdobePDFTimestamp(rawCreateDate)
|
|
|
+ const rawDate = U8StringData
|
|
|
+ const date = parseAdobePDFTimestamp(rawDate)
|
|
|
Module._GetAnnotContent(annotPtr)
|
|
|
const content = U8StringData
|
|
|
|
|
|
const type = Module._GetWidgetType(annotPtr)
|
|
|
|
|
|
const annotation = {
|
|
|
- createDate,
|
|
|
+ date,
|
|
|
content,
|
|
|
rect,
|
|
|
type: WidgetTypeString[type]
|
|
@@ -1919,10 +1940,10 @@ function exportXFDFByStream(doc) {
|
|
|
}
|
|
|
|
|
|
function setAnnotCreationDate(data) {
|
|
|
- const { annotPtr, createDate: rawCreateDate } = data
|
|
|
+ const { annotPtr, date: rawDate } = data
|
|
|
|
|
|
- const createDate = stringToNewUTF8(convertToPDFTimestamp(rawCreateDate))
|
|
|
- Module._SetAnnotCreationDate(annotPtr, createDate)
|
|
|
+ const date = stringToNewUTF8(convertToPDFTimestamp(rawDate))
|
|
|
+ Module._SetAnnotCreationDate(annotPtr, date)
|
|
|
}
|
|
|
|
|
|
function setAnnotRect(data) {
|
|
@@ -2196,12 +2217,14 @@ function createMarkup(data) {
|
|
|
}
|
|
|
|
|
|
function setFreeText(data) {
|
|
|
- const { annotPtr, fontName: rawFontName, fontSize, color, textAlignment, content: rawContent } = data
|
|
|
+ const { annotPtr, fontName: rawFontName, fontSize, textColor: rawTextColor, textAlignment, content: rawContent } = data
|
|
|
|
|
|
const fontName = stringToNewUTF8(rawFontName)
|
|
|
const content = stringToNewUTF8(rawContent)
|
|
|
|
|
|
- Module._SetFreeText(annotPtr, fontName, fontSize, color.R / 255, color.G / 255, color.B / 255, textAlignment, content)
|
|
|
+ const textColor = convertColorToCppFormat(rawTextColor)
|
|
|
+
|
|
|
+ Module._SetFreeText(annotPtr, fontName, fontSize, textColor.R / 255, textColor.G / 255, textColor.B / 255, textAlignment, content)
|
|
|
}
|
|
|
|
|
|
function createShape(data) {
|
|
@@ -2220,12 +2243,12 @@ function createStandardStamp(data) {
|
|
|
}
|
|
|
|
|
|
function createTextStamp(data) {
|
|
|
- const { annotPtr, content: rawContent, date: rawDate, stampShape, stampColor } = data
|
|
|
+ const { annotPtr, content: rawContent, time: rawTime, stampShape, stampColor } = data
|
|
|
|
|
|
const content = stringToNewUTF8(rawContent)
|
|
|
- const date = stringToNewUTF8(rawDate)
|
|
|
+ const time = stringToNewUTF8(rawTime)
|
|
|
|
|
|
- Module._SetTextStamp(annotPtr, content, date, stampShape, stampColor, 0)
|
|
|
+ Module._SetTextStamp(annotPtr, content, time, stampShape, stampColor, 0)
|
|
|
}
|
|
|
|
|
|
function createImageStamp(data) {
|