Experimental multi bytes unicode (emoji) support

pull/3/merge
Amio 2018-07-18 17:57:26 +08:00
rodzic 937753c8f9
commit daad4723a4
3 zmienionych plików z 14 dodań i 6 usunięć

Wyświetl plik

@ -1,10 +1,12 @@
const widthsVerdana11 = require('./widths-verdana-11.json')
const astralRegex = require('./unicode-astral-regex.js')
function calcWidth (charWidthTable) {
const SCALE = 10
const widthTable = charWidthTable.map(w => Math.round(w * SCALE))
return function (text) {
return function (text, unicode) {
typeAssert(typeof text === 'string', 'Input must be string')
if (unicode) text = text.match(astralRegex)
let total = 0
let i = text.length

Wyświetl plik

@ -1,11 +1,11 @@
const calcWidth = require('./calc-text-width.js').Verdana11
const colorPresets = require('./color-presets.js')
module.exports = function ({subject, status, color, style}) {
module.exports = function ({subject, status, color, style, unicode}) {
color = colorPresets[color] || color || colorPresets['blue']
const sbRectWidth = calcWidth(subject) + 10
const stRectWidth = calcWidth(status) + 10
const sbRectWidth = calcWidth(subject, unicode) + 10
const stRectWidth = calcWidth(status, unicode) + 10
const width = sbRectWidth + stRectWidth
if (style === 'flat') {
@ -40,8 +40,8 @@ module.exports = function ({subject, status, color, style}) {
<g fill="#fff" text-anchor="start" font-family="Verdana,DejaVu Sans,sans-serif" font-size="11">
<text x="6.4" y="14.8" fill="#000" opacity="0.25">${subject}</text>
<text x="5.4" y="13.8">${subject}</text>
<text x="${sbRectWidth + 5.5}" y="14.8" fill="#000" opacity="0.25">${status}</text>
<text x="${sbRectWidth + 4.5}" y="13.8">${status}</text>
<text x="${sbRectWidth + 5.5}" y="14.8" fill="#000" opacity="0.25" textLength="${stRectWidth - 10}">${status}</text>
<text x="${sbRectWidth + 4.5}" y="13.8" textLength="${stRectWidth - 10}">${status}</text>
</g>
</svg>
`

Wyświetl plik

@ -0,0 +1,6 @@
// Borrowed from:
// https://github.com/lodash/lodash/blob/master/lodash.js
// https://github.com/mathiasbynens/regenerate
// https://mathiasbynens.be/notes/javascript-unicode
// https://github.com/sallar/unicode-astral-regex
module.exports = /\ud83c[\udffb-\udfff](?=\ud83c[\udffb-\udfff])|(?:[^\ud800-\udfff][\u0300-\u036f\ufe20-\ufe23\u20d0-\u20f0]?|[\u0300-\u036f\ufe20-\ufe23\u20d0-\u20f0]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff]|[\ud800-\udfff])[\ufe0e\ufe0f]?(?:[\u0300-\u036f\ufe20-\ufe23\u20d0-\u20f0]|\ud83c[\udffb-\udfff])?(?:\u200d(?:[^\ud800-\udfff]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff])[\ufe0e\ufe0f]?(?:[\u0300-\u036f\ufe20-\ufe23\u20d0-\u20f0]|\ud83c[\udffb-\udfff])?)*/g