Skip to content

Commit d8b4c70

Browse files
authored
Merge pull request #1501 from rvilarl/fix/1126
fix scale calculation
2 parents 54ba908 + 5ce3f8a commit d8b4c70

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/svgcontext.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export type Attributes = {
1313
'font-size'?: string | number;
1414
'font-style'?: string;
1515
'font-weight'?: string | number;
16+
scaleX?: number;
17+
scaleY?: number;
1618
};
1719

1820
/** For a particular element type (e.g., rect), we will not apply certain presentation attributes. */
@@ -337,10 +339,10 @@ export class SVGContext extends RenderContext {
337339
// handle internal scaling, am trying to make it possible
338340
// for us to eventually move in that direction.
339341

340-
this.state.scaleX = x;
341-
this.state.scaleY = y;
342-
const visibleWidth = this.width / x;
343-
const visibleHeight = this.height / y;
342+
this.state.scaleX = this.state.scaleX ? this.state.scaleX * x : x;
343+
this.state.scaleY = this.state.scaleY ? this.state.scaleY * y : y;
344+
const visibleWidth = this.width / this.state.scaleX;
345+
const visibleHeight = this.height / this.state.scaleY;
344346
this.setViewBox(0, 0, visibleWidth, visibleHeight);
345347

346348
return this;

tests/notehead_tests.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ const NoteHeadTests = {
3434
};
3535

3636
function setContextStyle(ctx: RenderContext): void {
37-
// TODO: scale() method in SVGContext and CanvasContext should work similarly!
3837
// The final scale should be 1.8.
39-
// ctx.scale(0.9, 0.9);
40-
// ctx.scale(2.0, 2.0);
41-
ctx.scale(1.8, 1.8);
38+
ctx.scale(0.9, 0.9);
39+
ctx.scale(2.0, 2.0);
40+
//ctx.scale(1.8, 1.8);
4241

4342
ctx.font = '10pt Arial';
4443
}

0 commit comments

Comments
 (0)