32#include <glib/gstdio.h>
42#include <AvailabilityMacros.h>
50#if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_8 && ((CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR >= 6) || CUPS_VERSION_MAJOR > 1)
53#if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_9 && ((CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR >= 7) || CUPS_VERSION_MAJOR > 1)
55extern cups_dinfo_t *cupsCopyDestInfo()
__attribute__((weak_import));
56extern
int cupsGetDestMediaCount()
__attribute__((weak_import));
57extern
int cupsGetDestMediaByIndex()
__attribute__((weak_import));
61#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
92 const int num_dests = cupsGetDests(&dests);
93 cups_dest_t *dest = cupsGetDest(printer_name, NULL, num_dests, dests);
97 const char *PPDFile = cupsGetPPD (printer_name);
99 ppd_file_t *ppd = ppdOpenFile(PPDFile);
103 ppdMarkDefaults(ppd);
104 cupsMarkOptions(ppd, dest->num_options, dest->options);
109 ppd_attr_t *attr = ppdFindAttr(ppd,
"ModelName", NULL);
113 pinfo->
is_turboprint = strstr(attr->value,
"TurboPrint") != NULL;
118 attr = ppdFindAttr(ppd,
"HWMargins", NULL);
125 sscanf(attr->value,
"%lf %lf %lf %lf",
137 attr = ppdFindAttr(ppd,
"DefaultResolution", NULL);
141 char *
x = strstr(attr->value,
"x");
146 sscanf (attr->value,
"%ddpi", &pinfo->
resolution);
159 cupsFreeDests(num_dests, dests);
165 const char *psvalue = cupsGetOption(
"printer-state", dest->num_options, dest->options);
168 if (psvalue!=NULL && strtol(psvalue, NULL, 10) < IPP_PRINTER_STOPPED)
171 memset(&pr, 0,
sizeof(pr));
188#if ((CUPS_VERSION_MAJOR == 1) && (CUPS_VERSION_MINOR >= 6)) || CUPS_VERSION_MAJOR > 1
189#if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_8
193#if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_8
197#if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_8 || !(((CUPS_VERSION_MAJOR == 1) && (CUPS_VERSION_MINOR >= 6)) || CUPS_VERSION_MAJOR > 1)
200 const int num_dests = cupsGetDests(&dests);
201 for (
int k=0;
k<num_dests;
k++)
205 cupsFreeDests(num_dests, dests);
238 for(GList *
p = papers;
p;
p = g_list_next(
p))
251 for(GList *
p = papers;
p;
p = g_list_next(
p))
275 const char *printer_name = printer->
name;
276 GList *result = NULL;
278#if ((CUPS_VERSION_MAJOR == 1) && (CUPS_VERSION_MINOR >= 7)) || CUPS_VERSION_MAJOR > 1
279#if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_9
285 const int num_dests = cupsGetDests(&dests);
286 cups_dest_t *dest = cupsGetDest(printer_name, NULL, num_dests, dests);
294 http_t *hcon = cupsConnectDest(dest, 0, 2000, &cancel, resource,
sizeof(resource), NULL, (
void *)NULL);
299 cups_dinfo_t *info = cupsCopyDestInfo (hcon, dest);
300 const int count = cupsGetDestMediaCount(hcon, dest, info, CUPS_MEDIA_FLAGS_DEFAULT);
301 for (
int k=0;
k<count;
k++)
303 if (cupsGetDestMediaByIndex(hcon, dest, info,
k, CUPS_MEDIA_FLAGS_DEFAULT, &
size))
307 pwg_media_t *med = pwgMediaForPWG (
size.media);
311 g_strlcpy(common_name, med->ppd,
sizeof(common_name));
313 g_strlcpy(common_name,
size.media,
sizeof(common_name));
316 g_strlcpy(paper->
name,
size.media,
sizeof(paper->
name));
320 result = g_list_append (result, paper);
323 "[print] new media paper %4d %6.2f x %6.2f (%s) (%s)\n",
329 cupsFreeDestInfo(info);
336 cupsFreeDests(num_dests, dests);
342 const char *PPDFile = cupsGetPPD(printer_name);
343 ppd_file_t *ppd = ppdOpenFile(PPDFile);
347 ppd_size_t *
size = ppd->sizes;
349 for (
int k=0;
k<ppd->num_sizes;
k++)
358 result = g_list_append (result, paper);
361 "[print] new ppd paper %4d %6.2f x %6.2f (%s) (%s)\n",
371 result = g_list_sort_with_data (result, (GCompareDataFunc)
sort_papers, NULL);
377 const char *printer_name = printer->
name;
378 GList *result = NULL;
382 const char *PPDFile = cupsGetPPD(printer_name);
383 ppd_file_t *ppd = ppdOpenFile(PPDFile);
387 ppd_option_t *opt = ppdFindOption(ppd,
"MediaType");
391 ppd_choice_t *choice = opt->choices;
393 for (
int k=0;
k<opt->num_choices;
k++)
398 result = g_list_prepend (result, media);
409 return g_list_reverse(result);
416 for(GList *
m = media;
m;
m = g_list_next(
m))
432 if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR))
444 const char *tp_intent_name[] = {
"perception_0",
"colorimetric-relative_1",
"saturation_1",
"colorimetric-absolute_1" };
448 g_strlcat(tmpfile,
"/dt_cups_opts_XXXXXX",
sizeof(tmpfile));
450 gint fd = g_mkstemp(tmpfile);
453 dt_control_log(_(
"failed to create temporary file for printing options"));
454 fprintf(stderr,
"failed to create temporary pdf for printing options\n");
463 gchar * argv[15] = { 0 };
465 argv[0] =
"turboprint";
466 argv[1] = g_strdup_printf(
"--printer=%s", pinfo->
printer.
name);
467 argv[2] =
"--options";
468 argv[3] = g_strdup_printf(
"--output=%s", tmpfile);
470 argv[5] =
"copies=1";
474 argv[9] =
"InputSlot=AutoSelect";
476 argv[11] = g_strdup_printf(
"zedoIntent=%s", tp_intent_name[intent]);
478 argv[13] = g_strdup_printf(
"MediaType=%s", pinfo->
medium.
name);
481 gint exit_status = 0;
483 g_spawn_sync(NULL, argv, NULL,
484 G_SPAWN_SEARCH_PATH | G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
485 NULL, NULL, NULL, NULL, &exit_status, NULL);
495 FILE *stream = g_fopen(tmpfile,
"rb");
501 const int ropt = fscanf(stream,
"%*s %99[^= ]=%99s", optname, optvalue);
510 if (
v[strlen(
v)-1] ==
'\'')
v[strlen(
v)-1] =
'\0';
512 num_options = cupsAddOption(optname,
v, num_options, &
options);
514 else if (ropt == EOF)
530 const int num_dests = cupsGetDests(&dests);
531 cups_dest_t *dest = cupsGetDest(pinfo->
printer.
name, NULL, num_dests, dests);
533 for (
int j = 0; j < dest->num_options; j ++)
534 if (cupsGetOption(dest->options[j].name, num_options,
536 num_options = cupsAddOption(dest->options[j].name,
537 dest->options[j].value,
540 cupsFreeDests(num_dests, dests);
544 num_options = cupsAddOption(
"cm-calibration", *pinfo->
printer.
profile ?
"true" :
"false", num_options, &
options);
548 num_options = cupsAddOption(
"media", pinfo->
paper.
name, num_options, &
options);
552 num_options = cupsAddOption(
"MediaType", pinfo->
medium.
name, num_options, &
options);
556 num_options = cupsAddOption(
"sides",
"one-sided", num_options, &
options);
560 num_options = cupsAddOption(
"number-up",
"1", num_options, &
options);
568 num_options = cupsAddOption(
"StpFullBleed",
"true", num_options, &
options);
569 num_options = cupsAddOption(
"STP_FullBleed",
"true", num_options, &
options);
570 num_options = cupsAddOption(
"Borderless",
"true", num_options, &
options);
580 for (
int k=0;
k<num_options;
k++)
583 const int job_id = cupsPrintFile(pinfo->
printer.
name, filename, job_title, num_options,
options);
590 cupsFreeOptions (num_options,
options);
594 const int32_t area_width,
const int32_t area_height,
595 float *px,
float *py,
float *pwidth,
float *pheight,
596 float *ax,
float *ay,
float *awidth,
float *aheight,
597 gboolean *borderless)
618 float tmp = pg_width;
619 pg_width = pg_height;
625 np_right = np_bottom;
631 const float a_aspect = (float)area_width / (
float)area_height;
634 const float pg_aspect = pg_width / pg_height;
637 float p_bottom, p_right;
639 if(a_aspect > pg_aspect)
641 *px = (area_width - (area_height * pg_aspect)) / 2.0f;
643 p_bottom = area_height;
644 p_right = area_width - *px;
649 *py = (area_height - (area_width / pg_aspect)) / 2.0f;
650 p_right = area_width;
651 p_bottom = area_height - *py;
654 *pwidth = p_right - *px;
655 *pheight = p_bottom - *py;
668 const float bx = *px + (border_left / pg_width) * (*pwidth);
669 const float by = *py + (border_top / pg_height) * (*pheight);
670 const float bb = p_bottom - (border_bottom / pg_height) * (*pheight);
671 const float br = p_right - (border_right / pg_width) * (*pwidth);
673 *borderless = border_left < np_left
674 || border_right < np_right
675 || border_top < np_top
676 || border_bottom < np_bottom;
typedef void((*dt_cache_allocate_t)(void *userdata, dt_cache_entry_t *entry))
void dt_control_log(const char *msg,...)
struct dt_control_t * dt_control_get_global(void)
static gint sort_papers(gconstpointer p1, gconstpointer p2)
void dt_get_printer_info(const char *printer_name, dt_printer_info_t *pinfo)
static gboolean paper_exists(GList *papers, const char *name)
void dt_print_file(const int32_t imgid, const char *filename, const char *job_title, const dt_print_info_t *pinfo)
static int _dest_cb(void *user_data, unsigned flags, cups_dest_t *dest)
dt_medium_info_t * dt_get_medium(GList *media, const char *name)
static int _detect_printers_callback(dt_job_t *job)
GList * dt_get_media_type(const dt_printer_info_t *printer)
void dt_printers_discovery(void(*cb)(dt_printer_info_t *pr, void *user_data), void *user_data)
void dt_printers_abort_discovery(void)
void dt_get_print_layout(const dt_print_info_t *prt, const int32_t area_width, const int32_t area_height, float *px, float *py, float *pwidth, float *pheight, float *ax, float *ay, float *awidth, float *aheight, gboolean *borderless)
dt_paper_info_t * dt_get_paper(GList *papers, const char *name)
GList * dt_get_papers(const dt_printer_info_t *printer)
void dt_init_print_info(dt_print_info_t *pinfo)
void dt_loc_get_tmp_dir(char *tmpdir, size_t bufsize)
dt_job_t * dt_control_job_create(dt_job_execute_callback execute, const char *msg,...)
int dt_control_add_job(dt_control_t *control, dt_job_queue_t queue_id, _dt_job_t *job)
void * dt_control_job_get_params(const _dt_job_t *job)
void dt_control_job_set_params(_dt_job_t *job, void *params, dt_job_destroy_callback callback)
void dt_print(dt_debug_thread_t thread, const char *msg,...) __attribute__((format(printf
Print to stdout when thread is enabled, prefixed with seconds since startup.
float *const restrict const size_t k
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
#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_PATH_MAX
Buffer size for a filesystem path anywhere in Ansel.
#define dt_pdf_point_to_mm(pt)
float dt_aligned_pixel_simd_t __attribute__((vector_size(16), aligned(16)))
Apply one channel's tone curve to each of the three colour channels, or pass the channel through unto...
static const dt_aligned_pixel_simd_t value
dt_printer_info_t printer
dt_iop_color_intent_t intent
void(* cb)(dt_printer_info_t *, void *)
typedef double((*spd)(unsigned long int wavelength, double TempK))
void dt_util_str_to_loc_numbers_format(char *data)