36#include <AvailabilityMacros.h>
48#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)
51#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)
53extern cups_dinfo_t *cupsCopyDestInfo()
__attribute__((weak_import));
54extern
int cupsGetDestMediaCount()
__attribute__((weak_import));
55extern
int cupsGetDestMediaByIndex()
__attribute__((weak_import));
59#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
90 const int num_dests = cupsGetDests(&dests);
91 cups_dest_t *dest = cupsGetDest(printer_name, NULL, num_dests, dests);
95 const char *PPDFile = cupsGetPPD (printer_name);
97 ppd_file_t *ppd = ppdOpenFile(PPDFile);
101 ppdMarkDefaults(ppd);
102 cupsMarkOptions(ppd, dest->num_options, dest->options);
107 ppd_attr_t *attr = ppdFindAttr(ppd,
"ModelName", NULL);
111 pinfo->
is_turboprint = strstr(attr->value,
"TurboPrint") != NULL;
116 attr = ppdFindAttr(ppd,
"HWMargins", NULL);
123 sscanf(attr->value,
"%lf %lf %lf %lf",
135 attr = ppdFindAttr(ppd,
"DefaultResolution", NULL);
139 char *
x = strstr(attr->value,
"x");
144 sscanf (attr->value,
"%ddpi", &pinfo->
resolution);
157 cupsFreeDests(num_dests, dests);
163 const char *psvalue = cupsGetOption(
"printer-state", dest->num_options, dest->options);
166 if (psvalue!=NULL && strtol(psvalue, NULL, 10) < IPP_PRINTER_STOPPED)
169 memset(&pr, 0,
sizeof(pr));
186#if ((CUPS_VERSION_MAJOR == 1) && (CUPS_VERSION_MINOR >= 6)) || CUPS_VERSION_MAJOR > 1
187#if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_8
190 res = cupsEnumDests(CUPS_MEDIA_FLAGS_DEFAULT, 30000, &
_cancel, 0, 0,
_dest_cb, pctl);
191#if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_8
195#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)
198 const int num_dests = cupsGetDests(&dests);
199 for (
int k=0;
k<num_dests;
k++)
203 cupsFreeDests(num_dests, dests);
236 for(GList *
p = papers;
p;
p = g_list_next(
p))
249 for(GList *
p = papers;
p;
p = g_list_next(
p))
273 const char *printer_name = printer->
name;
274 GList *result = NULL;
276#if ((CUPS_VERSION_MAJOR == 1) && (CUPS_VERSION_MINOR >= 7)) || CUPS_VERSION_MAJOR > 1
277#if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_9
283 const int num_dests = cupsGetDests(&dests);
284 cups_dest_t *dest = cupsGetDest(printer_name, NULL, num_dests, dests);
292 http_t *hcon = cupsConnectDest(dest, 0, 2000, &cancel, resource,
sizeof(resource), NULL, (
void *)NULL);
297 cups_dinfo_t *info = cupsCopyDestInfo (hcon, dest);
298 const int count = cupsGetDestMediaCount(hcon, dest, info, CUPS_MEDIA_FLAGS_DEFAULT);
299 for (
int k=0;
k<count;
k++)
301 if (cupsGetDestMediaByIndex(hcon, dest, info,
k, CUPS_MEDIA_FLAGS_DEFAULT, &
size))
305 pwg_media_t *med = pwgMediaForPWG (
size.media);
309 g_strlcpy(common_name, med->ppd,
sizeof(common_name));
311 g_strlcpy(common_name,
size.media,
sizeof(common_name));
314 g_strlcpy(paper->
name,
size.media,
sizeof(paper->
name));
318 result = g_list_append (result, paper);
321 "[print] new media paper %4d %6.2f x %6.2f (%s) (%s)\n",
327 cupsFreeDestInfo(info);
334 cupsFreeDests(num_dests, dests);
340 const char *PPDFile = cupsGetPPD(printer_name);
341 ppd_file_t *ppd = ppdOpenFile(PPDFile);
345 ppd_size_t *
size = ppd->sizes;
347 for (
int k=0;
k<ppd->num_sizes;
k++)
356 result = g_list_append (result, paper);
359 "[print] new ppd paper %4d %6.2f x %6.2f (%s) (%s)\n",
369 result = g_list_sort_with_data (result, (GCompareDataFunc)
sort_papers, NULL);
375 const char *printer_name = printer->
name;
376 GList *result = NULL;
380 const char *PPDFile = cupsGetPPD(printer_name);
381 ppd_file_t *ppd = ppdOpenFile(PPDFile);
385 ppd_option_t *opt = ppdFindOption(ppd,
"MediaType");
389 ppd_choice_t *choice = opt->choices;
391 for (
int k=0;
k<opt->num_choices;
k++)
396 result = g_list_prepend (result, media);
407 return g_list_reverse(result);
414 for(GList *
m = media;
m;
m = g_list_next(
m))
430 if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR))
442 const char *tp_intent_name[] = {
"perception_0",
"colorimetric-relative_1",
"saturation_1",
"colorimetric-absolute_1" };
446 g_strlcat(tmpfile,
"/dt_cups_opts_XXXXXX",
sizeof(tmpfile));
448 gint fd = g_mkstemp(tmpfile);
451 dt_control_log(_(
"failed to create temporary file for printing options"));
452 fprintf(stderr,
"failed to create temporary pdf for printing options\n");
461 gchar * argv[15] = { 0 };
463 argv[0] =
"turboprint";
464 argv[1] = g_strdup_printf(
"--printer=%s", pinfo->
printer.
name);
465 argv[2] =
"--options";
466 argv[3] = g_strdup_printf(
"--output=%s", tmpfile);
468 argv[5] =
"copies=1";
472 argv[9] =
"InputSlot=AutoSelect";
474 argv[11] = g_strdup_printf(
"zedoIntent=%s", tp_intent_name[intent]);
476 argv[13] = g_strdup_printf(
"MediaType=%s", pinfo->
medium.
name);
479 gint exit_status = 0;
481 g_spawn_sync(NULL, argv, NULL,
482 G_SPAWN_SEARCH_PATH | G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
483 NULL, NULL, NULL, NULL, &exit_status, NULL);
493 FILE *stream = g_fopen(tmpfile,
"rb");
499 const int ropt = fscanf(stream,
"%*s %99[^= ]=%99s", optname, optvalue);
508 if (
v[strlen(
v)-1] ==
'\'')
v[strlen(
v)-1] =
'\0';
510 num_options = cupsAddOption(optname,
v, num_options, &
options);
512 else if (ropt == EOF)
528 const int num_dests = cupsGetDests(&dests);
529 cups_dest_t *dest = cupsGetDest(pinfo->
printer.
name, NULL, num_dests, dests);
531 for (
int j = 0; j < dest->num_options; j ++)
532 if (cupsGetOption(dest->options[j].name, num_options,
534 num_options = cupsAddOption(dest->options[j].name,
535 dest->options[j].value,
538 cupsFreeDests(num_dests, dests);
542 num_options = cupsAddOption(
"cm-calibration", *pinfo->
printer.
profile ?
"true" :
"false", num_options, &
options);
546 num_options = cupsAddOption(
"media", pinfo->
paper.
name, num_options, &
options);
550 num_options = cupsAddOption(
"MediaType", pinfo->
medium.
name, num_options, &
options);
554 num_options = cupsAddOption(
"sides",
"one-sided", num_options, &
options);
558 num_options = cupsAddOption(
"number-up",
"1", num_options, &
options);
566 num_options = cupsAddOption(
"StpFullBleed",
"true", num_options, &
options);
567 num_options = cupsAddOption(
"STP_FullBleed",
"true", num_options, &
options);
568 num_options = cupsAddOption(
"Borderless",
"true", num_options, &
options);
578 for (
int k=0;
k<num_options;
k++)
581 const int job_id = cupsPrintFile(pinfo->
printer.
name, filename, job_title, num_options,
options);
588 cupsFreeOptions (num_options,
options);
592 const int32_t area_width,
const int32_t area_height,
593 float *px,
float *py,
float *pwidth,
float *pheight,
594 float *ax,
float *ay,
float *awidth,
float *aheight,
595 gboolean *borderless)
616 float tmp = pg_width;
617 pg_width = pg_height;
623 np_right = np_bottom;
629 const float a_aspect = (float)area_width / (
float)area_height;
632 const float pg_aspect = pg_width / pg_height;
635 float p_bottom, p_right;
637 if(a_aspect > pg_aspect)
639 *px = (area_width - (area_height * pg_aspect)) / 2.0f;
641 p_bottom = area_height;
642 p_right = area_width - *px;
647 *py = (area_height - (area_width / pg_aspect)) / 2.0f;
648 p_right = area_width;
649 p_bottom = area_height - *py;
652 *pwidth = p_right - *px;
653 *pheight = p_bottom - *py;
666 const float bx = *px + (border_left / pg_width) * (*pwidth);
667 const float by = *py + (border_top / pg_height) * (*pheight);
668 const float bb = p_bottom - (border_bottom / pg_height) * (*pheight);
669 const float br = p_right - (border_right / pg_width) * (*pwidth);
671 *borderless = border_left < np_left
672 || border_right < np_right
673 || border_top < np_top
674 || border_bottom < np_bottom;
static const dt_aligned_pixel_simd_t const dt_adaptation_t const float p
typedef void((*dt_cache_allocate_t)(void *userdata, dt_cache_entry_t *entry))
void dt_control_log(const char *msg,...)
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_print(dt_debug_thread_t thread, const char *msg,...)
float dt_aligned_pixel_simd_t __attribute__((vector_size(16), aligned(16)))
Enable aggressive floating-point arithmetic optimizations, in denormals handling. Set through user pr...
static const dt_aligned_pixel_simd_t value
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
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)
float *const restrict const size_t k
dt_mipmap_buffer_dsc_flags flags
#define dt_pdf_point_to_mm(pt)
struct dt_control_t * control
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)