Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Automattic/node-canvas
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 58bc728df354c4d9a0e8a25d5b04710bfb8fb7e9
Choose a base ref
...
head repository: Automattic/node-canvas
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8707f3d693366a50e60b028404be606042025c51
Choose a head ref

Commits on Aug 19, 2020

  1. translate "sans-serif" to "sans" for Pango

    Fixes #1643
    chearon authored and zbjornson committed Aug 19, 2020
    1
    Copy the full SHA
    5054b7b View commit details
  2. Add invertSelf to the DOMMatrix object (#1649)

    * Add invertSelf + inverse to the DOMMatrix object
    
    * return early for non-invertible + test
    
    * made non-invertible return early, with tests
    Pomax authored Aug 19, 2020
    Copy the full SHA
    595d559 View commit details

Commits on Oct 4, 2020

  1. Fix PNG stream method name in benchmark (fixes #1672)

    * fixes #1672, updated `createSyncPNGStream` to `createPNGStream`
    
    * fix #1672 reflected in changelog
    gregzanch authored Oct 4, 2020
    1
    Copy the full SHA
    41d1c99 View commit details

Commits on Oct 26, 2020

  1. 1
    Copy the full SHA
    e476656 View commit details

Commits on Feb 27, 2021

  1. add Dockerfile for linux prebuild image

    chearon authored and zbjornson committed Feb 27, 2021
    Copy the full SHA
    beaee39 View commit details
  2. Copy the full SHA
    547b050 View commit details
  3. Fix dtslint failing in CI

    Version update needs typescript as a peer dependency.
    zbjornson committed Feb 27, 2021
    Copy the full SHA
    f8305fb View commit details
  4. Fix Windows CI build, add Node.js v15

    I don't know why redirects aren't working here. It's possible that the GitHub Actions runner is getting redirected to HTTP, which fails (PowerShell/PowerShell#2896), but Invoke-WebRequest has no way to log what it's doing. Hard-coding a mirror works (for now).
    zbjornson committed Feb 27, 2021
    Copy the full SHA
    b549ab6 View commit details
  5. Update changelog

    zbjornson committed Feb 27, 2021
    Copy the full SHA
    646b605 View commit details

Commits on Feb 28, 2021

  1. Fix always-false comparison warning in Canvas.cc in Node 15+

    Node.js v15 (V8 8.6) has kMaxLength of u64{1}<<32, which is statically determinable to be larger than the largest uint32_t:
    
    ```
    warning: comparison is always false due to limited range of data type [-Wtype-limits]
         if (static_cast<uint32_t>(canvas->nBytes()) > node::Buffer::kMaxLength) {
    ```
    zbjornson committed Feb 28, 2021
    Copy the full SHA
    7a84fc5 View commit details
  2. Use node pre gyp v1

    domoritz authored and zbjornson committed Feb 28, 2021
    1
    Copy the full SHA
    6fae569 View commit details
  3. Update changelog

    zbjornson committed Feb 28, 2021
    Copy the full SHA
    8cd191c View commit details
  4. Fix crash if exception thrown from onload/onerror

    If a user-provided .onload or .onerror handler on an Image throws an
    exception, the Node.js process crashes:
    
        FATAL ERROR: v8::ToLocalChecked Empty MaybeLocal.
         1: 0x94d778 node::Abort() [node]
         2: 0x94edb1 node::OnFatalError(char const*, char const*) [node]
         3: 0xad5b0d v8::Utils::ReportApiFailure(char const*, char const*) [node]
         4: 0x7f98f47799ae Image::SetSource(Nan::FunctionCallbackInfo<v8::Value> const&) [/home/strager/tmp/Projects/node-canvas/build/Release/canvas.node]
         5: 0x7f98f4774fec  [/home/strager/tmp/Projects/node-canvas/build/Release/canvas.node]
         6: 0xb395b9 v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo) [node]
         7: 0xb39970  [node]
         8: 0xb3a1ea  [node]
         9: 0xb3aa99 v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) [node]
        10: 0x12e89b9  [node]
    
    Fix this issue by not requiring a return value from the .onload and
    .onerror functions.
    strager authored and zbjornson committed Feb 28, 2021
    Copy the full SHA
    12e671d View commit details

