// page.js - module to generate pages
//
// Copyright (C) 2018-2025 Jean-Francois Moine
//
// This file is part of abc2svg.
//
// abc2svg is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// abc2svg is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with abc2svg. If not, see .
//
// This module is loaded when "%%pageheight" appears in a ABC source.
//
// Parameters
// %%pageheight
if (typeof abc2svg == "undefined")
var abc2svg = {}
abc2svg.page = {
// function called at end of generation
abc_end: function(of) {
var page = this.page
if (page && page.in_page)
abc2svg.page.close_page(page)
// restore user.img_out and abc2svg.abc_end (needed when more generation)
if (abc2svg.page.user_out) {
this.get_user().img_out = abc2svg.page.user_out
abc2svg.page.user_out = null
abc2svg.abc_end = of
}
of()
}, // abc_end()
// output the SVG tag
svg_tag: function(w, h, ty, user) {
w = Math.ceil(w)
h = Math.ceil(h)
return '')
page.hmax -= h;
page.hf = ''
} else if (ht) {
abc2svg.page.user_out(abc2svg.page.svg_tag(cfmt.pagewidth, ht,
"header", abc.get_user())
+ '\n')
}
if (page.footer) {
abc.clr_sty()
if (!cfmt.footerfont)
abc.param_set_font("footerfont", "text,serif 16")
page.fh = abc2svg.page.gen_hf(page, "footer")
sty = abc.get_font_style() // new style(s)
if (cfmt.fullsvg || sty != page.fsty) {
page.fsty = sty
page.ffsty = '\n'
} else {
page.ffsty = ''
}
page.hmax -= page.fh
}
page.h = 0
}, // open_page()
close_page: function(page) {
var h,
cfmt = page.abc.cfmt()
page.in_page = false
if (page.footer) {
h = page.hmax + page.fh - page.h
if (h)
abc2svg.page.user_out(
abc2svg.page.svg_tag(cfmt.pagewidth, h,
"footer", page.abc.get_user()) +
page.ffsty +
'\n' +
page.hf + '\n')
}
abc2svg.page.user_out('')
page.h = 0
}, // close_page()
// handle the output flow of the abc2svg generator
img_in: function(p) {
var h, ht, nh,
page = this.page
// copy a block
function blkcpy(page) {
while (page.blk.length)
abc2svg.page.user_out(page.blk.shift())
page.blk = null // direct output
} // blkcpy()
// img_in()
switch (p.slice(0, 4)) {
case "
0
|| (page.oneperpage && this.info().X)
|| !page.h) { // empty page
if (page.in_page)
abc2svg.page.close_page(page)
abc2svg.page.open_page(page, 0)
}
page.blk = [] // in block
page.hb = page.h // keep the offset of the start of tune
break
case "