|
@@ -4,10 +4,13 @@ import { parseAdobePDFTimestamp, convertToPDFTimestamp, roundToDecimalPlaces, co
|
|
|
import { AnnotationType, WidgetType, LineTypeString, StampType, StampTypeString, TextStampShapeString, ActionTypeString, WidgetTypeString, AnnotationFlags, BorderStyleInt, BorderStyleString, ALIGN, ALIGNMAP } from '../../constants'
|
|
|
|
|
|
let ComPDFKitJS = {
|
|
|
- opened_Font: [],
|
|
|
- opened_FontNames: [],
|
|
|
opened_DefFont: [],
|
|
|
- opened_image: []
|
|
|
+ opened_Font: [],
|
|
|
+ opened_image: [],
|
|
|
+ ComPDFKitDownloadFont,
|
|
|
+ ComPDFKitDownloadFontA,
|
|
|
+ FontNameList: [],
|
|
|
+ FontCount: 3000
|
|
|
}
|
|
|
|
|
|
let DataArray = []
|
|
@@ -52,6 +55,13 @@ function hexToRGB(hexColor) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+function ComPDFKitDownloadFont(index){
|
|
|
+ return ComPDFKitJS.opened_Font[index];
|
|
|
+}
|
|
|
+function ComPDFKitDownloadFontA(index){
|
|
|
+ return ComPDFKitJS.opened_Font[index];
|
|
|
+}
|
|
|
+
|
|
|
class CPDFWorker {
|
|
|
static async setUp() {
|
|
|
const messageHandler = new MessageHandler('worker', 'main', self)
|
|
@@ -88,40 +98,32 @@ class CPDFWorker {
|
|
|
return error
|
|
|
})
|
|
|
|
|
|
- messageHandler.on('InitDocument', () => {
|
|
|
- const doc = Module._InitDocument()
|
|
|
-
|
|
|
- return doc
|
|
|
- })
|
|
|
-
|
|
|
- messageHandler.on('LoadFile', async (data) => {
|
|
|
- ComPDFKitJS.opened_files = []
|
|
|
- ComPDFKitJS.opened_files[0] = data.buffer
|
|
|
-
|
|
|
- if (!data.fontFile) return true
|
|
|
-
|
|
|
+ messageHandler.on('InitDocument', async (data) => {
|
|
|
+ const { fontJson } = data
|
|
|
await 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
|
|
|
-
|
|
|
- ComPDFKitJS.opened_DefFont[0] = buf
|
|
|
-
|
|
|
resolve(true)
|
|
|
}
|
|
|
fileReader.onerror = () => {
|
|
|
reject(fileReader.error)
|
|
|
}
|
|
|
- fileReader.readAsArrayBuffer(data.fontFile)
|
|
|
+ fileReader.readAsArrayBuffer(fontJson)
|
|
|
})
|
|
|
+
|
|
|
+ Module._InitComPDFkitFont()
|
|
|
const doc = Module._InitDocument()
|
|
|
|
|
|
return doc
|
|
|
})
|
|
|
|
|
|
+ messageHandler.on('LoadFile', (data) => {
|
|
|
+ ComPDFKitJS.opened_files = []
|
|
|
+ ComPDFKitJS.opened_files[0] = data.buffer
|
|
|
+ })
|
|
|
+
|
|
|
messageHandler.on('LoadDocumentByStream', loadDocumentByStream)
|
|
|
|
|
|
messageHandler.on('GetPageCount', (data) => {
|
|
@@ -1092,23 +1094,6 @@ class CPDFWorker {
|
|
|
return U8StringData
|
|
|
})
|
|
|
|
|
|
- messageHandler.on('SetFontCallBackForEditPage',async (data) => {
|
|
|
- const { editPagePtr } = data
|
|
|
-
|
|
|
- const fileReader = new FileReader()
|
|
|
- fileReader.onload = () => {
|
|
|
- const buf = new Uint8Array(fileReader.result)
|
|
|
-
|
|
|
- ComPDFKitJS.opened_Font[0] = buf
|
|
|
- ComPDFKitJS.opened_FontNames[0] = data.fontName
|
|
|
- Module._SetFontCallBackForEditPage(editPagePtr)
|
|
|
- }
|
|
|
- fileReader.onerror = () => {
|
|
|
- reject(fileReader.error)
|
|
|
- }
|
|
|
- fileReader.readAsArrayBuffer(data.fontFile)
|
|
|
- })
|
|
|
-
|
|
|
messageHandler.on('createEditorDoc', async (data) => {
|
|
|
const { doc, password } = data
|
|
|
return await copyDocument(doc, password)
|