This simplifies and further optimizes text-width computation by computing the entire width table in advance, and serializing it in the style of QuickTextMeasurer (#1390). This entirely removes the need for PDFKit at runtime. This has the advantage of fixing #1305 – more generally: producing the same result everywhere – without having to deploy a copy of Verdana. The lifting is delegated to these three libraries, which are housed in a monorepo: https://github.com/metabolize/anafanafo I'd be happy to move it into the badges org if folks want to collaborate on maintaining them. QuickTextMeasurer took kerning pairs into account, whereas this implementation does not. I was thinking kerning would be a necessary refinement, though this seems to work well enough. I dropped in a binary-search package to traverse the data structure, in part to conserve space. This causes a moderate performance regression, though there is ample room for improving on that: https://github.com/badges/shields/pull/2311#issuecomment-439182704
1.8 KiB
1.8 KiB
gh-badges
Installation
npm install gh-badges
Usage
On the console
npm install -g gh-badges
badge build passed :green .png > mybadge.png
As a library
const { BadgeFactory } = require('gh-badges')
const bf = new BadgeFactory()
const format = {
text: ['build', 'passed'],
colorscheme: 'green',
template: 'flat',
}
const svg = bf.create(format)
Format
The format is the following:
{
text: [ 'build', 'passed' ], // Textual information shown, in order
format: 'svg', // Also supports json
colorscheme: 'green',
// or ...
colorA: '#555',
colorB: '#4c1',
// See templates/ for a list of available templates.
// Each offers a different visual design.
template: 'flat',
}
See also
- colorscheme.json for the
colorschemeoption - templates/ for the
templateoption
Defaults
If you want to use a colorscheme, head to lib/colorscheme.json. Each scheme
has a name and a CSS/SVG color for the color used in the first box (for the
first piece of text, field colorA) and for the one used in the second box
(field colorB).
"green": {
"colorB": "#4c1"
}
Both colorA and colorB have default values. Usually, the first box uses the
same dark grey, so you can rely on that default value by not providing a
"colorA" field (such as above).
You can also use the "colorA" and "colorB" fields directly in the badges if
you don't want to make a color scheme for it. In that case, remove the
"colorscheme" field altogether.