Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use \parshape for multiline initials #1608

Draft
wants to merge 8 commits into
base: develop
Choose a base branch
from
276 changes: 53 additions & 223 deletions tex/gregoriotex-main.tex
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@

%%%%%%%%%%%%%%%

\newluatexattribute\gre@attr@stafflines%
\edef\gre@attrid@stafflines{\the\allocationnumber}
\newluatexattribute\gre@attr@initial%
\edef\gre@attrid@initial{\the\allocationnumber}

% an attribute we put on the text nodes.
% if it is 1, it means that there may be a dash here if this syllable is at the end of a line
Expand Down Expand Up @@ -226,13 +230,10 @@
\relax%
}%


% Eliminates the error for big initials where the second new line is at the end of the score
\def\GreFinalNewLine{%
\global\advance\gre@knownline by 1\relax %
}%

% the macro we call each time we force a changing of line, it automatically sets \gre@knownline, and adjusts left spaces
% the macro we call each time we force a changing of line
% #1 is 0 in case of gabc z, 1 for Z
% #2 is 0 in the normal case, 1 after a bar in the new spacing algorithm
\def\gre@newlinecommon#1#2{%
Expand All @@ -241,16 +242,6 @@
\gre@localrightbox{}%
\fi\fi %
\ifgre@boxing\else%
\ifnum\gre@biginitial=1\relax %
\ifcase\gre@knownline %
% 0: should not happend...
\or % 1
\gre@adjustsecondline %
\or %2
\gre@adjustthirdline %
\fi %
\fi %
\global\advance\gre@knownline by 1\relax %
\global\gre@lastoflinecount=2\relax %
\ifnum#2=0\relax %
% we have to repeat the end of syllable shifts here because the manual line breaks will occur before we get to the regular shifting code in \GreSyllable
Expand All @@ -274,7 +265,6 @@
\fi %
\gre@penalty{-10001}%
\fi %
\gre@adjustlineifnecessary\relax %
%%
\GreResetEolCustos\relax %
\gre@trace@end%
Expand Down Expand Up @@ -314,78 +304,12 @@
%% box containing the initial, and dimen containing its width (and the width of the space after)
\newbox\gre@box@initial%


% gre@biginitial means that the inital takes two lines
\newcount\gre@biginitial%

% gre@knownline is the line we think we are in
\newcount\gre@knownline%

% macro to call before the call of \initial
\def\gre@setbiginitial{%
\gre@trace{gre@setbiginitial}%
\global\gre@biginitial=1\relax %
\relax %
\gre@trace@end%
}%

% macro to cancel before the call of \initial
\def\gre@normalinitial{%
\gre@trace{gre@normalinitial}%
\global\gre@biginitial=0\relax %
\relax %
\gre@trace@end%
}%

% macro to call before the first syllable, but after setinitialclef
\def\gre@adjustsecondline{%
\gre@trace{gre@adjustsecondline}%
\gre@dimen@additionalleftspace=\gre@dimen@initialwidth\relax%
\gre@updateleftbox %
\relax %
\gre@trace@end%
}%

% macro to call during the second line
\def\gre@adjustthirdline{%
\gre@trace{gre@adjustthirdline}%
\gre@dimen@additionalleftspace= 0 pt\relax%
\gre@updateleftbox %
\relax %
\gre@trace@end%
}%

\newif\ifgre@thirdlineadjustmentnecessary %
\def\gre@adjustlineifnecessary{%
\gre@trace{gre@adjustlineifnecessary}%
\ifgre@thirdlineadjustmentnecessary %
\gre@adjustthirdline %
\gre@thirdlineadjustmentnecessaryfalse %
\fi %
\gre@trace@end%
}%

\def\gre@updateleftbox{%
\gre@trace{gre@updateleftbox}%
\gre@updatelinewidth %
\gre@updatelinesclef %
\gre@trace@end%
}%

\def\gre@updatelinewidth{%
\gre@trace{gre@updatelinewidth}%
\gre@debugmsg{ifdim}{ additionalleftspace = 0pt}%
\ifdim\gre@dimen@additionalleftspace=0pt\relax%
\gre@generatelines %
\else %
\gre@dimen@temp@five=\gre@dimen@stafflinewidth\relax%
\global\advance\gre@dimen@stafflinewidth by -\gre@dimen@additionalleftspace\relax%
\gre@generatelines %
\global\gre@dimen@stafflinewidth=\gre@dimen@temp@five %
\fi %
\gre@trace@end%
}%

