Commit ffbf9ad5 by ramdayalmunda

added woff2 files for smaller file size

parent 1db5502d
......@@ -150,25 +150,24 @@ var ADocEditor = function (customConfig) {
`;
console.log();
addFonts(["./assets/fonts/ArchitectsDaughter-Regular.ttf"], 'Architects Daughter')
addFonts(["./assets/fonts/calibri-regular.ttf"], 'Calibri')
addFonts(["./assets/fonts/Caveat-VariableFont_wght.ttf"], 'Caveat')
//////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/IndieFlower-Regular.ttf"], 'Indie Flower')
addFonts(["./assets/fonts/Kanit-Regular.ttf"], 'Kanit')
addFonts(["./assets/fonts/Kenia-Regular.ttf"], 'Kenia')
addFonts(["./assets/fonts/Lato-Regular.ttf"], 'Lato')
addFonts(["./assets/fonts/Lora-Regular.ttf"], 'Lora')
addFonts(["./assets/fonts/Macondo-Regular.ttf"], 'Macondo')
addFonts(["./assets/fonts/Merriweather-Regular.ttf"], 'Merriweather')
addFonts(["./assets/fonts/Montserrat-VariableFont_wght.ttf"], 'Montserrat')
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/Rubik-VariableFont_wght.ttf"], 'Rubik')
addFonts(["./assets/fonts/Ubuntu-Regular.ttf"], 'Ubuntu')
addFonts(["./assets/fonts/WorkSans-VariableFont_wght.ttf"], 'Work Sans')
addFonts(["./assets/fonts/ArchitectsDaughter-Regular.woff2", "./assets/fonts/ArchitectsDaughter-Regular.ttf"], 'Architects Daughter')
addFonts(["./assets/fonts/calibri-regular.woff2", "./assets/fonts/calibri-regular.ttf"], 'Calibri')
addFonts(["./assets/fonts/Caveat-VariableFont_wght.woff2","./assets/fonts/Caveat-VariableFont_wght.ttf"], 'Caveat')
addFonts(["./assets/fonts/EduTASBeginner-VariableFont_wght.woff2","./assets/fonts/EduTASBeginner-VariableFont_wght.ttf"], 'Edu TAS Beginner')
addFonts(["./assets/fonts/IndieFlower-Regular.woff2","./assets/fonts/IndieFlower-Regular.ttf"], 'Indie Flower')
addFonts(["./assets/fonts/Kanit-Regular.woff2","./assets/fonts/Kanit-Regular.ttf"], 'Kanit')
addFonts(["./assets/fonts/Kenia-Regular.woff2","./assets/fonts/Kenia-Regular.ttf"], 'Kenia')
addFonts(["./assets/fonts/Lato-Regular.woff2", "./assets/fonts/Lato-Regular.ttf"], 'Lato')
addFonts(["./assets/fonts/Lora-Regular.woff2", "./assets/fonts/Lora-Regular.ttf"], 'Lora')
addFonts(["./assets/fonts/Macondo-Regular.woff2","./assets/fonts/Macondo-Regular.ttf"], 'Macondo')
addFonts(["./assets/fonts/Merriweather-Regular.woff2", "./assets/fonts/Merriweather-Regular.ttf"], 'Merriweather')
addFonts(["./assets/fonts/Montserrat-VariableFont_wght.woff2", "./assets/fonts/Montserrat-VariableFont_wght.ttf"], 'Montserrat')
addFonts(["./assets/fonts/OpenSans-VariableFont_wdth,wght.woff2", "./assets/fonts/OpenSans-VariableFont_wdth,wght.ttf"], 'Open Sans')
addFonts(["./assets/fonts/Pacifico-Regular.woff2", "./assets/fonts/Pacifico-Regular.ttf"], 'Pacifico')
addFonts(["./assets/fonts/Poppins-Regular.woff2", "./assets/fonts/Poppins-Regular.ttf"], 'Poppins')
addFonts(["./assets/fonts/Rubik-VariableFont_wght.woff2", "./assets/fonts/Rubik-VariableFont_wght.ttf"], 'Rubik')
addFonts(["./assets/fonts/Ubuntu-Regular.woff2", "./assets/fonts/Ubuntu-Regular.ttf"], 'Ubuntu')
addFonts(["./assets/fonts/WorkSans-Regular.woff2", "./assets/fonts/WorkSans-Regular.ttf"], 'Work Sans')
container.innerHTML = htmlSetup
container.append(styleTag)
......@@ -187,7 +186,7 @@ var ADocEditor = function (customConfig) {
rightSidebar.classList.toggle('hide')
})
fontFamilyDropdown = document.getElementById(fontFamilyDropdownId)
fontFamilyDropdown.addEventListener( 'change', changeFontFamily )
fontFamilyDropdown.addEventListener('change', changeFontFamily)
reRenderFontDropdown()
let generatePDFBtn = document.querySelector('[a-doc-editor-action]')
generatePDFBtn.addEventListener('click', generatePDF)
......@@ -451,9 +450,9 @@ var ADocEditor = function (customConfig) {
// Alpha channel remains unchanged (data[i + 3])
ctx.putImageData(imageData, rectX, rectY);
}
if (characterData){
if (characterData) {
caretData.style = { ...characterData }
}else{
} else {
caretData.style = { ...caretData.activeData.style }
}
......@@ -515,7 +514,7 @@ var ADocEditor = function (customConfig) {
if (e.shiftKey && (e.ctrlKey || e.metaKey)) {
return
}
else if (e.keyCode==16){ // only shift key
else if (e.keyCode == 16) { // only shift key
return
}
// ctr+shift combination
......@@ -690,19 +689,19 @@ var ADocEditor = function (customConfig) {
let embededFonts = {}
// Create a new PDFDocument
const pdfDoc = await PDFDocument.create()
function embedFont( name ){
return new Promise( (res, rej)=>{
let fontObj = fontList.find( item => item.name == name )
function embedFont(name) {
return new Promise((res, rej) => {
let fontObj = fontList.find(item => item.name == name)
console.log(fontObj)
fetch( fontObj.paths[0] )
.then( async(data)=>{
fetch(fontObj.paths[0])
.then(async (data) => {
let arrayBuffer = await data.arrayBuffer()
embededFonts[name] = await pdfDoc.embedFont(arrayBuffer)
res( embededFonts[name] )
} ).catch((err)=>{
res(embededFonts[name])
}).catch((err) => {
rej(err)
})
} )
})
}
// register font-kit
pdfDoc.registerFontkit(fontkit)
......@@ -739,11 +738,11 @@ var ADocEditor = function (customConfig) {
...config.style,
...setData.style
}
if (!embededFonts[style.fontFamily]) await embedFont( style.fontFamily )
page.drawText( `${lines[l].listIndex + 1}.` , {
x: numberX/config.pageSetup.canvasMultiplier,
y: (config.pageSetup.canvasHeight-y)/config.pageSetup.canvasMultiplier,
size: (style.fontSize*config.pageSetup.fontMultiplier)/config.pageSetup.canvasMultiplier,
if (!embededFonts[style.fontFamily]) await embedFont(style.fontFamily)
page.drawText(`${lines[l].listIndex + 1}.`, {
x: numberX / config.pageSetup.canvasMultiplier,
y: (config.pageSetup.canvasHeight - y) / config.pageSetup.canvasMultiplier,
size: (style.fontSize * config.pageSetup.fontMultiplier) / config.pageSetup.canvasMultiplier,
font: embededFonts[style.fontFamily],
color: rgb(0, 0, 0),
})
......@@ -757,11 +756,11 @@ var ADocEditor = function (customConfig) {
let char = setData?.plainContent[c]
if (char) {
let style = setData.formatedText[c]
if (!embededFonts[style.fontFamily]) await embedFont( style.fontFamily )
page.drawText( dataSet[lines[l].dataSetIndex].plainContent[c] , {
x: style.x/config.pageSetup.canvasMultiplier,
y:( config.pageSetup.canvasHeight-style.y)/config.pageSetup.canvasMultiplier,
size: (style.fontSize*config.pageSetup.fontMultiplier)/config.pageSetup.canvasMultiplier,
if (!embededFonts[style.fontFamily]) await embedFont(style.fontFamily)
page.drawText(dataSet[lines[l].dataSetIndex].plainContent[c], {
x: style.x / config.pageSetup.canvasMultiplier,
y: (config.pageSetup.canvasHeight - style.y) / config.pageSetup.canvasMultiplier,
size: (style.fontSize * config.pageSetup.fontMultiplier) / config.pageSetup.canvasMultiplier,
font: embededFonts[style.fontFamily],
color: rgb(0, 0, 0),
})
......@@ -787,8 +786,8 @@ var ADocEditor = function (customConfig) {
document.body.removeChild(downloadLink)
}
function addFonts(paths, name){
if (typeof paths == 'string') paths = [ paths ]
function addFonts(paths, name) {
if (typeof paths == 'string') paths = [paths]
let fontObj = {
paths: [],
name: name,
......@@ -796,21 +795,21 @@ var ADocEditor = function (customConfig) {
if (!isModule) {
let linkString = ''
for(let i=0; i<paths.length; i++){
for (let i = 0; i < paths.length; i++) {
let format = paths[i].split('.');
format = format[format.length-1]
fontObj.paths.push( paths[i] )
linkString += `url(${paths[i]}) format("${format=='ttf'?'truetype':format}")${(i>=paths.length-1)?'':',\n'}`
format = format[format.length - 1]
fontObj.paths.push(paths[i])
linkString += `url(${paths[i]}) format("${format == 'ttf' ? 'truetype' : format}")${(i >= paths.length - 1) ? '' : ',\n'}`
}
const customFont = new FontFace(`${name}`, `${linkString}`);
customFont.load()
.then( (loadedFont)=>{
.then((loadedFont) => {
document.fonts.add(loadedFont);
loadedFont.loaded.then( ()=>{
loadedFont.loaded.then(() => {
fontList.push(fontObj)
reRenderFontDropdown()
} )
} )
})
})
}
......@@ -821,27 +820,27 @@ var ADocEditor = function (customConfig) {
// // these are methods related to the toolbar items
function changeFontFamily(e){
function changeFontFamily(e) {
caretData.style.fontFamily = e.target.value
caretData.styleModified = false
if (lastFocusCanvas){
if (lastFocusCanvas) {
lastFocusCanvas.focus({ preventScroll: true })
}
if (!caretData.activeData.plainContent.length){
if (!caretData.activeData.plainContent.length) {
caretData.activeData.style.fontFamily = e.target.value
}
}
function reRenderFontDropdown(){
if (fontFamilyDropdown){
function reRenderFontDropdown() {
if (fontFamilyDropdown) {
fontFamilyDropdown.innerHTML = ""
fontList.forEach( (font,i)=>{
fontList.forEach((font, i) => {
let optionTag = document.createElement('option')
optionTag.setAttribute('value', font.name)
optionTag.innerHTML = font.name
fontFamilyDropdown.append(optionTag)
} )
})
}
}
......@@ -851,7 +850,7 @@ var ADocEditor = function (customConfig) {
clearInterval(caretData.interval)
}
function getContent(){
function getContent() {
return JSON.parse(JSON.stringify(dataSet))
}
......
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