-
Notifications
You must be signed in to change notification settings - Fork 668
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fonts: DEMOS #1216
Fonts: DEMOS #1216
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Fonts | ||
|
||
## all.html | ||
|
||
The full `vexflow.js` includes the following music engraving fonts: Bravura, Petaluma, Gonville, and Custom. In this case, `Vex.Flow.setMusicFont('Bravura', ...);` is a synchronous function that changes the current font stack. | ||
|
||
## core.html | ||
|
||
These files depends on `vexflow-core.js` and the individual font JS files: | ||
|
||
``` | ||
vexflow-font-bravura.js | ||
vexflow-font-gonville.js | ||
vexflow-font-petaluma.js | ||
vexflow-font-custom.js | ||
``` | ||
|
||
`core.html` uses the await keyword to call an async function that returns once the requested font is successfully loaded: | ||
|
||
``` | ||
await Vex.Flow.setMusicFont('Petaluma');` | ||
``` | ||
|
||
## core-with-promise.html | ||
|
||
The async `Vex.Flow.setMusicFont(...)` returns a Promise. This demo shows how to use a `.then(onFulfilledCallback)` to request a font stack, and initialize VexFlow once the fonts are ready. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
<div id="outputBravura"></div> | ||
<div id="outputGonville"></div> | ||
<div id="outputPetaluma"></div> | ||
<!-- The standard vexflow build includes three music fonts. --> | ||
<script src="../../build/vexflow.js"></script> | ||
<script type="module"> | ||
console.log('VexFlow BUILD ' + Vex.Flow.BUILD); | ||
|
||
//////////////////////////////////////////////////////////////////////// | ||
|
||
{ | ||
Vex.Flow.setMusicFont('Bravura'); | ||
ronyeh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const factory = new Vex.Flow.Factory({ | ||
renderer: { elementId: 'outputBravura', width: 500, height: 130 }, | ||
}); | ||
const score = factory.EasyScore(); | ||
factory | ||
.System() | ||
.addStave({ | ||
voices: [ | ||
score.voice(score.notes('C#5/q, B4, A4, G#4', { stem: 'up' })), | ||
score.voice(score.notes('C#4/h, C#4', { stem: 'down' })), | ||
], | ||
}) | ||
.addClef('treble') | ||
.addTimeSignature('4/4'); | ||
factory.draw(); | ||
} | ||
|
||
//////////////////////////////////////////////////////////////////////// | ||
|
||
{ | ||
Vex.Flow.setMusicFont('Gonville'); | ||
ronyeh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const factory = new Vex.Flow.Factory({ | ||
renderer: { elementId: 'outputGonville', width: 500, height: 130 }, | ||
}); | ||
const score = factory.EasyScore(); | ||
factory | ||
.System() | ||
.addStave({ | ||
voices: [ | ||
score.voice(score.notes('C#5/q, B4, A4, G#4', { stem: 'up' })), | ||
score.voice(score.notes('C#4/h, C#4', { stem: 'down' })), | ||
], | ||
}) | ||
.addClef('treble') | ||
.addTimeSignature('4/4'); | ||
factory.draw(); | ||
} | ||
|
||
//////////////////////////////////////////////////////////////////////// | ||
|
||
{ | ||
Vex.Flow.setMusicFont('Petaluma'); | ||
const factory = new Vex.Flow.Factory({ | ||
renderer: { elementId: 'outputPetaluma', width: 500, height: 130 }, | ||
}); | ||
const score = factory.EasyScore(); | ||
factory | ||
.System() | ||
.addStave({ | ||
voices: [ | ||
score.voice(score.notes('C#5/q, B4, A4, G#4', { stem: 'up' })), | ||
score.voice(score.notes('C#4/h, C#4', { stem: 'down' })), | ||
], | ||
}) | ||
.addClef('treble') | ||
.addTimeSignature('4/4'); | ||
factory.draw(); | ||
} | ||
</script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<!DOCTYPE html> | ||
<!-- | ||
Instead of async/await, you can use Promise style chains. | ||
For example: Vex.Flow.setMusicFont(...).then(onFulfilledCallback) | ||
--> | ||
<html> | ||
<body> | ||
<div id="output"></div> | ||
<!-- The vexflow core build includes no music fonts. --> | ||
<script src="../../build/vexflow-core.js"></script> | ||
<script> | ||
// Vex.Flow.setMusicFont(...fontNames) is an async function that triggers | ||
// the loading of the fonts (stored in vexflow-font-xxxx.js). | ||
// It returns a Promise that resolves to the loaded music font(s). | ||
Vex.Flow.setMusicFont('Petaluma', 'Bravura', 'Gonville', 'Custom').then(onFontsLoaded); | ||
ronyeh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
function onFontsLoaded(musicFonts) { | ||
console.log('Successfully loaded this music font stack:'); | ||
const [bravura, gonville, petaluma, custom] = musicFonts; | ||
console.log(bravura, gonville, petaluma, custom); | ||
|
||
const factory = new Vex.Flow.Factory({ renderer: { elementId: 'output', width: 500, height: 200 } }); | ||
const score = factory.EasyScore(); | ||
const system = factory.System(); | ||
system | ||
.addStave({ | ||
voices: [ | ||
score.voice(score.notes('C#5/q, B4, A4, G#4', { stem: 'up' })), | ||
score.voice(score.notes('C#4/h, C#4', { stem: 'down' })), | ||
], | ||
}) | ||
.addClef('treble') | ||
.addTimeSignature('4/4'); | ||
factory.draw(); | ||
} | ||
</script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<!-- | ||
Use async/await to load fonts dynamically. | ||
For example: await Vex.Flow.setMusicFont('Bravura') | ||
Open the developer console to verify that only vexflow-core.js is loaded when this page is first shown. | ||
--> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<style> | ||
html { | ||
font: 16px 'Helvetica Neue', Arial, sans-serif; | ||
} | ||
body { | ||
margin: 20px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<p>Choose one of the fonts below:</p> | ||
<div> | ||
<a href="#" onclick="chooseFont('Bravura')">Bravura</a> | ||
<a href="#" onclick="chooseFont('Gonville')">Gonville</a> | ||
<a href="#" onclick="chooseFont('Petaluma')">Petaluma</a> | ||
</div> | ||
<div id="output"></div> | ||
<!-- The vexflow core build includes no music fonts. --> | ||
<script src="../../build/vexflow-core.js"></script> | ||
<script type="module"> | ||
async function chooseFont(fontName) { | ||
const container = document.getElementById('output'); | ||
while (container.firstChild) { | ||
container.removeChild(container.firstChild); | ||
} | ||
|
||
// Vex.Flow.setMusicFont(fontName) is an async function that triggers | ||
// the loading of the font stored in vexflow-font-${fontName}.js. | ||
// Choose between: | ||
// await Vex.Flow.setMusicFont('Bravura') | ||
// await Vex.Flow.setMusicFont('Gonville') | ||
// await Vex.Flow.setMusicFont('Petaluma') | ||
await Vex.Flow.setMusicFont(fontName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For vexflow-core.js, Flow.setMusicFont(fontName) is async. So you'll have to use |
||
|
||
renderScore(); | ||
} | ||
|
||
function renderScore() { | ||
const factory = new Vex.Flow.Factory({ renderer: { elementId: 'output', width: 500, height: 200 } }); | ||
const score = factory.EasyScore(); | ||
const system = factory.System(); | ||
system | ||
.addStave({ | ||
voices: [ | ||
score.voice(score.notes('C#5/q, B4, A4, G#4', { stem: 'up' })), | ||
score.voice(score.notes('C#4/h, C#4', { stem: 'down' })), | ||
], | ||
}) | ||
.addClef('treble') | ||
.addTimeSignature('4/4'); | ||
factory.draw(); | ||
} | ||
window.chooseFont = chooseFont; | ||
</script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!DOCTYPE html> | ||
<!-- | ||
vexflow-core-with-bravura.js bundles the Bravura music font. | ||
There is no need to call Vex.Flow.setMusicFont(...). | ||
--> | ||
<html> | ||
<body> | ||
<div id="output"></div> | ||
<script src="../../build/vexflow-core-with-bravura.js"></script> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are new! Simon of OSMD requested support for smaller builds without undesired fonts.
|
||
<script type="module"> | ||
const factory = new Vex.Flow.Factory({ renderer: { elementId: 'output', width: 500, height: 200 } }); | ||
const score = factory.EasyScore(); | ||
const system = factory.System(); | ||
system | ||
.addStave({ | ||
voices: [ | ||
score.voice(score.notes('C#5/q, B4, A4, G#4', { stem: 'up' })), | ||
score.voice(score.notes('C#4/h, C#4', { stem: 'down' })), | ||
], | ||
}) | ||
.addClef('treble') | ||
.addTimeSignature('4/4'); | ||
factory.draw(); | ||
</script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!DOCTYPE html> | ||
<!-- | ||
vexflow-core-with-gonville.js bundles the Gonville music font. | ||
There is no need to call Vex.Flow.setMusicFont(...). | ||
--> | ||
<html> | ||
<body> | ||
<div id="output"></div> | ||
<script src="../../build/vexflow-core-with-gonville.js"></script> | ||
<script type="module"> | ||
const factory = new Vex.Flow.Factory({ renderer: { elementId: 'output', width: 500, height: 200 } }); | ||
const score = factory.EasyScore(); | ||
const system = factory.System(); | ||
system | ||
.addStave({ | ||
voices: [ | ||
score.voice(score.notes('C#5/q, B4, A4, G#4', { stem: 'up' })), | ||
score.voice(score.notes('C#4/h, C#4', { stem: 'down' })), | ||
], | ||
}) | ||
.addClef('treble') | ||
.addTimeSignature('4/4'); | ||
factory.draw(); | ||
</script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!DOCTYPE html> | ||
<!-- | ||
vexflow-core-with-petaluma.js bundles the Petaluma music font. | ||
There is no need to call Vex.Flow.setMusicFont(...). | ||
--> | ||
<html> | ||
<body> | ||
<div id="output"></div> | ||
<script src="../../build/vexflow-core-with-petaluma.js"></script> | ||
<script type="module"> | ||
const factory = new Vex.Flow.Factory({ renderer: { elementId: 'output', width: 500, height: 200 } }); | ||
const score = factory.EasyScore(); | ||
const system = factory.System(); | ||
system | ||
.addStave({ | ||
voices: [ | ||
score.voice(score.notes('C#5/q, B4, A4, G#4', { stem: 'up' })), | ||
score.voice(score.notes('C#4/h, C#4', { stem: 'down' })), | ||
], | ||
}) | ||
.addClef('treble') | ||
.addTimeSignature('4/4'); | ||
factory.draw(); | ||
</script> | ||
</body> | ||
</html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a huge fan of this big comment line :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. Will remove. Sometimes I put in these "horizontal separators" to help guide the code reader between large code blocks, but here I have extra braces { } anyways, so they're probably not needed.