File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed
Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -2474,6 +2474,8 @@ export class Stream<ElementType extends base.Music21Object = base.Music21Object>
24742474 * if height is undefined will use
24752475 * `this.renderOptions.height`. If still undefined, will use
24762476 * `this.estimateStreamHeight()`
2477+ *
2478+ * Estimated widths and heights are multiplied by this.renderOptions.scaleFactor.
24772479 */
24782480 createNewDOM (
24792481 width ?: number | string ,
@@ -2504,7 +2506,10 @@ export class Stream<ElementType extends base.Music21Object = base.Music21Object>
25042506 const computedWidth
25052507 = this . estimateStaffLength ( )
25062508 + this . renderOptions . staffPadding ;
2507- newCanvasOrDIV . setAttribute ( 'width' , computedWidth . toString ( ) ) ;
2509+ newCanvasOrDIV . setAttribute (
2510+ 'width' ,
2511+ ( computedWidth * this . renderOptions . scaleFactor . x ) . toString ( )
2512+ ) ;
25082513 }
25092514 if ( height !== undefined ) {
25102515 newCanvasOrDIV . setAttribute ( 'height' , height . toString ( ) ) ;
Original file line number Diff line number Diff line change @@ -442,6 +442,26 @@ export default function tests() {
442442 assert . ok ( true ) ;
443443 } ) ;
444444
445+ test ( 'music21.stream.Stream.createNewDOM' , assert => {
446+ const s = music21 . tinyNotation . TinyNotation ( '4/4 c2 c2 c2 c2' ) ;
447+ s . renderOptions . scaleFactor = { x : 1.0 , y : 1.0 } ;
448+
449+ const where1 = s . createNewDOM ( ) ;
450+ const full_height = parseInt ( where1 . getAttribute ( 'height' ) ) ;
451+ const full_width = parseInt ( where1 . getAttribute ( 'width' ) ) ;
452+
453+ // sanity check
454+ assert . ok ( full_height > 0 ) ;
455+ assert . ok ( full_width > 0 ) ;
456+
457+ s . renderOptions . scaleFactor = { x : 0.5 , y : 0.5 } ;
458+ const where2 = s . createNewDOM ( ) ;
459+ const half_height = parseInt ( where2 . getAttribute ( 'height' ) ) ;
460+ const half_width = parseInt ( where2 . getAttribute ( 'width' ) ) ;
461+ assert . equal ( full_height / 2 , half_height ) ;
462+ assert . equal ( full_width / 2 , half_width ) ;
463+ } ) ;
464+
445465 test ( 'music21.stream.Stream.getElementsByClass' , assert => {
446466 const s = new music21 . stream . Stream ( ) ;
447467 const n1 = new music21 . note . Note ( 'C#5' ) ;
You can’t perform that action at this time.
0 commit comments