getSvgAttributes method
Implementation
Map<String, dynamic> getSvgAttributes(
ChantContext ctxt, [
ChantLayoutElement? source,
]) {
String className = '';
String? id;
bool porrectus = <GlyphCode>[
.porrectus1,
.porrectus2,
.porrectus3,
.porrectus4,
].contains(glyphCode);
if (porrectus) {
var notes = (source as Note).neume!.notes;
var noteIndex = notes.indexOf(source);
var nextNote = noteIndex < notes.length - 1 ? notes[noteIndex + 1] : null;
className = switch ((source.selected, nextNote?.selected ?? false)) {
(true, true) => "selected",
(true, false) => "selectedA",
(false, true) => "selectedB",
(false, false) => "",
};
} else {
bool selected = switch (source) {
Clef c => c.model?.selected ?? false,
ChantLayoutElement e => e.selected,
_ => false,
};
className = selected ? "selected" : "";
}
if (source is Note) {
className += ' note';
id = '${ctxt.noteIdPrefix}${source.noteIndex ?? 0 + 1}';
if (porrectus) {
className += ' porrectus porrectus-start';
} else if (source.glyphVisualizer?.glyphCode == .none) {
className += ' porrectus porrectus-end';
}
} else if (source is Clef) {
className += ' clef';
}
return <String, dynamic>{
'xlink:href': '#$glyphCode',
'class': className,
if (ctxt.stylingMode == .attributes)
'fill': ctxt.theme.neumeColor.toSvgString(),
'id': ?id,
if (source is ChantNotationElement)
'data-source-index': source.sourceIndex,
if (source is ChantNotationElement)
'data-element-index': source.elementIndex,
'x': ctxt.scaleDefs
? bounds.x + origin.x
: (bounds.x + origin.x) / ctxt.glyphScaling,
'y': ctxt.scaleDefs
? bounds.y + origin.y
: (bounds.y + origin.y) / ctxt.glyphScaling,
if (!ctxt.scaleDefs) 'transform': 'scale(${ctxt.glyphScaling})',
};
}