Skip to content

Commit

Permalink
Merge pull request #201 from rettinghaus/develop-text
Browse files Browse the repository at this point in the history
add technique text handling
  • Loading branch information
ahankinson authored Feb 13, 2023
2 parents 1818b4d + 71761ac commit c112f4f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
37 changes: 25 additions & 12 deletions src/TextHandler.mss
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ function InitTextHandlers() {
RegisterHandlers(textHandlers, CreateDictionary(
'StyleId', CreateDictionary(
'text.staff.expression', 'ExpressionTextHandler',
'text.system.page_aligned.title', 'PageTitleHandler',
'text.system.page_aligned.subtitle', 'PageTitleHandler',
'text.system.page_aligned.composer', 'PageComposerTextHandler',
'text.system.tempo', 'TempoTextHandler',
'text.staff.plain', 'CreateAnchoredText',
'text.staff.space.figuredbass', 'FiguredBassTextHandler',
'text.staff.plain', 'CreateAnchoredText'
'text.staff.technique', 'CreateDirective',
'text.system.page_aligned.composer', 'PageComposerTextHandler',
'text.system.page_aligned.subtitle', 'PageTitleHandler',
'text.system.page_aligned.title', 'PageTitleHandler',
'text.system.tempo', 'TempoTextHandler'
)
), Self);

Expand Down Expand Up @@ -111,27 +112,39 @@ function FiguredBassTextHandler (this, textObject) {
} //$end


function CreateAnchoredText (this, textObj) {
function CreateAnchoredText (this, textObject) {
anchoredText = libmei.AnchoredText();
AddFormattedText(anchoredText, textObj);
AddFormattedText(anchoredText, textObject);
return anchoredText;
} //$end

function CreateDirective (this, textObject) {
directive = GenerateControlEvent(textObject, 'Dir');
AddFormattedText(directive, textObject);
styleIdPrefix = 'text.staff.';
textStyle = Substring(textObject.StyleId, Length(styleIdPrefix));
if (MSplitString(textObject.StyleId, '.')[-2] = 'user')
{
textStyle = textObject.StyleAsText;
}
libmei.AddAttribute(directive, 'label', textStyle);
return directive;
} //$end

function AddFormattedText (parentElement, textObj) {
textWithFormatting = textObj.TextWithFormatting;
function AddFormattedText (parentElement, textObject) {
textWithFormatting = textObject.TextWithFormatting;
if (textWithFormatting.NumChildren < 2 and CharAt(textWithFormatting[0], 0) != '\\')
{
// We have a simple text element without special style properties
if (parentElement.name = 'div')
{
p = libmei.P();
libmei.SetText(p, textObj.Text);
libmei.SetText(p, textObject.Text);
libmei.AddChild(parentElement, p);
}
else
{
libmei.SetText(parentElement, textObj.Text);
libmei.SetText(parentElement, textObject.Text);
}
return parentElement;
}
Expand All @@ -148,7 +161,7 @@ function AddFormattedText (parentElement, textObj) {
'meiNodes', nodes
);

for each component in textObj.TextWithFormatting
for each component in textObject.TextWithFormatting
{
switch (Substring(component, 0, 2))
{
Expand Down
6 changes: 5 additions & 1 deletion test/mocha/test-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,8 @@ describe("Text elements", function() {
assert.notStrictEqual(larger.length, 0, "No matching elements to assert were found!");
assert.notEqual(larger.getAttribute("fontsize"), null, "@fontsize is missing");
});
});
it("exports techique text from measure 7", function() {
const dir = xpath.evaluateXPath("//*:measure[@n='7']/*:dir", meiText);
assert.strictEqual(dir.getAttribute('class'), "technique");
});
});
Binary file modified test/sibmeiTestSibs/text.sib
Binary file not shown.

0 comments on commit c112f4f

Please sign in to comment.