Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
pdf.h
Go to the documentation of this file.
1/*
2 * This file is part of darktable,
3 * Copyright (C) 2015, 2020-2021 Pascal Obry.
4 * Copyright (C) 2015-2016, 2018 Tobias Ellinghaus.
5 * Copyright (C) 2016 Roman Lebedev.
6 * Copyright (C) 2017 luzpaz.
7 * Copyright (C) 2020 Heiko Bauke.
8 * Copyright (C) 2022 Martin Baƙinka.
9 *
10 * darktable is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * darktable is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with darktable. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24/*
25 * this is a simple PDF writer, capable of creating multi page PDFs with embedded images.
26 * it is NOT meant to be a full fledged PDF library, and shall never turn into something like that!
27 * see the main() function in pdf.c to see an example how to use this.
28 */
29
30#ifndef DT_COMMON_PDF_H
31#define DT_COMMON_PDF_H
32
33#include <glib.h>
34#include <glib/gi18n.h>
35#include <inttypes.h>
36#include <stdio.h>
37
38// clang-format off
39
40#define dt_pdf_inch_to_point(inch) ((inch) * 72.0)
41#define dt_pdf_point_to_inch(pt) ((pt) / 72.0)
42#define dt_pdf_mm_to_point(mm) dt_pdf_inch_to_point((mm) / 25.4)
43#define dt_pdf_point_to_mm(pt) dt_pdf_point_to_inch((pt) * 25.4)
44#define dt_pdf_point_to_pixel(pt, dpi) (dt_pdf_point_to_inch(pt) * (dpi))
45#define dt_pdf_pixel_to_point(px, dpi) (dt_pdf_inch_to_point((px) / (dpi)))
46
48{
49 DT_PDF_STREAM_ENCODER_ASCII_HEX = 0, // inflate size by 2 -- big & fast
50 DT_PDF_STREAM_ENCODER_FLATE = 1 // use zlib to compress -- small & slow
52
67
68typedef struct dt_pdf_image_t
69{
72 size_t size;
73 size_t width, height;
75
76 gboolean rotate_to_fit;
77
78 gboolean outline_mode; // set to 1 to only draw a box instead of the image
79 gboolean show_bb; // set to 1 to draw the bounding box. useful for debugging
81
82typedef struct dt_pdf_page_t
83{
85 size_t size;
87
88static const struct
89{
90 const char *name;
91 const float factor;
92} dt_pdf_units[] =
93{
94 {N_("mm"), dt_pdf_mm_to_point(1.0)},
95 {N_("cm"), dt_pdf_mm_to_point(10.0)},
96 {N_("inch"), dt_pdf_inch_to_point(1.0)},
97 {N_("\""), dt_pdf_inch_to_point(1.0)},
98 {NULL, 0.0}
99};
100
101static const int dt_pdf_units_n = sizeof(dt_pdf_units) / sizeof(dt_pdf_units[0]);
102
103static const struct
104{
105 const char *name;
106 const float width;
107 const float height;
109{
110 {N_("a4"), dt_pdf_mm_to_point(210), dt_pdf_mm_to_point(297)},
111 {N_("a3"), dt_pdf_mm_to_point(297), dt_pdf_mm_to_point(420)},
112 {N_("letter"), dt_pdf_inch_to_point(8.5), dt_pdf_inch_to_point(11.0)},
113 {N_("legal"), dt_pdf_inch_to_point(8.5), dt_pdf_inch_to_point(14.0)},
114 {NULL, 0.0, 0.0}
116
117// clang-format on
118
119static const int dt_pdf_paper_sizes_n = sizeof(dt_pdf_paper_sizes) / sizeof(dt_pdf_paper_sizes[0]) - 1;
120
121// construction of the pdf
122dt_pdf_t *dt_pdf_start(const char *filename, float width, float height, float dpi, dt_pdf_stream_encoder_t default_encoder);
123int dt_pdf_add_icc(dt_pdf_t *pdf, const char *filename);
124int dt_pdf_add_icc_from_data(dt_pdf_t *pdf, const unsigned char *data, size_t size);
125dt_pdf_image_t *dt_pdf_add_image(dt_pdf_t *pdf, const unsigned char *image, int width, int height, int bpp, int icc_id, float border);
126dt_pdf_page_t *dt_pdf_add_page(dt_pdf_t *pdf, dt_pdf_image_t **images, int n_images);
127void dt_pdf_finish(dt_pdf_t *pdf, dt_pdf_page_t **pages, int n_pages);
128
129// general helpers
130int dt_pdf_parse_length(const char *str, float *length);
131int dt_pdf_parse_paper_size(const char *str, float *width, float *height);
132
133#endif // DT_COMMON_PDF_H
134
135// clang-format off
136// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
137// vim: shiftwidth=2 expandtab tabstop=2 cindent
138// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
139// clang-format on
140
GHashTable * pages
row label -> path of the illustration, relative to the destination
int bpp
size_t size
Definition mipmap_cache.c:3
dt_pdf_page_t * dt_pdf_add_page(dt_pdf_t *pdf, dt_pdf_image_t **images, int n_images)
Definition common/pdf.c:457
static const int dt_pdf_paper_sizes_n
Definition pdf.h:119
dt_pdf_image_t * dt_pdf_add_image(dt_pdf_t *pdf, const unsigned char *image, int width, int height, int bpp, int icc_id, float border)
Definition common/pdf.c:375
int dt_pdf_parse_length(const char *str, float *length)
Definition common/pdf.c:69
const float width
Definition pdf.h:106
static const struct @5 dt_pdf_units[]
const float factor
Definition pdf.h:91
int dt_pdf_add_icc_from_data(dt_pdf_t *pdf, const unsigned char *data, size_t size)
Definition common/pdf.c:331
#define dt_pdf_inch_to_point(inch)
Definition pdf.h:40
#define dt_pdf_mm_to_point(mm)
Definition pdf.h:42
const float height
Definition pdf.h:107
int dt_pdf_parse_paper_size(const char *str, float *width, float *height)
Definition common/pdf.c:117
int dt_pdf_add_icc(dt_pdf_t *pdf, const char *filename)
Definition common/pdf.c:317
static const struct @6 dt_pdf_paper_sizes[]
void dt_pdf_finish(dt_pdf_t *pdf, dt_pdf_page_t **pages, int n_pages)
Definition common/pdf.c:639
static const int dt_pdf_units_n
Definition pdf.h:101
dt_pdf_t * dt_pdf_start(const char *filename, float width, float height, float dpi, dt_pdf_stream_encoder_t default_encoder)
Definition common/pdf.c:217
dt_pdf_stream_encoder_t
Definition pdf.h:48
@ DT_PDF_STREAM_ENCODER_ASCII_HEX
Definition pdf.h:49
@ DT_PDF_STREAM_ENCODER_FLATE
Definition pdf.h:50
const char * name
Definition pdf.h:90
float bb_x
Definition pdf.h:74
size_t width
Definition pdf.h:73
float bb_width
Definition pdf.h:74
float bb_y
Definition pdf.h:74
gboolean rotate_to_fit
Definition pdf.h:76
gboolean show_bb
Definition pdf.h:79
size_t height
Definition pdf.h:73
int object_id
Definition pdf.h:70
int name_id
Definition pdf.h:71
float bb_height
Definition pdf.h:74
gboolean outline_mode
Definition pdf.h:78
size_t size
Definition pdf.h:72
size_t size
Definition pdf.h:85
int object_id
Definition pdf.h:84
Definition pdf.h:54
char * title
Definition pdf.h:62
float page_width
Definition pdf.h:59
float page_height
Definition pdf.h:59
int next_image
Definition pdf.h:57
int next_id
Definition pdf.h:56
size_t bytes_written
Definition pdf.h:58
FILE * fd
Definition pdf.h:55
dt_pdf_stream_encoder_t default_encoder
Definition pdf.h:60
int n_offsets
Definition pdf.h:65
size_t * offsets
Definition pdf.h:64
float dpi
Definition pdf.h:59