Exemplo n.º 1
0
int QPrinter::metric(int m) const
{
  int val = 1;
  switch (m) {
    case QPaintDeviceMetrics::PdmWidth: {
      bool orientInSync = true;
      PMOrientation o;
      QPrinter::Orientation tmpOrient = orientation();
      if (PMGetOrientation(pformat, &o) == noErr) {
        orientInSync = ((o == kPMPortrait && tmpOrient == Portrait)
                        || o == kPMLandscape && tmpOrient == Landscape);
      }
      PageSize s = pageSize();
      if (s >= QPrinter::Custom) {
        val = tmpOrient == Portrait ? customPaperSize_.width() : customPaperSize_.height();
      } else {
        if (state == PST_ACTIVE || (tmpOrient == Portrait || orientInSync)) {
          val = qt_get_PDMWidth(pformat, fullPage());
        } else {
          val = qt_get_PDMHeight(pformat, fullPage());
        }
      }
      break;
    }
    case QPaintDeviceMetrics::PdmHeight: {
      bool orientInSync = true;
      PMOrientation o;
      QPrinter::Orientation tmpOrient = orientation();
      if (PMGetOrientation(pformat, &o) == noErr) {
        orientInSync = ((o == kPMPortrait && tmpOrient == Portrait)
                        || o == kPMLandscape && tmpOrient == Landscape);
      }
      PageSize s = pageSize();
      if (s >= QPrinter::Custom) {
        val = tmpOrient == Portrait ? customPaperSize_.height() : customPaperSize_.width();
      } else {
        if (state == PST_ACTIVE || (tmpOrient == Portrait || orientInSync)) {
          val = qt_get_PDMHeight(pformat, fullPage());
        } else {
          val = qt_get_PDMWidth(pformat, fullPage());
        }
      }
      break;
    }
    // We don't have to worry about the printer state here as metric() does that for us.
    case QPaintDeviceMetrics::PdmWidthMM:
      val = metric(QPaintDeviceMetrics::PdmWidth);
      val = (val * 254 + 5 * res) / (10 * res);
      break;
    case QPaintDeviceMetrics::PdmHeightMM:
      val = metric(QPaintDeviceMetrics::PdmHeight);
      val = (val * 254 + 5 * res) / (10 * res);
      break;
    case QPaintDeviceMetrics::PdmPhysicalDpiX:
    case QPaintDeviceMetrics::PdmPhysicalDpiY: {
      PMPrinter printer;
      if (PMSessionGetCurrentPrinter(psession, &printer) == noErr) {
        PMResolution resolution;
        PMPrinterGetPrinterResolution(printer, kPMCurrentValue, &resolution);
        val = (int)resolution.vRes;
        break;
      }
      //otherwise fall through
    }
    case QPaintDeviceMetrics::PdmDpiY:
    case QPaintDeviceMetrics::PdmDpiX:
      val = res;
      break;
    case QPaintDeviceMetrics::PdmNumColors:
      val = (1 << metric(QPaintDeviceMetrics::PdmDepth));
      break;
    case QPaintDeviceMetrics::PdmDepth:
      val = 24;
      break;
    default:
      val = 0;
#if defined(QT_CHECK_RANGE)
      qWarning("Qt: QPixmap::metric: Invalid metric command");
#endif
  }
  return val;
}
Exemplo n.º 2
0
int QMacPrintEngine::metric(QPaintDevice::PaintDeviceMetric m) const
{
    Q_D(const QMacPrintEngine);
    int val = 1;
    switch (m) {
    case QPaintDevice::PdmWidth:
        if (d->hasCustomPaperSize) {
            val = qRound(d->customSize.width());
            if (d->hasCustomPageMargins) {
                val -= qRound(d->leftMargin + d->rightMargin);
            } else {
                QList<QVariant> margins = property(QPrintEngine::PPK_PageMargins).toList();
                val -= qRound(margins.at(0).toDouble() + margins.at(2).toDouble());
            }
        } else {
            val = qt_get_PDMWidth(d->format, property(PPK_FullPage).toBool(), d->resolution);
        }
        break;
    case QPaintDevice::PdmHeight:
        if (d->hasCustomPaperSize) {
            val = qRound(d->customSize.height());
            if (d->hasCustomPageMargins) {
                val -= qRound(d->topMargin + d->bottomMargin);
            } else {
                QList<QVariant> margins = property(QPrintEngine::PPK_PageMargins).toList();
                val -= qRound(margins.at(1).toDouble() + margins.at(3).toDouble());
            }
        } else {
            val = qt_get_PDMHeight(d->format, property(PPK_FullPage).toBool(), d->resolution);
        }
        break;
    case QPaintDevice::PdmWidthMM:
        val = metric(QPaintDevice::PdmWidth);
        val = int((val * 254 + 5 * d->resolution.hRes) / (10 * d->resolution.hRes));
        break;
    case QPaintDevice::PdmHeightMM:
        val = metric(QPaintDevice::PdmHeight);
        val = int((val * 254 + 5 * d->resolution.vRes) / (10 * d->resolution.vRes));
        break;
    case QPaintDevice::PdmPhysicalDpiX:
    case QPaintDevice::PdmPhysicalDpiY: {
        PMPrinter printer;
        if(PMSessionGetCurrentPrinter(d->session, &printer) == noErr) {
            PMResolution resolution;
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
            if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) {
                PMPrinterGetOutputResolution(printer, d->settings, &resolution);
            } else
#endif
            {
#ifndef Q_OS_MAC64
                PMPrinterGetPrinterResolution(printer, kPMCurrentValue, &resolution);
#endif
            }
            val = (int)resolution.vRes;
            break;
        }
        //otherwise fall through
    }
    case QPaintDevice::PdmDpiY:
        val = (int)d->resolution.vRes;
        break;
    case QPaintDevice::PdmDpiX:
        val = (int)d->resolution.hRes;
        break;
    case QPaintDevice::PdmNumColors:
        val = (1 << metric(QPaintDevice::PdmDepth));
        break;
    case QPaintDevice::PdmDepth:
        val = 24;
        break;
    default:
        val = 0;
        qWarning("QPrinter::metric: Invalid metric command");
    }
    return val;
}