2.2.0
@sutton-signwriting/font-db is a javascript package for node that generates SVG and PNG images for individual symbols, complete signs, and structured text. The package covers the entire set of the International SignWritnig Alphabet 2010 (ISWA 2010).
This package supports both Formal SignWriting in ASCII (FSW) and SignWriting in Unicode (SWU) character sets, along with the style string. See draft-slevinski-formal-signwriting for detailed specification.
Author: https://SteveSlevinski.me
Channel: https://www.youtube.com/channel/UCXu4AXlG0rXFtk_5SzumDow
Sponsor: https://www.patreon.com/signwriting
Donate: https://donate.sutton-signwriting.io
npm install @sutton-signwriting/font-db
# download package
git clone https://github.com/sutton-signwriting/font-db.git
# install dependancies
cd font-db
npm install
# test project
npm run test
npm run testit fsw
npm run testit fsw-symbol-svg
# create project documentation
npm run docs
# start built-in server
npm run server
// import entire library
const fontDb = require('@sutton-signwriting/font-db');
// import individual module
const fsw = require('@sutton-signwriting/font-db/fsw');
# works for script with FSW and SWU, Symbol and Sign, SVG and PNG.
# output in the terminal
node fsw/fsw-sign-svg M525x535S2e748483x510S10011501x466S2e704510x500S10019476x475-C
# save to file
node fsw/fsw-sign-svg M525x535S2e748483x510S10011501x466S2e704510x500S10019476x475-C output.svg
MIT
The fsw module contains functions for handling Formal SignWriitng in ASCII (FSW) characters. FSW characters definition
Function that creates an SVG image from an FSW symbol key with an optional style string
(string)
an FSW symbol key with optional style string
string
:
symbol svg body
// using promise.then
fsw.symbolSvgBody('S20500-C').then( svg => {
console.log(svg)
})
// using async/await
const svg = await fsw.symbolSvgBody('S20500-C')
Function that creates an SVG image from an FSW symbol key with an optional style string
(string)
an FSW symbol key with optional style string
string
:
symbol svg
// using promise.then
fsw.symbolSvg('S20500-C').then( svg => {
console.log(svg)
})
// using async/await
const svg = await fsw.symbolSvg('S20500-C')
Function that creates a binary PNG image from an FSW symbol key with an optional style string
(string)
an FSW symbol key with optional style string
ArrayBuffer
:
symbol png
// using promise.then
fsw.symbolPng('S20500-C').then( png => {
console.log(png)
})
// using promise.then with options which scales the image to 100 pixels width
fsw.symbolPng('S20500-C', { width: 100 }).then( png => {
console.log(png)
})
// using async/await
const png = await fsw.symbolPng('S20500-C')
// using async/await with options which scales the image to 100 pixels width
const png = await fsw.symbolPng('S20500-C', { width: 100 })
Function that creates a data url PNG image from an FSW symbol key with an optional style string
(string)
an FSW symbol key with optional style string
string
:
symbol png
// using promise.then
fsw.symbolPngDataUrl('S20500-C').then( png => {
console.log(png)
})
// using promise.then with options which scales the image to 100 pixels width
fsw.symbolPngDataUrl('S20500-C', { width: 100 }).then( png => {
console.log(png)
})
// using async/await
const png = await fsw.symbolPngDataUrl('S20500-C')
// using async/await with options which scales the image to 100 pixels width
const png = await fsw.symbolPngDataUrl('S20500-C', { width: 100 })
Function that normalizes a symbol with a minimum coordinate for a center of 500,500
(string)
an FSW symbol key with optional coordinate and style string
string
:
normalized symbol
// using promise.then
fsw.symbolNormalize('S20500-C').then( norm => {
console.log(norm)
})
// using async/await
const norm = await fsw.symbolNormalize('S20500-C')
Function that creates an SVG image from an FSW sign with an optional style string
(string)
an FSW sign with optional style string
string
:
sign svg body
// using promise.then
fsw.signSvgBody('M525x535S2e748483x510S10011501x466S2e704510x500S10019476x475').then( svg => {
console.log(svg)
})
// using async/await
const svg = await fsw.signSvgBody('M525x535S2e748483x510S10011501x466S2e704510x500S10019476x475')
Function that creates an SVG image from an FSW sign with an optional style string
(string)
an FSW sign with optional style string
string
:
sign svg
// using promise.then
fsw.signSvg('M525x535S2e748483x510S10011501x466S2e704510x500S10019476x475').then( svg => {
console.log(svg)
})
// using async/await
const svg = await fsw.signSvg('M525x535S2e748483x510S10011501x466S2e704510x500S10019476x475')
Function that creates a binary PNG image from an FSW sign with an optional style string
(string)
an FSW sign with optional style string
ArrayBuffer
:
sign png
// using promise.then
fsw.signPng('M525x535S2e748483x510S10011501x466S20544510x500S10019476x475').then( png => {
console.log(png)
})
// using promise.then with options which scales the image to 100 pixels width
fsw.signPng('M525x535S2e748483x510S10011501x466S20544510x500S10019476x475', { width: 100 }).then(png => {
console.log(png)
})
// using async/await
const png = await fsw.signPng('M525x535S2e748483x510S10011501x466S20544510x500S10019476x475')
// using async/await with options which scales the image to 100 pixels width
const png = await fsw.signPng('M525x535S2e748483x510S10011501x466S20544510x500S10019476x475', { width: 100 })
Function that creates a data url PNG image from an FSW sign with an optional style string
(string)
an FSW sign with optional style string
string
:
sign png
// using promise.then
fsw.signPngDataUrl('M525x535S2e748483x510S10011501x466S20544510x500S10019476x475').then( png => {
console.log(png)
})
// using promise.then with options which scales the image to 100 pixels width
fsw.signPngDataUrl('M525x535S2e748483x510S10011501x466S20544510x500S10019476x475', { width: 100 }).then(png => {
console.log(png)
})
// using async/await
const png = await fsw.signPngDataUrl('M525x535S2e748483x510S10011501x466S20544510x500S10019476x475')
// using async/await with options which scales the image to 100 pixels width
const png = await fsw.signPngDataUrl('M525x535S2e748483x510S10011501x466S20544510x500S10019476x475', { width: 100 })
Function that normalizes an FSW sign for a center of 500,500
(string)
an FSW sign with optional style string
string
:
normalized sign
// using promise.then
fsw.signNormalize('M525x535S2e748483x510S10011501x466S2e704510x500S10019476x475').then( norm => {
console.log(norm)
})
// using async/await
const norm = await fsw.signNormalize('M525x535S2e748483x510S10011501x466S2e704510x500S10019476x475')
Function that creates an SVG image for a column of FSW
(ColumnData)
an array of objects with information about FSW signs and punctuation
(ColumnOptions)
an object of column options
string
:
column svg
const columnData = [
{"x":56,"y":20,"minX":481,"minY":471,"width":37,"height":58,"lane":0,"padding":0,"segment":"sign","text":"AS14c20S27106M518x529S14c20481x471S27106503x489","zoom":1},
{"x":57,"y":118,"minX":482,"minY":468,"width":36,"height":65,"lane":0,"padding":0,"segment":"sign","text":"AS18701S1870aS2e734S20500M518x533S1870a489x515S18701482x490S20500508x496S2e734500x468","zoom":1},
{"x":39,"y":203,"minX":464,"minY":496,"width":72,"height":8,"lane":0,"padding":0,"segment":"symbol","text":"S38800464x496","zoom":1}
];
const columnOptions = {"height": 250, "width": 150};
// using promise.then
fsw.columnSvg(columnData, columnOptions).then( svg => {
console.log(svg)
})
// using async/await
const svg = await fsw.columnSvg(columnData, columnOptions)
Function that creates an array of SVG column images for an FSW text
(string)
a text of FSW signs and punctuation
(ColumnOptions)
an object of column options
Array<string>
:
array of svg columns
const fswText = "AS14c20S27106M518x529S14c20481x471S27106503x489 AS18701S1870aS2e734S20500M518x533S1870a489x515S18701482x490S20500508x496S2e734500x468 S38800464x496";
const columnOptions = {"height": 250, "width": 150};
// using promise.then
fsw.columnsSvg(fswText, columnOptions).then( svgs => {
console.log(svgs)
})
// using async/await
const svgs = await fsw.columnsSvg(fswText, columnOptions)
Function that creates an PNG image for a column of FSW
(ColumnData)
an array of objects with information about FSW signs and punctuation
(ColumnOptions)
an object of column options
ArrayBuffer
:
column png
const columnData = [
{"x":56,"y":20,"minX":481,"minY":471,"width":37,"height":58,"lane":0,"padding":0,"segment":"sign","text":"AS14c20S27106M518x529S14c20481x471S27106503x489","zoom":1},
{"x":57,"y":118,"minX":482,"minY":468,"width":36,"height":65,"lane":0,"padding":0,"segment":"sign","text":"AS18701S1870aS2e734S20500M518x533S1870a489x515S18701482x490S20500508x496S2e734500x468","zoom":1},
{"x":39,"y":203,"minX":464,"minY":496,"width":72,"height":8,"lane":0,"padding":0,"segment":"symbol","text":"S38800464x496","zoom":1}
];
const columnOptions = {"height": 250, "width": 150};
// using promise.then
fsw.columnPng(columnData, columnOptions).then( png => {
console.log(png)
})
// using async/await
const png = await fsw.columnPng(columnData, columnOptions)
Function that creates a data url PNG image from an FSW sign with an optional style string
(string)
an FSW sign with optional style string
string
:
column png
const columnData = [
{"x":56,"y":20,"minX":481,"minY":471,"width":37,"height":58,"lane":0,"padding":0,"segment":"sign","text":"AS14c20S27106M518x529S14c20481x471S27106503x489","zoom":1},
{"x":57,"y":118,"minX":482,"minY":468,"width":36,"height":65,"lane":0,"padding":0,"segment":"sign","text":"AS18701S1870aS2e734S20500M518x533S1870a489x515S18701482x490S20500508x496S2e734500x468","zoom":1},
{"x":39,"y":203,"minX":464,"minY":496,"width":72,"height":8,"lane":0,"padding":0,"segment":"symbol","text":"S38800464x496","zoom":1}
];
const columnOptions = {"height": 250, "width": 150};
// using promise.then
fsw.columnPngDataUrl(columnData, columnOptions).then( png => {
console.log(png)
})
// using async/await
const png = await fsw.columnPngDataUrl(columnData, columnOptions)
Function that creates an array of PNG column images for an FSW text
(string)
a text of FSW signs and punctuation
(ColumnOptions)
an object of column options
Array<ArrayBuffer>
:
array of PNG data urls
const fswText = "AS14c20S27106M518x529S14c20481x471S27106503x489 AS18701S1870aS2e734S20500M518x533S1870a489x515S18701482x490S20500508x496S2e734500x468 S38800464x496";
const columnOptions = {"height": 250, "width": 150};
// using promise.then
fsw.columnsPng(fswText, columnOptions).then( pngs => {
console.log(pngs)
})
// using async/await
const pngs = await fsw.columnsPng(fswText, columnOptions)
Function that creates an array of PNG column images for an FSW text
(string)
a text of FSW signs and punctuation
(ColumnOptions)
an object of column options
Array<string>
:
array of PNG data urls
const fswText = "AS14c20S27106M518x529S14c20481x471S27106503x489 AS18701S1870aS2e734S20500M518x533S1870a489x515S18701482x490S20500508x496S2e734500x468 S38800464x496";
const columnOptions = {"height": 250, "width": 150};
// using promise.then
fsw.columnsPng(fswText, columnOptions).then( pngs => {
console.log(pngs)
})
// using async/await
const pngs = await fsw.columnsPng(fswText, columnOptions)
The swu module contains functions for handling Formal SignWriitng in ASCII (SWU) characters. SWU characters definition
Function that creates an SVG image from an SWU symbol key with an optional style string
(string)
an SWU symbol key with optional style string
string
:
symbol svg body
// using promise.then
swu.symbolSvgBody('-C').then( svg => {
console.log(svg)
})
// using async/await
const svg = await swu.symbolSvgBody('-C')
Function that creates an SVG image from an SWU symbol key with an optional style string
(string)
an SWU symbol key with optional style string
string
:
symbol svg
// using promise.then
swu.symbolSvg('-C').then( svg => {
console.log(svg)
})
// using async/await
const svg = await swu.symbolSvg('-C')
Function that creates a binary PNG image from an SWU symbol key with an optional style string
(string)
an SWU symbol key with optional style string
ArrayBuffer
:
symbol png
// using promise.then
swu.symbolPng('-C').then( png => {
console.log(png)
})
// using promise.then with options which scales the image to 100 pixels width
swu.symbolPng('-C', { width: 100 }).then( png => {
console.log(png)
})
// using async/await
const png = await swu.symbolPng('-C')
// using async/await with options which scales the image to 100 pixels width
const png = await swu.symbolPng('-C', { width: 100 })
Function that creates a data url PNG image from an SWU symbol key with an optional stle string
(string)
an SWU symbol key with optional style string
string
:
symbol png
// using promise.then
swu.symbolPndDataUrl('-C').then( png => {
console.log(png)
})
// using promise.then with options which scales the image to 100 pixels width
swu.symbolPndDataUrl('-C', { width: 100 }).then( png => {
console.log(png)
})
// using async/await
const png = await swu.symbolPndDataUrl('-C')
// using async/await with options which scales the image to 100 pixels width
const png = await swu.symbolPndDataUrl('-C', { width: 100 })
Function that normalizes a symbol with a minimum coordinate for a center of 500,500
(string)
an SWU symbol with optional coordinate and style string
string
:
normalized symbol
// using promise.then
swu.symbolNormalize('-C').then( norm => {
console.log(norm)
})
// using async/await
const norm = await swu.symbolNormalize('-C')
Function that creates an SVG image from an SWU sign with an optional style string
(string)
an SWU sign with optional style string
string
:
sign svg body
// using promise.then
swu.signSvgBody('𝠃𝤟𝤩𝣵𝤐𝤇𝣤𝤐𝤆𝣮𝣭').then( svg => {
console.log(svg)
})
// using async/await
const svg = await swu.signSvgBody('𝠃𝤟𝤩𝣵𝤐𝤇𝣤𝤐𝤆𝣮𝣭')
Function that creates an SVG image from an SWU sign with an optional style string
(string)
an SWU sign with optional style string
string
:
sign svg
// using promise.then
swu.signSvg('𝠃𝤟𝤩𝣵𝤐𝤇𝣤𝤐𝤆𝣮𝣭').then( svg => {
console.log(svg)
})
// using async/await
const svg = await swu.signSvg('𝠃𝤟𝤩𝣵𝤐𝤇𝣤𝤐𝤆𝣮𝣭')
Function that creates a binary PNG image from an SWU sign with an optional style string
(string)
an SWU sign with optional style string
ArrayBuffer
:
sign png
// using promise.then
swu.signPng('𝠃𝤟𝤩𝣵𝤐𝤇𝣤𝤐𝤆𝣮𝣭').then( png => {
console.log(png)
})
// using promise.then with options which scales the image to 100 pixels width
swu.signPng('𝠃𝤟𝤩𝣵𝤐𝤇𝣤𝤐𝤆𝣮𝣭', { width: 100 }).then( png => {
console.log(png)
})
// using async/await
const png = await swu.signPng('𝠃𝤟𝤩𝣵𝤐𝤇𝣤𝤐𝤆𝣮𝣭')
// using async/await with options which scales the image to 100 pixels width
const png = await swu.signPng('𝠃𝤟𝤩𝣵𝤐𝤇𝣤𝤐𝤆𝣮𝣭', { width: 100 })
Function that creates a data url PNG image from an SWU sign with an optional style string
(string)
an SWU sign with optional style string
string
:
sign png
// using promise.then
swu.signPngDataUrl('𝠃𝤟𝤩𝣵𝤐𝤇𝣤𝤐𝤆𝣮𝣭').then( png => {
console.log(png)
})
// using promise.then with options which scales the image to 100 pixels width
swu.signPngDataUrl('𝠃𝤟𝤩𝣵𝤐𝤇𝣤𝤐𝤆𝣮𝣭', { width: 100 }).then( png => {
console.log(png)
})
// using async/await
const png = await swu.signPngDataUrl('𝠃𝤟𝤩𝣵𝤐𝤇𝣤𝤐𝤆𝣮𝣭')
// using async/await with options which scales the image to 100 pixels width
const png = await swu.signPngDataUrl('𝠃𝤟𝤩𝣵𝤐𝤇𝣤𝤐𝤆𝣮𝣭', { width: 100 })
Function that normalizes an SWU sign for a center of 500,500
(string)
an SWU sign with optional style string
string
:
normalized sign
// using promise.then
swu.signNormalize('𝠃𝤟𝤩𝣵𝤐𝤇𝣤𝤐𝤆𝣮𝣭').then( norm => {
console.log(norm)
})
// using async/await
const norm = await swu.signNormalize('𝠃𝤟𝤩𝣵𝤐𝤇𝣤𝤐𝤆𝣮𝣭')
Function that creates an SVG image for a column of SWU
(ColumnData)
an array of objects with information about SWU signs and punctuation
(ColumnOptions)
an object of column options
string
:
column svg
const columnData = [
{"x":56,"y":20,"minX":481,"minY":471,"width":37,"height":58,"lane":0,"padding":0,"segment":"sign","text":"𝠀𝠃𝤘𝤣𝣳𝣩𝤉𝣻","zoom":1},
{"x":57,"y":118,"minX":482,"minY":468,"width":36,"height":65,"lane":0,"padding":0,"segment":"sign","text":"𝠀𝠃𝤘𝤧𝣻𝤕𝣴𝣼𝤎𝤂𝤆𝣦","zoom":1},
{"x":39,"y":203,"minX":464,"minY":496,"width":72,"height":8,"lane":0,"padding":0,"segment":"symbol","text":"𝣢𝤂","zoom":1}
];
const columnOptions = {"height": 250, "width": 150};
// using promise.then
swu.columnSvg(columnData, columnOptions).then( svg => {
console.log(svg)
})
// using async/await
const svg = await swu.columnSvg(columnData, columnOptions)
Function that creates an array of SVG column images for an SWU text
(string)
a text of SWU signs and punctuation
(ColumnOptions)
an object of column options
Array<string>
:
array of svg columns
const swuText = "𝠀𝠃𝤘𝤣𝣳𝣩𝤉𝣻 𝠀𝠃𝤘𝤧𝣻𝤕𝣴𝣼𝤎𝤂𝤆𝣦 𝣢𝤂";
const columnOptions = {"height": 250, "width": 150};
// using promise.then
swu.columnsSvg(swuText, columnOptions).then( svgs => {
console.log(svgs)
})
// using async/await
const svgs = await swu.columnsSvg(swuText, columnOptions)
Function that creates an PNG image for a column of SWU
(ColumnData)
an array of objects with information about SWU signs and punctuation
(ColumnOptions)
an object of column options
ArrayBuffer
:
column png
const columnData = [
{"x":56,"y":20,"minX":481,"minY":471,"width":37,"height":58,"lane":0,"padding":0,"segment":"sign","text":"𝠀𝠃𝤘𝤣𝣳𝣩𝤉𝣻","zoom":1},
{"x":57,"y":118,"minX":482,"minY":468,"width":36,"height":65,"lane":0,"padding":0,"segment":"sign","text":"𝠀𝠃𝤘𝤧𝣻𝤕𝣴𝣼𝤎𝤂𝤆𝣦","zoom":1},
{"x":39,"y":203,"minX":464,"minY":496,"width":72,"height":8,"lane":0,"padding":0,"segment":"symbol","text":"𝣢𝤂","zoom":1}
];
const columnOptions = {"height": 250, "width": 150};
// using promise.then
swu.columnPng(columnData, columnOptions).then( png => {
console.log(png)
})
// using async/await
const png = await swu.columnPng(columnData, columnOptions)
Function that creates a data url PNG image from an SWU sign with an optional style string
(string)
an SWU sign with optional style string
string
:
column png
const columnData = [
{"x":56,"y":20,"minX":481,"minY":471,"width":37,"height":58,"lane":0,"padding":0,"segment":"sign","text":"𝠀𝠃𝤘𝤣𝣳𝣩𝤉𝣻","zoom":1},
{"x":57,"y":118,"minX":482,"minY":468,"width":36,"height":65,"lane":0,"padding":0,"segment":"sign","text":"𝠀𝠃𝤘𝤧𝣻𝤕𝣴𝣼𝤎𝤂𝤆𝣦","zoom":1},
{"x":39,"y":203,"minX":464,"minY":496,"width":72,"height":8,"lane":0,"padding":0,"segment":"symbol","text":"𝣢𝤂","zoom":1}
];
const columnOptions = {"height": 250, "width": 150};
// using promise.then
swu.columnPngDataUrl(columnData, columnOptions).then( png => {
console.log(png)
})
// using async/await
const png = await swu.columnPngDataUrl(columnData, columnOptions)
Function that creates an array of PNG column images for an SWU text
(string)
a text of SWU signs and punctuation
(ColumnOptions)
an object of column options
Array<ArrayBuffer>
:
array of PNG data urls
const swuText = "𝠀𝠃𝤘𝤣𝣳𝣩𝤉𝣻 𝠀𝠃𝤘𝤧𝣻𝤕𝣴𝣼𝤎𝤂𝤆𝣦 𝣢𝤂";
const columnOptions = {"height": 250, "width": 150};
// using promise.then
swu.columnsPng(swuText, columnOptions).then( pngs => {
console.log(pngs)
})
// using async/await
const pngs = await swu.columnsPng(swuText, columnOptions)
Function that creates an array of PNG column images for an SWU text
(string)
a text of SWU signs and punctuation
(ColumnOptions)
an object of column options
Array<string>
:
array of PNG data urls
const swuText = "𝠀𝠃𝤘𝤣𝣳𝣩𝤉𝣻 𝠀𝠃𝤘𝤧𝣻𝤕𝣴𝣼𝤎𝤂𝤆𝣦 𝣢𝤂";
const columnOptions = {"height": 250, "width": 150};
// using promise.then
swu.columnsPng(swuText, columnOptions).then( pngs => {
console.log(pngs)
})
// using async/await
const pngs = await swu.columnsPng(swuText, columnOptions)
The elements of a style string
Type: object
(boolean)
: boolean to use standardized colors for symbol groups
(number)
: integer value for padding around symbol or sign
(string)
: css name or hex color for background
(array)
: array for css name or hex color for line and optional fill
(number)
: decimal value for zoom level
(string)
: list of class names separated with spaces used for SVG
(string)
: id name used for SVG
Type: object
(number)
: the height of the columns
(number)
: the widths of the columns
(number)
: the lane offset for left and right lanes
(number)
: amount of padding before and after signs as well as at top, left, and right of columns
(number)
: amount of space at bottom of column that is not available
(boolean)
: enables variable width columns
(string)
: background color for columns
(StyleObject)
: an object of style options
(object)
: an object of punctuation options
punctuation.spacing
boolean
enables special spacing for punctuation with no space above and custom space below
punctuation.pad
number
the amount of spacing after a punctuation if punctuation spacing is enabled
punctuation.pull
boolean
prevents line breaks before punctuation by reducing spacing between signs in a column
Type: Array<ColumnSegment>
Type: object
(number)
: the x position in the column
(number)
: the y position in the column
(number)
: the min x value within the segment
(number)
: the min y value within the segment
(number)
: the width of the text segment
(number)
: the height of the text segment
(number)
: Left as -1, Middle as 0, Right as 1
(number)
: the padding of the text segment affects colored background
(string)
: "sign" or "symbol"
(string)
: the text of the sign or symbol with optional style string
(number)
: the zoom size of the segment
Convert SVG to PNG
(string)
SVG string
(any
= {}
)
Promise<Buffer>
:
PNG buffer