forked from openlp/openlp
Minor adjustsments + a test.
This commit is contained in:
parent
31ee3999c0
commit
9ae1af72c7
@ -326,7 +326,7 @@ def expand_and_align_chords_in_line(match):
|
||||
:param match:
|
||||
:return: The line with expanded html-chords
|
||||
"""
|
||||
slimchars = 'fiíIÍjlĺľrtť.,;/ ()|"\'!:\\'
|
||||
SLIMCHARS = 'fiíIÍjlĺľrtť.,;/ ()|"\'!:\\'
|
||||
whitespaces = ''
|
||||
chordlen = 0
|
||||
taillen = 0
|
||||
@ -341,19 +341,19 @@ def expand_and_align_chords_in_line(match):
|
||||
end = match.group(4)
|
||||
# Based on char width calculate width of chord
|
||||
for chord_char in chord:
|
||||
if chord_char not in slimchars:
|
||||
if chord_char not in SLIMCHARS:
|
||||
chordlen += 2
|
||||
else:
|
||||
chordlen += 1
|
||||
# Based on char width calculate width of tail
|
||||
for tail_char in tail:
|
||||
if tail_char not in slimchars:
|
||||
if tail_char not in SLIMCHARS:
|
||||
taillen += 2
|
||||
else:
|
||||
taillen += 1
|
||||
# Based on char width calculate width of remainder
|
||||
for remainder_char in remainder:
|
||||
if remainder_char not in slimchars:
|
||||
if remainder_char not in SLIMCHARS:
|
||||
taillen += 2
|
||||
else:
|
||||
taillen += 1
|
||||
@ -362,10 +362,10 @@ def expand_and_align_chords_in_line(match):
|
||||
# Decide if the padding should be "_" for drawing out words or spaces
|
||||
if tail:
|
||||
if not remainder:
|
||||
for c in range(math.ceil((chordlen - taillen) / 2) + 1):
|
||||
for c in range(math.ceil((chordlen - taillen) / 2) + 2):
|
||||
whitespaces += '_'
|
||||
else:
|
||||
for c in range(chordlen - taillen + 2):
|
||||
for c in range(chordlen - taillen + 1):
|
||||
whitespaces += ' '
|
||||
else:
|
||||
if not remainder:
|
||||
|
@ -89,7 +89,6 @@
|
||||
|
||||
.ws {
|
||||
white-space: pre-wrap;
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
#nextslide .chordline span.chord span strong {
|
||||
|
@ -40,18 +40,17 @@ function storeTransposeValue(songId,transposeValueToSet) {
|
||||
|
||||
// NOTE: This function has a python equivalent in openlp/plugins/songs/lib/__init__.py - make sure to update both!
|
||||
function transposeChord(chord, transposeValue, notation) {
|
||||
var chordSplit = chord.replace('♭', 'b').split(/[\/\(\)]/);
|
||||
var chordSplit = chord.replace('♭', 'b').split(/[\/]/);
|
||||
var transposedChord = '', note, notenumber, rest, currentChord;
|
||||
var notesSharp = notesSharpNotation[notation];
|
||||
var notesFlat = notesFlatNotation[notation];
|
||||
var notesPreferred = ['b','#','#','#','#','#','#','#','#','#','#','#'];
|
||||
var chordNotes = Array();
|
||||
for (i = 0; i <= chordSplit.length - 1; i++) {
|
||||
if (i > 0) {
|
||||
transposedChord += '/';
|
||||
}
|
||||
currentchord = chordSplit[i];
|
||||
if (currentchord.charAt(0) === '(') {
|
||||
if (currentchord.length > 0 && currentchord.charAt(0) === '(') {
|
||||
transposedChord += '(';
|
||||
if (currentchord.length > 1) {
|
||||
currentchord = currentchord.substr(1);
|
||||
@ -186,9 +185,9 @@ window.OpenLP = {
|
||||
var $taillen = 0;
|
||||
var slimchars='fiíIÍjlĺľrtť.,;/ ()|"\'!:\\';
|
||||
// Transpose chord as dictated by the transpose value in local storage
|
||||
$chord = transposeChord($chord, transposeValue, OpenLP.chordNotation);
|
||||
// Replace any padding '_' added to tail
|
||||
$tail = $tail.replace(/_+$/, '')
|
||||
if (transposeValue != 0) {
|
||||
$chord = transposeChord($chord, transposeValue, OpenLP.chordNotation);
|
||||
}
|
||||
for (var i = 0; i < $chord.length; i++) if (slimchars.indexOf($chord.charAt(i)) === -1) {$chordlen += 2;} else {$chordlen += 1;}
|
||||
for (var i = 0; i < $tail.length; i++) if (slimchars.indexOf($tail.charAt(i)) === -1) {$taillen += 2;} else {$taillen += 1;}
|
||||
for (var i = 0; i < $remainder.length; i++) if (slimchars.indexOf($tail.charAt(i)) === -1) {$taillen += 2;} else {$taillen += 1;}
|
||||
@ -216,7 +215,7 @@ window.OpenLP = {
|
||||
w = '–';
|
||||
} else {
|
||||
wsl_mod = Math.floor(ws_length / 2);
|
||||
ws_right = ws_left = new Array(wsl_mod +1).join(' ');
|
||||
ws_right = ws_left = new Array(wsl_mod + 1).join(' ');
|
||||
w = ws_left + '–' + ws_right;
|
||||
}
|
||||
}
|
||||
|
@ -617,7 +617,7 @@ def transpose_chord(chord, transpose_value, notation):
|
||||
notes_flat_notation['english'] = ['C', 'Db', 'D', 'Eb', 'Fb', 'F', 'Gb', 'G', 'Ab', 'A', 'Bb', 'B']
|
||||
notes_sharp_notation['neo-latin'] = ['Do', 'Do#', 'Re', 'Re#', 'Mi', 'Fa', 'Fa#', 'Sol', 'Sol#', 'La', 'La#', 'Si']
|
||||
notes_flat_notation['neo-latin'] = ['Do', 'Reb', 'Re', 'Mib', 'Fab', 'Fa', 'Solb', 'Sol', 'Lab', 'La', 'Sib', 'Si']
|
||||
chord_split = chord.replace('♭', 'b').split('/[\/\(\)]/')
|
||||
chord_split = chord.replace('♭', 'b').split('/')
|
||||
transposed_chord = ''
|
||||
last_chord = ''
|
||||
notes_sharp = notes_sharp_notation[notation]
|
||||
@ -627,12 +627,12 @@ def transpose_chord(chord, transpose_value, notation):
|
||||
if i > 0:
|
||||
transposed_chord += '/'
|
||||
currentchord = chord_split[i]
|
||||
if currentchord[0] == '(':
|
||||
if currentchord and currentchord[0] == '(':
|
||||
transposed_chord += '('
|
||||
if len(currentchord) > 1:
|
||||
currentchord = currentchord[1:]
|
||||
else:
|
||||
currentchord = ""
|
||||
currentchord = ''
|
||||
if len(currentchord) > 0:
|
||||
if len(currentchord) > 1:
|
||||
if '#b'.find(currentchord[1]) == -1:
|
||||
|
@ -30,7 +30,7 @@ from datetime import datetime, timedelta
|
||||
from PyQt5 import QtCore, QtGui
|
||||
|
||||
from openlp.core.lib import build_icon, check_item_selected, clean_tags, create_thumb, create_separated_list, \
|
||||
expand_tags, get_text_file_string, image_to_byte, resize_image, str_to_bool, validate_thumb
|
||||
expand_tags, get_text_file_string, image_to_byte, resize_image, str_to_bool, validate_thumb, expand_chords
|
||||
from tests.functional import MagicMock, patch
|
||||
|
||||
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'resources'))
|
||||
@ -746,3 +746,19 @@ class TestLib(TestCase):
|
||||
# THEN: We should have "Author 1, Author 2 and Author 3"
|
||||
self.assertEqual(string_result, 'Author 1, Author 2 and Author 3', 'The string should be "Author 1, '
|
||||
'Author 2, and Author 3".')
|
||||
|
||||
def test_expand_chords(self):
|
||||
"""
|
||||
Test that the expanding of chords works as expected.
|
||||
"""
|
||||
# GIVEN: A lyrics-line with chords
|
||||
text_with_chords = 'H[C]alleluya.[F] [G]'
|
||||
|
||||
# WHEN: Expanding the chords
|
||||
text_with_expanded_chords = expand_chords(text_with_chords)
|
||||
|
||||
# THEN: We should get html that looks like below
|
||||
expected_html = '<span class="chordline firstchordline">H<span class="chord"><span><strong>C</strong></span>' \
|
||||
'</span>alleluya.<span class="chord"><span><strong>F</strong></span></span><span class="ws">' \
|
||||
' </span> <span class="chord"><span><strong>G</strong></span></span></span>'
|
||||
self.assertEqual(expected_html, text_with_expanded_chords, 'The expanded chords should look as expected!')
|
||||
|
Loading…
Reference in New Issue
Block a user