@@ -117,7 +117,7 @@ export default class AddText {
const data = {
rect,
fontData: {
- fontName: 'Helvetica',
+ fontName: 'DroidSansFallbackFull',
fontSize: 14,
r: 0,
g: 0,
@@ -17,6 +17,7 @@ export class ContentContainer {
this.tool = this.pageViewer.tool || ''
this.color = this.pageViewer.color || ''
this._selectedFrameIndex = -1
+ this.isSetFont = false
this.onHandleTool = this.handleTool.bind(this)
}
@@ -26,6 +27,21 @@ export class ContentContainer {
pagePtr: this.pagePtr
})
this.editPagePtr = editPagePtr
+
+ if (!this.isSetFont) {
+ try {
+ const response = await fetch('/lib/DroidSansFallbackFull.ttf')
+ const blob = await response.blob()
+ const file = new File([blob], 'DroidSansFallbackFull.ttf', { type: blob.type })
+ await this.messageHandler.sendWithPromise('SetFontCallBackForEditPage', {
+ editPagePtr: this.editPagePtr,
+ file: file
+ })
+ this.isSetFont = true
+ } catch (error) {
+ console.log(error)
+ }
async render () {
@@ -795,7 +795,7 @@ export class TextEditor {
let keyCode = e.keyCode || e.which
const toolKey = [9, 16, 17, 18, 20, 27, 37, 38, 39, 40, 91, 93]
- let isToolKey = e.ctrlKey || e.shiftKey || e.altKey || e.metaKey || toolKey.includes(keyCode)
+ let isToolKey = e.ctrlKey || e.altKey || e.metaKey || toolKey.includes(keyCode)
this.isToolKey = isToolKey
@@ -910,6 +910,24 @@ class CPDFWorker {
)
return U8StringData
+ messageHandler.on('SetFontCallBackForEditPage', (data) => {
+ const { editPagePtr, file } = 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)