Skip to content

Commit 6f62818

Browse files
committed
Merge remote-tracking branch 'Automattic/master' into static
2 parents c65bfb9 + 188c4ca commit 6f62818

35 files changed

+2845
-2824
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ node_js:
44
- '4'
55
- '0.12'
66
- '0.10'
7-
- '0.8'
87
addons:
98
apt:
109
sources:
@@ -18,6 +17,5 @@ addons:
1817
env:
1918
- CXX=g++-4.9
2019
before_install:
21-
- if [[ $TRAVIS_NODE_VERSION == 0.8 ]]; then npm install -g [email protected]; fi
2220
- npm explore npm -g -- npm install node-gyp@latest
2321
sudo: false

History.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
1.6.0 / 2016-10-16
2+
==================
3+
4+
* Support canvas.getBuffer('raw') (#819)
5+
16
1.5.0 / 2016-09-11
27
==================
38

Readme.md

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
node-canvas
2-
===========
1+
# node-canvas
2+
3+
-----
4+
5+
## This is the documentation for the unreleased version 2.0
6+
7+
**For the current version 1.x documentation, see [the v1.x branch](https://github.com/Automattic/node-canvas/tree/v1.x)**
8+
9+
-----
10+
311
### Canvas graphics API backed by Cairo
412
[![Build Status](https://travis-ci.org/Automattic/node-canvas.svg?branch=master)](https://travis-ci.org/Automattic/node-canvas)
513
[![NPM version](https://badge.fury.io/js/canvas.svg)](http://badge.fury.io/js/canvas)
@@ -19,16 +27,18 @@ node-canvas
1927
$ npm install canvas
2028
```
2129

22-
Unless previously installed you'll _need_ __Cairo__. For system-specific installation view the [Wiki](https://github.com/Automattic/node-canvas/wiki/_pages).
30+
Unless previously installed you'll _need_ __Cairo__ and __Pango__. For system-specific installation view the [Wiki](https://github.com/Automattic/node-canvas/wiki/_pages).
31+
32+
Currently the minimum version of node required is __0.10.0__
2333

2434
You can quickly install the dependencies by using the command for your OS:
2535

2636
OS | Command
2737
----- | -----
28-
OS X | `brew install pkg-config cairo libpng jpeg giflib`
38+
OS X | `brew install pkg-config cairo pango libpng jpeg giflib`
2939
Ubuntu | `sudo apt-get install libcairo2-dev libjpeg8-dev libpango1.0-dev libgif-dev build-essential g++`
3040
Fedora | `sudo yum install cairo cairo-devel cairomm-devel libjpeg-turbo-devel pango pango-devel pangomm pangomm-devel giflib-devel`
31-
Solaris | `pkgin install cairo pkg-config xproto renderproto kbproto xextproto`
41+
Solaris | `pkgin install cairo pango pkg-config xproto renderproto kbproto xextproto`
3242
Windows | [Instructions on our wiki](https://github.com/Automattic/node-canvas/wiki/Installation---Windows)
3343

3444
**El Capitan users:** If you have recently updated to El Capitan and are experiencing trouble when compiling, run the following command: `xcode-select --install`. Read more about the problem [on Stack Overflow](http://stackoverflow.com/a/32929012/148072).
@@ -140,10 +150,22 @@ var stream = canvas.jpegStream({
140150

141151
### Canvas#toBuffer()
142152

143-
A call to `Canvas#toBuffer()` will return a node `Buffer` instance containing all of the PNG data.
153+
A call to `Canvas#toBuffer()` will return a node `Buffer` instance containing image data.
144154

145155
```javascript
146-
canvas.toBuffer();
156+
// PNG Buffer, default settings
157+
var buf = canvas.toBuffer();
158+
159+
// PNG Buffer, zlib compression level 3 (from 0-9), faster but bigger
160+
var buf2 = canvas.toBuffer(undefined, 3, canvas.PNG_FILTER_NONE);
161+
162+
// ARGB32 Buffer, native-endian
163+
var buf3 = canvas.toBuffer('raw');
164+
var stride = canvas.stride;
165+
// In memory, this is `canvas.height * canvas.stride` bytes long.
166+
// The top row of pixels, in ARGB order, left-to-right, is:
167+
var topPixelsARGBLeftToRight = buf3.slice(0, canvas.width * 4);
168+
var row3 = buf3.slice(2 * canvas.stride, 2 * canvas.stride + canvas.width * 4);
147169
```
148170

149171
### Canvas#toBuffer() async
@@ -170,6 +192,26 @@ canvas.toDataURL('image/jpeg', {opts...}, function(err, jpeg){ }); // see Canvas
170192
canvas.toDataURL('image/jpeg', quality, function(err, jpeg){ }); // spec-following; quality from 0 to 1
171193
```
172194

195+
### Canvas.registerFont for bundled fonts
196+
197+
It can be useful to use a custom font file if you are distributing code that uses node-canvas and a specific font. Or perhaps you are using it to do automated tests and you want the renderings to be the same across operating systems regardless of what fonts are installed.
198+
199+
To do that, you should use `Canvas.registerFont`.
200+
201+
**You need to call it before the Canvas is created**
202+
203+
```javascript
204+
Canvas.registerFont('comicsans.ttf', {family: 'Comic Sans'});
205+
206+
var canvas = new Canvas(500, 500),
207+
ctx = canvas.getContext('2d');
208+
209+
ctx.font = '12px "Comic Sans"';
210+
ctx.fillText(250, 10, 'Everyone hates this font :(');
211+
```
212+
213+
The second argument is an object with properties that resemble the CSS properties that are specified in `@font-face` rules. You must specify at least `family`. `weight`, and `style` are optional (and default to "normal").
214+
173215
### CanvasRenderingContext2D#patternQuality
174216

175217
Given one of the values below will alter pattern (gradients, images, etc) render quality, defaults to _good_.
@@ -298,16 +340,6 @@ Visual tests:
298340

299341
$ make test-server
300342

301-
## Versions
302-
303-
Tested with and designed for:
304-
305-
- node 0.4.2
306-
- cairo 1.8.6
307-
308-
For node 0.2.x `node-canvas` <= 0.4.3 may be used,
309-
0.5.0 and above are designed for node 0.4.x only.
310-
311343
## License
312344

313345
(The MIT License)

0 commit comments

Comments
 (0)