{"version":3,"sources":["../src/index.js"],"names":["xOffsetBasedOnAlignment","constants","font","line","maxWidth","alignment","HORIZONTAL_ALIGN_LEFT","HORIZONTAL_ALIGN_CENTER","drawCharacter","image","x","y","char","width","height","characterPage","pages","page","blit","xoffset","yoffset","printText","text","defaultCharWidth","i","length","chars","test","fontChar","fontKerning","kernings","kerning","xadvance","splitLines","words","split","lines","currentLine","longestLine","forEach","word","join","push","loadPages","Jimp","dir","newPages","map","read","Promise","all","process","env","DIRNAME","__dirname","measureText","measureTextHeight","FONT_SANS_8_BLACK","Path","FONT_SANS_10_BLACK","FONT_SANS_12_BLACK","FONT_SANS_14_BLACK","FONT_SANS_16_BLACK","FONT_SANS_32_BLACK","FONT_SANS_64_BLACK","FONT_SANS_128_BLACK","FONT_SANS_8_WHITE","FONT_SANS_16_WHITE","FONT_SANS_32_WHITE","FONT_SANS_64_WHITE","FONT_SANS_128_WHITE","loadFont","file","cb","throwError","call","resolve","reject","err","String","fromCharCode","id","firstString","first","second","amount","dirname","then","common","info","print","maxHeight","Infinity","alignmentX","alignmentY","undefined","constructor","VERTICAL_ALIGN_TOP","toString","VERTICAL_ALIGN_BOTTOM","VERTICAL_ALIGN_MIDDLE","Object","entries","lineString","alignmentWidth","lineHeight"],"mappings":";;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AAEA,SAASA,uBAAT,CAAiCC,SAAjC,EAA4CC,IAA5C,EAAkDC,IAAlD,EAAwDC,QAAxD,EAAkEC,SAAlE,EAA6E;AAC3E,MAAIA,SAAS,KAAKJ,SAAS,CAACK,qBAA5B,EAAmD;AACjD,WAAO,CAAP;AACD;;AAED,MAAID,SAAS,KAAKJ,SAAS,CAACM,uBAA5B,EAAqD;AACnD,WAAO,CAACH,QAAQ,GAAG,8BAAYF,IAAZ,EAAkBC,IAAlB,CAAZ,IAAuC,CAA9C;AACD;;AAED,SAAOC,QAAQ,GAAG,8BAAYF,IAAZ,EAAkBC,IAAlB,CAAlB;AACD;;AAED,SAASK,a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CAAU,GAAV,CAAnB;AACA,cAAM+D,cAAc,GAAGxG,uBAAuB,CAC5C,MAAI,CAACgG,WADuC,EAE5C9F,IAF4C,EAG5CqG,UAH4C,EAI5CnG,QAJ4C,EAK5CyF,UAL4C,CAA9C;AAQAxE,UAAAA,SAAS,CAACsD,IAAV,CACE,MADF,EAEEzE,IAFF,EAGEQ,CAAC,GAAG8F,cAHN,EAIE7F,CAJF,EAKE4F,UALF,EAMEhF,gBANF;AASAZ,UAAAA,CAAC,IAAIT,IAAI,CAACsF,MAAL,CAAYiB,UAAjB;AACD,SApBD;;AAsBA,YAAI,0BAAchC,EAAd,CAAJ,EAAuB;AACrBA,UAAAA,EAAE,CAACE,IAAH,CAAQ,IAAR,EAAc,IAAd,EAAoB,IAApB,EAA0B;AAAEjE,YAAAA,CAAC,EAAEA,CAAC,GAAG4B,WAAT;AAAsB3B,YAAAA,CAAC,EAADA;AAAtB,WAA1B;AACD;;AAED,eAAO,IAAP;AACD;AA9GI;AA9Ga,GAAP;AAAA,C","sourcesContent":["import Path from 'path';\nimport bMFont from 'load-bmfont';\nimport { isNodePattern, throwError } from '@jimp/utils';\nimport { measureText, measureTextHeight } from './measure-text';\n\nfunction xOffsetBasedOnAlignment(constants, font, line, maxWidth, alignment) {\n if (alignment === constants.HORIZONTAL_ALIGN_LEFT) {\n return 0;\n }\n\n if (alignment === constants.HORIZONTAL_ALIGN_CENTER) {\n return (maxWidth - measureText(font, line)) / 2;\n }\n\n return maxWidth - measureText(font, line);\n}\n\nfunction drawCharacter(image, font, x, y, char) {\n if (char.width > 0 && char.height > 0) {\n const characterPage = font.pages[char.page];\n\n image.blit(\n characterPage,\n x + char.xoffset,\n y + char.yoffset,\n char.x,\n char.y,\n char.width,\n char.height\n );\n }\n\n return image;\n}\n\nfunction printText(font, x, y, text, defaultCharWidth) {\n for (let i = 0; i < text.length; i++) {\n let char;\n\n if (font.chars[text[i]]) {\n char = text[i];\n } else if (/\\s/.test(text[i])) {\n char = '';\n } else {\n char = '?';\n }\n\n const fontChar = font.chars[char] || {};\n const fontKerning = font.kernings[char];\n\n drawCharacter(this, font, x, y, fontChar || {});\n\n const kerning =\n fontKerning && fontKerning[text[i + 1]] ? fontKerning[text[i + 1]] : 0;\n\n x += kerning + (fontChar.xadvance || defaultCharWidth);\n }\n}\n\nfunction splitLines(font, text, maxWidth) {\n const words = text.split(' ');\n const lines = [];\n let currentLine = [];\n let longestLine = 0;\n\n words.forEach(word => {\n const line = [...currentLine, word].join(' ');\n const length = measureText(font, line);\n\n if (length <= maxWidth) {\n if (length > longestLine) {\n longestLine = length;\n }\n\n currentLine.push(word);\n } else {\n lines.push(currentLine);\n currentLine = [word];\n }\n });\n\n lines.push(currentLine);\n\n return {\n lines,\n longestLine\n };\n}\n\nfunction loadPages(Jimp, dir, pages) {\n const newPages = pages.map(page => {\n return Jimp.read(dir + '/' + page);\n });\n\n return Promise.all(newPages);\n}\n\nconst dir = process.env.DIRNAME || `${__dirname}/../`;\n\nexport default () => ({\n constants: {\n measureText,\n measureTextHeight,\n FONT_SANS_8_BLACK: Path.join(\n dir,\n 'fonts/open-sans/open-sans-8-black/open-sans-8-black.fnt'\n ),\n FONT_SANS_10_BLACK: Path.join(\n dir,\n 'fonts/open-sans/open-sans-10-black/open-sans-10-black.fnt'\n ),\n FONT_SANS_12_BLACK: Path.join(\n dir,\n 'fonts/open-sans/open-sans-12-black/open-sans-12-black.fnt'\n ),\n FONT_SANS_14_BLACK: Path.join(\n dir,\n 'fonts/open-sans/open-sans-14-black/open-sans-14-black.fnt'\n ),\n FONT_SANS_16_BLACK: Path.join(\n dir,\n 'fonts/open-sans/open-sans-16-black/open-sans-16-black.fnt'\n ),\n FONT_SANS_32_BLACK: Path.join(\n dir,\n 'fonts/open-sans/open-sans-32-black/open-sans-32-black.fnt'\n ),\n FONT_SANS_64_BLACK: Path.join(\n dir,\n 'fonts/open-sans/open-sans-64-black/open-sans-64-black.fnt'\n ),\n FONT_SANS_128_BLACK: Path.join(\n dir,\n 'fonts/open-sans/open-sans-128-black/open-sans-128-black.fnt'\n ),\n\n FONT_SANS_8_WHITE: Path.join(\n dir,\n 'fonts/open-sans/open-sans-8-white/open-sans-8-white.fnt'\n ),\n FONT_SANS_16_WHITE: Path.join(\n dir,\n 'fonts/open-sans/open-sans-16-white/open-sans-16-white.fnt'\n ),\n FONT_SANS_32_WHITE: Path.join(\n dir,\n 'fonts/open-sans/open-sans-32-white/open-sans-32-white.fnt'\n ),\n FONT_SANS_64_WHITE: Path.join(\n dir,\n 'fonts/open-sans/open-sans-64-white/open-sans-64-white.fnt'\n ),\n FONT_SANS_128_WHITE: Path.join(\n dir,\n 'fonts/open-sans/open-sans-128-white/open-sans-128-white.fnt'\n ),\n\n /**\n * Loads a bitmap font from a file\n * @param {string} file the file path of a .fnt file\n * @param {function(Error, Jimp)} cb (optional) a function to call when the font is loaded\n * @returns {Promise} a promise\n */\n loadFont(file, cb) {\n if (typeof file !== 'string')\n return throwError.call(this, 'file must be a string', cb);\n\n return new Promise((resolve, reject) => {\n cb =\n cb ||\n function(err, font) {\n if (err) reject(err);\n else resolve(font);\n };\n\n bMFont(file, (err, font) => {\n const chars = {};\n const kernings = {};\n\n if (err) {\n return throwError.call(this, err, cb);\n }\n\n for (let i = 0; i < font.chars.length; i++) {\n chars[String.fromCharCode(font.chars[i].id)] = font.chars[i];\n }\n\n for (let i = 0; i < font.kernings.length; i++) {\n const firstString = String.fromCharCode(font.kernings[i].first);\n kernings[firstString] = kernings[firstString] || {};\n kernings[firstString][\n String.fromCharCode(font.kernings[i].second)\n ] = font.kernings[i].amount;\n }\n\n loadPages(this, Path.dirname(file), font.pages).then(pages => {\n cb(null, {\n chars,\n kernings,\n pages,\n common: font.common,\n info: font.info\n });\n });\n });\n });\n }\n },\n\n class: {\n /**\n * Draws a text on a image on a given boundary\n * @param {Jimp} font a bitmap font loaded from `Jimp.loadFont` command\n * @param {number} x the x position to start drawing the text\n * @param {number} y the y position to start drawing the text\n * @param {any} text the text to draw (string or object with `text`, `alignmentX`, and/or `alignmentY`)\n * @param {number} maxWidth (optional) the boundary width to draw in\n * @param {number} maxHeight (optional) the boundary height to draw in\n * @param {function(Error, Jimp)} cb (optional) a function to call when the text is written\n * @returns {Jimp} this for chaining of methods\n */\n print(font, x, y, text, maxWidth, maxHeight, cb) {\n if (typeof maxWidth === 'function' && typeof cb === 'undefined') {\n cb = maxWidth;\n maxWidth = Infinity;\n }\n\n if (typeof maxWidth === 'undefined') {\n maxWidth = Infinity;\n }\n\n if (typeof maxHeight === 'function' && typeof cb === 'undefined') {\n cb = maxHeight;\n maxHeight = Infinity;\n }\n\n if (typeof maxHeight === 'undefined') {\n maxHeight = Infinity;\n }\n\n if (typeof font !== 'object') {\n return throwError.call(this, 'font must be a Jimp loadFont', cb);\n }\n\n if (\n typeof x !== 'number' ||\n typeof y !== 'number' ||\n typeof maxWidth !== 'number'\n ) {\n return throwError.call(this, 'x, y and maxWidth must be numbers', cb);\n }\n\n if (typeof maxWidth !== 'number') {\n return throwError.call(this, 'maxWidth must be a number', cb);\n }\n\n if (typeof maxHeight !== 'number') {\n return throwError.call(this, 'maxHeight must be a number', cb);\n }\n\n let alignmentX;\n let alignmentY;\n\n if (\n typeof text === 'object' &&\n text.text !== null &&\n text.text !== undefined\n ) {\n alignmentX = text.alignmentX || this.constructor.HORIZONTAL_ALIGN_LEFT;\n alignmentY = text.alignmentY || this.constructor.VERTICAL_ALIGN_TOP;\n ({ text } = text);\n } else {\n alignmentX = this.constructor.HORIZONTAL_ALIGN_LEFT;\n alignmentY = this.constructor.VERTICAL_ALIGN_TOP;\n text = text.toString();\n }\n\n if (\n maxHeight !== Infinity &&\n alignmentY === this.constructor.VERTICAL_ALIGN_BOTTOM\n ) {\n y += maxHeight - measureTextHeight(font, text, maxWidth);\n } else if (\n maxHeight !== Infinity &&\n alignmentY === this.constructor.VERTICAL_ALIGN_MIDDLE\n ) {\n y += maxHeight / 2 - measureTextHeight(font, text, maxWidth) / 2;\n }\n\n const defaultCharWidth = Object.entries(font.chars)[0][1].xadvance;\n const { lines, longestLine } = splitLines(font, text, maxWidth);\n\n lines.forEach(line => {\n const lineString = line.join(' ');\n const alignmentWidth = xOffsetBasedOnAlignment(\n this.constructor,\n font,\n lineString,\n maxWidth,\n alignmentX\n );\n\n printText.call(\n this,\n font,\n x + alignmentWidth,\n y,\n lineString,\n defaultCharWidth\n );\n\n y += font.common.lineHeight;\n });\n\n if (isNodePattern(cb)) {\n cb.call(this, null, this, { x: x + longestLine, y });\n }\n\n return this;\n }\n }\n});\n"],"file":"index.js"}