462 int content_id = pdf->
next_id++;
463 int length_id = pdf->
next_id++;
464 size_t stream_size = 0, bytes_written = 0;
468 bytes_written += fprintf(pdf->
fd,
477 for(
int i = 0;
i < n_images;
i++)
479 bytes_written += fprintf(pdf->
fd,
481 "/ProcSet [ /PDF /Text /ImageC ] >>\n"
482 "/MediaBox [0 0 %d %d]\n"
491 bytes_written += fprintf(pdf->
fd,
497 content_id, length_id
504 for(
int i = 0;
i < n_images;
i++)
507 float scale_x, scale_y, translate_x, translate_y;
509 gboolean portrait_image = images[
i]->
width < images[
i]->
height;
510 gboolean rotate_to_fit = images[
i]->
rotate_to_fit && (portrait_page != portrait_image);
525 if(image_aspect_ratio <= bb_aspect_ratio)
528 float height_in_point = (
height / pdf->
dpi) * 72.0;
529 scale_y =
MIN(images[
i]->bb_height, height_in_point);
530 scale_x = scale_y * image_aspect_ratio;
535 float width_in_point = (
width / pdf->
dpi) * 72.0;
536 scale_x =
MIN(images[
i]->bb_width, width_in_point);
537 scale_y = scale_x / image_aspect_ratio;
541 translate_x = images[
i]->
bb_x + 0.5 * (images[
i]->
bb_width - scale_x);
542 translate_y = images[
i]->
bb_y + 0.5 * (images[
i]->
bb_height - scale_y);
544 if(rotate_to_fit && !images[
i]->outline_mode)
549 translate_x += scale_y;
554 char translate_x_str[G_ASCII_DTOSTR_BUF_SIZE];
555 char translate_y_str[G_ASCII_DTOSTR_BUF_SIZE];
556 char scale_x_str[G_ASCII_DTOSTR_BUF_SIZE];
557 char scale_y_str[G_ASCII_DTOSTR_BUF_SIZE];
559 g_ascii_dtostr(translate_x_str, G_ASCII_DTOSTR_BUF_SIZE, translate_x);
560 g_ascii_dtostr(translate_y_str, G_ASCII_DTOSTR_BUF_SIZE, translate_y);
561 g_ascii_dtostr(scale_x_str, G_ASCII_DTOSTR_BUF_SIZE, scale_x);
562 g_ascii_dtostr(scale_y_str, G_ASCII_DTOSTR_BUF_SIZE, scale_y);
564 if(images[
i]->outline_mode)
567 stream_size += fprintf(pdf->
fd,
573 translate_x_str, translate_y_str, scale_x_str, scale_y_str
578 stream_size += fprintf(pdf->
fd,
580 "1 0 0 1 %s %s cm\n",
581 translate_x_str, translate_y_str
584 stream_size += fprintf(pdf->
fd,
587 stream_size += fprintf(pdf->
fd,
591 scale_x_str, scale_y_str, images[
i]->
name_id
596 if(images[
i]->show_bb)
598 char bb_x_str[G_ASCII_DTOSTR_BUF_SIZE];
599 char bb_y_str[G_ASCII_DTOSTR_BUF_SIZE];
600 char bb_w_str[G_ASCII_DTOSTR_BUF_SIZE];
601 char bb_h_str[G_ASCII_DTOSTR_BUF_SIZE];
603 g_ascii_dtostr(bb_x_str, G_ASCII_DTOSTR_BUF_SIZE, images[
i]->bb_x);
604 g_ascii_dtostr(bb_y_str, G_ASCII_DTOSTR_BUF_SIZE, images[
i]->bb_y);
605 g_ascii_dtostr(bb_w_str, G_ASCII_DTOSTR_BUF_SIZE, images[
i]->bb_width);
606 g_ascii_dtostr(bb_h_str, G_ASCII_DTOSTR_BUF_SIZE, images[
i]->bb_height);
608 stream_size += fprintf(pdf->
fd,
613 bb_x_str, bb_y_str, bb_w_str, bb_h_str
618 bytes_written += fprintf(pdf->
fd,
622 bytes_written += stream_size;
626 bytes_written += fprintf(pdf->
fd,
"%d 0 obj\n"
627 "%" G_GSIZE_FORMAT
"\n"
629 length_id, stream_size);
631 pdf_page->
size = bytes_written;
642 size_t bytes_written = 0;
646 bytes_written += fprintf(pdf->
fd,
652 for(
int i = 0;
i < n_pages;
i++)
653 bytes_written += fprintf(pdf->
fd,
"%d 0 R\n",
pages[
i]->object_id);
654 bytes_written += fprintf(pdf->
fd,
669 int off, off_hours, off_mins;
673 localtime_r(&
t, <);
674 size = strftime(time_str,
sizeof(time_str),
"D:%Y%m%d%H%M%S", <);
686 if(time_str[14] ==
'6')
697 off = 60 * (lt.tm_hour -
gmt.tm_hour) + lt.tm_min -
gmt.tm_min;
698 if(lt.tm_year !=
gmt.tm_year)
699 off += (lt.tm_year >
gmt.tm_year) ? 1440 : -1440;
700 else if(lt.tm_yday !=
gmt.tm_yday)
701 off += (lt.tm_yday >
gmt.tm_yday) ? 1440 : -1440;
705 time_str[
size++] =
'Z';
710 off_hours = off / 60;
711 off_mins = abs(off - off_hours * 60);
712 g_snprintf(&time_str[
size],
sizeof(time_str) -
size,
"%+03d'%02d'", off_hours, off_mins);
718 bytes_written += fprintf(pdf->
fd,
726 bytes_written += fprintf(pdf->
fd,
727 "/CreationDate (%s)\n"
732 bytes_written += fprintf(pdf->
fd,
"/Producer (%s https://www.darktable.org)\n"
743 "0000000000 65535 f \n",
746 for(
int i = 0;
i < pdf->
next_id - 1;
i++) fprintf(pdf->
fd,
"%010zu 00000 n \n", pdf->
offsets[
i]);
755 "/ID [<dead> <babe>]\n"
761 fprintf(pdf->
fd,
"startxref\n"
762 "%" G_GSIZE_FORMAT
"\n"