App-Music-ChordPro
view release on metacpan or search on metacpan
lib/ChordPro/res/abc/abc2svg/tunhd-1.js view on Meta::CPAN
item = line[i++] // [ align, string, height ]
if (!item)
break
align = item[0]
h = item[2] * 1.1
if (y < h)
y = h
yb[align] = item[2]
}
ya.l += y - yb.l
ya.c += y - yb.c
ya.r += y - yb.r
while (1) {
item = line.shift()
if (!item)
break
align = item[0]
p = item[1]
h = item[2] * 1.1
x = xa[align]
y = ya[align] + h
yd = y - item[2] * .22 // descent
abc.out_svg('<text class="'
+ abc.font_class(hfnt)
+ '" x="')
abc.out_sxsy(x, '" y="', -yd)
if (align == 'c')
abc.out_svg('" text-anchor="middle')
else if (align == 'r')
abc.out_svg('" text-anchor="end')
abc.out_svg('">' + p + '</text>\n')
ya[align] = y
}
if (ya.c > ya.l)
ya.l = ya.c
if (ya.r > ya.l)
ya.l = ya.r
ya.c = ya.r = ya.l
} // out()
// convert a string containing info fields ($x)
// and return [ align, string, height ]
function cnv(p) {
var c, j, t, fntnam, fnt, wh, nfnt,
h = 0,
i = 0,
l = 0,
o = ""
while (1) {
c = p[i++]
if (!c)
break
if (c != '$') {
if (!o)
h = hfnt.size * 1.1
o += c
continue
}
if (p[i] < 'A' || p[i] > 'Z') {
if (isNaN(+p[i]))
o += c
else
nfnt = +p[i++]
continue
}
c = p[i++] // info letter
if (!info[c])
continue // return?
j = info_nb[c] || 0
info_nb[c] = j + 1
t = info[c].split('\n')[j] // info value
if (!t)
continue // return?
fntnam = abc2svg.tunhd.info_fnt[c] || "history"
fnt = abc.get_font(fntnam)
switch (c) {
case 'P':
t = cfmt.partname ? abc.part_seq(c) : info.P
break
case 'Q':
abc.set_width(glovar.tempo)
t = glovar.tempo.tempo_str
glovar.tempo.invis = 1 //true
break
case 'T':
if (j)
fnt = abc.get_font("subtitle")
break
default:
t = info[c].split('\n')[j]
break
}
if (fnt != hfnt || nfnt) {
if (nfnt)
fnt = abc.get_font("u" + nfnt)
abc.set_font(fnt)
}
if (c == 'Q') { // string already formatted
wh = glovar.tempo.tempo_wh
} else {
t = abc.str2svg(t)
wh = t.wh
}
if (fnt != hfnt)
t = '<tspan class="' + abc.font_class(fnt)
+ '">' + t + '</tspan>'
if (wh[1] > h)
h = wh[1]
o += t
}
if (!o)
return
return [ align, o, h]
} // cnv()
abc.set_font(hfnt)
while (1) {
while (p[i] == ' ')
i++
c = p[i++]
( run in 0.523 second using v1.01-cache-2.11-cpan-4e7a2411597 )