Commit 7ea0d811 authored by Thaddee Tyl's avatar Thaddee Tyl
Browse files

Allow specifying a custom font path in the library

parent fa736619
......@@ -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][]:
......
......@@ -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);
}
\ No newline at end of file
}
module.exports = measure;
module.exports.loadFont = loadFont;
{
"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",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment