38#include <glib/gstdio.h>
154 fprintf(stderr,
"[imageio_format_pdf] invalid paper size: `%s'!\n",
d->size);
161 fprintf(stderr,
"[imageio_format_pdf] invalid border size: `%s'! using 0\n",
d->border);
182 *page_border = border;
190 void *exif,
int exif_len, int32_t imgid,
int num,
int total,
struct dt_dev_pixelpipe_t *pipe,
191 const gboolean export_masks)
198 float page_width, page_height, page_border;
199 float page_dpi =
d->params.dpi;
201 if(
_paper_size(&
d->params, &page_width, &page_height, &page_border))
204 unsigned int compression =
d->params.compression;
211 fprintf(stderr,
"[imageio_format_pdf] could not export to file: `%s'!\n", filename);
217 pdf->
title = *
d->params.title ?
d->params.title : NULL;
220 d->actual_filename = g_strdup(filename);
221 d->page_border = page_border;
226 if(imgid > 0 &&
d->params.icc &&
d->params.mode ==
MODE_NORMAL)
232 for(GList *iter =
d->icc_profiles; iter; iter = g_list_next(iter))
244 cmsSaveProfileToMem(profile->
profile, 0, &len);
247 unsigned char *buf = malloc(
sizeof(
unsigned char) * len);
248 cmsSaveProfileToMem(profile->
profile, buf, &len);
254 d->icc_profiles = g_list_append(
d->icc_profiles, icc);
259 void *image_data = NULL;
266 if(
d->params.bpp == 8)
271 const uint8_t *in_ptr = (
const uint8_t *)in;
272 uint8_t *out_ptr = (uint8_t *)image_data;
273 for(
int y = 0; y < data->
height; y++)
275 for(
int x = 0;
x < data->
width;
x++, in_ptr += 4, out_ptr += 3)
276 memcpy(out_ptr, in_ptr, 3);
284 const uint16_t *in_ptr = (
const uint16_t *)in;
285 uint16_t *out_ptr = (uint16_t *)image_data;
286 for(
int y = 0; y < data->
height; y++)
288 for(
int x = 0;
x < data->
width;
x++, in_ptr += 4, out_ptr += 3)
290 for(
int c = 0; c < 3; c++)
291 out_ptr[c] = (0xff00 & (in_ptr[c] << 8)) | (in_ptr[c] >> 8);
301 d->images = g_list_append(
d->images, image);
307 int n_images = g_list_length(
d->images);
315 for(
const GList *iter =
d->images; iter; iter = g_list_next(iter))
337 d->icc_profiles = NULL;
341 d->actual_filename = NULL;
342 d->icc_profiles = NULL;
360 return "application/pdf";
384 float page_width, page_height, page_border;
385 float page_dpi =
d->params.dpi;
387 if(
_paper_size(&
d->params, &page_width, &page_height, &page_border))
462 dt_conf_set_string(
"plugins/imageio/format/pdf/title", gtk_entry_get_text(GTK_ENTRY(widget)));
467 dt_conf_set_string(
"plugins/imageio/format/pdf/border", gtk_entry_get_text(GTK_ENTRY(widget)));
486 dt_conf_set_float(
"plugins/imageio/format/pdf/dpi", gtk_spin_button_get_value(GTK_SPIN_BUTTON(widget)));
526 self->
widget = gtk_grid_new();
527 GtkGrid *grid = GTK_GRID(self->
widget);
537 d->title = GTK_ENTRY(gtk_entry_new());
539 gtk_entry_set_placeholder_text(
d->title,
"untitled");
540 gtk_entry_set_width_chars(
d->title, 5);
541 gtk_widget_set_hexpand(GTK_WIDGET(
d->title),
TRUE);
542 gtk_grid_attach(grid, GTK_WIDGET(
d->title), 1, line, 1, 1);
543 gtk_widget_set_tooltip_text(GTK_WIDGET(
d->title), _(
"enter the title of the pdf"));
547 gtk_entry_set_text(GTK_ENTRY(
d->title), str);
558 gtk_grid_attach(grid, GTK_WIDGET(
d->size), 0, ++line, 2, 1);
560 gtk_widget_set_tooltip_text(
d->size, _(
"paper size of the pdf\neither one from the list or "
561 "\"<width> [unit] x <height> <unit>\n"
562 "example: 210 mm x 2.97 cm"));
573 gtk_grid_attach(grid, GTK_WIDGET(
d->orientation), 0, ++line, 2, 1);
575 gtk_widget_set_tooltip_text(
d->orientation, _(
"paper orientation of the pdf"));
582 d->border = GTK_ENTRY(gtk_entry_new());
584 gtk_entry_set_width_chars(
d->border, 5);
586 gtk_entry_set_placeholder_text(
d->border,
"0 mm");
587 gtk_grid_attach(grid, GTK_WIDGET(
d->border), 1, line, 1, 1);
588 gtk_widget_set_tooltip_text(GTK_WIDGET(
d->border), _(
"empty space around the pdf\n"
589 "format: size + unit\nexamples: 10 mm, 1 inch"));
593 gtk_entry_set_text(GTK_ENTRY(
d->border), str);
601 d->dpi = GTK_SPIN_BUTTON(gtk_spin_button_new_with_range(1, 5000, 1));
602 gtk_grid_attach(grid, GTK_WIDGET(
d->dpi), 1, line, 1, 1);
603 gtk_widget_set_tooltip_text(GTK_WIDGET(
d->dpi), _(
"dpi of the images inside the pdf"));
604 gtk_spin_button_set_value(
d->dpi,
dt_conf_get_float(
"plugins/imageio/format/pdf/dpi"));
613 gtk_grid_attach(grid, GTK_WIDGET(
d->rotate), 0, ++line, 2, 1);
615 gtk_widget_set_tooltip_text(
d->rotate, _(
"images can be rotated to match the pdf orientation "
616 "to waste less space when printing"));
628 gtk_widget_set_tooltip_text(
d->pages, _(
"what pages should be added to the pdf"));
630 gtk_widget_set_sensitive(
d->pages,
FALSE);
638 gtk_grid_attach(grid, GTK_WIDGET(
d->icc), 0, ++line, 2, 1);
640 gtk_widget_set_tooltip_text(
d->icc, _(
"images can be tagged with their icc profile"));
654 gtk_grid_attach(grid, GTK_WIDGET(
d->bpp), 0, ++line, 2, 1);
656 gtk_widget_set_tooltip_text(
d->bpp, _(
"bits per channel of the embedded images"));
665 gtk_grid_attach(grid, GTK_WIDGET(
d->compression), 0, ++line, 2, 1);
667 gtk_widget_set_tooltip_text(
d->compression, _(
"method used for image compression\n"
668 "uncompressed -- fast but big files\n"
669 "deflate -- smaller files but slower"));
679 gtk_grid_attach(grid, GTK_WIDGET(
d->mode), 0, ++line, 2, 1);
681 gtk_widget_set_tooltip_text(
d->mode, _(
"normal -- just put the images into the pdf\n"
682 "draft -- images are replaced with boxes\n"
683 "debug -- only show the outlines and bounding boxen"));
720 g_strlcpy(
d->params.title, text,
sizeof(
d->params.title));
723 g_strlcpy(
d->params.border, text,
sizeof(
d->params.border));
726 g_strlcpy(
d->params.size, text,
sizeof(
d->params.size));
729 d->params.compression =
dt_conf_get_int(
"plugins/imageio/format/pdf/compression");
733 d->params.orientation =
dt_conf_get_int(
"plugins/imageio/format/pdf/orientation");
753 if(
d->actual_filename)
755 g_unlink(
d->actual_filename);
760 d->icc_profiles = NULL;
764 d->actual_filename = NULL;
765 d->icc_profiles = NULL;
772 if(
size != self->params_size(self))
return 1;
782 gtk_entry_set_text(
g->title,
d->params.title);
783 gtk_entry_set_text(
g->border,
d->params.border);
785 gtk_spin_button_set_value(
g->dpi,
d->params.dpi);
796 dt_conf_set_int(
"plugins/imageio/format/pdf/compression",
d->params.compression);
800 dt_conf_set_int(
"plugins/imageio/format/pdf/orientation",
d->params.orientation);
void dt_accels_disconnect_on_text_input(GtkWidget *widget)
Disconnect accels while a text or search entry has the focus, and reconnect them when it loses it....
Handle default and user-set shortcuts (accelerators)
void dt_bauhaus_combobox_set_editable(GtkWidget *widget, int editable)
const char * dt_bauhaus_combobox_get_entry(GtkWidget *widget, int pos)
int dt_bauhaus_combobox_get(GtkWidget *widget)
int dt_bauhaus_combobox_length(GtkWidget *widget)
const char * dt_bauhaus_combobox_get_text(GtkWidget *widget)
void dt_bauhaus_combobox_set(GtkWidget *widget, const int pos)
void dt_bauhaus_widget_set_label(GtkWidget *widget, const char *label)
GtkWidget * dt_bauhaus_combobox_new(dt_bauhaus_t *bh, dt_gui_module_t *self)
void dt_bauhaus_combobox_add(GtkWidget *widget, const char *text)
The colour-profile module's API: which profiles exist, and how to apply one.
struct _GtkWidget GtkWidget
GtkWidget, opaque, spelled exactly as GTK spells it.
void dt_conf_set_bool(const char *name, int val)
int dt_conf_get_bool(const char *name)
void dt_conf_set_float(const char *name, float val)
float dt_conf_get_float(const char *name)
Float for name, clamped to its declared bounds.
gchar * dt_conf_get_string(const char *name)
Read the stored string for name as a private copy.
void dt_conf_set_int(const char *name, int val)
int dt_conf_get_int(const char *name)
Integer for name, clamped to the bounds declared in the XML.
void dt_conf_set_string(const char *name, const char *val)
const char * dt_conf_get_string_const(const char *name)
Borrow the stored string for name without copying it.
dt_pdf_page_t * dt_pdf_add_page(dt_pdf_t *pdf, dt_pdf_image_t **images, int n_images)
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)
int dt_pdf_parse_length(const char *str, float *length)
int dt_pdf_add_icc_from_data(dt_pdf_t *pdf, const unsigned char *data, size_t size)
int dt_pdf_parse_paper_size(const char *str, float *width, float *height)
void dt_pdf_finish(dt_pdf_t *pdf, dt_pdf_page_t **pages, int n_pages)
dt_pdf_t * dt_pdf_start(const char *filename, float width, float height, float dpi, dt_pdf_stream_encoder_t default_encoder)
void dt_control_log(const char *msg,...)
struct dt_bauhaus_t * dt_bauhaus_get_global(void)
GHashTable * pages
row label -> path of the illustration, relative to the destination
@ FORMAT_FLAGS_NO_TMPFILE
const dt_colorspaces_color_profile_t * dt_colorspaces_get_output_profile(const int32_t imgid, dt_colorspaces_color_profile_type_t *over_type, const char *over_filename)
GtkWidget * dt_ui_label_new(const gchar *str)
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
static void dt_free_gpointer(gpointer ptr)
g_free() one pointer, with the signature GDestroyNotify wants.
#define dt_free(ptr)
g_free() ptr and set it to NULL, skipping both if it is already NULL.
dt_mipmap_buffer_dsc_flags flags
#define DT_MODULE(MODVER)
Instantiate the version handshake every module must export. Use once, at file scope,...
#define dt_pdf_point_to_pixel(pt, dpi)
static const int dt_pdf_paper_sizes_n
static const struct @6 dt_pdf_paper_sizes[]
@ DT_PDF_STREAM_ENCODER_FLATE
#define dt_pixelpipe_cache_alloc_align_cache(size, id)
#define dt_pixelpipe_cache_free_align(mem)
dt_colorspaces_color_profile_type_t
const dt_colorspaces_color_profile_t * profile
One registered profile: its identity, its LCMS handle, and where it sits in each combo box.
cmsHPROFILE profile
the actual profile; NULL for the three category entries
dt_imageio_module_data_t global
dt_pdf_stream_encoder_t compression
_pdf_orientation_t orientation
dt_imageio_pdf_params_t params
Telling the user something happened.