prelom strani glede na split_by_stanza nastavitev #3
This commit is contained in:
42
projector.py
42
projector.py
@@ -336,17 +336,21 @@ class SongProjector:
|
||||
max_height = self.screen_height * 0.85
|
||||
|
||||
# 1. Razdelimo na kitice (stanzas)
|
||||
# Kitice so ločene z eno ali več praznimi vrsticami
|
||||
# Kitice so ločene z dvojno prazno vrstico (\n\n\n ali \n\s*\n\s*\n)
|
||||
import re
|
||||
stanzas_raw = re.split(r'\n\s*\n', lyrics.strip())
|
||||
# Razdelimo po vsaj dveh praznih vrsticah (trije ali več \n)
|
||||
stanzas_raw = re.split(r'\n\s*\n\s*\n+', lyrics.strip())
|
||||
|
||||
processed_stanzas = []
|
||||
for stanza in stanzas_raw:
|
||||
# Znotraj kitice ohranimo enojne prazne vrstice kot razmike
|
||||
lines = stanza.splitlines()
|
||||
stanza_lines = []
|
||||
for line in lines:
|
||||
if line.strip():
|
||||
stanza_lines.extend(self.split_long_line(line))
|
||||
else:
|
||||
stanza_lines.append("") # Enojna prazna vrstica znotraj kitice
|
||||
if stanza_lines:
|
||||
processed_stanzas.append(stanza_lines)
|
||||
|
||||
@@ -354,19 +358,43 @@ class SongProjector:
|
||||
pages = []
|
||||
current_page_lines = []
|
||||
current_height = 0
|
||||
split_by_stanza = self.settings.get("split_by_stanza", False)
|
||||
|
||||
for stanza in processed_stanzas:
|
||||
stanza_height = len(stanza) * self.line_height
|
||||
|
||||
# Če kitica sama po sebi presega max_height, jo moramo razdeliti
|
||||
if stanza_height > max_height:
|
||||
# Če imamo že kaj na strani, to zaključimo
|
||||
# Če je vklopljen split_by_stanza, vsaka kitica dobi svojo stran
|
||||
if split_by_stanza:
|
||||
if current_page_lines:
|
||||
pages.append("\n".join(current_page_lines))
|
||||
current_page_lines = []
|
||||
current_height = 0
|
||||
|
||||
# Če je kitica predolga za eno stran, jo še vedno moramo razdeliti
|
||||
if stanza_height > max_height:
|
||||
temp_stanza_lines = []
|
||||
temp_height = 0
|
||||
for line in stanza:
|
||||
if temp_height + self.line_height > max_height:
|
||||
pages.append("\n".join(temp_stanza_lines))
|
||||
temp_stanza_lines = [line]
|
||||
temp_height = self.line_height
|
||||
else:
|
||||
temp_stanza_lines.append(line)
|
||||
temp_height += self.line_height
|
||||
if temp_stanza_lines:
|
||||
pages.append("\n".join(temp_stanza_lines))
|
||||
else:
|
||||
pages.append("\n".join(stanza))
|
||||
continue
|
||||
|
||||
# Standardna logika (več kitic na stran, če grejo)
|
||||
if stanza_height > max_height:
|
||||
if current_page_lines:
|
||||
pages.append("\n".join(current_page_lines))
|
||||
current_page_lines = []
|
||||
current_height = 0
|
||||
|
||||
# Razdelimo predolgo kitico na več strani
|
||||
temp_stanza_lines = []
|
||||
temp_height = 0
|
||||
for line in stanza:
|
||||
@@ -381,13 +409,11 @@ class SongProjector:
|
||||
current_page_lines = temp_stanza_lines
|
||||
current_height = temp_height
|
||||
|
||||
# Če kitica ne gre več na trenutno stran
|
||||
elif current_height + stanza_height + (self.line_height if current_page_lines else 0) > max_height:
|
||||
pages.append("\n".join(current_page_lines))
|
||||
current_page_lines = stanza
|
||||
current_height = stanza_height
|
||||
|
||||
# Kitica gre na trenutno stran
|
||||
else:
|
||||
if current_page_lines:
|
||||
current_page_lines.append("") # Razmik med kiticami
|
||||
|
||||
Reference in New Issue
Block a user