commit afc140535cb1270958e031b53ed85ba48103f39c
parent 8b71175992609d9bd033c5229d577708b27c8b19
Author: nibo <nibo@relim.de>
Date: Thu, 15 Aug 2024 03:05:02 +0200
out_pdf: Break page if text too long
Diffstat:
| M | out_pdf.c | | | 36 | ++++++++++++++++++++++++++++++------ |
1 file changed, 30 insertions(+), 6 deletions(-)
diff --git a/out_pdf.c b/out_pdf.c
@@ -583,7 +583,7 @@ static struct SpaceNeeded *needs_space(struct SpaceNeeded **spaces, int ly, int
return NULL;
}
-static void text_line_set_lineheight(struct TextLine *line, enum SongFragmentType ftype)
+static double text_line_set_lineheight(struct TextLine *line, enum SongFragmentType ftype)
{
double biggest_font_size = 0.0;
int tli;
@@ -599,6 +599,7 @@ static void text_line_set_lineheight(struct TextLine *line, enum SongFragmentTyp
default:
line->height = 8.0 + biggest_font_size;
}
+ return line->height;
}
static struct Text **text_create(struct ChoSong **songs, struct Config *config)
@@ -606,6 +607,7 @@ static struct Text **text_create(struct ChoSong **songs, struct Config *config)
struct PrintableItem *printable_item;
int so, se, li, ly, ch;
double width;
+ double y = MEDIABOX_HEIGHT - VERTICAL_MARGIN;
bool add_space_to_next_chord = false;
struct ChoLine **lines;
struct ChoLineItemAbove **text_above;
@@ -637,7 +639,11 @@ static struct Text **text_create(struct ChoSong **songs, struct Config *config)
text[t]->lines[tl]->items[0]->x = PADDING + (LINE_LEN - width) / 2;
text[t]->lines[tl]->items[1] = NULL;
text[t]->lines[tl]->btype = BT_LINE;
- text_line_set_lineheight(text[t]->lines[tl], SF_TEXT);
+ y -= text_line_set_lineheight(text[t]->lines[tl], SF_TEXT);
+ if (y < MARGIN_BOTTOM) {
+ y = MEDIABOX_HEIGHT - VERTICAL_MARGIN;
+ text[t]->lines[tl]->btype = BT_PAGE;
+ }
tl++;
}
}
@@ -662,7 +668,11 @@ static struct Text **text_create(struct ChoSong **songs, struct Config *config)
text[t]->lines[tl]->items[0]->x = PADDING + (LINE_LEN - width) / 2;
text[t]->lines[tl]->items[1] = NULL;
text[t]->lines[tl]->btype = BT_LINE;
- text_line_set_lineheight(text[t]->lines[tl], SF_TEXT);
+ y -= text_line_set_lineheight(text[t]->lines[tl], SF_TEXT);
+ if (y < MARGIN_BOTTOM) {
+ y = MEDIABOX_HEIGHT - VERTICAL_MARGIN;
+ text[t]->lines[tl]->btype = BT_PAGE;
+ }
tl++;
}
}
@@ -683,7 +693,11 @@ static struct Text **text_create(struct ChoSong **songs, struct Config *config)
text[t]->lines[tl]->items[0]->x = PADDING;
text[t]->lines[tl]->items[1] = NULL;
text[t]->lines[tl]->btype = BT_LINE;
- text_line_set_lineheight(text[t]->lines[tl], SF_TEXT);
+ y -= text_line_set_lineheight(text[t]->lines[tl], SF_TEXT);
+ if (y < MARGIN_BOTTOM) {
+ y = MEDIABOX_HEIGHT - VERTICAL_MARGIN;
+ text[t]->lines[tl]->btype = BT_PAGE;
+ }
tl++;
}
lines = songs[so]->sections[se]->lines;
@@ -760,7 +774,13 @@ static struct Text **text_create(struct ChoSong **songs, struct Config *config)
text[t]->lines[tl]->items = realloc(text[t]->lines[tl]->items, (tli+1) * sizeof(struct TextLineItem *));
text[t]->lines[tl]->items[tli] = NULL;
text[t]->lines[tl]->btype = lines[li]->btype;
- text_line_set_lineheight(text[t]->lines[tl], SF_CHORD);
+ y -= text_line_set_lineheight(text[t]->lines[tl], SF_CHORD);
+ if (y < MARGIN_BOTTOM) {
+ // INFO: we don't split the chords and corresponding lyrics
+ y = MEDIABOX_HEIGHT - VERTICAL_MARGIN;
+ y -= text[t]->lines[tl]->height;
+ text[t]->lines[tl-1]->btype = BT_PAGE;
+ }
tli = 0;
tl++;
}
@@ -817,8 +837,12 @@ static struct Text **text_create(struct ChoSong **songs, struct Config *config)
}
text[t]->lines[tl]->items = realloc(text[t]->lines[tl]->items, (tli+1) * sizeof(struct TextLineItem *));
text[t]->lines[tl]->items[tli] = NULL;
- text_line_set_lineheight(text[t]->lines[tl], SF_TEXT);
text[t]->lines[tl]->btype = lines[li]->btype;
+ y -= text_line_set_lineheight(text[t]->lines[tl], SF_TEXT);
+ if (y < MARGIN_BOTTOM) {
+ y = MEDIABOX_HEIGHT - VERTICAL_MARGIN;
+ text[t]->lines[tl]->btype = BT_PAGE;
+ }
tli = 0;
if (spaces) {
for (sn = 0; spaces[sn]; sn++) {