Allow specifying a custom font path in the library
This commit is contained in:
parent
fa736619bb
commit
7ea0d811a5
27
INSTALL.md
27
INSTALL.md
|
@ -18,10 +18,13 @@ npm install gh-badges
|
|||
|
||||
```js
|
||||
var badge = require('gh-badges');
|
||||
badge({ text: [ "build", "passed" ], colorscheme: "green" },
|
||||
function(svg, err) {
|
||||
// svg is a String… of your badge.
|
||||
});
|
||||
// Optional step, to have accurate text width computation.
|
||||
badge.loadFont('/path/to/Verdana.ttf', function(err) {
|
||||
badge({ text: ["build", "passed"], colorscheme: "green", template: "flat" },
|
||||
function(svg, err) {
|
||||
// svg is a String of your badge.
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
# Use the CLI
|
||||
|
@ -35,12 +38,11 @@ badge build passed :green .png > mybadge.png
|
|||
# Start the Server
|
||||
To run the server you will need the following executables on your Path:
|
||||
- [PhantomJS](http://www.phantomjs.org/)
|
||||
- [Cairo](http://cairographics.org/) (runtime dependency for Canvas)
|
||||
|
||||
On an OS X machine, [Homebrew](brew.sh) is a good package manager that will
|
||||
allow you to install them.
|
||||
allow you to install that.
|
||||
|
||||
On Ubuntu / Debian: `sudo apt-get install phantomjs libcairo2-dev libjpeg-turbo8-dev`.
|
||||
On Ubuntu / Debian: `sudo apt-get install phantomjs`.
|
||||
|
||||
```bash
|
||||
git clone https://github.com/badges/shields.git
|
||||
|
@ -104,17 +106,6 @@ 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.
|
||||
|
||||
# Requirements
|
||||
|
||||
Because of the usage of the npm module [canvas][canvas-pkg] *you need* to have
|
||||
**cairo** installed.
|
||||
|
||||
For more information check the [wiki][canvas-wiki] of the canvas project with
|
||||
system-specific installation details.
|
||||
|
||||
[canvas-pkg]: https://npmjs.org/package/canvas
|
||||
[canvas-wiki]: https://github.com/LearnBoost/node-canvas/wiki/_pages
|
||||
|
||||
# Making your Heroku badge server
|
||||
|
||||
Once you have installed the [Heroku Toolbelt][]:
|
||||
|
|
1
badge.js
1
badge.js
|
@ -99,3 +99,4 @@ function makeImage(data, cb) {
|
|||
}
|
||||
|
||||
module.exports = makeImage;
|
||||
module.exports.loadFont = measureTextWidth.loadFont;
|
||||
|
|
|
@ -3,17 +3,26 @@
|
|||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
var PDFDocument = require('pdfkit');
|
||||
var doc = new PDFDocument({size:'A4', layout:'landscape'});
|
||||
|
||||
var doc = (new PDFDocument({size:'A4', layout:'landscape'}));
|
||||
try {
|
||||
doc = doc.font(path.join(__dirname, 'Verdana.ttf'));
|
||||
} catch (ex) {
|
||||
doc = doc.font('Helvetica-Bold')
|
||||
console.warn('Could not load font file "Verdana.ttf", text widths will therefore be approximate', ex);
|
||||
// Attempt to use a particular font.
|
||||
// callback: (optional) takes an error if it failed.
|
||||
function loadFont(path, callback) {
|
||||
try {
|
||||
doc = doc.font(path);
|
||||
if (callback) { callback(null); }
|
||||
} catch(err) {
|
||||
doc = doc.font('Helvetica-Bold');
|
||||
if (callback) { callback(err); }
|
||||
}
|
||||
}
|
||||
|
||||
loadFont(path.join(__dirname, 'Verdana.ttf'));
|
||||
doc = doc.fontSize(11);
|
||||
|
||||
module.exports = measure;
|
||||
function measure(str) {
|
||||
return doc.widthOfString(str);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = measure;
|
||||
module.exports.loadFont = loadFont;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
{
|
||||
"name": "gh-badges",
|
||||
"version": "1.2.2",
|
||||
"description": "GitHub badges implemented in SVG.",
|
||||
"keywords": ["GitHub", "badge", "SVG", "image"],
|
||||
"version": "1.3.0",
|
||||
"description": "Official Shields.io badge library.",
|
||||
"keywords": ["GitHub", "badge", "SVG", "image", "shields.io"],
|
||||
"homepage": "http://shields.io",
|
||||
"bugs": {
|
||||
"url": "https://github.com/badges/shields/issues",
|
||||
|
|
Loading…
Reference in New Issue
Block a user