\def\greillumination#1{%
\setbox\gre@box@initial=\hbox{#1}%
}%
Expand All @@ -405,96 +329,69 @@
\gre@trace@end%
}

\def\gre@makeparshape#1#2{%
\edef\gre@parshape@dims{\numexpr#1+1\relax}%
\gre@count@temp@one=0\relax
\loop
\edef\gre@parshape@dims{\gre@parshape@dims#2\dimexpr\gre@dimen@linewidth-#2\relax}%
\advance\gre@count@temp@one by 1\relax
\ifnum\gre@count@temp@one<#1\repeat
\parshape\gre@parshape@dims0pt\gre@dimen@linewidth
}

\def\gre@setinitial#1{%
\gre@trace{gre@setinitial{#1}}%
\gre@debugmsg{annotation}{Time to calculate the true raise.}%
\gre@calculate@annotationtrueraise %
% we print the initial always at the same place, and then we print the gre@box@annotation, centered
% first we print the initial
\gre@dimen@temp@five = \dimexpr(\gre@dimen@textlower+\gre@space@dimen@initialraise)\relax%
% if it is a big initial we print it on the second line
\ifnum\gre@biginitial=0\relax %
\ifvoid\gre@box@initial%
\gre@debugmsg{initial}{Fill initial box a}%
\setbox\gre@box@initial=\hbox{\gre@style@initial\gre@fixedtextformat{#1}\endgre@style@initial}%
\fi%
\gre@debugmsg{ifdim}{ manualinitialwidth = 0pt}%
\ifdim\gre@space@dimen@manualinitialwidth=0 pt\relax%
\global\gre@dimen@initialwidth=\wd\gre@box@initial %
\gre@style@initial%
\ifdim\gre@dimen@initialwidth<\gre@space@dimen@minimalinitialwidth\relax%
\global\gre@dimen@initialwidth=\gre@space@dimen@minimalinitialwidth\relax%
\fi%
\endgre@style@initial%
\else%
\gre@style@initial%
\global\gre@dimen@initialwidth=\gre@space@dimen@manualinitialwidth\relax%
\endgre@style@initial%
\fi%
\gre@debugmsg{ifdim}{ wd(gre@box@annotation) > initialwidth}%
\ifdim\wd\gre@box@annotation>\gre@dimen@initialwidth\relax%
\global\gre@dimen@initialwidth=\wd\gre@box@annotation%
\fi%
\gre@debugmsg{annotation}{Width check completed.}%
\setbox\gre@box@initial=\hbox to \gre@dimen@initialwidth {\hss\raise \gre@dimen@temp@five\box\gre@box@initial\hss}%
\gre@debugmsg{annotation}{Initial set.}%
\ifvoid\gre@box@initial%
\gre@debugmsg{initial}{Fill initial box a}%
\setbox\gre@box@initial=\hbox{\gre@style@initial\gre@fixedtextformat{#1}\endgre@style@initial}%
\fi%
\gre@debugmsg{ifdim}{ manualinitialwidth = 0pt}%
\ifdim\gre@space@dimen@manualinitialwidth=0 pt\relax%
\global\gre@dimen@initialwidth=\wd\gre@box@initial %
\gre@style@initial%
\global\gre@dimen@temp@four = \gre@space@dimen@beforeinitialshift\relax%
\ifdim\gre@dimen@initialwidth<\gre@space@dimen@minimalinitialwidth\relax%
\global\gre@dimen@initialwidth=\gre@space@dimen@minimalinitialwidth\relax%
\fi%
\endgre@style@initial%
\else %
\advance\gre@dimen@temp@five by \dimexpr(-\gre@dimen@additionalbottomspace %
- \gre@space@dimen@spacebeneathtext %
- \gre@space@dimen@spacelinestext %
- 4\gre@dimen@interstafflinespace %
- 4\gre@dimen@stafflineheight %
- \gre@dimen@currenttranslationheight %
- \f@size pt %
+ \gre@space@dimen@initialraise)\relax%
\ifvoid\gre@box@initial%
\gre@debugmsg{initial}{fill big initial box}%
\setbox\gre@box@initial=\hbox{\gre@style@initial\gre@fixedtextformat{#1}\endgre@style@initial}%
\fi%
\gre@debugmsg{ifdim}{ manualinitialwidth = 0pt}%
\ifdim\gre@space@dimen@manualinitialwidth=0 pt\relax%
\global\gre@dimen@initialwidth=\wd\gre@box@initial %
\gre@style@initial%
\ifdim\gre@dimen@initialwidth<\gre@space@dimen@minimalinitialwidth\relax%
\global\gre@dimen@initialwidth=\gre@space@dimen@minimalinitialwidth\relax%
\fi%
\endgre@style@initial%
\else%
\gre@style@initial%
\global\gre@dimen@initialwidth=\gre@space@dimen@manualinitialwidth\relax%
\endgre@style@initial%
\fi%
\gre@debugmsg{ifdim}{ wd(GreAboveinitialfirstbox) > initialwidth}%
\ifdim\wd\gre@box@annotation>\gre@dimen@initialwidth\relax%
\global\gre@dimen@initialwidth=\wd\gre@box@annotation%
\fi%
\setbox\gre@box@initial=\hbox{\vtop to 0pt{\hbox to \gre@dimen@initialwidth {\hss\raise \gre@dimen@temp@five\box\gre@box@initial\hss}\vss}}%
\else
\gre@style@initial%
\global\gre@dimen@temp@four = \gre@space@dimen@beforeinitialshift\relax%
\global\gre@dimen@initialwidth=\gre@space@dimen@manualinitialwidth\relax%
\endgre@style@initial%
\fi %
\fi
\gre@debugmsg{ifdim}{ wd(gre@box@annotation) > initialwidth}%
\ifdim\wd\gre@box@annotation>\gre@dimen@initialwidth\relax%
\global\gre@dimen@initialwidth=\wd\gre@box@annotation%
\fi%
\gre@debugmsg{annotation}{Width check completed.}%
\setbox\gre@box@initial=\hbox to \gre@dimen@initialwidth {\hss\raise \gre@dimen@temp@five\box\gre@box@initial\hss}%
\gre@debugmsg{annotation}{Initial set.}%
\gre@style@initial%
\global\gre@dimen@temp@four = \gre@space@dimen@beforeinitialshift\relax%
\endgre@style@initial%
\setbox\gre@box@temp@width=\hbox attr \gre@attrid@initial=1 {%
\gre@hskip\gre@dimen@temp@four %
\global\advance\gre@dimen@initialwidth by \gre@dimen@temp@four %
\gre@debugmsg{annotation}{Ready to place initial.}%
\ifgre@showlyrics%
\box\gre@box@initial%
\smash{\box\gre@box@initial}%
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The \smash is presumably what's changing the appearance of initials with descenders.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember why the \smash was there. It seems to make no difference now...

\else%
\kern\wd\gre@box@initial%
\fi%
\ifnum\gre@biginitial=0\relax%
\gre@style@initial%
\global\gre@dimen@temp@four = \gre@space@dimen@afterinitialshift\relax%
\endgre@style@initial%
\else%
\gre@style@initial%
\global\gre@dimen@temp@four = \gre@space@dimen@afterinitialshift\relax%
\endgre@style@initial%
\fi%
\gre@style@initial%
\global\gre@dimen@temp@four = \gre@space@dimen@afterinitialshift\relax%
\endgre@style@initial%
\gre@hskip\gre@dimen@temp@four %
\global\advance\gre@dimen@initialwidth by \gre@dimen@temp@four%
}%
% Set the paragraph shape. This should happen before anything is printed.
\gre@makeparshape{\gre@count@initiallines}{\wd\gre@box@temp@width}%
% Set the initial.
\llap{\box\gre@box@temp@width}%
% then we center the annotation box above the initial, if there is one
\gre@debugmsg{annotation}{Time to set the annotation.}%
\ifvoid\gre@box@annotation\relax%
Expand Down Expand Up @@ -678,7 +575,10 @@
%% has to be called before drawing the key, after drawing the initial
\def\gre@beginnotes{%
\gre@trace{gre@beginnotes}%
\gre@drawfirstlines %
% Draw the staff lines the same as the other staves; post_linebreak
% will fix them. The \hbox is there so that post_linebreak can find
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a hack. It would be better either to mark the initial with an attribute, or to draw all the lines using \localleftbox (I couldn't figure out how).

% it more easily.
\hbox{\copy\gre@box@lines}%
%%localeleftbox is a primitive of Omega, it draws the same box at the beginning of new lines (here after the first)
\gre@localleftbox{%
\copy\gre@box@lines %
Expand Down Expand Up @@ -816,77 +716,14 @@
]%
}

%% macro that draws the stafflines on the first line, it is different from others due to the initial that can take some place, without lines
\def\gre@drawfirstlines{%
\gre@trace{gre@drawfirstlines}%
\advance\gre@dimen@stafflinewidth by -\gre@dimen@initialwidth\relax%
%\advance\gre@dimen@stafflinewidth by -\gre@space@dimen@minimalspaceatlinebeginning
%\gre@dimen@initialwidth=0pt
\hbox to 0pt{%
\vbox{%
\gre@style@normalstafflines%
\vskip\gre@dimen@currentabovelinestextheight\relax%
\vskip\gre@dimen@additionaltopspace\relax%
\ifgre@showlines %
\hrule height \gre@dimen@stafflineheight width \gre@dimen@stafflinewidth\relax%
\else %
\vskip\gre@dimen@stafflineheight\relax%
\fi %
\gre@skip@temp@four = \gre@dimen@interstafflinespace\relax%
\kern\gre@skip@temp@four %
\ifgre@showlines %
\hrule height \gre@dimen@stafflineheight width \gre@dimen@stafflinewidth\relax%
\else %
\vskip\gre@dimen@stafflineheight\relax%
\fi %
\ifgre@haslinethree %
\gre@skip@temp@four = \gre@dimen@interstafflinespace\relax%
\kern\gre@skip@temp@four %
\ifgre@showlines %
\hrule height \gre@dimen@stafflineheight width \gre@dimen@stafflinewidth\relax%
\else %
\vskip\gre@dimen@stafflineheight\relax%
\fi %
\fi %
\ifgre@haslinefour %
\gre@skip@temp@four = \gre@dimen@interstafflinespace\relax%
\kern\gre@skip@temp@four %
\ifgre@showlines %
\hrule height \gre@dimen@stafflineheight width \gre@dimen@stafflinewidth\relax%
\else %
\vskip\gre@dimen@stafflineheight\relax%
\fi %
\fi %
\ifgre@haslinefive %
\gre@skip@temp@four = \gre@dimen@interstafflinespace\relax%
\kern\gre@skip@temp@four %
\ifgre@showlines %
\hrule height \gre@dimen@stafflineheight width \gre@dimen@stafflinewidth\relax%
\else %
\vskip\gre@dimen@stafflineheight\relax%
\fi %
\fi %
\vskip\gre@space@dimen@spacelinestext\relax%
\vskip\gre@space@dimen@spacebeneathtext\relax%
\vskip\gre@dimen@currenttranslationheight\relax%
\vskip\gre@dimen@additionalbottomspace\relax%
\endgre@style@normalstafflines%
}%
\hss%
}%
\gre@dimen@stafflinewidth=\gre@dimen@linewidth\relax%
\relax%
\gre@trace@end%
}%

%% box containing the stafflines for other lines than the first
\newbox\gre@box@lines%

% macro that must be called at each change of linewidth and gre@factor
\def\gre@generatelines{%
\gre@trace{gre@generatelines}%
\setbox\gre@box@lines=\hbox to 0pt{%
\vbox{%
\vbox attr \gre@attrid@stafflines=1 {%
\gre@style@normalstafflines%
\vskip\glueexpr(\gre@dimen@additionaltopspace+\gre@space@skip@spaceabovelines+\gre@dimen@currentabovelinestextheight)\relax%
\ifgre@showlines %
Expand Down Expand Up @@ -1304,19 +1141,13 @@
\ifdefined\optgabcAtScoreBeginning %
\optgabcAtScoreBeginning %
\fi %
\global\gre@knownline=1\relax %
\global\gre@lastoflinecount=2\relax %
\global\gre@endofscorefalse %
\relax%
}%

%macro called at the end of a score
\def\GreEndScore{%
\ifnum\gre@biginitial=1\relax%
\ifnum\gre@knownline<3\relax%
\gre@error{Score ended before finding the end\MessageBreak of the second line of a 2-line initial. Make sure\MessageBreak you have at least two manual line breaks in \MessageBreak your gabc}%
\fi%
\fi%
\global\gre@lastoflinecount=0\relax %
\gre@useautoeolcustos%
\GreEndEUOUAE{}%
Expand All @@ -1338,7 +1169,6 @@
\gre@calculate@additionalspaces{\gre@pitch@dummy}{\gre@pitch@dummy}{0}{0}%
\global\gre@dimen@currentabovelinestextheight=0 sp%
\gre@removetranslationspace %
\gre@normalinitial %
\gre@restorepenalties %
\gre@dimen@temp@one=0pt\relax%
\gre@dimen@temp@two=0pt\relax%
Expand Down
Loading