Skip to content

Commit

Permalink
Added a way to set counts per line.
Browse files Browse the repository at this point in the history
Enhancement mentioned in gregorio-project#1125.
  • Loading branch information
henryso committed Jan 17, 2017
1 parent 17f062d commit b1fa894
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 41 deletions.
9 changes: 9 additions & 0 deletions doc/Command_Index_User.tex
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,15 @@ \subsubsection{Fine Tuning Dimensions}
\#2 & integer & The new value.\\
\end{argtable}

\macroname{\textbackslash grechangenextscorelinecount}{\{\#1\}\{\#2\}\{\#3\}}{gregoriotex-spaces.tex}
Changes one of Gregorio\TeX’s counts or penalties for a given line in the next included score.

\begin{argtable}
\#1 & integer & The number of the line in the next score to be adjusted.\\
\#2 & string & The name of the count to be changed. See \nameref{counts} and \nameref{penalties} below.\\
\#3 & integer & The new value.\\
\end{argtable}

\macroname{\textbackslash greloadspaceconf}{\{\#1\}}{gregoriotex-spaces.tex}
Macro to load a space configuration file. Space configuration file names have the format \verb=gsp-identifier.tex= and must be in the same directory as your project or in your texmf directory.

Expand Down
5 changes: 5 additions & 0 deletions doc/Command_Index_internal.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,11 @@ \section{Gregorio\TeX{} Controls}
are the same as \verb=\grechangedim=. Used to temporarily change the dimension
for a given line, which is restored at the next beginning of the next line.
\macroname{\textbackslash gre@changecountforline}{\#1\#2}{gregoriotex-spaces.tex}
Saves the current value of the count and then changes it. The arguments
are the same as \verb=\grechangeocount=. Used to temporarily change the count
for a given line, which is restored at the next beginning of the next line.
\macroname{\textbackslash gre@setstafflines}{\#1}{gregoriotex-main.tex}
Sets the number of staff lines.
Expand Down
32 changes: 30 additions & 2 deletions tex/gregoriotex-spaces.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1625,12 +1625,13 @@
\fi%
\directlua{%
gregoriotex.save_dim(%
"\luatexluaescapestring{\gre@prefix @#1}",%
"\luatexluaescapestring{#1}",%
"\luatexluaescapestring{\expandafter\unexpanded%
\expandafter\expandafter\expandafter{%
\csname gre@space@\gre@prefix @#1\endcsname%
}%
}"%
}",%
"\csname ifgre@scale@#1\endcsname scalable\else fixed\fi"%
)%
}%
\grechangedim{#1}{#2}{#3}%
Expand All @@ -1648,6 +1649,33 @@
}%
}%

% same arguments as \grechangecount, but used for setting the dimension for a
% single line
\def\gre@changecountforline#1#2{%
\directlua{%
gregoriotex.save_count(%
"\luatexluaescapestring{#1}",%
"\luatexluaescapestring{\expandafter\unexpanded%
\expandafter\expandafter\expandafter{%
\expandafter\the\csname gre@space@count@#1\endcsname%
}%
}"%
)%
}%
\grechangecount{#1}{#2}%
}%

% #1 : line number
% #2-#3 : same as #1-#2 of \grechangecount
\def\grechangenextscorelinecount#1#2#3{%
\directlua{%
gregoriotex.change_next_score_line_count(#1,%
"\luatexluaescapestring{#2}",%
"\luatexluaescapestring{#3}"%
)%
}%
}%

\newcount\gre@space@count@newlinepenalty%
\newcount\gre@space@count@nobreakpenalty%
\newcount\gre@space@count@endofwordpenalty%
Expand Down
109 changes: 70 additions & 39 deletions tex/gregoriotex.lua
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ local hashed_spaces = {}
local space_hash = ''

local per_line_dims = {}
local per_line_counts = {}
local saved_dims = {}
local saved_counts = {}

local catcode_at_letter = luatexbase.catcodetables['gre@atletter']

Expand Down Expand Up @@ -689,7 +691,9 @@ local function atScoreEnd()
luatexbase.remove_from_callback('post_linebreak_filter', 'gregoriotex.post_linebreak')
luatexbase.remove_from_callback("hyphenate", "gregoriotex.disable_hyphenation")
per_line_dims = {}
per_line_counts = {}
saved_dims = {}
saved_counts = {}
end

local function clean_old_gtex_files(file_withdir)
Expand Down Expand Up @@ -1090,10 +1094,15 @@ local function adjust_line_height(inside_discretionary)
local name, value
for name, value in pairs(saved_dims) do
tex.sprint(catcode_at_letter, string.format(
[[\def\gre@space@%s{%s}]], name, value))
[[\grechangedim{%s}{%s}{%s}]], name, value[1], value[2]))
end
for name, value in pairs(saved_counts) do
tex.sprint(catcode_at_letter, string.format(
[[\grechangecount{%s}{%s}]], name, value))
end
-- clear saved dims
saved_dims = {}
saved_counts = {}
-- apply per-line dims
local line_dims = per_line_dims[heights[1]]
if line_dims ~= nil then
Expand All @@ -1102,6 +1111,13 @@ local function adjust_line_height(inside_discretionary)
[[\gre@changedimforline{%s}{%s}{%s}]], name, value[1], value[2]))
end
end
local line_counts = per_line_counts[heights[1]]
if line_counts ~= nil then
for name, value in pairs(line_counts) do
tex.sprint(catcode_at_letter, string.format(
[[\gre@changecountforline{%s}{%s}]], name, value))
end
end
-- recalculate spaces
tex.sprint(catcode_at_letter, string.format(
[[\gre@calculate@additionalspaces{%d}{%d}{%d}{%d}]],
Expand All @@ -1113,8 +1129,12 @@ local function adjust_line_height(inside_discretionary)
end
end

local function save_dim(name, value)
saved_dims[name] = value
local function save_dim(name, value, modifier)
saved_dims[name] = { value, modifier }
end

local function save_count(name, value)
saved_counts[name] = value
end

local function change_next_score_line_dim(linenum, name, value, modifier)
Expand All @@ -1126,6 +1146,15 @@ local function change_next_score_line_dim(linenum, name, value, modifier)
line_dims[name] = { value, modifier }
end

local function change_next_score_line_count(linenum, name, value)
local line_counts = per_line_counts[linenum]
if line_counts == nil then
line_counts = {}
per_line_counts[linenum] = line_counts
end
line_counts[name] = value
end

local function prep_save_position(index, fn)
if saved_positions[cur_score_id] == nil then
saved_positions[cur_score_id] = {}
Expand Down Expand Up @@ -1323,42 +1352,44 @@ local function hash_spaces(name, value)
space_hash = md5.sumhexa(mash)
end

gregoriotex.number_to_letter = number_to_letter
gregoriotex.init = init
gregoriotex.include_score = include_score
gregoriotex.atScoreEnd = atScoreEnd
gregoriotex.atScoreBeginning = atScoreBeginning
gregoriotex.check_font_version = check_font_version
gregoriotex.get_gregoriotexluaversion = get_gregoriotexluaversion
gregoriotex.map_font = map_font
gregoriotex.init_variant_font = init_variant_font
gregoriotex.change_score_glyph = change_score_glyph
gregoriotex.reset_score_glyph = reset_score_glyph
gregoriotex.scale_score_fonts = scale_score_fonts
gregoriotex.set_font_factor = set_font_factor
gregoriotex.def_symbol = def_symbol
gregoriotex.font_size = font_size
gregoriotex.direct_gabc = direct_gabc
gregoriotex.adjust_line_height = adjust_line_height
gregoriotex.var_brace_len = var_brace_len
gregoriotex.save_length = save_length
gregoriotex.mark_translation = mark_translation
gregoriotex.mark_abovelinestext = mark_abovelinestext
gregoriotex.width_to_bp = width_to_bp
gregoriotex.hypotenuse = hypotenuse
gregoriotex.rotation = rotation
gregoriotex.scale_space = scale_space
gregoriotex.set_header_capture = set_header_capture
gregoriotex.capture_header = capture_header
gregoriotex.is_ypos_different = is_ypos_different
gregoriotex.save_euouae = save_euouae
gregoriotex.mode_part = mode_part
gregoriotex.set_debug_string = set_debug_string
gregoriotex.late_save_position = late_save_position
gregoriotex.is_last_syllable_on_line = is_last_syllable_on_line
gregoriotex.hash_spaces = hash_spaces
gregoriotex.save_dim = save_dim
gregoriotex.change_next_score_line_dim = change_next_score_line_dim
gregoriotex.number_to_letter = number_to_letter
gregoriotex.init = init
gregoriotex.include_score = include_score
gregoriotex.atScoreEnd = atScoreEnd
gregoriotex.atScoreBeginning = atScoreBeginning
gregoriotex.check_font_version = check_font_version
gregoriotex.get_gregoriotexluaversion = get_gregoriotexluaversion
gregoriotex.map_font = map_font
gregoriotex.init_variant_font = init_variant_font
gregoriotex.change_score_glyph = change_score_glyph
gregoriotex.reset_score_glyph = reset_score_glyph
gregoriotex.scale_score_fonts = scale_score_fonts
gregoriotex.set_font_factor = set_font_factor
gregoriotex.def_symbol = def_symbol
gregoriotex.font_size = font_size
gregoriotex.direct_gabc = direct_gabc
gregoriotex.adjust_line_height = adjust_line_height
gregoriotex.var_brace_len = var_brace_len
gregoriotex.save_length = save_length
gregoriotex.mark_translation = mark_translation
gregoriotex.mark_abovelinestext = mark_abovelinestext
gregoriotex.width_to_bp = width_to_bp
gregoriotex.hypotenuse = hypotenuse
gregoriotex.rotation = rotation
gregoriotex.scale_space = scale_space
gregoriotex.set_header_capture = set_header_capture
gregoriotex.capture_header = capture_header
gregoriotex.is_ypos_different = is_ypos_different
gregoriotex.save_euouae = save_euouae
gregoriotex.mode_part = mode_part
gregoriotex.set_debug_string = set_debug_string
gregoriotex.late_save_position = late_save_position
gregoriotex.is_last_syllable_on_line = is_last_syllable_on_line
gregoriotex.hash_spaces = hash_spaces
gregoriotex.save_dim = save_dim
gregoriotex.save_count = save_count
gregoriotex.change_next_score_line_dim = change_next_score_line_dim
gregoriotex.change_next_score_line_count = change_next_score_line_count

dofile(kpse.find_file('gregoriotex-nabc.lua', 'lua'))
dofile(kpse.find_file('gregoriotex-signs.lua', 'lua'))
Expand Down

0 comments on commit b1fa894

Please sign in to comment.