App-Music-ChordPro

 view release on metacpan or  search on metacpan

lib/ChordPro/res/abc/abc2svg/grid2-1.js  view on Meta::CPAN


    // adjust the width of the symbol with a chord
    set_w: function(of, s) {
	of(s)
	if (!s.p_v || !s.p_v.grid2
	 || !s.a_gch
	 || ((!s.prev || s.prev.invis)
	  && (!s.next || s.next.invis)))
		return
    var	i, gch

	for (i = 0; i < s.a_gch.length; i++) {
		gch = s.a_gch[i]
		if (gch.type == 'g') {
			if (s.wl < -gch.x)
				s.wl = -gch.x
			if (s.wr < gch.text.wh[0])
				s.wr = gch.text.wh[0]
			break
		}
	}
    }, // set_w()

    // draw the chord symbol in the middle of the staff
    draw_gchord: function(of, i, s, x, y) {
    var	an
	if (s.p_v.grid2) {
		this.set_dscale(s.st)
		an = s.a_gch[i]
		if (an.type == 'g') {
			this.use_font(an.font)
			this.set_font(an.font)
			this.xy_str(s.x + an.x, 12 - an.font.size * .5,
					an.text)
		}
	} else {
		of(i, s, x, y)
	}
    },

    output_music: function(of) {
	abc2svg.grid2.do_grid.call(this);
	of()
    },

    set_fmt: function(of, cmd, param) {
	if (cmd == "grid2") {
	    var	curvoice = this.get_curvoice(),
		v = this.get_bool(param)

		if (curvoice)
			curvoice.grid2 = v
		else
			this.cfmt().grid2 = v
		return
	}
	of(cmd, param)
    },

    set_hooks: function(abc) {
	abc.draw_gchord = abc2svg.grid2.draw_gchord.bind(abc, abc.draw_gchord);
	abc.output_music = abc2svg.grid2.output_music.bind(abc, abc.output_music);
	abc.set_format = abc2svg.grid2.set_fmt.bind(abc, abc.set_format)
	abc.set_width = abc2svg.grid2.set_w.bind(abc, abc.set_width)
    }
} // grid2

if (!abc2svg.mhooks)
	abc2svg.mhooks = {}
abc2svg.mhooks.grid2 = abc2svg.grid2.set_hooks



( run in 0.691 second using v1.01-cache-2.11-cpan-2398b32b56e )