App-Music-ChordPro
view release on metacpan or search on metacpan
lib/ChordPro/res/abc/abc2svg/grid-1.js view on Meta::CPAN
}
// get the number of columns
if (nc < 0)
nc = -nc
if (nc < 3) // auto
nc = cells.length % 6 == 0 ? 6 : 8
if (nc > cells.length)
nc = cells.length;
hr = font.size * 2
if (wmx < hr * 1.5)
wmx = hr * 1.5 // cell width
x0 = img.width - img.lm - img.rm // staff width
w = wmx * nc
if (w > x0) {
nc /= 2;
w /= 2
}
// generate the cells
yl = -1
y = -1 + font.size * .6
nr = -1
x0 = (x0 / cfmt.scale - w) / 2
d = []
for (i = 0; i < cells.length; i++) {
if (i == 0
|| (grid.repbrk
&& (bars[i].slice(-1) == ':' || bars[i][0] == ':'))
|| parts[i]
|| k >= nc) {
y -= hr // new row
yl -= hr
x = x0 + wmx / 2
k = 0
nr++
d[nr] = []
}
d[nr][k] = 1
k++
build_cell(cells[i], x, y, yl, hr)
x += wmx
}
// draw the lines
abc.out_svg('<path class="stroke" stroke-width="1" d="\n')
draw_hl()
draw_vl()
abc.out_svg('"/>\n')
// show the repeat signs and the parts
y = -1 + font.size * .7
x = x0
for (i = 0; i < bars.length; i++) {
bar = bars[i]
if (bar[0] == ':') {
abc.out_svg('<text class="' + cls + '" x="')
abc.out_sxsy(x - 5, '" y="', y)
abc.out_svg('" style="font-weight:bold;font-size:' +
(font.size * 1.5).toFixed(1) + 'px">:</text>\n')
}
if (i == 0
|| (grid.repbrk
&& (bar.slice(-1) == ':' || bar[0] == ':'))
|| parts[i]
|| k >= nc) {
y -= hr; // new row
x = x0
k = 0
if (parts[i]) {
w = abc.strwh(parts[i])[0]
abc.out_svg('<text class="' + cls + '" x="')
abc.out_sxsy(x - 2 - w, '" y="', y)
abc.out_svg('" style="font-weight:bold">' +
parts[i] + '</text>\n')
}
}
k++
if (bar.slice(-1) == ':') {
abc.out_svg('<text class="' + cls + '" x="')
abc.out_sxsy(x + 5, '" y="', y)
abc.out_svg('" style="font-weight:bold;font-size:' +
(font.size * 1.5).toFixed(1) + 'px">:</text>\n')
}
x += wmx
}
abc.vskip(hr * (nr + 1) + 6)
} // build_grid()
// ----- block_gen() -----
var p_voice, n, font, f2
abc.set_page()
img = abc.get_img()
// set the text style
font = abc.get_font('grid')
if (font.class)
font.class += ' mid'
else
font.class = 'mid'
cls = abc.font_class(font)
// define a smaller font
abc.param_set_font("gsfont",
font.name + ' ' + (font.size * .7).toFixed(1))
f2 = cfmt.gsfont
if (font.weight)
f2.weight = font.weight
if (font.style)
f2.style = font.style
f2.class = font.class
abc.add_style("\n.mid {text-anchor:middle}")
// create the grid
abc.blk_flush()
build_grid(s, font)
abc.blk_flush()
}, // block_gen()
set_stems: function(of) {
var C = abc2svg.C,
abc = this,
tsfirst = abc.get_tsfirst(),
voice_tb = abc.get_voice_tb(),
cfmt = abc.cfmt(),
grid = cfmt.grid
// extract one of the chord symbols
// With chords as "[yyy];xxx"
// (!sel - default) returns "yyy" and (sel) returns "xxx"
function cs_filter(a_cs) {
var i, cs, t
for (i = 0; i < a_cs.length; i++) {
cs = a_cs[i]
if (cs.type != 'g')
continue
t = cs.text
if (cfmt.altchord) {
for (i++; i < a_cs.length; i++) {
cs = a_cs[i]
( run in 0.804 second using v1.01-cache-2.11-cpan-5a3173703d6 )