⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qpdf.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    bool hb = d->hasBrush;    QPainterPath p;    switch(mode) {    case OddEvenMode:        p.setFillRule(Qt::OddEvenFill);        break;    case ConvexMode:    case WindingMode:        p.setFillRule(Qt::WindingFill);        break;    case PolylineMode:        d->hasBrush = false;        break;    default:        break;    }    p.moveTo(points[0]);    for (int i = 1; i < pointCount; ++i)        p.lineTo(points[i]);    if (mode != PolylineMode)        p.closeSubpath();    drawPath(p);    d->hasBrush = hb;}void QPdfBaseEngine::drawPath (const QPainterPath &p){    Q_D(QPdfBaseEngine);    if (d->clipEnabled && d->allClipped)        return;    if (!d->hasPen && !d->hasBrush)        return;    if (d->simplePen) {        // draw strokes natively in this case for better output        *d->currentPage << QPdf::generatePath(p, QTransform(), d->hasBrush ? QPdf::FillAndStrokePath : QPdf::StrokePath);    } else {        if (d->hasBrush)            *d->currentPage << QPdf::generatePath(p, d->stroker.matrix, QPdf::FillPath);        if (d->hasPen) {            *d->currentPage << "q\n";            QBrush b = d->brush;            d->brush = d->pen.brush();            setBrush();            d->stroker.strokePath(p);            *d->currentPage << "Q\n";            d->brush = b;        }    }}void QPdfBaseEngine::drawTextItem(const QPointF &p, const QTextItem &textItem){    Q_D(QPdfBaseEngine);    if (!d->hasPen || (d->clipEnabled && d->allClipped))        return;    *d->currentPage << "q\n";    if(!d->simplePen)        *d->currentPage << QPdf::generateMatrix(d->stroker.matrix);    bool hp = d->hasPen;    d->hasPen = false;    QBrush b = d->brush;    d->brush = d->pen.brush();    setBrush();    const QTextItemInt &ti = static_cast<const QTextItemInt &>(textItem);    Q_ASSERT(ti.fontEngine->type() != QFontEngine::Multi);    d->drawTextItem(p, ti);    d->hasPen = hp;    d->brush = b;    *d->currentPage << "Q\n";}void QPdfBaseEngine::updateState(const QPaintEngineState &state){    Q_D(QPdfBaseEngine);    QPaintEngine::DirtyFlags flags = state.state();    if (flags & DirtyTransform)        d->stroker.matrix = state.transform();    if (flags & DirtyPen) {        d->pen = state.pen();        d->hasPen = d->pen.style() != Qt::NoPen;        d->stroker.setPen(d->pen);        QBrush penBrush = d->pen.brush();        bool oldSimple = d->simplePen;        d->simplePen = (d->hasPen && (penBrush.style() == Qt::SolidPattern) && penBrush.isOpaque());        if (oldSimple != d->simplePen)            flags |= DirtyTransform;    }    if (flags & DirtyBrush) {        d->brush = state.brush();        d->hasBrush = d->brush.style() != Qt::NoBrush;    }    if (flags & DirtyBrushOrigin) {        d->brushOrigin = state.brushOrigin();        flags |= DirtyBrush;    }    bool ce = d->clipEnabled;    if (flags & DirtyClipPath) {        d->clipEnabled = true;        updateClipPath(state.clipPath(), state.clipOperation());    } else if (flags & DirtyClipRegion) {        d->clipEnabled = true;        QPainterPath path;        QVector<QRect> rects = state.clipRegion().rects();        for (int i = 0; i < rects.size(); ++i)            path.addRect(rects.at(i));        updateClipPath(path, state.clipOperation());        flags |= DirtyClipPath;    } else if (flags & DirtyClipEnabled) {        d->clipEnabled = state.isClipEnabled();    }    if (ce != d->clipEnabled)        flags |= DirtyClipPath;    else if (!d->clipEnabled)        flags &= ~DirtyClipPath;    setupGraphicsState(flags);}void QPdfBaseEngine::setupGraphicsState(QPaintEngine::DirtyFlags flags){    Q_D(QPdfBaseEngine);    if (flags & DirtyClipPath)        flags |= DirtyTransform|DirtyPen|DirtyBrush;    if (flags & DirtyTransform) {        *d->currentPage << "Q\n";        flags |= DirtyPen|DirtyBrush;    }    if (flags & DirtyClipPath) {        *d->currentPage << "Q q\n";        d->allClipped = false;        if (d->clipEnabled && !d->clips.isEmpty()) {            for (int i = 0; i < d->clips.size(); ++i) {                if (d->clips.at(i).isEmpty()) {                    d->allClipped = true;                    break;                }            }            if (!d->allClipped) {                for (int i = 0; i < d->clips.size(); ++i) {                    *d->currentPage << QPdf::generatePath(d->clips.at(i), QTransform(), QPdf::ClipPath);                }            }        }    }    if (flags & DirtyTransform) {        *d->currentPage << "q\n";        if (d->simplePen && !d->stroker.matrix.isIdentity())            *d->currentPage << QPdf::generateMatrix(d->stroker.matrix);    }    if (flags & DirtyBrush)        setBrush();    if (d->simplePen && (flags & DirtyPen))        setPen();}void QPdfBaseEngine::updateClipPath(const QPainterPath &p, Qt::ClipOperation op){    Q_D(QPdfBaseEngine);    QPainterPath path = d->stroker.matrix.map(p);    //qDebug() << "updateClipPath: " << d->stroker.matrix << p.boundingRect() << path.boundingRect() << op;    if (op == Qt::NoClip) {        d->clipEnabled = false;        d->clips.clear();    } else if (op == Qt::ReplaceClip) {        d->clips.clear();        d->clips.append(path);    } else if (op == Qt::IntersectClip) {        d->clips.append(path);    } else { // UniteClip        // ask the painter for the current clipping path. that's the easiest solution        path = painter()->clipPath();        path = d->stroker.matrix.map(path);        d->clips.clear();        d->clips.append(path);    }}void QPdfBaseEngine::setPen(){    Q_D(QPdfBaseEngine);    if (d->pen.style() == Qt::NoPen)        return;    QBrush b = d->pen.brush();    Q_ASSERT(b.style() == Qt::SolidPattern && b.isOpaque());    QColor rgba = b.color();    *d->currentPage << rgba.redF()                   << rgba.greenF()                   << rgba.blueF()                   << "SCN\n";    *d->currentPage << d->pen.widthF() << "w ";    int pdfCapStyle = 0;    switch(d->pen.capStyle()) {    case Qt::FlatCap:        pdfCapStyle = 0;        break;    case Qt::SquareCap:        pdfCapStyle = 2;        break;    case Qt::RoundCap:        pdfCapStyle = 1;        break;    default:        break;    }    *d->currentPage << pdfCapStyle << "J ";    int pdfJoinStyle = 0;    switch(d->pen.joinStyle()) {    case Qt::MiterJoin:        pdfJoinStyle = 0;        break;    case Qt::BevelJoin:        pdfJoinStyle = 2;        break;    case Qt::RoundJoin:        pdfJoinStyle = 1;        break;    default:        break;    }    *d->currentPage << pdfJoinStyle << "j ";    *d->currentPage << QPdf::generateDashes(d->pen) << " 0 d\n";}bool QPdfBaseEngine::newPage(){    setupGraphicsState(DirtyBrush|DirtyPen|DirtyClipPath);    return true;}int QPdfBaseEngine::metric(QPaintDevice::PaintDeviceMetric metricType) const{    Q_D(const QPdfBaseEngine);    int val;    QRect r = d->fullPage ? d->paperRect() : d->pageRect();    switch (metricType) {    case QPaintDevice::PdmWidth:        val = r.width();        break;    case QPaintDevice::PdmHeight:        val = r.height();        break;    case QPaintDevice::PdmDpiX:    case QPaintDevice::PdmDpiY:        val = d->resolution;        break;    case QPaintDevice::PdmPhysicalDpiX:    case QPaintDevice::PdmPhysicalDpiY:        val = 1200;        break;    case QPaintDevice::PdmWidthMM:        val = qRound(r.width()*25.4/d->resolution);        break;    case QPaintDevice::PdmHeightMM:        val = qRound(r.height()*25.4/d->resolution);        break;    case QPaintDevice::PdmNumColors:        val = INT_MAX;        break;    case QPaintDevice::PdmDepth:        val = 32;        break;    default:        qWarning("QPrinter::metric: Invalid metric command");        return 0;    }    return val;}void QPdfBaseEngine::setProperty(PrintEnginePropertyKey key, const QVariant &value){    Q_D(QPdfBaseEngine);    switch (key) {    case PPK_CollateCopies:        d->collate = value.toBool();        break;    case PPK_ColorMode:        d->colorMode = QPrinter::ColorMode(value.toInt());        break;    case PPK_Creator:        d->creator = value.toString();        break;    case PPK_DocumentName:        d->title = value.toString();        break;    case PPK_FullPage:        d->fullPage = value.toBool();        break;    case PPK_NumberOfCopies:        d->copies = value.toInt();        break;    case PPK_Orientation:        d->orientation = QPrinter::Orientation(value.toInt());        break;    case PPK_OutputFileName:        d->outputFileName = value.toString();        break;    case PPK_PageOrder:        d->pageOrder = QPrinter::PageOrder(value.toInt());        break;    case PPK_PageSize:        d->pageSize = QPrinter::PageSize(value.toInt());        break;    case PPK_PaperSource:        d->paperSource = QPrinter::PaperSource(value.toInt());        break;    case PPK_PrinterName:        d->printerName = value.toString();        break;    case PPK_PrinterProgram:        d->printProgram = value.toString();        break;    case PPK_Resolution:        d->resolution = value.toInt();        break;    case PPK_SelectionOption:        d->selectionOption = value.toString();        break;    case PPK_FontEmbedding:        d->embedFonts = value.toBool();        break;    case PPK_Duplex:        d->duplex = value.toBool();        break;    case PPK_CupsPageRect:        d->cupsPageRect = value.toRect();        break;    case PPK_CupsPaperRect:        d->cupsPaperRect = value.toRect();        break;    case PPK_CupsOptions:        d->cupsOptions = value.toStringList();        break;    case PPK_CupsStringPageSize:        d->cupsStringPageSize = value.toString();        break;    default:        break;    }}QVariant QPdfBaseEngine::property(PrintEnginePropertyKey key) const{    Q_D(const QPdfBaseEngine);    QVariant ret;    switch (key) {    case PPK_CollateCopies:        ret = d->collate;        break;    case PPK_ColorMode:        ret = d->colorMode;        break;    case PPK_Creator:        ret = d->creator;        break;    case PPK_DocumentName:        ret = d->title;        break;    case PPK_FullPage:        ret = d->fullPage;        break;    case PPK_NumberOfCopies:#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)        if (QCUPSSupport::isAvailable())            ret = 1;        else#endif            ret = d->copies;        break;    case PPK_Orientation:        ret = d->orientation;        break;    case PPK_OutputFileName:        ret = d->outputFileName;        break;    case PPK_PageOrder:        ret = d->pageOrder;        break;    case PPK_PageSize:        ret = d->pageSize;        break;    case PPK_PaperSource:        ret = d->paperSource;        break;    case PPK_PrinterName:        ret = d->printerName;        break;    case PPK_PrinterProgram:        ret = d->printProgram;        break;    case PPK_Resolution:        ret = d->resolution;        break;    case PPK_SupportedResolutions:        ret = QList<QVariant>() << 72;        break;    case PPK_PaperRect:        ret = d->paperRect();        break;    case PPK_PageRect:        ret = d->pageRect();        break;    case PPK_SelectionOption:        ret = d->selectionOption;        break;    case PPK_FontEmbedding:        ret = d->embedFonts;        break;    case PPK_Duplex:        ret = d->duplex;        break;    case PPK_CupsPageRect:        ret = d->cupsPageRect;        break;    case PPK_CupsPaperRect:        ret = d->cupsPaperRect;        break;    case PPK_CupsOptions:        ret = d->cupsOptions;        break;    case PPK_CupsStringPageSize:        ret = d->cupsStringPageSize;        break;    default:        break;    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -