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