Commits on Apr 20, 2021

  1. Loosen text measurement expectation.

    Cherry-picked out of f0974bc.
    Ref #1776 (review)
    zbjornson committed Apr 20, 2021
    Copy the full SHA
    e4f901c View commit details
  2. Fix text actualBoundingBoxLeft and actualBoundingBoxRight measures by…

    … using ink_rect instead of logical_rect
    Mickaël Sérégé authored and zbjornson committed Apr 20, 2021
    Copy the full SHA
    234e659 View commit details
  3. Copy the full SHA
    d107c04 View commit details
  4. Add ctx2d.getTransform() function

    Based on currentTransform getter
    Tirondzo authored and zbjornson committed Apr 20, 2021
    Copy the full SHA
    2f84eee View commit details
  5. Add ctx2d.setTransform(mat) overload

    Based on currentTransform setter
    Tirondzo authored and zbjornson committed Apr 20, 2021
    Copy the full SHA
    c166443 View commit details
  6. Copy the full SHA
    0b49442 View commit details

Commits on May 5, 2021

  1. Copy the full SHA
    2bf76b5 View commit details
  2. Copy the full SHA
    5b5140e View commit details

Commits on May 16, 2021

  1. v2.8.0

    zbjornson committed May 16, 2021
    Copy the full SHA
    8707f3d View commit details
11 changes: 5 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -6,15 +6,14 @@ on:
pull_request:
paths-ignore:
- ".github/workflows/prebuild.yaml"


