commit 8f902ca4ceced15f3e194cf40d7d7cc89fe5e7f6
parent 8ace6ebe5ca1dbb7a12e906be514567624ba7128
Author: nibo <nibo@relim.de>
Date: Fri, 31 Jan 2025 08:55:03 +0100
Fix toc dots width
Diffstat:
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/out_pdf.c b/out_pdf.c
@@ -2033,6 +2033,7 @@ pdf_texts_add_toc_entry(
struct PDFText ***texts;
texts = &ctx->content->pages[ctx->page]->texts;
double width, page_no_x, end_of_title_x, width_between_title_and_page_no, available_dots_width;
+ double page_no_width, dots_width;
int index, line_count;
char tmp[strlen(entry->title)+1];
char page_no[11+1];
@@ -2158,13 +2159,13 @@ pdf_texts_add_toc_entry(
(*texts)[ctx->text]->width = width;
ctx->text++;
sprintf((char *)&page_no, "%d", entry->page_index+1);
- width = text_width(page_no, style);
- if (width == ERROR) {
+ page_no_width = text_width(page_no, style);
+ if (page_no_width == ERROR) {
LOG_DEBUG("text_width failed.");
return false;
}
- page_no_x = MEDIABOX_WIDTH - width - MARGIN_HORIZONTAL;
+ page_no_x = MEDIABOX_WIDTH - page_no_width - MARGIN_HORIZONTAL;
width_between_title_and_page_no = page_no_x - end_of_title_x;
available_dots_width = width_between_title_and_page_no - TOC_DOTS_GAP_WIDTH*2;
const char *dots = toc_dots_create(available_dots_width, dot_width);
@@ -2172,6 +2173,11 @@ pdf_texts_add_toc_entry(
LOG_DEBUG("toc_dots_create failed.");
return false;
}
+ dots_width = text_width(dots, style);
+ if (dots_width == ERROR) {
+ LOG_DEBUG("text_width failed.");
+ return false;
+ }
*texts = erealloc(*texts, (ctx->text+1) * sizeof(struct PDFText *));
(*texts)[ctx->text] = pdf_text_new();
@@ -2179,6 +2185,7 @@ pdf_texts_add_toc_entry(
(*texts)[ctx->text]->style = cho_style_copy(style);
(*texts)[ctx->text]->x = MARGIN_HORIZONTAL + end_of_title_x + TOC_DOTS_GAP_WIDTH;
(*texts)[ctx->text]->y = ctx->y;
+ (*texts)[ctx->text]->width = dots_width;
ctx->text++;
*texts = erealloc(*texts, (ctx->text+1) * sizeof(struct PDFText *));
@@ -2187,7 +2194,7 @@ pdf_texts_add_toc_entry(
(*texts)[ctx->text]->style = cho_style_copy(style);
(*texts)[ctx->text]->x = page_no_x;
(*texts)[ctx->text]->y = ctx->y;
- (*texts)[ctx->text]->width = width;
+ (*texts)[ctx->text]->width = page_no_width;
if (!annot_page_link_add(ctx, entry, toc_page_count, 1, style->font->size)) {
LOG_DEBUG("annot_page_link_add");
return false;