vexflow 4.0.1-beta.1 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -65
- package/build/cjs/vexflow-bravura.js +2 -2
- package/build/cjs/vexflow-bravura.js.map +1 -1
- package/build/cjs/vexflow-core.js +2 -2
- package/build/cjs/vexflow-core.js.map +1 -1
- package/build/cjs/vexflow-debug-with-tests.js +724 -697
- package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
- package/build/cjs/vexflow-debug.js +550 -610
- package/build/cjs/vexflow-debug.js.map +1 -1
- package/build/cjs/vexflow-font-gonville.js +1 -1
- package/build/cjs/vexflow-font-gonville.js.map +1 -1
- package/build/cjs/vexflow-gonville.js +2 -2
- package/build/cjs/vexflow-gonville.js.map +1 -1
- package/build/cjs/vexflow-petaluma.js +2 -2
- package/build/cjs/vexflow-petaluma.js.map +1 -1
- package/build/cjs/vexflow.js +2 -2
- package/build/cjs/vexflow.js.map +1 -1
- package/build/esm/entry/vexflow-bravura.js +10 -0
- package/build/esm/entry/vexflow-core.js +53 -0
- package/build/esm/entry/vexflow-debug-with-tests.js +11 -0
- package/build/esm/entry/vexflow-debug.js +8 -0
- package/build/esm/entry/vexflow-font-bravura.js +7 -0
- package/build/esm/entry/vexflow-font-custom.js +7 -0
- package/build/esm/entry/vexflow-font-gonville.js +7 -0
- package/build/esm/entry/vexflow-font-petaluma.js +7 -0
- package/build/esm/entry/vexflow-gonville.js +10 -0
- package/build/esm/entry/vexflow-petaluma.js +10 -0
- package/build/esm/entry/vexflow.js +8 -0
- package/build/esm/src/accidental.js +348 -0
- package/build/esm/src/annotation.js +238 -0
- package/build/esm/src/articulation.js +267 -0
- package/build/esm/src/barnote.js +58 -0
- package/build/esm/src/beam.js +644 -0
- package/build/esm/src/bend.js +202 -0
- package/build/esm/src/boundingbox.js +59 -0
- package/build/esm/src/boundingboxcomputation.js +107 -0
- package/build/esm/src/canvascontext.js +202 -0
- package/build/esm/src/chordsymbol.js +578 -0
- package/build/esm/src/clef.js +153 -0
- package/build/esm/src/clefnote.js +65 -0
- package/build/esm/src/crescendo.js +77 -0
- package/build/esm/src/curve.js +118 -0
- package/build/esm/src/dot.js +137 -0
- package/build/esm/src/easyscore.js +374 -0
- package/build/esm/src/element.js +216 -0
- package/build/esm/src/factory.js +445 -0
- package/build/esm/src/flow.js +288 -0
- package/build/esm/src/font.js +262 -0
- package/build/esm/src/fonts/bravura_glyphs.js +3239 -0
- package/build/esm/src/fonts/bravura_metrics.js +507 -0
- package/build/esm/src/fonts/custom_glyphs.js +78 -0
- package/build/esm/src/fonts/custom_metrics.js +5 -0
- package/build/esm/src/fonts/gonville_glyphs.js +828 -0
- package/build/esm/src/fonts/gonville_metrics.js +421 -0
- package/build/esm/src/fonts/load_all.js +10 -0
- package/build/esm/src/fonts/load_bravura.js +6 -0
- package/build/esm/src/fonts/load_custom.js +6 -0
- package/build/esm/src/fonts/load_gonville.js +6 -0
- package/build/esm/src/fonts/load_petaluma.js +6 -0
- package/build/esm/src/fonts/petaluma_glyphs.js +1335 -0
- package/build/esm/src/fonts/petaluma_metrics.js +536 -0
- package/build/esm/src/fonts/petalumascript_glyphs.js +863 -0
- package/build/esm/src/fonts/robotoslab_glyphs.js +863 -0
- package/build/esm/src/fonts/textfonts.js +44 -0
- package/build/esm/src/formatter.js +585 -0
- package/build/esm/src/fraction.js +171 -0
- package/build/esm/src/frethandfinger.js +156 -0
- package/build/esm/src/ghostnote.js +50 -0
- package/build/esm/src/glyph.js +337 -0
- package/build/esm/src/glyphnote.js +55 -0
- package/build/esm/src/gracenote.js +133 -0
- package/build/esm/src/gracenotegroup.js +128 -0
- package/build/esm/src/gracetabnote.js +12 -0
- package/build/esm/src/index.js +89 -0
- package/build/esm/src/keymanager.js +99 -0
- package/build/esm/src/keysignature.js +250 -0
- package/build/esm/src/keysignote.js +28 -0
- package/build/esm/src/modifier.js +128 -0
- package/build/esm/src/modifiercontext.js +110 -0
- package/build/esm/src/multimeasurerest.js +173 -0
- package/build/esm/src/music.js +322 -0
- package/build/esm/src/note.js +371 -0
- package/build/esm/src/notehead.js +169 -0
- package/build/esm/src/notesubgroup.js +59 -0
- package/build/esm/src/ornament.js +206 -0
- package/build/esm/src/parenthesis.js +76 -0
- package/build/esm/src/parser.js +164 -0
- package/build/esm/src/pedalmarking.js +192 -0
- package/build/esm/src/registry.js +81 -0
- package/build/esm/src/rendercontext.js +24 -0
- package/build/esm/src/renderer.js +112 -0
- package/build/esm/src/repeatnote.js +22 -0
- package/build/esm/src/stave.js +547 -0
- package/build/esm/src/stavebarline.js +182 -0
- package/build/esm/src/staveconnector.js +196 -0
- package/build/esm/src/stavehairpin.js +120 -0
- package/build/esm/src/staveline.js +215 -0
- package/build/esm/src/stavemodifier.js +77 -0
- package/build/esm/src/stavenote.js +860 -0
- package/build/esm/src/staverepetition.js +155 -0
- package/build/esm/src/stavesection.js +58 -0
- package/build/esm/src/stavetempo.js +91 -0
- package/build/esm/src/stavetext.js +82 -0
- package/build/esm/src/stavetie.js +141 -0
- package/build/esm/src/stavevolta.js +67 -0
- package/build/esm/src/stem.js +131 -0
- package/build/esm/src/stemmablenote.js +193 -0
- package/build/esm/src/stringnumber.js +231 -0
- package/build/esm/src/strokes.js +200 -0
- package/build/esm/src/svgcontext.js +414 -0
- package/build/esm/src/system.js +109 -0
- package/build/esm/src/tables.js +1102 -0
- package/build/esm/src/tabnote.js +299 -0
- package/build/esm/src/tabslide.js +76 -0
- package/build/esm/src/tabstave.js +17 -0
- package/build/esm/src/tabtie.js +19 -0
- package/build/esm/src/textbracket.js +144 -0
- package/build/esm/src/textdynamics.js +81 -0
- package/build/esm/src/textformatter.js +177 -0
- package/build/esm/src/textnote.js +174 -0
- package/build/esm/src/tickable.js +214 -0
- package/build/esm/src/tickcontext.js +170 -0
- package/build/esm/src/timesigglyph.js +85 -0
- package/build/esm/src/timesignature.js +89 -0
- package/build/esm/src/timesignote.js +32 -0
- package/build/esm/src/tremolo.js +47 -0
- package/build/esm/src/tuning.js +54 -0
- package/build/esm/src/tuplet.js +240 -0
- package/build/esm/src/typeguard.js +30 -0
- package/build/esm/src/util.js +58 -0
- package/build/esm/src/version.js +3 -3
- package/build/esm/src/vex.js +51 -0
- package/build/esm/src/vibrato.js +100 -0
- package/build/esm/src/vibratobracket.js +50 -0
- package/build/esm/src/voice.js +187 -0
- package/build/esm/src/web.js +15 -0
- package/build/esm/tests/accidental_tests.js +974 -0
- package/build/esm/tests/annotation_tests.js +390 -0
- package/build/esm/tests/articulation_tests.js +365 -0
- package/build/esm/tests/auto_beam_formatting_tests.js +548 -0
- package/build/esm/tests/bach_tests.js +335 -0
- package/build/esm/tests/barline_tests.js +52 -0
- package/build/esm/tests/beam_tests.js +614 -0
- package/build/esm/tests/bend_tests.js +215 -0
- package/build/esm/tests/boundingbox_tests.js +53 -0
- package/build/esm/tests/boundingboxcomputation_tests.js +183 -0
- package/build/esm/tests/chordsymbol_tests.js +320 -0
- package/build/esm/tests/clef_tests.js +131 -0
- package/build/esm/tests/curve_tests.js +118 -0
- package/build/esm/tests/dot_tests.js +123 -0
- package/build/esm/tests/easyscore_tests.js +462 -0
- package/build/esm/tests/factory_tests.js +44 -0
- package/build/esm/tests/font_tests.js +135 -0
- package/build/esm/tests/formatter/framestack.js +61 -0
- package/build/esm/tests/formatter/tests.js +203 -0
- package/build/esm/tests/formatter_tests.js +670 -0
- package/build/esm/tests/fraction_tests.js +72 -0
- package/build/esm/tests/ghostnote_tests.js +77 -0
- package/build/esm/tests/glyphnote_tests.js +113 -0
- package/build/esm/tests/gracenote_tests.js +413 -0
- package/build/esm/tests/gracetabnote_tests.js +79 -0
- package/build/esm/tests/index.js +68 -0
- package/build/esm/tests/key_clef_tests.js +103 -0
- package/build/esm/tests/keymanager_tests.js +68 -0
- package/build/esm/tests/keysignature_tests.js +308 -0
- package/build/esm/tests/mocks.js +71 -0
- package/build/esm/tests/modifier_tests.js +24 -0
- package/build/esm/tests/multimeasurerest_tests.js +141 -0
- package/build/esm/tests/music_tests.js +161 -0
- package/build/esm/tests/notehead_tests.js +137 -0
- package/build/esm/tests/notesubgroup_tests.js +149 -0
- package/build/esm/tests/offscreencanvas_tests.js +47 -0
- package/build/esm/tests/ornament_tests.js +298 -0
- package/build/esm/tests/parser_tests.js +122 -0
- package/build/esm/tests/pedalmarking_tests.js +64 -0
- package/build/esm/tests/percussion_tests.js +180 -0
- package/build/esm/tests/registry_tests.js +64 -0
- package/build/esm/tests/renderer_tests.js +113 -0
- package/build/esm/tests/rests_tests.js +248 -0
- package/build/esm/tests/rhythm_tests.js +357 -0
- package/build/esm/tests/stave_tests.js +560 -0
- package/build/esm/tests/staveconnector_tests.js +402 -0
- package/build/esm/tests/stavehairpin_tests.js +90 -0
- package/build/esm/tests/staveline_tests.js +122 -0
- package/build/esm/tests/stavemodifier_tests.js +51 -0
- package/build/esm/tests/stavenote_tests.js +867 -0
- package/build/esm/tests/stavetie_tests.js +108 -0
- package/build/esm/tests/stringnumber_tests.js +259 -0
- package/build/esm/tests/strokes_tests.js +275 -0
- package/build/esm/tests/style_tests.js +98 -0
- package/build/esm/tests/support/qunit.js +2765 -0
- package/build/esm/tests/tabnote_tests.js +474 -0
- package/build/esm/tests/tabslide_tests.js +135 -0
- package/build/esm/tests/tabstave_tests.js +23 -0
- package/build/esm/tests/tabtie_tests.js +173 -0
- package/build/esm/tests/textbracket_tests.js +100 -0
- package/build/esm/tests/textformatter_tests.js +24 -0
- package/build/esm/tests/textnote_tests.js +215 -0
- package/build/esm/tests/threevoice_tests.js +132 -0
- package/build/esm/tests/tickcontext_tests.js +36 -0
- package/build/esm/tests/timesignature_tests.js +134 -0
- package/build/esm/tests/tremolo_tests.js +75 -0
- package/build/esm/tests/tuning_tests.js +56 -0
- package/build/esm/tests/tuplet_tests.js +450 -0
- package/build/esm/tests/typeguard_tests.js +82 -0
- package/build/esm/tests/vexflow_test_helpers.js +266 -0
- package/build/esm/tests/vf_prefix_tests.js +115 -0
- package/build/esm/tests/vibrato_tests.js +92 -0
- package/build/esm/tests/vibratobracket_tests.js +45 -0
- package/build/esm/tests/voice_tests.js +69 -0
- package/build/types/entry/vexflow-bravura.d.ts +2 -0
- package/build/types/entry/vexflow-core.d.ts +2 -0
- package/build/types/entry/vexflow-debug.d.ts +2 -0
- package/build/types/entry/vexflow-font-bravura.d.ts +3771 -0
- package/build/types/entry/vexflow-font-custom.d.ts +86 -0
- package/build/types/entry/vexflow-font-gonville.d.ts +1267 -0
- package/build/types/entry/vexflow-font-petaluma.d.ts +1896 -0
- package/build/types/entry/vexflow-gonville.d.ts +2 -0
- package/build/types/entry/vexflow-petaluma.d.ts +2 -0
- package/build/types/entry/vexflow.d.ts +2 -0
- package/build/types/src/accidental.d.ts +66 -0
- package/build/types/src/annotation.d.ts +61 -0
- package/build/types/src/articulation.d.ts +62 -0
- package/build/types/src/barnote.d.ts +29 -0
- package/build/types/src/beam.d.ts +153 -0
- package/build/types/src/bend.d.ts +73 -0
- package/build/types/src/boundingbox.d.ts +42 -0
- package/build/types/src/boundingboxcomputation.d.ts +33 -0
- package/build/types/src/canvascontext.d.ts +89 -0
- package/build/types/src/chordsymbol.d.ts +149 -0
- package/build/types/src/clef.d.ts +48 -0
- package/build/types/src/clefnote.d.ts +25 -0
- package/build/types/src/crescendo.d.ts +27 -0
- package/build/types/src/curve.d.ts +41 -0
- package/build/types/src/dot.d.ts +20 -0
- package/build/types/src/easyscore.d.ts +152 -0
- package/build/types/src/element.d.ts +202 -0
- package/build/types/src/factory.d.ts +274 -0
- package/build/types/src/flow.d.ts +260 -0
- package/build/types/src/font.d.ts +180 -0
- package/build/types/src/fonts/bravura_glyphs.d.ts +3239 -0
- package/build/types/src/fonts/bravura_metrics.d.ts +533 -0
- package/build/types/src/fonts/custom_glyphs.d.ts +78 -0
- package/build/types/src/fonts/custom_metrics.d.ts +5 -0
- package/build/types/src/fonts/gonville_glyphs.d.ts +828 -0
- package/build/types/src/fonts/gonville_metrics.d.ts +440 -0
- package/build/types/src/fonts/load_all.d.ts +1 -0
- package/build/types/src/fonts/load_bravura.d.ts +1 -0
- package/build/types/src/fonts/load_custom.d.ts +1 -0
- package/build/types/src/fonts/load_gonville.d.ts +1 -0
- package/build/types/src/fonts/load_petaluma.d.ts +1 -0
- package/build/types/src/fonts/petaluma_glyphs.d.ts +1335 -0
- package/build/types/src/fonts/petaluma_metrics.d.ts +562 -0
- package/build/types/src/fonts/petalumascript_glyphs.d.ts +863 -0
- package/build/types/src/fonts/robotoslab_glyphs.d.ts +863 -0
- package/build/types/src/fonts/textfonts.d.ts +1 -0
- package/build/types/src/formatter.d.ts +203 -0
- package/build/types/src/fraction.d.ts +62 -0
- package/build/types/src/frethandfinger.d.ts +22 -0
- package/build/types/src/ghostnote.d.ts +16 -0
- package/build/types/src/glyph.d.ts +141 -0
- package/build/types/src/glyphnote.d.ts +17 -0
- package/build/types/src/gracenote.d.ts +19 -0
- package/build/types/src/gracenotegroup.d.ts +33 -0
- package/build/types/src/gracetabnote.d.ts +5 -0
- package/build/types/src/index.d.ts +89 -0
- package/build/types/src/keymanager.d.ts +25 -0
- package/build/types/src/keysignature.d.ts +50 -0
- package/build/types/src/keysignote.d.ts +11 -0
- package/build/types/src/modifier.d.ts +97 -0
- package/build/types/src/modifiercontext.d.ts +45 -0
- package/build/types/src/multimeasurerest.d.ts +61 -0
- package/build/types/src/music.d.ts +91 -0
- package/build/types/src/note.d.ts +232 -0
- package/build/types/src/notehead.d.ts +70 -0
- package/build/types/src/notesubgroup.d.ts +18 -0
- package/build/types/src/ornament.d.ts +76 -0
- package/build/types/src/parenthesis.d.ts +22 -0
- package/build/types/src/parser.d.ts +45 -0
- package/build/types/src/pedalmarking.d.ts +69 -0
- package/build/types/src/registry.d.ts +40 -0
- package/build/types/src/rendercontext.d.ts +64 -0
- package/build/types/src/renderer.d.ts +35 -0
- package/build/types/src/repeatnote.d.ts +6 -0
- package/build/types/src/stave.d.ts +186 -0
- package/build/types/src/stavebarline.d.ts +28 -0
- package/build/types/src/staveconnector.d.ts +67 -0
- package/build/types/src/stavehairpin.d.ts +56 -0
- package/build/types/src/staveline.d.ts +54 -0
- package/build/types/src/stavemodifier.d.ts +44 -0
- package/build/types/src/stavenote.d.ts +154 -0
- package/build/types/src/staverepetition.d.ts +32 -0
- package/build/types/src/stavesection.d.ts +15 -0
- package/build/types/src/stavetempo.d.ts +25 -0
- package/build/types/src/stavetext.d.ts +25 -0
- package/build/types/src/stavetie.d.ts +59 -0
- package/build/types/src/stavevolta.d.ts +21 -0
- package/build/types/src/stem.d.ts +58 -0
- package/build/types/src/stemmablenote.d.ts +39 -0
- package/build/types/src/stringnumber.d.ts +27 -0
- package/build/types/src/strokes.d.ts +33 -0
- package/build/types/src/svgcontext.d.ts +131 -0
- package/build/types/src/system.d.ts +92 -0
- package/build/types/src/tables.d.ts +96 -0
- package/build/types/src/tabnote.d.ts +44 -0
- package/build/types/src/tabslide.d.ts +34 -0
- package/build/types/src/tabstave.d.ts +7 -0
- package/build/types/src/tabtie.d.ts +18 -0
- package/build/types/src/textbracket.d.ts +55 -0
- package/build/types/src/textdynamics.d.ts +39 -0
- package/build/types/src/textformatter.d.ts +109 -0
- package/build/types/src/textnote.d.ts +49 -0
- package/build/types/src/tickable.d.ts +140 -0
- package/build/types/src/tickcontext.d.ts +82 -0
- package/build/types/src/timesigglyph.d.ts +14 -0
- package/build/types/src/timesignature.d.ts +26 -0
- package/build/types/src/timesignote.d.ts +11 -0
- package/build/types/src/tremolo.d.ts +17 -0
- package/build/types/src/tuning.d.ts +23 -0
- package/build/types/src/tuplet.d.ts +105 -0
- package/build/types/src/typeguard.d.ts +99 -0
- package/build/types/src/util.d.ts +27 -0
- package/build/types/src/version.d.ts +3 -0
- package/build/types/src/vex.d.ts +18 -0
- package/build/types/src/vibrato.d.ts +29 -0
- package/build/types/src/vibratobracket.d.ts +33 -0
- package/build/types/src/voice.d.ts +108 -0
- package/build/types/src/web.d.ts +2 -0
- package/entry/vexflow-bravura.ts +3 -3
- package/entry/vexflow-core.ts +3 -3
- package/entry/vexflow-debug-with-tests.ts +16 -2
- package/entry/vexflow-debug.ts +11 -3
- package/entry/vexflow-gonville.ts +3 -3
- package/entry/vexflow-petaluma.ts +3 -3
- package/entry/vexflow.ts +3 -3
- package/package.json +1 -1
- package/src/annotation.ts +38 -6
- package/src/articulation.ts +8 -2
- package/src/beam.ts +53 -6
- package/src/easyscore.ts +11 -1
- package/src/factory.ts +16 -2
- package/src/flow.ts +35 -20
- package/src/font.ts +0 -4
- package/src/fonts/gonville_glyphs.ts +4 -4
- package/src/formatter.ts +24 -8
- package/src/glyph.ts +8 -0
- package/src/index.ts +2 -7
- package/src/note.ts +2 -1
- package/src/staveline.ts +2 -5
- package/src/stavenote.ts +13 -9
- package/src/stavetext.ts +3 -3
- package/src/system.ts +1 -7
- package/src/textnote.ts +9 -11
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { Font, FontStyle, FontWeight } from './font.js';
|
|
2
|
+
import { Glyph } from './glyph.js';
|
|
3
|
+
import { Modifier } from './modifier.js';
|
|
4
|
+
import { isNote, isStaveNote, isTabNote } from './typeguard.js';
|
|
5
|
+
import { RuntimeError } from './util.js';
|
|
6
|
+
export class Stroke extends Modifier {
|
|
7
|
+
constructor(type, options) {
|
|
8
|
+
super();
|
|
9
|
+
this.options = Object.assign({ all_voices: true }, options);
|
|
10
|
+
this.all_voices = this.options.all_voices;
|
|
11
|
+
this.type = type;
|
|
12
|
+
this.position = Modifier.Position.LEFT;
|
|
13
|
+
this.render_options = {
|
|
14
|
+
font_scale: 38,
|
|
15
|
+
};
|
|
16
|
+
this.resetFont();
|
|
17
|
+
this.setXShift(0);
|
|
18
|
+
this.setWidth(10);
|
|
19
|
+
}
|
|
20
|
+
static get CATEGORY() {
|
|
21
|
+
return "Stroke";
|
|
22
|
+
}
|
|
23
|
+
static format(strokes, state) {
|
|
24
|
+
const left_shift = state.left_shift;
|
|
25
|
+
const stroke_spacing = 0;
|
|
26
|
+
if (!strokes || strokes.length === 0)
|
|
27
|
+
return false;
|
|
28
|
+
const strokeList = strokes.map((stroke) => {
|
|
29
|
+
const note = stroke.getNote();
|
|
30
|
+
const index = stroke.checkIndex();
|
|
31
|
+
if (isStaveNote(note)) {
|
|
32
|
+
const { line } = note.getKeyProps()[index];
|
|
33
|
+
const shift = note.getLeftDisplacedHeadPx();
|
|
34
|
+
return { line, shift, stroke };
|
|
35
|
+
}
|
|
36
|
+
else if (isTabNote(note)) {
|
|
37
|
+
const { str: string } = note.getPositions()[index];
|
|
38
|
+
return { line: string, shift: 0, stroke };
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
throw new RuntimeError('Internal', 'Unexpected instance.');
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
const strokeShift = left_shift;
|
|
45
|
+
const xShift = strokeList.reduce((xShift, { stroke, shift }) => {
|
|
46
|
+
stroke.setXShift(strokeShift + shift);
|
|
47
|
+
return Math.max(stroke.getWidth() + stroke_spacing, xShift);
|
|
48
|
+
}, 0);
|
|
49
|
+
state.left_shift += xShift;
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
getPosition() {
|
|
53
|
+
return this.position;
|
|
54
|
+
}
|
|
55
|
+
addEndNote(note) {
|
|
56
|
+
this.note_end = note;
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
draw() {
|
|
60
|
+
const ctx = this.checkContext();
|
|
61
|
+
const note = this.checkAttachedNote();
|
|
62
|
+
this.setRendered();
|
|
63
|
+
const start = note.getModifierStartXY(this.position, this.index);
|
|
64
|
+
let ys = note.getYs();
|
|
65
|
+
let topY = start.y;
|
|
66
|
+
let botY = start.y;
|
|
67
|
+
const x = start.x - 5;
|
|
68
|
+
const line_space = note.checkStave().getSpacingBetweenLines();
|
|
69
|
+
const notes = this.checkModifierContext().getMembers(note.getCategory());
|
|
70
|
+
for (let i = 0; i < notes.length; i++) {
|
|
71
|
+
const note = notes[i];
|
|
72
|
+
if (isNote(note)) {
|
|
73
|
+
ys = note.getYs();
|
|
74
|
+
for (let n = 0; n < ys.length; n++) {
|
|
75
|
+
if (this.note === notes[i] || this.all_voices) {
|
|
76
|
+
topY = Math.min(topY, ys[n]);
|
|
77
|
+
botY = Math.max(botY, ys[n]);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
let arrow = '';
|
|
83
|
+
let arrow_shift_x = 0;
|
|
84
|
+
let arrow_y = 0;
|
|
85
|
+
let text_shift_x = 0;
|
|
86
|
+
let text_y = 0;
|
|
87
|
+
switch (this.type) {
|
|
88
|
+
case Stroke.Type.BRUSH_DOWN:
|
|
89
|
+
arrow = 'arrowheadBlackUp';
|
|
90
|
+
arrow_shift_x = -3;
|
|
91
|
+
arrow_y = topY - line_space / 2 + 10;
|
|
92
|
+
botY += line_space / 2;
|
|
93
|
+
break;
|
|
94
|
+
case Stroke.Type.BRUSH_UP:
|
|
95
|
+
arrow = 'arrowheadBlackDown';
|
|
96
|
+
arrow_shift_x = 0.5;
|
|
97
|
+
arrow_y = botY + line_space / 2;
|
|
98
|
+
topY -= line_space / 2;
|
|
99
|
+
break;
|
|
100
|
+
case Stroke.Type.ROLL_DOWN:
|
|
101
|
+
case Stroke.Type.RASQUEDO_DOWN:
|
|
102
|
+
arrow = 'arrowheadBlackUp';
|
|
103
|
+
arrow_shift_x = -3;
|
|
104
|
+
text_shift_x = this.x_shift + arrow_shift_x - 2;
|
|
105
|
+
if (isStaveNote(note)) {
|
|
106
|
+
topY += 1.5 * line_space;
|
|
107
|
+
if ((botY - topY) % 2 !== 0) {
|
|
108
|
+
botY += 0.5 * line_space;
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
botY += line_space;
|
|
112
|
+
}
|
|
113
|
+
arrow_y = topY - line_space;
|
|
114
|
+
text_y = botY + line_space + 2;
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
topY += 1.5 * line_space;
|
|
118
|
+
botY += line_space;
|
|
119
|
+
arrow_y = topY - 0.75 * line_space;
|
|
120
|
+
text_y = botY + 0.25 * line_space;
|
|
121
|
+
}
|
|
122
|
+
break;
|
|
123
|
+
case Stroke.Type.ROLL_UP:
|
|
124
|
+
case Stroke.Type.RASQUEDO_UP:
|
|
125
|
+
arrow = 'arrowheadBlackDown';
|
|
126
|
+
arrow_shift_x = -4;
|
|
127
|
+
text_shift_x = this.x_shift + arrow_shift_x - 1;
|
|
128
|
+
if (isStaveNote(note)) {
|
|
129
|
+
arrow_y = line_space / 2;
|
|
130
|
+
topY += 0.5 * line_space;
|
|
131
|
+
if ((botY - topY) % 2 === 0) {
|
|
132
|
+
botY += line_space / 2;
|
|
133
|
+
}
|
|
134
|
+
arrow_y = botY + 0.5 * line_space;
|
|
135
|
+
text_y = topY - 1.25 * line_space;
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
topY += 0.25 * line_space;
|
|
139
|
+
botY += 0.5 * line_space;
|
|
140
|
+
arrow_y = botY + 0.25 * line_space;
|
|
141
|
+
text_y = topY - line_space;
|
|
142
|
+
}
|
|
143
|
+
break;
|
|
144
|
+
case Stroke.Type.ARPEGGIO_DIRECTIONLESS:
|
|
145
|
+
topY += 0.5 * line_space;
|
|
146
|
+
botY += line_space;
|
|
147
|
+
break;
|
|
148
|
+
default:
|
|
149
|
+
throw new RuntimeError('InvalidType', `The stroke type ${this.type} does not exist`);
|
|
150
|
+
}
|
|
151
|
+
let strokeLine = 'straight';
|
|
152
|
+
if (this.type === Stroke.Type.BRUSH_DOWN || this.type === Stroke.Type.BRUSH_UP) {
|
|
153
|
+
ctx.fillRect(x + this.x_shift, topY, 1, botY - topY);
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
strokeLine = 'wiggly';
|
|
157
|
+
if (isStaveNote(note)) {
|
|
158
|
+
for (let i = topY; i <= botY; i += line_space) {
|
|
159
|
+
Glyph.renderGlyph(ctx, x + this.x_shift - 4, i, this.render_options.font_scale, 'vexWiggleArpeggioUp');
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
let i;
|
|
164
|
+
for (i = topY; i <= botY; i += 10) {
|
|
165
|
+
Glyph.renderGlyph(ctx, x + this.x_shift - 4, i, this.render_options.font_scale, 'vexWiggleArpeggioUp');
|
|
166
|
+
}
|
|
167
|
+
if (this.type === Stroke.Type.RASQUEDO_DOWN) {
|
|
168
|
+
text_y = i + 0.25 * line_space;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (this.type === Stroke.Type.ARPEGGIO_DIRECTIONLESS) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
Glyph.renderGlyph(ctx, x + this.x_shift + arrow_shift_x, arrow_y, this.render_options.font_scale, arrow, {
|
|
176
|
+
category: `stroke.${arrow}.${strokeLine}`,
|
|
177
|
+
});
|
|
178
|
+
if (this.type === Stroke.Type.RASQUEDO_DOWN || this.type === Stroke.Type.RASQUEDO_UP) {
|
|
179
|
+
ctx.save();
|
|
180
|
+
ctx.setFont(this.textFont);
|
|
181
|
+
ctx.fillText('R', x + text_shift_x, text_y);
|
|
182
|
+
ctx.restore();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
Stroke.Type = {
|
|
187
|
+
BRUSH_DOWN: 1,
|
|
188
|
+
BRUSH_UP: 2,
|
|
189
|
+
ROLL_DOWN: 3,
|
|
190
|
+
ROLL_UP: 4,
|
|
191
|
+
RASQUEDO_DOWN: 5,
|
|
192
|
+
RASQUEDO_UP: 6,
|
|
193
|
+
ARPEGGIO_DIRECTIONLESS: 7,
|
|
194
|
+
};
|
|
195
|
+
Stroke.TEXT_FONT = {
|
|
196
|
+
family: Font.SERIF,
|
|
197
|
+
size: Font.SIZE,
|
|
198
|
+
weight: FontWeight.BOLD,
|
|
199
|
+
style: FontStyle.ITALIC,
|
|
200
|
+
};
|
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
import { Font, FontStyle, FontWeight } from './font.js';
|
|
2
|
+
import { RenderContext } from './rendercontext.js';
|
|
3
|
+
import { normalizeAngle, prefix, RuntimeError } from './util.js';
|
|
4
|
+
const ATTRIBUTES_TO_IGNORE = {
|
|
5
|
+
path: {
|
|
6
|
+
x: true,
|
|
7
|
+
y: true,
|
|
8
|
+
width: true,
|
|
9
|
+
height: true,
|
|
10
|
+
'font-family': true,
|
|
11
|
+
'font-weight': true,
|
|
12
|
+
'font-style': true,
|
|
13
|
+
'font-size': true,
|
|
14
|
+
},
|
|
15
|
+
rect: {
|
|
16
|
+
'font-family': true,
|
|
17
|
+
'font-weight': true,
|
|
18
|
+
'font-style': true,
|
|
19
|
+
'font-size': true,
|
|
20
|
+
},
|
|
21
|
+
text: {
|
|
22
|
+
width: true,
|
|
23
|
+
height: true,
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
27
|
+
const TWO_PI = 2 * Math.PI;
|
|
28
|
+
class MeasureTextCache {
|
|
29
|
+
constructor() {
|
|
30
|
+
this.cache = {};
|
|
31
|
+
}
|
|
32
|
+
lookup(text, svg, attributes) {
|
|
33
|
+
let entries = this.cache[text];
|
|
34
|
+
if (entries === undefined) {
|
|
35
|
+
entries = {};
|
|
36
|
+
this.cache[text] = entries;
|
|
37
|
+
}
|
|
38
|
+
const family = attributes['font-family'];
|
|
39
|
+
const size = attributes['font-size'];
|
|
40
|
+
const weight = attributes['font-weight'];
|
|
41
|
+
const style = attributes['font-style'];
|
|
42
|
+
const key = `${family}%${size}%${weight}%${style}`;
|
|
43
|
+
let entry = entries[key];
|
|
44
|
+
if (entry === undefined) {
|
|
45
|
+
entry = this.measureImpl(text, svg, attributes);
|
|
46
|
+
entries[key] = entry;
|
|
47
|
+
}
|
|
48
|
+
return entry;
|
|
49
|
+
}
|
|
50
|
+
measureImpl(text, svg, attributes) {
|
|
51
|
+
let txt = this.txt;
|
|
52
|
+
if (!txt) {
|
|
53
|
+
txt = document.createElementNS(SVG_NS, 'text');
|
|
54
|
+
this.txt = txt;
|
|
55
|
+
}
|
|
56
|
+
txt.textContent = text;
|
|
57
|
+
txt.setAttributeNS(null, 'font-family', attributes['font-family']);
|
|
58
|
+
txt.setAttributeNS(null, 'font-size', attributes['font-size']);
|
|
59
|
+
txt.setAttributeNS(null, 'font-style', attributes['font-style']);
|
|
60
|
+
txt.setAttributeNS(null, 'font-weight', attributes['font-weight']);
|
|
61
|
+
svg.appendChild(txt);
|
|
62
|
+
const bbox = txt.getBBox();
|
|
63
|
+
svg.removeChild(txt);
|
|
64
|
+
return { x: bbox.x, y: bbox.y, width: bbox.width, height: bbox.height };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export class SVGContext extends RenderContext {
|
|
68
|
+
constructor(element) {
|
|
69
|
+
super();
|
|
70
|
+
this.width = 0;
|
|
71
|
+
this.height = 0;
|
|
72
|
+
this.backgroundFillStyle = 'white';
|
|
73
|
+
this.fontCSSString = '';
|
|
74
|
+
this.element = element;
|
|
75
|
+
const svg = this.create('svg');
|
|
76
|
+
this.element.appendChild(svg);
|
|
77
|
+
this.svg = svg;
|
|
78
|
+
this.parent = this.svg;
|
|
79
|
+
this.groups = [this.svg];
|
|
80
|
+
this.path = '';
|
|
81
|
+
this.pen = { x: NaN, y: NaN };
|
|
82
|
+
this.lineWidth = 1.0;
|
|
83
|
+
const defaultFontAttributes = {
|
|
84
|
+
'font-family': Font.SANS_SERIF,
|
|
85
|
+
'font-size': Font.SIZE + 'pt',
|
|
86
|
+
'font-weight': FontWeight.NORMAL,
|
|
87
|
+
'font-style': FontStyle.NORMAL,
|
|
88
|
+
};
|
|
89
|
+
this.state = Object.assign({ scale: { x: 1, y: 1 } }, defaultFontAttributes);
|
|
90
|
+
this.attributes = Object.assign({ 'stroke-width': 0.3, 'stroke-dasharray': 'none', fill: 'black', stroke: 'black' }, defaultFontAttributes);
|
|
91
|
+
this.shadow_attributes = {
|
|
92
|
+
width: 0,
|
|
93
|
+
color: 'black',
|
|
94
|
+
};
|
|
95
|
+
this.state_stack = [];
|
|
96
|
+
}
|
|
97
|
+
create(svgElementType) {
|
|
98
|
+
return document.createElementNS(SVG_NS, svgElementType);
|
|
99
|
+
}
|
|
100
|
+
openGroup(cls, id, attrs) {
|
|
101
|
+
const group = this.create('g');
|
|
102
|
+
this.groups.push(group);
|
|
103
|
+
this.parent.appendChild(group);
|
|
104
|
+
this.parent = group;
|
|
105
|
+
if (cls)
|
|
106
|
+
group.setAttribute('class', prefix(cls));
|
|
107
|
+
if (id)
|
|
108
|
+
group.setAttribute('id', prefix(id));
|
|
109
|
+
if (attrs && attrs.pointerBBox) {
|
|
110
|
+
group.setAttribute('pointer-events', 'bounding-box');
|
|
111
|
+
}
|
|
112
|
+
return group;
|
|
113
|
+
}
|
|
114
|
+
closeGroup() {
|
|
115
|
+
this.groups.pop();
|
|
116
|
+
this.parent = this.groups[this.groups.length - 1];
|
|
117
|
+
}
|
|
118
|
+
add(elem) {
|
|
119
|
+
this.parent.appendChild(elem);
|
|
120
|
+
}
|
|
121
|
+
setFillStyle(style) {
|
|
122
|
+
this.attributes.fill = style;
|
|
123
|
+
return this;
|
|
124
|
+
}
|
|
125
|
+
setBackgroundFillStyle(style) {
|
|
126
|
+
this.backgroundFillStyle = style;
|
|
127
|
+
return this;
|
|
128
|
+
}
|
|
129
|
+
setStrokeStyle(style) {
|
|
130
|
+
this.attributes.stroke = style;
|
|
131
|
+
return this;
|
|
132
|
+
}
|
|
133
|
+
setShadowColor(color) {
|
|
134
|
+
this.shadow_attributes.color = color;
|
|
135
|
+
return this;
|
|
136
|
+
}
|
|
137
|
+
setShadowBlur(blur) {
|
|
138
|
+
this.shadow_attributes.width = blur;
|
|
139
|
+
return this;
|
|
140
|
+
}
|
|
141
|
+
setLineWidth(width) {
|
|
142
|
+
this.attributes['stroke-width'] = width;
|
|
143
|
+
this.lineWidth = width;
|
|
144
|
+
return this;
|
|
145
|
+
}
|
|
146
|
+
setLineDash(lineDash) {
|
|
147
|
+
if (Object.prototype.toString.call(lineDash) === '[object Array]') {
|
|
148
|
+
this.attributes['stroke-dasharray'] = lineDash.join(',');
|
|
149
|
+
return this;
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
throw new RuntimeError('ArgumentError', 'lineDash must be an array of integers.');
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
setLineCap(capType) {
|
|
156
|
+
this.attributes['stroke-linecap'] = capType;
|
|
157
|
+
return this;
|
|
158
|
+
}
|
|
159
|
+
resize(width, height) {
|
|
160
|
+
this.width = width;
|
|
161
|
+
this.height = height;
|
|
162
|
+
this.element.style.width = width.toString();
|
|
163
|
+
this.svg.style.width = width.toString();
|
|
164
|
+
this.svg.style.height = height.toString();
|
|
165
|
+
const attributes = {
|
|
166
|
+
width,
|
|
167
|
+
height,
|
|
168
|
+
};
|
|
169
|
+
this.applyAttributes(this.svg, attributes);
|
|
170
|
+
this.scale(this.state.scale.x, this.state.scale.y);
|
|
171
|
+
return this;
|
|
172
|
+
}
|
|
173
|
+
scale(x, y) {
|
|
174
|
+
this.state.scale = { x, y };
|
|
175
|
+
const visibleWidth = this.width / x;
|
|
176
|
+
const visibleHeight = this.height / y;
|
|
177
|
+
this.setViewBox(0, 0, visibleWidth, visibleHeight);
|
|
178
|
+
return this;
|
|
179
|
+
}
|
|
180
|
+
setViewBox(viewBox_or_minX, minY, width, height) {
|
|
181
|
+
if (typeof viewBox_or_minX === 'string') {
|
|
182
|
+
this.svg.setAttribute('viewBox', viewBox_or_minX);
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
const viewBoxString = viewBox_or_minX + ' ' + minY + ' ' + width + ' ' + height;
|
|
186
|
+
this.svg.setAttribute('viewBox', viewBoxString);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
applyAttributes(element, attributes) {
|
|
190
|
+
const attrNamesToIgnore = ATTRIBUTES_TO_IGNORE[element.nodeName];
|
|
191
|
+
for (const attrName in attributes) {
|
|
192
|
+
if (attrNamesToIgnore && attrNamesToIgnore[attrName]) {
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
element.setAttributeNS(null, attrName, attributes[attrName]);
|
|
196
|
+
}
|
|
197
|
+
return element;
|
|
198
|
+
}
|
|
199
|
+
clear() {
|
|
200
|
+
while (this.svg.lastChild) {
|
|
201
|
+
this.svg.removeChild(this.svg.lastChild);
|
|
202
|
+
}
|
|
203
|
+
this.scale(this.state.scale.x, this.state.scale.y);
|
|
204
|
+
}
|
|
205
|
+
rect(x, y, width, height, attributes) {
|
|
206
|
+
if (height < 0) {
|
|
207
|
+
y += height;
|
|
208
|
+
height *= -1;
|
|
209
|
+
}
|
|
210
|
+
const rectangle = this.create('rect');
|
|
211
|
+
attributes = attributes !== null && attributes !== void 0 ? attributes : { fill: 'none', 'stroke-width': this.lineWidth, stroke: 'black' };
|
|
212
|
+
this.applyAttributes(rectangle, Object.assign({ x, y, width, height }, attributes));
|
|
213
|
+
this.add(rectangle);
|
|
214
|
+
return this;
|
|
215
|
+
}
|
|
216
|
+
fillRect(x, y, width, height) {
|
|
217
|
+
const attributes = { fill: this.attributes.fill };
|
|
218
|
+
this.rect(x, y, width, height, attributes);
|
|
219
|
+
return this;
|
|
220
|
+
}
|
|
221
|
+
clearRect(x, y, width, height) {
|
|
222
|
+
this.rect(x, y, width, height, { 'stroke-width': 0, fill: this.backgroundFillStyle });
|
|
223
|
+
return this;
|
|
224
|
+
}
|
|
225
|
+
beginPath() {
|
|
226
|
+
this.path = '';
|
|
227
|
+
this.pen.x = NaN;
|
|
228
|
+
this.pen.y = NaN;
|
|
229
|
+
return this;
|
|
230
|
+
}
|
|
231
|
+
moveTo(x, y) {
|
|
232
|
+
this.path += 'M' + x + ' ' + y;
|
|
233
|
+
this.pen.x = x;
|
|
234
|
+
this.pen.y = y;
|
|
235
|
+
return this;
|
|
236
|
+
}
|
|
237
|
+
lineTo(x, y) {
|
|
238
|
+
this.path += 'L' + x + ' ' + y;
|
|
239
|
+
this.pen.x = x;
|
|
240
|
+
this.pen.y = y;
|
|
241
|
+
return this;
|
|
242
|
+
}
|
|
243
|
+
bezierCurveTo(x1, y1, x2, y2, x, y) {
|
|
244
|
+
this.path += 'C' + x1 + ' ' + y1 + ',' + x2 + ' ' + y2 + ',' + x + ' ' + y;
|
|
245
|
+
this.pen.x = x;
|
|
246
|
+
this.pen.y = y;
|
|
247
|
+
return this;
|
|
248
|
+
}
|
|
249
|
+
quadraticCurveTo(x1, y1, x, y) {
|
|
250
|
+
this.path += 'Q' + x1 + ' ' + y1 + ',' + x + ' ' + y;
|
|
251
|
+
this.pen.x = x;
|
|
252
|
+
this.pen.y = y;
|
|
253
|
+
return this;
|
|
254
|
+
}
|
|
255
|
+
arc(x, y, radius, startAngle, endAngle, counterclockwise) {
|
|
256
|
+
const x0 = x + radius * Math.cos(startAngle);
|
|
257
|
+
const y0 = y + radius * Math.sin(startAngle);
|
|
258
|
+
if ((!counterclockwise && endAngle - startAngle >= TWO_PI) ||
|
|
259
|
+
(counterclockwise && startAngle - endAngle >= TWO_PI)) {
|
|
260
|
+
const x1 = x + radius * Math.cos(startAngle + Math.PI);
|
|
261
|
+
const y1 = y + radius * Math.sin(startAngle + Math.PI);
|
|
262
|
+
this.path += `M${x0} ${y0} A${radius} ${radius} 0 0 0 ${x1} ${y1} `;
|
|
263
|
+
this.path += `A${radius} ${radius} 0 0 0 ${x0} ${y0}`;
|
|
264
|
+
this.pen.x = x0;
|
|
265
|
+
this.pen.y = y0;
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
const x1 = x + radius * Math.cos(endAngle);
|
|
269
|
+
const y1 = y + radius * Math.sin(endAngle);
|
|
270
|
+
startAngle = normalizeAngle(startAngle);
|
|
271
|
+
endAngle = normalizeAngle(endAngle);
|
|
272
|
+
let large;
|
|
273
|
+
if (Math.abs(endAngle - startAngle) < Math.PI) {
|
|
274
|
+
large = counterclockwise;
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
large = !counterclockwise;
|
|
278
|
+
}
|
|
279
|
+
if (startAngle > endAngle) {
|
|
280
|
+
large = !large;
|
|
281
|
+
}
|
|
282
|
+
const sweep = !counterclockwise;
|
|
283
|
+
this.path += `M${x0} ${y0} A${radius} ${radius} 0 ${+large} ${+sweep} ${x1} ${y1}`;
|
|
284
|
+
this.pen.x = x1;
|
|
285
|
+
this.pen.y = y1;
|
|
286
|
+
}
|
|
287
|
+
return this;
|
|
288
|
+
}
|
|
289
|
+
closePath() {
|
|
290
|
+
this.path += 'Z';
|
|
291
|
+
return this;
|
|
292
|
+
}
|
|
293
|
+
getShadowStyle() {
|
|
294
|
+
const sa = this.shadow_attributes;
|
|
295
|
+
return `filter: drop-shadow(0 0 ${sa.width / 1.5}px ${sa.color})`;
|
|
296
|
+
}
|
|
297
|
+
fill(attributes) {
|
|
298
|
+
const path = this.create('path');
|
|
299
|
+
if (typeof attributes === 'undefined') {
|
|
300
|
+
attributes = Object.assign(Object.assign({}, this.attributes), { stroke: 'none' });
|
|
301
|
+
}
|
|
302
|
+
attributes.d = this.path;
|
|
303
|
+
if (this.shadow_attributes.width > 0) {
|
|
304
|
+
attributes.style = this.getShadowStyle();
|
|
305
|
+
}
|
|
306
|
+
this.applyAttributes(path, attributes);
|
|
307
|
+
this.add(path);
|
|
308
|
+
return this;
|
|
309
|
+
}
|
|
310
|
+
stroke() {
|
|
311
|
+
const path = this.create('path');
|
|
312
|
+
const attributes = Object.assign(Object.assign({}, this.attributes), { fill: 'none', 'stroke-width': this.lineWidth, d: this.path });
|
|
313
|
+
if (this.shadow_attributes.width > 0) {
|
|
314
|
+
attributes.style = this.getShadowStyle();
|
|
315
|
+
}
|
|
316
|
+
this.applyAttributes(path, attributes);
|
|
317
|
+
this.add(path);
|
|
318
|
+
return this;
|
|
319
|
+
}
|
|
320
|
+
measureText(text) {
|
|
321
|
+
return SVGContext.measureTextCache.lookup(text, this.svg, this.attributes);
|
|
322
|
+
}
|
|
323
|
+
fillText(text, x, y) {
|
|
324
|
+
if (!text || text.length <= 0) {
|
|
325
|
+
return this;
|
|
326
|
+
}
|
|
327
|
+
const attributes = Object.assign(Object.assign({}, this.attributes), { stroke: 'none', x,
|
|
328
|
+
y });
|
|
329
|
+
const txt = this.create('text');
|
|
330
|
+
txt.textContent = text;
|
|
331
|
+
this.applyAttributes(txt, attributes);
|
|
332
|
+
this.add(txt);
|
|
333
|
+
return this;
|
|
334
|
+
}
|
|
335
|
+
save() {
|
|
336
|
+
this.state_stack.push({
|
|
337
|
+
state: {
|
|
338
|
+
'font-family': this.state['font-family'],
|
|
339
|
+
'font-weight': this.state['font-weight'],
|
|
340
|
+
'font-style': this.state['font-style'],
|
|
341
|
+
'font-size': this.state['font-size'],
|
|
342
|
+
scale: this.state.scale,
|
|
343
|
+
},
|
|
344
|
+
attributes: {
|
|
345
|
+
'font-family': this.attributes['font-family'],
|
|
346
|
+
'font-weight': this.attributes['font-weight'],
|
|
347
|
+
'font-style': this.attributes['font-style'],
|
|
348
|
+
'font-size': this.attributes['font-size'],
|
|
349
|
+
fill: this.attributes.fill,
|
|
350
|
+
stroke: this.attributes.stroke,
|
|
351
|
+
'stroke-width': this.attributes['stroke-width'],
|
|
352
|
+
'stroke-dasharray': this.attributes['stroke-dasharray'],
|
|
353
|
+
},
|
|
354
|
+
shadow_attributes: {
|
|
355
|
+
width: this.shadow_attributes.width,
|
|
356
|
+
color: this.shadow_attributes.color,
|
|
357
|
+
},
|
|
358
|
+
lineWidth: this.lineWidth,
|
|
359
|
+
});
|
|
360
|
+
return this;
|
|
361
|
+
}
|
|
362
|
+
restore() {
|
|
363
|
+
const savedState = this.state_stack.pop();
|
|
364
|
+
if (savedState) {
|
|
365
|
+
const state = savedState;
|
|
366
|
+
this.state['font-family'] = state.state['font-family'];
|
|
367
|
+
this.state['font-weight'] = state.state['font-weight'];
|
|
368
|
+
this.state['font-style'] = state.state['font-style'];
|
|
369
|
+
this.state['font-size'] = state.state['font-size'];
|
|
370
|
+
this.state.scale = state.state.scale;
|
|
371
|
+
this.attributes['font-family'] = state.attributes['font-family'];
|
|
372
|
+
this.attributes['font-weight'] = state.attributes['font-weight'];
|
|
373
|
+
this.attributes['font-style'] = state.attributes['font-style'];
|
|
374
|
+
this.attributes['font-size'] = state.attributes['font-size'];
|
|
375
|
+
this.attributes.fill = state.attributes.fill;
|
|
376
|
+
this.attributes.stroke = state.attributes.stroke;
|
|
377
|
+
this.attributes['stroke-width'] = state.attributes['stroke-width'];
|
|
378
|
+
this.attributes['stroke-dasharray'] = state.attributes['stroke-dasharray'];
|
|
379
|
+
this.shadow_attributes.width = state.shadow_attributes.width;
|
|
380
|
+
this.shadow_attributes.color = state.shadow_attributes.color;
|
|
381
|
+
this.lineWidth = state.lineWidth;
|
|
382
|
+
}
|
|
383
|
+
return this;
|
|
384
|
+
}
|
|
385
|
+
set fillStyle(style) {
|
|
386
|
+
this.setFillStyle(style);
|
|
387
|
+
}
|
|
388
|
+
get fillStyle() {
|
|
389
|
+
return this.attributes.fill;
|
|
390
|
+
}
|
|
391
|
+
set strokeStyle(style) {
|
|
392
|
+
this.setStrokeStyle(style);
|
|
393
|
+
}
|
|
394
|
+
get strokeStyle() {
|
|
395
|
+
return this.attributes.stroke;
|
|
396
|
+
}
|
|
397
|
+
setFont(f, size, weight, style) {
|
|
398
|
+
const fontInfo = Font.validate(f, size, weight, style);
|
|
399
|
+
this.fontCSSString = Font.toCSSString(fontInfo);
|
|
400
|
+
const fontAttributes = {
|
|
401
|
+
'font-family': fontInfo.family,
|
|
402
|
+
'font-size': fontInfo.size,
|
|
403
|
+
'font-weight': fontInfo.weight,
|
|
404
|
+
'font-style': fontInfo.style,
|
|
405
|
+
};
|
|
406
|
+
this.attributes = Object.assign(Object.assign({}, this.attributes), fontAttributes);
|
|
407
|
+
this.state = Object.assign(Object.assign({}, this.state), fontAttributes);
|
|
408
|
+
return this;
|
|
409
|
+
}
|
|
410
|
+
getFont() {
|
|
411
|
+
return this.fontCSSString;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
SVGContext.measureTextCache = new MeasureTextCache();
|