jobs:
Linux:
name: Test on Linux
runs-on: ubuntu-latest
strategy:
matrix:
node: [10, 12, 14]
node: [10, 12, 14, 16]
steps:
- uses: actions/setup-node@v1
with:
@@ -34,15 +33,15 @@ jobs:
runs-on: windows-latest
strategy:
matrix:
node: [10, 12, 14]
node: [10, 12, 14, 16]
steps:
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- uses: actions/checkout@v2
- name: Install Dependencies
run: |
Invoke-WebRequest "http://ftp.gnome.org/pub/GNOME/binaries/win64/gtk+/2.22/gtk+-bundle_2.22.1-20101229_win64.zip" -OutFile "gtk.zip"
Invoke-WebRequest "https://ftp-osl.osuosl.org/pub/gnome/binaries/win64/gtk+/2.22/gtk+-bundle_2.22.1-20101229_win64.zip" -OutFile "gtk.zip"
Expand-Archive gtk.zip -DestinationPath "C:\GTK"
Invoke-WebRequest "https://downloads.sourceforge.net/project/libjpeg-turbo/2.0.4/libjpeg-turbo-2.0.4-vc64.exe" -OutFile "libjpeg.exe" -UserAgent NativeHost
.\libjpeg.exe /S
@@ -56,7 +55,7 @@ jobs:
runs-on: macos-latest
strategy:
matrix:
node: [10, 12, 14]
node: [10, 12, 14, 16]
steps:
- uses: actions/setup-node@v1
with:
@@ -77,7 +76,7 @@ jobs:
steps:
- uses: actions/setup-node@v1
with:
node-version: 12
node-version: 14
- uses: actions/checkout@v2
- name: Install
run: npm install --ignore-scripts
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -11,6 +11,30 @@ project adheres to [Semantic Versioning](http://semver.org/).
### Added
### Fixed

2.8.0
==================
### Changed
* Upgrade dtslint
* Upgrade node-pre-gyp to 1.0.0. Note that if you are using special node-pre-gyp
features like `node_pre_gyp_accessKeyId`, you may need to make changes to your
installation procedure. See https://github.com/mapbox/node-pre-gyp/blob/master/CHANGELOG.md#100.
* Add Node.js v16 to CI.
* The C++ class method `nBytes()` now returns a size_t. (Because this is a C++
method only, this is not considered a breaking change.)
* Export type NodeCanvasRenderingContext2D so you can pass the current context
to functions (TypeScript).
### Added
* Add support for `inverse()` and `invertSelf()` to `DOMMatrix` (#1648)
* Add support for `context.getTransform()` ([#1769](https://github.com/Automattic/node-canvas/pull/1769))
* Add support for `context.setTransform(dommatrix)` ([#1769](https://github.com/Automattic/node-canvas/pull/1769))
### Fixed
* Fix `actualBoundingBoxLeft` and `actualBoundingBoxRight` returned by `measureText` to be the ink rect ([#1776](https://github.com/Automattic/node-canvas/pull/1776), fixes [#1703](https://github.com/Automattic/node-canvas/issues/1703)).
* Fix Pango logging "expect ugly output" on Windows (#1643)
* Fix benchmark for createPNGStream (#1672)
* Fix dangling reference in BackendOperationNotAvailable exception (#1740)
* Fix always-false comparison warning in Canvas.cc.
* Fix Node.js crash when throwing from an onload or onerror handler.

2.7.0
==================
### Changed
2 changes: 1 addition & 1 deletion benchmarks/run.js
Original file line number Diff line number Diff line change
@@ -157,7 +157,7 @@ bm('getImageData(0,0,100,100)', function () {
})

bm('PNGStream 200x200', function (done) {
var stream = canvas.createSyncPNGStream()
var stream = canvas.createPNGStream()
stream.on('data', function (chunk) {
// whatever
})
137 changes: 132 additions & 5 deletions lib/DOMMatrix.js
Original file line number Diff line number Diff line change
@@ -425,7 +425,7 @@ DOMMatrix.prototype.skewYSelf = function (sy) {
return this
}

DOMMatrix.prototype.flipX = function () {
DOMMatrix.prototype.flipX = function () {
return newInstance(multiply([
-1, 0, 0, 0,
0, 1, 0, 0,
@@ -446,8 +446,135 @@ DOMMatrix.prototype.inverse = function () {
return newInstance(this._values).invertSelf()
}
DOMMatrix.prototype.invertSelf = function () {
// If not invertible, set all attributes to NaN and is2D to false
throw new Error('Not implemented')
var m = this._values;
var inv = m.map(v => 0);

inv[0] = m[5] * m[10] * m[15] -
m[5] * m[11] * m[14] -
m[9] * m[6] * m[15] +
m[9] * m[7] * m[14] +
m[13] * m[6] * m[11] -
m[13] * m[7] * m[10];

inv[4] = -m[4] * m[10] * m[15] +
m[4] * m[11] * m[14] +
m[8] * m[6] * m[15] -
m[8] * m[7] * m[14] -
m[12] * m[6] * m[11] +
m[12] * m[7] * m[10];

inv[8] = m[4] * m[9] * m[15] -
m[4] * m[11] * m[13] -
m[8] * m[5] * m[15] +
m[8] * m[7] * m[13] +
m[12] * m[5] * m[11] -
m[12] * m[7] * m[9];

inv[12] = -m[4] * m[9] * m[14] +
m[4] * m[10] * m[13] +
m[8] * m[5] * m[14] -
m[8] * m[6] * m[13] -
m[12] * m[5] * m[10] +
m[12] * m[6] * m[9];

// If the determinant is zero, this matrix cannot be inverted, and all
// values should be set to NaN, with the is2D flag set to false.

var det = m[0] * inv[0] + m[1] * inv[4] + m[2] * inv[8] + m[3] * inv[12];

if (det === 0) {
this._values = m.map(v => NaN);
this._is2D = false;
return this;
}

inv[1] = -m[1] * m[10] * m[15] +
m[1] * m[11] * m[14] +
m[9] * m[2] * m[15] -
m[9] * m[3] * m[14] -
m[13] * m[2] * m[11] +
m[13] * m[3] * m[10];

inv[5] = m[0] * m[10] * m[15] -
m[0] * m[11] * m[14] -
m[8] * m[2] * m[15] +
m[8] * m[3] * m[14] +
m[12] * m[2] * m[11] -
m[12] * m[3] * m[10];

inv[9] = -m[0] * m[9] * m[15] +
m[0] * m[11] * m[13] +
m[8] * m[1] * m[15] -
m[8] * m[3] * m[13] -
m[12] * m[1] * m[11] +
m[12] * m[3] * m[9];

inv[13] = m[0] * m[9] * m[14] -
m[0] * m[10] * m[13] -
m[8] * m[1] * m[14] +
m[8] * m[2] * m[13] +
m[12] * m[1] * m[10] -
m[12] * m[2] * m[9];

inv[2] = m[1] * m[6] * m[15] -
m[1] * m[7] * m[14] -
m[5] * m[2] * m[15] +
m[5] * m[3] * m[14] +
m[13] * m[2] * m[7] -
m[13] * m[3] * m[6];

inv[6] = -m[0] * m[6] * m[15] +
m[0] * m[7] * m[14] +
m[4] * m[2] * m[15] -
m[4] * m[3] * m[14] -
m[12] * m[2] * m[7] +
m[12] * m[3] * m[6];

inv[10] = m[0] * m[5] * m[15] -
m[0] * m[7] * m[13] -
m[4] * m[1] * m[15] +
m[4] * m[3] * m[13] +
m[12] * m[1] * m[7] -
m[12] * m[3] * m[5];

inv[14] = -m[0] * m[5] * m[14] +
m[0] * m[6] * m[13] +
m[4] * m[1] * m[14] -
m[4] * m[2] * m[13] -
m[12] * m[1] * m[6] +
m[12] * m[2] * m[5];

inv[3] = -m[1] * m[6] * m[11] +
m[1] * m[7] * m[10] +
m[5] * m[2] * m[11] -
m[5] * m[3] * m[10] -
m[9] * m[2] * m[7] +
m[9] * m[3] * m[6];

inv[7] = m[0] * m[6] * m[11] -
m[0] * m[7] * m[10] -
m[4] * m[2] * m[11] +
m[4] * m[3] * m[10] +
m[8] * m[2] * m[7] -
m[8] * m[3] * m[6];

inv[11] = -m[0] * m[5] * m[11] +
m[0] * m[7] * m[9] +
m[4] * m[1] * m[11] -
m[4] * m[3] * m[9] -
m[8] * m[1] * m[7] +
m[8] * m[3] * m[5];

inv[15] = m[0] * m[5] * m[10] -
m[0] * m[6] * m[9] -
m[4] * m[1] * m[10] +
m[4] * m[2] * m[9] +
m[8] * m[1] * m[6] -
m[8] * m[2] * m[5];

inv.forEach((v,i) => inv[i] = v/det);
this._values = inv;
return this
}

DOMMatrix.prototype.setMatrixValue = function (transformList) {
@@ -471,11 +598,11 @@ DOMMatrix.prototype.transformPoint = function (point) {
return new DOMPoint(nx, ny, nz, nw)
}

DOMMatrix.prototype.toFloat32Array = function () {
DOMMatrix.prototype.toFloat32Array = function () {
return Float32Array.from(this._values)
}

DOMMatrix.prototype.toFloat64Array = function () {
DOMMatrix.prototype.toFloat64Array = function () {
return this._values.slice(0)
}

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "canvas",
"description": "Canvas graphics API backed by Cairo",
"version": "2.7.0",
"version": "2.8.0",
"author": "TJ Holowaychuk <tj@learnboost.com>",
"main": "index.js",
"browser": "browser.js",
@@ -49,17 +49,18 @@
"types": "types/index.d.ts",
"dependencies": {
"nan": "^2.14.0",
"node-pre-gyp": "^0.15.0",
"@mapbox/node-pre-gyp": "^1.0.0",
"simple-get": "^3.0.3"
},
"devDependencies": {
"@types/node": "^10.12.18",
"assert-rejects": "^1.0.0",
"dtslint": "^0.5.3",
"dtslint": "^4.0.7",
"express": "^4.16.3",
"mocha": "^5.2.0",
"pixelmatch": "^4.0.2",
"standard": "^12.0.1"
"standard": "^12.0.1",
"typescript": "^4.2.2"
},
"engines": {
"node": ">=6"
43 changes: 43 additions & 0 deletions prebuild/Linux/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
FROM debian:stretch
RUN apt-get update && apt-get -y install curl git cmake make gcc g++ nasm wget gperf bzip2 meson uuid-dev perl libxml-parser-perl

RUN bash -c 'cd; curl -LO https://pkg-config.freedesktop.org/releases/pkg-config-0.29.2.tar.gz; tar -xvf pkg-config-0.29.2.tar.gz; cd pkg-config-0.29.2; ./configure --with-internal-glib; make; make install'
RUN bash -c 'cd; curl -O https://zlib.net/fossils/zlib-1.2.11.tar.gz; tar -xvf zlib-1.2.11.tar.gz; cd zlib-1.2.11; ./configure; make; make install'
RUN bash -c 'cd; curl -LO https://github.com/libffi/libffi/releases/download/v3.3/libffi-3.3.tar.gz; tar -xvf libffi-3.3.tar.gz; cd libffi-3.3; ./configure; make; make install'
RUN bash -c 'cd; curl -O https://www.openssl.org/source/openssl-1.1.1i.tar.gz; tar -xvf openssl-1.1.1i.tar.gz; cd openssl-1.1.1i; ./config; make; make install'
RUN ldconfig
RUN bash -c 'cd; curl -O https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tgz; tar -xvf Python-3.9.1.tgz; cd Python-3.9.1; ./configure --enable-shared --with-ensurepip=yes; make; make install'
RUN ldconfig
RUN pip3 install meson
RUN bash -c 'cd; curl -LO https://download.sourceforge.net/giflib/giflib-5.2.1.tar.gz; tar -xvf giflib-5.2.1.tar.gz; cd giflib-5.2.1; ./configure; make; make install'
RUN bash -c 'cd; curl -LO https://download.sourceforge.net/libpng/libpng-1.6.37.tar.gz; tar -xvf libpng-1.6.37.tar.gz; cd libpng-1.6.37; ./configure; make; make install'
RUN bash -c 'cd; curl -LO https://github.com/libjpeg-turbo/libjpeg-turbo/archive/2.0.6.tar.gz; tar -xvf 2.0.6.tar.gz; cd libjpeg-turbo-2.0.6; mkdir b; cd b; cmake -G"Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/usr/local ..; make; make install'
RUN bash -c 'cd; curl -O https://ftp.pcre.org/pub/pcre/pcre-8.44.tar.bz2; tar -xvf pcre-8.44.tar.bz2; cd pcre-8.44; ./configure --enable-pcre16 --enable-pcre32 --enable-utf --enable-unicode-properties; make; make install '
RUN ldconfig
RUN bash -c 'cd; curl -LO https://download.gnome.org/sources/glib/2.67/glib-2.67.1.tar.xz; tar -xvf glib-2.67.1.tar.xz; cd glib-2.67.1; meson _build; cd _build; ninja; ninja install'
RUN ldconfig
RUN bash -c 'cd; curl -LO https://download.sourceforge.net/freetype/freetype-2.10.4.tar.gz; tar -xvf freetype-2.10.4.tar.gz; cd freetype-2.10.4; ./configure; make; make install'
RUN bash -c 'cd; curl -LO https://github.com/harfbuzz/harfbuzz/releases/download/2.7.4/harfbuzz-2.7.4.tar.xz; tar -xvf harfbuzz-2.7.4.tar.xz; cd harfbuzz-2.7.4; ./configure; make; make install;'
RUN bash -c 'cd; curl -LO https://github.com/libexpat/libexpat/releases/download/R_2_2_10/expat-2.2.10.tar.gz; tar -xvf expat-2.2.10.tar.gz; cd expat-2.2.10; ./configure; make; make install'
RUN ldconfig
RUN ls -l /usr/include
RUN bash -c 'cd; curl -O https://www.freedesktop.org/software/fontconfig/release/fontconfig-2.13.1.tar.bz2; tar -xvf fontconfig-2.13.1.tar.bz2; cd fontconfig-2.13.1; UUID_LIBS="-L/lib/x86_64-linux-gnu -luuid" UUID_CFLAGS="-I/include" ./configure --enable-static --sysconfdir=/etc --localstatedir=/var; make; make install'
RUN bash -c 'cd; curl -O https://www.cairographics.org/releases/pixman-0.40.0.tar.gz; tar -xvf pixman-0.40.0.tar.gz; cd pixman-0.40.0; ./configure; make; make install'
RUN bash -c 'cd; curl -O https://cairographics.org/releases/cairo-1.16.0.tar.xz; tar -xvf cairo-1.16.0.tar.xz; cd cairo-1.16.0; ./configure; make; make install'
RUN bash -c 'cd; curl -LO https://github.com/fribidi/fribidi/releases/download/v1.0.10/fribidi-1.0.10.tar.xz; tar -xvf fribidi-1.0.10.tar.xz; cd fribidi-1.0.10; ./configure; make; make install'
RUN bash -c 'cd; curl -LO https://download.gnome.org/sources/pango/1.48/pango-1.48.0.tar.xz; tar -xvf pango-1.48.0.tar.xz; cd pango-1.48.0; meson -Dharfbuzz:docs=disabled -Dgtk_doc=false _build; cd _build; ninja; ninja install'
RUN ldconfig

# librsvg
RUN bash -c 'curl https://sh.rustup.rs -sSf | sh -s -- -y';
RUN bash -c 'curl -O http://xmlsoft.org/sources/libxml2-2.9.10.tar.gz; tar -xvf libxml2-2.9.10.tar.gz; cd libxml2-2.9.10; ./configure --without-python; make; make install'
RUN bash -c 'curl -O https://ftp.gnu.org/pub/gnu/gettext/gettext-0.21.tar.gz; tar -xvf gettext-0.21.tar.gz; cd gettext-0.21; ./configure; make; make install'
RUN ldconfig
RUN bash -c 'curl -LO https://launchpad.net/intltool/trunk/0.51.0/+download/intltool-0.51.0.tar.gz; tar -xvf intltool-0.51.0.tar.gz; cd intltool-0.51.0; ./configure; make; make install'
# using an old version of shared-mime-info because 2.1 has a ridiculous number of dependencies for what is essentially just a database
RUN bash -c 'curl -O https://people.freedesktop.org/~hadess/shared-mime-info-1.8.tar.xz; tar -xvf shared-mime-info-1.8.tar.xz; cd shared-mime-info-1.8; ./configure; make; make install'
RUN bash -c 'curl -LO https://download.gnome.org/sources/gdk-pixbuf/2.42/gdk-pixbuf-2.42.2.tar.xz; tar -xvf gdk-pixbuf-2.42.2.tar.xz; cd gdk-pixbuf-2.42.2; meson _build; cd _build; ninja install';
RUN ldconfig
RUN bash -c 'curl -LO https://download.gnome.org/sources/libcroco/0.6/libcroco-0.6.13.tar.xz; tar -xvf libcroco-0.6.13.tar.xz; cd libcroco-0.6.13; ./configure; make; make install'
RUN bash -c 'cd; . .cargo/env; curl -LO https://download.gnome.org/sources/librsvg/2.50/librsvg-2.50.2.tar.xz; tar -xvf librsvg-2.50.2.tar.xz; cd librsvg-2.50.2; ./configure --enable-introspection=no; make; make install'
RUN ldconfig
11 changes: 4 additions & 7 deletions src/Canvas.cc
Original file line number Diff line number Diff line change
@@ -408,7 +408,7 @@ NAN_METHOD(Canvas::ToBuffer) {
if (info[0]->StrictEquals(Nan::New<String>("raw").ToLocalChecked())) {
cairo_surface_t *surface = canvas->surface();
cairo_surface_flush(surface);
if (static_cast<uint32_t>(canvas->nBytes()) > node::Buffer::kMaxLength) {
if (canvas->nBytes() > node::Buffer::kMaxLength) {
Nan::ThrowError("Data exceeds maximum buffer length.");
return;
}
@@ -597,6 +597,9 @@ streamPDF(void *c, const uint8_t *data, unsigned len) {
Nan::HandleScope scope;
Nan::AsyncResource async("canvas:StreamPDF");
PdfStreamInfo* streaminfo = static_cast<PdfStreamInfo*>(c);
// TODO this is technically wrong, we're returning a pointer to the data in a
// vector in a class with automatic storage duration. If the canvas goes out
// of scope while we're in the handler, a use-after-free could happen.
Local<Object> buf = Nan::NewBuffer(const_cast<char *>(reinterpret_cast<const char *>(data)), len, stream_pdf_free, 0).ToLocalChecked();
Local<Value> argv[3] = {
Nan::Null()
@@ -837,12 +840,6 @@ Canvas::GetWeightFromCSSString(const char *weight) {
return w;
}

bool streq_casein(std::string& str1, std::string& str2) {
return str1.size() == str2.size() && std::equal(str1.begin(), str1.end(), str2.begin(), [](char& c1, char& c2) {
return c1 == c2 || std::toupper(c1) == std::toupper(c2);
});
}

/*
* Given a user description, return a description that will select the
* font either from the system or @font-face
5 changes: 4 additions & 1 deletion src/Canvas.h
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
#include <pango/pangocairo.h>
#include <v8.h>
#include <vector>
#include <cstddef>

/*
* Maxmimum states per context.
@@ -63,7 +64,9 @@ class Canvas: public Nan::ObjectWrap {

DLL_PUBLIC inline uint8_t *data(){ return cairo_image_surface_get_data(surface()); }
DLL_PUBLIC inline int stride(){ return cairo_image_surface_get_stride(surface()); }
DLL_PUBLIC inline int nBytes(){ return getHeight() * stride(); }
DLL_PUBLIC inline std::size_t nBytes(){
return static_cast<std::size_t>(getHeight()) * stride();
}

DLL_PUBLIC inline int getWidth() { return backend()->getWidth(); }
DLL_PUBLIC inline int getHeight() { return backend()->getHeight(); }
Loading