Skip to content

Commit

Permalink
Merge commit '4c276e07f570ee6a727f88dcc67251823895c671'
Browse files Browse the repository at this point in the history
* commit '4c276e07f570ee6a727f88dcc67251823895c671':
  fix incorrect text width with newer (1.43?) Pango
  fix macos CI
  Add canvas property to CanvasRenderingContext2D type
  v2.11.0
  use tailored types instead of extending DOM
  v2.10.2
  src: shorten receiver checks
  src: shorten copy assignment operator decl for Point
  Bugfix/Node.js 18 -> Assertion failed: (object->InternalFieldCount() > 0) (#2133)

# Conflicts:
#	package.json
  • Loading branch information
Philippe Plantier committed Jan 7, 2023
2 parents ae416b0 + 4c276e0 commit a99a655
Show file tree
Hide file tree
Showing 12 changed files with 386 additions and 135 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: [10, 12, 14, 16]
node: [10, 12, 14, 16, 18]
steps:
- uses: actions/setup-node@v3
with:
Expand All @@ -33,7 +33,7 @@ jobs:
runs-on: windows-2019
strategy:
matrix:
node: [10, 12, 14, 16]
node: [10, 12, 14, 16, 18]
steps:
- uses: actions/setup-node@v3
with:
Expand All @@ -57,7 +57,7 @@ jobs:
runs-on: macos-latest
strategy:
matrix:
node: [10, 12, 14, 16]
node: [10, 12, 14, 16, 18]
steps:
- uses: actions/setup-node@v3
with:
Expand All @@ -66,6 +66,7 @@ jobs:
- name: Install Dependencies
run: |
brew update
brew install python3 || : # python doesn't need to be linked
brew install pkg-config cairo pango libpng jpeg giflib librsvg
- name: Install
run: npm install --build-from-source
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/prebuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
Linux:
strategy:
matrix:
node: [8, 9, 10, 11, 12, 13, 14]
node: [8, 9, 10, 11, 12, 13, 14, 16, 18]
canvas_tag: [] # e.g. "v2.6.1"
name: ${{ matrix.canvas_tag}}, Node.js ${{ matrix.node }}, Linux
runs-on: ubuntu-latest
Expand Down Expand Up @@ -97,7 +97,7 @@ jobs:
macOS:
strategy:
matrix:
node: [8, 9, 10, 11, 12, 13, 14]
node: [8, 9, 10, 11, 12, 13, 14, 16, 18]
canvas_tag: [] # e.g. "v2.6.1"
name: ${{ matrix.canvas_tag}}, Node.js ${{ matrix.node }}, macOS
runs-on: macos-latest
Expand Down Expand Up @@ -163,7 +163,7 @@ jobs:
Win:
strategy:
matrix:
node: [8, 9, 10, 11, 12, 13, 14]
node: [8, 9, 10, 11, 12, 13, 14, 16, 18]
canvas_tag: [] # e.g. "v2.6.1"
name: ${{ matrix.canvas_tag}}, Node.js ${{ matrix.node }}, Windows
runs-on: windows-latest
Expand Down
18 changes: 16 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,25 @@ project adheres to [Semantic Versioning](http://semver.org/).
(Unreleased)
==================
### Changed
* Improve performance and memory usage of `save()`/`restore()`.
* `save()`/`restore()` no longer have a maximum depth (previously 64 states).
### Added
### Fixed
* Add missing property `canvas` to the `CanvasRenderingContext2D` type
* Fixed glyph positions getting rounded, resulting text having a slight `letter-spacing` effect

2.11.0
==================
### Fixed
* Replace triple-slash directive in types with own types to avoid polluting TS modules with globals ([#1656](https://github.com/Automattic/node-canvas/issues/1656))

2.10.2
==================
### Fixed
* Fix `Assertion failed: (object->InternalFieldCount() > 0), function Unwrap, file nan_object_wrap.h, line 32.` ([#2025](https://github.com/Automattic/node-canvas/issues/2025))
* `textBaseline` and `textAlign` were not saved/restored by `save()`/`restore()`. ([#1936](https://github.com/Automattic/node-canvas/issues/2029))
* Update nan to v2.17.0 to ensure Node.js v18+ support.
### Changed
* Improve performance and memory usage of `save()`/`restore()`.
* `save()`/`restore()` no longer have a maximum depth (previously 64 states).

2.10.1
==================
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"types": "types/index.d.ts",
"dependencies": {
"@mapbox/node-pre-gyp": "^1.0.0",
"nan": "^2.15.0",
"nan": "^2.17.0",
"simple-get": "^3.0.3"
},
"devDependencies": {
Expand Down
26 changes: 20 additions & 6 deletions src/Canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
"with at least a family (string) and optionally weight (string/number) " \
"and style (string)."

#define CHECK_RECEIVER(prop) \
if (!Canvas::constructor.Get(info.GetIsolate())->HasInstance(info.This())) { \
Nan::ThrowTypeError("Method " #prop " called on incompatible receiver"); \
return; \
}

using namespace v8;
using namespace std;

Expand Down Expand Up @@ -64,10 +70,10 @@ Canvas::Initialize(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE target) {
#ifdef HAVE_JPEG
Nan::SetPrototypeMethod(ctor, "streamJPEGSync", StreamJPEGSync);
#endif
SetProtoAccessor(proto, Nan::New("type").ToLocalChecked(), GetType, NULL, ctor);
SetProtoAccessor(proto, Nan::New("stride").ToLocalChecked(), GetStride, NULL, ctor);
SetProtoAccessor(proto, Nan::New("width").ToLocalChecked(), GetWidth, SetWidth, ctor);
SetProtoAccessor(proto, Nan::New("height").ToLocalChecked(), GetHeight, SetHeight, ctor);
Nan::SetAccessor(proto, Nan::New("type").ToLocalChecked(), GetType);
Nan::SetAccessor(proto, Nan::New("stride").ToLocalChecked(), GetStride);
Nan::SetAccessor(proto, Nan::New("width").ToLocalChecked(), GetWidth, SetWidth);
Nan::SetAccessor(proto, Nan::New("height").ToLocalChecked(), GetHeight, SetHeight);

Nan::SetTemplate(proto, "PNG_NO_FILTERS", Nan::New<Uint32>(PNG_NO_FILTERS));
Nan::SetTemplate(proto, "PNG_FILTER_NONE", Nan::New<Uint32>(PNG_FILTER_NONE));
Expand Down Expand Up @@ -144,6 +150,7 @@ NAN_METHOD(Canvas::New) {
*/

NAN_GETTER(Canvas::GetType) {
CHECK_RECEIVER(Canvas.GetType);
Canvas *canvas = Nan::ObjectWrap::Unwrap<Canvas>(info.This());
info.GetReturnValue().Set(Nan::New<String>(canvas->backend()->getName()).ToLocalChecked());
}
Expand All @@ -152,6 +159,7 @@ NAN_GETTER(Canvas::GetType) {
* Get stride.
*/
NAN_GETTER(Canvas::GetStride) {
CHECK_RECEIVER(Canvas.GetStride);
Canvas *canvas = Nan::ObjectWrap::Unwrap<Canvas>(info.This());
info.GetReturnValue().Set(Nan::New<Number>(canvas->stride()));
}
Expand All @@ -161,6 +169,7 @@ NAN_GETTER(Canvas::GetStride) {
*/

NAN_GETTER(Canvas::GetWidth) {
CHECK_RECEIVER(Canvas.GetWidth);
Canvas *canvas = Nan::ObjectWrap::Unwrap<Canvas>(info.This());
info.GetReturnValue().Set(Nan::New<Number>(canvas->getWidth()));
}
Expand All @@ -170,6 +179,7 @@ NAN_GETTER(Canvas::GetWidth) {
*/

NAN_SETTER(Canvas::SetWidth) {
CHECK_RECEIVER(Canvas.SetWidth);
if (value->IsNumber()) {
Canvas *canvas = Nan::ObjectWrap::Unwrap<Canvas>(info.This());
canvas->backend()->setWidth(Nan::To<uint32_t>(value).FromMaybe(0));
Expand All @@ -182,6 +192,7 @@ NAN_SETTER(Canvas::SetWidth) {
*/

NAN_GETTER(Canvas::GetHeight) {
CHECK_RECEIVER(Canvas.GetHeight);
Canvas *canvas = Nan::ObjectWrap::Unwrap<Canvas>(info.This());
info.GetReturnValue().Set(Nan::New<Number>(canvas->getHeight()));
}
Expand All @@ -191,6 +202,7 @@ NAN_GETTER(Canvas::GetHeight) {
*/

NAN_SETTER(Canvas::SetHeight) {
CHECK_RECEIVER(Canvas.SetHeight);
if (value->IsNumber()) {
Canvas *canvas = Nan::ObjectWrap::Unwrap<Canvas>(info.This());
canvas->backend()->setHeight(Nan::To<uint32_t>(value).FromMaybe(0));
Expand Down Expand Up @@ -773,13 +785,13 @@ NAN_METHOD(Canvas::RegisterFont) {
NAN_METHOD(Canvas::DeregisterAllFonts) {
// Unload all fonts from pango to free up memory
bool success = true;

std::for_each(font_face_list.begin(), font_face_list.end(), [&](FontFace& f) {
if (!deregister_font( (unsigned char *)f.file_path )) success = false;
pango_font_description_free(f.user_desc);
pango_font_description_free(f.sys_desc);
});

font_face_list.clear();
if (!success) Nan::ThrowError("Could not deregister one or more fonts");
}
Expand Down Expand Up @@ -949,3 +961,5 @@ Local<Value>
Canvas::Error(cairo_status_t status) {
return Exception::Error(Nan::New<String>(cairo_status_to_string(status)).ToLocalChecked());
}

#undef CHECK_RECEIVER
Loading

0 comments on commit a99a655

Please sign in to comment.