Skip to content
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

Implement additional font options #3586

Merged
merged 30 commits into from
Feb 7, 2024
Merged

Implement additional font options #3586

merged 30 commits into from
Feb 7, 2024

Conversation

lpugin
Copy link
Contributor

@lpugin lpugin commented Jan 31, 2024

Allow support for @fontfam (currently on clef and meterSig) to use another font for these elements. To do so, the font needs to be loaded with the --font-load-all option.

Example:

image
<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="https://music-encoding.org/schema/5.0/mei-all.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?>
<?xml-model href="https://music-encoding.org/schema/5.0/mei-all.rng" type="application/xml" schematypens="http://purl.oclc.org/dsdl/schematron"?>
<mei xmlns="http://www.music-encoding.org/ns/mei" meiversion="5.0">
   <meiHead>
      <fileDesc>
         <titleStmt>
            <title>Clef change and spacing</title>
            <respStmt>
               <persName role="editor">Laurent Pugin</persName>
               <persName role="encoder">Craig Sapp</persName>
            </respStmt>
         </titleStmt>
         <pubStmt>
            <date isodate="2021-02-02">2021-02-02</date>
            <pubPlace>
               <ref target="https://github.com/rism-digital/verovio/issues/2018" />
            </pubPlace>
         </pubStmt>
         <seriesStmt>
            <title>Verovio test suite</title>
         </seriesStmt>
         <notesStmt>
            <annot>It is not necessary for clef changes on one staff to be allocated space on other staves </annot>
         </notesStmt>
      </fileDesc>
      <encodingDesc>
         <appInfo>
            <application version="3.2.0" label="2">
               <name>Verovio</name>
            </application>
         </appInfo>
      </encodingDesc>
   </meiHead>
   <music>
      <body>
         <mdiv>
            <score>
               <scoreDef midi.bpm="112">
                  <staffGrp bar.thru="true" symbol="brace">
                     <staffDef n="1" lines="5">
                        <clef shape="G" line="2" fontname="Petaluma" />
                        <keySig pname="a" mode="major" sig="3s" />
                        <meterSig count="3" unit="8" sym="common" fontname="Petaluma" enclose="brack" />
                     </staffDef>
                     <staffDef n="2" lines="5">
                        <clef shape="G" line="2" />
                        <keySig pname="a" mode="major" sig="3s" />
                        <meterSig count="3" unit="8" />
                     </staffDef>
                  </staffGrp>
               </scoreDef>
               <section>
                  <measure n="15">
                     <staff n="1">
                        <layer n="1">
                           <beam>
                              <note xml:id="note-L9F2" dur="16" oct="5" pname="b" accid.ges="n" />
                              <note dur="16" oct="5" pname="g" accid.ges="s" />
                              <note dur="16" oct="5" pname="e" accid.ges="n" />
                              <note dur="16" oct="4" pname="b" accid.ges="n" />
                              <note dur="16" oct="5" pname="d" accid="s" />
                              <note dur="16" oct="4" pname="b" accid.ges="n" />
                           </beam>
                        </layer>
                     </staff>
                     <staff n="2">
                        <layer n="1">
                           <rest dur="8" />
                           <rest dur="8" />
                           <clef shape="G" line="2" />
                           <note dur="8" oct="4" pname="a" accid.ges="n">
                              <artic artic="stacciss" />
                           </note>
                        </layer>
                     </staff>
                     <dynam place="between" staff="1 2" tstamp="1.000000">mf</dynam>
                     <slur staff="1" startid="#note-L9F2" endid="#note-L22F2" />
                  </measure>
                  <measure n="16">
                     <staff n="1">
                        <layer n="1">
                           <beam>
                              <note dur="16" oct="5" pname="e" accid.ges="n" />
                              <note dur="16" oct="4" pname="b" accid.ges="n" />
                              <note dur="16" oct="5" pname="f" accid.ges="s" />
                              <note dur="16" oct="4" pname="b" accid.ges="n" />
                              <note dur="16" oct="5" pname="g" accid.ges="s" />
                              <note xml:id="note-L22F2" dur="16" oct="4" pname="b" accid.ges="n" />
                           </beam>
                        </layer>
                     </staff>
                     <staff n="2">
                        <layer n="1">
                           <beam>
                              <note dur="8" oct="4" pname="g" accid.ges="s">
                                 <artic artic="stacciss" />
                              </note>
                              <note dur="8" oct="4" pname="f" accid.ges="s">
                                 <artic artic="stacciss" />
                              </note>
                              <note dur="8" oct="4" pname="e" accid.ges="n">
                                 <artic artic="stacciss" />
                              </note>
                           </beam>
                        </layer>
                     </staff>
                  </measure>
               </section>
            </score>
         </mdiv>
      </body>
   </music>
</mei>

@lpugin
Copy link
Contributor Author

lpugin commented Jan 31, 2024

@fernandoherreradelasheras the --font-add-custom option will be for loading external font (i.e., fonts not in the resource directory but to be passed as parameter as zip files).

@lpugin
Copy link
Contributor Author

lpugin commented Feb 7, 2024

Summary: this PR add the following font options

Load all fonts

The --font-load-all boolean option makes Verovio loads all the music fonts available in the resource directory. That way, a specific font other than the default font Leipzig or the font set with the --font option can be used by specifying a @fontname value. At this stage, this is supporting only on clef and meterSig.

Set a specific fall back

The --font-fallback parameter option allows to choose between Leipzig (default) or Bravura as the fallback font to be used when the font chosen is missing a glyph.

