+static int ResolutionSorter(const void *e1, const void *e2)
+{
+ const PMResolution *res1 = (const PMResolution *)e1;
+ const PMResolution *res2 = (const PMResolution *)e2;
+ const double area1 = res1->hRes * res1->vRes;
+ const double area2 = res2->hRes * res2->vRes;
+
+ if (area1 < area2)
+ return -1;
+ else if (area1 > area2)
+ return 1;
+ else
+ return 0;
+}
+
+static PMResolution *GetSupportedResolutions(PMPrinter printer, UInt32 *count)
+{
+ PMResolution res, *resolutions = NULL;
+ OSStatus status = PMPrinterGetPrinterResolutionCount(printer, count);
+ if (status == noErr)
+ {
+ resolutions = (PMResolution *)malloc(sizeof(PMResolution) * (*count));
+ UInt32 realCount = 0;
+ for (UInt32 i = 0; i < *count; i++)
+ {
+ if (PMPrinterGetIndexedPrinterResolution(printer, i + 1, &res) == noErr)
+ resolutions[realCount++] = res;
+ }
+ qsort(resolutions, realCount, sizeof(PMResolution), ResolutionSorter);
+
+ *count = realCount;
+ }
+ if ((*count == 0) && (resolutions))
+ {
+ free(resolutions);
+ resolutions = NULL;
+ }
+ return resolutions;
+}
+
+
+