thedesk/app/node_modules/@jimp/plugin-print/es/index.js.map
2019-09-12 23:38:13 +09:00

1 line
19 KiB
Plaintext

{"version":3,"sources":["../src/index.js"],"names":["Path","bMFont","isNodePattern","throwError","measureText","measureTextHeight","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","FONT_SANS_8_BLACK","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","call","resolve","reject","err","String","fromCharCode","id","firstString","first","second","amount","dirname","then","common","info","class","print","maxHeight","Infinity","alignmentX","alignmentY","undefined","constructor","VERTICAL_ALIGN_TOP","toString","VERTICAL_ALIGN_BOTTOM","VERTICAL_ALIGN_MIDDLE","Object","entries","lineString","alignmentWidth","lineHeight"],"mappings":";;;;;;;;;;AAAA,OAAOA,IAAP,MAAiB,MAAjB;AACA,OAAOC,MAAP,MAAmB,aAAnB;AACA,SAASC,aAAT,EAAwBC,UAAxB,QAA0C,aAA1C;AACA,SAASC,WAAT,EAAsBC,iBAAtB,QAA+C,gBAA/C;;AAEA,SAASC,uBAAT,CAAiCC,SAAjC,EAA4CC,IAA5C,EAAkDC,IAAlD,EAAwDC,QAAxD,EAAkEC,SAAlE,EAA6E;AAC3E,MAAIA,SAAS,KAAKJ,SAAS,CAACK,qBAA5B,EAAmD;AACjD,WAAO,CAAP;A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;AAED,YAAMmB,gBAAgB,GAAG2E,MAAM,CAACC,OAAP,CAAejG,IAAI,CAACwB,KAApB,EAA2B,CAA3B,EAA8B,CAA9B,EAAiCM,QAA1D;;AApE+C,0BAqEhBC,UAAU,CAAC/B,IAAD,EAAOoB,IAAP,EAAalB,QAAb,CArEM;AAAA,YAqEvCgC,KArEuC,eAqEvCA,KArEuC;AAAA,YAqEhCE,WArEgC,eAqEhCA,WArEgC;;AAuE/CF,QAAAA,KAAK,CAACG,OAAN,CAAc,UAAApC,IAAI,EAAI;AACpB,cAAMiG,UAAU,GAAGjG,IAAI,CAACsC,IAAL,CAAU,GAAV,CAAnB;AACA,cAAM4D,cAAc,GAAGrG,uBAAuB,CAC5C,MAAI,CAAC6F,WADuC,EAE5C3F,IAF4C,EAG5CkG,UAH4C,EAI5ChG,QAJ4C,EAK5CsF,UAL4C,CAA9C;AAQArE,UAAAA,SAAS,CAACkD,IAAV,CACE,MADF,EAEErE,IAFF,EAGEQ,CAAC,GAAG2F,cAHN,EAIE1F,CAJF,EAKEyF,UALF,EAME7E,gBANF;AASAZ,UAAAA,CAAC,IAAIT,IAAI,CAACkF,MAAL,CAAYkB,UAAjB;AACD,SApBD;;AAsBA,YAAI1G,aAAa,CAAC0E,EAAD,CAAjB,EAAuB;AACrBA,UAAAA,EAAE,CAACC,IAAH,CAAQ,IAAR,EAAc,IAAd,EAAoB,IAApB,EAA0B;AAAE7D,YAAAA,CAAC,EAAEA,CAAC,GAAG4B,WAAT;AAAsB3B,YAAAA,CAAC,EAADA;AAAtB,WAA1B;AACD;;AAED,eAAO,IAAP;AACD;AA9GI;AA9Ga,GAAP;AAAA,CAAf","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"}