Loading custom fonts

The --font-add-custom parameter option allows to load and use an external font not available in the resource directory. The option is repeatable, which means that more than one external font can be loaded. For bindings that use JSON options, the value(s) must be passed in an array.

The custom font must be archived in a ZIP file containing the files produced by the font script Verovio provides for extracting relevant information from an SVG font file and the corresponding SMuFL metadata. These files are:

  • The XML file with bounding boxes of the included glyphs.
  • The XML snippets for each glyph
  • The CSS file of the font for text

The ZIP filename must correspond to the name of the font. For the JavaScript binding, the ZIP file must be encoded in Base64 and passed as a URL.

Example rendered with --font-fallback Bravura and --font-add-custom GoldenAge.zip (available here) and all fonts loaded with --font-load-all. The elements in olive have a @fontame="Petaluma". The clef in orange is a Bravura fallback.

image
<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="https://music-encoding.org/schema/5.0/mei-all.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?>
<?xml-model href="https://music-encoding.org/schema/5.0/mei-all.rng" type="application/xml" schematypens="http://purl.oclc.org/dsdl/schematron"?>
<mei xmlns="http://www.music-encoding.org/ns/mei" meiversion="5.0">
   <meiHead>
      <fileDesc>
         <titleStmt>
            <title>Changing fonts</title>
            <respStmt>
               <persName role="encoder">Laurent Pugin</persName>
            </respStmt>
         </titleStmt>
         <pubStmt>
            <date isodate="2024-02-07" />
         </pubStmt>
         <seriesStmt>
            <title>Verovio test suite</title>
         </seriesStmt>
         <notesStmt>
            <annot>The font can be changed on clef and metersig with @fontname. This option --font-load-all needs to be set.</annot>
         </notesStmt>
      </fileDesc>
      <encodingDesc>
         <appInfo>
            <application version="4.2.0" label="2">
               <name>Verovio</name>
            </application>
         </appInfo>
      </encodingDesc>
   </meiHead>
   <music>
      <body>
         <mdiv>
            <score>
               <scoreDef midi.bpm="112.000000">
                  <staffGrp bar.thru="true" symbol="brace">
                     <staffDef n="1" lines="5">
                        <clef shape="G" color="olive" line="2" fontname="Petaluma" />
                        <keySig mode="major" sig="3s" pname="a" />
                        <meterSig enclose="brack" count="3" sym="common" unit="8" fontname="Petaluma" color="olive" />
                     </staffDef>
                     <staffDef n="2" lines="5">
                        <clef shape="F" line="4" />
                        <keySig mode="major" sig="3s" pname="a" />
                        <meterSig count="3" unit="8" />
                     </staffDef>
                  </staffGrp>
               </scoreDef>
               <section>
                  <measure n="15">
                     <staff n="1">
                        <layer n="1">
                           <beam>
                              <note xml:id="note-L9F2" dur="16" oct="5" pname="b" accid.ges="n" />
                              <note dur="16" oct="5" pname="g" accid.ges="s" />
                              <note dur="16" oct="5" pname="e" accid.ges="n" />
                              <note dur="16" oct="4" pname="b" accid.ges="n" />
                              <note dur="16" oct="5" pname="d" accid="s" />
                              <note dur="16" oct="4" pname="b" accid.ges="n" />
                           </beam>
                        </layer>
                     </staff>
                     <staff n="2">
                        <layer n="1">
                           <rest dur="8" />
                           <rest dur="8" />
                           <clef shape="G" line="2" color="orange" />
                           <note dur="8" oct="4" pname="a" accid.ges="n">
                              <artic artic="stacciss" />
                           </note>
                        </layer>
                     </staff>
                     <dynam place="between" staff="1 2" tstamp="1.000000">mezzo f</dynam>
                     <slur staff="1" startid="#note-L9F2" endid="#note-L22F2" />
                  </measure>
                  <measure n="16">
                     <staff n="1">
                        <layer n="1">
                           <beam>
                              <note dur="16" oct="5" pname="e" accid.ges="n" />
                              <note dur="16" oct="4" pname="b" accid.ges="n" />
                              <note dur="16" oct="5" pname="f" accid.ges="s" />
                              <note dur="16" oct="4" pname="b" accid.ges="n" />
                              <note dur="16" oct="5" pname="g" accid.ges="s" />
                              <note xml:id="note-L22F2" dur="16" oct="4" pname="b" accid.ges="n" />
                           </beam>
                        </layer>
                     </staff>
                     <staff n="2">
                        <layer n="1">
                           <beam>
                              <note dur="8" oct="4" pname="g" accid.ges="s">
                                 <artic artic="stacciss" />
                              </note>
                              <note dur="8" oct="4" pname="f" accid.ges="s">
                                 <artic artic="stacciss" />
                              </note>
                              <note dur="8" oct="4" pname="e" accid.ges="n">
                                 <artic artic="stacciss" />
                              </note>
                           </beam>
                        </layer>
                     </staff>
                  </measure>
               </section>
            </score>
         </mdiv>
      </body>
   </music>
</mei>

@rettinghaus
Copy link
Contributor

I think in your description you mixed up load-all-font with font-load-all.

@lpugin lpugin requested review from xhero and rettinghaus February 7, 2024 11:23
@xhero xhero merged commit a4931e3 into develop Feb 7, 2024
9 checks passed
@lpugin lpugin deleted the develop-fonts branch February 7, 2024 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants