Skip to content

Commit

Permalink
fix: add ctx.canvas property on svg context (#697)
Browse files Browse the repository at this point in the history
* add ctx.canvas on svg context

* add ctx.canvas test for svg canvas

* lint fix
  • Loading branch information
twlite authored Jul 26, 2023
1 parent 4fd0d31 commit 968e501
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions __test__/canvas-class.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ test('ctx.canvas should be equal to canvas', (t) => {
const ctx = canvas.getContext('2d')
t.is(ctx.canvas, canvas)
})

test('[SVG] ctx.canvas should be equal to canvas', (t) => {
const canvas = createCanvas(100, 100, SvgExportFlag.NoPrettyXML)
const ctx = canvas.getContext('2d')
t.is(ctx.canvas, canvas)
})
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,13 @@ impl SVGCanvas {
Property::new(STROKE_STYLE_HIDDEN_NAME)?
.with_value(&env.create_string("#000")?)
.with_property_attributes(PropertyAttributes::Writable | PropertyAttributes::Configurable),
Property::new("canvas")?
.with_value(&this)
.with_property_attributes(
PropertyAttributes::Default
| PropertyAttributes::Writable
| PropertyAttributes::Enumerable,
),
])?;
env.adjust_external_memory((width * height * 4) as i64)?;
this.define_properties(&[Property::new("ctx")?
Expand Down

0 comments on commit 968e501

Please sign in to comment.