False,
'an' => 'Ant',
'ca' => 'Cant',
'co' => 'Comm',
'gr' => 'Grad',
'hy' => 'Hymn',
'in' => 'Intr',
'im' => False,
'ky' => False,
'of' => 'Offert',
'or' => False,
'pr' => False,
'ps' => False,
're' => 'Resp',
'rb' => 'R. br',
'se' => 'Seq',
'tr' => 'Tract',
'va' => False);
#
# Document header
#
$tex = '% !TEX TS-program = lualatex
% !TEX encoding = UTF-8
\documentclass[12pt]{article}
\usepackage{geometry}
\geometry{paperwidth=16cm,paperheight=600cm}
\usepackage{gregoriotex}
\usepackage{fullpage}
\usepackage{multicol}
\usepackage{paracol}
\usepackage{Tabbing}
\usepackage{longtable}
\usepackage[savepos]{zref}
\let\grelocalleftbox\localleftbox
\let\grelocalrightbox\localrightbox
\usepackage[latin]{babel}
\usepackage{fontspec}
\defaultfontfeatures{Ligatures=TeX}
\setmainfont{Libertinus Serif}
\pagestyle{empty}
\begin{document}
\newcommand{\red}[1]{\textcolor{red}{#1}}
\newcommand{\black}[1]{\textcolor{black}{#1}}
\setlength{\parindent}{0pt}
\gresetbracerendering{font}
';
if($c['initial'] == 1) $tex .= '\grechangestyle{initial}{\fontsize{38}{38}\selectfont}{}
';
if($c['initial'] == 2) $tex .= '\grechangestyle{initial}{\fontsize{120}{120}\selectfont}{}
\grechangedim{initialraise}{1.2mm}{scalable}
';
if($ann[$c['office-part']]) {
$tex .= '\greannotation{\small \textbf{'.$ann[$c['office-part']].".}}\n";
}
if($c['mode'] || $c['mode_var']) {
if($c['mode'] == 'p') {
$mode = "T. pereg.";
} elseif(in_array($c['mode'], array('c','d','e'))) {
$mode = strtoupper($c['mode']).($c['mode_var']?' '.$c['mode_var']:'');
} else {
$mode = $c['mode'].($c['mode_var']?' '.$c['mode_var']:'');
}
$tex .= '\greannotation{\small \textbf{'.$mode.".}}\n";
}
if($c['commentary']) {
if(strpos($c['gabc'], '|') === false) {
$tex .= '\grecommentary{{\small \emph{'.$c['commentary']."}}}\n";
} else {
$tex .= '\grecommentary[1em]{{\small \emph{'.$c['commentary']."}}}\n";
}
$tex .= '\nolinebreak[4]'."\n";
}
#
# Parsing gabc
#
$g = json_decode($c['gabc']);
if($c['initial'] != 1) $tex .= "\\gresetinitiallines{".$c['initial']."}\n";
if(is_array($g)) {
foreach($g as $l) {
if($l[0] == 'gabc') {
$tex .= gregorio($l[1]);
} elseif($l[0] == 'tex') {
$tex .= "\\vspace{10pt}\n".$l[1]."\\par\n";
}
}
} elseif($c['gabc_verses'] && !$firstverse) {
$tex .= gregorio($g."\n".$c['gabc_verses']);
} elseif($c['tex_verses'] && !$firstverse) {
$tex .= gregorio($g);
$tex .= "\\vspace{10pt}\n".$c['tex_verses']."\\par\n";
} else {
$tex .= gregorio($g);
}
#
# Document footer
#
$tex .= '
\end{document}
';
return $tex;
}
function makeimgfiles($id, $tex, $suffix = '') {
$path = __DIR__.'/scores/';
$f = mkstemp('.tex');
fwrite($f[0],$tex);
fclose($f[0]);
chdir(dirname($f[1]));
exec('lualatex --interaction=nonstopmode '.basename($f[1]));
exec('lualatex --interaction=nonstopmode '.basename($f[1])); # for variable line height
exec('pdfcrop '.substr($f[1],0,-4).'.pdf '.$path.'pdf/'.$id.$suffix.'.pdf');
chmod($path.'pdf/'.$id.$suffix.'.pdf', 0666);
exec('mutool draw -F png -r 300 -o '.$path.'png/'.$id.$suffix.'.png '.$path.'pdf/'.$id.$suffix.'.pdf');
chmod($path.'png/'.$id.$suffix.'.png', 0666);
exec('mutool draw -F png -r 100 -o '.$path.$id.$suffix.'.png '.$path.'pdf/'.$id.$suffix.'.pdf');
chmod($path.$id.$suffix.'.png', 0666);
exec('mutool draw -F svg -o '.$path.'svg/'.$id.$suffix.'.svg '.$path.'pdf/'.$id.$suffix.'.pdf');
chmod($path.'svg/'.$id.$suffix.'.svg', 0666);
exec('gs -q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=eps2write -dCompatibilityLevel=1.3 -dEmbedAllFonts=true -dSubsetFonts=true -sOutputFile='.$path.'eps/'.$id.$suffix.'.eps '.$path.'pdf/'.$id.$suffix.'.pdf');
chmod($path.'eps/'.$id.$suffix.'.eps', 0666);
unlink($f[1]);
unlink(substr($f[1],0,-4).'.log');
unlink(substr($f[1],0,-4).'.aux');
unlink(substr($f[1],0,-4).'.gaux');
unlink(substr($f[1],0,-4).'.pdf');
}
$uri = __DIR__.'/scores/svg/'.$id.'.svg';
if(!is_file($uri) || (array_key_exists("force", $_GET) && $_GET["force"] == "1")) {
$sql1 = 'SELECT * FROM '.db('chants').' WHERE id = '.$id;
$req1 = $mysqli->query($sql1) or die('Erreur SQL !
'.$sql1.'
'.$mysqli->error);
$c = $req1->fetch_assoc();
if(!$c) {
die('Wrong id');
}
makeimg($c);
}
header('Content-Disposition: inline; filename='.$id.'.svg');
header("Content-type: image/svg+xml");
readfile($uri);
?>