Prelom strani upošteva odstavke
This commit is contained in:
131
projector.py
131
projector.py
@@ -415,16 +415,19 @@ class SongProjector:
|
||||
|
||||
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)
|
||||
# Razdelimo kitico na odstavke (ločene z eno prazno vrstico)
|
||||
paragraphs_raw = re.split(r'\n\s*\n', stanza)
|
||||
stanza_paragraphs = []
|
||||
for para in paragraphs_raw:
|
||||
lines = para.splitlines()
|
||||
para_lines = []
|
||||
for line in lines:
|
||||
if line.strip():
|
||||
para_lines.extend(self.split_long_line(line))
|
||||
if para_lines:
|
||||
stanza_paragraphs.append(para_lines)
|
||||
if stanza_paragraphs:
|
||||
processed_stanzas.append(stanza_paragraphs)
|
||||
|
||||
# 2. Razdeljevanje kitic na strani
|
||||
pages = []
|
||||
@@ -432,66 +435,80 @@ class SongProjector:
|
||||
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 je vklopljen split_by_stanza, vsaka kitica dobi svojo stran
|
||||
for stanza_paragraphs in processed_stanzas:
|
||||
# Če je vklopljen split_by_stanza, vsaka kitica dobi svojo stran (ali več, če je predolga)
|
||||
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
|
||||
for para in stanza_paragraphs:
|
||||
para_height = len(para) * self.line_height
|
||||
# Če odstavek ne gre na trenutno stran (ki je v tem načinu prazna ali vsebuje prejšnje odstavke iste kitice)
|
||||
if current_height + para_height + (self.line_height if current_page_lines else 0) > max_height:
|
||||
if current_page_lines:
|
||||
pages.append("\n".join(current_page_lines))
|
||||
current_page_lines = []
|
||||
current_height = 0
|
||||
|
||||
# Če je sam odstavek predolg za eno stran, ga razdelimo po vrsticah
|
||||
if para_height > max_height:
|
||||
for line in para:
|
||||
if current_height + self.line_height > max_height:
|
||||
pages.append("\n".join(current_page_lines))
|
||||
current_page_lines = [line]
|
||||
current_height = self.line_height
|
||||
else:
|
||||
current_page_lines.append(line)
|
||||
current_height += self.line_height
|
||||
else:
|
||||
current_page_lines = para[:]
|
||||
current_height = para_height
|
||||
else:
|
||||
if current_page_lines:
|
||||
current_page_lines.append("") # Razmik med odstavki znotraj kitice
|
||||
current_height += self.line_height
|
||||
current_page_lines.extend(para)
|
||||
current_height += para_height
|
||||
|
||||
# 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
|
||||
continue
|
||||
|
||||
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
|
||||
# Standardna logika (več kitic na stran, če grejo, upoštevajoč odstavke)
|
||||
for para in stanza_paragraphs:
|
||||
para_height = len(para) * self.line_height
|
||||
|
||||
# Preverimo, če odstavek gre na trenutno stran
|
||||
# (self.line_height if current_page_lines else 0) upošteva prazno vrstico pred odstavkom
|
||||
if current_height + para_height + (self.line_height if current_page_lines else 0) > max_height:
|
||||
if current_page_lines:
|
||||
pages.append("\n".join(current_page_lines))
|
||||
current_page_lines = []
|
||||
current_height = 0
|
||||
|
||||
# Če je sam odstavek predolg za eno stran
|
||||
if para_height > max_height:
|
||||
for line in para:
|
||||
if current_height + self.line_height > max_height:
|
||||
pages.append("\n".join(current_page_lines))
|
||||
current_page_lines = [line]
|
||||
current_height = self.line_height
|
||||
else:
|
||||
current_page_lines.append(line)
|
||||
current_height += self.line_height
|
||||
else:
|
||||
temp_stanza_lines.append(line)
|
||||
temp_height += self.line_height
|
||||
if temp_stanza_lines:
|
||||
current_page_lines = temp_stanza_lines
|
||||
current_height = temp_height
|
||||
|
||||
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
|
||||
|
||||
else:
|
||||
if current_page_lines:
|
||||
current_page_lines.append("") # Razmik med kiticami
|
||||
current_height += self.line_height
|
||||
current_page_lines.extend(stanza)
|
||||
current_height += stanza_height
|
||||
current_page_lines = para[:]
|
||||
current_height = para_height
|
||||
else:
|
||||
if current_page_lines:
|
||||
current_page_lines.append("")
|
||||
current_height += self.line_height
|
||||
current_page_lines.extend(para)
|
||||
current_height += para_height
|
||||
|
||||
if current_page_lines:
|
||||
pages.append("\n".join(current_page_lines))
|
||||
|
||||
Reference in New Issue
Block a user