GList *dt_get_papers(const dt_printer_info_t *printer) { const char *printer_name = printer->name; GList *result = NULL; #if ((CUPS_VERSION_MAJOR == 1) && (CUPS_VERSION_MINOR >= 7)) || CUPS_VERSION_MAJOR > 1 #if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_9 if (cupsConnectDest != NULL && cupsCopyDestInfo != NULL && cupsGetDestMediaCount != NULL && cupsGetDestMediaByIndex != NULL && cupsFreeDestInfo != NULL) #endif { cups_dest_t *dests; int num_dests = cupsGetDests(&dests); cups_dest_t *dest = cupsGetDest(printer_name, NULL, num_dests, dests); int cancel = 0; // important char resource[1024]; if (dest) { http_t *hcon = cupsConnectDest(dest, 0, 2000, &cancel, resource, sizeof(resource), NULL, (void *)NULL); if (hcon) { cups_size_t size; cups_dinfo_t *info = cupsCopyDestInfo (hcon, dest); const int count = cupsGetDestMediaCount(hcon, dest, info, CUPS_MEDIA_FLAGS_DEFAULT); for (int k=0; k<count; k++) { if (cupsGetDestMediaByIndex(hcon, dest, info, k, CUPS_MEDIA_FLAGS_DEFAULT, &size)) { if (size.width!=0 && size.length!=0 && !paper_exists(result, size.media)) { pwg_media_t *med = pwgMediaForPWG (size.media); char common_name[MAX_NAME] = { 0 }; if (med->ppd) g_strlcpy(common_name, med->ppd, sizeof(common_name)); else g_strlcpy(common_name, size.media, sizeof(common_name)); dt_paper_info_t *paper = (dt_paper_info_t*)malloc(sizeof(dt_paper_info_t)); g_strlcpy(paper->name, size.media, sizeof(paper->name)); g_strlcpy(paper->common_name, common_name, sizeof(paper->common_name)); paper->width = (double)size.width / 100.0; paper->height = (double)size.length / 100.0; result = g_list_append (result, paper); dt_print(DT_DEBUG_PRINT, "[print] new media paper %4d %6.2f x %6.2f (%s) (%s)\n", k, paper->width, paper->height, paper->name, paper->common_name); } } } cupsFreeDestInfo(info); httpClose(hcon); } else dt_print(DT_DEBUG_PRINT, "[print] cannot connect to printer %s (cancel=%d)\n", printer_name, cancel); } cupsFreeDests(num_dests, dests); } #endif // check now PPD page sizes const char *PPDFile = cupsGetPPD(printer_name); ppd_file_t *ppd = ppdOpenFile(PPDFile); if (ppd) { ppd_size_t *size = ppd->sizes; for (int k=0; k<ppd->num_sizes; k++) { if (size->width!=0 && size->length!=0 && !paper_exists(result, size->name)) { dt_paper_info_t *paper = (dt_paper_info_t*)malloc(sizeof(dt_paper_info_t)); g_strlcpy(paper->name, size->name, MAX_NAME); g_strlcpy(paper->common_name, size->name, MAX_NAME); paper->width = (double)dt_pdf_point_to_mm(size->width); paper->height = (double)dt_pdf_point_to_mm(size->length); result = g_list_append (result, paper); dt_print(DT_DEBUG_PRINT, "[print] new ppd paper %4d %6.2f x %6.2f (%s) (%s)\n", k, paper->width, paper->height, paper->name, paper->common_name); } size++; } ppdClose(ppd); g_unlink(PPDFile); } result = g_list_sort_with_data (result, (GCompareDataFunc)sort_papers, NULL); return result; }
static void show_media(http_t *http, /* I - Connection to destination */ cups_dest_t *dest, /* I - Destination */ cups_dinfo_t *dinfo, /* I - Destination information */ unsigned flags, /* I - Media flags */ const char *name) /* I - Size name */ { int i, /* Looping var */ count; /* Number of sizes */ cups_size_t size; /* Media size info */ if (name) { double dw, dl; /* Width and length from name */ char units[32]; /* Units */ int width, /* Width in 100ths of millimeters */ length; /* Length in 100ths of millimeters */ if (sscanf(name, "%lfx%lf%31s", &dw, &dl, units) == 3) { if (!strcmp(units, "in")) { width = (int)(dw * 2540.0); length = (int)(dl * 2540.0); } else if (!strcmp(units, "mm")) { width = (int)(dw * 100.0); length = (int)(dl * 100.0); } else { puts(" bad units in size"); return; } if (cupsGetDestMediaBySize(http, dest, dinfo, width, length, flags, &size)) { printf(" %s (%s) %dx%d B%d L%d R%d T%d\n", size.media, cupsLocalizeDestMedia(http, dest, dinfo, flags, &size), size.width, size.length, size.bottom, size.left, size.right, size.top); } else { puts(" not supported"); } } else if (cupsGetDestMediaByName(http, dest, dinfo, name, flags, &size)) { printf(" %s (%s) %dx%d B%d L%d R%d T%d\n", size.media, cupsLocalizeDestMedia(http, dest, dinfo, flags, &size), size.width, size.length, size.bottom, size.left, size.right, size.top); } else { puts(" not supported"); } } else { count = cupsGetDestMediaCount(http, dest, dinfo, flags); printf("%d size%s:\n", count, count == 1 ? "" : "s"); for (i = 0; i < count; i ++) { if (cupsGetDestMediaByIndex(http, dest, dinfo, i, flags, &size)) printf(" %s (%s) %dx%d B%d L%d R%d T%d\n", size.media, cupsLocalizeDestMedia(http, dest, dinfo, flags, &size), size.width, size.length, size.bottom, size.left, size.right, size.top); else puts(" error"); } } }