App-Music-ChordPro
view release on metacpan or search on metacpan
lib/ChordPro/res/abc/abc2svg/grid3-1.js view on Meta::CPAN
? (img.width / cfmt.scale - w) / 2 // center
: s.lm + 1
if ((s.fmt || cfmt).trimsvg) // adjust the SVG width
img.wx = x0 + w - img.lm - img.rm
// generate the cells
yl = posy + 3
y = posy + 3 - font.size * .7
while (1) {
cl = cells.shift()
if (!cl)
break
y += hr
yl += hr
x = x0 + wc / 2
while (1) {
cell = cl.shift()
if (!cell)
break
lc += build_cell(cell, x, y, yl, hr)
x += wc
}
}
// draw the lines
line = '<path class="stroke" d="\n'
y = posy + 3
for (i = 0; i <= nr; i++) {
line += 'M' + x0.toFixed(1) + ' ' + y.toFixed(1) +
'h' + w.toFixed(1)+ '\n'
y += hr
}
x = x0
y = posy + 3
for (i = 0; i <= nc; i++) {
line += 'M' + x.toFixed(1) + ' ' + y.toFixed(1) +
'v' + (hr * nr).toFixed(1) + '\n'
x += wc
}
line += '"/>\n'
// insert the cells
line += lc
// show the repeat signs
y = posy + 3 - font.size * .7
while (1) {
bl = bars.shift()
if (!bl)
break
x = x0
y += hr
while (1) {
bar = bl.shift()
if (!bar)
break
if (bar[0] == ':')
line += '<text class="' + cls + '" x="' +
(x - 5).toFixed(1) +
'" y="' + y.toFixed(1) +
'" style="font-weight:bold;font-size:' +
(font.size * 1.6).toFixed(1) +
'px">:</text>\n'
if (bar.slice(-1) == ':')
line += '<text class="' + cls + '" x="' +
(x + 5).toFixed(1) +
'" y="' + y.toFixed(1) +
'" style="font-weight:bold;font-size:' +
(font.size * 1.6).toFixed(1) +
'px">:</text>\n'
x += wc
}
}
abc.out_svg(line)
abc.vskip(hr * nr + 6)
} // build_grid()
// ----- block_gen ----
// set the text style
if (!cfmt.gridfont)
abc.param_set_font("gridfont", "serif 16")
font = abc.get_font('grid')
font_cl = abc.font_class(font)
cls = font_cl + " mid"
abc.add_style("\n.mid {text-anchor:middle}")
abc.set_font('grid') // (for strwh())
// scan the grid content
txt = txt.split('\n')
while (1) {
ln = txt.shift() // line
if (!ln)
break
// extract the bars and the chords
ln = ln.match(/[|:]+|[^|:\s]+/g)
bars[nr] = []
cells[nr] = []
i = -1
while (1) {
cl = ln.shift()
if (!cl)
break
if (cl.match(/[:|]+/)) {
bars[nr][++i] = cl
cells[nr][i] = []
} else {
if (!cells[nr][i]) { // if starting '|' is missing
bars[nr][++i] = '|'
cells[nr][i] = []
}
if (cl == '.' || cl == '-')
cl = ''
cells[nr][i].push(cl)
}
}
if (cells[nr][i].length)
bars[nr][++i] = '|' // missing ending bar
else
cells[nr][i] = null // keep just the measure bar
if (i > nc)
nc = i
i = 0
while (1) {
cl = cells[nr][i++]
( run in 0.683 second using v1.01-cache-2.11-cpan-98e64b0badf )