463 int content_id = pdf->
next_id++;
464 int length_id = pdf->
next_id++;
465 size_t stream_size = 0, bytes_written = 0;
469 bytes_written += fprintf(pdf->
fd,
478 for(
int i = 0;
i < n_images;
i++)
480 bytes_written += fprintf(pdf->
fd,
482 "/ProcSet [ /PDF /Text /ImageC ] >>\n"
483 "/MediaBox [0 0 %d %d]\n"
492 bytes_written += fprintf(pdf->
fd,
498 content_id, length_id
505 for(
int i = 0;
i < n_images;
i++)
508 float scale_x, scale_y, translate_x, translate_y;
510 gboolean portrait_image = images[
i]->
width < images[
i]->
height;
511 gboolean rotate_to_fit = images[
i]->
rotate_to_fit && (portrait_page != portrait_image);
526 if(image_aspect_ratio <= bb_aspect_ratio)
529 float height_in_point = (
height / pdf->
dpi) * 72.0;
530 scale_y =
MIN(images[
i]->bb_height, height_in_point);
531 scale_x = scale_y * image_aspect_ratio;
536 float width_in_point = (
width / pdf->
dpi) * 72.0;
537 scale_x =
MIN(images[
i]->bb_width, width_in_point);
538 scale_y = scale_x / image_aspect_ratio;
542 translate_x = images[
i]->
bb_x + 0.5 * (images[
i]->
bb_width - scale_x);
543 translate_y = images[
i]->
bb_y + 0.5 * (images[
i]->
bb_height - scale_y);
545 if(rotate_to_fit && !images[
i]->outline_mode)
550 translate_x += scale_y;
555 char translate_x_str[G_ASCII_DTOSTR_BUF_SIZE];
556 char translate_y_str[G_ASCII_DTOSTR_BUF_SIZE];
557 char scale_x_str[G_ASCII_DTOSTR_BUF_SIZE];
558 char scale_y_str[G_ASCII_DTOSTR_BUF_SIZE];
560 g_ascii_dtostr(translate_x_str, G_ASCII_DTOSTR_BUF_SIZE, translate_x);
561 g_ascii_dtostr(translate_y_str, G_ASCII_DTOSTR_BUF_SIZE, translate_y);
562 g_ascii_dtostr(scale_x_str, G_ASCII_DTOSTR_BUF_SIZE, scale_x);
563 g_ascii_dtostr(scale_y_str, G_ASCII_DTOSTR_BUF_SIZE, scale_y);
565 if(images[
i]->outline_mode)
568 stream_size += fprintf(pdf->
fd,
574 translate_x_str, translate_y_str, scale_x_str, scale_y_str
579 stream_size += fprintf(pdf->
fd,
581 "1 0 0 1 %s %s cm\n",
582 translate_x_str, translate_y_str
585 stream_size += fprintf(pdf->
fd,
588 stream_size += fprintf(pdf->
fd,
592 scale_x_str, scale_y_str, images[
i]->
name_id
597 if(images[
i]->show_bb)
599 char bb_x_str[G_ASCII_DTOSTR_BUF_SIZE];
600 char bb_y_str[G_ASCII_DTOSTR_BUF_SIZE];
601 char bb_w_str[G_ASCII_DTOSTR_BUF_SIZE];
602 char bb_h_str[G_ASCII_DTOSTR_BUF_SIZE];
604 g_ascii_dtostr(bb_x_str, G_ASCII_DTOSTR_BUF_SIZE, images[
i]->bb_x);
605 g_ascii_dtostr(bb_y_str, G_ASCII_DTOSTR_BUF_SIZE, images[
i]->bb_y);
606 g_ascii_dtostr(bb_w_str, G_ASCII_DTOSTR_BUF_SIZE, images[
i]->bb_width);
607 g_ascii_dtostr(bb_h_str, G_ASCII_DTOSTR_BUF_SIZE, images[
i]->bb_height);
609 stream_size += fprintf(pdf->
fd,
614 bb_x_str, bb_y_str, bb_w_str, bb_h_str
619 bytes_written += fprintf(pdf->
fd,
623 bytes_written += stream_size;
627 bytes_written += fprintf(pdf->
fd,
"%d 0 obj\n"
628 "%" G_GSIZE_FORMAT
"\n"
630 length_id, stream_size);
632 pdf_page->
size = bytes_written;
643 size_t bytes_written = 0;
647 bytes_written += fprintf(pdf->
fd,
653 for(
int i = 0;
i < n_pages;
i++)
654 bytes_written += fprintf(pdf->
fd,
"%d 0 R\n", pages[
i]->
object_id);
655 bytes_written += fprintf(pdf->
fd,
670 int off, off_hours, off_mins;
674 localtime_r(&
t, <);
675 size = strftime(time_str,
sizeof(time_str),
"D:%Y%m%d%H%M%S", <);
687 if(time_str[14] ==
'6')
698 off = 60 * (lt.tm_hour -
gmt.tm_hour) + lt.tm_min -
gmt.tm_min;
699 if(lt.tm_year !=
gmt.tm_year)
700 off += (lt.tm_year >
gmt.tm_year) ? 1440 : -1440;
701 else if(lt.tm_yday !=
gmt.tm_yday)
702 off += (lt.tm_yday >
gmt.tm_yday) ? 1440 : -1440;
706 time_str[
size++] =
'Z';
711 off_hours = off / 60;
712 off_mins = abs(off - off_hours * 60);
713 g_snprintf(&time_str[
size],
sizeof(time_str) -
size,
"%+03d'%02d'", off_hours, off_mins);
719 bytes_written += fprintf(pdf->
fd,
727 bytes_written += fprintf(pdf->
fd,
728 "/CreationDate (%s)\n"
733 bytes_written += fprintf(pdf->
fd,
"/Producer (%s https://www.darktable.org)\n"
744 "0000000000 65535 f \n",
747 for(
int i = 0;
i < pdf->
next_id - 1;
i++) fprintf(pdf->
fd,
"%010zu 00000 n \n", pdf->
offsets[
i]);
756 "/ID [<dead> <babe>]\n"
762 fprintf(pdf->
fd,
"startxref\n"
763 "%" G_GSIZE_FORMAT
"\n"