Commit 1db5502d by ramdayalmunda

unuxed fonts removed

parent 504086a2
...@@ -151,9 +151,9 @@ var ADocEditor = function (customConfig) { ...@@ -151,9 +151,9 @@ var ADocEditor = function (customConfig) {
console.log(); console.log();
addFonts(["./assets/fonts/ArchitectsDaughter-Regular.ttf"], 'Architects Daughter') addFonts(["./assets/fonts/ArchitectsDaughter-Regular.ttf"], 'Architects Daughter')
addFonts(["./assets/fonts/Calibri.ttf"], 'Calibri') addFonts(["./assets/fonts/calibri-regular.ttf"], 'Calibri')
addFonts(["./assets/fonts/Caveat-VariableFont_wght.ttf"], 'Caveat') addFonts(["./assets/fonts/Caveat-VariableFont_wght.ttf"], 'Caveat')
addFonts(["./assets/fonts/DancingScript-VariableFont_wght.ttf"], 'Dancing Script') //////addFonts(["./assets/fonts/DancingScript-VariableFont_wght.ttf"], 'Dancing Script'); // this font is not working with pdf-lib
addFonts(["./assets/fonts/EduTASBeginner-VariableFont_wght.ttf"], 'Edu TAS Beginner') addFonts(["./assets/fonts/EduTASBeginner-VariableFont_wght.ttf"], 'Edu TAS Beginner')
addFonts(["./assets/fonts/IndieFlower-Regular.ttf"], 'Indie Flower') addFonts(["./assets/fonts/IndieFlower-Regular.ttf"], 'Indie Flower')
addFonts(["./assets/fonts/Kanit-Regular.ttf"], 'Kanit') addFonts(["./assets/fonts/Kanit-Regular.ttf"], 'Kanit')
...@@ -164,6 +164,7 @@ var ADocEditor = function (customConfig) { ...@@ -164,6 +164,7 @@ var ADocEditor = function (customConfig) {
addFonts(["./assets/fonts/Merriweather-Regular.ttf"], 'Merriweather') addFonts(["./assets/fonts/Merriweather-Regular.ttf"], 'Merriweather')
addFonts(["./assets/fonts/Montserrat-VariableFont_wght.ttf"], 'Montserrat') addFonts(["./assets/fonts/Montserrat-VariableFont_wght.ttf"], 'Montserrat')
addFonts(["./assets/fonts/OpenSans-VariableFont_wdth,wght.ttf"], 'Open Sans') addFonts(["./assets/fonts/OpenSans-VariableFont_wdth,wght.ttf"], 'Open Sans')
addFonts(["./assets/fonts/Pacifico-Regular.woff","./assets/fonts/Pacifico-Regular.ttf"], 'Pacifico')
addFonts(["./assets/fonts/Poppins-Regular.ttf"], 'Poppins') addFonts(["./assets/fonts/Poppins-Regular.ttf"], 'Poppins')
addFonts(["./assets/fonts/Rubik-VariableFont_wght.ttf"], 'Rubik') addFonts(["./assets/fonts/Rubik-VariableFont_wght.ttf"], 'Rubik')
addFonts(["./assets/fonts/Ubuntu-Regular.ttf"], 'Ubuntu') addFonts(["./assets/fonts/Ubuntu-Regular.ttf"], 'Ubuntu')
...@@ -685,19 +686,26 @@ var ADocEditor = function (customConfig) { ...@@ -685,19 +686,26 @@ var ADocEditor = function (customConfig) {
let embededFonts = {}
// Create a new PDFDocument // Create a new PDFDocument
const pdfDoc = await PDFDocument.create() const pdfDoc = await PDFDocument.create()
// register font-kit function embedFont( name ){
pdfDoc.registerFontkit(fontkit) return new Promise( (res, rej)=>{
let fontBytes = await new Promise( async ( res, rej )=>{ let fontObj = fontList.find( item => item.name == name )
fetch( "./assets/fonts/Kenia-Regular.ttf" ) console.log(fontObj)
fetch( fontObj.paths[0] )
.then( async(data)=>{ .then( async(data)=>{
res( await data.arrayBuffer() ) let arrayBuffer = await data.arrayBuffer()
embededFonts[name] = await pdfDoc.embedFont(arrayBuffer)
res( embededFonts[name] )
} ).catch((err)=>{ } ).catch((err)=>{
rej(err) rej(err)
}) })
} ) } )
const customFont = await pdfDoc.embedFont(fontBytes) }
// register font-kit
pdfDoc.registerFontkit(fontkit)
// Add a blank page to the document // Add a blank page to the document
var page = pdfDoc.addPage([config.pageSetup.width, config.pageSetup.height]) var page = pdfDoc.addPage([config.pageSetup.width, config.pageSetup.height])
...@@ -731,11 +739,12 @@ var ADocEditor = function (customConfig) { ...@@ -731,11 +739,12 @@ var ADocEditor = function (customConfig) {
...config.style, ...config.style,
...setData.style ...setData.style
} }
if (!embededFonts[style.fontFamily]) await embedFont( style.fontFamily )
page.drawText( `${lines[l].listIndex + 1}.` , { page.drawText( `${lines[l].listIndex + 1}.` , {
x: numberX/config.pageSetup.canvasMultiplier, x: numberX/config.pageSetup.canvasMultiplier,
y: (config.pageSetup.canvasHeight-y)/config.pageSetup.canvasMultiplier, y: (config.pageSetup.canvasHeight-y)/config.pageSetup.canvasMultiplier,
size: (style.fontSize*config.pageSetup.fontMultiplier)/config.pageSetup.canvasMultiplier, size: (style.fontSize*config.pageSetup.fontMultiplier)/config.pageSetup.canvasMultiplier,
font: customFont, font: embededFonts[style.fontFamily],
color: rgb(0, 0, 0), color: rgb(0, 0, 0),
}) })
} }
...@@ -748,11 +757,12 @@ var ADocEditor = function (customConfig) { ...@@ -748,11 +757,12 @@ var ADocEditor = function (customConfig) {
let char = setData?.plainContent[c] let char = setData?.plainContent[c]
if (char) { if (char) {
let style = setData.formatedText[c] let style = setData.formatedText[c]
if (!embededFonts[style.fontFamily]) await embedFont( style.fontFamily )
page.drawText( dataSet[lines[l].dataSetIndex].plainContent[c] , { page.drawText( dataSet[lines[l].dataSetIndex].plainContent[c] , {
x: style.x/config.pageSetup.canvasMultiplier, x: style.x/config.pageSetup.canvasMultiplier,
y:( config.pageSetup.canvasHeight-style.y)/config.pageSetup.canvasMultiplier, y:( config.pageSetup.canvasHeight-style.y)/config.pageSetup.canvasMultiplier,
size: (style.fontSize*config.pageSetup.fontMultiplier)/config.pageSetup.canvasMultiplier, size: (style.fontSize*config.pageSetup.fontMultiplier)/config.pageSetup.canvasMultiplier,
font: customFont, font: embededFonts[style.fontFamily],
color: rgb(0, 0, 0), color: rgb(0, 0, 0),
}) })
setData.formatedText[c].x = x setData.formatedText[c].x = x
...@@ -789,6 +799,7 @@ var ADocEditor = function (customConfig) { ...@@ -789,6 +799,7 @@ var ADocEditor = function (customConfig) {
for(let i=0; i<paths.length; i++){ for(let i=0; i<paths.length; i++){
let format = paths[i].split('.'); let format = paths[i].split('.');
format = format[format.length-1] format = format[format.length-1]
fontObj.paths.push( paths[i] )
linkString += `url(${paths[i]}) format("${format=='ttf'?'truetype':format}")${(i>=paths.length-1)?'':',\n'}` linkString += `url(${paths[i]}) format("${format=='ttf'?'truetype':format}")${(i>=paths.length-1)?'':',\n'}`
} }
const customFont = new FontFace(`${name}`, `${linkString}`); const customFont = new FontFace(`${name}`, `${linkString}`);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment